blob: 059d2989ad01c6827a60bd624b96c7fbdd968755 [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"
[email protected]bffc8302014-01-23 20:52:1643#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4044#include "content/browser/frame_host/interstitial_page_impl.h"
45#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3346#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0147#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1848#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0749#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1650#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5751#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0552#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4453#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4054#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3055#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5256#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1857#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5258#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5359#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0960#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3061#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5062#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3263#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5064#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5965#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4866#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0967#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3368#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1269#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1170#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5871#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0372#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5673#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1474#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4275#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4476#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1777#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0778#include "content/common/page_messages.h"
avi286019ce2015-07-29 01:26:5879#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5180#include "content/common/ssl_status_serialization.h"
ekaramad2bd4a2f2016-04-06 20:12:4681#include "content/common/text_input_state.h"
[email protected]2c5569662011-03-22 20:45:0282#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3683#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1184#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2885#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4486#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3687#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1788#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1489#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4690#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1591#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0092#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2793#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0094#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3795#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1496#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3097#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3298#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0999#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:12100#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34101#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38102#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:42103#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21104#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08105#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35106#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48107#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54108#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49109#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20110#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01111#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03112#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57113#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05114#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40115#include "mojo/common/url_type_converters.h"
116#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53117#include "net/http/http_cache.h"
118#include "net/http/http_transaction_factory.h"
119#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34120#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40121#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38122#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40123#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39124#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56125#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01126#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41127#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52128#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31129
[email protected]583418cc2013-01-17 14:01:10130#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40131#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15132#include "content/browser/android/date_time_chooser_android.h"
dalecurtisc85ed632016-01-13 00:22:46133#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18134#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15135#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10136
[email protected]f66df822012-05-18 16:52:17137#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50138#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57139#endif
[email protected]3e45ba92009-02-20 21:09:00140
fsamuel9cf7bdf2015-11-20 02:19:32141#if defined(MOJO_SHELL_CLIENT)
142#include "content/browser/web_contents/web_contents_view_mus.h"
143#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46144#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32145#endif
146
[email protected]8ff00d72012-10-23 19:12:21147namespace content {
[email protected]420ae012009-04-24 05:16:32148namespace {
149
[email protected]960b0372014-05-19 18:01:00150const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41151const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05152
[email protected]155c7f22013-12-09 17:07:18153#if defined(OS_ANDROID)
154const char kWebContentsAndroidKey[] = "web_contents_android";
155#endif // OS_ANDROID
156
[email protected]e4abd3b42013-11-12 18:28:47157base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46158g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
159
[email protected]8bfc8272013-09-09 20:10:53160void NotifyCacheOnIO(
161 scoped_refptr<net::URLRequestContextGetter> request_context,
162 const GURL& url,
163 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58164 net::HttpCache* cache = request_context->GetURLRequestContext()->
165 http_transaction_factory()->GetCache();
166 if (cache)
167 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53168}
169
dcheng57e39e22016-01-21 00:25:38170bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
171 for (FrameTreeNode* node : tree->Nodes()) {
172 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
173 return true;
alexmos4cf2aa32015-07-15 23:40:43174 }
dcheng57e39e22016-01-21 00:25:38175 return false;
[email protected]95640212014-07-26 18:14:30176}
177
[email protected]95640212014-07-26 18:14:30178void SetAccessibilityModeOnFrame(AccessibilityMode mode,
179 RenderFrameHost* frame_host) {
180 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
181}
182
dtseng0dd3fa12015-07-22 19:00:52183void ResetAccessibility(RenderFrameHost* rfh) {
184 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
185}
186
dmazzonid95ae842016-04-12 21:17:39187using AXTreeSnapshotCallback =
188 base::Callback<void(const ui::AXTreeUpdate&)>;
189
190// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
191// Handles the callbacks from parallel snapshot requests to each frame,
192// and feeds the results to an AXTreeCombiner, which converts them into a
193// single combined accessibility tree.
194class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
195 public:
196 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
197 : callback_(callback) {
198 }
199
200 AXTreeSnapshotCallback AddFrame(bool is_root) {
201 // Adds a reference to |this|.
202 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
203 this,
204 is_root);
205 }
206
207 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
208 combiner_.AddTree(snapshot, is_root);
209 }
210
211 private:
212 friend class base::RefCounted<AXTreeSnapshotCombiner>;
213
214 // This is called automatically after the last call to ReceiveSnapshot
215 // when there are no more references to this object.
216 ~AXTreeSnapshotCombiner() {
217 combiner_.Combine();
218 callback_.Run(combiner_.combined());
219 }
220
221 ui::AXTreeCombiner combiner_;
222 AXTreeSnapshotCallback callback_;
223};
224
[email protected]420ae012009-04-24 05:16:32225} // namespace
226
[email protected]54944cde2012-12-09 09:24:59227WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21228 FrameTreeNode* opener_node = nullptr;
229 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
230 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
231 params.opener_render_process_id, params.opener_render_frame_id);
232 if (opener_rfh)
233 opener_node = opener_rfh->frame_tree_node();
234 }
235 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19236}
237
238WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59239 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30240 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21241 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30242
243 for (SessionStorageNamespaceMap::const_iterator it =
244 session_storage_namespace_map.begin();
245 it != session_storage_namespace_map.end();
246 ++it) {
247 new_contents->GetController()
248 .SetSessionStorageNamespace(it->first, it->second.get());
249 }
250
[email protected]54944cde2012-12-09 09:24:59251 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19252 return new_contents;
[email protected]a81343d232011-12-27 07:39:20253}
[email protected]746d3052012-05-22 15:15:47254
nickf9acfbe2014-12-23 19:12:37255void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
256 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46257 g_created_callbacks.Get().push_back(callback);
258}
259
nickf9acfbe2014-12-23 19:12:37260void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
261 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46262 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
263 if (g_created_callbacks.Get().at(i).Equals(callback)) {
264 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
265 return;
266 }
267 }
268}
269
avidf38c952015-10-27 13:45:13270WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
271 if (!rvh)
272 return nullptr;
[email protected]746d3052012-05-22 15:15:47273 return rvh->GetDelegate()->GetAsWebContents();
274}
275
[email protected]a86c0e962013-12-17 17:10:39276WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13277 if (!rfh)
278 return nullptr;
279 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39280}
281
[email protected]7fff43e2013-05-21 20:21:10282// WebContentsImpl::DestructionObserver ----------------------------------------
283
284class WebContentsImpl::DestructionObserver : public WebContentsObserver {
285 public:
286 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
287 : WebContentsObserver(watched_contents),
288 owner_(owner) {
289 }
290
291 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58292 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58293 owner_->OnWebContentsDestroyed(
294 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10295 }
296
297 private:
298 WebContentsImpl* owner_;
299
300 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
301};
302
[email protected]8ed16472014-04-11 19:02:48303WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
304 int render_frame_id,
305 ColorChooser* chooser,
306 int identifier)
307 : render_process_id(render_process_id),
308 render_frame_id(render_frame_id),
309 chooser(chooser),
310 identifier(identifier) {
311}
312
313WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
314}
315
lazyboy6ec48b2a2015-06-29 15:18:14316// WebContentsImpl::WebContentsTreeNode ----------------------------------------
317WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
318 : outer_web_contents_(nullptr),
319 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37320 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14321}
322
323WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
324 // Remove child pointer from our parent.
325 if (outer_web_contents_) {
326 ChildrenSet& child_ptrs_in_parent =
327 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
328 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
329 DCHECK(iter != child_ptrs_in_parent.end());
330 child_ptrs_in_parent.erase(this);
331 }
332
333 // Remove parent pointers from our children.
334 // TODO(lazyboy): We should destroy the children WebContentses too. If the
335 // children do not manage their own lifetime, then we would leak their
336 // WebContentses.
337 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
338 child->outer_web_contents_ = nullptr;
339}
340
341void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
342 WebContentsImpl* outer_web_contents,
343 RenderFrameHostImpl* outer_contents_frame) {
344 outer_web_contents_ = outer_web_contents;
345 outer_contents_frame_tree_node_id_ =
346 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
347
348 if (!outer_web_contents_->node_)
349 outer_web_contents_->node_.reset(new WebContentsTreeNode());
350
351 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
352}
353
[email protected]b172aee2012-04-10 17:05:26354// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32355
alexmose201c7cd2015-06-10 17:14:21356WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42357 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22358 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57359 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21360 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01361 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57362 this,
363 this,
364 this,
365 this),
[email protected]6dfed692014-05-22 04:18:03366 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23367 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
368 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34369 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26370 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56371 upload_size_(0),
372 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16373 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47374 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10375 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28376 theme_color_(SK_ColorTRANSPARENT),
377 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29378 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55379 capturer_count_(0),
380 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00381 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57382 is_being_destroyed_(false),
383 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15384 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01385 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39386 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38387 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21388 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
389 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22390 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44391 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55392 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42393 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03394 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49395 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05396 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30397 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57398 geolocation_service_context_(new GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48399 accessibility_mode_(
400 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15401 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35402 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50403 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46404 page_scale_factor_is_one_(true),
ekaramad2bd4a2f2016-04-06 20:12:46405 text_input_state_(new TextInputState()),
pkotwicz75ca8ffd2016-02-16 23:10:19406 loading_weak_factory_(this),
407 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55408 frame_tree_.SetFrameRemoveListener(
409 base::Bind(&WebContentsImpl::OnFrameRemoved,
410 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46411#if defined(OS_ANDROID)
412 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
413#else
qinmin58567c82015-01-07 21:00:20414 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46415#endif
csharrisona2280cd2016-02-03 23:21:15416 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12417 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35418}
initial.commit09911bf2008-07-26 23:55:29419
[email protected]b172aee2012-04-10 17:05:26420WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32421 is_being_destroyed_ = true;
422
kenrb2a565f82015-09-02 20:24:59423 rwh_input_event_router_.reset();
424
dcheng72be33c2016-01-21 04:11:31425 for (FrameTreeNode* node : frame_tree_.Nodes()) {
426 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
427 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38428 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38429 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31430 }
carlosk35f35af2015-12-01 10:55:40431
dcheng57e39e22016-01-21 00:25:38432 for (RenderWidgetHostImpl* widget : created_widgets_)
433 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26434 created_widgets_.clear();
435
[email protected]3ab9cb82011-06-03 18:02:07436 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15437 if (dialog_manager_)
avi2460c762015-04-17 15:21:54438 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07439
[email protected]8ed16472014-04-11 19:02:48440 if (color_chooser_info_.get())
441 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20442
[email protected]420ae012009-04-24 05:16:32443 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32444
[email protected]ca13a442012-04-17 14:00:12445 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21446 NotificationService::current()->Notify(
447 NOTIFICATION_WEB_CONTENTS_DESTROYED,
448 Source<WebContents>(this),
449 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32450
[email protected]df0c843f2014-05-23 20:37:23451 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14452 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23453 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59454
clamy0e119882015-07-31 16:12:33455 // Manually call the observer methods for the root frame tree node. It is
456 // necessary to manually delete all objects tracking navigations
457 // (NavigationHandle, NavigationRequest) for observers to be properly
458 // notified of these navigations stopping before the WebContents is
459 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23460 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56461
clamy0e119882015-07-31 16:12:33462 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56463 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33464 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08465 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33466 }
naskob21fe4872015-02-24 14:15:56467 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33468 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08469 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33470
471 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35472 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41473 // Do not update state as the WebContents is being destroyed.
474 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33475 if (root->speculative_frame_host()) {
476 root->speculative_frame_host()->SetRenderFrameCreated(false);
477 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08478 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33479 }
480 }
[email protected]f273ee52013-10-18 16:05:27481
naskoa83483fb2015-02-27 16:57:10482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
483 FrameDeleted(root->current_frame_host()));
484
[email protected]df0c843f2014-05-23 20:37:23485 if (root->pending_render_view_host()) {
486 FOR_EACH_OBSERVER(WebContentsObserver,
487 observers_,
488 RenderViewDeleted(root->pending_render_view_host()));
489 }
[email protected]c06c58c2014-03-12 20:31:59490
[email protected]f273ee52013-10-18 16:05:27491 FOR_EACH_OBSERVER(WebContentsObserver,
492 observers_,
[email protected]df0c843f2014-05-23 20:37:23493 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27494
[email protected]2db9bd72012-04-13 20:20:56495 FOR_EACH_OBSERVER(WebContentsObserver,
496 observers_,
[email protected]12a46832014-05-09 13:35:58497 WebContentsDestroyed());
498
499 FOR_EACH_OBSERVER(WebContentsObserver,
500 observers_,
501 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08502
[email protected]6934a702011-12-20 00:04:51503 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10504
505 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
506 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42507}
508
[email protected]d1198fd2012-08-13 22:50:19509WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59510 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21511 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03512 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21513 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19514
alexmosaedfc6f2016-01-21 23:57:38515 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
516
alexmose201c7cd2015-06-10 17:14:21517 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38518 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21519 new_contents->created_with_opener_ = true;
520 }
521
alexmosaedfc6f2016-01-21 23:57:38522 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
523 // flags, and these flags take effect immediately. An exception is if the
524 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
525 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
526 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
527 if (opener) {
528 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
529 const blink::WebSandboxFlags inherit_flag =
530 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
531 if ((opener_flags & inherit_flag) == inherit_flag) {
532 new_root->SetPendingSandboxFlags(opener_flags);
533 new_root->CommitPendingSandboxFlags();
534 }
535 }
536
alexmose201c7cd2015-06-10 17:14:21537 // This may be true even when opener is null, such as when opening blocked
538 // popups.
alexmos090fae8e2015-05-28 17:09:28539 if (params.created_with_opener)
540 new_contents->created_with_opener_ = true;
541
[email protected]4858e432014-06-23 18:14:17542 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06543 // This makes |new_contents| act as a guest.
544 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16545 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06546 // We are instantiating a WebContents for browser plugin. Set its subframe
547 // bit to true.
548 new_contents->is_subframe_ = true;
549 }
[email protected]54944cde2012-12-09 09:24:59550 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19551 return new_contents;
552}
553
[email protected]95640212014-07-26 18:14:30554// static
555std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
556 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08557 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30558 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30559 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30560 RenderViewHost* rvh = RenderViewHost::From(rwh);
561 if (!rvh)
562 continue;
563 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
564 if (!web_contents)
565 continue;
avidf38c952015-10-27 13:45:13566 if (web_contents->GetRenderViewHost() != rvh)
567 continue;
568 // Because a WebContents can only have one current RVH at a time, there will
569 // be no duplicate WebContents here.
570 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30571 }
572 return result;
573}
574
clamya16aa8172015-05-26 13:07:25575// static
576WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
577 FrameTreeNode* frame_tree_node) {
578 return static_cast<WebContentsImpl*>(
579 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
580}
581
clamy0d32d6d2015-11-24 11:16:26582// static
583WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
584 int render_frame_host_id) {
585 DCHECK_CURRENTLY_ON(BrowserThread::UI);
586 RenderFrameHost* render_frame_host =
587 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
588 if (!render_frame_host)
589 return nullptr;
590
591 return WebContents::FromRenderFrameHost(render_frame_host);
592}
593
[email protected]b0936d22013-11-28 06:47:36594RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21595 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28596}
597
[email protected]7bb761892012-07-20 09:32:47598bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
599 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44600 return OnMessageReceived(render_view_host, NULL, message);
601}
602
603bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
604 RenderFrameHost* render_frame_host,
605 const IPC::Message& message) {
606 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56607 if (GetWebUI() &&
608 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17609 return true;
[email protected]d2353452012-01-19 19:53:56610 }
[email protected]f82d57b52011-04-27 19:13:17611
brettw5a1613dc2015-06-02 05:34:43612 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25613 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33614 if (render_frame_host) {
615 while ((observer = it.GetNext()) != NULL)
616 if (observer->OnMessageReceived(message, render_frame_host))
617 return true;
618 } else {
619 while ((observer = it.GetNext()) != NULL)
620 if (observer->OnMessageReceived(message))
621 return true;
622 }
[email protected]403415a2011-01-10 18:57:53623
[email protected]1d62cf72014-02-07 21:31:57624 // Message handlers should be aware of which
625 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
626 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02627 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57628 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02629 else
[email protected]1d62cf72014-02-07 21:31:57630 render_view_message_source_ = render_view_host;
631
[email protected]724159a2010-12-30 01:11:18632 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33633 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40634 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
635 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05636 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
637 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48638 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
639 OnDocumentLoadedInFrame)
640 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
641 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
642 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
643 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
644 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18645
dglazkov79c426102015-08-31 21:22:43646 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11647 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25648 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18649 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54650 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18651 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54652 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18653 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41654 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
655 OnDidDisplayContentWithCertificateErrors)
656 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
657 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25658 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26659 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46660 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
661 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21662 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48663 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
664 OnRegisterProtocolHandler)
665 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
666 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01667 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
668 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52669 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10670 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50671 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50672#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00673 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
674 OnPepperInstanceCreated)
675 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
676 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42677 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
678 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50679 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
680 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55681 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40682 OnBrowserPluginMessage(render_frame_host,
683 message))
thestigc4cac8f2014-09-04 21:17:50684#endif
[email protected]41225fe2013-03-29 05:32:02685 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07686 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
687 OnShowValidationMessage)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
689 OnHideValidationMessage)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
691 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15692#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52693 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48694 OnFindMatchRectsReply)
695 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
696 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48697#endif
[email protected]724159a2010-12-30 01:11:18698 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33699 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44700 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57701 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18702
[email protected]724159a2010-12-30 01:11:18703 return handled;
704}
705
nasko907fcb62015-01-28 04:24:11706bool WebContentsImpl::HasValidFrameSource() {
707 if (!render_frame_message_source_) {
708 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18709 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
710 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11711 return false;
712 }
713
714 return true;
715}
716
[email protected]b172aee2012-04-10 17:05:26717void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18718 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21719 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43720 if (delegate_)
721 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18722}
723
[email protected]d1198fd2012-08-13 22:50:19724NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56725 return controller_;
726}
727
[email protected]d1198fd2012-08-13 22:50:19728const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56729 return controller_;
730}
731
[email protected]8ff00d72012-10-23 19:12:21732BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55733 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30734}
735
[email protected]b172aee2012-04-10 17:05:26736const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24737 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32738 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51739 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31740}
741
[email protected]a093ce02013-07-22 20:53:14742const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24743 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32744 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24745 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
746}
747
748const GURL& WebContentsImpl::GetLastCommittedURL() const {
749 // We may not have a navigation entry yet.
750 NavigationEntry* entry = controller_.GetLastCommittedEntry();
751 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
752}
753
[email protected]8ff00d72012-10-23 19:12:21754WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31755 return delegate_;
756}
757
[email protected]8ff00d72012-10-23 19:12:21758void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31759 // TODO(cbentzel): remove this debugging code?
760 if (delegate == delegate_)
761 return;
762 if (delegate_)
763 delegate_->Detach(this);
764 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08765 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31766 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08767 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00768 if (view_)
[email protected]e85165c642014-06-10 14:34:31769 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08770 }
[email protected]be1f56ab2011-12-22 06:55:31771}
772
[email protected]8ff00d72012-10-23 19:12:21773RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21774 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41775 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16776}
777
clamydf1975e2015-02-05 19:12:24778RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41779 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16780}
781
nick53d5cbf2015-04-23 22:50:14782RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
783 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
784 if (!focused_node)
785 return nullptr;
786 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07787}
788
rob3e2a0732016-01-06 21:22:09789RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
790 int frame_tree_node_id) {
791 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
792 return frame ? frame->current_frame_host() : nullptr;
793}
794
[email protected]a86c0e962013-12-17 17:10:39795void WebContentsImpl::ForEachFrame(
796 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38797 for (FrameTreeNode* node : frame_tree_.Nodes()) {
798 on_frame.Run(node->current_frame_host());
799 }
[email protected]a86c0e962013-12-17 17:10:39800}
801
dchengafb53e22016-02-04 08:11:08802std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
803 std::vector<RenderFrameHost*> frame_hosts;
804 for (FrameTreeNode* node : frame_tree_.Nodes())
805 frame_hosts.push_back(node->current_frame_host());
806 return frame_hosts;
807}
808
lukaszacbdf52e2016-01-15 21:19:51809int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
810 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08811 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25812 if (!rfh->IsRenderFrameLive())
813 continue;
814
dchengafb53e22016-02-04 08:11:08815 ++number_of_messages;
816 IPC::Message* message_copy = new IPC::Message(*message);
817 message_copy->set_routing_id(rfh->GetRoutingID());
818 rfh->Send(message_copy);
819 }
[email protected]a86c0e962013-12-17 17:10:39820 delete message;
lukaszacbdf52e2016-01-15 21:19:51821 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39822}
823
lfgdb5c4ed2016-03-04 23:09:07824void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
825 frame_tree_.root()->render_manager()->SendPageMessage(msg);
826}
827
creisc014b402015-04-23 16:41:45828RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21829 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31830}
831
[email protected]6b618e62012-08-16 12:59:18832int WebContentsImpl::GetRoutingID() const {
833 if (!GetRenderViewHost())
834 return MSG_ROUTING_NONE;
835
836 return GetRenderViewHost()->GetRoutingID();
837}
838
creis89a0f782015-05-27 16:13:17839void WebContentsImpl::CancelActiveAndPendingDialogs() {
840 if (dialog_manager_)
841 dialog_manager_->CancelActiveAndPendingDialogs(this);
842 if (browser_plugin_embedder_)
843 browser_plugin_embedder_->CancelGuestDialogs();
844}
845
[email protected]44470a22013-01-24 01:21:54846int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
847 return fullscreen_widget_routing_id_;
848}
849
naskoc0fceff2015-04-30 15:53:52850void WebContentsImpl::ClosePage() {
851 GetRenderViewHost()->ClosePage();
852}
853
[email protected]b172aee2012-04-10 17:05:26854RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21855 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31856}
857
[email protected]4aebbca2013-09-17 22:26:49858RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
859 const {
860 RenderWidgetHost* const widget_host =
861 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
862 GetFullscreenWidgetRoutingID());
863 return widget_host ? widget_host->GetView() : NULL;
864}
865
[email protected]8ff00d72012-10-23 19:12:21866WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return view_.get();
868}
869
yusufod41c5f92015-03-06 00:14:28870SkColor WebContentsImpl::GetThemeColor() const {
871 return theme_color_;
872}
873
[email protected]95640212014-07-26 18:14:30874void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
875 if (mode == accessibility_mode_)
876 return;
877
878 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38879
880 for (FrameTreeNode* node : frame_tree_.Nodes()) {
881 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
882 RenderFrameHost* pending_frame_host =
883 node->render_manager()->pending_frame_host();
884 if (pending_frame_host)
885 SetAccessibilityModeOnFrame(mode, pending_frame_host);
886 }
[email protected]95640212014-07-26 18:14:30887}
888
889void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50890 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30891}
892
893void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50894 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30895}
896
dmazzoni83ba5c82015-04-14 07:11:51897void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39898 // Send a request to each of the frames in parallel. Each one will return
899 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
900 // them into a single tree and call |callback| with that result, then
901 // delete |combiner|.
902 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
903 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
904 bool is_root = frame_tree_node->parent() == nullptr;
905 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
906 combiner->AddFrame(is_root));
907 }
dmazzoni83ba5c82015-04-14 07:11:51908}
909
dbeama1b926a2015-08-31 23:17:51910WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
911 const std::string& frame_name) {
912 DCHECK(!frame_name.empty());
913 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22914}
915
[email protected]8ff00d72012-10-23 19:12:21916WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40917 WebUI* commited_web_ui = GetCommittedWebUI();
918 return commited_web_ui ? commited_web_ui
919 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31920}
921
[email protected]8ff00d72012-10-23 19:12:21922WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40923 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34924}
925
[email protected]86ef6a392012-05-11 22:03:11926void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22927 if (GetUserAgentOverride() == override)
928 return;
929
930 renderer_preferences_.user_agent_override = override;
931
932 // Send the new override string to the renderer.
933 RenderViewHost* host = GetRenderViewHost();
934 if (host)
935 host->SyncRendererPrefs();
936
937 // Reload the page if a load is currently in progress to avoid having
938 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27939 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25940 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05941 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53942
943 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
944 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11945}
946
947const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22948 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11949}
950
[email protected]95640212014-07-26 18:14:30951void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08952 if (GetAccessibilityMode() != AccessibilityModeOff) {
953 for (RenderFrameHost* rfh : GetAllFrames())
954 ResetAccessibility(rfh);
955 } else {
dtseng0dd3fa12015-07-22 19:00:52956 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08957 }
[email protected]95640212014-07-26 18:14:30958}
959
960bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
961 return accessibility_mode_ == AccessibilityModeTreeOnly;
962}
963
964bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
965 return accessibility_mode_ == AccessibilityModeComplete;
966}
967
kouhei40f03cb2015-09-24 07:47:01968const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
969 return page_importance_signals_;
970}
971
[email protected]fcf75d42013-12-03 20:11:26972const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55973 // Transient entries take precedence. They are used for interstitial pages
974 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23975 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23976 if (entry) {
jshin1fb76462016-04-05 22:13:03977 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23978 }
carlosk35f35af2015-12-01 10:55:40979
980 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
981 WebUI* our_web_ui = navigating_web_ui
982 ? navigating_web_ui
983 : GetRenderManager()->current_frame_host()->web_ui();
984
[email protected]7ade2732011-02-10 00:13:58985 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54986 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32987 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54988 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35989 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26990 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54991 if (!title.empty())
992 return title;
993 }
994 }
995
996 // We use the title for the last committed entry rather than a pending
997 // navigation entry. For example, when the user types in a URL, we want to
998 // keep the old page's title until the new load has committed and we get a new
999 // title.
[email protected]96d185d2009-04-24 03:28:541000 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321001
creis072b61f2015-09-28 20:52:241002 // We make an exception for initial navigations. We only want to use the title
1003 // from the visible entry if:
1004 // 1. The pending entry has been explicitly assigned a title to display.
1005 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1006 // which case there is a pending entry index other than -1.
1007 //
1008 // Otherwise, we want to stick with the last committed entry's title during
1009 // new navigations, which have pending entries at index -1 with no title.
1010 if (controller_.IsInitialNavigation() &&
1011 ((controller_.GetVisibleEntry() &&
1012 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1013 controller_.GetPendingEntryIndex() != -1)) {
1014 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471015 }
[email protected]59167c22013-06-03 18:07:321016
[email protected]45d0ef7f2011-01-05 13:46:231017 if (entry) {
jshin1fb76462016-04-05 22:13:031018 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231019 }
[email protected]987fc3a2011-05-26 14:18:091020
1021 // |page_title_when_no_navigation_entry_| is finally used
1022 // if no title cannot be retrieved.
1023 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541024}
1025
avib7348942015-12-25 20:57:101026int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461027 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1028}
1029
avib7348942015-12-25 20:57:101030int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261031 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331032 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1033 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461034
[email protected]b6583592012-01-25 19:52:331035 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341036}
1037
avib7348942015-12-25 20:57:101038void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461039 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1040}
1041
[email protected]b172aee2012-04-10 17:05:261042void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101043 SiteInstance* site_instance,
1044 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461045 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331046 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341047}
1048
[email protected]ec6c05f2013-10-23 18:41:571049void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1050 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1051 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571052}
1053
creiscce56cd2014-09-29 22:45:221054SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211055 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541056}
1057
creiscce56cd2014-09-29 22:45:221058SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1059 RenderViewHostImpl* dest_rvh =
1060 GetRenderManager()->pending_render_view_host() ?
1061 GetRenderManager()->pending_render_view_host() :
1062 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581063 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381064}
1065
[email protected]b172aee2012-04-10 17:05:261066bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251067 return frame_tree_.IsLoading() &&
1068 !(ShowingInterstitialPage() &&
1069 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491070}
1071
[email protected]6dfed692014-05-22 04:18:031072bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251073 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031074}
1075
[email protected]b172aee2012-04-10 17:05:261076bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031077 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311078}
1079
[email protected]b172aee2012-04-10 17:05:261080const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311081 return load_state_;
1082}
1083
[email protected]fcf75d42013-12-03 20:11:261084const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311085 return load_state_host_;
1086}
1087
avib7348942015-12-25 20:57:101088uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311089 return upload_size_;
1090}
1091
avib7348942015-12-25 20:57:101092uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311093 return upload_position_;
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541097 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311098}
1099
[email protected]b172aee2012-04-10 17:05:261100bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311101 return displayed_insecure_content_;
1102}
1103
[email protected]222f5822014-02-05 23:40:491104void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251105 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551106 ++capturer_count_;
1107 DVLOG(1) << "There are now " << capturer_count_
1108 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491109
1110 // Note: This provides a hint to upstream code to size the views optimally
1111 // for quality (e.g., to avoid scaling).
1112 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1113 preferred_size_for_capture_ = capture_size;
1114 OnPreferredSizeChanged(preferred_size_);
1115 }
ccameron8807c38f2015-01-17 00:29:191116
1117 // Ensure that all views are un-occluded before capture begins.
1118 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551119}
1120
1121void WebContentsImpl::DecrementCapturerCount() {
1122 --capturer_count_;
1123 DVLOG(1) << "There are now " << capturer_count_
1124 << " capturing(s) of WebContentsImpl@" << this;
1125 DCHECK_LE(0, capturer_count_);
1126
[email protected]5a652232013-02-12 06:15:251127 if (is_being_destroyed_)
1128 return;
1129
[email protected]222f5822014-02-05 23:40:491130 if (capturer_count_ == 0) {
1131 const gfx::Size old_size = preferred_size_for_capture_;
1132 preferred_size_for_capture_ = gfx::Size();
1133 OnPreferredSizeChanged(old_size);
1134 }
1135
[email protected]1ac10dca2013-08-20 20:47:041136 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551137 DVLOG(1) << "Executing delayed WasHidden().";
1138 WasHidden();
1139 }
[email protected]be1f56ab2011-12-22 06:55:311140}
1141
[email protected]f2bd40812013-07-20 04:30:441142int WebContentsImpl::GetCapturerCount() const {
1143 return capturer_count_;
1144}
1145
miu50f97892014-09-22 22:49:521146bool WebContentsImpl::IsAudioMuted() const {
1147 return audio_muter_.get() && audio_muter_->is_muting();
1148}
1149
1150void WebContentsImpl::SetAudioMuted(bool mute) {
1151 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1152 << " for WebContentsImpl@" << this;
1153
1154 if (mute == IsAudioMuted())
1155 return;
1156
1157 if (mute) {
1158 if (!audio_muter_)
1159 audio_muter_.reset(new WebContentsAudioMuter(this));
1160 audio_muter_->StartMuting();
1161 } else {
1162 DCHECK(audio_muter_);
1163 audio_muter_->StopMuting();
1164 }
1165
wjmaclean2f797c782016-01-07 14:52:031166 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1167 DidUpdateAudioMutingState(mute));
1168
miu50f97892014-09-22 22:49:521169 // Notification for UI updates in response to the changed muting state.
1170 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1171}
1172
ortunodf4d7982016-04-08 02:33:351173void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
1174 // Notify for UI updates if the state changes.
1175 bluetooth_connected_device_count_++;
1176 if (bluetooth_connected_device_count_ == 1) {
1177 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1178 }
ortuno32e7db3c2016-03-29 16:14:201179}
1180
ortunodf4d7982016-04-08 02:33:351181void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
1182 // Notify for UI updates if the state changes.
1183 DCHECK(bluetooth_connected_device_count_ != 0);
1184 bluetooth_connected_device_count_--;
1185 if (bluetooth_connected_device_count_ == 0) {
1186 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1187 }
1188}
1189
1190bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1191 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201192}
1193
[email protected]b172aee2012-04-10 17:05:261194bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311195 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1196 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581197 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271198#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581199 crashed_status_ ==
1200 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271201#endif
wfh0d9532a2015-09-02 23:18:581202 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271203 );
[email protected]3c9e1872010-11-18 16:17:491204}
1205
[email protected]b172aee2012-04-10 17:05:261206void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1207 int error_code) {
[email protected]443b80e2010-12-14 00:42:231208 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341209 return;
1210
[email protected]443b80e2010-12-14 00:42:231211 crashed_status_ = status;
1212 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211213 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341214}
1215
[email protected]b172aee2012-04-10 17:05:261216base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311217 return crashed_status_;
1218}
1219
afakhry98241832016-03-11 19:27:471220int WebContentsImpl::GetCrashedErrorCode() const {
1221 return crashed_error_code_;
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311225 return is_being_destroyed_;
1226}
1227
[email protected]7f924832014-08-09 05:57:221228void WebContentsImpl::NotifyNavigationStateChanged(
1229 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541230 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1231 // is fixed.
1232 tracked_objects::ScopedTracker tracking_profile(
1233 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1234 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181235 // Notify the media observer of potential audibility changes.
1236 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271237 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301238 }
1239
[email protected]d5f942ba2008-09-26 19:30:341240 if (delegate_)
1241 delegate_->NavigationStateChanged(this, changed_flags);
1242}
1243
gab0dccfef2015-05-20 18:43:391244base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021245 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331246}
1247
georgesak5582cbe2015-05-22 22:08:071248void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1249 last_active_time_ = last_active_time;
1250}
1251
[email protected]9e2e4632012-07-27 16:38:411252void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541253 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591254
ccameron8807c38f2015-01-17 00:29:191255 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1256 if (view) {
1257 view->Show();
[email protected]789e9152009-08-04 21:59:431258#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191259 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431260#endif
[email protected]de3c5d82014-05-28 22:12:591261 }
[email protected]789e9152009-08-04 21:59:431262 }
[email protected]96d185d2009-04-24 03:28:541263
gab0dccfef2015-05-20 18:43:391264 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381265
[email protected]b9769d82012-02-10 00:23:591266 // The resize rect might have changed while this was inactive -- send the new
1267 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451268 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221269 if (rvh) {
1270 rvh->GetWidget()->ResizeRectChanged(
1271 GetRootWindowResizerRect(rvh->GetWidget()));
1272 }
[email protected]96d185d2009-04-24 03:28:541273
[email protected]c0d9d5672013-10-09 07:38:031274 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1275
[email protected]54597982013-02-06 01:59:551276 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311277}
1278
[email protected]b172aee2012-04-10 17:05:261279void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551280 // If there are entities capturing screenshots or video (e.g., mirroring),
1281 // don't activate the "disable rendering" optimization.
1282 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521283 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551284 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261285 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521286 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331287 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521288 // calls us).
ccameron8807c38f2015-01-17 00:29:191289 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1290 if (view)
1291 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591292 }
[email protected]96d185d2009-04-24 03:28:541293 }
1294
[email protected]c0d9d5672013-10-09 07:38:031295 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1296
[email protected]54597982013-02-06 01:59:551297 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371298}
1299
ccameron8807c38f2015-01-17 00:29:191300void WebContentsImpl::WasOccluded() {
1301 if (capturer_count_ > 0)
1302 return;
1303
1304 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1305 if (view)
1306 view->WasOccluded();
1307 }
1308}
1309
1310void WebContentsImpl::WasUnOccluded() {
1311 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1312 if (view)
1313 view->WasUnOccluded();
1314 }
1315}
1316
[email protected]b172aee2012-04-10 17:05:261317bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311318 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451319 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1320 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311321}
1322
[email protected]1c3f80bd2014-04-08 23:02:061323void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451324 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061325}
1326
lazyboy6ec48b2a2015-06-29 15:18:141327void WebContentsImpl::AttachToOuterWebContentsFrame(
1328 WebContents* outer_web_contents,
1329 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081330 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lfg91a79e12016-04-01 23:52:191331 RenderFrameHostManager* render_manager = GetRenderManager();
1332
1333 // When the WebContents being initialized has an opener, the browser side
1334 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1335 // created. This is needed because the usual initialization happens during
1336 // the first navigation, but when attaching a new window we don't navigate
1337 // before attaching. If the browser side is already initialized, the calls
1338 // below will just early return.
1339 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1340 GetMainFrame()->Init();
1341 if (!render_manager->GetRenderWidgetHostView())
1342 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1343
lazyboy6ec48b2a2015-06-29 15:18:141344 // Create a link to our outer WebContents.
1345 node_.reset(new WebContentsTreeNode());
1346 node_->ConnectToOuterWebContents(
1347 static_cast<WebContentsImpl*>(outer_web_contents),
1348 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1349
1350 DCHECK(outer_contents_frame);
1351
1352 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1353 // SiteInstance of the outer WebContents. The proxy will be used to send
1354 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191355 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141356 outer_contents_frame->GetSiteInstance(),
1357 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1358
lfg91a79e12016-04-01 23:52:191359 render_manager->SetRWHViewForInnerContents(
1360 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391361
1362 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191363 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391364 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141365}
1366
[email protected]b172aee2012-04-10 17:05:261367void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381368 for (FrameTreeNode* node : frame_tree_.Nodes())
1369 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401370 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271371}
1372
[email protected]b172aee2012-04-10 17:05:261373WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441374 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211375 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451376 // before.
[email protected]54944cde2012-12-09 09:24:591377 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451378 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211379 WebContentsImpl* tc =
1380 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191381 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221382 FOR_EACH_OBSERVER(WebContentsObserver,
1383 observers_,
1384 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271385 return tc;
1386}
1387
[email protected]14392a52012-05-02 20:28:441388void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211389 const NotificationSource& source,
1390 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441391 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211392 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1393 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031394 RenderWidgetHostView* view = host->GetView();
1395 if (view == GetFullscreenRenderWidgetHostView()) {
1396 // We cannot just call view_->RestoreFocus() here. On some platforms,
1397 // attempting to focus the currently-invisible WebContentsView will be
1398 // flat-out ignored. Therefore, this boolean is used to track whether
1399 // we will request focus after the fullscreen widget has been
1400 // destroyed.
1401 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1402 } else {
1403 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1404 i != pending_widget_views_.end(); ++i) {
1405 if (host->GetView() == i->second) {
1406 pending_widget_views_.erase(i);
1407 break;
1408 }
[email protected]bafe6cd2012-05-23 23:09:501409 }
1410 }
1411 break;
1412 }
[email protected]14392a52012-05-02 20:28:441413 default:
1414 NOTREACHED();
1415 }
1416}
1417
[email protected]ec6c05f2013-10-23 18:41:571418WebContents* WebContentsImpl::GetWebContents() {
1419 return this;
1420}
1421
[email protected]54944cde2012-12-09 09:24:591422void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211423 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361424 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211425 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431426 should_normally_be_visible_ = !params.initially_hidden;
1427
dcheng3ce04b62015-10-26 23:30:551428 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541429 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551430 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1431 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541432 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551433 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1434 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1435
1436 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1437 if (!site_instance)
1438 site_instance = SiteInstance::Create(params.browser_context);
1439
1440 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1441 // local root by definition.
1442 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1443 // longer be necessary to eagerly grab a routing ID for the view.
1444 // https://crbug.com/545684
1445 int32_t view_routing_id = params.routing_id;
1446 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1447 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1448 view_routing_id = main_frame_widget_routing_id =
1449 site_instance->GetProcess()->GetNextRoutingID();
1450 }
1451
1452 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1453 params.main_frame_routing_id,
1454 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321455
1456 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1457 // frame - let's do the same thing here.
1458 std::string unique_name = params.main_frame_name;
1459 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191460
[email protected]fc2b46b2014-05-03 16:33:451461 WebContentsViewDelegate* delegate =
1462 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1463
fsamueladb0033602015-12-09 19:20:411464#if defined(MOJO_SHELL_CLIENT)
1465 if (MojoShellConnection::Get() &&
1466 base::CommandLine::ForCurrentProcess()->HasSwitch(
1467 switches::kUseMusInRenderer)) {
1468 mus::Window* mus_window = aura::GetMusWindow(params.context);
1469 if (mus_window) {
1470 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1471 &render_view_host_delegate_view_));
1472 }
1473 }
1474#endif
1475
1476 if (!view_) {
1477 view_.reset(CreateWebContentsView(this, delegate,
1478 &render_view_host_delegate_view_));
1479 }
fsamuel9cf7bdf2015-11-20 02:19:321480
lazyboy6ec48b2a2015-06-29 15:18:141481 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081482 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321483 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361484 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321485 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191486 }
[email protected]fc2b46b2014-05-03 16:33:451487 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191488 CHECK(view_.get());
1489
[email protected]ed245db2012-12-18 08:00:451490 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591491 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191492
tommyclieb25b2a2014-11-03 19:45:091493#if defined(ENABLE_PLUGINS)
1494 plugin_content_origin_whitelist_.reset(
1495 new PluginContentOriginWhitelist(this));
1496#endif
1497
[email protected]d1198fd2012-08-13 22:50:191498 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211499 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1500 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101501
[email protected]01f83f92014-06-17 14:41:541502 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091503 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541504
mlamouriefdca9d2014-09-16 16:55:401505 manifest_manager_host_.reset(new ManifestManagerHost(this));
1506
mfomitchev2b8b066a2016-01-28 19:23:151507#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101508 date_time_chooser_.reset(new DateTimeChooserAndroid());
1509#endif
fsamuel7310a4262014-12-05 05:06:441510
1511 // BrowserPluginGuest::Init needs to be called after this WebContents has
1512 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1513 if (browser_plugin_guest_)
1514 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371515
1516 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1517 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561518
1519 // If the WebContents creation was renderer-initiated, it means that the
1520 // corresponding RenderView and main RenderFrame have already been created.
1521 // Ensure observers are notified about this.
1522 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431523 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561524 RenderViewCreated(GetRenderViewHost());
1525 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1526 }
naskof5940b9f2015-03-02 23:04:051527
1528 // Ensure that observers are notified of the creation of this WebContents's
1529 // main RenderFrameHost. It must be done here for main frames, since the
1530 // NotifySwappedFromRenderManager expects view_ to already be created and that
1531 // happens after RenderFrameHostManager::Init.
1532 NotifySwappedFromRenderManager(
1533 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191534}
1535
[email protected]7fff43e2013-05-21 20:21:101536void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1537 RemoveDestructionObserver(web_contents);
1538
[email protected]ceee8cd2013-03-08 04:59:511539 // Clear a pending contents that has been closed before being shown.
1540 for (PendingContents::iterator iter = pending_contents_.begin();
1541 iter != pending_contents_.end();
1542 ++iter) {
1543 if (iter->second != web_contents)
1544 continue;
1545 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511546 return;
1547 }
1548 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441549}
1550
[email protected]7fff43e2013-05-21 20:21:101551void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1552 if (!ContainsKey(destruction_observers_, web_contents)) {
1553 destruction_observers_[web_contents] =
1554 new DestructionObserver(this, web_contents);
1555 }
1556}
1557
1558void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1559 DestructionObservers::iterator iter =
1560 destruction_observers_.find(web_contents);
1561 if (iter != destruction_observers_.end()) {
1562 delete destruction_observers_[web_contents];
1563 destruction_observers_.erase(iter);
1564 }
1565}
1566
[email protected]b172aee2012-04-10 17:05:261567void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311568 observers_.AddObserver(observer);
1569}
1570
[email protected]b172aee2012-04-10 17:05:261571void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311572 observers_.RemoveObserver(observer);
1573}
1574
[email protected]948481d2014-06-11 18:32:221575std::set<RenderWidgetHostView*>
1576WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1577 std::set<RenderWidgetHostView*> set;
1578 if (ShowingInterstitialPage()) {
1579 set.insert(GetRenderWidgetHostView());
1580 } else {
dchengafb53e22016-02-04 08:11:081581 for (RenderFrameHost* rfh : GetAllFrames()) {
1582 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1583 ->frame_tree_node()
1584 ->render_manager()
1585 ->GetRenderWidgetHostView();
1586 set.insert(rwhv);
1587 }
[email protected]948481d2014-06-11 18:32:221588 }
[email protected]de3c5d82014-05-28 22:12:591589 return set;
1590}
1591
[email protected]b172aee2012-04-10 17:05:261592void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341593 if (delegate_)
1594 delegate_->ActivateContents(this);
1595}
1596
avi3e4b8512015-11-11 01:55:491597void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1598 if (!RenderViewHostImpl::From(render_widget_host))
1599 return;
1600
[email protected]63954792011-07-11 04:17:481601 if (delegate_)
1602 delegate_->LostCapture();
1603}
1604
lazyboy63f5b312015-11-23 20:19:521605void WebContentsImpl::RenderWidgetCreated(
1606 RenderWidgetHostImpl* render_widget_host) {
1607 created_widgets_.insert(render_widget_host);
1608}
1609
[email protected]b24b68a2012-09-24 21:57:261610void WebContentsImpl::RenderWidgetDeleted(
1611 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521612 // Note that |is_being_destroyed_| can be true at this point as
1613 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1614 // us here.
1615 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261616
lazyboy63f5b312015-11-23 20:19:521617 if (is_being_destroyed_)
1618 return;
[email protected]44470a22013-01-24 01:21:541619
1620 if (render_widget_host &&
1621 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491622 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531623 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541624 FOR_EACH_OBSERVER(WebContentsObserver,
1625 observers_,
1626 DidDestroyFullscreenWidget(
1627 fullscreen_widget_routing_id_));
1628 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031629 if (fullscreen_widget_had_focus_at_shutdown_)
1630 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541631 }
[email protected]b24b68a2012-09-24 21:57:261632}
1633
miu9e14e492014-10-25 02:39:041634void WebContentsImpl::RenderWidgetGotFocus(
1635 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371636 // Notify the observers if an embedded fullscreen widget was focused.
1637 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1638 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1639 NotifyWebContentsFocused();
1640 }
miu9e14e492014-10-25 02:39:041641}
1642
estaded0a0c992015-01-21 14:12:061643void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311644 RenderWidgetHostImpl* render_widget_host,
1645 bool width_changed) {
creisc014b402015-04-23 16:41:451646 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291647 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061648 return;
estaded0a0c992015-01-21 14:12:061649
rouslan2f5993f2015-01-29 00:18:311650 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1651 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061652}
1653
paulmeyer9ef6e4462015-02-24 19:15:101654void WebContentsImpl::ScreenInfoChanged() {
1655 if (browser_plugin_embedder_)
1656 browser_plugin_embedder_->ScreenInfoChanged();
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659bool WebContentsImpl::PreHandleKeyboardEvent(
1660 const NativeWebKeyboardEvent& event,
1661 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481662 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131663 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481664}
1665
[email protected]b172aee2012-04-10 17:05:261666void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101667 if (browser_plugin_embedder_ &&
1668 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1669 return;
1670 }
[email protected]63954792011-07-11 04:17:481671 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131672 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481673}
1674
[email protected]d92026ef2014-03-03 21:04:131675bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461676 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191677#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331678 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1679 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191680 // -the OS already has a gesture to do this through pinch-zoom
1681 // -if a user starts an inertial scroll, let's go, and presses control
1682 // (i.e. control+tab) then the OS's buffered scroll events will come in
1683 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331684 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551685 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331686 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221687 // Count only integer cumulative scrolls as zoom events; this handles
1688 // smooth scroll and regular scroll device behavior.
1689 zoom_scroll_remainder_ += event.wheelTicksY;
1690 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1691 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1692 if (whole_zoom_scroll_remainder_ != 0) {
1693 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1694 }
[email protected]fb3f066e2013-02-12 19:12:521695 return true;
1696 }
[email protected]bccc4472013-04-18 16:37:191697#endif
[email protected]fb3f066e2013-02-12 19:12:521698 return false;
1699}
1700
[email protected]04bce562014-01-30 05:34:541701bool WebContentsImpl::PreHandleGestureEvent(
1702 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031703 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541704}
1705
kenrb2a565f82015-09-02 20:24:591706RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451707 if (!is_being_destroyed_ && GetOuterWebContents())
1708 return GetOuterWebContents()->GetInputEventRouter();
1709
1710 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591711 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1712 return rwh_input_event_router_.get();
1713}
1714
alexmos3fcd0ca2015-10-23 18:18:331715void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1716 // Focus loss may occur while this WebContents is being destroyed. Don't
1717 // send the message in this case, as the main frame's RenderFrameHost and
1718 // other state has already been cleared.
1719 if (is_being_destroyed_)
1720 return;
1721
1722 frame_tree_.ReplicatePageFocus(is_focused);
1723}
1724
alexmosc4cbacb2015-11-21 01:29:221725RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1726 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521727 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221728 return receiving_widget;
1729
1730 // Events for widgets other than the main frame (e.g., popup menus) should be
1731 // forwarded directly to the widget they arrived on.
1732 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1733 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521734
1735 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1736 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221737 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521738
alexmos732ca3a2015-12-08 02:01:021739 // The view may be null if a subframe's renderer process has crashed while
1740 // the subframe has focus. Drop the event in that case. Do not give
1741 // it to the main frame, so that the user doesn't unexpectedly type into the
1742 // wrong frame if a focused subframe renderer crashes while they type.
1743 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1744 if (!view)
1745 return nullptr;
1746
1747 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521748}
1749
mlamouri7a78d6fd2015-01-17 13:23:531750void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1751 // This method is being called to enter renderer-initiated fullscreen mode.
1752 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491753 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371754 if (widget_view) {
1755 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1756 ->ShutdownAndDestroyWidget(true);
1757 }
[email protected]4aebbca2013-09-17 22:26:491758
[email protected]8a5e0ca2011-08-25 06:30:471759 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531760 delegate_->EnterFullscreenModeForTab(this, origin);
1761
1762 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461763 DidToggleFullscreenModeForTab(
1764 IsFullscreenForCurrentTab(
1765 GetRenderViewHost()->GetWidget()),
1766 false));
mlamouri7a78d6fd2015-01-17 13:23:531767}
1768
bokanece34a82016-01-28 19:49:461769void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531770 // This method is being called to leave renderer-initiated fullscreen mode.
1771 // Make sure any existing fullscreen widget is shut down first.
1772 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371773 if (widget_view) {
1774 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1775 ->ShutdownAndDestroyWidget(true);
1776 }
mlamouri7a78d6fd2015-01-17 13:23:531777
hugo.holgersson61288e6c2015-01-28 17:04:401778#if defined(OS_ANDROID)
1779 ContentVideoView* video_view = ContentVideoView::GetInstance();
1780 if (video_view != NULL)
watk98292292016-01-19 22:24:081781 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401782#endif
1783
mlamouri7a78d6fd2015-01-17 13:23:531784 if (delegate_)
1785 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371786
bokanece34a82016-01-28 19:49:461787 // The fullscreen state is communicated to the renderer through a resize
1788 // message. If the change in fullscreen state doesn't cause a view resize
1789 // then we must ensure web contents exit the fullscreen state by explicitly
1790 // sending a resize message. This is required for the situation of the browser
1791 // moving the view into a "browser fullscreen" state and then the contents
1792 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1793 // have the side effect of the view resizing, hence the explicit call here is
1794 // required.
1795 if (!will_cause_resize) {
1796 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1797 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1798 render_widget_host->WasResized();
1799 }
scheib3dcb6c932015-02-23 10:55:581800 }
1801
avibf58fa0c2015-11-11 01:45:521802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461803 DidToggleFullscreenModeForTab(
1804 IsFullscreenForCurrentTab(
1805 GetRenderViewHost()->GetWidget()),
1806 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471807}
1808
avibf58fa0c2015-11-11 01:45:521809bool WebContentsImpl::IsFullscreenForCurrentTab(
1810 RenderWidgetHostImpl* render_widget_host) const {
1811 if (!RenderViewHostImpl::From(render_widget_host))
1812 return false;
1813
[email protected]199bba6e2012-04-04 16:19:381814 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121815}
1816
avibf58fa0c2015-11-11 01:45:521817blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1818 RenderWidgetHostImpl* render_widget_host) const {
1819 if (!RenderViewHostImpl::From(render_widget_host))
1820 return blink::WebDisplayModeBrowser;
1821
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121822 return delegate_ ? delegate_->GetDisplayMode(this)
1823 : blink::WebDisplayModeBrowser;
1824}
1825
avic3aa8422015-11-09 20:57:221826void WebContentsImpl::RequestToLockMouse(
1827 RenderWidgetHostImpl* render_widget_host,
1828 bool user_gesture,
1829 bool last_unlocked_by_target) {
1830 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1831 render_widget_host->GotResponseToLockMouseRequest(false);
1832 return;
[email protected]e9621112011-10-17 05:38:371833 }
avic3aa8422015-11-09 20:57:221834
1835 if (delegate_)
1836 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1837 else
1838 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371839}
1840
avi3e4b8512015-11-11 01:55:491841void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1842 if (!RenderViewHostImpl::From(render_widget_host))
1843 return;
1844
[email protected]e9621112011-10-17 05:38:371845 if (delegate_)
1846 delegate_->LostMouseLock();
1847}
1848
dtrainor5ef644e2015-11-19 00:12:471849void WebContentsImpl::ForwardCompositorProto(
1850 RenderWidgetHostImpl* render_widget_host,
1851 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471852 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291853 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471854}
1855
ekaramada4f42692016-02-11 19:48:371856void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1857 if (visible)
1858 WasShown();
1859 else
1860 WasHidden();
1861}
1862
[email protected]bafe6cd2012-05-23 23:09:501863void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431864 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551865 int32_t route_id,
1866 int32_t main_frame_route_id,
1867 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131868 const ViewHostMsg_CreateWindow_Params& params,
1869 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501870 // We usually create the new window in the same BrowsingInstance (group of
1871 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551872 // if the opener is being suppressed (in a non-guest), we create a new
1873 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251874 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551875
[email protected]04cbd3d2013-12-04 04:58:201876 // If the opener is to be suppressed, the new window can be in any process.
1877 // Since routing ids are process specific, we must not have one passed in
1878 // as argument here.
1879 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1880
[email protected]bafe6cd2012-05-23 23:09:501881 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431882 params.opener_suppressed && !is_guest
1883 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1884 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501885
alexmos4cf2aa32015-07-15 23:40:431886 // A message to create a new window can only come from a process for a frame
1887 // in this WebContents' FrameTree. If any other process sends the request, it
1888 // is invalid and the process must be terminated.
1889 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381890 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431891 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351892 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201893 if (process_handle != base::kNullProcessHandle) {
1894 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391895 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351896 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201897 }
1898 return;
1899 }
1900
[email protected]d1198fd2012-08-13 22:50:191901 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341902 //
1903 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301904 const std::string& partition_id =
1905 GetContentClient()->browser()->
1906 GetStoragePartitionIdForSite(GetBrowserContext(),
1907 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461908 StoragePartition* partition = BrowserContext::GetStoragePartition(
1909 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411910 DOMStorageContextWrapper* dom_storage_context =
1911 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191912 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1913 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1914 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371915
1916 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551917 !delegate_->ShouldCreateWebContents(
1918 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1919 params.window_container_type, params.frame_name, params.target_url,
1920 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011921 if (route_id != MSG_ROUTING_NONE &&
1922 !RenderViewHost::FromID(render_process_id, route_id)) {
1923 // If the embedder didn't create a WebContents for this route, we need to
1924 // delete the RenderView that had already been created.
1925 Send(new ViewMsg_Close(route_id));
1926 }
csharrisona2280cd2016-02-03 23:21:151927 // It's safe to only target the frame because the render process will not
1928 // have a chance to create more frames at this point.
1929 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1930 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371931 return;
1932 }
1933
1934 // Create the new web contents. This will automatically create the new
1935 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461936 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591937 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041938 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551939 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121940 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431941 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211942 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061943 create_params.opener_suppressed = params.opener_suppressed;
1944 if (params.disposition == NEW_BACKGROUND_TAB)
1945 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191946 create_params.renderer_initiated_creation =
1947 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061948
[email protected]4858e432014-06-23 18:14:171949 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551950 if (!is_guest) {
1951 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451952 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171953 new_contents = static_cast<WebContentsImpl*>(
1954 WebContents::Create(create_params));
1955 } else {
1956 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551957 }
[email protected]50d326e2014-05-20 17:59:061958 new_contents->GetController().SetSessionStorageNamespace(
1959 partition_id,
1960 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191961
alexmos646fec02015-07-25 00:11:491962 // If the new frame has a name, make sure any SiteInstances that can find
1963 // this named frame have proxies for it. Must be called after
1964 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1965 // GetSessionStorageNamespace.
1966 if (!params.frame_name.empty())
1967 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1968
[email protected]c4538072013-03-18 02:17:551969 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341970 // will be shown immediately).
1971 if (!params.opener_suppressed) {
1972 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451973 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501974
[email protected]d70bea92013-04-05 04:23:341975 // TODO(brettw): It seems bogus that we have to call this function on the
1976 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431977 new_view->CreateViewForWidget(
1978 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341979 }
[email protected]bafe6cd2012-05-23 23:09:501980 // Save the created window associated with the route so we can show it
1981 // later.
1982 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1983 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101984 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501985 }
1986
1987 if (delegate_) {
1988 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071989 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131990 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501991 }
1992
1993 if (params.opener_suppressed) {
1994 // When the opener is suppressed, the original renderer cannot access the
1995 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001996 bool was_blocked = false;
1997 if (delegate_) {
bokan107a47f2015-02-03 23:23:391998 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001999 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392000 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002001 params.user_gesture, &was_blocked);
2002 }
2003 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:212004 OpenURLParams open_params(params.target_url,
2005 Referrer(),
2006 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352007 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212008 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302009 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372010
2011 if (delegate_ && !is_guest &&
2012 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2013 // We are in asynchronous add new contents path, delay opening url
2014 new_contents->delayed_open_url_params_.reset(
2015 new OpenURLParams(open_params));
2016 } else {
2017 new_contents->OpenURL(open_params);
2018 }
[email protected]eda238a12012-09-07 23:44:002019 }
[email protected]bafe6cd2012-05-23 23:09:502020 }
2021}
2022
avib7348942015-12-25 20:57:102023void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2024 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462025 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052026 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502027}
2028
avib7348942015-12-25 20:57:102029void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2030 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052031 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502032}
2033
avib7348942015-12-25 20:57:102034void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2035 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502036 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462037 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252038 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232039 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512040 // this WebContentsImpl instance. If any other process sends the request,
2041 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382042 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252043 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512044 if (process_handle != base::kNullProcessHandle) {
2045 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392046 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252047 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512048 }
2049 return;
2050 }
2051
[email protected]bafe6cd2012-05-23 23:09:502052 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052053 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262054
[email protected]cfd80b02014-05-01 17:46:482055 RenderWidgetHostViewBase* widget_view =
2056 static_cast<RenderWidgetHostViewBase*>(
2057 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192058 if (!widget_view)
2059 return;
[email protected]bafe6cd2012-05-23 23:09:502060 if (!is_fullscreen) {
2061 // Popups should not get activated.
2062 widget_view->SetPopupType(popup_type);
2063 }
2064 // Save the created widget associated with the route so we can show it later.
2065 pending_widget_views_[route_id] = widget_view;
2066
2067#if defined(OS_MACOSX)
2068 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2069 // to allow it to survive the trip without being hosted.
2070 base::mac::NSObjectRetain(widget_view->GetNativeView());
2071#endif
2072}
2073
2074void WebContentsImpl::ShowCreatedWindow(int route_id,
2075 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392076 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502077 bool user_gesture) {
2078 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002079 if (contents) {
2080 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162081 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382082 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2083 contents->ResumeLoadingCreatedWebContents();
2084
[email protected]eda238a12012-09-07 23:44:002085 if (delegate) {
2086 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392087 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002088 }
2089 }
[email protected]bafe6cd2012-05-23 23:09:502090}
2091
2092void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392093 const gfx::Rect& initial_rect) {
2094 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502095}
2096
2097void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2098 ShowCreatedWidget(route_id, true, gfx::Rect());
2099}
2100
2101void WebContentsImpl::ShowCreatedWidget(int route_id,
2102 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392103 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482104 RenderWidgetHostViewBase* widget_host_view =
2105 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502106 if (!widget_host_view)
2107 return;
[email protected]cfd80b02014-05-01 17:46:482108
2109 RenderWidgetHostView* view = NULL;
2110 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2111 if (guest && guest->embedder_web_contents()) {
2112 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2113 } else {
2114 view = GetRenderWidgetHostView();
2115 }
2116
[email protected]4aebbca2013-09-17 22:26:492117 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312118 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032119 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312120 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492121 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2122 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532123 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492124 } else {
[email protected]cfd80b02014-05-01 17:46:482125 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492126 }
[email protected]4aebbca2013-09-17 22:26:492127 FOR_EACH_OBSERVER(WebContentsObserver,
2128 observers_,
2129 DidShowFullscreenWidget(route_id));
2130 if (!widget_host_view->HasFocus())
2131 widget_host_view->Focus();
2132 } else {
bokan107a47f2015-02-03 23:23:392133 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492134 }
[email protected]89054502012-06-03 10:29:242135
2136 RenderWidgetHostImpl* render_widget_host_impl =
2137 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2138 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312139 // Only allow privileged mouse lock for fullscreen render widget, which is
2140 // used to implement Pepper Flash fullscreen.
2141 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502142
2143#if defined(OS_MACOSX)
2144 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2145 // properly embedded (or purposefully ignored) we can release the retain we
2146 // took in CreateNewWidget().
2147 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2148#endif
2149}
2150
2151WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2152 PendingContents::iterator iter = pending_contents_.find(route_id);
2153
2154 // Certain systems can block the creation of new windows. If we didn't succeed
2155 // in creating one, just return NULL.
2156 if (iter == pending_contents_.end()) {
2157 return NULL;
2158 }
2159
2160 WebContentsImpl* new_contents = iter->second;
2161 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102162 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502163
[email protected]d70bea92013-04-05 04:23:342164 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252165 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342166 return new_contents;
2167
[email protected]bafe6cd2012-05-23 23:09:502168 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432169 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502170 return NULL;
2171
[email protected]bafe6cd2012-05-23 23:09:502172 return new_contents;
2173}
2174
2175RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2176 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2177 if (iter == pending_widget_views_.end()) {
2178 DCHECK(false);
2179 return NULL;
2180 }
2181
2182 RenderWidgetHostView* widget_host_view = iter->second;
2183 pending_widget_views_.erase(route_id);
2184
2185 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2186 if (!widget_host->GetProcess()->HasConnection()) {
2187 // The view has gone away or the renderer crashed. Nothing to do.
2188 return NULL;
2189 }
2190
2191 return widget_host_view;
2192}
2193
[email protected]f13b4202012-06-12 23:53:232194void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092195 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212196 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372197 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232198 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372199 } else {
dcheng59716272016-04-09 05:19:082200 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2201 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372202 }
[email protected]f13b4202012-06-12 23:53:232203}
2204
grunell657d4d82014-09-18 00:09:432205bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2206 MediaStreamType type) {
2207 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2208 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2209 return delegate_ &&
2210 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2211}
2212
[email protected]cc9200432013-07-23 23:02:402213SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2214 SiteInstance* instance) {
2215 return controller_.GetSessionStorageNamespace(instance);
2216}
2217
[email protected]6de7fc482014-06-06 10:46:442218SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2219 return controller_.GetSessionStorageNamespaceMap();
2220}
2221
[email protected]9b159a52013-10-03 17:24:552222FrameTree* WebContentsImpl::GetFrameTree() {
2223 return &frame_tree_;
2224}
2225
lukendc35e7f2014-11-10 19:06:142226void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2227 virtual_keyboard_requested_ = requested;
2228}
2229
2230bool WebContentsImpl::IsVirtualKeyboardRequested() {
2231 return virtual_keyboard_requested_;
2232}
2233
aelias5252baa2016-04-10 01:18:022234bool WebContentsImpl::IsOverridingUserAgent() {
2235 return GetController().GetVisibleEntry() &&
2236 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2237}
2238
[email protected]95640212014-07-26 18:14:302239AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2240 return accessibility_mode_;
2241}
2242
[email protected]31a71eaf2014-03-13 01:47:362243void WebContentsImpl::AccessibilityEventReceived(
2244 const std::vector<AXEventNotificationDetails>& details) {
2245 FOR_EACH_OBSERVER(
2246 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2247}
2248
dmazzonia656928e2014-09-15 20:28:542249RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402250 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542251 int browser_plugin_instance_id) {
2252 BrowserPluginGuestManager* guest_manager =
2253 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202254 if (!guest_manager)
2255 return nullptr;
2256
dmazzonia656928e2014-09-15 20:28:542257 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442258 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542259 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202260 return nullptr;
2261
dmazzonia656928e2014-09-15 20:28:542262 return guest->GetMainFrame();
2263}
2264
blundellc57b93f2014-10-29 13:19:572265GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2266 return geolocation_service_context_.get();
2267}
2268
alogvinovf50445a2015-10-30 13:00:122269WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2270 return wake_lock_service_context_.get();
2271}
2272
[email protected]edc3af82013-12-12 21:24:072273void WebContentsImpl::OnShowValidationMessage(
2274 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292275 const base::string16& main_text,
2276 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072277 if (delegate_)
2278 delegate_->ShowValidationMessage(
2279 this, anchor_in_root_view, main_text, sub_text);
2280}
2281
2282void WebContentsImpl::OnHideValidationMessage() {
2283 if (delegate_)
2284 delegate_->HideValidationMessage(this);
2285}
2286
2287void WebContentsImpl::OnMoveValidationMessage(
2288 const gfx::Rect& anchor_in_root_view) {
2289 if (delegate_)
2290 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2291}
2292
lfgbb9c28a2016-03-01 03:19:492293void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372294 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2295 if (node->current_frame_host()->GetRenderWidgetHost())
2296 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2297 }
lfgbb9c28a2016-03-01 03:19:492298
lfgdb5c4ed2016-03-04 23:09:072299 RenderWidgetHostViewBase* rwhv =
2300 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2301 if (rwhv) {
2302 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2303 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2304 }
2305
[email protected]32deec62013-05-15 23:55:042306 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442307 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042308}
2309
ekaramad2bd4a2f2016-04-06 20:12:462310const TextInputState* WebContentsImpl::GetTextInputState() {
2311 if (GetOuterWebContents())
2312 return GetOuterWebContents()->GetTextInputState();
2313 // A RWHV should update WebContentsImpl in its destruction path so that state
2314 // type is reset to none.
2315 DCHECK(view_with_active_text_input_ ||
2316 text_input_state_->type == ui::TEXT_INPUT_TYPE_NONE);
2317 return text_input_state_.get();
2318}
2319
2320void WebContentsImpl::UpdateTextInputState(RenderWidgetHostViewBase* rwhv,
2321 bool text_input_state_changed) {
2322 // If there is an outer WebContents, let it process this update.
2323 if (GetOuterWebContents()) {
2324 return GetOuterWebContents()->UpdateTextInputState(
2325 rwhv, text_input_state_changed);
2326 }
2327
2328 // If this RWHV has a text input type of NONE, then there is nothing to
2329 // report to the tab RWHV.
2330 if (view_with_active_text_input_.get() != rwhv &&
2331 rwhv->text_input_state()->type == ui::TEXT_INPUT_TYPE_NONE)
2332 return;
2333
2334 if (rwhv->text_input_state()->type != ui::TEXT_INPUT_TYPE_NONE)
2335 view_with_active_text_input_ = rwhv->GetWeakPtr();
2336 else
2337 view_with_active_text_input_.reset();
2338
2339 *text_input_state_ = *rwhv->text_input_state();
2340
2341 // The top level RWHV should know about the change.
2342 RenderWidgetHostViewBase* tab_rwhv =
2343 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2344 if (tab_rwhv)
2345 tab_rwhv->UpdateInputMethodIfNecessary(text_input_state_changed);
2346}
2347
[email protected]95640212014-07-26 18:14:302348BrowserAccessibilityManager*
2349 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452350 RenderFrameHostImpl* rfh = GetMainFrame();
2351 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302352}
2353
2354BrowserAccessibilityManager*
2355 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452356 RenderFrameHostImpl* rfh = GetMainFrame();
2357 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302358}
2359
mohsen7ab1ec16ec2015-07-02 18:26:232360void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2361 RenderFrameHost* focused_frame = GetFocusedFrame();
2362 if (!focused_frame)
2363 return;
2364
2365 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2366 focused_frame->GetRoutingID(), extent));
2367}
2368
2369void WebContentsImpl::SelectRange(const gfx::Point& base,
2370 const gfx::Point& extent) {
2371 RenderFrameHost* focused_frame = GetFocusedFrame();
2372 if (!focused_frame)
2373 return;
2374
2375 focused_frame->Send(
2376 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2377}
2378
aurimasab0319022015-07-10 21:57:382379void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2380 int end_adjust) {
2381 RenderFrameHost* focused_frame = GetFocusedFrame();
2382 if (!focused_frame)
2383 return;
2384
2385 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2386 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492390 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232391 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492392 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332393}
2394
avic3aa8422015-11-09 20:57:222395void WebContentsImpl::ResizeDueToAutoResize(
2396 RenderWidgetHostImpl* render_widget_host,
2397 const gfx::Size& new_size) {
2398 if (render_widget_host != GetRenderViewHost()->GetWidget())
2399 return;
2400
[email protected]61e2b3cc2012-03-02 16:13:342401 if (delegate_)
2402 delegate_->ResizeDueToAutoResize(this, new_size);
2403}
2404
[email protected]b172aee2012-04-10 17:05:262405WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202406 if (!delegate_)
2407 return NULL;
[email protected]00c37fc2011-08-02 00:22:502408
[email protected]e5d549d2011-12-28 01:29:202409 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202410 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342411}
2412
[email protected]6b618e62012-08-16 12:59:182413bool WebContentsImpl::Send(IPC::Message* message) {
2414 if (!GetRenderViewHost()) {
2415 delete message;
2416 return false;
2417 }
2418
2419 return GetRenderViewHost()->Send(message);
2420}
2421
[email protected]a86c0e962013-12-17 17:10:392422void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2423 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392425 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442426}
2427
[email protected]20ca0382013-02-28 19:50:072428void WebContentsImpl::AttachInterstitialPage(
2429 InterstitialPageImpl* interstitial_page) {
2430 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212431 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292432
2433 // Cancel any visible dialogs so that they don't interfere with the
2434 // interstitial.
creis89a0f782015-05-27 16:13:172435 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292436
[email protected]20ca0382013-02-28 19:50:072437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2438 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252439
2440 // Stop the throbber if needed while the interstitial page is shown.
2441 if (frame_tree_.IsLoading())
2442 LoadingStateChanged(true, true, nullptr);
2443}
2444
2445void WebContentsImpl::DidProceedOnInterstitial() {
2446 // The interstitial page should no longer be pausing the throbber.
2447 DCHECK(!(ShowingInterstitialPage() &&
2448 GetRenderManager()->interstitial_page()->pause_throbber()));
2449
2450 // Restart the throbber now that the interstitial page no longer pauses it.
2451 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2452 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072453}
2454
2455void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252456 bool interstitial_pausing_throbber =
2457 ShowingInterstitialPage() &&
2458 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572459 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212460 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2462 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252463
2464 // Restart the throbber if needed now that the interstitial page is going
2465 // away.
2466 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2467 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072468}
2469
avi2b177592014-12-10 02:08:022470void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2471 int history_length) {
2472 SetHistoryOffsetAndLengthForView(
2473 GetRenderViewHost(), history_offset, history_length);
2474}
2475
2476void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2477 RenderViewHost* render_view_host,
2478 int history_offset,
2479 int history_length) {
2480 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2481 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142482}
2483
toyoshim24a4c7ab2016-04-05 09:24:142484void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172485 RenderFrameHost* focused_frame = GetFocusedFrame();
2486 if (!focused_frame)
2487 return;
2488
[email protected]959be4c2014-04-08 15:01:332489 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142490 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332491}
2492
megjablon3f5941072016-02-04 23:27:522493void WebContentsImpl::ReloadLoFiImages() {
2494 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2495}
2496
[email protected]959be4c2014-04-08 15:01:332497void WebContentsImpl::Undo() {
2498 RenderFrameHost* focused_frame = GetFocusedFrame();
2499 if (!focused_frame)
2500 return;
2501
2502 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2503 RecordAction(base::UserMetricsAction("Undo"));
2504}
2505
2506void WebContentsImpl::Redo() {
2507 RenderFrameHost* focused_frame = GetFocusedFrame();
2508 if (!focused_frame)
2509 return;
2510 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2511 RecordAction(base::UserMetricsAction("Redo"));
2512}
2513
2514void WebContentsImpl::Cut() {
2515 RenderFrameHost* focused_frame = GetFocusedFrame();
2516 if (!focused_frame)
2517 return;
2518
2519 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2520 RecordAction(base::UserMetricsAction("Cut"));
2521}
2522
2523void WebContentsImpl::Copy() {
2524 RenderFrameHost* focused_frame = GetFocusedFrame();
2525 if (!focused_frame)
2526 return;
2527
2528 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2529 RecordAction(base::UserMetricsAction("Copy"));
2530}
2531
2532void WebContentsImpl::CopyToFindPboard() {
2533#if defined(OS_MACOSX)
2534 RenderFrameHost* focused_frame = GetFocusedFrame();
2535 if (!focused_frame)
2536 return;
2537
2538 // Windows/Linux don't have the concept of a find pasteboard.
2539 focused_frame->Send(
2540 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2541 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2542#endif
2543}
2544
2545void WebContentsImpl::Paste() {
2546 RenderFrameHost* focused_frame = GetFocusedFrame();
2547 if (!focused_frame)
2548 return;
2549
2550 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2551 RecordAction(base::UserMetricsAction("Paste"));
2552}
2553
2554void WebContentsImpl::PasteAndMatchStyle() {
2555 RenderFrameHost* focused_frame = GetFocusedFrame();
2556 if (!focused_frame)
2557 return;
2558
2559 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2560 focused_frame->GetRoutingID()));
2561 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2562}
2563
2564void WebContentsImpl::Delete() {
2565 RenderFrameHost* focused_frame = GetFocusedFrame();
2566 if (!focused_frame)
2567 return;
2568
2569 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2570 RecordAction(base::UserMetricsAction("DeleteSelection"));
2571}
2572
2573void WebContentsImpl::SelectAll() {
2574 RenderFrameHost* focused_frame = GetFocusedFrame();
2575 if (!focused_frame)
2576 return;
2577
2578 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2579 RecordAction(base::UserMetricsAction("SelectAll"));
2580}
2581
2582void WebContentsImpl::Unselect() {
2583 RenderFrameHost* focused_frame = GetFocusedFrame();
2584 if (!focused_frame)
2585 return;
2586
2587 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2588 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172589}
2590
2591void WebContentsImpl::Replace(const base::string16& word) {
2592 RenderFrameHost* focused_frame = GetFocusedFrame();
2593 if (!focused_frame)
2594 return;
2595
[email protected]959be4c2014-04-08 15:01:332596 focused_frame->Send(new InputMsg_Replace(
2597 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172598}
2599
2600void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2601 RenderFrameHost* focused_frame = GetFocusedFrame();
2602 if (!focused_frame)
2603 return;
2604
[email protected]959be4c2014-04-08 15:01:332605 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2606 focused_frame->GetRoutingID(), word));
2607}
2608
2609void WebContentsImpl::NotifyContextMenuClosed(
2610 const CustomContextMenuContext& context) {
2611 RenderFrameHost* focused_frame = GetFocusedFrame();
2612 if (!focused_frame)
2613 return;
2614
2615 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2616 focused_frame->GetRoutingID(), context));
2617}
2618
2619void WebContentsImpl::ExecuteCustomContextMenuCommand(
2620 int action, const CustomContextMenuContext& context) {
2621 RenderFrameHost* focused_frame = GetFocusedFrame();
2622 if (!focused_frame)
2623 return;
2624
2625 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2626 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002627}
2628
[email protected]fc2b46b2014-05-03 16:33:452629gfx::NativeView WebContentsImpl::GetNativeView() {
2630 return view_->GetNativeView();
2631}
2632
2633gfx::NativeView WebContentsImpl::GetContentNativeView() {
2634 return view_->GetContentNativeView();
2635}
2636
2637gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2638 return view_->GetTopLevelNativeWindow();
2639}
2640
2641gfx::Rect WebContentsImpl::GetViewBounds() {
2642 return view_->GetViewBounds();
2643}
2644
2645gfx::Rect WebContentsImpl::GetContainerBounds() {
2646 gfx::Rect rv;
2647 view_->GetContainerBounds(&rv);
2648 return rv;
2649}
2650
2651DropData* WebContentsImpl::GetDropData() {
2652 return view_->GetDropData();
2653}
2654
2655void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042656 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452657}
2658
2659void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042660 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452661}
2662
2663void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042664 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452665}
2666
2667void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042668 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452669}
2670
[email protected]b172aee2012-04-10 17:05:262671void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272672 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212673 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542674 return;
2675 }
[email protected]0b431992014-06-24 00:08:032676 RenderWidgetHostView* const fullscreen_view =
2677 GetFullscreenRenderWidgetHostView();
2678 if (fullscreen_view) {
2679 fullscreen_view->Focus();
2680 return;
2681 }
creisc014b402015-04-23 16:41:452682 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542683}
2684
[email protected]b172aee2012-04-10 17:05:262685bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212686 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542687}
2688
[email protected]b172aee2012-04-10 17:05:262689InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212690 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222691}
2692
[email protected]b172aee2012-04-10 17:05:262693bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162694 // WebKit creates Document object when MIME type is application/xhtml+xml,
2695 // so we also support this MIME type.
2696 return contents_mime_type_ == "text/html" ||
2697 contents_mime_type_ == "text/xml" ||
2698 contents_mime_type_ == "application/xhtml+xml" ||
2699 contents_mime_type_ == "text/plain" ||
2700 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252701 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162702}
2703
[email protected]b172aee2012-04-10 17:05:262704void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592705 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162706 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552707 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192708 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142709 return;
[email protected]c7dd2f62011-07-18 15:57:592710 }
2711
2712 Stop();
2713
2714 // Create the save package and possibly prompt the user for the name to save
2715 // the page as. The user prompt is an asynchronous operation that runs on
2716 // another thread.
2717 save_package_ = new SavePackage(this);
2718 save_package_->GetSaveInfo();
2719}
2720
2721// Used in automated testing to bypass prompting the user for file names.
2722// Instead, the names and paths are hard coded rather than running them through
2723// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342724bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2725 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212726 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592727 // Stop the page from navigating.
2728 Stop();
2729
2730 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212731 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592732}
2733
[email protected]3c71576ce2013-07-23 02:00:012734void WebContentsImpl::SaveFrame(const GURL& url,
2735 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372736 SaveFrameWithHeaders(url, referrer, std::string());
2737}
2738
2739void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2740 const Referrer& referrer,
2741 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192742 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012743 return;
sammc92af61552014-11-19 23:27:402744 if (delegate_ && delegate_->SaveFrame(url, referrer))
2745 return;
2746
nasko89ad7742015-03-05 22:14:192747 // TODO(nasko): This check for main frame is incorrect and should be fixed
2748 // by explicitly passing in which frame this method should target.
2749 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012750
2751 DownloadManager* dlm =
2752 BrowserContext::GetDownloadManager(GetBrowserContext());
2753 if (!dlm)
2754 return;
avib7348942015-12-25 20:57:102755 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012756 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272757 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012758 if (entry)
2759 post_id = entry->GetPostID();
2760 }
dcheng59716272016-04-09 05:19:082761 std::unique_ptr<DownloadUrlParameters> params(
[email protected]3c71576ce2013-07-23 02:00:012762 DownloadUrlParameters::FromWebContents(this, url));
2763 params->set_referrer(referrer);
2764 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012765 if (post_id >= 0)
2766 params->set_method("POST");
2767 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372768
2769 if (headers.empty()) {
2770 params->set_prefer_cache(true);
2771 } else {
brettw26dab8f02015-08-08 00:28:472772 for (const base::StringPiece& key_value :
2773 base::SplitStringPiece(
2774 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2775 std::vector<std::string> pair = base::SplitString(
2776 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372777 DCHECK_EQ(2ul, pair.size());
2778 params->add_request_header(pair[0], pair[1]);
2779 }
2780 }
dcheng36b6aec92015-12-26 06:16:362781 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012782}
2783
[email protected]b172aee2012-04-10 17:05:262784void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342785 const base::FilePath& file,
avib7348942015-12-25 20:57:102786 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482787 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122788}
2789
[email protected]b172aee2012-04-10 17:05:262790const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272791 return contents_mime_type_;
2792}
2793
[email protected]b172aee2012-04-10 17:05:262794bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272795 return notify_disconnection_;
2796}
2797
[email protected]b172aee2012-04-10 17:05:262798void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312799 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182800 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542804 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182805 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162806}
2807
[email protected]8ff00d72012-10-23 19:12:212808RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272809 return &renderer_preferences_;
2810}
2811
[email protected]e35ccd52012-05-23 16:22:472812void WebContentsImpl::Close() {
2813 Close(GetRenderViewHost());
2814}
2815
[email protected]cf200a562013-05-03 16:24:292816void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462817 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292818 if (browser_plugin_embedder_.get())
2819 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2820 screen_x, screen_y, operation);
2821 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452822 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2823 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292824}
2825
[email protected]d60f3702013-12-26 16:30:242826void WebContentsImpl::DidGetResourceResponseStart(
2827 const ResourceRequestDetails& details) {
2828 controller_.ssl_manager()->DidStartResourceResponse(details);
2829
2830 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2831 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242832}
2833
2834void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462835 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242836 const ResourceRedirectDetails& details) {
2837 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2838
2839 FOR_EACH_OBSERVER(
2840 WebContentsObserver,
2841 observers_,
creis114ca1b2014-11-13 23:51:462842 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242843
2844 // TODO(avi): Remove. http://crbug.com/170921
2845 NotificationService::current()->Notify(
2846 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2847 Source<WebContents>(this),
2848 Details<const ResourceRedirectDetails>(&details));
2849}
2850
calamity7fe55ce2015-04-10 03:59:372851void WebContentsImpl::NotifyWebContentsFocused() {
2852 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2853}
2854
[email protected]b172aee2012-04-10 17:05:262855void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522856 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452857 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292858 if (browser_plugin_embedder_.get())
2859 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342860}
2861
[email protected]e35ccd52012-05-23 16:22:472862void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532863 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2864 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472865}
2866
[email protected]b172aee2012-04-10 17:05:262867void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272868 closed_by_user_gesture_ = value;
2869}
2870
[email protected]b172aee2012-04-10 17:05:262871bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272872 return closed_by_user_gesture_;
2873}
2874
[email protected]b172aee2012-04-10 17:05:262875void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502876 if (!delegate_)
2877 return;
2878
[email protected]6286a372013-10-09 04:03:272879 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2880 if (!entry)
[email protected]1788e772010-12-15 16:40:502881 return;
2882
[email protected]6286a372013-10-09 04:03:272883 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122884}
2885
[email protected]b172aee2012-04-10 17:05:262886void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042887 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272888 if (!delegate_)
2889 return;
2890
[email protected]691aa2f2013-05-28 22:52:042891 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272892}
2893
[email protected]b172aee2012-04-10 17:05:262894int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272895 return minimum_zoom_percent_;
2896}
2897
[email protected]b172aee2012-04-10 17:05:262898int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272899 return maximum_zoom_percent_;
2900}
2901
mcnee432e47d2015-11-09 19:37:462902void WebContentsImpl::SetPageScale(float page_scale_factor) {
2903 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242904}
2905
[email protected]b172aee2012-04-10 17:05:262906gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492907 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232908}
2909
[email protected]b172aee2012-04-10 17:05:262910bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052911 if (GetBrowserPluginGuest())
2912 return GetBrowserPluginGuest()->LockMouse(allowed);
2913
creisc014b402015-04-23 16:41:452914 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432915 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2916 allowed)
creisc014b402015-04-23 16:41:452917 : false;
[email protected]0bfbf882011-12-22 18:19:272918}
2919
[email protected]b172aee2012-04-10 17:05:262920bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212921 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502922}
2923
alexmose201c7cd2015-06-10 17:14:212924WebContentsImpl* WebContentsImpl::GetOpener() const {
2925 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2926 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572927}
2928
[email protected]cb805452013-05-22 15:16:212929void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482930 if (!color_chooser_info_.get())
2931 return;
2932 RenderFrameHost* rfh = RenderFrameHost::FromID(
2933 color_chooser_info_->render_process_id,
2934 color_chooser_info_->render_frame_id);
2935 if (!rfh)
2936 return;
2937
2938 rfh->Send(new FrameMsg_DidChooseColorResponse(
2939 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202940}
2941
[email protected]cb805452013-05-22 15:16:212942void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482943 if (!color_chooser_info_.get())
2944 return;
2945 RenderFrameHost* rfh = RenderFrameHost::FromID(
2946 color_chooser_info_->render_process_id,
2947 color_chooser_info_->render_frame_id);
2948 if (!rfh)
2949 return;
2950
2951 rfh->Send(new FrameMsg_DidEndColorChooser(
2952 rfh->GetRoutingID(), color_chooser_info_->identifier));
2953 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202954}
2955
halton.huoca2eabd2015-07-06 08:17:402956int WebContentsImpl::DownloadImage(
2957 const GURL& url,
2958 bool is_favicon,
2959 uint32_t max_bitmap_size,
2960 bool bypass_cache,
2961 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552962 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402963 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062964 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402965 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552966 const int download_id = ++next_image_download_id;
2967 if (!mojo_image_downloader) {
2968 // If the renderer process is dead (i.e. crash, or memory pressure on
2969 // Android), the downloader service will be invalid. Pre-Mojo, this would
2970 // hang the callback indefinetly since the IPC would be dropped. Now,
2971 // respond with a 400 HTTP error code to indicate that something went wrong.
2972 BrowserThread::PostTask(
2973 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192974 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522975 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2976 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552977 return download_id;
2978 }
2979
halton.huoca2eabd2015-07-06 08:17:402980 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522981 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2982 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2983 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552984 return download_id;
[email protected]795c28972012-12-06 06:13:392985}
2986
[email protected]5dcaf8e2013-12-28 01:31:422987bool WebContentsImpl::IsSubframe() const {
2988 return is_subframe_;
2989}
2990
[email protected]36ec24f2014-01-09 00:32:082991void WebContentsImpl::Find(int request_id,
2992 const base::string16& search_text,
2993 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332994 // Cowardly refuse to search for no text.
2995 if (search_text.empty()) {
2996 NOTREACHED();
2997 return;
2998 }
2999
raymes0fa0be52014-10-13 20:38:093000 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:473001 if (browser_plugin_embedder_ &&
3002 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3003 return;
raymes0fa0be52014-10-13 20:38:093004 }
paulmeyer5d0a5f02016-01-21 20:15:523005 GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(),
3006 request_id, search_text, options));
[email protected]36ec24f2014-01-09 00:32:083007}
3008
3009void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013010 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:473011 if (browser_plugin_embedder_ &&
3012 browser_plugin_embedder_->StopFinding(action)) {
3013 return;
raymes2bc64182015-02-06 01:23:013014 }
paulmeyer5d0a5f02016-01-21 20:15:523015 GetMainFrame()->Send(
3016 new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action));
[email protected]36ec24f2014-01-09 00:32:083017}
3018
[email protected]4fe53add2014-04-08 19:53:363019void WebContentsImpl::InsertCSS(const std::string& css) {
3020 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
3021 GetMainFrame()->GetRoutingID(), css));
3022}
3023
dalecurtisbc6572e12014-09-12 19:22:303024bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:153025 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:303026}
3027
mlamouriefdca9d2014-09-16 16:55:403028void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3029 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3030}
3031
dominickn6919ce32015-10-15 01:52:283032void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
3033 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
3034}
3035
bokanece34a82016-01-28 19:49:463036void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533037 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433038 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463039 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533040}
3041
mariakhomenko44bdc4732015-04-29 01:55:383042void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373043 if (delayed_open_url_params_.get()) {
3044 OpenURL(*delayed_open_url_params_.get());
3045 delayed_open_url_params_.reset(nullptr);
3046 return;
3047 }
3048
mariakhomenko44bdc4732015-04-29 01:55:383049 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3050 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163051 if (is_resume_pending_) {
3052 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133053 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163054 GetMainFrame()->Init();
3055 }
mariakhomenko44bdc4732015-04-29 01:55:383056}
3057
[email protected]b172aee2012-04-10 17:05:263058bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263059 // When the browser is started with about:blank as the startup URL, focus
3060 // the location bar (which will also select its contents) so people can
3061 // simply begin typing to navigate elsewhere.
3062 //
3063 // We need to be careful not to trigger this for anything other than the
3064 // startup navigation. In particular, if we allow an attacker to open a
3065 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3066 // end of the new URL to be scrolled into view instead of the start,
3067 // allowing the attacker to spoof other URLs. The conditions checked here
3068 // are all aimed at ensuring no such attacker-controlled navigation can
3069 // trigger this.
3070 //
3071 // Note that we check the pending entry instead of the visible one; for the
3072 // startup URL case these are the same, but for the attacker-controlled
3073 // navigation case the visible entry is the committed "about:blank" URL and
3074 // the pending entry is the problematic navigation elsewhere.
3075 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3076 if (controller_.IsInitialNavigation() && entry &&
3077 !entry->is_renderer_initiated() &&
3078 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333079 return true;
palmerc70cb1f2016-03-04 23:41:263080 }
[email protected]0c9406632013-02-08 01:13:333081 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273082}
3083
[email protected]b172aee2012-04-10 17:05:263084void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273085 if (delegate_)
3086 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213087}
3088
clamy0e119882015-07-31 16:12:333089void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3090 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3091 DidStartNavigation(navigation_handle));
3092}
3093
3094void WebContentsImpl::DidRedirectNavigation(
3095 NavigationHandle* navigation_handle) {
3096 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3097 DidRedirectNavigation(navigation_handle));
3098}
3099
clamyefca29e2015-09-17 00:22:113100void WebContentsImpl::ReadyToCommitNavigation(
3101 NavigationHandle* navigation_handle) {
3102 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3103 ReadyToCommitNavigation(navigation_handle));
3104}
3105
clamy0e119882015-07-31 16:12:333106void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3107 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3108 DidFinishNavigation(navigation_handle));
3109}
3110
[email protected]52913802013-12-10 05:52:183111void WebContentsImpl::DidStartProvisionalLoad(
3112 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183113 const GURL& validated_url,
3114 bool is_error_page,
3115 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103116 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483117 FOR_EACH_OBSERVER(
3118 WebContentsObserver,
3119 observers_,
3120 DidStartProvisionalLoadForFrame(
3121 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083122
3123 // Notify accessibility if this is a reload.
3124 NavigationEntry* entry = controller_.GetVisibleEntry();
3125 if (entry && ui::PageTransitionCoreTypeIs(
3126 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3127 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3128 BrowserAccessibilityManager* manager =
3129 ftn->current_frame_host()->browser_accessibility_manager();
3130 if (manager)
3131 manager->UserIsReloading();
3132 }
[email protected]400992b2012-06-14 00:03:543133}
3134
[email protected]3109fbb72014-01-06 23:57:153135void WebContentsImpl::DidFailProvisionalLoadWithError(
3136 RenderFrameHostImpl* render_frame_host,
3137 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3138 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313139 FOR_EACH_OBSERVER(WebContentsObserver,
3140 observers_,
3141 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313142 validated_url,
3143 params.error_code,
gsennton6fbb38692015-06-24 19:23:553144 params.error_description,
3145 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083146
3147 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3148 BrowserAccessibilityManager* manager =
3149 ftn->current_frame_host()->browser_accessibility_manager();
3150 if (manager)
3151 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153152}
3153
[email protected]b80624c2014-02-09 02:46:553154void WebContentsImpl::DidFailLoadWithError(
3155 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553156 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553157 int error_code,
gsennton6fbb38692015-06-24 19:23:553158 const base::string16& error_description,
3159 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143160 FOR_EACH_OBSERVER(
3161 WebContentsObserver,
3162 observers_,
gsennton6fbb38692015-06-24 19:23:553163 DidFailLoad(render_frame_host, url, error_code, error_description,
3164 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553165}
3166
[email protected]52913802013-12-10 05:52:183167void WebContentsImpl::NotifyChangedNavigationState(
3168 InvalidateTypes changed_flags) {
3169 NotifyNavigationStateChanged(changed_flags);
3170}
3171
[email protected]3691e5cf2014-01-22 10:16:203172void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203173 const GURL& url,
3174 NavigationController::ReloadType reload_type) {
3175 // Notify observers about navigation.
3176 FOR_EACH_OBSERVER(
3177 WebContentsObserver,
3178 observers_,
3179 DidStartNavigationToPendingEntry(url, reload_type));
3180}
3181
[email protected]8cb834e2014-03-06 14:23:233182void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3183 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503184 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3185 // weak pointer of sorts.
3186 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3187 const int32_t frame_id = render_frame_host->GetRoutingID();
3188
[email protected]65920f332014-03-04 21:14:183189 WebContents* new_contents = OpenURL(params);
3190
dchengb907f7332015-01-07 20:35:503191 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183192 // Notify observers.
3193 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3194 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463195 render_frame_host,
[email protected]65920f332014-03-04 21:14:183196 params.url,
3197 params.referrer,
3198 params.disposition,
creis114ca1b2014-11-13 23:51:463199 params.transition));
[email protected]65920f332014-03-04 21:14:183200 }
3201}
3202
creis29460272015-12-16 04:38:223203bool WebContentsImpl::ShouldTransferNavigation() {
3204 if (!delegate_)
3205 return true;
3206 return delegate_->ShouldTransferNavigation();
3207}
3208
[email protected]aa62afd2014-04-22 19:22:463209bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3210 if (!delegate_)
3211 return false;
3212 return delegate_->ShouldPreserveAbortedURLs(this);
3213}
3214
[email protected]37567b432014-02-12 01:12:223215void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433216 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223217 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353218 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223219 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483220 FOR_EACH_OBSERVER(WebContentsObserver,
3221 observers_,
3222 DidCommitProvisionalLoadForFrame(
3223 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083224
3225 BrowserAccessibilityManager* manager =
3226 render_frame_host->browser_accessibility_manager();
3227 if (manager)
3228 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223229}
3230
[email protected]0d0f4c492014-04-02 06:42:573231void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233232 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573233 // Ensure fullscreen mode is exited before committing the navigation to a
3234 // different page. The next page will not start out assuming it is in
3235 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233236 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193237 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573238 return;
3239 }
avibf58fa0c2015-11-11 01:45:523240 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463241 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523242 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573243}
3244
[email protected]37567b432014-02-12 01:12:223245void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283246 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223247 const LoadCommittedDetails& details,
3248 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3249 if (details.is_navigation_to_different_page()) {
3250 // Clear the status bubble. This is a workaround for a bug where WebKit
3251 // doesn't let us know that the cursor left an element during a
3252 // transition (this is also why the mouse cursor remains as a hand after
3253 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3254 // clear the bubble when a user navigates to a named anchor in the same
3255 // page.
sky8b00392d2015-01-10 00:30:283256 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003257
3258 RenderWidgetHostViewBase* rwhvb =
3259 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3260 if (rwhvb)
3261 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283262
peter90afaba2015-06-01 12:05:293263 did_first_visually_non_empty_paint_ = false;
3264
yusufod41c5f92015-03-06 00:14:283265 // Reset theme color on navigation to new page.
3266 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223267 }
3268
3269 if (!details.is_in_page) {
3270 // Once the main frame is navigated, we're no longer considered to have
3271 // displayed insecure content.
3272 displayed_insecure_content_ = false;
3273 SSLManager::NotifySSLInternalStateChanged(
3274 GetController().GetBrowserContext());
3275 }
3276
3277 // Notify observers about navigation.
3278 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3279 DidNavigateMainFrame(details, params));
3280
[email protected]e85165c642014-06-10 14:34:313281 if (delegate_)
[email protected]37567b432014-02-12 01:12:223282 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313283 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223284}
3285
3286void WebContentsImpl::DidNavigateAnyFramePostCommit(
3287 RenderFrameHostImpl* render_frame_host,
3288 const LoadCommittedDetails& details,
3289 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103290 // Now that something has committed, we don't need to track whether the
3291 // initial page has been accessed.
3292 has_accessed_initial_document_ = false;
3293
[email protected]37567b432014-02-12 01:12:223294 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173295 if (!details.is_in_page)
3296 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223297
avid53461d2016-02-25 17:15:043298 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3299 // again.
3300 if (params.gesture == NavigationGestureUser && dialog_manager_)
3301 dialog_manager_->ResetDialogState(this);
3302
[email protected]37567b432014-02-12 01:12:223303 // Notify observers about navigation.
3304 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093305 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223306}
3307
3308void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3309 contents_mime_type_ = mime_type;
3310}
3311
[email protected]277857a2014-06-03 10:38:013312bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313313 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053314 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313315 return false;
3316
[email protected]37567b432014-02-12 01:12:223317 if (delegate_)
3318 return delegate_->CanOverscrollContent();
3319
3320 return false;
3321}
3322
[email protected]37b64c52014-07-11 21:14:053323void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293324 // Update the theme color. This is to be published to observers after the
3325 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283326 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293327
3328 if (did_first_visually_non_empty_paint_ &&
3329 last_sent_theme_color_ != theme_color_) {
3330 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3331 DidChangeThemeColor(theme_color_));
3332 last_sent_theme_color_ = theme_color_;
3333 }
[email protected]e7104762014-06-20 19:17:253334}
3335
[email protected]b172aee2012-04-10 17:05:263336void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183337 const GURL& url,
[email protected]70435962011-08-02 20:13:283338 const std::string& security_info,
3339 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183340 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403341 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533342 SSLStatus status;
3343 if (!DeserializeSecurityInfo(security_info, &status)) {
3344 bad_message::ReceivedBadMessage(
3345 GetRenderProcessHost(),
3346 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3347 return;
3348 }
[email protected]724159a2010-12-30 01:11:183349
3350 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593351 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213352 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263353 url, status.cert_id, status.cert_status, http_method, mime_type,
3354 resource_type);
[email protected]724159a2010-12-30 01:11:183355
[email protected]b0f724c2013-09-05 04:21:133356 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3357
3358 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3359 DidLoadResourceFromMemoryCache(details));
3360
[email protected]8bfc8272013-09-09 20:10:533361 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3362 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403363 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533364 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3365 GetRenderProcessHost()->GetID()) :
jam608f2992016-03-31 16:35:343366 GetRenderProcessHost()->GetStoragePartition()->
3367 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533368 BrowserThread::PostTask(
3369 BrowserThread::IO,
3370 FROM_HERE,
3371 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3372 }
[email protected]724159a2010-12-30 01:11:183373}
3374
[email protected]b172aee2012-04-10 17:05:263375void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393376 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183377 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193378 SSLManager::NotifySSLInternalStateChanged(
3379 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183380}
3381
estark910b4572015-12-09 20:55:413382void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3383 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583384 LOG(WARNING) << security_origin << " ran insecure content from "
3385 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393386 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413387 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293388 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393389 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183390 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193391 SSLManager::NotifySSLInternalStateChanged(
3392 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183393}
3394
estark910b4572015-12-09 20:55:413395void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3396 const GURL& url,
3397 const std::string& security_info) {
3398 SSLStatus ssl;
3399 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3400 bad_message::ReceivedBadMessage(
3401 GetRenderProcessHost(),
3402 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3403 return;
3404 }
3405
3406 displayed_insecure_content_ = true;
3407 SSLManager::NotifySSLInternalStateChanged(
3408 GetController().GetBrowserContext());
3409}
3410
3411void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3412 const GURL& security_origin,
3413 const GURL& url,
3414 const std::string& security_info) {
3415 SSLStatus ssl;
3416 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3417 bad_message::ReceivedBadMessage(
3418 GetRenderProcessHost(),
3419 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3420 return;
3421 }
3422
3423 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3424 SSLManager::NotifySSLInternalStateChanged(
3425 GetController().GetBrowserContext());
3426}
3427
[email protected]501052ff2014-02-21 22:19:073428void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113429 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473430 return;
naskofbd033392015-01-27 02:34:473431
[email protected]1d62cf72014-02-07 21:31:573432 RenderFrameHostImpl* rfh =
3433 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143434 FOR_EACH_OBSERVER(
3435 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183436}
3437
naskofbd033392015-01-27 02:34:473438void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113439 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123440 return;
[email protected]a1b99262013-12-27 21:56:223441
[email protected]8b3af1e2014-01-24 13:29:123442 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443443 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373444 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423445 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373446
[email protected]61ac9e242014-03-21 20:55:263447 RenderFrameHostImpl* rfh =
3448 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143449 FOR_EACH_OBSERVER(
3450 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313451}
3452
[email protected]b172aee2012-04-10 17:05:263453void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573454 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3455 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263456}
3457
[email protected]b172aee2012-04-10 17:05:263458void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303459 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263460 minimum_zoom_percent_ = minimum_percent;
3461 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263462}
3463
mcnee432e47d2015-11-09 19:37:463464void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3465 bool is_one = page_scale_factor == 1.f;
3466 if (is_one != page_scale_factor_is_one_) {
3467 page_scale_factor_is_one_ = is_one;
3468
3469 HostZoomMapImpl* host_zoom_map =
3470 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3471
3472 if (host_zoom_map && GetRenderProcessHost()) {
3473 host_zoom_map->SetPageScaleFactorIsOneForView(
3474 GetRenderProcessHost()->GetID(), GetRoutingID(),
3475 page_scale_factor_is_one_);
3476 }
3477 }
3478
3479 FOR_EACH_OBSERVER(WebContentsObserver,
3480 observers_,
3481 OnPageScaleFactorChanged(page_scale_factor));
3482}
3483
[email protected]b172aee2012-04-10 17:05:263484void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343485 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433486 if (!delegate_)
3487 return;
3488
[email protected]b9535422012-02-09 01:47:593489 ChildProcessSecurityPolicyImpl* policy =
3490 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223491 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593492 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213493}
3494
[email protected]b172aee2012-04-10 17:05:263495void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3496 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263497 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363498 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433499 if (!delegate_)
3500 return;
3501
[email protected]b9535422012-02-09 01:47:593502 ChildProcessSecurityPolicyImpl* policy =
3503 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323504 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593505 return;
[email protected]8f810632013-06-06 22:33:323506
[email protected]c125e532014-05-10 20:39:063507 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203508}
3509
[email protected]f5273e52014-07-14 16:30:203510void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3511 const GURL& url,
3512 bool user_gesture) {
3513 if (!delegate_)
3514 return;
3515
3516 ChildProcessSecurityPolicyImpl* policy =
3517 ChildProcessSecurityPolicyImpl::GetInstance();
3518 if (policy->IsPseudoScheme(protocol))
3519 return;
3520
3521 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3522}
3523
kouhei40f03cb2015-09-24 07:47:013524void WebContentsImpl::OnUpdatePageImportanceSignals(
3525 const PageImportanceSignals& signals) {
3526 page_importance_signals_ = signals;
3527}
3528
[email protected]b172aee2012-04-10 17:05:263529void WebContentsImpl::OnFindReply(int request_id,
3530 int number_of_matches,
3531 const gfx::Rect& selection_rect,
3532 int active_match_ordinal,
3533 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433534 if (delegate_) {
3535 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3536 active_match_ordinal, final_update);
3537 }
[email protected]b888919c2011-09-02 00:32:163538}
3539
mfomitchev2b8b066a2016-01-28 19:23:153540#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313541void WebContentsImpl::OnFindMatchRectsReply(
3542 int version,
3543 const std::vector<gfx::RectF>& rects,
3544 const gfx::RectF& active_rect) {
3545 if (delegate_)
3546 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3547}
[email protected]583418cc2013-01-17 14:01:103548
[email protected]1ff427972013-02-07 21:14:073549void WebContentsImpl::OnOpenDateTimeDialog(
3550 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173551 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093552 GetRenderViewHost(),
3553 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133554 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093555 value.minimum,
3556 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173557 value.step,
3558 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103559}
[email protected]59363fc92012-09-05 03:46:313560#endif
3561
avi60bd4902015-09-23 20:39:243562void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3563 std::string json = json_string;
3564 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3565 Source<WebContents>(this),
3566 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403567}
3568
[email protected]b172aee2012-04-10 17:05:263569void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3570 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103571 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253572 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103573 AppCacheAccessed(manifest_url, blocked_by_policy));
3574}
3575
[email protected]8bc5ff02013-11-29 06:34:033576void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483577 int color_chooser_id,
3578 SkColor color,
3579 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113580 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003581 return;
nasko907fcb62015-01-28 04:24:113582
[email protected]aa62afd2014-04-22 19:22:463583 ColorChooser* new_color_chooser = delegate_ ?
3584 delegate_->OpenColorChooser(this, color, suggestions) :
3585 NULL;
[email protected]820957a2014-01-14 14:56:303586 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213587 return;
[email protected]8ed16472014-04-11 19:02:483588 if (color_chooser_info_.get())
3589 color_chooser_info_->chooser->End();
3590
3591 color_chooser_info_.reset(new ColorChooserInfo(
3592 render_frame_message_source_->GetProcess()->GetID(),
3593 render_frame_message_source_->GetRoutingID(),
3594 new_color_chooser,
3595 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203596}
3597
[email protected]b172aee2012-04-10 17:05:263598void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483599 if (color_chooser_info_ &&
3600 color_chooser_id == color_chooser_info_->identifier)
3601 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203602}
3603
[email protected]b172aee2012-04-10 17:05:263604void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323605 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483606 if (color_chooser_info_ &&
3607 color_chooser_id == color_chooser_info_->identifier)
3608 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203609}
3610
[email protected]d0759f492012-04-19 22:50:503611// This exists for render views that don't have a WebUI, but do have WebUI
3612// bindings enabled.
3613void WebContentsImpl::OnWebUISend(const GURL& source_url,
3614 const std::string& name,
3615 const base::ListValue& args) {
3616 if (delegate_)
3617 delegate_->WebUISend(this, source_url, name, args);
3618}
3619
thestigc4cac8f2014-09-04 21:17:503620#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003621void WebContentsImpl::OnPepperInstanceCreated() {
3622 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3623}
3624
3625void WebContentsImpl::OnPepperInstanceDeleted() {
3626 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3627}
3628
tommyclie6633ca72014-10-31 00:40:423629void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3630 const base::FilePath& path,
3631 bool is_hung) {
3632 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3633
3634 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3635 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3636}
3637
3638void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3639 base::ProcessId plugin_pid) {
3640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3641 PluginCrashed(plugin_path, plugin_pid));
3642}
3643
[email protected]d8415ad92012-08-23 14:40:503644void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443645 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503646 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343647 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163648 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443649 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163650 return;
[email protected]d8415ad92012-08-23 14:40:503651 }
3652
[email protected]8c8fc292012-11-23 18:57:163653 if (!delegate_->RequestPpapiBrokerPermission(
3654 this, url, plugin_path,
3655 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443656 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163657 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443658 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163659 }
[email protected]d8415ad92012-08-23 14:40:503660}
3661
[email protected]ea0309c2013-08-06 19:35:443662void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503663 bool result) {
[email protected]ea0309c2013-08-06 19:35:443664 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503665}
3666
fsamuel833ee7c2015-02-13 23:40:403667void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3668 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393669 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143670 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403671 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373672}
tommyclie6633ca72014-10-31 00:40:423673#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373674
[email protected]795c28972012-12-06 06:13:393675void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393676 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063677 // We get updated favicon URLs after the page stops loading. If a cross-site
3678 // navigation occurs while a page is still loading, the initial page
3679 // may stop loading and send us updated favicon URLs after the navigation
3680 // for the new page has committed.
3681 RenderViewHostImpl* rvhi =
3682 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3683 if (!rvhi->is_active())
3684 return;
3685
[email protected]795c28972012-12-06 06:13:393686 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293687 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393688}
3689
avayvod41634b12015-07-08 17:07:053690void WebContentsImpl::OnMediaSessionStateChanged() {
3691 MediaSession* session = MediaSession::Get(this);
3692 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3693 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543694 session->IsSuspended(),
3695 session->metadata()));
avayvod41634b12015-07-08 17:07:053696}
3697
3698void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523699 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053700}
3701
3702void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523703 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053704}
3705
mlamouri4c4fbed2015-08-17 15:51:013706void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523707 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013708}
3709
[email protected]50279492014-05-05 23:24:293710void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153711 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293712 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283713
peter90afaba2015-06-01 12:05:293714 did_first_visually_non_empty_paint_ = true;
3715
yusufod41c5f92015-03-06 00:14:283716 if (theme_color_ != last_sent_theme_color_) {
3717 // Theme color should have updated by now if there was one.
3718 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3719 DidChangeThemeColor(theme_color_));
3720 last_sent_theme_color_ = theme_color_;
3721 }
[email protected]9f268072013-11-07 00:02:153722}
[email protected]d9030b82013-07-19 08:26:063723
[email protected]e67ebf32013-02-13 11:07:193724void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013725 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073726 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013727
estark5ea80e52015-06-19 18:43:123728 SecurityStyleExplanations security_style_explanations;
3729 SecurityStyle security_style =
3730 delegate_->GetSecurityStyle(this, &security_style_explanations);
3731 FOR_EACH_OBSERVER(
3732 WebContentsObserver, observers_,
3733 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013734 }
[email protected]e67ebf32013-02-13 11:07:193735}
3736
[email protected]17e286e2013-03-01 23:29:393737void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3738 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3739 BeforeFormRepostWarningShow());
3740}
3741
[email protected]ec6c05f2013-10-23 18:41:573742void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3743 Activate();
3744 if (delegate_)
3745 delegate_->ShowRepostFormWarningDialog(this);
3746}
3747
[email protected]b4c84012014-04-28 19:51:103748bool WebContentsImpl::HasAccessedInitialDocument() {
3749 return has_accessed_initial_document_;
3750}
3751
[email protected]b172aee2012-04-10 17:05:263752void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463753 // If we are creating a RVH for a restored controller, then we need to make
3754 // sure the RenderView starts with a next_page_id_ larger than the number
3755 // of restored entries. This must be called before the RenderView starts
3756 // navigating (to avoid a race between the browser updating max_page_id and
3757 // the renderer updating next_page_id_). Because of this, we only call this
3758 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563759 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583760 if (max_restored_page_id >
3761 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3762 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3763 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323764}
3765
[email protected]b172aee2012-04-10 17:05:263766bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263767 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323768 // For file URLs without a title, use the pathname instead. In the case of a
3769 // synthesized title, we don't want the update to count toward the "one set
3770 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263771 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323772 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513773 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243774 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323775 explicit_set = false; // Don't count synthetic titles toward the set limit.
3776 } else {
[email protected]8af69c6c2014-03-03 19:05:313777 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323778 explicit_set = true;
3779 }
3780
[email protected]987fc3a2011-05-26 14:18:093781 // If a page is created via window.open and never navigated,
3782 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553783 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093784 if (entry) {
[email protected]36fc0392011-12-25 03:59:513785 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093786 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323787
[email protected]36fc0392011-12-25 03:59:513788 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093789 } else {
3790 if (page_title_when_no_navigation_entry_ == final_title)
3791 return false; // Nothing changed, don't bother.
3792
3793 page_title_when_no_navigation_entry_ = final_title;
3794 }
[email protected]420ae012009-04-24 05:16:323795
[email protected]420ae012009-04-24 05:16:323796 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233797 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323798
[email protected]66798902013-10-01 18:40:163799 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533800 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163801
[email protected]420ae012009-04-24 05:16:323802 return true;
3803}
3804
fdegansa696e5112015-04-17 01:57:593805void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003806 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003807 if (delegate_)
fdegansa696e5112015-04-17 01:57:593808 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003809}
3810
3811void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343812 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003813 loading_weak_factory_.InvalidateWeakPtrs();
3814 loading_last_progress_update_ = base::TimeTicks();
3815}
3816
clamy44e84ce2016-02-22 15:38:253817// Notifies the RenderWidgetHost instance about the fact that the page is
3818// loading, or done loading.
3819void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3820 bool due_to_interstitial,
3821 LoadNotificationDetails* details) {
3822 // Do not send notifications about loading changes in the FrameTree while the
3823 // interstitial page is pausing the throbber.
3824 if (ShowingInterstitialPage() &&
3825 GetRenderManager()->interstitial_page()->pause_throbber() &&
3826 !due_to_interstitial) {
3827 return;
3828 }
3829
3830 bool is_loading = IsLoading();
3831
3832 if (!is_loading) {
3833 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3834 base::string16());
3835 load_state_host_.clear();
3836 upload_size_ = 0;
3837 upload_position_ = 0;
3838 }
3839
3840 GetRenderManager()->SetIsLoading(is_loading);
3841
3842 waiting_for_response_ = is_loading;
3843 is_load_to_different_document_ = to_different_document;
3844
3845 if (delegate_)
3846 delegate_->LoadingStateChanged(this, to_different_document);
3847 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3848
3849 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3850 if (is_loading) {
3851 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3852 this, "URL", url, "Main FrameTreeNode id",
3853 GetFrameTree()->root()->frame_tree_node_id());
3854 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3855 } else {
3856 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3857 this, "URL", url);
3858 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3859 }
3860
3861 // TODO(avi): Remove. http://crbug.com/170921
3862 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3863 NotificationDetails det = NotificationService::NoDetails();
3864 if (details)
3865 det = Details<LoadNotificationDetails>(details);
3866 NotificationService::current()->Notify(
3867 type, Source<NavigationController>(&controller_), det);
3868}
3869
[email protected]02d7b6e2014-06-24 21:01:503870void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3871 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323872 // After sending out a swap notification, we need to send a disconnect
3873 // notification so that clients that pick up a pointer to |this| can NULL the
3874 // pointer. See Bug 1230284.
3875 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113876 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283877 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113878
[email protected]7a846df2012-09-20 19:17:393879 // Ensure that the associated embedder gets cleared after a RenderViewHost
3880 // gets swapped, so we don't reuse the same embedder next time a
3881 // RenderViewHost is attached to this WebContents.
3882 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323883}
3884
[email protected]02d7b6e2014-06-24 21:01:503885void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3886 RenderFrameHost* new_host) {
3887 FOR_EACH_OBSERVER(WebContentsObserver,
3888 observers_,
3889 RenderFrameHostChanged(old_host, new_host));
3890}
3891
[email protected]da7a7182013-09-06 08:11:113892// TODO(avi): Remove this entire function because this notification is already
3893// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263894void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323895 if (!notify_disconnection_)
3896 return;
3897
3898 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213899 NotificationService::current()->Notify(
3900 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3901 Source<WebContents>(this),
3902 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323903}
3904
[email protected]cbb1ef592013-06-05 19:49:463905void WebContentsImpl::NotifyNavigationEntryCommitted(
3906 const LoadCommittedDetails& load_details) {
3907 FOR_EACH_OBSERVER(
3908 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3909}
3910
[email protected]f114fa42013-12-06 17:06:443911bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3912 const IPC::Message& message) {
3913 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313914}
3915
[email protected]c31a84802014-04-03 15:55:493916const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3917 return GetLastCommittedURL();
3918}
3919
[email protected]b849847b2013-12-10 21:57:583920void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583921 FOR_EACH_OBSERVER(WebContentsObserver,
3922 observers_,
3923 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303924 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453925
3926 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3927 return;
3928
3929 NavigationEntry* entry = controller_.GetPendingEntry();
3930 if (entry && entry->IsViewSourceMode()) {
3931 // Put the renderer in view source mode.
3932 render_frame_host->Send(
3933 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3934 }
[email protected]b849847b2013-12-10 21:57:583935}
3936
3937void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3938 FOR_EACH_OBSERVER(WebContentsObserver,
3939 observers_,
3940 RenderFrameDeleted(render_frame_host));
3941}
3942
[email protected]a09d53ce2014-01-31 00:46:423943void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3944 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103945 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423946 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103947 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423948 return;
3949
[email protected]077e704b2014-05-23 19:24:103950 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3951 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423952}
3953
[email protected]87de04b02014-04-08 22:14:493954void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013955 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493956 const base::string16& message,
3957 const base::string16& default_prompt,
3958 const GURL& frame_url,
3959 JavaScriptMessageType javascript_message_type,
3960 IPC::Message* reply_msg) {
3961 // Suppress JavaScript dialogs when requested. Also suppress messages when
3962 // showing an interstitial as it's shown over the previous page and we don't
3963 // want the hidden page's dialogs to interfere with the interstitial.
3964 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503965 ShowingInterstitialPage() || !delegate_ ||
3966 delegate_->ShouldSuppressDialogs(this) ||
3967 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493968
3969 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:503970 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493971 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:033972 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:413973 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013974 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413975 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493976 &suppress_this_message);
3977 }
3978
3979 if (suppress_this_message) {
3980 // If we are suppressing messages, just reply as if the user immediately
3981 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013982 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3983 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283984 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493985 }
3986
3987 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3988 // http://crbug.com/288961 ). The only safe thing to do here is return.
3989}
3990
3991void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013992 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493993 bool is_reload,
3994 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013995 RenderFrameHostImpl* rfhi =
3996 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493997 if (delegate_)
3998 delegate_->WillRunBeforeUnloadConfirm();
3999
4000 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454001 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024002 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504003 delegate_->ShouldSuppressDialogs(this) ||
4004 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494005 if (suppress_this_message) {
4006 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4007 return;
4008 }
4009
4010 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504011 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494012 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424013 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494014 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014015 render_frame_host->GetProcess()->GetID(),
4016 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284017 false));
[email protected]87de04b02014-04-08 22:14:494018}
4019
[email protected]a86c0e962013-12-17 17:10:394020WebContents* WebContentsImpl::GetAsWebContents() {
4021 return this;
4022}
4023
[email protected]7912e822014-04-16 02:37:034024bool WebContentsImpl::IsNeverVisible() {
4025 if (!delegate_)
4026 return false;
4027 return delegate_->IsNeverVisible(this);
4028}
4029
[email protected]5a3bdf52012-05-24 15:12:574030RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4031 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324032}
4033
[email protected]8ff00d72012-10-23 19:12:214034RendererPreferences WebContentsImpl::GetRendererPrefs(
4035 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464036 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514037}
4038
avic3aa8422015-11-09 20:57:224039gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
4040 RenderWidgetHostImpl* render_widget_host) const {
4041 if (!RenderViewHostImpl::From(render_widget_host))
4042 return gfx::Rect();
4043
[email protected]b7a756d42012-01-23 18:08:174044 if (delegate_)
4045 return delegate_->GetRootWindowResizerRect();
4046 return gfx::Rect();
4047}
4048
[email protected]7a846df2012-09-20 19:17:394049void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274050 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394051 browser_plugin_embedder_.reset();
4052}
4053
[email protected]b172aee2012-04-10 17:05:264054void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444055 // Don't send notifications if we are just creating a swapped-out RVH for
4056 // the opener chain. These won't be used for view-source or WebUI, so it's
4057 // ok to return early.
creiscce56cd2014-09-29 22:45:224058 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444059 return;
4060
[email protected]86f98a22013-03-20 14:35:004061 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314062 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084063
[email protected]8ff00d72012-10-23 19:12:214064 NotificationService::current()->Notify(
4065 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4066 Source<WebContents>(this),
4067 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324068
[email protected]60780f412013-02-25 16:34:104069 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264070
4071 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254072 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324073}
4074
[email protected]b172aee2012-04-10 17:05:264075void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524076 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324077 // Don't notify the world, since this came from a renderer in the
4078 // background.
4079 return;
4080 }
4081
[email protected]da7a7182013-09-06 08:11:114082 notify_disconnection_ = true;
4083 // TODO(avi): Remove. http://crbug.com/170921
4084 NotificationService::current()->Notify(
4085 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4086 Source<WebContents>(this),
4087 NotificationService::NoDetails());
4088
[email protected]be1f56ab2011-12-22 06:55:314089 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234090 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304091
4092 // Restore the focus to the tab (otherwise the focus will be on the top
4093 // window).
[email protected]484ae5912010-09-29 19:16:144094 if (was_crashed && !FocusLocationBarByDefault() &&
4095 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064096 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144097 }
[email protected]32ded2212011-11-10 18:51:434098
[email protected]d8c660432011-12-22 20:51:254099 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324100}
4101
[email protected]ec6a7eb2013-04-22 17:34:224102void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4103 base::TerminationStatus status,
4104 int error_code) {
[email protected]151a63d2011-12-20 22:32:524105 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324106 // The pending page's RenderViewHost is gone.
4107 return;
4108 }
4109
[email protected]2fcdcc32014-03-05 02:14:074110 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4111 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524112 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464113 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074114
[email protected]698191dc2014-02-25 01:06:134115 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174116 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134117
[email protected]f738bdcb2014-07-11 20:40:444118 if (delegate_)
4119 delegate_->HideValidationMessage(this);
4120
[email protected]960b0372014-05-19 18:01:004121 // Reset the loading progress. TODO(avi): What does it mean to have a
4122 // "renderer crash" when there is more than one renderer process serving a
4123 // webpage? Once this function is called at a more granular frame level, we
4124 // probably will need to more granularly reset the state here.
4125 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254126 NotifyDisconnected();
4127 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004128
[email protected]d8c660432011-12-22 20:51:254129 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274130 observers_,
[email protected]58d5cfe2013-07-10 02:40:524131 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324132}
4133
[email protected]b172aee2012-04-10 17:05:264134void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254135 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064136}
4137
[email protected]b172aee2012-04-10 17:05:264138void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104139 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044140 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384141 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4142
creise1d3e5b2014-12-01 18:21:574143 // Ensure that this state update comes from a RenderViewHost that belongs to
4144 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414145 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574146 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414147 return;
[email protected]420ae012009-04-24 05:16:324148
avi286019ce2015-07-29 01:26:584149 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324150 // when the user is scrolling and entering form data, as well as when we're
4151 // leaving a page, in which case our state may have already been moved to
4152 // the next page. The navigation controller will look up the appropriate
4153 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584154 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114155 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584156 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114157 if (!entry)
[email protected]420ae012009-04-24 05:16:324158 return;
[email protected]420ae012009-04-24 05:16:324159
nasko346969912015-12-16 22:36:474160 // Sanity check that ensures nav_entry_id and page_id point to the same
4161 // navigation entry.
4162 if (rvhi->GetMainFrame()) {
4163 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4164 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4165 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534166
nasko346969912015-12-16 22:36:474167 DCHECK_EQ(entry, new_entry);
4168 }
creisd63f6c4a2015-11-06 19:05:534169
[email protected]691aa2f2013-05-28 22:52:044170 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324171 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044172 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114173 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324174}
4175
sky8b00392d2015-01-10 00:30:284176void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4177 const GURL& url) {
4178 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4179 // If we're fullscreen only update the url if it's from the fullscreen
4180 // renderer.
4181 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444182 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284183 return;
4184 }
[email protected]6934a702011-12-20 00:04:514185 if (delegate_)
avi450ce00e2014-09-24 01:58:524186 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324187}
4188
[email protected]b172aee2012-04-10 17:05:264189void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104190#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294191 // The UI may be in an event-tracking loop, such as between the
4192 // mouse-down and mouse-up in text selection or a button click.
4193 // Defer the close until after tracking is complete, so that we
4194 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294195 // TODO(shess): This could get more fine-grained. For instance,
4196 // closing a tab in another window while selecting text in the
4197 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104198 if (view_->IsEventTracking()) {
4199 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294200 return;
4201 }
[email protected]60780f412013-02-25 16:34:104202#endif
[email protected]07707302009-11-06 00:50:294203
[email protected]420ae012009-04-24 05:16:324204 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524205 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514206 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324207}
4208
[email protected]66bbadaf2014-03-28 16:25:544209void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574210 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4211 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574212}
4213
[email protected]b172aee2012-04-10 17:05:264214void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514215 if (delegate_ && delegate_->IsPopupOrPanel(this))
4216 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324217}
4218
fdegansa696e5112015-04-17 01:57:594219void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094220 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254221 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084222
4223 // Notify accessibility that the user is navigating away from the
4224 // current document.
4225 //
4226 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084227 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594228 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084229 if (manager)
4230 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324231}
4232
fdegansc73eec22015-03-19 14:47:544233void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084234 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324235
[email protected]9595fd82013-04-19 21:28:494236 // Use the last committed entry rather than the active one, in case a
4237 // pending entry has been created.
4238 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204239 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494240
[email protected]420ae012009-04-24 05:16:324241 // An entry may not exist for a stop when loading an initial blank page or
4242 // if an iframe injected by script into a blank page finishes loading.
4243 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204244 base::TimeDelta elapsed =
4245 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324246
4247 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514248 entry->GetVirtualURL(),
4249 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324250 elapsed,
4251 &controller_,
4252 controller_.GetCurrentEntryIndex()));
4253 }
4254
clamy44e84ce2016-02-22 15:38:254255 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324256}
4257
fdegansa696e5112015-04-17 01:57:594258void WebContentsImpl::DidChangeLoadProgress() {
4259 double load_progress = frame_tree_.load_progress();
4260
4261 // The delegate is notified immediately for the first and last updates. Also,
4262 // since the message loop may be pretty busy when a page is loaded, it might
4263 // not execute a posted task in a timely manner so the progress report is sent
4264 // immediately if enough time has passed.
4265 base::TimeDelta min_delay =
4266 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4267 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4268 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4269
4270 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4271 // If there is a pending task to send progress, it is now obsolete.
4272 loading_weak_factory_.InvalidateWeakPtrs();
4273
4274 // Notify the load progress change.
4275 SendChangeLoadProgress();
4276
4277 // Clean-up the states if needed.
4278 if (load_progress == 1.0)
4279 ResetLoadProgressState();
4280 return;
4281 }
4282
4283 if (loading_weak_factory_.HasWeakPtrs())
4284 return;
4285
skyostil95082a62015-06-05 19:53:074286 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4287 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4288 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594289 min_delay);
4290}
4291
[email protected]b172aee2012-04-10 17:05:264292void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164293 controller_.DiscardNonCommittedEntries();
4294
4295 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214296 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164297}
4298
[email protected]59167c22013-06-03 18:07:324299void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104300 has_accessed_initial_document_ = true;
4301
[email protected]d1371bf8e2014-04-19 03:26:244302 // We may have left a failed browser-initiated navigation in the address bar
4303 // to let the user edit it and try again. Clear it now that content might
4304 // show up underneath it.
4305 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454306 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244307
[email protected]59167c22013-06-03 18:07:324308 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504309 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324310}
4311
alexmosbe2f4c32015-03-10 02:30:234312void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4313 const std::string& name) {
4314 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4315 FrameNameChanged(render_frame_host, name));
4316}
4317
[email protected]39f2f9252014-05-03 00:54:014318void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294319 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294321 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094322
4323 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214324 NotificationService::current()->Notify(
4325 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4326 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294327 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084328}
4329
creis8eb8ef22015-11-04 22:51:384330void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4331 const PageState& page_state) {
4332 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4333
4334 // The state update affects the last NavigationEntry associated with the given
4335 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4336 // in the case of an UpdateState from a frame being swapped out). We track
4337 // which entry this is in the RenderFrameHost's nav_entry_id.
4338 RenderFrameHostImpl* rfhi =
4339 static_cast<RenderFrameHostImpl*>(render_frame_host);
4340 NavigationEntryImpl* entry =
4341 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4342 if (!entry)
4343 return;
4344
4345 FrameNavigationEntry* frame_entry =
4346 entry->GetFrameEntry(rfhi->frame_tree_node());
4347 if (!frame_entry)
4348 return;
4349
creisd06a9422015-11-11 03:08:454350 // The SiteInstance might not match if we do a cross-process navigation with
4351 // replacement (e.g., auto-subframe), in which case the swap out of the old
4352 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4353 // has already been replaced and destroyed.
4354 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4355 return;
4356
creis8eb8ef22015-11-04 22:51:384357 if (page_state == frame_entry->page_state())
4358 return; // Nothing to update.
4359
4360 frame_entry->set_page_state(page_state);
4361 controller_.NotifyEntryChanged(entry);
4362}
4363
[email protected]ef3adfc2014-05-11 00:04:544364void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104365 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544366 const base::string16& title,
4367 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544368 // If we have a title, that's a pretty good indication that we've started
4369 // getting useful data.
4370 SetNotWaitingForResponse();
4371
4372 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584373 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544374 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584375 render_frame_host->GetSiteInstance(), page_id);
4376
creis081bc102016-02-26 00:56:274377 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4378 // and intentionally skip updates when the most recent commit was ignored.
4379 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544380
4381 // We can handle title updates when we don't have an entry in
4382 // UpdateTitleForEntry, but only if the update is from the current RVH.
4383 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584384 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544385 return;
4386
4387 // TODO(evan): make use of title_direction.
4388 // http://code.google.com/p/chromium/issues/detail?id=27094
4389 if (!UpdateTitleForEntry(entry, title))
4390 return;
4391
4392 // Broadcast notifications when the UI should be updated.
4393 if (entry == controller_.GetEntryAtOffset(0))
4394 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4395}
4396
4397void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4398 const std::string& encoding) {
4399 SetEncoding(encoding);
4400}
4401
[email protected]39f2f9252014-05-03 00:54:014402void WebContentsImpl::DocumentAvailableInMainFrame(
4403 RenderViewHost* render_view_host) {
4404 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4405 DocumentAvailableInMainFrame());
4406}
naskoc0fceff2015-04-30 15:53:524407
[email protected]e1c3a552012-05-04 20:51:324408void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4409 // Tell the active RenderViewHost to run unload handlers and close, as long
4410 // as the request came from a RenderViewHost in the same BrowsingInstance.
4411 // In most cases, we receive this from a swapped out RenderViewHost.
4412 // It is possible to receive it from one that has just been swapped in,
4413 // in which case we might as well deliver the message anyway.
4414 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524415 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324416}
4417
alexmose7da5a12015-04-09 02:22:164418bool WebContentsImpl::ShouldRouteMessageEvent(
4419 RenderFrameHost* target_rfh,
4420 SiteInstance* source_site_instance) const {
4421 // Allow the message if this WebContents is dedicated to a browser plugin
4422 // guest.
[email protected]0eba810b2012-10-18 03:19:364423 // Note: This check means that an embedder could theoretically receive a
4424 // postMessage from anyone (not just its own guests). However, this is
4425 // probably not a risk for apps since other pages won't have references
4426 // to App windows.
alexmose7da5a12015-04-09 02:22:164427 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4428}
[email protected]f546640b2012-05-15 00:03:494429
alexmos58729042015-06-18 23:20:004430void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164431 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4432 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494433
alexmose7da5a12015-04-09 02:22:164434 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144435 // If this message is going to outer WebContents from inner WebContents,
4436 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4437 // already created a RenderFrameProxyHost for that purpose.
4438 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084439 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144440 return;
4441 }
4442
lfg812874d2016-02-09 22:26:134443 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064444 // We create a RenderFrameProxyHost for the embedder in the guest's render
4445 // process but we intentionally do not expose the embedder's opener chain
4446 // to it.
4447 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4448 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494449 } else {
alexmos58729042015-06-18 23:20:004450 RenderFrameHostImpl* source_rfhi =
4451 static_cast<RenderFrameHostImpl*>(source_rfh);
4452 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394453 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494454 }
4455 }
[email protected]f546640b2012-05-15 00:03:494456}
4457
avib7348942015-12-25 20:57:104458bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264459 const base::string16& message,
avib7348942015-12-25 20:57:104460 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264461 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254462 if (!delegate_)
4463 return false;
4464 return delegate_->AddMessageToConsole(this, level, message, line_no,
4465 source_id);
4466}
4467
dominickn9c7ceaa32016-02-27 01:52:534468void WebContentsImpl::OnUserInteraction(
4469 RenderWidgetHostImpl* render_widget_host,
4470 const blink::WebInputEvent::Type type) {
4471 // Ignore when the renderer is swapped out.
4472 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224473 if (render_widget_host != GetRenderViewHost()->GetWidget())
4474 return;
4475
dominickn2dd142dd2015-10-29 05:30:504476 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4477 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534478
4479 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4480 // Exclude scroll events as user gestures for resource load dispatches.
4481 // rdh is NULL in unittests.
4482 if (rdh && type != blink::WebInputEvent::MouseWheel)
4483 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504484}
4485
[email protected]b172aee2012-04-10 17:05:264486void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444487 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254488 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444489}
4490
avic3aa8422015-11-09 20:57:224491void WebContentsImpl::RendererUnresponsive(
4492 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474493 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4494 OnRendererUnresponsive(render_widget_host));
4495
[email protected]992db4c2011-05-12 15:37:154496 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224497 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154498 return;
4499
creiscce56cd2014-09-29 22:45:224500 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224501 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584502
[email protected]e5fc1632011-08-08 07:51:534503 // Ignore renderer unresponsive event if debugger is attached to the tab
4504 // since the event may be a result of the renderer sitting on a breakpoint.
4505 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364506 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534507 return;
4508
clamy226727e2015-06-29 10:28:474509 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224510 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324511 // Hang occurred while firing the beforeunload/unload handler.
4512 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224513 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324514
[email protected]fa944cb82013-11-15 17:51:214515 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324516 return;
4517
4518 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564519 // nothing we can do to recover. If the hang is in the beforeunload handler,
4520 // pretend the beforeunload listeners have all fired and allow the delegate
4521 // to continue closing; the user will not have the option of cancelling the
4522 // close. Otherwise, pretend the unload listeners have all fired and close
4523 // the tab.
4524 bool close = true;
clamy226727e2015-06-29 10:28:474525 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564526 delegate_->BeforeUnloadFired(this, true, &close);
4527 }
4528 if (close)
avic3aa8422015-11-09 20:57:224529 Close();
[email protected]420ae012009-04-24 05:16:324530 return;
4531 }
4532
creisc014b402015-04-23 16:41:454533 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474534 return;
4535
[email protected]6934a702011-12-20 00:04:514536 if (delegate_)
4537 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324538}
4539
avic3aa8422015-11-09 20:57:224540void WebContentsImpl::RendererResponsive(
4541 RenderWidgetHostImpl* render_widget_host) {
4542 if (render_widget_host != GetRenderViewHost()->GetWidget())
4543 return;
4544
[email protected]6934a702011-12-20 00:04:514545 if (delegate_)
4546 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324547}
4548
[email protected]b172aee2012-04-10 17:05:264549void WebContentsImpl::LoadStateChanged(
4550 const GURL& url,
4551 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104552 uint64_t upload_position,
4553 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544554 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4555 // is fixed.
4556 tracked_objects::ScopedTracker tracking_profile1(
4557 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4558 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324559 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564560 upload_position_ = upload_position;
4561 upload_size_ = upload_size;
jshin1fb76462016-04-05 22:13:034562 load_state_host_ = url_formatter::IDNToUnicode(url.host());
[email protected]9c235f042011-08-10 22:28:214563 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324564 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464565 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224566 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4567 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464568 }
[email protected]420ae012009-04-24 05:16:324569}
4570
[email protected]b172aee2012-04-10 17:05:264571void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554572 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324573 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124574 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4575 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514576 if (delegate_)
4577 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094578 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324579}
4580
[email protected]58d5cfe2013-07-10 02:40:524581void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544582 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234583 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224584 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544585}
4586
[email protected]b172aee2012-04-10 17:05:264587void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104588 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214589 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264590 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4591 // here during container initialization and normal window size will be set
4592 // later. In case of tab duplication this resizing to 0x0 prevents setting
4593 // normal size later so just ignore it.
4594 if (!size.IsEmpty())
4595 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324596}
4597
[email protected]af905902013-10-01 21:38:514598void WebContentsImpl::CancelModalDialogsForRenderManager() {
4599 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544600 // deferrer would prevent us from swapping out. We also clear the state
4601 // because this is a cross-process navigation, which means that it's a new
4602 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174603 //
4604 // Note that we don't bother telling browser_plugin_embedder_ because the
4605 // cross-process navigation will either destroy the browser plugins or not
4606 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514607 if (dialog_manager_)
avi2460c762015-04-17 15:21:544608 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514609}
4610
[email protected]02d7b6e2014-06-24 21:01:504611void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4612 RenderFrameHost* new_host,
4613 bool is_main_frame) {
4614 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054615 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504616 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084617
[email protected]02d7b6e2014-06-24 21:01:504618 // Make sure the visible RVH reflects the new delegate's preferences.
4619 if (delegate_)
4620 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394621
[email protected]02d7b6e2014-06-24 21:01:504622 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4623 }
4624
4625 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544626}
4627
naskof5940b9f2015-03-02 23:04:054628void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4629 RenderViewHost* old_host,
4630 RenderViewHost* new_host) {
4631 NotifyViewSwapped(old_host, new_host);
4632}
4633
[email protected]b172aee2012-04-10 17:05:264634NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194635 return GetController();
[email protected]3a3d47472010-07-15 21:03:544636}
4637
dcheng59716272016-04-09 05:19:084638std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294639 const GURL& url) {
dcheng59716272016-04-09 05:19:084640 return std::unique_ptr<WebUIImpl>(
4641 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324642}
4643
[email protected]10f417c52011-12-28 21:04:234644NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264645 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324646 return controller_.GetLastCommittedEntry();
4647}
4648
lfgbede6392015-09-11 21:54:064649void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4650 RenderViewHost* render_view_host) {
4651 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144652 bool is_guest_in_site_per_process =
4653 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084654 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064655 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164656 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444657 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164658 rwh_view = rwh_view_child;
4659 } else {
avif9ab5d942015-10-15 14:05:444660 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164661 }
[email protected]1a98a932009-11-17 00:12:524662
[email protected]420ae012009-04-24 05:16:324663 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444664 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214665 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064666}
4667
4668bool WebContentsImpl::CreateRenderViewForRenderManager(
4669 RenderViewHost* render_view_host,
4670 int opener_frame_routing_id,
4671 int proxy_routing_id,
4672 const FrameReplicationState& replicated_frame_state) {
4673 TRACE_EVENT0("browser,navigation",
4674 "WebContentsImpl::CreateRenderViewForRenderManager");
4675
4676 if (proxy_routing_id == MSG_ROUTING_NONE)
4677 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324678
[email protected]74ce1ad2011-12-16 21:51:464679 // Make sure we use the correct starting page_id in the new RenderView.
4680 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104681 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584682 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464683
alexmos5ac402d2015-07-09 07:51:104684 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4685 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4686 max_page_id, replicated_frame_state,
4687 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524688 return false;
[email protected]14392a52012-05-02 20:28:444689 }
[email protected]a4127722011-04-27 23:13:524690
avi2b177592014-12-10 02:08:024691 SetHistoryOffsetAndLengthForView(render_view_host,
4692 controller_.GetLastCommittedEntryIndex(),
4693 controller_.GetEntryCount());
4694
[email protected]a220b5932013-09-21 03:47:444695#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504696 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4697 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444698 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444699 if (rwh_view) {
4700 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4701 render_widget_host->WasResized();
4702 }
[email protected]f8233cc2011-05-31 20:24:504703#endif
4704
[email protected]420ae012009-04-24 05:16:324705 return true;
4706}
4707
[email protected]82307f6b2014-08-07 03:30:124708bool WebContentsImpl::CreateRenderFrameForRenderManager(
4709 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044710 int proxy_routing_id,
4711 int opener_routing_id,
japhete6adf142014-10-31 00:01:494712 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044713 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434714 TRACE_EVENT0("browser,navigation",
4715 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124716
4717 RenderFrameHostImpl* rfh =
4718 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044719 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4720 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124721 return false;
4722
4723 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4724 // RenderFrameHost will have to be associated with the appropriate
4725 // RenderWidgetHostView or a new one should be created here.
4726
4727 return true;
4728}
4729
mfomitchev2b8b066a2016-01-28 19:23:154730#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454731
[email protected]155c7f22013-12-09 17:07:184732base::android::ScopedJavaLocalRef<jobject>
4733WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404734 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564735 return GetWebContentsAndroid()->GetJavaObject();
4736}
[email protected]155c7f22013-12-09 17:07:184737
[email protected]0e813a52014-08-13 10:34:564738WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184739 WebContentsAndroid* web_contents_android =
4740 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4741 if (!web_contents_android) {
4742 web_contents_android = new WebContentsAndroid(this);
4743 SetUserData(kWebContentsAndroidKey, web_contents_android);
4744 }
[email protected]0e813a52014-08-13 10:34:564745 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184746}
4747
[email protected]7d244f12013-08-22 21:41:514748bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064749 return CreateRenderViewForRenderManager(
4750 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064751 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514752}
[email protected]fc2b46b2014-05-03 16:33:454753
4754#elif defined(OS_MACOSX)
4755
[email protected]75f4df72014-07-16 22:39:424756void WebContentsImpl::SetAllowOtherViews(bool allow) {
4757 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454758}
4759
[email protected]75f4df72014-07-16 22:39:424760bool WebContentsImpl::GetAllowOtherViews() {
4761 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454762}
4763
[email protected]7d244f12013-08-22 21:41:514764#endif
4765
pkotwicz75ca8ffd2016-02-16 23:10:194766void WebContentsImpl::OnDidDownloadImage(
4767 const ImageDownloadCallback& callback,
4768 int id,
4769 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524770 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044771 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524772 mojo::Array<mojo::SizePtr> original_image_sizes) {
4773 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4774 const std::vector<gfx::Size> sizes =
4775 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194776
leon.hancbc4bc3c2016-02-26 07:08:524777 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194778}
4779
[email protected]6fba26d2014-04-29 09:38:284780void WebContentsImpl::OnDialogClosed(int render_process_id,
4781 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264782 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494783 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264784 bool success,
[email protected]fcf75d42013-12-03 20:11:264785 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284786 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4787 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494788 last_dialog_suppressed_ = dialog_was_suppressed;
4789
[email protected]beb440c2009-11-06 04:08:544790 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:234791 // It is possible for the current RenderFrameHost to have changed in the
4792 // meantime. Do not reset the navigation state in that case.
4793 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:254794 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:234795 controller_.DiscardNonCommittedEntries();
4796 }
[email protected]ec8e8b02013-06-19 04:57:104797
[email protected]6d65a462013-06-21 21:29:124798 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4799 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544800 }
[email protected]87de04b02014-04-08 22:14:494801
[email protected]beb440c2009-11-06 04:08:544802 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284803 if (rfh) {
4804 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4805 dialog_was_suppressed);
4806 } else {
4807 // Don't leak the sync IPC reply if the RFH or process is gone.
4808 delete reply_msg;
4809 }
[email protected]beb440c2009-11-06 04:08:544810}
4811
[email protected]b172aee2012-04-10 17:05:264812void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544813 if (encoding == last_reported_encoding_)
4814 return;
4815 last_reported_encoding_ = encoding;
4816
4817 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124818 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104819}
[email protected]f45d2a72010-03-08 23:28:354820
[email protected]1ac10dca2013-08-20 20:47:044821bool WebContentsImpl::IsHidden() {
4822 return capturer_count_ == 0 && !should_normally_be_visible_;
4823}
4824
rob97250742015-12-10 17:45:154825int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144826 if (node_ && node_->outer_web_contents())
4827 return node_->outer_contents_frame_tree_node_id();
4828
nick2482a2d2015-12-18 01:39:374829 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144830}
4831
[email protected]b0936d22013-11-28 06:47:364832RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214833 return frame_tree_.root()->render_manager();
4834}
4835
lazyboy8e16ddfd2015-09-28 03:41:564836WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4837 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4838 if (node_)
4839 return node_->outer_web_contents();
4840 } else {
4841 if (GetBrowserPluginGuest())
4842 return GetBrowserPluginGuest()->embedder_web_contents();
4843 }
4844 return nullptr;
4845}
4846
[email protected]f8497342013-02-05 22:15:024847BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394848 return browser_plugin_guest_.get();
4849}
4850
[email protected]738f57a2013-06-29 21:06:544851void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4852 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144853 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544854 browser_plugin_guest_.reset(guest);
4855}
4856
[email protected]f8497342013-02-05 22:15:024857BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394858 return browser_plugin_embedder_.get();
4859}
[email protected]8ff00d72012-10-23 19:12:214860
fsamuel60b42282015-03-10 03:29:144861void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4862 if (browser_plugin_embedder_)
4863 return;
4864 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4865}
4866
[email protected]fc2b46b2014-05-03 16:33:454867gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214868 gfx::Size size;
4869 if (delegate_)
4870 size = delegate_->GetSizeForNewRenderView(this);
4871 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454872 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214873 return size;
4874}
4875
[email protected]ae7eeda2014-07-04 01:53:264876void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4877 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024878 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554879}
4880
[email protected]222f5822014-02-05 23:40:494881void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4882 if (!delegate_)
4883 return;
4884 const gfx::Size new_size = GetPreferredSize();
4885 if (new_size != old_size)
4886 delegate_->UpdatePreferredSize(this, new_size);
4887}
4888
dbeama1b926a2015-08-31 23:17:514889WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4890 const std::string& frame_name) {
4891 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4892 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4893 CreateWebUIControllerForURL(web_ui, url);
4894 if (controller) {
4895 web_ui->AddMessageHandler(new GenericHandler());
4896 web_ui->SetController(controller);
4897 return web_ui;
4898 }
4899
4900 delete web_ui;
4901 return NULL;
4902}
4903
[email protected]34ff1cfc2014-08-20 06:16:054904void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4905 force_disable_overscroll_content_ = force_disable;
4906 if (view_)
4907 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4908}
4909
dalecurtis88c240072015-12-09 02:11:184910void WebContentsImpl::MediaStartedPlaying(
4911 const WebContentsObserver::MediaPlayerId& id) {
4912 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4913}
4914
4915void WebContentsImpl::MediaStoppedPlaying(
4916 const WebContentsObserver::MediaPlayerId& id) {
4917 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4918}
4919
tapted65ff2ea72016-03-01 23:39:004920void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4921 if (!did_first_set_visible_) {
4922 // If this WebContents has not yet been set to be visible for the first
4923 // time, ignore any requests to make it hidden, since resources would
4924 // immediately be destroyed and only re-created after content loaded. In
4925 // this state the window content is undefined and can show garbage.
4926 // However, the page load mechanism requires an activation call through a
4927 // visibility call to (re)load.
4928 if (visible) {
4929 did_first_set_visible_ = true;
4930 WasShown();
4931 }
4932 return;
4933 }
4934 if (visible == should_normally_be_visible_)
4935 return;
4936
4937 if (visible)
4938 WasShown();
4939 else
4940 WasHidden();
4941}
4942
aelias5252baa2016-04-10 01:18:024943void WebContentsImpl::UpdateOverridingUserAgent() {
4944 std::set<RenderViewHost*> render_view_host_set;
4945 for (FrameTreeNode* node : frame_tree_.Nodes()) {
4946 RenderWidgetHost* render_widget_host =
4947 node->current_frame_host()->GetRenderWidgetHost();
4948 if (!render_widget_host)
4949 continue;
4950 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
4951 if (!render_view_host)
4952 continue;
4953 render_view_host_set.insert(render_view_host);
4954 }
4955 for (RenderViewHost* render_view_host : render_view_host_set)
4956 render_view_host->OnWebkitPreferencesChanged();
4957}
4958
avid53461d2016-02-25 17:15:044959void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
4960 JavaScriptDialogManager* dialog_manager) {
4961 dialog_manager_ = dialog_manager;
4962}
4963
[email protected]8ff00d72012-10-23 19:12:214964} // namespace content