blob: d7b45b73ae2f5482699c71789130a2af9257f74d [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
[email protected]b75b8292010-10-01 07:28:2511
[email protected]36fb2c7c2011-04-04 15:49:0812#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4613#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0714#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5615#include "base/logging.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
dmazzonid95ae842016-04-12 21:17:3917#include "base/memory/ref_counted.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2019#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2220#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0721#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5122#include "base/strings/string16.h"
23#include "base/strings/string_number_conversions.h"
24#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0025#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0726#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3727#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4228#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1029#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2530#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2131#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3032#include "content/browser/accessibility/accessibility_mode_helper.h"
33#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1834#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3935#include "content/browser/browser_plugin/browser_plugin_embedder.h"
36#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5937#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4138#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0439#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4640#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1241#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1642#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1743#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1644#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4045#include "content/browser/frame_host/interstitial_page_impl.h"
46#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3347#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0148#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1849#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1651#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5752#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0553#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4454#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4055#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3056#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5257#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1858#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5259#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5360#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0961#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3062#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5063#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3264#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5065#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5966#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4867#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0968#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3369#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1270#include "content/browser/wake_lock/wake_lock_service_context.h"
lfgc740d4b22016-04-15 16:45:3371#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1172#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5873#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0374#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5675#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1476#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4277#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4478#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1779#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0780#include "content/common/page_messages.h"
avi286019ce2015-07-29 01:26:5881#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5182#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0283#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3684#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1185#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2886#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4487#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3688#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1789#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1490#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4691#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1592#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0093#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2794#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0095#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3796#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1497#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3098#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3299#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:09100#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:12101#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34102#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38103#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:42104#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21105#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08106#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35107#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48108#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54109#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49110#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20111#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01112#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03113#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57114#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05115#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40116#include "mojo/common/url_type_converters.h"
117#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53118#include "net/http/http_cache.h"
119#include "net/http/http_transaction_factory.h"
120#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34121#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40122#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38123#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40124#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39125#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56126#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01127#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41128#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52129#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31130
[email protected]583418cc2013-01-17 14:01:10131#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40132#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15133#include "content/browser/android/date_time_chooser_android.h"
dalecurtisc85ed632016-01-13 00:22:46134#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18135#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15136#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10137
[email protected]f66df822012-05-18 16:52:17138#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50139#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57140#endif
[email protected]3e45ba92009-02-20 21:09:00141
fsamuel9cf7bdf2015-11-20 02:19:32142#if defined(MOJO_SHELL_CLIENT)
143#include "content/browser/web_contents/web_contents_view_mus.h"
144#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46145#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32146#endif
147
[email protected]8ff00d72012-10-23 19:12:21148namespace content {
[email protected]420ae012009-04-24 05:16:32149namespace {
150
[email protected]960b0372014-05-19 18:01:00151const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41152const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05153
[email protected]155c7f22013-12-09 17:07:18154#if defined(OS_ANDROID)
155const char kWebContentsAndroidKey[] = "web_contents_android";
156#endif // OS_ANDROID
157
[email protected]e4abd3b42013-11-12 18:28:47158base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46159g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
160
[email protected]8bfc8272013-09-09 20:10:53161void NotifyCacheOnIO(
162 scoped_refptr<net::URLRequestContextGetter> request_context,
163 const GURL& url,
164 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58165 net::HttpCache* cache = request_context->GetURLRequestContext()->
166 http_transaction_factory()->GetCache();
167 if (cache)
168 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53169}
170
dcheng57e39e22016-01-21 00:25:38171bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
172 for (FrameTreeNode* node : tree->Nodes()) {
173 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
174 return true;
alexmos4cf2aa32015-07-15 23:40:43175 }
dcheng57e39e22016-01-21 00:25:38176 return false;
[email protected]95640212014-07-26 18:14:30177}
178
[email protected]95640212014-07-26 18:14:30179void SetAccessibilityModeOnFrame(AccessibilityMode mode,
180 RenderFrameHost* frame_host) {
181 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
182}
183
dtseng0dd3fa12015-07-22 19:00:52184void ResetAccessibility(RenderFrameHost* rfh) {
185 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
186}
187
dmazzonid95ae842016-04-12 21:17:39188using AXTreeSnapshotCallback =
189 base::Callback<void(const ui::AXTreeUpdate&)>;
190
191// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
192// Handles the callbacks from parallel snapshot requests to each frame,
193// and feeds the results to an AXTreeCombiner, which converts them into a
194// single combined accessibility tree.
195class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
196 public:
197 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
198 : callback_(callback) {
199 }
200
201 AXTreeSnapshotCallback AddFrame(bool is_root) {
202 // Adds a reference to |this|.
203 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
204 this,
205 is_root);
206 }
207
208 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
209 combiner_.AddTree(snapshot, is_root);
210 }
211
212 private:
213 friend class base::RefCounted<AXTreeSnapshotCombiner>;
214
215 // This is called automatically after the last call to ReceiveSnapshot
216 // when there are no more references to this object.
217 ~AXTreeSnapshotCombiner() {
218 combiner_.Combine();
219 callback_.Run(combiner_.combined());
220 }
221
222 ui::AXTreeCombiner combiner_;
223 AXTreeSnapshotCallback callback_;
224};
225
[email protected]420ae012009-04-24 05:16:32226} // namespace
227
[email protected]54944cde2012-12-09 09:24:59228WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21229 FrameTreeNode* opener_node = nullptr;
230 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
231 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
232 params.opener_render_process_id, params.opener_render_frame_id);
233 if (opener_rfh)
234 opener_node = opener_rfh->frame_tree_node();
235 }
236 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19237}
238
239WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59240 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30241 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21242 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30243
244 for (SessionStorageNamespaceMap::const_iterator it =
245 session_storage_namespace_map.begin();
246 it != session_storage_namespace_map.end();
247 ++it) {
248 new_contents->GetController()
249 .SetSessionStorageNamespace(it->first, it->second.get());
250 }
251
[email protected]54944cde2012-12-09 09:24:59252 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19253 return new_contents;
[email protected]a81343d232011-12-27 07:39:20254}
[email protected]746d3052012-05-22 15:15:47255
nickf9acfbe2014-12-23 19:12:37256void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
257 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46258 g_created_callbacks.Get().push_back(callback);
259}
260
nickf9acfbe2014-12-23 19:12:37261void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
262 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46263 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
264 if (g_created_callbacks.Get().at(i).Equals(callback)) {
265 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
266 return;
267 }
268 }
269}
270
avidf38c952015-10-27 13:45:13271WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
272 if (!rvh)
273 return nullptr;
[email protected]746d3052012-05-22 15:15:47274 return rvh->GetDelegate()->GetAsWebContents();
275}
276
[email protected]a86c0e962013-12-17 17:10:39277WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13278 if (!rfh)
279 return nullptr;
280 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39281}
282
[email protected]7fff43e2013-05-21 20:21:10283// WebContentsImpl::DestructionObserver ----------------------------------------
284
285class WebContentsImpl::DestructionObserver : public WebContentsObserver {
286 public:
287 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
288 : WebContentsObserver(watched_contents),
289 owner_(owner) {
290 }
291
292 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58293 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58294 owner_->OnWebContentsDestroyed(
295 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10296 }
297
298 private:
299 WebContentsImpl* owner_;
300
301 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
302};
303
[email protected]8ed16472014-04-11 19:02:48304WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
305 int render_frame_id,
306 ColorChooser* chooser,
307 int identifier)
308 : render_process_id(render_process_id),
309 render_frame_id(render_frame_id),
310 chooser(chooser),
311 identifier(identifier) {
312}
313
314WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
315}
316
lazyboy6ec48b2a2015-06-29 15:18:14317// WebContentsImpl::WebContentsTreeNode ----------------------------------------
318WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
319 : outer_web_contents_(nullptr),
320 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37321 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14322}
323
324WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
325 // Remove child pointer from our parent.
326 if (outer_web_contents_) {
327 ChildrenSet& child_ptrs_in_parent =
328 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
329 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
330 DCHECK(iter != child_ptrs_in_parent.end());
331 child_ptrs_in_parent.erase(this);
332 }
333
334 // Remove parent pointers from our children.
335 // TODO(lazyboy): We should destroy the children WebContentses too. If the
336 // children do not manage their own lifetime, then we would leak their
337 // WebContentses.
338 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
339 child->outer_web_contents_ = nullptr;
340}
341
342void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
343 WebContentsImpl* outer_web_contents,
344 RenderFrameHostImpl* outer_contents_frame) {
345 outer_web_contents_ = outer_web_contents;
346 outer_contents_frame_tree_node_id_ =
347 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
348
349 if (!outer_web_contents_->node_)
350 outer_web_contents_->node_.reset(new WebContentsTreeNode());
351
352 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
353}
354
[email protected]b172aee2012-04-10 17:05:26355// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32356
alexmose201c7cd2015-06-10 17:14:21357WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42358 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22359 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57360 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21361 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01362 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57363 this,
364 this,
365 this,
366 this),
[email protected]6dfed692014-05-22 04:18:03367 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23368 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
369 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34370 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26371 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56372 upload_size_(0),
373 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16374 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47375 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10376 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28377 theme_color_(SK_ColorTRANSPARENT),
378 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29379 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55380 capturer_count_(0),
381 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00382 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57383 is_being_destroyed_(false),
384 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15385 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01386 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39387 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38388 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21389 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
390 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22391 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44392 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55393 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42394 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03395 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49396 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05397 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30398 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57399 geolocation_service_context_(new GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48400 accessibility_mode_(
401 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15402 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35403 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50404 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46405 page_scale_factor_is_one_(true),
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)
dglazkov79c426102015-08-31 21:22:43645 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11646 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25647 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18648 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54649 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18650 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54651 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18652 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41653 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
654 OnDidDisplayContentWithCertificateErrors)
655 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
656 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25657 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26658 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46659 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
660 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21661 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48662 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
663 OnRegisterProtocolHandler)
664 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
665 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01666 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
667 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52668 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10669 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50670 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50671#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00672 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
673 OnPepperInstanceCreated)
674 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
675 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42676 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
677 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50678 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
679 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55680 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40681 OnBrowserPluginMessage(render_frame_host,
682 message))
thestigc4cac8f2014-09-04 21:17:50683#endif
[email protected]41225fe2013-03-29 05:32:02684 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07685 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
686 OnShowValidationMessage)
687 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
688 OnHideValidationMessage)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
690 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15691#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52692 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48693 OnFindMatchRectsReply)
694 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
695 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48696#endif
[email protected]724159a2010-12-30 01:11:18697 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33698 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44699 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57700 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18701
[email protected]724159a2010-12-30 01:11:18702 return handled;
703}
704
nasko907fcb62015-01-28 04:24:11705bool WebContentsImpl::HasValidFrameSource() {
706 if (!render_frame_message_source_) {
707 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18708 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
709 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11710 return false;
711 }
712
713 return true;
714}
715
[email protected]b172aee2012-04-10 17:05:26716void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18717 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21718 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43719 if (delegate_)
720 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18721}
722
[email protected]d1198fd2012-08-13 22:50:19723NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56724 return controller_;
725}
726
[email protected]d1198fd2012-08-13 22:50:19727const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56728 return controller_;
729}
730
[email protected]8ff00d72012-10-23 19:12:21731BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55732 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30733}
734
[email protected]b172aee2012-04-10 17:05:26735const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24736 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32737 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51738 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31739}
740
[email protected]a093ce02013-07-22 20:53:14741const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24742 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32743 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24744 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
745}
746
747const GURL& WebContentsImpl::GetLastCommittedURL() const {
748 // We may not have a navigation entry yet.
749 NavigationEntry* entry = controller_.GetLastCommittedEntry();
750 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
751}
752
[email protected]8ff00d72012-10-23 19:12:21753WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31754 return delegate_;
755}
756
[email protected]8ff00d72012-10-23 19:12:21757void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31758 // TODO(cbentzel): remove this debugging code?
759 if (delegate == delegate_)
760 return;
761 if (delegate_)
762 delegate_->Detach(this);
763 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08764 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31765 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08766 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00767 if (view_)
[email protected]e85165c642014-06-10 14:34:31768 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08769 }
[email protected]be1f56ab2011-12-22 06:55:31770}
771
[email protected]8ff00d72012-10-23 19:12:21772RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21773 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41774 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16775}
776
clamydf1975e2015-02-05 19:12:24777RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41778 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16779}
780
nick53d5cbf2015-04-23 22:50:14781RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
782 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
783 if (!focused_node)
784 return nullptr;
785 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07786}
787
rob3e2a0732016-01-06 21:22:09788RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
789 int frame_tree_node_id) {
790 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
791 return frame ? frame->current_frame_host() : nullptr;
792}
793
[email protected]a86c0e962013-12-17 17:10:39794void WebContentsImpl::ForEachFrame(
795 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38796 for (FrameTreeNode* node : frame_tree_.Nodes()) {
797 on_frame.Run(node->current_frame_host());
798 }
[email protected]a86c0e962013-12-17 17:10:39799}
800
dchengafb53e22016-02-04 08:11:08801std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
802 std::vector<RenderFrameHost*> frame_hosts;
803 for (FrameTreeNode* node : frame_tree_.Nodes())
804 frame_hosts.push_back(node->current_frame_host());
805 return frame_hosts;
806}
807
lukaszacbdf52e2016-01-15 21:19:51808int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
809 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08810 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25811 if (!rfh->IsRenderFrameLive())
812 continue;
813
dchengafb53e22016-02-04 08:11:08814 ++number_of_messages;
815 IPC::Message* message_copy = new IPC::Message(*message);
816 message_copy->set_routing_id(rfh->GetRoutingID());
817 rfh->Send(message_copy);
818 }
[email protected]a86c0e962013-12-17 17:10:39819 delete message;
lukaszacbdf52e2016-01-15 21:19:51820 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39821}
822
lfgdb5c4ed2016-03-04 23:09:07823void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
824 frame_tree_.root()->render_manager()->SendPageMessage(msg);
825}
826
creisc014b402015-04-23 16:41:45827RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21828 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31829}
830
[email protected]6b618e62012-08-16 12:59:18831int WebContentsImpl::GetRoutingID() const {
832 if (!GetRenderViewHost())
833 return MSG_ROUTING_NONE;
834
835 return GetRenderViewHost()->GetRoutingID();
836}
837
creis89a0f782015-05-27 16:13:17838void WebContentsImpl::CancelActiveAndPendingDialogs() {
839 if (dialog_manager_)
840 dialog_manager_->CancelActiveAndPendingDialogs(this);
841 if (browser_plugin_embedder_)
842 browser_plugin_embedder_->CancelGuestDialogs();
843}
844
[email protected]44470a22013-01-24 01:21:54845int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
846 return fullscreen_widget_routing_id_;
847}
848
naskoc0fceff2015-04-30 15:53:52849void WebContentsImpl::ClosePage() {
850 GetRenderViewHost()->ClosePage();
851}
852
[email protected]b172aee2012-04-10 17:05:26853RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21854 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31855}
856
[email protected]4aebbca2013-09-17 22:26:49857RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
858 const {
859 RenderWidgetHost* const widget_host =
860 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
861 GetFullscreenWidgetRoutingID());
862 return widget_host ? widget_host->GetView() : NULL;
863}
864
[email protected]8ff00d72012-10-23 19:12:21865WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return view_.get();
867}
868
yusufod41c5f92015-03-06 00:14:28869SkColor WebContentsImpl::GetThemeColor() const {
870 return theme_color_;
871}
872
[email protected]95640212014-07-26 18:14:30873void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
874 if (mode == accessibility_mode_)
875 return;
876
877 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38878
879 for (FrameTreeNode* node : frame_tree_.Nodes()) {
880 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
881 RenderFrameHost* pending_frame_host =
882 node->render_manager()->pending_frame_host();
883 if (pending_frame_host)
884 SetAccessibilityModeOnFrame(mode, pending_frame_host);
885 }
[email protected]95640212014-07-26 18:14:30886}
887
888void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50889 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30890}
891
892void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50893 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30894}
895
dmazzoni83ba5c82015-04-14 07:11:51896void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39897 // Send a request to each of the frames in parallel. Each one will return
898 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
899 // them into a single tree and call |callback| with that result, then
900 // delete |combiner|.
901 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
902 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
903 bool is_root = frame_tree_node->parent() == nullptr;
904 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
905 combiner->AddFrame(is_root));
906 }
dmazzoni83ba5c82015-04-14 07:11:51907}
908
dbeama1b926a2015-08-31 23:17:51909WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
910 const std::string& frame_name) {
911 DCHECK(!frame_name.empty());
912 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22913}
914
[email protected]8ff00d72012-10-23 19:12:21915WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40916 WebUI* commited_web_ui = GetCommittedWebUI();
917 return commited_web_ui ? commited_web_ui
918 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31919}
920
[email protected]8ff00d72012-10-23 19:12:21921WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40922 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34923}
924
[email protected]86ef6a392012-05-11 22:03:11925void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22926 if (GetUserAgentOverride() == override)
927 return;
928
929 renderer_preferences_.user_agent_override = override;
930
931 // Send the new override string to the renderer.
932 RenderViewHost* host = GetRenderViewHost();
933 if (host)
934 host->SyncRendererPrefs();
935
936 // Reload the page if a load is currently in progress to avoid having
937 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27938 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25939 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05940 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53941
942 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
943 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11944}
945
946const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22947 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11948}
949
[email protected]95640212014-07-26 18:14:30950void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08951 if (GetAccessibilityMode() != AccessibilityModeOff) {
952 for (RenderFrameHost* rfh : GetAllFrames())
953 ResetAccessibility(rfh);
954 } else {
dtseng0dd3fa12015-07-22 19:00:52955 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08956 }
[email protected]95640212014-07-26 18:14:30957}
958
959bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
960 return accessibility_mode_ == AccessibilityModeTreeOnly;
961}
962
963bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
964 return accessibility_mode_ == AccessibilityModeComplete;
965}
966
kouhei40f03cb2015-09-24 07:47:01967const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
968 return page_importance_signals_;
969}
970
[email protected]fcf75d42013-12-03 20:11:26971const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55972 // Transient entries take precedence. They are used for interstitial pages
973 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23974 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23975 if (entry) {
jshin1fb76462016-04-05 22:13:03976 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23977 }
carlosk35f35af2015-12-01 10:55:40978
979 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
980 WebUI* our_web_ui = navigating_web_ui
981 ? navigating_web_ui
982 : GetRenderManager()->current_frame_host()->web_ui();
983
[email protected]7ade2732011-02-10 00:13:58984 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54985 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32986 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54987 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35988 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26989 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54990 if (!title.empty())
991 return title;
992 }
993 }
994
995 // We use the title for the last committed entry rather than a pending
996 // navigation entry. For example, when the user types in a URL, we want to
997 // keep the old page's title until the new load has committed and we get a new
998 // title.
[email protected]96d185d2009-04-24 03:28:54999 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321000
creis072b61f2015-09-28 20:52:241001 // We make an exception for initial navigations. We only want to use the title
1002 // from the visible entry if:
1003 // 1. The pending entry has been explicitly assigned a title to display.
1004 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1005 // which case there is a pending entry index other than -1.
1006 //
1007 // Otherwise, we want to stick with the last committed entry's title during
1008 // new navigations, which have pending entries at index -1 with no title.
1009 if (controller_.IsInitialNavigation() &&
1010 ((controller_.GetVisibleEntry() &&
1011 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1012 controller_.GetPendingEntryIndex() != -1)) {
1013 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471014 }
[email protected]59167c22013-06-03 18:07:321015
[email protected]45d0ef7f2011-01-05 13:46:231016 if (entry) {
jshin1fb76462016-04-05 22:13:031017 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231018 }
[email protected]987fc3a2011-05-26 14:18:091019
1020 // |page_title_when_no_navigation_entry_| is finally used
1021 // if no title cannot be retrieved.
1022 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541023}
1024
avib7348942015-12-25 20:57:101025int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461026 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1027}
1028
avib7348942015-12-25 20:57:101029int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261030 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331031 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1032 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461033
[email protected]b6583592012-01-25 19:52:331034 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341035}
1036
avib7348942015-12-25 20:57:101037void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461038 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1039}
1040
[email protected]b172aee2012-04-10 17:05:261041void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101042 SiteInstance* site_instance,
1043 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461044 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331045 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341046}
1047
[email protected]ec6c05f2013-10-23 18:41:571048void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1049 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1050 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571051}
1052
creiscce56cd2014-09-29 22:45:221053SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211054 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541055}
1056
creiscce56cd2014-09-29 22:45:221057SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1058 RenderViewHostImpl* dest_rvh =
1059 GetRenderManager()->pending_render_view_host() ?
1060 GetRenderManager()->pending_render_view_host() :
1061 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581062 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381063}
1064
[email protected]b172aee2012-04-10 17:05:261065bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251066 return frame_tree_.IsLoading() &&
1067 !(ShowingInterstitialPage() &&
1068 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491069}
1070
[email protected]6dfed692014-05-22 04:18:031071bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251072 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031073}
1074
[email protected]b172aee2012-04-10 17:05:261075bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031076 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311077}
1078
[email protected]b172aee2012-04-10 17:05:261079const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311080 return load_state_;
1081}
1082
[email protected]fcf75d42013-12-03 20:11:261083const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311084 return load_state_host_;
1085}
1086
avib7348942015-12-25 20:57:101087uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311088 return upload_size_;
1089}
1090
avib7348942015-12-25 20:57:101091uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311092 return upload_position_;
1093}
1094
[email protected]b172aee2012-04-10 17:05:261095const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541096 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311097}
1098
[email protected]b172aee2012-04-10 17:05:261099bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311100 return displayed_insecure_content_;
1101}
1102
[email protected]222f5822014-02-05 23:40:491103void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251104 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551105 ++capturer_count_;
1106 DVLOG(1) << "There are now " << capturer_count_
1107 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491108
1109 // Note: This provides a hint to upstream code to size the views optimally
1110 // for quality (e.g., to avoid scaling).
1111 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1112 preferred_size_for_capture_ = capture_size;
1113 OnPreferredSizeChanged(preferred_size_);
1114 }
ccameron8807c38f2015-01-17 00:29:191115
1116 // Ensure that all views are un-occluded before capture begins.
1117 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551118}
1119
1120void WebContentsImpl::DecrementCapturerCount() {
1121 --capturer_count_;
1122 DVLOG(1) << "There are now " << capturer_count_
1123 << " capturing(s) of WebContentsImpl@" << this;
1124 DCHECK_LE(0, capturer_count_);
1125
[email protected]5a652232013-02-12 06:15:251126 if (is_being_destroyed_)
1127 return;
1128
[email protected]222f5822014-02-05 23:40:491129 if (capturer_count_ == 0) {
1130 const gfx::Size old_size = preferred_size_for_capture_;
1131 preferred_size_for_capture_ = gfx::Size();
1132 OnPreferredSizeChanged(old_size);
1133 }
1134
[email protected]1ac10dca2013-08-20 20:47:041135 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551136 DVLOG(1) << "Executing delayed WasHidden().";
1137 WasHidden();
1138 }
[email protected]be1f56ab2011-12-22 06:55:311139}
1140
[email protected]f2bd40812013-07-20 04:30:441141int WebContentsImpl::GetCapturerCount() const {
1142 return capturer_count_;
1143}
1144
miu50f97892014-09-22 22:49:521145bool WebContentsImpl::IsAudioMuted() const {
1146 return audio_muter_.get() && audio_muter_->is_muting();
1147}
1148
1149void WebContentsImpl::SetAudioMuted(bool mute) {
1150 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1151 << " for WebContentsImpl@" << this;
1152
1153 if (mute == IsAudioMuted())
1154 return;
1155
1156 if (mute) {
1157 if (!audio_muter_)
1158 audio_muter_.reset(new WebContentsAudioMuter(this));
1159 audio_muter_->StartMuting();
1160 } else {
1161 DCHECK(audio_muter_);
1162 audio_muter_->StopMuting();
1163 }
1164
wjmaclean2f797c782016-01-07 14:52:031165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1166 DidUpdateAudioMutingState(mute));
1167
miu50f97892014-09-22 22:49:521168 // Notification for UI updates in response to the changed muting state.
1169 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1170}
1171
ortunodf4d7982016-04-08 02:33:351172void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
1173 // Notify for UI updates if the state changes.
1174 bluetooth_connected_device_count_++;
1175 if (bluetooth_connected_device_count_ == 1) {
1176 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1177 }
ortuno32e7db3c2016-03-29 16:14:201178}
1179
ortunodf4d7982016-04-08 02:33:351180void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
1181 // Notify for UI updates if the state changes.
1182 DCHECK(bluetooth_connected_device_count_ != 0);
1183 bluetooth_connected_device_count_--;
1184 if (bluetooth_connected_device_count_ == 0) {
1185 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1186 }
1187}
1188
1189bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1190 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201191}
1192
[email protected]b172aee2012-04-10 17:05:261193bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311194 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1195 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581196 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271197#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581198 crashed_status_ ==
1199 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271200#endif
wfh0d9532a2015-09-02 23:18:581201 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271202 );
[email protected]3c9e1872010-11-18 16:17:491203}
1204
[email protected]b172aee2012-04-10 17:05:261205void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1206 int error_code) {
[email protected]443b80e2010-12-14 00:42:231207 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341208 return;
1209
[email protected]443b80e2010-12-14 00:42:231210 crashed_status_ = status;
1211 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211212 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341213}
1214
[email protected]b172aee2012-04-10 17:05:261215base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311216 return crashed_status_;
1217}
1218
afakhry98241832016-03-11 19:27:471219int WebContentsImpl::GetCrashedErrorCode() const {
1220 return crashed_error_code_;
1221}
1222
[email protected]b172aee2012-04-10 17:05:261223bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311224 return is_being_destroyed_;
1225}
1226
[email protected]7f924832014-08-09 05:57:221227void WebContentsImpl::NotifyNavigationStateChanged(
1228 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541229 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1230 // is fixed.
1231 tracked_objects::ScopedTracker tracking_profile(
1232 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1233 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181234 // Notify the media observer of potential audibility changes.
1235 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271236 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301237 }
1238
[email protected]d5f942ba2008-09-26 19:30:341239 if (delegate_)
1240 delegate_->NavigationStateChanged(this, changed_flags);
1241}
1242
gab0dccfef2015-05-20 18:43:391243base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021244 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331245}
1246
georgesak5582cbe2015-05-22 22:08:071247void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1248 last_active_time_ = last_active_time;
1249}
1250
[email protected]9e2e4632012-07-27 16:38:411251void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541252 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591253
ccameron8807c38f2015-01-17 00:29:191254 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1255 if (view) {
1256 view->Show();
[email protected]789e9152009-08-04 21:59:431257#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191258 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431259#endif
[email protected]de3c5d82014-05-28 22:12:591260 }
[email protected]789e9152009-08-04 21:59:431261 }
[email protected]96d185d2009-04-24 03:28:541262
gab0dccfef2015-05-20 18:43:391263 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381264
[email protected]b9769d82012-02-10 00:23:591265 // The resize rect might have changed while this was inactive -- send the new
1266 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451267 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221268 if (rvh) {
1269 rvh->GetWidget()->ResizeRectChanged(
1270 GetRootWindowResizerRect(rvh->GetWidget()));
1271 }
[email protected]96d185d2009-04-24 03:28:541272
[email protected]c0d9d5672013-10-09 07:38:031273 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1274
[email protected]54597982013-02-06 01:59:551275 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311276}
1277
[email protected]b172aee2012-04-10 17:05:261278void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551279 // If there are entities capturing screenshots or video (e.g., mirroring),
1280 // don't activate the "disable rendering" optimization.
1281 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521282 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551283 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261284 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521285 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331286 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521287 // calls us).
ccameron8807c38f2015-01-17 00:29:191288 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1289 if (view)
1290 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591291 }
[email protected]96d185d2009-04-24 03:28:541292 }
1293
[email protected]c0d9d5672013-10-09 07:38:031294 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1295
[email protected]54597982013-02-06 01:59:551296 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371297}
1298
ccameron8807c38f2015-01-17 00:29:191299void WebContentsImpl::WasOccluded() {
1300 if (capturer_count_ > 0)
1301 return;
1302
1303 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1304 if (view)
1305 view->WasOccluded();
1306 }
1307}
1308
1309void WebContentsImpl::WasUnOccluded() {
1310 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1311 if (view)
1312 view->WasUnOccluded();
1313 }
1314}
1315
[email protected]b172aee2012-04-10 17:05:261316bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311317 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451318 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1319 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311320}
1321
[email protected]1c3f80bd2014-04-08 23:02:061322void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451323 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061324}
1325
lazyboy6ec48b2a2015-06-29 15:18:141326void WebContentsImpl::AttachToOuterWebContentsFrame(
1327 WebContents* outer_web_contents,
1328 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081329 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lfg91a79e12016-04-01 23:52:191330 RenderFrameHostManager* render_manager = GetRenderManager();
1331
1332 // When the WebContents being initialized has an opener, the browser side
1333 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1334 // created. This is needed because the usual initialization happens during
1335 // the first navigation, but when attaching a new window we don't navigate
1336 // before attaching. If the browser side is already initialized, the calls
1337 // below will just early return.
1338 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1339 GetMainFrame()->Init();
1340 if (!render_manager->GetRenderWidgetHostView())
1341 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1342
lazyboy6ec48b2a2015-06-29 15:18:141343 // Create a link to our outer WebContents.
1344 node_.reset(new WebContentsTreeNode());
1345 node_->ConnectToOuterWebContents(
1346 static_cast<WebContentsImpl*>(outer_web_contents),
1347 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1348
1349 DCHECK(outer_contents_frame);
1350
1351 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1352 // SiteInstance of the outer WebContents. The proxy will be used to send
1353 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191354 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141355 outer_contents_frame->GetSiteInstance(),
1356 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1357
lfg91a79e12016-04-01 23:52:191358 render_manager->SetRWHViewForInnerContents(
1359 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391360
1361 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191362 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391363 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141364}
1365
[email protected]b172aee2012-04-10 17:05:261366void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381367 for (FrameTreeNode* node : frame_tree_.Nodes())
1368 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401369 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271370}
1371
[email protected]b172aee2012-04-10 17:05:261372WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441373 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211374 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451375 // before.
[email protected]54944cde2012-12-09 09:24:591376 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451377 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211378 WebContentsImpl* tc =
1379 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191380 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221381 FOR_EACH_OBSERVER(WebContentsObserver,
1382 observers_,
1383 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271384 return tc;
1385}
1386
[email protected]14392a52012-05-02 20:28:441387void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211388 const NotificationSource& source,
1389 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441390 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211391 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1392 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031393 RenderWidgetHostView* view = host->GetView();
1394 if (view == GetFullscreenRenderWidgetHostView()) {
1395 // We cannot just call view_->RestoreFocus() here. On some platforms,
1396 // attempting to focus the currently-invisible WebContentsView will be
1397 // flat-out ignored. Therefore, this boolean is used to track whether
1398 // we will request focus after the fullscreen widget has been
1399 // destroyed.
1400 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1401 } else {
1402 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1403 i != pending_widget_views_.end(); ++i) {
1404 if (host->GetView() == i->second) {
1405 pending_widget_views_.erase(i);
1406 break;
1407 }
[email protected]bafe6cd2012-05-23 23:09:501408 }
1409 }
1410 break;
1411 }
[email protected]14392a52012-05-02 20:28:441412 default:
1413 NOTREACHED();
1414 }
1415}
1416
[email protected]ec6c05f2013-10-23 18:41:571417WebContents* WebContentsImpl::GetWebContents() {
1418 return this;
1419}
1420
[email protected]54944cde2012-12-09 09:24:591421void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211422 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361423 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211424 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431425 should_normally_be_visible_ = !params.initially_hidden;
1426
dcheng3ce04b62015-10-26 23:30:551427 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541428 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551429 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1430 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541431 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551432 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1433 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1434
1435 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1436 if (!site_instance)
1437 site_instance = SiteInstance::Create(params.browser_context);
1438
1439 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1440 // local root by definition.
1441 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1442 // longer be necessary to eagerly grab a routing ID for the view.
1443 // https://crbug.com/545684
1444 int32_t view_routing_id = params.routing_id;
1445 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1446 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1447 view_routing_id = main_frame_widget_routing_id =
1448 site_instance->GetProcess()->GetNextRoutingID();
1449 }
1450
1451 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1452 params.main_frame_routing_id,
1453 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321454
1455 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1456 // frame - let's do the same thing here.
1457 std::string unique_name = params.main_frame_name;
1458 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191459
[email protected]fc2b46b2014-05-03 16:33:451460 WebContentsViewDelegate* delegate =
1461 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1462
fsamueladb0033602015-12-09 19:20:411463#if defined(MOJO_SHELL_CLIENT)
1464 if (MojoShellConnection::Get() &&
1465 base::CommandLine::ForCurrentProcess()->HasSwitch(
1466 switches::kUseMusInRenderer)) {
1467 mus::Window* mus_window = aura::GetMusWindow(params.context);
1468 if (mus_window) {
1469 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1470 &render_view_host_delegate_view_));
1471 }
1472 }
1473#endif
1474
1475 if (!view_) {
lfgc740d4b22016-04-15 16:45:331476 if (browser_plugin_guest_ &&
1477 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
1478 view_.reset(new WebContentsViewChildFrame(
1479 this, delegate, &render_view_host_delegate_view_));
1480 } else {
1481 view_.reset(CreateWebContentsView(this, delegate,
1482 &render_view_host_delegate_view_));
1483 }
fsamueladb0033602015-12-09 19:20:411484 }
fsamuel9cf7bdf2015-11-20 02:19:321485
lazyboy6ec48b2a2015-06-29 15:18:141486 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081487 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321488 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361489 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321490 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191491 }
[email protected]fc2b46b2014-05-03 16:33:451492 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191493 CHECK(view_.get());
1494
[email protected]ed245db2012-12-18 08:00:451495 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591496 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191497
tommyclieb25b2a2014-11-03 19:45:091498#if defined(ENABLE_PLUGINS)
1499 plugin_content_origin_whitelist_.reset(
1500 new PluginContentOriginWhitelist(this));
1501#endif
1502
[email protected]d1198fd2012-08-13 22:50:191503 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211504 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1505 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101506
[email protected]01f83f92014-06-17 14:41:541507 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091508 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541509
mlamouriefdca9d2014-09-16 16:55:401510 manifest_manager_host_.reset(new ManifestManagerHost(this));
1511
mfomitchev2b8b066a2016-01-28 19:23:151512#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101513 date_time_chooser_.reset(new DateTimeChooserAndroid());
1514#endif
fsamuel7310a4262014-12-05 05:06:441515
1516 // BrowserPluginGuest::Init needs to be called after this WebContents has
1517 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1518 if (browser_plugin_guest_)
1519 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371520
1521 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1522 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561523
1524 // If the WebContents creation was renderer-initiated, it means that the
1525 // corresponding RenderView and main RenderFrame have already been created.
1526 // Ensure observers are notified about this.
1527 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431528 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561529 RenderViewCreated(GetRenderViewHost());
1530 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1531 }
naskof5940b9f2015-03-02 23:04:051532
1533 // Ensure that observers are notified of the creation of this WebContents's
1534 // main RenderFrameHost. It must be done here for main frames, since the
1535 // NotifySwappedFromRenderManager expects view_ to already be created and that
1536 // happens after RenderFrameHostManager::Init.
1537 NotifySwappedFromRenderManager(
1538 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191539}
1540
[email protected]7fff43e2013-05-21 20:21:101541void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1542 RemoveDestructionObserver(web_contents);
1543
[email protected]ceee8cd2013-03-08 04:59:511544 // Clear a pending contents that has been closed before being shown.
1545 for (PendingContents::iterator iter = pending_contents_.begin();
1546 iter != pending_contents_.end();
1547 ++iter) {
1548 if (iter->second != web_contents)
1549 continue;
1550 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511551 return;
1552 }
1553 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441554}
1555
[email protected]7fff43e2013-05-21 20:21:101556void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1557 if (!ContainsKey(destruction_observers_, web_contents)) {
1558 destruction_observers_[web_contents] =
1559 new DestructionObserver(this, web_contents);
1560 }
1561}
1562
1563void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1564 DestructionObservers::iterator iter =
1565 destruction_observers_.find(web_contents);
1566 if (iter != destruction_observers_.end()) {
1567 delete destruction_observers_[web_contents];
1568 destruction_observers_.erase(iter);
1569 }
1570}
1571
[email protected]b172aee2012-04-10 17:05:261572void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311573 observers_.AddObserver(observer);
1574}
1575
[email protected]b172aee2012-04-10 17:05:261576void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311577 observers_.RemoveObserver(observer);
1578}
1579
[email protected]948481d2014-06-11 18:32:221580std::set<RenderWidgetHostView*>
1581WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1582 std::set<RenderWidgetHostView*> set;
1583 if (ShowingInterstitialPage()) {
1584 set.insert(GetRenderWidgetHostView());
1585 } else {
dchengafb53e22016-02-04 08:11:081586 for (RenderFrameHost* rfh : GetAllFrames()) {
1587 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1588 ->frame_tree_node()
1589 ->render_manager()
1590 ->GetRenderWidgetHostView();
1591 set.insert(rwhv);
1592 }
[email protected]948481d2014-06-11 18:32:221593 }
[email protected]de3c5d82014-05-28 22:12:591594 return set;
1595}
1596
[email protected]b172aee2012-04-10 17:05:261597void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341598 if (delegate_)
1599 delegate_->ActivateContents(this);
1600}
1601
avi3e4b8512015-11-11 01:55:491602void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1603 if (!RenderViewHostImpl::From(render_widget_host))
1604 return;
1605
[email protected]63954792011-07-11 04:17:481606 if (delegate_)
1607 delegate_->LostCapture();
1608}
1609
lazyboy63f5b312015-11-23 20:19:521610void WebContentsImpl::RenderWidgetCreated(
1611 RenderWidgetHostImpl* render_widget_host) {
1612 created_widgets_.insert(render_widget_host);
1613}
1614
[email protected]b24b68a2012-09-24 21:57:261615void WebContentsImpl::RenderWidgetDeleted(
1616 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521617 // Note that |is_being_destroyed_| can be true at this point as
1618 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1619 // us here.
1620 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261621
lazyboy63f5b312015-11-23 20:19:521622 if (is_being_destroyed_)
1623 return;
[email protected]44470a22013-01-24 01:21:541624
1625 if (render_widget_host &&
1626 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491627 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531628 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541629 FOR_EACH_OBSERVER(WebContentsObserver,
1630 observers_,
1631 DidDestroyFullscreenWidget(
1632 fullscreen_widget_routing_id_));
1633 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031634 if (fullscreen_widget_had_focus_at_shutdown_)
1635 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541636 }
[email protected]b24b68a2012-09-24 21:57:261637}
1638
miu9e14e492014-10-25 02:39:041639void WebContentsImpl::RenderWidgetGotFocus(
1640 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371641 // Notify the observers if an embedded fullscreen widget was focused.
1642 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1643 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1644 NotifyWebContentsFocused();
1645 }
miu9e14e492014-10-25 02:39:041646}
1647
estaded0a0c992015-01-21 14:12:061648void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311649 RenderWidgetHostImpl* render_widget_host,
1650 bool width_changed) {
creisc014b402015-04-23 16:41:451651 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291652 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061653 return;
estaded0a0c992015-01-21 14:12:061654
rouslan2f5993f2015-01-29 00:18:311655 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1656 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061657}
1658
paulmeyer9ef6e4462015-02-24 19:15:101659void WebContentsImpl::ScreenInfoChanged() {
1660 if (browser_plugin_embedder_)
1661 browser_plugin_embedder_->ScreenInfoChanged();
1662}
1663
[email protected]b172aee2012-04-10 17:05:261664bool WebContentsImpl::PreHandleKeyboardEvent(
1665 const NativeWebKeyboardEvent& event,
1666 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481667 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131668 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481669}
1670
[email protected]b172aee2012-04-10 17:05:261671void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101672 if (browser_plugin_embedder_ &&
1673 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1674 return;
1675 }
[email protected]63954792011-07-11 04:17:481676 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131677 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481678}
1679
[email protected]d92026ef2014-03-03 21:04:131680bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461681 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191682#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331683 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1684 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191685 // -the OS already has a gesture to do this through pinch-zoom
1686 // -if a user starts an inertial scroll, let's go, and presses control
1687 // (i.e. control+tab) then the OS's buffered scroll events will come in
1688 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331689 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551690 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331691 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221692 // Count only integer cumulative scrolls as zoom events; this handles
1693 // smooth scroll and regular scroll device behavior.
1694 zoom_scroll_remainder_ += event.wheelTicksY;
1695 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1696 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1697 if (whole_zoom_scroll_remainder_ != 0) {
1698 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1699 }
[email protected]fb3f066e2013-02-12 19:12:521700 return true;
1701 }
[email protected]bccc4472013-04-18 16:37:191702#endif
[email protected]fb3f066e2013-02-12 19:12:521703 return false;
1704}
1705
[email protected]04bce562014-01-30 05:34:541706bool WebContentsImpl::PreHandleGestureEvent(
1707 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031708 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541709}
1710
kenrb2a565f82015-09-02 20:24:591711RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451712 if (!is_being_destroyed_ && GetOuterWebContents())
1713 return GetOuterWebContents()->GetInputEventRouter();
1714
1715 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591716 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1717 return rwh_input_event_router_.get();
1718}
1719
alexmos3fcd0ca2015-10-23 18:18:331720void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1721 // Focus loss may occur while this WebContents is being destroyed. Don't
1722 // send the message in this case, as the main frame's RenderFrameHost and
1723 // other state has already been cleared.
1724 if (is_being_destroyed_)
1725 return;
1726
1727 frame_tree_.ReplicatePageFocus(is_focused);
1728}
1729
alexmosc4cbacb2015-11-21 01:29:221730RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1731 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521732 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221733 return receiving_widget;
1734
1735 // Events for widgets other than the main frame (e.g., popup menus) should be
1736 // forwarded directly to the widget they arrived on.
1737 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1738 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521739
1740 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1741 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221742 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521743
alexmos732ca3a2015-12-08 02:01:021744 // The view may be null if a subframe's renderer process has crashed while
1745 // the subframe has focus. Drop the event in that case. Do not give
1746 // it to the main frame, so that the user doesn't unexpectedly type into the
1747 // wrong frame if a focused subframe renderer crashes while they type.
1748 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1749 if (!view)
1750 return nullptr;
1751
1752 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521753}
1754
mlamouri7a78d6fd2015-01-17 13:23:531755void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1756 // This method is being called to enter renderer-initiated fullscreen mode.
1757 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491758 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371759 if (widget_view) {
1760 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1761 ->ShutdownAndDestroyWidget(true);
1762 }
[email protected]4aebbca2013-09-17 22:26:491763
[email protected]8a5e0ca2011-08-25 06:30:471764 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531765 delegate_->EnterFullscreenModeForTab(this, origin);
1766
1767 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461768 DidToggleFullscreenModeForTab(
1769 IsFullscreenForCurrentTab(
1770 GetRenderViewHost()->GetWidget()),
1771 false));
mlamouri7a78d6fd2015-01-17 13:23:531772}
1773
bokanece34a82016-01-28 19:49:461774void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531775 // This method is being called to leave renderer-initiated fullscreen mode.
1776 // Make sure any existing fullscreen widget is shut down first.
1777 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371778 if (widget_view) {
1779 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1780 ->ShutdownAndDestroyWidget(true);
1781 }
mlamouri7a78d6fd2015-01-17 13:23:531782
hugo.holgersson61288e6c2015-01-28 17:04:401783#if defined(OS_ANDROID)
1784 ContentVideoView* video_view = ContentVideoView::GetInstance();
1785 if (video_view != NULL)
watk98292292016-01-19 22:24:081786 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401787#endif
1788
mlamouri7a78d6fd2015-01-17 13:23:531789 if (delegate_)
1790 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371791
bokanece34a82016-01-28 19:49:461792 // The fullscreen state is communicated to the renderer through a resize
1793 // message. If the change in fullscreen state doesn't cause a view resize
1794 // then we must ensure web contents exit the fullscreen state by explicitly
1795 // sending a resize message. This is required for the situation of the browser
1796 // moving the view into a "browser fullscreen" state and then the contents
1797 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1798 // have the side effect of the view resizing, hence the explicit call here is
1799 // required.
1800 if (!will_cause_resize) {
1801 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1802 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1803 render_widget_host->WasResized();
1804 }
scheib3dcb6c932015-02-23 10:55:581805 }
1806
avibf58fa0c2015-11-11 01:45:521807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461808 DidToggleFullscreenModeForTab(
1809 IsFullscreenForCurrentTab(
1810 GetRenderViewHost()->GetWidget()),
1811 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471812}
1813
avibf58fa0c2015-11-11 01:45:521814bool WebContentsImpl::IsFullscreenForCurrentTab(
1815 RenderWidgetHostImpl* render_widget_host) const {
1816 if (!RenderViewHostImpl::From(render_widget_host))
1817 return false;
1818
[email protected]199bba6e2012-04-04 16:19:381819 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121820}
1821
avibf58fa0c2015-11-11 01:45:521822blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1823 RenderWidgetHostImpl* render_widget_host) const {
1824 if (!RenderViewHostImpl::From(render_widget_host))
1825 return blink::WebDisplayModeBrowser;
1826
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121827 return delegate_ ? delegate_->GetDisplayMode(this)
1828 : blink::WebDisplayModeBrowser;
1829}
1830
avic3aa8422015-11-09 20:57:221831void WebContentsImpl::RequestToLockMouse(
1832 RenderWidgetHostImpl* render_widget_host,
1833 bool user_gesture,
1834 bool last_unlocked_by_target) {
1835 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1836 render_widget_host->GotResponseToLockMouseRequest(false);
1837 return;
[email protected]e9621112011-10-17 05:38:371838 }
avic3aa8422015-11-09 20:57:221839
1840 if (delegate_)
1841 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1842 else
1843 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371844}
1845
avi3e4b8512015-11-11 01:55:491846void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1847 if (!RenderViewHostImpl::From(render_widget_host))
1848 return;
1849
[email protected]e9621112011-10-17 05:38:371850 if (delegate_)
1851 delegate_->LostMouseLock();
1852}
1853
dtrainor5ef644e2015-11-19 00:12:471854void WebContentsImpl::ForwardCompositorProto(
1855 RenderWidgetHostImpl* render_widget_host,
1856 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471857 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291858 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471859}
1860
ekaramada4f42692016-02-11 19:48:371861void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1862 if (visible)
1863 WasShown();
1864 else
1865 WasHidden();
1866}
1867
[email protected]bafe6cd2012-05-23 23:09:501868void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431869 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551870 int32_t route_id,
1871 int32_t main_frame_route_id,
1872 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131873 const ViewHostMsg_CreateWindow_Params& params,
1874 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501875 // We usually create the new window in the same BrowsingInstance (group of
1876 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551877 // if the opener is being suppressed (in a non-guest), we create a new
1878 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251879 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551880
[email protected]04cbd3d2013-12-04 04:58:201881 // If the opener is to be suppressed, the new window can be in any process.
1882 // Since routing ids are process specific, we must not have one passed in
1883 // as argument here.
1884 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1885
[email protected]bafe6cd2012-05-23 23:09:501886 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431887 params.opener_suppressed && !is_guest
1888 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1889 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501890
alexmos4cf2aa32015-07-15 23:40:431891 // A message to create a new window can only come from a process for a frame
1892 // in this WebContents' FrameTree. If any other process sends the request, it
1893 // is invalid and the process must be terminated.
1894 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381895 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431896 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351897 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201898 if (process_handle != base::kNullProcessHandle) {
1899 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391900 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351901 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201902 }
1903 return;
1904 }
1905
[email protected]d1198fd2012-08-13 22:50:191906 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341907 //
1908 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301909 const std::string& partition_id =
1910 GetContentClient()->browser()->
1911 GetStoragePartitionIdForSite(GetBrowserContext(),
1912 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461913 StoragePartition* partition = BrowserContext::GetStoragePartition(
1914 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411915 DOMStorageContextWrapper* dom_storage_context =
1916 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191917 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1918 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1919 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371920
1921 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551922 !delegate_->ShouldCreateWebContents(
1923 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1924 params.window_container_type, params.frame_name, params.target_url,
1925 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011926 if (route_id != MSG_ROUTING_NONE &&
1927 !RenderViewHost::FromID(render_process_id, route_id)) {
1928 // If the embedder didn't create a WebContents for this route, we need to
1929 // delete the RenderView that had already been created.
1930 Send(new ViewMsg_Close(route_id));
1931 }
csharrisona2280cd2016-02-03 23:21:151932 // It's safe to only target the frame because the render process will not
1933 // have a chance to create more frames at this point.
1934 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1935 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371936 return;
1937 }
1938
1939 // Create the new web contents. This will automatically create the new
1940 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461941 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591942 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041943 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551944 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121945 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431946 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211947 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061948 create_params.opener_suppressed = params.opener_suppressed;
1949 if (params.disposition == NEW_BACKGROUND_TAB)
1950 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191951 create_params.renderer_initiated_creation =
1952 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061953
[email protected]4858e432014-06-23 18:14:171954 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551955 if (!is_guest) {
1956 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451957 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171958 new_contents = static_cast<WebContentsImpl*>(
1959 WebContents::Create(create_params));
1960 } else {
1961 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551962 }
[email protected]50d326e2014-05-20 17:59:061963 new_contents->GetController().SetSessionStorageNamespace(
1964 partition_id,
1965 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191966
alexmos646fec02015-07-25 00:11:491967 // If the new frame has a name, make sure any SiteInstances that can find
1968 // this named frame have proxies for it. Must be called after
1969 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1970 // GetSessionStorageNamespace.
1971 if (!params.frame_name.empty())
1972 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1973
[email protected]c4538072013-03-18 02:17:551974 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341975 // will be shown immediately).
1976 if (!params.opener_suppressed) {
1977 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451978 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501979
[email protected]d70bea92013-04-05 04:23:341980 // TODO(brettw): It seems bogus that we have to call this function on the
1981 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431982 new_view->CreateViewForWidget(
1983 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341984 }
[email protected]bafe6cd2012-05-23 23:09:501985 // Save the created window associated with the route so we can show it
1986 // later.
1987 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1988 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101989 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501990 }
1991
1992 if (delegate_) {
1993 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071994 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131995 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501996 }
1997
1998 if (params.opener_suppressed) {
1999 // When the opener is suppressed, the original renderer cannot access the
2000 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002001 bool was_blocked = false;
2002 if (delegate_) {
bokan107a47f2015-02-03 23:23:392003 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002004 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392005 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002006 params.user_gesture, &was_blocked);
2007 }
2008 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:212009 OpenURLParams open_params(params.target_url,
2010 Referrer(),
2011 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352012 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212013 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302014 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372015
2016 if (delegate_ && !is_guest &&
2017 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2018 // We are in asynchronous add new contents path, delay opening url
2019 new_contents->delayed_open_url_params_.reset(
2020 new OpenURLParams(open_params));
2021 } else {
2022 new_contents->OpenURL(open_params);
2023 }
[email protected]eda238a12012-09-07 23:44:002024 }
[email protected]bafe6cd2012-05-23 23:09:502025 }
2026}
2027
avib7348942015-12-25 20:57:102028void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2029 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462030 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052031 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502032}
2033
avib7348942015-12-25 20:57:102034void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2035 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052036 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502037}
2038
avib7348942015-12-25 20:57:102039void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2040 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502041 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462042 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252043 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232044 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512045 // this WebContentsImpl instance. If any other process sends the request,
2046 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382047 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252048 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512049 if (process_handle != base::kNullProcessHandle) {
2050 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392051 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252052 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512053 }
2054 return;
2055 }
2056
[email protected]bafe6cd2012-05-23 23:09:502057 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052058 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262059
[email protected]cfd80b02014-05-01 17:46:482060 RenderWidgetHostViewBase* widget_view =
2061 static_cast<RenderWidgetHostViewBase*>(
2062 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192063 if (!widget_view)
2064 return;
[email protected]bafe6cd2012-05-23 23:09:502065 if (!is_fullscreen) {
2066 // Popups should not get activated.
2067 widget_view->SetPopupType(popup_type);
2068 }
2069 // Save the created widget associated with the route so we can show it later.
2070 pending_widget_views_[route_id] = widget_view;
2071
2072#if defined(OS_MACOSX)
2073 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2074 // to allow it to survive the trip without being hosted.
2075 base::mac::NSObjectRetain(widget_view->GetNativeView());
2076#endif
2077}
2078
2079void WebContentsImpl::ShowCreatedWindow(int route_id,
2080 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392081 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502082 bool user_gesture) {
2083 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002084 if (contents) {
2085 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162086 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382087 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2088 contents->ResumeLoadingCreatedWebContents();
2089
[email protected]eda238a12012-09-07 23:44:002090 if (delegate) {
2091 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392092 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002093 }
2094 }
[email protected]bafe6cd2012-05-23 23:09:502095}
2096
2097void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392098 const gfx::Rect& initial_rect) {
2099 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502100}
2101
2102void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2103 ShowCreatedWidget(route_id, true, gfx::Rect());
2104}
2105
2106void WebContentsImpl::ShowCreatedWidget(int route_id,
2107 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392108 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482109 RenderWidgetHostViewBase* widget_host_view =
2110 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502111 if (!widget_host_view)
2112 return;
[email protected]cfd80b02014-05-01 17:46:482113
2114 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332115 if (GetOuterWebContents()) {
2116 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482117 } else {
2118 view = GetRenderWidgetHostView();
2119 }
2120
[email protected]4aebbca2013-09-17 22:26:492121 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312122 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032123 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312124 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492125 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2126 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532127 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492128 } else {
[email protected]cfd80b02014-05-01 17:46:482129 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492130 }
[email protected]4aebbca2013-09-17 22:26:492131 FOR_EACH_OBSERVER(WebContentsObserver,
2132 observers_,
2133 DidShowFullscreenWidget(route_id));
2134 if (!widget_host_view->HasFocus())
2135 widget_host_view->Focus();
2136 } else {
bokan107a47f2015-02-03 23:23:392137 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492138 }
[email protected]89054502012-06-03 10:29:242139
2140 RenderWidgetHostImpl* render_widget_host_impl =
2141 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2142 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312143 // Only allow privileged mouse lock for fullscreen render widget, which is
2144 // used to implement Pepper Flash fullscreen.
2145 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502146
2147#if defined(OS_MACOSX)
2148 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2149 // properly embedded (or purposefully ignored) we can release the retain we
2150 // took in CreateNewWidget().
2151 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2152#endif
2153}
2154
2155WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2156 PendingContents::iterator iter = pending_contents_.find(route_id);
2157
2158 // Certain systems can block the creation of new windows. If we didn't succeed
2159 // in creating one, just return NULL.
2160 if (iter == pending_contents_.end()) {
2161 return NULL;
2162 }
2163
2164 WebContentsImpl* new_contents = iter->second;
2165 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102166 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502167
[email protected]d70bea92013-04-05 04:23:342168 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252169 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342170 return new_contents;
2171
[email protected]bafe6cd2012-05-23 23:09:502172 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432173 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502174 return NULL;
2175
[email protected]bafe6cd2012-05-23 23:09:502176 return new_contents;
2177}
2178
2179RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2180 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2181 if (iter == pending_widget_views_.end()) {
2182 DCHECK(false);
2183 return NULL;
2184 }
2185
2186 RenderWidgetHostView* widget_host_view = iter->second;
2187 pending_widget_views_.erase(route_id);
2188
2189 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2190 if (!widget_host->GetProcess()->HasConnection()) {
2191 // The view has gone away or the renderer crashed. Nothing to do.
2192 return NULL;
2193 }
2194
2195 return widget_host_view;
2196}
2197
[email protected]f13b4202012-06-12 23:53:232198void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092199 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212200 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372201 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232202 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372203 } else {
dcheng59716272016-04-09 05:19:082204 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2205 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372206 }
[email protected]f13b4202012-06-12 23:53:232207}
2208
grunell657d4d82014-09-18 00:09:432209bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2210 MediaStreamType type) {
2211 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2212 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2213 return delegate_ &&
2214 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2215}
2216
[email protected]cc9200432013-07-23 23:02:402217SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2218 SiteInstance* instance) {
2219 return controller_.GetSessionStorageNamespace(instance);
2220}
2221
[email protected]6de7fc482014-06-06 10:46:442222SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2223 return controller_.GetSessionStorageNamespaceMap();
2224}
2225
[email protected]9b159a52013-10-03 17:24:552226FrameTree* WebContentsImpl::GetFrameTree() {
2227 return &frame_tree_;
2228}
2229
lukendc35e7f2014-11-10 19:06:142230void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2231 virtual_keyboard_requested_ = requested;
2232}
2233
2234bool WebContentsImpl::IsVirtualKeyboardRequested() {
2235 return virtual_keyboard_requested_;
2236}
2237
aelias5252baa2016-04-10 01:18:022238bool WebContentsImpl::IsOverridingUserAgent() {
2239 return GetController().GetVisibleEntry() &&
2240 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2241}
2242
[email protected]95640212014-07-26 18:14:302243AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2244 return accessibility_mode_;
2245}
2246
[email protected]31a71eaf2014-03-13 01:47:362247void WebContentsImpl::AccessibilityEventReceived(
2248 const std::vector<AXEventNotificationDetails>& details) {
2249 FOR_EACH_OBSERVER(
2250 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2251}
2252
dmazzonia656928e2014-09-15 20:28:542253RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402254 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542255 int browser_plugin_instance_id) {
2256 BrowserPluginGuestManager* guest_manager =
2257 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202258 if (!guest_manager)
2259 return nullptr;
2260
dmazzonia656928e2014-09-15 20:28:542261 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442262 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542263 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202264 return nullptr;
2265
dmazzonia656928e2014-09-15 20:28:542266 return guest->GetMainFrame();
2267}
2268
blundellc57b93f2014-10-29 13:19:572269GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2270 return geolocation_service_context_.get();
2271}
2272
alogvinovf50445a2015-10-30 13:00:122273WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2274 return wake_lock_service_context_.get();
2275}
2276
[email protected]edc3af82013-12-12 21:24:072277void WebContentsImpl::OnShowValidationMessage(
2278 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292279 const base::string16& main_text,
2280 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072281 if (delegate_)
2282 delegate_->ShowValidationMessage(
2283 this, anchor_in_root_view, main_text, sub_text);
2284}
2285
2286void WebContentsImpl::OnHideValidationMessage() {
2287 if (delegate_)
2288 delegate_->HideValidationMessage(this);
2289}
2290
2291void WebContentsImpl::OnMoveValidationMessage(
2292 const gfx::Rect& anchor_in_root_view) {
2293 if (delegate_)
2294 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2295}
2296
lfgbb9c28a2016-03-01 03:19:492297void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372298 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2299 if (node->current_frame_host()->GetRenderWidgetHost())
2300 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2301 }
lfgbb9c28a2016-03-01 03:19:492302
lfgdb5c4ed2016-03-04 23:09:072303 RenderWidgetHostViewBase* rwhv =
2304 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2305 if (rwhv) {
2306 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2307 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2308 }
2309
[email protected]32deec62013-05-15 23:55:042310 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442311 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042312}
2313
[email protected]95640212014-07-26 18:14:302314BrowserAccessibilityManager*
2315 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452316 RenderFrameHostImpl* rfh = GetMainFrame();
2317 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302318}
2319
2320BrowserAccessibilityManager*
2321 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452322 RenderFrameHostImpl* rfh = GetMainFrame();
2323 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302324}
2325
mohsen7ab1ec16ec2015-07-02 18:26:232326void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2327 RenderFrameHost* focused_frame = GetFocusedFrame();
2328 if (!focused_frame)
2329 return;
2330
2331 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2332 focused_frame->GetRoutingID(), extent));
2333}
2334
2335void WebContentsImpl::SelectRange(const gfx::Point& base,
2336 const gfx::Point& extent) {
2337 RenderFrameHost* focused_frame = GetFocusedFrame();
2338 if (!focused_frame)
2339 return;
2340
2341 focused_frame->Send(
2342 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2343}
2344
aurimasab0319022015-07-10 21:57:382345void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2346 int end_adjust) {
2347 RenderFrameHost* focused_frame = GetFocusedFrame();
2348 if (!focused_frame)
2349 return;
2350
2351 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2352 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2353}
2354
[email protected]b172aee2012-04-10 17:05:262355void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492356 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232357 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492358 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332359}
2360
avic3aa8422015-11-09 20:57:222361void WebContentsImpl::ResizeDueToAutoResize(
2362 RenderWidgetHostImpl* render_widget_host,
2363 const gfx::Size& new_size) {
2364 if (render_widget_host != GetRenderViewHost()->GetWidget())
2365 return;
2366
[email protected]61e2b3cc2012-03-02 16:13:342367 if (delegate_)
2368 delegate_->ResizeDueToAutoResize(this, new_size);
2369}
2370
[email protected]b172aee2012-04-10 17:05:262371WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202372 if (!delegate_)
2373 return NULL;
[email protected]00c37fc2011-08-02 00:22:502374
[email protected]e5d549d2011-12-28 01:29:202375 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202376 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342377}
2378
[email protected]6b618e62012-08-16 12:59:182379bool WebContentsImpl::Send(IPC::Message* message) {
2380 if (!GetRenderViewHost()) {
2381 delete message;
2382 return false;
2383 }
2384
2385 return GetRenderViewHost()->Send(message);
2386}
2387
[email protected]a86c0e962013-12-17 17:10:392388void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2389 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442390 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392391 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442392}
2393
[email protected]20ca0382013-02-28 19:50:072394void WebContentsImpl::AttachInterstitialPage(
2395 InterstitialPageImpl* interstitial_page) {
2396 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212397 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292398
2399 // Cancel any visible dialogs so that they don't interfere with the
2400 // interstitial.
creis89a0f782015-05-27 16:13:172401 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292402
[email protected]20ca0382013-02-28 19:50:072403 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2404 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252405
2406 // Stop the throbber if needed while the interstitial page is shown.
2407 if (frame_tree_.IsLoading())
2408 LoadingStateChanged(true, true, nullptr);
2409}
2410
2411void WebContentsImpl::DidProceedOnInterstitial() {
2412 // The interstitial page should no longer be pausing the throbber.
2413 DCHECK(!(ShowingInterstitialPage() &&
2414 GetRenderManager()->interstitial_page()->pause_throbber()));
2415
2416 // Restart the throbber now that the interstitial page no longer pauses it.
2417 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2418 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072419}
2420
2421void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252422 bool interstitial_pausing_throbber =
2423 ShowingInterstitialPage() &&
2424 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572425 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212426 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072427 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2428 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252429
2430 // Restart the throbber if needed now that the interstitial page is going
2431 // away.
2432 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2433 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072434}
2435
avi2b177592014-12-10 02:08:022436void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2437 int history_length) {
2438 SetHistoryOffsetAndLengthForView(
2439 GetRenderViewHost(), history_offset, history_length);
2440}
2441
2442void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2443 RenderViewHost* render_view_host,
2444 int history_offset,
2445 int history_length) {
2446 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2447 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142448}
2449
toyoshim24a4c7ab2016-04-05 09:24:142450void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172451 RenderFrameHost* focused_frame = GetFocusedFrame();
2452 if (!focused_frame)
2453 return;
2454
[email protected]959be4c2014-04-08 15:01:332455 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142456 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332457}
2458
megjablon3f5941072016-02-04 23:27:522459void WebContentsImpl::ReloadLoFiImages() {
2460 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2461}
2462
[email protected]959be4c2014-04-08 15:01:332463void WebContentsImpl::Undo() {
2464 RenderFrameHost* focused_frame = GetFocusedFrame();
2465 if (!focused_frame)
2466 return;
2467
2468 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2469 RecordAction(base::UserMetricsAction("Undo"));
2470}
2471
2472void WebContentsImpl::Redo() {
2473 RenderFrameHost* focused_frame = GetFocusedFrame();
2474 if (!focused_frame)
2475 return;
2476 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2477 RecordAction(base::UserMetricsAction("Redo"));
2478}
2479
2480void WebContentsImpl::Cut() {
2481 RenderFrameHost* focused_frame = GetFocusedFrame();
2482 if (!focused_frame)
2483 return;
2484
2485 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2486 RecordAction(base::UserMetricsAction("Cut"));
2487}
2488
2489void WebContentsImpl::Copy() {
2490 RenderFrameHost* focused_frame = GetFocusedFrame();
2491 if (!focused_frame)
2492 return;
2493
2494 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2495 RecordAction(base::UserMetricsAction("Copy"));
2496}
2497
2498void WebContentsImpl::CopyToFindPboard() {
2499#if defined(OS_MACOSX)
2500 RenderFrameHost* focused_frame = GetFocusedFrame();
2501 if (!focused_frame)
2502 return;
2503
2504 // Windows/Linux don't have the concept of a find pasteboard.
2505 focused_frame->Send(
2506 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2507 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2508#endif
2509}
2510
2511void WebContentsImpl::Paste() {
2512 RenderFrameHost* focused_frame = GetFocusedFrame();
2513 if (!focused_frame)
2514 return;
2515
2516 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2517 RecordAction(base::UserMetricsAction("Paste"));
2518}
2519
2520void WebContentsImpl::PasteAndMatchStyle() {
2521 RenderFrameHost* focused_frame = GetFocusedFrame();
2522 if (!focused_frame)
2523 return;
2524
2525 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2526 focused_frame->GetRoutingID()));
2527 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2528}
2529
2530void WebContentsImpl::Delete() {
2531 RenderFrameHost* focused_frame = GetFocusedFrame();
2532 if (!focused_frame)
2533 return;
2534
2535 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2536 RecordAction(base::UserMetricsAction("DeleteSelection"));
2537}
2538
2539void WebContentsImpl::SelectAll() {
2540 RenderFrameHost* focused_frame = GetFocusedFrame();
2541 if (!focused_frame)
2542 return;
2543
2544 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2545 RecordAction(base::UserMetricsAction("SelectAll"));
2546}
2547
2548void WebContentsImpl::Unselect() {
2549 RenderFrameHost* focused_frame = GetFocusedFrame();
2550 if (!focused_frame)
2551 return;
2552
2553 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2554 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172555}
2556
2557void WebContentsImpl::Replace(const base::string16& word) {
2558 RenderFrameHost* focused_frame = GetFocusedFrame();
2559 if (!focused_frame)
2560 return;
2561
[email protected]959be4c2014-04-08 15:01:332562 focused_frame->Send(new InputMsg_Replace(
2563 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172564}
2565
2566void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2567 RenderFrameHost* focused_frame = GetFocusedFrame();
2568 if (!focused_frame)
2569 return;
2570
[email protected]959be4c2014-04-08 15:01:332571 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2572 focused_frame->GetRoutingID(), word));
2573}
2574
2575void WebContentsImpl::NotifyContextMenuClosed(
2576 const CustomContextMenuContext& context) {
2577 RenderFrameHost* focused_frame = GetFocusedFrame();
2578 if (!focused_frame)
2579 return;
2580
2581 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2582 focused_frame->GetRoutingID(), context));
2583}
2584
2585void WebContentsImpl::ExecuteCustomContextMenuCommand(
2586 int action, const CustomContextMenuContext& context) {
2587 RenderFrameHost* focused_frame = GetFocusedFrame();
2588 if (!focused_frame)
2589 return;
2590
2591 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2592 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002593}
2594
[email protected]fc2b46b2014-05-03 16:33:452595gfx::NativeView WebContentsImpl::GetNativeView() {
2596 return view_->GetNativeView();
2597}
2598
2599gfx::NativeView WebContentsImpl::GetContentNativeView() {
2600 return view_->GetContentNativeView();
2601}
2602
2603gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2604 return view_->GetTopLevelNativeWindow();
2605}
2606
2607gfx::Rect WebContentsImpl::GetViewBounds() {
2608 return view_->GetViewBounds();
2609}
2610
2611gfx::Rect WebContentsImpl::GetContainerBounds() {
2612 gfx::Rect rv;
2613 view_->GetContainerBounds(&rv);
2614 return rv;
2615}
2616
2617DropData* WebContentsImpl::GetDropData() {
2618 return view_->GetDropData();
2619}
2620
2621void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042622 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452623}
2624
2625void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042626 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452627}
2628
2629void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042630 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452631}
2632
2633void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042634 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452635}
2636
[email protected]b172aee2012-04-10 17:05:262637void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272638 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212639 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542640 return;
2641 }
[email protected]0b431992014-06-24 00:08:032642 RenderWidgetHostView* const fullscreen_view =
2643 GetFullscreenRenderWidgetHostView();
2644 if (fullscreen_view) {
2645 fullscreen_view->Focus();
2646 return;
2647 }
creisc014b402015-04-23 16:41:452648 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542649}
2650
[email protected]b172aee2012-04-10 17:05:262651bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212652 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542653}
2654
[email protected]b172aee2012-04-10 17:05:262655InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212656 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222657}
2658
[email protected]b172aee2012-04-10 17:05:262659bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162660 // WebKit creates Document object when MIME type is application/xhtml+xml,
2661 // so we also support this MIME type.
2662 return contents_mime_type_ == "text/html" ||
2663 contents_mime_type_ == "text/xml" ||
2664 contents_mime_type_ == "application/xhtml+xml" ||
2665 contents_mime_type_ == "text/plain" ||
2666 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252667 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162668}
2669
[email protected]b172aee2012-04-10 17:05:262670void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592671 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162672 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552673 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192674 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142675 return;
[email protected]c7dd2f62011-07-18 15:57:592676 }
2677
2678 Stop();
2679
2680 // Create the save package and possibly prompt the user for the name to save
2681 // the page as. The user prompt is an asynchronous operation that runs on
2682 // another thread.
2683 save_package_ = new SavePackage(this);
2684 save_package_->GetSaveInfo();
2685}
2686
2687// Used in automated testing to bypass prompting the user for file names.
2688// Instead, the names and paths are hard coded rather than running them through
2689// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342690bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2691 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212692 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592693 // Stop the page from navigating.
2694 Stop();
2695
2696 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212697 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592698}
2699
[email protected]3c71576ce2013-07-23 02:00:012700void WebContentsImpl::SaveFrame(const GURL& url,
2701 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372702 SaveFrameWithHeaders(url, referrer, std::string());
2703}
2704
2705void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2706 const Referrer& referrer,
2707 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192708 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012709 return;
sammc92af61552014-11-19 23:27:402710 if (delegate_ && delegate_->SaveFrame(url, referrer))
2711 return;
2712
nasko89ad7742015-03-05 22:14:192713 // TODO(nasko): This check for main frame is incorrect and should be fixed
2714 // by explicitly passing in which frame this method should target.
2715 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012716
2717 DownloadManager* dlm =
2718 BrowserContext::GetDownloadManager(GetBrowserContext());
2719 if (!dlm)
2720 return;
avib7348942015-12-25 20:57:102721 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012722 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272723 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012724 if (entry)
2725 post_id = entry->GetPostID();
2726 }
dcheng59716272016-04-09 05:19:082727 std::unique_ptr<DownloadUrlParameters> params(
[email protected]3c71576ce2013-07-23 02:00:012728 DownloadUrlParameters::FromWebContents(this, url));
2729 params->set_referrer(referrer);
2730 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012731 if (post_id >= 0)
2732 params->set_method("POST");
2733 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372734
2735 if (headers.empty()) {
2736 params->set_prefer_cache(true);
2737 } else {
brettw26dab8f02015-08-08 00:28:472738 for (const base::StringPiece& key_value :
2739 base::SplitStringPiece(
2740 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2741 std::vector<std::string> pair = base::SplitString(
2742 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372743 DCHECK_EQ(2ul, pair.size());
2744 params->add_request_header(pair[0], pair[1]);
2745 }
2746 }
dcheng36b6aec92015-12-26 06:16:362747 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012748}
2749
[email protected]b172aee2012-04-10 17:05:262750void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342751 const base::FilePath& file,
dewittj3287e2052016-04-21 00:33:172752 bool use_binary_encoding,
avib7348942015-12-25 20:57:102753 const base::Callback<void(int64_t)>& callback) {
dewittj3287e2052016-04-21 00:33:172754 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, use_binary_encoding,
2755 file, callback);
[email protected]aa4f3972012-03-01 18:12:122756}
2757
[email protected]b172aee2012-04-10 17:05:262758const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272759 return contents_mime_type_;
2760}
2761
[email protected]b172aee2012-04-10 17:05:262762bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272763 return notify_disconnection_;
2764}
2765
[email protected]b172aee2012-04-10 17:05:262766void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312767 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182768 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162769}
2770
[email protected]b172aee2012-04-10 17:05:262771void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542772 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182773 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162774}
2775
[email protected]8ff00d72012-10-23 19:12:212776RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272777 return &renderer_preferences_;
2778}
2779
[email protected]e35ccd52012-05-23 16:22:472780void WebContentsImpl::Close() {
2781 Close(GetRenderViewHost());
2782}
2783
[email protected]cf200a562013-05-03 16:24:292784void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462785 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292786 if (browser_plugin_embedder_.get())
2787 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2788 screen_x, screen_y, operation);
2789 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452790 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2791 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292792}
2793
[email protected]d60f3702013-12-26 16:30:242794void WebContentsImpl::DidGetResourceResponseStart(
2795 const ResourceRequestDetails& details) {
2796 controller_.ssl_manager()->DidStartResourceResponse(details);
2797
2798 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2799 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242800}
2801
2802void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462803 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242804 const ResourceRedirectDetails& details) {
2805 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2806
2807 FOR_EACH_OBSERVER(
2808 WebContentsObserver,
2809 observers_,
creis114ca1b2014-11-13 23:51:462810 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242811
2812 // TODO(avi): Remove. http://crbug.com/170921
2813 NotificationService::current()->Notify(
2814 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2815 Source<WebContents>(this),
2816 Details<const ResourceRedirectDetails>(&details));
2817}
2818
calamity7fe55ce2015-04-10 03:59:372819void WebContentsImpl::NotifyWebContentsFocused() {
2820 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2821}
2822
[email protected]b172aee2012-04-10 17:05:262823void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522824 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452825 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292826 if (browser_plugin_embedder_.get())
2827 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342828}
2829
[email protected]e35ccd52012-05-23 16:22:472830void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532831 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2832 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472833}
2834
[email protected]b172aee2012-04-10 17:05:262835void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272836 closed_by_user_gesture_ = value;
2837}
2838
[email protected]b172aee2012-04-10 17:05:262839bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272840 return closed_by_user_gesture_;
2841}
2842
[email protected]b172aee2012-04-10 17:05:262843void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502844 if (!delegate_)
2845 return;
2846
[email protected]6286a372013-10-09 04:03:272847 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2848 if (!entry)
[email protected]1788e772010-12-15 16:40:502849 return;
2850
[email protected]6286a372013-10-09 04:03:272851 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122852}
2853
[email protected]b172aee2012-04-10 17:05:262854void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042855 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272856 if (!delegate_)
2857 return;
2858
[email protected]691aa2f2013-05-28 22:52:042859 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272860}
2861
[email protected]b172aee2012-04-10 17:05:262862int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272863 return minimum_zoom_percent_;
2864}
2865
[email protected]b172aee2012-04-10 17:05:262866int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272867 return maximum_zoom_percent_;
2868}
2869
mcnee432e47d2015-11-09 19:37:462870void WebContentsImpl::SetPageScale(float page_scale_factor) {
2871 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242872}
2873
[email protected]b172aee2012-04-10 17:05:262874gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492875 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232876}
2877
[email protected]b172aee2012-04-10 17:05:262878bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052879 if (GetBrowserPluginGuest())
2880 return GetBrowserPluginGuest()->LockMouse(allowed);
2881
creisc014b402015-04-23 16:41:452882 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432883 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2884 allowed)
creisc014b402015-04-23 16:41:452885 : false;
[email protected]0bfbf882011-12-22 18:19:272886}
2887
[email protected]b172aee2012-04-10 17:05:262888bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212889 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502890}
2891
alexmose201c7cd2015-06-10 17:14:212892WebContentsImpl* WebContentsImpl::GetOpener() const {
2893 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2894 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572895}
2896
[email protected]cb805452013-05-22 15:16:212897void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482898 if (!color_chooser_info_.get())
2899 return;
2900 RenderFrameHost* rfh = RenderFrameHost::FromID(
2901 color_chooser_info_->render_process_id,
2902 color_chooser_info_->render_frame_id);
2903 if (!rfh)
2904 return;
2905
2906 rfh->Send(new FrameMsg_DidChooseColorResponse(
2907 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202908}
2909
[email protected]cb805452013-05-22 15:16:212910void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482911 if (!color_chooser_info_.get())
2912 return;
2913 RenderFrameHost* rfh = RenderFrameHost::FromID(
2914 color_chooser_info_->render_process_id,
2915 color_chooser_info_->render_frame_id);
2916 if (!rfh)
2917 return;
2918
2919 rfh->Send(new FrameMsg_DidEndColorChooser(
2920 rfh->GetRoutingID(), color_chooser_info_->identifier));
2921 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202922}
2923
halton.huoca2eabd2015-07-06 08:17:402924int WebContentsImpl::DownloadImage(
2925 const GURL& url,
2926 bool is_favicon,
2927 uint32_t max_bitmap_size,
2928 bool bypass_cache,
2929 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552930 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402931 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062932 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402933 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552934 const int download_id = ++next_image_download_id;
2935 if (!mojo_image_downloader) {
2936 // If the renderer process is dead (i.e. crash, or memory pressure on
2937 // Android), the downloader service will be invalid. Pre-Mojo, this would
2938 // hang the callback indefinetly since the IPC would be dropped. Now,
2939 // respond with a 400 HTTP error code to indicate that something went wrong.
2940 BrowserThread::PostTask(
2941 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192942 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522943 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2944 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552945 return download_id;
2946 }
2947
halton.huoca2eabd2015-07-06 08:17:402948 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522949 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2950 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2951 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552952 return download_id;
[email protected]795c28972012-12-06 06:13:392953}
2954
[email protected]5dcaf8e2013-12-28 01:31:422955bool WebContentsImpl::IsSubframe() const {
2956 return is_subframe_;
2957}
2958
[email protected]36ec24f2014-01-09 00:32:082959void WebContentsImpl::Find(int request_id,
2960 const base::string16& search_text,
2961 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332962 // Cowardly refuse to search for no text.
2963 if (search_text.empty()) {
2964 NOTREACHED();
2965 return;
2966 }
2967
raymes0fa0be52014-10-13 20:38:092968 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:172969 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:472970 if (browser_plugin_embedder_ &&
2971 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2972 return;
raymes0fa0be52014-10-13 20:38:092973 }
paulmeyerc0b762b2016-04-13 11:55:172974
2975 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:082976}
2977
2978void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012979 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:172980 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:472981 if (browser_plugin_embedder_ &&
2982 browser_plugin_embedder_->StopFinding(action)) {
2983 return;
raymes2bc64182015-02-06 01:23:012984 }
paulmeyerc0b762b2016-04-13 11:55:172985
2986 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:082987}
2988
[email protected]4fe53add2014-04-08 19:53:362989void WebContentsImpl::InsertCSS(const std::string& css) {
2990 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2991 GetMainFrame()->GetRoutingID(), css));
2992}
2993
dalecurtisbc6572e12014-09-12 19:22:302994bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152995 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302996}
2997
mlamouriefdca9d2014-09-16 16:55:402998void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2999 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3000}
3001
dominickn6919ce32015-10-15 01:52:283002void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
3003 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
3004}
3005
bokanece34a82016-01-28 19:49:463006void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533007 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433008 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463009 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533010}
3011
mariakhomenko44bdc4732015-04-29 01:55:383012void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373013 if (delayed_open_url_params_.get()) {
3014 OpenURL(*delayed_open_url_params_.get());
3015 delayed_open_url_params_.reset(nullptr);
3016 return;
3017 }
3018
mariakhomenko44bdc4732015-04-29 01:55:383019 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3020 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163021 if (is_resume_pending_) {
3022 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133023 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163024 GetMainFrame()->Init();
3025 }
mariakhomenko44bdc4732015-04-29 01:55:383026}
3027
[email protected]b172aee2012-04-10 17:05:263028bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263029 // When the browser is started with about:blank as the startup URL, focus
3030 // the location bar (which will also select its contents) so people can
3031 // simply begin typing to navigate elsewhere.
3032 //
3033 // We need to be careful not to trigger this for anything other than the
3034 // startup navigation. In particular, if we allow an attacker to open a
3035 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3036 // end of the new URL to be scrolled into view instead of the start,
3037 // allowing the attacker to spoof other URLs. The conditions checked here
3038 // are all aimed at ensuring no such attacker-controlled navigation can
3039 // trigger this.
3040 //
3041 // Note that we check the pending entry instead of the visible one; for the
3042 // startup URL case these are the same, but for the attacker-controlled
3043 // navigation case the visible entry is the committed "about:blank" URL and
3044 // the pending entry is the problematic navigation elsewhere.
3045 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3046 if (controller_.IsInitialNavigation() && entry &&
3047 !entry->is_renderer_initiated() &&
3048 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333049 return true;
palmerc70cb1f2016-03-04 23:41:263050 }
[email protected]0c9406632013-02-08 01:13:333051 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273052}
3053
[email protected]b172aee2012-04-10 17:05:263054void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273055 if (delegate_)
3056 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213057}
3058
clamy0e119882015-07-31 16:12:333059void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3060 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3061 DidStartNavigation(navigation_handle));
3062}
3063
3064void WebContentsImpl::DidRedirectNavigation(
3065 NavigationHandle* navigation_handle) {
3066 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3067 DidRedirectNavigation(navigation_handle));
3068}
3069
clamyefca29e2015-09-17 00:22:113070void WebContentsImpl::ReadyToCommitNavigation(
3071 NavigationHandle* navigation_handle) {
3072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3073 ReadyToCommitNavigation(navigation_handle));
3074}
3075
clamy0e119882015-07-31 16:12:333076void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3077 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3078 DidFinishNavigation(navigation_handle));
3079}
3080
[email protected]52913802013-12-10 05:52:183081void WebContentsImpl::DidStartProvisionalLoad(
3082 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183083 const GURL& validated_url,
3084 bool is_error_page,
3085 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103086 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483087 FOR_EACH_OBSERVER(
3088 WebContentsObserver,
3089 observers_,
3090 DidStartProvisionalLoadForFrame(
3091 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083092
3093 // Notify accessibility if this is a reload.
3094 NavigationEntry* entry = controller_.GetVisibleEntry();
3095 if (entry && ui::PageTransitionCoreTypeIs(
3096 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3097 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3098 BrowserAccessibilityManager* manager =
3099 ftn->current_frame_host()->browser_accessibility_manager();
3100 if (manager)
3101 manager->UserIsReloading();
3102 }
[email protected]400992b2012-06-14 00:03:543103}
3104
[email protected]3109fbb72014-01-06 23:57:153105void WebContentsImpl::DidFailProvisionalLoadWithError(
3106 RenderFrameHostImpl* render_frame_host,
3107 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3108 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313109 FOR_EACH_OBSERVER(WebContentsObserver,
3110 observers_,
3111 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313112 validated_url,
3113 params.error_code,
gsennton6fbb38692015-06-24 19:23:553114 params.error_description,
3115 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083116
3117 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3118 BrowserAccessibilityManager* manager =
3119 ftn->current_frame_host()->browser_accessibility_manager();
3120 if (manager)
3121 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153122}
3123
[email protected]b80624c2014-02-09 02:46:553124void WebContentsImpl::DidFailLoadWithError(
3125 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553126 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553127 int error_code,
gsennton6fbb38692015-06-24 19:23:553128 const base::string16& error_description,
3129 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143130 FOR_EACH_OBSERVER(
3131 WebContentsObserver,
3132 observers_,
gsennton6fbb38692015-06-24 19:23:553133 DidFailLoad(render_frame_host, url, error_code, error_description,
3134 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553135}
3136
[email protected]52913802013-12-10 05:52:183137void WebContentsImpl::NotifyChangedNavigationState(
3138 InvalidateTypes changed_flags) {
3139 NotifyNavigationStateChanged(changed_flags);
3140}
3141
[email protected]3691e5cf2014-01-22 10:16:203142void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203143 const GURL& url,
3144 NavigationController::ReloadType reload_type) {
3145 // Notify observers about navigation.
3146 FOR_EACH_OBSERVER(
3147 WebContentsObserver,
3148 observers_,
3149 DidStartNavigationToPendingEntry(url, reload_type));
3150}
3151
[email protected]8cb834e2014-03-06 14:23:233152void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3153 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503154 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3155 // weak pointer of sorts.
3156 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3157 const int32_t frame_id = render_frame_host->GetRoutingID();
3158
[email protected]65920f332014-03-04 21:14:183159 WebContents* new_contents = OpenURL(params);
3160
dchengb907f7332015-01-07 20:35:503161 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183162 // Notify observers.
3163 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3164 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463165 render_frame_host,
[email protected]65920f332014-03-04 21:14:183166 params.url,
3167 params.referrer,
3168 params.disposition,
creis114ca1b2014-11-13 23:51:463169 params.transition));
[email protected]65920f332014-03-04 21:14:183170 }
3171}
3172
creis29460272015-12-16 04:38:223173bool WebContentsImpl::ShouldTransferNavigation() {
3174 if (!delegate_)
3175 return true;
3176 return delegate_->ShouldTransferNavigation();
3177}
3178
[email protected]aa62afd2014-04-22 19:22:463179bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3180 if (!delegate_)
3181 return false;
3182 return delegate_->ShouldPreserveAbortedURLs(this);
3183}
3184
[email protected]37567b432014-02-12 01:12:223185void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433186 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223187 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353188 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223189 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483190 FOR_EACH_OBSERVER(WebContentsObserver,
3191 observers_,
3192 DidCommitProvisionalLoadForFrame(
3193 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083194
3195 BrowserAccessibilityManager* manager =
3196 render_frame_host->browser_accessibility_manager();
3197 if (manager)
3198 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223199}
3200
[email protected]0d0f4c492014-04-02 06:42:573201void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233202 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573203 // Ensure fullscreen mode is exited before committing the navigation to a
3204 // different page. The next page will not start out assuming it is in
3205 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233206 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193207 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573208 return;
3209 }
avibf58fa0c2015-11-11 01:45:523210 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463211 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523212 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573213}
3214
[email protected]37567b432014-02-12 01:12:223215void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283216 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223217 const LoadCommittedDetails& details,
3218 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3219 if (details.is_navigation_to_different_page()) {
3220 // Clear the status bubble. This is a workaround for a bug where WebKit
3221 // doesn't let us know that the cursor left an element during a
3222 // transition (this is also why the mouse cursor remains as a hand after
3223 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3224 // clear the bubble when a user navigates to a named anchor in the same
3225 // page.
sky8b00392d2015-01-10 00:30:283226 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003227
3228 RenderWidgetHostViewBase* rwhvb =
3229 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3230 if (rwhvb)
3231 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283232
peter90afaba2015-06-01 12:05:293233 did_first_visually_non_empty_paint_ = false;
3234
yusufod41c5f92015-03-06 00:14:283235 // Reset theme color on navigation to new page.
3236 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223237 }
3238
3239 if (!details.is_in_page) {
3240 // Once the main frame is navigated, we're no longer considered to have
3241 // displayed insecure content.
3242 displayed_insecure_content_ = false;
3243 SSLManager::NotifySSLInternalStateChanged(
3244 GetController().GetBrowserContext());
3245 }
3246
3247 // Notify observers about navigation.
3248 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3249 DidNavigateMainFrame(details, params));
3250
[email protected]e85165c642014-06-10 14:34:313251 if (delegate_)
[email protected]37567b432014-02-12 01:12:223252 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313253 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223254}
3255
3256void WebContentsImpl::DidNavigateAnyFramePostCommit(
3257 RenderFrameHostImpl* render_frame_host,
3258 const LoadCommittedDetails& details,
3259 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103260 // Now that something has committed, we don't need to track whether the
3261 // initial page has been accessed.
3262 has_accessed_initial_document_ = false;
3263
[email protected]37567b432014-02-12 01:12:223264 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173265 if (!details.is_in_page)
3266 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223267
avid53461d2016-02-25 17:15:043268 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3269 // again.
3270 if (params.gesture == NavigationGestureUser && dialog_manager_)
3271 dialog_manager_->ResetDialogState(this);
3272
[email protected]37567b432014-02-12 01:12:223273 // Notify observers about navigation.
3274 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093275 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223276}
3277
3278void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3279 contents_mime_type_ = mime_type;
3280}
3281
[email protected]277857a2014-06-03 10:38:013282bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313283 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053284 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313285 return false;
3286
[email protected]37567b432014-02-12 01:12:223287 if (delegate_)
3288 return delegate_->CanOverscrollContent();
3289
3290 return false;
3291}
3292
[email protected]37b64c52014-07-11 21:14:053293void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293294 // Update the theme color. This is to be published to observers after the
3295 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283296 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293297
3298 if (did_first_visually_non_empty_paint_ &&
3299 last_sent_theme_color_ != theme_color_) {
3300 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3301 DidChangeThemeColor(theme_color_));
3302 last_sent_theme_color_ = theme_color_;
3303 }
[email protected]e7104762014-06-20 19:17:253304}
3305
[email protected]b172aee2012-04-10 17:05:263306void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183307 const GURL& url,
[email protected]70435962011-08-02 20:13:283308 const std::string& security_info,
3309 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183310 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403311 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533312 SSLStatus status;
3313 if (!DeserializeSecurityInfo(security_info, &status)) {
3314 bad_message::ReceivedBadMessage(
3315 GetRenderProcessHost(),
3316 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3317 return;
3318 }
[email protected]724159a2010-12-30 01:11:183319
3320 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593321 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213322 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263323 url, status.cert_id, status.cert_status, http_method, mime_type,
3324 resource_type);
[email protected]724159a2010-12-30 01:11:183325
[email protected]b0f724c2013-09-05 04:21:133326 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3327
3328 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3329 DidLoadResourceFromMemoryCache(details));
3330
[email protected]8bfc8272013-09-09 20:10:533331 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3332 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403333 resource_type == RESOURCE_TYPE_MEDIA ?
jam2503f932016-04-15 20:08:303334 GetRenderProcessHost()->GetStoragePartition()->
3335 GetMediaURLRequestContext() :
jam608f2992016-03-31 16:35:343336 GetRenderProcessHost()->GetStoragePartition()->
3337 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533338 BrowserThread::PostTask(
3339 BrowserThread::IO,
3340 FROM_HERE,
3341 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3342 }
[email protected]724159a2010-12-30 01:11:183343}
3344
[email protected]b172aee2012-04-10 17:05:263345void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393346 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183347 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193348 SSLManager::NotifySSLInternalStateChanged(
3349 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183350}
3351
estark910b4572015-12-09 20:55:413352void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3353 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583354 LOG(WARNING) << security_origin << " ran insecure content from "
3355 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393356 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413357 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293358 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393359 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183360 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193361 SSLManager::NotifySSLInternalStateChanged(
3362 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183363}
3364
estark910b4572015-12-09 20:55:413365void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3366 const GURL& url,
3367 const std::string& security_info) {
3368 SSLStatus ssl;
3369 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3370 bad_message::ReceivedBadMessage(
3371 GetRenderProcessHost(),
3372 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3373 return;
3374 }
3375
3376 displayed_insecure_content_ = true;
3377 SSLManager::NotifySSLInternalStateChanged(
3378 GetController().GetBrowserContext());
3379}
3380
3381void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3382 const GURL& security_origin,
3383 const GURL& url,
3384 const std::string& security_info) {
3385 SSLStatus ssl;
3386 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3387 bad_message::ReceivedBadMessage(
3388 GetRenderProcessHost(),
3389 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3390 return;
3391 }
3392
3393 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3394 SSLManager::NotifySSLInternalStateChanged(
3395 GetController().GetBrowserContext());
3396}
3397
[email protected]501052ff2014-02-21 22:19:073398void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113399 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473400 return;
naskofbd033392015-01-27 02:34:473401
[email protected]1d62cf72014-02-07 21:31:573402 RenderFrameHostImpl* rfh =
3403 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143404 FOR_EACH_OBSERVER(
3405 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183406}
3407
naskofbd033392015-01-27 02:34:473408void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113409 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123410 return;
[email protected]a1b99262013-12-27 21:56:223411
[email protected]8b3af1e2014-01-24 13:29:123412 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443413 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373414 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423415 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373416
[email protected]61ac9e242014-03-21 20:55:263417 RenderFrameHostImpl* rfh =
3418 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143419 FOR_EACH_OBSERVER(
3420 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313421}
3422
[email protected]b172aee2012-04-10 17:05:263423void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573424 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3425 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263426}
3427
[email protected]b172aee2012-04-10 17:05:263428void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303429 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263430 minimum_zoom_percent_ = minimum_percent;
3431 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263432}
3433
mcnee432e47d2015-11-09 19:37:463434void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3435 bool is_one = page_scale_factor == 1.f;
3436 if (is_one != page_scale_factor_is_one_) {
3437 page_scale_factor_is_one_ = is_one;
3438
3439 HostZoomMapImpl* host_zoom_map =
3440 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3441
3442 if (host_zoom_map && GetRenderProcessHost()) {
3443 host_zoom_map->SetPageScaleFactorIsOneForView(
3444 GetRenderProcessHost()->GetID(), GetRoutingID(),
3445 page_scale_factor_is_one_);
3446 }
3447 }
3448
3449 FOR_EACH_OBSERVER(WebContentsObserver,
3450 observers_,
3451 OnPageScaleFactorChanged(page_scale_factor));
3452}
3453
[email protected]b172aee2012-04-10 17:05:263454void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343455 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433456 if (!delegate_)
3457 return;
3458
[email protected]b9535422012-02-09 01:47:593459 ChildProcessSecurityPolicyImpl* policy =
3460 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223461 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593462 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213463}
3464
[email protected]b172aee2012-04-10 17:05:263465void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3466 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263467 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363468 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433469 if (!delegate_)
3470 return;
3471
[email protected]b9535422012-02-09 01:47:593472 ChildProcessSecurityPolicyImpl* policy =
3473 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323474 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593475 return;
[email protected]8f810632013-06-06 22:33:323476
[email protected]c125e532014-05-10 20:39:063477 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203478}
3479
[email protected]f5273e52014-07-14 16:30:203480void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3481 const GURL& url,
3482 bool user_gesture) {
3483 if (!delegate_)
3484 return;
3485
3486 ChildProcessSecurityPolicyImpl* policy =
3487 ChildProcessSecurityPolicyImpl::GetInstance();
3488 if (policy->IsPseudoScheme(protocol))
3489 return;
3490
3491 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3492}
3493
kouhei40f03cb2015-09-24 07:47:013494void WebContentsImpl::OnUpdatePageImportanceSignals(
3495 const PageImportanceSignals& signals) {
3496 page_importance_signals_ = signals;
3497}
3498
[email protected]b172aee2012-04-10 17:05:263499void WebContentsImpl::OnFindReply(int request_id,
3500 int number_of_matches,
3501 const gfx::Rect& selection_rect,
3502 int active_match_ordinal,
3503 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173504 // Forward the find reply to the FindRequestManager, along with the
3505 // RenderFrameHost associated with the frame that the reply came from.
3506 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3507 request_id,
3508 number_of_matches,
3509 selection_rect,
3510 active_match_ordinal,
3511 final_update);
[email protected]b888919c2011-09-02 00:32:163512}
3513
mfomitchev2b8b066a2016-01-28 19:23:153514#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313515void WebContentsImpl::OnFindMatchRectsReply(
3516 int version,
3517 const std::vector<gfx::RectF>& rects,
3518 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173519 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3520 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313521}
[email protected]583418cc2013-01-17 14:01:103522
[email protected]1ff427972013-02-07 21:14:073523void WebContentsImpl::OnOpenDateTimeDialog(
3524 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173525 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093526 GetRenderViewHost(),
3527 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133528 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093529 value.minimum,
3530 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173531 value.step,
3532 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103533}
[email protected]59363fc92012-09-05 03:46:313534#endif
3535
avi60bd4902015-09-23 20:39:243536void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3537 std::string json = json_string;
3538 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3539 Source<WebContents>(this),
3540 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403541}
3542
[email protected]b172aee2012-04-10 17:05:263543void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3544 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103545 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253546 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103547 AppCacheAccessed(manifest_url, blocked_by_policy));
3548}
3549
[email protected]8bc5ff02013-11-29 06:34:033550void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483551 int color_chooser_id,
3552 SkColor color,
3553 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113554 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003555 return;
nasko907fcb62015-01-28 04:24:113556
[email protected]aa62afd2014-04-22 19:22:463557 ColorChooser* new_color_chooser = delegate_ ?
3558 delegate_->OpenColorChooser(this, color, suggestions) :
3559 NULL;
[email protected]820957a2014-01-14 14:56:303560 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213561 return;
[email protected]8ed16472014-04-11 19:02:483562 if (color_chooser_info_.get())
3563 color_chooser_info_->chooser->End();
3564
3565 color_chooser_info_.reset(new ColorChooserInfo(
3566 render_frame_message_source_->GetProcess()->GetID(),
3567 render_frame_message_source_->GetRoutingID(),
3568 new_color_chooser,
3569 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203570}
3571
[email protected]b172aee2012-04-10 17:05:263572void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483573 if (color_chooser_info_ &&
3574 color_chooser_id == color_chooser_info_->identifier)
3575 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203576}
3577
[email protected]b172aee2012-04-10 17:05:263578void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323579 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483580 if (color_chooser_info_ &&
3581 color_chooser_id == color_chooser_info_->identifier)
3582 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203583}
3584
[email protected]d0759f492012-04-19 22:50:503585// This exists for render views that don't have a WebUI, but do have WebUI
3586// bindings enabled.
3587void WebContentsImpl::OnWebUISend(const GURL& source_url,
3588 const std::string& name,
3589 const base::ListValue& args) {
3590 if (delegate_)
3591 delegate_->WebUISend(this, source_url, name, args);
3592}
3593
thestigc4cac8f2014-09-04 21:17:503594#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003595void WebContentsImpl::OnPepperInstanceCreated() {
3596 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3597}
3598
3599void WebContentsImpl::OnPepperInstanceDeleted() {
3600 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3601}
3602
tommyclie6633ca72014-10-31 00:40:423603void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3604 const base::FilePath& path,
3605 bool is_hung) {
3606 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3607
3608 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3609 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3610}
3611
3612void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3613 base::ProcessId plugin_pid) {
3614 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3615 PluginCrashed(plugin_path, plugin_pid));
3616}
3617
[email protected]d8415ad92012-08-23 14:40:503618void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443619 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503620 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343621 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163622 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443623 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163624 return;
[email protected]d8415ad92012-08-23 14:40:503625 }
3626
[email protected]8c8fc292012-11-23 18:57:163627 if (!delegate_->RequestPpapiBrokerPermission(
3628 this, url, plugin_path,
3629 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443630 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163631 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443632 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163633 }
[email protected]d8415ad92012-08-23 14:40:503634}
3635
[email protected]ea0309c2013-08-06 19:35:443636void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503637 bool result) {
[email protected]ea0309c2013-08-06 19:35:443638 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503639}
3640
fsamuel833ee7c2015-02-13 23:40:403641void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3642 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393643 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143644 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403645 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373646}
tommyclie6633ca72014-10-31 00:40:423647#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373648
[email protected]795c28972012-12-06 06:13:393649void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393650 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063651 // We get updated favicon URLs after the page stops loading. If a cross-site
3652 // navigation occurs while a page is still loading, the initial page
3653 // may stop loading and send us updated favicon URLs after the navigation
3654 // for the new page has committed.
3655 RenderViewHostImpl* rvhi =
3656 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3657 if (!rvhi->is_active())
3658 return;
3659
[email protected]795c28972012-12-06 06:13:393660 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293661 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393662}
3663
avayvod41634b12015-07-08 17:07:053664void WebContentsImpl::OnMediaSessionStateChanged() {
3665 MediaSession* session = MediaSession::Get(this);
3666 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3667 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543668 session->IsSuspended(),
3669 session->metadata()));
avayvod41634b12015-07-08 17:07:053670}
3671
3672void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523673 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053674}
3675
3676void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523677 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053678}
3679
mlamouri4c4fbed2015-08-17 15:51:013680void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523681 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013682}
3683
[email protected]50279492014-05-05 23:24:293684void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153685 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293686 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283687
peter90afaba2015-06-01 12:05:293688 did_first_visually_non_empty_paint_ = true;
3689
yusufod41c5f92015-03-06 00:14:283690 if (theme_color_ != last_sent_theme_color_) {
3691 // Theme color should have updated by now if there was one.
3692 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3693 DidChangeThemeColor(theme_color_));
3694 last_sent_theme_color_ = theme_color_;
3695 }
[email protected]9f268072013-11-07 00:02:153696}
[email protected]d9030b82013-07-19 08:26:063697
[email protected]e67ebf32013-02-13 11:07:193698void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013699 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073700 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013701
estark5ea80e52015-06-19 18:43:123702 SecurityStyleExplanations security_style_explanations;
3703 SecurityStyle security_style =
3704 delegate_->GetSecurityStyle(this, &security_style_explanations);
3705 FOR_EACH_OBSERVER(
3706 WebContentsObserver, observers_,
3707 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013708 }
[email protected]e67ebf32013-02-13 11:07:193709}
3710
[email protected]17e286e2013-03-01 23:29:393711void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3712 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3713 BeforeFormRepostWarningShow());
3714}
3715
[email protected]ec6c05f2013-10-23 18:41:573716void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3717 Activate();
3718 if (delegate_)
3719 delegate_->ShowRepostFormWarningDialog(this);
3720}
3721
[email protected]b4c84012014-04-28 19:51:103722bool WebContentsImpl::HasAccessedInitialDocument() {
3723 return has_accessed_initial_document_;
3724}
3725
[email protected]b172aee2012-04-10 17:05:263726void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463727 // If we are creating a RVH for a restored controller, then we need to make
3728 // sure the RenderView starts with a next_page_id_ larger than the number
3729 // of restored entries. This must be called before the RenderView starts
3730 // navigating (to avoid a race between the browser updating max_page_id and
3731 // the renderer updating next_page_id_). Because of this, we only call this
3732 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563733 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583734 if (max_restored_page_id >
3735 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3736 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3737 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323738}
3739
[email protected]b172aee2012-04-10 17:05:263740bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263741 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323742 // For file URLs without a title, use the pathname instead. In the case of a
3743 // synthesized title, we don't want the update to count toward the "one set
3744 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263745 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323746 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513747 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243748 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323749 explicit_set = false; // Don't count synthetic titles toward the set limit.
3750 } else {
[email protected]8af69c6c2014-03-03 19:05:313751 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323752 explicit_set = true;
3753 }
3754
[email protected]987fc3a2011-05-26 14:18:093755 // If a page is created via window.open and never navigated,
3756 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553757 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093758 if (entry) {
[email protected]36fc0392011-12-25 03:59:513759 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093760 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323761
[email protected]36fc0392011-12-25 03:59:513762 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093763 } else {
3764 if (page_title_when_no_navigation_entry_ == final_title)
3765 return false; // Nothing changed, don't bother.
3766
3767 page_title_when_no_navigation_entry_ = final_title;
3768 }
[email protected]420ae012009-04-24 05:16:323769
[email protected]420ae012009-04-24 05:16:323770 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233771 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323772
[email protected]66798902013-10-01 18:40:163773 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533774 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163775
[email protected]420ae012009-04-24 05:16:323776 return true;
3777}
3778
fdegansa696e5112015-04-17 01:57:593779void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003780 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003781 if (delegate_)
fdegansa696e5112015-04-17 01:57:593782 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003783}
3784
3785void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343786 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003787 loading_weak_factory_.InvalidateWeakPtrs();
3788 loading_last_progress_update_ = base::TimeTicks();
3789}
3790
clamy44e84ce2016-02-22 15:38:253791// Notifies the RenderWidgetHost instance about the fact that the page is
3792// loading, or done loading.
3793void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3794 bool due_to_interstitial,
3795 LoadNotificationDetails* details) {
3796 // Do not send notifications about loading changes in the FrameTree while the
3797 // interstitial page is pausing the throbber.
3798 if (ShowingInterstitialPage() &&
3799 GetRenderManager()->interstitial_page()->pause_throbber() &&
3800 !due_to_interstitial) {
3801 return;
3802 }
3803
3804 bool is_loading = IsLoading();
3805
3806 if (!is_loading) {
3807 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3808 base::string16());
3809 load_state_host_.clear();
3810 upload_size_ = 0;
3811 upload_position_ = 0;
3812 }
3813
3814 GetRenderManager()->SetIsLoading(is_loading);
3815
3816 waiting_for_response_ = is_loading;
3817 is_load_to_different_document_ = to_different_document;
3818
3819 if (delegate_)
3820 delegate_->LoadingStateChanged(this, to_different_document);
3821 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3822
3823 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3824 if (is_loading) {
3825 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3826 this, "URL", url, "Main FrameTreeNode id",
3827 GetFrameTree()->root()->frame_tree_node_id());
3828 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3829 } else {
3830 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3831 this, "URL", url);
3832 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3833 }
3834
3835 // TODO(avi): Remove. http://crbug.com/170921
3836 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3837 NotificationDetails det = NotificationService::NoDetails();
3838 if (details)
3839 det = Details<LoadNotificationDetails>(details);
3840 NotificationService::current()->Notify(
3841 type, Source<NavigationController>(&controller_), det);
3842}
3843
[email protected]02d7b6e2014-06-24 21:01:503844void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3845 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323846 // After sending out a swap notification, we need to send a disconnect
3847 // notification so that clients that pick up a pointer to |this| can NULL the
3848 // pointer. See Bug 1230284.
3849 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113850 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283851 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113852
[email protected]7a846df2012-09-20 19:17:393853 // Ensure that the associated embedder gets cleared after a RenderViewHost
3854 // gets swapped, so we don't reuse the same embedder next time a
3855 // RenderViewHost is attached to this WebContents.
3856 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323857}
3858
[email protected]02d7b6e2014-06-24 21:01:503859void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3860 RenderFrameHost* new_host) {
3861 FOR_EACH_OBSERVER(WebContentsObserver,
3862 observers_,
3863 RenderFrameHostChanged(old_host, new_host));
3864}
3865
[email protected]da7a7182013-09-06 08:11:113866// TODO(avi): Remove this entire function because this notification is already
3867// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263868void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323869 if (!notify_disconnection_)
3870 return;
3871
3872 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213873 NotificationService::current()->Notify(
3874 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3875 Source<WebContents>(this),
3876 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323877}
3878
[email protected]cbb1ef592013-06-05 19:49:463879void WebContentsImpl::NotifyNavigationEntryCommitted(
3880 const LoadCommittedDetails& load_details) {
3881 FOR_EACH_OBSERVER(
3882 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3883}
3884
[email protected]f114fa42013-12-06 17:06:443885bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3886 const IPC::Message& message) {
3887 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313888}
3889
[email protected]c31a84802014-04-03 15:55:493890const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3891 return GetLastCommittedURL();
3892}
3893
[email protected]b849847b2013-12-10 21:57:583894void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583895 FOR_EACH_OBSERVER(WebContentsObserver,
3896 observers_,
3897 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303898 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453899
3900 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3901 return;
3902
3903 NavigationEntry* entry = controller_.GetPendingEntry();
3904 if (entry && entry->IsViewSourceMode()) {
3905 // Put the renderer in view source mode.
3906 render_frame_host->Send(
3907 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3908 }
[email protected]b849847b2013-12-10 21:57:583909}
3910
3911void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3912 FOR_EACH_OBSERVER(WebContentsObserver,
3913 observers_,
3914 RenderFrameDeleted(render_frame_host));
3915}
3916
[email protected]a09d53ce2014-01-31 00:46:423917void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3918 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103919 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423920 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103921 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423922 return;
3923
[email protected]077e704b2014-05-23 19:24:103924 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3925 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423926}
3927
[email protected]87de04b02014-04-08 22:14:493928void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013929 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493930 const base::string16& message,
3931 const base::string16& default_prompt,
3932 const GURL& frame_url,
3933 JavaScriptMessageType javascript_message_type,
3934 IPC::Message* reply_msg) {
3935 // Suppress JavaScript dialogs when requested. Also suppress messages when
3936 // showing an interstitial as it's shown over the previous page and we don't
3937 // want the hidden page's dialogs to interfere with the interstitial.
3938 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503939 ShowingInterstitialPage() || !delegate_ ||
3940 delegate_->ShouldSuppressDialogs(this) ||
3941 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493942
3943 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:503944 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493945 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:033946 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:413947 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013948 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413949 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493950 &suppress_this_message);
3951 }
3952
3953 if (suppress_this_message) {
3954 // If we are suppressing messages, just reply as if the user immediately
3955 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013956 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3957 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283958 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493959 }
3960
3961 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3962 // http://crbug.com/288961 ). The only safe thing to do here is return.
3963}
3964
3965void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013966 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493967 bool is_reload,
3968 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013969 RenderFrameHostImpl* rfhi =
3970 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493971 if (delegate_)
3972 delegate_->WillRunBeforeUnloadConfirm();
3973
3974 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:453975 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:023976 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503977 delegate_->ShouldSuppressDialogs(this) ||
3978 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493979 if (suppress_this_message) {
3980 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3981 return;
3982 }
3983
3984 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503985 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493986 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:423987 this, is_reload,
[email protected]87de04b02014-04-08 22:14:493988 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013989 render_frame_host->GetProcess()->GetID(),
3990 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283991 false));
[email protected]87de04b02014-04-08 22:14:493992}
3993
[email protected]a86c0e962013-12-17 17:10:393994WebContents* WebContentsImpl::GetAsWebContents() {
3995 return this;
3996}
3997
[email protected]7912e822014-04-16 02:37:033998bool WebContentsImpl::IsNeverVisible() {
3999 if (!delegate_)
4000 return false;
4001 return delegate_->IsNeverVisible(this);
4002}
4003
[email protected]5a3bdf52012-05-24 15:12:574004RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4005 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324006}
4007
[email protected]8ff00d72012-10-23 19:12:214008RendererPreferences WebContentsImpl::GetRendererPrefs(
4009 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464010 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514011}
4012
avic3aa8422015-11-09 20:57:224013gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
4014 RenderWidgetHostImpl* render_widget_host) const {
4015 if (!RenderViewHostImpl::From(render_widget_host))
4016 return gfx::Rect();
4017
[email protected]b7a756d42012-01-23 18:08:174018 if (delegate_)
4019 return delegate_->GetRootWindowResizerRect();
4020 return gfx::Rect();
4021}
4022
[email protected]7a846df2012-09-20 19:17:394023void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274024 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394025 browser_plugin_embedder_.reset();
4026}
4027
[email protected]b172aee2012-04-10 17:05:264028void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444029 // Don't send notifications if we are just creating a swapped-out RVH for
4030 // the opener chain. These won't be used for view-source or WebUI, so it's
4031 // ok to return early.
creiscce56cd2014-09-29 22:45:224032 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444033 return;
4034
[email protected]86f98a22013-03-20 14:35:004035 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314036 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084037
[email protected]8ff00d72012-10-23 19:12:214038 NotificationService::current()->Notify(
4039 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4040 Source<WebContents>(this),
4041 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324042
[email protected]60780f412013-02-25 16:34:104043 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264044
4045 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254046 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324047}
4048
[email protected]b172aee2012-04-10 17:05:264049void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524050 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324051 // Don't notify the world, since this came from a renderer in the
4052 // background.
4053 return;
4054 }
4055
[email protected]da7a7182013-09-06 08:11:114056 notify_disconnection_ = true;
4057 // TODO(avi): Remove. http://crbug.com/170921
4058 NotificationService::current()->Notify(
4059 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4060 Source<WebContents>(this),
4061 NotificationService::NoDetails());
4062
[email protected]be1f56ab2011-12-22 06:55:314063 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234064 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304065
4066 // Restore the focus to the tab (otherwise the focus will be on the top
4067 // window).
[email protected]484ae5912010-09-29 19:16:144068 if (was_crashed && !FocusLocationBarByDefault() &&
4069 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064070 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144071 }
[email protected]32ded2212011-11-10 18:51:434072
[email protected]d8c660432011-12-22 20:51:254073 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324074}
4075
[email protected]ec6a7eb2013-04-22 17:34:224076void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4077 base::TerminationStatus status,
4078 int error_code) {
[email protected]151a63d2011-12-20 22:32:524079 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324080 // The pending page's RenderViewHost is gone.
4081 return;
4082 }
4083
[email protected]2fcdcc32014-03-05 02:14:074084 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4085 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524086 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464087 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074088
[email protected]698191dc2014-02-25 01:06:134089 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174090 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134091
[email protected]f738bdcb2014-07-11 20:40:444092 if (delegate_)
4093 delegate_->HideValidationMessage(this);
4094
[email protected]960b0372014-05-19 18:01:004095 // Reset the loading progress. TODO(avi): What does it mean to have a
4096 // "renderer crash" when there is more than one renderer process serving a
4097 // webpage? Once this function is called at a more granular frame level, we
4098 // probably will need to more granularly reset the state here.
4099 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254100 NotifyDisconnected();
4101 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004102
[email protected]d8c660432011-12-22 20:51:254103 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274104 observers_,
[email protected]58d5cfe2013-07-10 02:40:524105 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324106}
4107
[email protected]b172aee2012-04-10 17:05:264108void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254109 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064110}
4111
[email protected]b172aee2012-04-10 17:05:264112void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104113 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044114 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384115 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4116
creise1d3e5b2014-12-01 18:21:574117 // Ensure that this state update comes from a RenderViewHost that belongs to
4118 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414119 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574120 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414121 return;
[email protected]420ae012009-04-24 05:16:324122
avi286019ce2015-07-29 01:26:584123 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324124 // when the user is scrolling and entering form data, as well as when we're
4125 // leaving a page, in which case our state may have already been moved to
4126 // the next page. The navigation controller will look up the appropriate
4127 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584128 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114129 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584130 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114131 if (!entry)
[email protected]420ae012009-04-24 05:16:324132 return;
[email protected]420ae012009-04-24 05:16:324133
nasko346969912015-12-16 22:36:474134 // Sanity check that ensures nav_entry_id and page_id point to the same
4135 // navigation entry.
4136 if (rvhi->GetMainFrame()) {
4137 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4138 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4139 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534140
nasko346969912015-12-16 22:36:474141 DCHECK_EQ(entry, new_entry);
4142 }
creisd63f6c4a2015-11-06 19:05:534143
[email protected]691aa2f2013-05-28 22:52:044144 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324145 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044146 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114147 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324148}
4149
sky8b00392d2015-01-10 00:30:284150void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4151 const GURL& url) {
4152 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4153 // If we're fullscreen only update the url if it's from the fullscreen
4154 // renderer.
4155 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444156 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284157 return;
4158 }
[email protected]6934a702011-12-20 00:04:514159 if (delegate_)
avi450ce00e2014-09-24 01:58:524160 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324161}
4162
[email protected]b172aee2012-04-10 17:05:264163void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104164#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294165 // The UI may be in an event-tracking loop, such as between the
4166 // mouse-down and mouse-up in text selection or a button click.
4167 // Defer the close until after tracking is complete, so that we
4168 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294169 // TODO(shess): This could get more fine-grained. For instance,
4170 // closing a tab in another window while selecting text in the
4171 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104172 if (view_->IsEventTracking()) {
4173 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294174 return;
4175 }
[email protected]60780f412013-02-25 16:34:104176#endif
[email protected]07707302009-11-06 00:50:294177
[email protected]420ae012009-04-24 05:16:324178 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524179 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514180 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324181}
4182
[email protected]66bbadaf2014-03-28 16:25:544183void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574184 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4185 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574186}
4187
[email protected]b172aee2012-04-10 17:05:264188void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514189 if (delegate_ && delegate_->IsPopupOrPanel(this))
4190 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324191}
4192
fdegansa696e5112015-04-17 01:57:594193void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094194 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254195 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084196
4197 // Notify accessibility that the user is navigating away from the
4198 // current document.
4199 //
4200 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084201 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594202 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084203 if (manager)
4204 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324205}
4206
fdegansc73eec22015-03-19 14:47:544207void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084208 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324209
[email protected]9595fd82013-04-19 21:28:494210 // Use the last committed entry rather than the active one, in case a
4211 // pending entry has been created.
4212 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204213 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494214
[email protected]420ae012009-04-24 05:16:324215 // An entry may not exist for a stop when loading an initial blank page or
4216 // if an iframe injected by script into a blank page finishes loading.
4217 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204218 base::TimeDelta elapsed =
4219 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324220
4221 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514222 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324223 elapsed,
4224 &controller_,
4225 controller_.GetCurrentEntryIndex()));
4226 }
4227
clamy44e84ce2016-02-22 15:38:254228 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324229}
4230
fdegansa696e5112015-04-17 01:57:594231void WebContentsImpl::DidChangeLoadProgress() {
4232 double load_progress = frame_tree_.load_progress();
4233
4234 // The delegate is notified immediately for the first and last updates. Also,
4235 // since the message loop may be pretty busy when a page is loaded, it might
4236 // not execute a posted task in a timely manner so the progress report is sent
4237 // immediately if enough time has passed.
4238 base::TimeDelta min_delay =
4239 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4240 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4241 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4242
4243 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4244 // If there is a pending task to send progress, it is now obsolete.
4245 loading_weak_factory_.InvalidateWeakPtrs();
4246
4247 // Notify the load progress change.
4248 SendChangeLoadProgress();
4249
4250 // Clean-up the states if needed.
4251 if (load_progress == 1.0)
4252 ResetLoadProgressState();
4253 return;
4254 }
4255
4256 if (loading_weak_factory_.HasWeakPtrs())
4257 return;
4258
skyostil95082a62015-06-05 19:53:074259 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4260 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4261 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594262 min_delay);
4263}
4264
[email protected]b172aee2012-04-10 17:05:264265void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164266 controller_.DiscardNonCommittedEntries();
4267
4268 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214269 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164270}
4271
[email protected]59167c22013-06-03 18:07:324272void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104273 has_accessed_initial_document_ = true;
4274
[email protected]d1371bf8e2014-04-19 03:26:244275 // We may have left a failed browser-initiated navigation in the address bar
4276 // to let the user edit it and try again. Clear it now that content might
4277 // show up underneath it.
4278 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454279 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244280
[email protected]59167c22013-06-03 18:07:324281 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504282 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324283}
4284
alexmosbe2f4c32015-03-10 02:30:234285void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4286 const std::string& name) {
4287 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4288 FrameNameChanged(render_frame_host, name));
4289}
4290
[email protected]39f2f9252014-05-03 00:54:014291void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294292 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094293 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294294 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094295
4296 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214297 NotificationService::current()->Notify(
4298 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4299 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294300 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084301}
4302
creis8eb8ef22015-11-04 22:51:384303void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4304 const PageState& page_state) {
4305 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4306
4307 // The state update affects the last NavigationEntry associated with the given
4308 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4309 // in the case of an UpdateState from a frame being swapped out). We track
4310 // which entry this is in the RenderFrameHost's nav_entry_id.
4311 RenderFrameHostImpl* rfhi =
4312 static_cast<RenderFrameHostImpl*>(render_frame_host);
4313 NavigationEntryImpl* entry =
4314 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4315 if (!entry)
4316 return;
4317
4318 FrameNavigationEntry* frame_entry =
4319 entry->GetFrameEntry(rfhi->frame_tree_node());
4320 if (!frame_entry)
4321 return;
4322
creisd06a9422015-11-11 03:08:454323 // The SiteInstance might not match if we do a cross-process navigation with
4324 // replacement (e.g., auto-subframe), in which case the swap out of the old
4325 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4326 // has already been replaced and destroyed.
4327 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4328 return;
4329
creis8eb8ef22015-11-04 22:51:384330 if (page_state == frame_entry->page_state())
4331 return; // Nothing to update.
4332
4333 frame_entry->set_page_state(page_state);
4334 controller_.NotifyEntryChanged(entry);
4335}
4336
[email protected]ef3adfc2014-05-11 00:04:544337void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104338 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544339 const base::string16& title,
4340 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544341 // If we have a title, that's a pretty good indication that we've started
4342 // getting useful data.
4343 SetNotWaitingForResponse();
4344
4345 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584346 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544347 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584348 render_frame_host->GetSiteInstance(), page_id);
4349
creis081bc102016-02-26 00:56:274350 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4351 // and intentionally skip updates when the most recent commit was ignored.
4352 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544353
4354 // We can handle title updates when we don't have an entry in
4355 // UpdateTitleForEntry, but only if the update is from the current RVH.
4356 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584357 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544358 return;
4359
4360 // TODO(evan): make use of title_direction.
4361 // http://code.google.com/p/chromium/issues/detail?id=27094
4362 if (!UpdateTitleForEntry(entry, title))
4363 return;
4364
4365 // Broadcast notifications when the UI should be updated.
4366 if (entry == controller_.GetEntryAtOffset(0))
4367 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4368}
4369
4370void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4371 const std::string& encoding) {
4372 SetEncoding(encoding);
4373}
4374
[email protected]39f2f9252014-05-03 00:54:014375void WebContentsImpl::DocumentAvailableInMainFrame(
4376 RenderViewHost* render_view_host) {
4377 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4378 DocumentAvailableInMainFrame());
4379}
naskoc0fceff2015-04-30 15:53:524380
[email protected]e1c3a552012-05-04 20:51:324381void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4382 // Tell the active RenderViewHost to run unload handlers and close, as long
4383 // as the request came from a RenderViewHost in the same BrowsingInstance.
4384 // In most cases, we receive this from a swapped out RenderViewHost.
4385 // It is possible to receive it from one that has just been swapped in,
4386 // in which case we might as well deliver the message anyway.
4387 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524388 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324389}
4390
alexmose7da5a12015-04-09 02:22:164391bool WebContentsImpl::ShouldRouteMessageEvent(
4392 RenderFrameHost* target_rfh,
4393 SiteInstance* source_site_instance) const {
4394 // Allow the message if this WebContents is dedicated to a browser plugin
4395 // guest.
[email protected]0eba810b2012-10-18 03:19:364396 // Note: This check means that an embedder could theoretically receive a
4397 // postMessage from anyone (not just its own guests). However, this is
4398 // probably not a risk for apps since other pages won't have references
4399 // to App windows.
alexmose7da5a12015-04-09 02:22:164400 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4401}
[email protected]f546640b2012-05-15 00:03:494402
alexmos58729042015-06-18 23:20:004403void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164404 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4405 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494406
alexmose7da5a12015-04-09 02:22:164407 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144408 // If this message is going to outer WebContents from inner WebContents,
4409 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4410 // already created a RenderFrameProxyHost for that purpose.
4411 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084412 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144413 return;
4414 }
4415
lfg812874d2016-02-09 22:26:134416 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064417 // We create a RenderFrameProxyHost for the embedder in the guest's render
4418 // process but we intentionally do not expose the embedder's opener chain
4419 // to it.
4420 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4421 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494422 } else {
alexmos58729042015-06-18 23:20:004423 RenderFrameHostImpl* source_rfhi =
4424 static_cast<RenderFrameHostImpl*>(source_rfh);
4425 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394426 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494427 }
4428 }
[email protected]f546640b2012-05-15 00:03:494429}
4430
avib7348942015-12-25 20:57:104431bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264432 const base::string16& message,
avib7348942015-12-25 20:57:104433 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264434 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254435 if (!delegate_)
4436 return false;
4437 return delegate_->AddMessageToConsole(this, level, message, line_no,
4438 source_id);
4439}
4440
dominickn9c7ceaa32016-02-27 01:52:534441void WebContentsImpl::OnUserInteraction(
4442 RenderWidgetHostImpl* render_widget_host,
4443 const blink::WebInputEvent::Type type) {
4444 // Ignore when the renderer is swapped out.
4445 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224446 if (render_widget_host != GetRenderViewHost()->GetWidget())
4447 return;
4448
dominickn2dd142dd2015-10-29 05:30:504449 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4450 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534451
4452 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4453 // Exclude scroll events as user gestures for resource load dispatches.
4454 // rdh is NULL in unittests.
4455 if (rdh && type != blink::WebInputEvent::MouseWheel)
4456 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504457}
4458
[email protected]b172aee2012-04-10 17:05:264459void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444460 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254461 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444462}
4463
avic3aa8422015-11-09 20:57:224464void WebContentsImpl::RendererUnresponsive(
4465 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474466 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4467 OnRendererUnresponsive(render_widget_host));
4468
[email protected]992db4c2011-05-12 15:37:154469 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224470 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154471 return;
4472
creiscce56cd2014-09-29 22:45:224473 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224474 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584475
[email protected]e5fc1632011-08-08 07:51:534476 // Ignore renderer unresponsive event if debugger is attached to the tab
4477 // since the event may be a result of the renderer sitting on a breakpoint.
4478 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364479 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534480 return;
4481
clamy226727e2015-06-29 10:28:474482 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224483 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324484 // Hang occurred while firing the beforeunload/unload handler.
4485 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224486 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324487
[email protected]fa944cb82013-11-15 17:51:214488 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324489 return;
4490
4491 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564492 // nothing we can do to recover. If the hang is in the beforeunload handler,
4493 // pretend the beforeunload listeners have all fired and allow the delegate
4494 // to continue closing; the user will not have the option of cancelling the
4495 // close. Otherwise, pretend the unload listeners have all fired and close
4496 // the tab.
4497 bool close = true;
clamy226727e2015-06-29 10:28:474498 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564499 delegate_->BeforeUnloadFired(this, true, &close);
4500 }
4501 if (close)
avic3aa8422015-11-09 20:57:224502 Close();
[email protected]420ae012009-04-24 05:16:324503 return;
4504 }
4505
creisc014b402015-04-23 16:41:454506 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474507 return;
4508
[email protected]6934a702011-12-20 00:04:514509 if (delegate_)
4510 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324511}
4512
avic3aa8422015-11-09 20:57:224513void WebContentsImpl::RendererResponsive(
4514 RenderWidgetHostImpl* render_widget_host) {
4515 if (render_widget_host != GetRenderViewHost()->GetWidget())
4516 return;
4517
[email protected]6934a702011-12-20 00:04:514518 if (delegate_)
4519 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324520}
4521
[email protected]b172aee2012-04-10 17:05:264522void WebContentsImpl::LoadStateChanged(
4523 const GURL& url,
4524 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104525 uint64_t upload_position,
4526 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544527 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4528 // is fixed.
4529 tracked_objects::ScopedTracker tracking_profile1(
4530 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4531 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324532 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564533 upload_position_ = upload_position;
4534 upload_size_ = upload_size;
jshin1fb76462016-04-05 22:13:034535 load_state_host_ = url_formatter::IDNToUnicode(url.host());
[email protected]9c235f042011-08-10 22:28:214536 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324537 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464538 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224539 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4540 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464541 }
[email protected]420ae012009-04-24 05:16:324542}
4543
[email protected]b172aee2012-04-10 17:05:264544void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554545 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324546 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124547 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4548 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514549 if (delegate_)
4550 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094551 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324552}
4553
[email protected]58d5cfe2013-07-10 02:40:524554void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544555 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234556 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224557 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544558}
4559
[email protected]b172aee2012-04-10 17:05:264560void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104561 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214562 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264563 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4564 // here during container initialization and normal window size will be set
4565 // later. In case of tab duplication this resizing to 0x0 prevents setting
4566 // normal size later so just ignore it.
4567 if (!size.IsEmpty())
4568 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324569}
4570
[email protected]af905902013-10-01 21:38:514571void WebContentsImpl::CancelModalDialogsForRenderManager() {
4572 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544573 // deferrer would prevent us from swapping out. We also clear the state
4574 // because this is a cross-process navigation, which means that it's a new
4575 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174576 //
4577 // Note that we don't bother telling browser_plugin_embedder_ because the
4578 // cross-process navigation will either destroy the browser plugins or not
4579 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514580 if (dialog_manager_)
avi2460c762015-04-17 15:21:544581 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514582}
4583
[email protected]02d7b6e2014-06-24 21:01:504584void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4585 RenderFrameHost* new_host,
4586 bool is_main_frame) {
4587 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054588 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504589 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084590
[email protected]02d7b6e2014-06-24 21:01:504591 // Make sure the visible RVH reflects the new delegate's preferences.
4592 if (delegate_)
4593 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394594
[email protected]02d7b6e2014-06-24 21:01:504595 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4596 }
4597
4598 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544599}
4600
naskof5940b9f2015-03-02 23:04:054601void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4602 RenderViewHost* old_host,
4603 RenderViewHost* new_host) {
4604 NotifyViewSwapped(old_host, new_host);
4605}
4606
[email protected]b172aee2012-04-10 17:05:264607NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194608 return GetController();
[email protected]3a3d47472010-07-15 21:03:544609}
4610
dcheng59716272016-04-09 05:19:084611std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294612 const GURL& url) {
dcheng59716272016-04-09 05:19:084613 return std::unique_ptr<WebUIImpl>(
4614 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324615}
4616
[email protected]10f417c52011-12-28 21:04:234617NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264618 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324619 return controller_.GetLastCommittedEntry();
4620}
4621
lfgbede6392015-09-11 21:54:064622void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4623 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334624 RenderWidgetHostViewBase* rwh_view =
4625 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524626
[email protected]420ae012009-04-24 05:16:324627 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444628 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214629 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064630}
4631
4632bool WebContentsImpl::CreateRenderViewForRenderManager(
4633 RenderViewHost* render_view_host,
4634 int opener_frame_routing_id,
4635 int proxy_routing_id,
4636 const FrameReplicationState& replicated_frame_state) {
4637 TRACE_EVENT0("browser,navigation",
4638 "WebContentsImpl::CreateRenderViewForRenderManager");
4639
4640 if (proxy_routing_id == MSG_ROUTING_NONE)
4641 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324642
[email protected]74ce1ad2011-12-16 21:51:464643 // Make sure we use the correct starting page_id in the new RenderView.
4644 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104645 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584646 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464647
alexmos5ac402d2015-07-09 07:51:104648 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4649 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4650 max_page_id, replicated_frame_state,
4651 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524652 return false;
[email protected]14392a52012-05-02 20:28:444653 }
[email protected]a4127722011-04-27 23:13:524654
avi2b177592014-12-10 02:08:024655 SetHistoryOffsetAndLengthForView(render_view_host,
4656 controller_.GetLastCommittedEntryIndex(),
4657 controller_.GetEntryCount());
4658
[email protected]a220b5932013-09-21 03:47:444659#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504660 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4661 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444662 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444663 if (rwh_view) {
4664 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4665 render_widget_host->WasResized();
4666 }
[email protected]f8233cc2011-05-31 20:24:504667#endif
4668
[email protected]420ae012009-04-24 05:16:324669 return true;
4670}
4671
[email protected]82307f6b2014-08-07 03:30:124672bool WebContentsImpl::CreateRenderFrameForRenderManager(
4673 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044674 int proxy_routing_id,
4675 int opener_routing_id,
japhete6adf142014-10-31 00:01:494676 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044677 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434678 TRACE_EVENT0("browser,navigation",
4679 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124680
4681 RenderFrameHostImpl* rfh =
4682 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044683 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4684 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124685 return false;
4686
4687 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4688 // RenderFrameHost will have to be associated with the appropriate
4689 // RenderWidgetHostView or a new one should be created here.
4690
4691 return true;
4692}
4693
mfomitchev2b8b066a2016-01-28 19:23:154694#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454695
[email protected]155c7f22013-12-09 17:07:184696base::android::ScopedJavaLocalRef<jobject>
4697WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404698 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564699 return GetWebContentsAndroid()->GetJavaObject();
4700}
[email protected]155c7f22013-12-09 17:07:184701
[email protected]0e813a52014-08-13 10:34:564702WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184703 WebContentsAndroid* web_contents_android =
4704 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4705 if (!web_contents_android) {
4706 web_contents_android = new WebContentsAndroid(this);
4707 SetUserData(kWebContentsAndroidKey, web_contents_android);
4708 }
[email protected]0e813a52014-08-13 10:34:564709 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184710}
4711
paulmeyerc0b762b2016-04-13 11:55:174712void WebContentsImpl::ActivateNearestFindResult(float x,
4713 float y) {
4714 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4715}
4716
4717void WebContentsImpl::RequestFindMatchRects(int current_version) {
4718 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4719}
4720
[email protected]7d244f12013-08-22 21:41:514721bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064722 return CreateRenderViewForRenderManager(
4723 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064724 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514725}
[email protected]fc2b46b2014-05-03 16:33:454726
4727#elif defined(OS_MACOSX)
4728
[email protected]75f4df72014-07-16 22:39:424729void WebContentsImpl::SetAllowOtherViews(bool allow) {
4730 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454731}
4732
[email protected]75f4df72014-07-16 22:39:424733bool WebContentsImpl::GetAllowOtherViews() {
4734 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454735}
4736
[email protected]7d244f12013-08-22 21:41:514737#endif
4738
pkotwicz75ca8ffd2016-02-16 23:10:194739void WebContentsImpl::OnDidDownloadImage(
4740 const ImageDownloadCallback& callback,
4741 int id,
4742 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524743 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044744 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524745 mojo::Array<mojo::SizePtr> original_image_sizes) {
4746 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4747 const std::vector<gfx::Size> sizes =
4748 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194749
leon.hancbc4bc3c2016-02-26 07:08:524750 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194751}
4752
[email protected]6fba26d2014-04-29 09:38:284753void WebContentsImpl::OnDialogClosed(int render_process_id,
4754 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264755 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494756 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264757 bool success,
[email protected]fcf75d42013-12-03 20:11:264758 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284759 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4760 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494761 last_dialog_suppressed_ = dialog_was_suppressed;
4762
[email protected]beb440c2009-11-06 04:08:544763 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:234764 // It is possible for the current RenderFrameHost to have changed in the
4765 // meantime. Do not reset the navigation state in that case.
4766 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:254767 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:234768 controller_.DiscardNonCommittedEntries();
4769 }
[email protected]ec8e8b02013-06-19 04:57:104770
[email protected]6d65a462013-06-21 21:29:124771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4772 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544773 }
[email protected]87de04b02014-04-08 22:14:494774
[email protected]beb440c2009-11-06 04:08:544775 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284776 if (rfh) {
4777 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4778 dialog_was_suppressed);
4779 } else {
4780 // Don't leak the sync IPC reply if the RFH or process is gone.
4781 delete reply_msg;
4782 }
[email protected]beb440c2009-11-06 04:08:544783}
4784
[email protected]b172aee2012-04-10 17:05:264785void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544786 if (encoding == last_reported_encoding_)
4787 return;
4788 last_reported_encoding_ = encoding;
4789
4790 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124791 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104792}
[email protected]f45d2a72010-03-08 23:28:354793
[email protected]1ac10dca2013-08-20 20:47:044794bool WebContentsImpl::IsHidden() {
4795 return capturer_count_ == 0 && !should_normally_be_visible_;
4796}
4797
rob97250742015-12-10 17:45:154798int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144799 if (node_ && node_->outer_web_contents())
4800 return node_->outer_contents_frame_tree_node_id();
4801
nick2482a2d2015-12-18 01:39:374802 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144803}
4804
[email protected]b0936d22013-11-28 06:47:364805RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214806 return frame_tree_.root()->render_manager();
4807}
4808
lazyboy8e16ddfd2015-09-28 03:41:564809WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4810 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4811 if (node_)
4812 return node_->outer_web_contents();
4813 } else {
4814 if (GetBrowserPluginGuest())
4815 return GetBrowserPluginGuest()->embedder_web_contents();
4816 }
4817 return nullptr;
4818}
4819
[email protected]f8497342013-02-05 22:15:024820BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394821 return browser_plugin_guest_.get();
4822}
4823
[email protected]738f57a2013-06-29 21:06:544824void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4825 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144826 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544827 browser_plugin_guest_.reset(guest);
4828}
4829
[email protected]f8497342013-02-05 22:15:024830BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394831 return browser_plugin_embedder_.get();
4832}
[email protected]8ff00d72012-10-23 19:12:214833
fsamuel60b42282015-03-10 03:29:144834void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4835 if (browser_plugin_embedder_)
4836 return;
4837 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4838}
4839
[email protected]fc2b46b2014-05-03 16:33:454840gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214841 gfx::Size size;
4842 if (delegate_)
4843 size = delegate_->GetSizeForNewRenderView(this);
4844 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454845 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214846 return size;
4847}
4848
[email protected]ae7eeda2014-07-04 01:53:264849void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4850 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024851 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554852}
4853
[email protected]222f5822014-02-05 23:40:494854void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4855 if (!delegate_)
4856 return;
4857 const gfx::Size new_size = GetPreferredSize();
4858 if (new_size != old_size)
4859 delegate_->UpdatePreferredSize(this, new_size);
4860}
4861
dbeama1b926a2015-08-31 23:17:514862WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4863 const std::string& frame_name) {
4864 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4865 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4866 CreateWebUIControllerForURL(web_ui, url);
4867 if (controller) {
4868 web_ui->AddMessageHandler(new GenericHandler());
4869 web_ui->SetController(controller);
4870 return web_ui;
4871 }
4872
4873 delete web_ui;
4874 return NULL;
4875}
4876
paulmeyerc0b762b2016-04-13 11:55:174877FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
4878 // TODO(paulmeyer): This method will need to access (or potentially create)
4879 // the FindRequestManager in the outermost WebContents once find-in-page
4880 // across GuestViews is implemented.
4881 if (!find_request_manager_)
4882 find_request_manager_.reset(new FindRequestManager(this));
4883
4884 return find_request_manager_.get();
4885}
4886
4887void WebContentsImpl::NotifyFindReply(int request_id,
4888 int number_of_matches,
4889 const gfx::Rect& selection_rect,
4890 int active_match_ordinal,
4891 bool final_update) {
4892 if (delegate_) {
4893 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
4894 active_match_ordinal, final_update);
4895 }
4896}
4897
4898#if defined(OS_ANDROID)
4899void WebContentsImpl::NotifyFindMatchRectsReply(
4900 int version,
4901 const std::vector<gfx::RectF>& rects,
4902 const gfx::RectF& active_rect) {
4903 if (delegate_)
4904 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
4905}
4906#endif
4907
[email protected]34ff1cfc2014-08-20 06:16:054908void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4909 force_disable_overscroll_content_ = force_disable;
4910 if (view_)
4911 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4912}
4913
dalecurtis88c240072015-12-09 02:11:184914void WebContentsImpl::MediaStartedPlaying(
4915 const WebContentsObserver::MediaPlayerId& id) {
4916 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4917}
4918
4919void WebContentsImpl::MediaStoppedPlaying(
4920 const WebContentsObserver::MediaPlayerId& id) {
4921 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4922}
4923
tapted65ff2ea72016-03-01 23:39:004924void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4925 if (!did_first_set_visible_) {
4926 // If this WebContents has not yet been set to be visible for the first
4927 // time, ignore any requests to make it hidden, since resources would
4928 // immediately be destroyed and only re-created after content loaded. In
4929 // this state the window content is undefined and can show garbage.
4930 // However, the page load mechanism requires an activation call through a
4931 // visibility call to (re)load.
4932 if (visible) {
4933 did_first_set_visible_ = true;
4934 WasShown();
4935 }
4936 return;
4937 }
4938 if (visible == should_normally_be_visible_)
4939 return;
4940
4941 if (visible)
4942 WasShown();
4943 else
4944 WasHidden();
4945}
4946
aelias5252baa2016-04-10 01:18:024947void WebContentsImpl::UpdateOverridingUserAgent() {
4948 std::set<RenderViewHost*> render_view_host_set;
4949 for (FrameTreeNode* node : frame_tree_.Nodes()) {
4950 RenderWidgetHost* render_widget_host =
4951 node->current_frame_host()->GetRenderWidgetHost();
4952 if (!render_widget_host)
4953 continue;
4954 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
4955 if (!render_view_host)
4956 continue;
4957 render_view_host_set.insert(render_view_host);
4958 }
4959 for (RenderViewHost* render_view_host : render_view_host_set)
4960 render_view_host->OnWebkitPreferencesChanged();
4961}
4962
avid53461d2016-02-25 17:15:044963void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
4964 JavaScriptDialogManager* dialog_manager) {
4965 dialog_manager_ = dialog_manager;
4966}
4967
[email protected]8ff00d72012-10-23 19:12:214968} // namespace content