blob: efb92b12f9284cd5bd3c9938884c7443cfeac6f7 [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"
[email protected]b5a40842012-11-28 15:26:1171#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5872#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0373#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5674#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1475#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4276#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4477#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1778#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0779#include "content/common/page_messages.h"
avi286019ce2015-07-29 01:26:5880#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5181#include "content/common/ssl_status_serialization.h"
ekaramad2bd4a2f2016-04-06 20:12:4682#include "content/common/text_input_state.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),
ekaramad2bd4a2f2016-04-06 20:12:46406 text_input_state_(new TextInputState()),
pkotwicz75ca8ffd2016-02-16 23:10:19407 loading_weak_factory_(this),
408 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55409 frame_tree_.SetFrameRemoveListener(
410 base::Bind(&WebContentsImpl::OnFrameRemoved,
411 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46412#if defined(OS_ANDROID)
413 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
414#else
qinmin58567c82015-01-07 21:00:20415 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46416#endif
csharrisona2280cd2016-02-03 23:21:15417 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12418 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35419}
initial.commit09911bf2008-07-26 23:55:29420
[email protected]b172aee2012-04-10 17:05:26421WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32422 is_being_destroyed_ = true;
423
kenrb2a565f82015-09-02 20:24:59424 rwh_input_event_router_.reset();
425
dcheng72be33c2016-01-21 04:11:31426 for (FrameTreeNode* node : frame_tree_.Nodes()) {
427 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
428 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38429 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38430 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31431 }
carlosk35f35af2015-12-01 10:55:40432
dcheng57e39e22016-01-21 00:25:38433 for (RenderWidgetHostImpl* widget : created_widgets_)
434 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26435 created_widgets_.clear();
436
[email protected]3ab9cb82011-06-03 18:02:07437 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15438 if (dialog_manager_)
avi2460c762015-04-17 15:21:54439 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07440
[email protected]8ed16472014-04-11 19:02:48441 if (color_chooser_info_.get())
442 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20443
[email protected]420ae012009-04-24 05:16:32444 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32445
[email protected]ca13a442012-04-17 14:00:12446 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21447 NotificationService::current()->Notify(
448 NOTIFICATION_WEB_CONTENTS_DESTROYED,
449 Source<WebContents>(this),
450 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32451
[email protected]df0c843f2014-05-23 20:37:23452 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14453 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23454 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59455
clamy0e119882015-07-31 16:12:33456 // Manually call the observer methods for the root frame tree node. It is
457 // necessary to manually delete all objects tracking navigations
458 // (NavigationHandle, NavigationRequest) for observers to be properly
459 // notified of these navigations stopping before the WebContents is
460 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23461 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56462
clamy0e119882015-07-31 16:12:33463 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56464 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33465 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08466 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33467 }
naskob21fe4872015-02-24 14:15:56468 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33469 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08470 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33471
472 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35473 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41474 // Do not update state as the WebContents is being destroyed.
475 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33476 if (root->speculative_frame_host()) {
477 root->speculative_frame_host()->SetRenderFrameCreated(false);
478 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08479 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33480 }
481 }
[email protected]f273ee52013-10-18 16:05:27482
naskoa83483fb2015-02-27 16:57:10483 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
484 FrameDeleted(root->current_frame_host()));
485
[email protected]df0c843f2014-05-23 20:37:23486 if (root->pending_render_view_host()) {
487 FOR_EACH_OBSERVER(WebContentsObserver,
488 observers_,
489 RenderViewDeleted(root->pending_render_view_host()));
490 }
[email protected]c06c58c2014-03-12 20:31:59491
[email protected]f273ee52013-10-18 16:05:27492 FOR_EACH_OBSERVER(WebContentsObserver,
493 observers_,
[email protected]df0c843f2014-05-23 20:37:23494 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27495
[email protected]2db9bd72012-04-13 20:20:56496 FOR_EACH_OBSERVER(WebContentsObserver,
497 observers_,
[email protected]12a46832014-05-09 13:35:58498 WebContentsDestroyed());
499
500 FOR_EACH_OBSERVER(WebContentsObserver,
501 observers_,
502 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08503
[email protected]6934a702011-12-20 00:04:51504 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10505
506 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
507 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42508}
509
[email protected]d1198fd2012-08-13 22:50:19510WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59511 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21512 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03513 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21514 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19515
alexmosaedfc6f2016-01-21 23:57:38516 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
517
alexmose201c7cd2015-06-10 17:14:21518 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38519 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21520 new_contents->created_with_opener_ = true;
521 }
522
alexmosaedfc6f2016-01-21 23:57:38523 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
524 // flags, and these flags take effect immediately. An exception is if the
525 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
526 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
527 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
528 if (opener) {
529 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
530 const blink::WebSandboxFlags inherit_flag =
531 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
532 if ((opener_flags & inherit_flag) == inherit_flag) {
533 new_root->SetPendingSandboxFlags(opener_flags);
534 new_root->CommitPendingSandboxFlags();
535 }
536 }
537
alexmose201c7cd2015-06-10 17:14:21538 // This may be true even when opener is null, such as when opening blocked
539 // popups.
alexmos090fae8e2015-05-28 17:09:28540 if (params.created_with_opener)
541 new_contents->created_with_opener_ = true;
542
[email protected]4858e432014-06-23 18:14:17543 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06544 // This makes |new_contents| act as a guest.
545 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16546 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06547 // We are instantiating a WebContents for browser plugin. Set its subframe
548 // bit to true.
549 new_contents->is_subframe_ = true;
550 }
[email protected]54944cde2012-12-09 09:24:59551 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19552 return new_contents;
553}
554
[email protected]95640212014-07-26 18:14:30555// static
556std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
557 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08558 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30559 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30560 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30561 RenderViewHost* rvh = RenderViewHost::From(rwh);
562 if (!rvh)
563 continue;
564 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
565 if (!web_contents)
566 continue;
avidf38c952015-10-27 13:45:13567 if (web_contents->GetRenderViewHost() != rvh)
568 continue;
569 // Because a WebContents can only have one current RVH at a time, there will
570 // be no duplicate WebContents here.
571 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30572 }
573 return result;
574}
575
clamya16aa8172015-05-26 13:07:25576// static
577WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
578 FrameTreeNode* frame_tree_node) {
579 return static_cast<WebContentsImpl*>(
580 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
581}
582
clamy0d32d6d2015-11-24 11:16:26583// static
584WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
585 int render_frame_host_id) {
586 DCHECK_CURRENTLY_ON(BrowserThread::UI);
587 RenderFrameHost* render_frame_host =
588 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
589 if (!render_frame_host)
590 return nullptr;
591
592 return WebContents::FromRenderFrameHost(render_frame_host);
593}
594
[email protected]b0936d22013-11-28 06:47:36595RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21596 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28597}
598
[email protected]7bb761892012-07-20 09:32:47599bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
600 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44601 return OnMessageReceived(render_view_host, NULL, message);
602}
603
604bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
605 RenderFrameHost* render_frame_host,
606 const IPC::Message& message) {
607 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56608 if (GetWebUI() &&
609 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17610 return true;
[email protected]d2353452012-01-19 19:53:56611 }
[email protected]f82d57b52011-04-27 19:13:17612
brettw5a1613dc2015-06-02 05:34:43613 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25614 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33615 if (render_frame_host) {
616 while ((observer = it.GetNext()) != NULL)
617 if (observer->OnMessageReceived(message, render_frame_host))
618 return true;
619 } else {
620 while ((observer = it.GetNext()) != NULL)
621 if (observer->OnMessageReceived(message))
622 return true;
623 }
[email protected]403415a2011-01-10 18:57:53624
[email protected]1d62cf72014-02-07 21:31:57625 // Message handlers should be aware of which
626 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
627 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02628 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57629 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02630 else
[email protected]1d62cf72014-02-07 21:31:57631 render_view_message_source_ = render_view_host;
632
[email protected]724159a2010-12-30 01:11:18633 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33634 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40635 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
636 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05637 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
638 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48639 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
640 OnDocumentLoadedInFrame)
641 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
642 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
643 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
644 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
645 OnSetSelectedColorInColorChooser)
dglazkov79c426102015-08-31 21:22:43646 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11647 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25648 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18649 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54650 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18651 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54652 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18653 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41654 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
655 OnDidDisplayContentWithCertificateErrors)
656 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
657 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25658 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26659 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46660 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
661 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21662 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48663 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
664 OnRegisterProtocolHandler)
665 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
666 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01667 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
668 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52669 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10670 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50671 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50672#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00673 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
674 OnPepperInstanceCreated)
675 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
676 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42677 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
678 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50679 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
680 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55681 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40682 OnBrowserPluginMessage(render_frame_host,
683 message))
thestigc4cac8f2014-09-04 21:17:50684#endif
[email protected]41225fe2013-03-29 05:32:02685 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07686 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
687 OnShowValidationMessage)
688 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
689 OnHideValidationMessage)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
691 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15692#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52693 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48694 OnFindMatchRectsReply)
695 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
696 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48697#endif
[email protected]724159a2010-12-30 01:11:18698 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33699 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44700 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57701 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18702
[email protected]724159a2010-12-30 01:11:18703 return handled;
704}
705
nasko907fcb62015-01-28 04:24:11706bool WebContentsImpl::HasValidFrameSource() {
707 if (!render_frame_message_source_) {
708 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18709 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
710 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11711 return false;
712 }
713
714 return true;
715}
716
[email protected]b172aee2012-04-10 17:05:26717void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18718 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21719 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43720 if (delegate_)
721 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18722}
723
[email protected]d1198fd2012-08-13 22:50:19724NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56725 return controller_;
726}
727
[email protected]d1198fd2012-08-13 22:50:19728const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56729 return controller_;
730}
731
[email protected]8ff00d72012-10-23 19:12:21732BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55733 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30734}
735
[email protected]b172aee2012-04-10 17:05:26736const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24737 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32738 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51739 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31740}
741
[email protected]a093ce02013-07-22 20:53:14742const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24743 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32744 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24745 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
746}
747
748const GURL& WebContentsImpl::GetLastCommittedURL() const {
749 // We may not have a navigation entry yet.
750 NavigationEntry* entry = controller_.GetLastCommittedEntry();
751 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
752}
753
[email protected]8ff00d72012-10-23 19:12:21754WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31755 return delegate_;
756}
757
[email protected]8ff00d72012-10-23 19:12:21758void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31759 // TODO(cbentzel): remove this debugging code?
760 if (delegate == delegate_)
761 return;
762 if (delegate_)
763 delegate_->Detach(this);
764 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08765 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31766 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08767 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00768 if (view_)
[email protected]e85165c642014-06-10 14:34:31769 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08770 }
[email protected]be1f56ab2011-12-22 06:55:31771}
772
[email protected]8ff00d72012-10-23 19:12:21773RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21774 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41775 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16776}
777
clamydf1975e2015-02-05 19:12:24778RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41779 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16780}
781
nick53d5cbf2015-04-23 22:50:14782RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
783 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
784 if (!focused_node)
785 return nullptr;
786 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07787}
788
rob3e2a0732016-01-06 21:22:09789RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
790 int frame_tree_node_id) {
791 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
792 return frame ? frame->current_frame_host() : nullptr;
793}
794
[email protected]a86c0e962013-12-17 17:10:39795void WebContentsImpl::ForEachFrame(
796 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38797 for (FrameTreeNode* node : frame_tree_.Nodes()) {
798 on_frame.Run(node->current_frame_host());
799 }
[email protected]a86c0e962013-12-17 17:10:39800}
801
dchengafb53e22016-02-04 08:11:08802std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
803 std::vector<RenderFrameHost*> frame_hosts;
804 for (FrameTreeNode* node : frame_tree_.Nodes())
805 frame_hosts.push_back(node->current_frame_host());
806 return frame_hosts;
807}
808
lukaszacbdf52e2016-01-15 21:19:51809int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
810 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08811 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25812 if (!rfh->IsRenderFrameLive())
813 continue;
814
dchengafb53e22016-02-04 08:11:08815 ++number_of_messages;
816 IPC::Message* message_copy = new IPC::Message(*message);
817 message_copy->set_routing_id(rfh->GetRoutingID());
818 rfh->Send(message_copy);
819 }
[email protected]a86c0e962013-12-17 17:10:39820 delete message;
lukaszacbdf52e2016-01-15 21:19:51821 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39822}
823
lfgdb5c4ed2016-03-04 23:09:07824void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
825 frame_tree_.root()->render_manager()->SendPageMessage(msg);
826}
827
creisc014b402015-04-23 16:41:45828RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21829 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31830}
831
[email protected]6b618e62012-08-16 12:59:18832int WebContentsImpl::GetRoutingID() const {
833 if (!GetRenderViewHost())
834 return MSG_ROUTING_NONE;
835
836 return GetRenderViewHost()->GetRoutingID();
837}
838
creis89a0f782015-05-27 16:13:17839void WebContentsImpl::CancelActiveAndPendingDialogs() {
840 if (dialog_manager_)
841 dialog_manager_->CancelActiveAndPendingDialogs(this);
842 if (browser_plugin_embedder_)
843 browser_plugin_embedder_->CancelGuestDialogs();
844}
845
[email protected]44470a22013-01-24 01:21:54846int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
847 return fullscreen_widget_routing_id_;
848}
849
naskoc0fceff2015-04-30 15:53:52850void WebContentsImpl::ClosePage() {
851 GetRenderViewHost()->ClosePage();
852}
853
[email protected]b172aee2012-04-10 17:05:26854RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21855 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31856}
857
[email protected]4aebbca2013-09-17 22:26:49858RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
859 const {
860 RenderWidgetHost* const widget_host =
861 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
862 GetFullscreenWidgetRoutingID());
863 return widget_host ? widget_host->GetView() : NULL;
864}
865
[email protected]8ff00d72012-10-23 19:12:21866WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return view_.get();
868}
869
yusufod41c5f92015-03-06 00:14:28870SkColor WebContentsImpl::GetThemeColor() const {
871 return theme_color_;
872}
873
[email protected]95640212014-07-26 18:14:30874void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
875 if (mode == accessibility_mode_)
876 return;
877
878 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38879
880 for (FrameTreeNode* node : frame_tree_.Nodes()) {
881 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
882 RenderFrameHost* pending_frame_host =
883 node->render_manager()->pending_frame_host();
884 if (pending_frame_host)
885 SetAccessibilityModeOnFrame(mode, pending_frame_host);
886 }
[email protected]95640212014-07-26 18:14:30887}
888
889void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50890 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30891}
892
893void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50894 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30895}
896
dmazzoni83ba5c82015-04-14 07:11:51897void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39898 // Send a request to each of the frames in parallel. Each one will return
899 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
900 // them into a single tree and call |callback| with that result, then
901 // delete |combiner|.
902 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
903 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
904 bool is_root = frame_tree_node->parent() == nullptr;
905 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
906 combiner->AddFrame(is_root));
907 }
dmazzoni83ba5c82015-04-14 07:11:51908}
909
dbeama1b926a2015-08-31 23:17:51910WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
911 const std::string& frame_name) {
912 DCHECK(!frame_name.empty());
913 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22914}
915
[email protected]8ff00d72012-10-23 19:12:21916WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40917 WebUI* commited_web_ui = GetCommittedWebUI();
918 return commited_web_ui ? commited_web_ui
919 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31920}
921
[email protected]8ff00d72012-10-23 19:12:21922WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40923 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34924}
925
[email protected]86ef6a392012-05-11 22:03:11926void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22927 if (GetUserAgentOverride() == override)
928 return;
929
930 renderer_preferences_.user_agent_override = override;
931
932 // Send the new override string to the renderer.
933 RenderViewHost* host = GetRenderViewHost();
934 if (host)
935 host->SyncRendererPrefs();
936
937 // Reload the page if a load is currently in progress to avoid having
938 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27939 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25940 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05941 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53942
943 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
944 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11945}
946
947const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22948 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11949}
950
[email protected]95640212014-07-26 18:14:30951void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08952 if (GetAccessibilityMode() != AccessibilityModeOff) {
953 for (RenderFrameHost* rfh : GetAllFrames())
954 ResetAccessibility(rfh);
955 } else {
dtseng0dd3fa12015-07-22 19:00:52956 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08957 }
[email protected]95640212014-07-26 18:14:30958}
959
960bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
961 return accessibility_mode_ == AccessibilityModeTreeOnly;
962}
963
964bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
965 return accessibility_mode_ == AccessibilityModeComplete;
966}
967
kouhei40f03cb2015-09-24 07:47:01968const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
969 return page_importance_signals_;
970}
971
[email protected]fcf75d42013-12-03 20:11:26972const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55973 // Transient entries take precedence. They are used for interstitial pages
974 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23975 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23976 if (entry) {
jshin1fb76462016-04-05 22:13:03977 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23978 }
carlosk35f35af2015-12-01 10:55:40979
980 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
981 WebUI* our_web_ui = navigating_web_ui
982 ? navigating_web_ui
983 : GetRenderManager()->current_frame_host()->web_ui();
984
[email protected]7ade2732011-02-10 00:13:58985 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54986 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32987 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54988 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35989 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26990 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54991 if (!title.empty())
992 return title;
993 }
994 }
995
996 // We use the title for the last committed entry rather than a pending
997 // navigation entry. For example, when the user types in a URL, we want to
998 // keep the old page's title until the new load has committed and we get a new
999 // title.
[email protected]96d185d2009-04-24 03:28:541000 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321001
creis072b61f2015-09-28 20:52:241002 // We make an exception for initial navigations. We only want to use the title
1003 // from the visible entry if:
1004 // 1. The pending entry has been explicitly assigned a title to display.
1005 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1006 // which case there is a pending entry index other than -1.
1007 //
1008 // Otherwise, we want to stick with the last committed entry's title during
1009 // new navigations, which have pending entries at index -1 with no title.
1010 if (controller_.IsInitialNavigation() &&
1011 ((controller_.GetVisibleEntry() &&
1012 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1013 controller_.GetPendingEntryIndex() != -1)) {
1014 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471015 }
[email protected]59167c22013-06-03 18:07:321016
[email protected]45d0ef7f2011-01-05 13:46:231017 if (entry) {
jshin1fb76462016-04-05 22:13:031018 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231019 }
[email protected]987fc3a2011-05-26 14:18:091020
1021 // |page_title_when_no_navigation_entry_| is finally used
1022 // if no title cannot be retrieved.
1023 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541024}
1025
avib7348942015-12-25 20:57:101026int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461027 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1028}
1029
avib7348942015-12-25 20:57:101030int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261031 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331032 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1033 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461034
[email protected]b6583592012-01-25 19:52:331035 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341036}
1037
avib7348942015-12-25 20:57:101038void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461039 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1040}
1041
[email protected]b172aee2012-04-10 17:05:261042void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101043 SiteInstance* site_instance,
1044 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461045 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331046 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341047}
1048
[email protected]ec6c05f2013-10-23 18:41:571049void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1050 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1051 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571052}
1053
creiscce56cd2014-09-29 22:45:221054SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211055 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541056}
1057
creiscce56cd2014-09-29 22:45:221058SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1059 RenderViewHostImpl* dest_rvh =
1060 GetRenderManager()->pending_render_view_host() ?
1061 GetRenderManager()->pending_render_view_host() :
1062 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581063 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381064}
1065
[email protected]b172aee2012-04-10 17:05:261066bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251067 return frame_tree_.IsLoading() &&
1068 !(ShowingInterstitialPage() &&
1069 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491070}
1071
[email protected]6dfed692014-05-22 04:18:031072bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251073 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031074}
1075
[email protected]b172aee2012-04-10 17:05:261076bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031077 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311078}
1079
[email protected]b172aee2012-04-10 17:05:261080const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311081 return load_state_;
1082}
1083
[email protected]fcf75d42013-12-03 20:11:261084const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311085 return load_state_host_;
1086}
1087
avib7348942015-12-25 20:57:101088uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311089 return upload_size_;
1090}
1091
avib7348942015-12-25 20:57:101092uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311093 return upload_position_;
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541097 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311098}
1099
[email protected]b172aee2012-04-10 17:05:261100bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311101 return displayed_insecure_content_;
1102}
1103
[email protected]222f5822014-02-05 23:40:491104void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251105 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551106 ++capturer_count_;
1107 DVLOG(1) << "There are now " << capturer_count_
1108 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491109
1110 // Note: This provides a hint to upstream code to size the views optimally
1111 // for quality (e.g., to avoid scaling).
1112 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1113 preferred_size_for_capture_ = capture_size;
1114 OnPreferredSizeChanged(preferred_size_);
1115 }
ccameron8807c38f2015-01-17 00:29:191116
1117 // Ensure that all views are un-occluded before capture begins.
1118 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551119}
1120
1121void WebContentsImpl::DecrementCapturerCount() {
1122 --capturer_count_;
1123 DVLOG(1) << "There are now " << capturer_count_
1124 << " capturing(s) of WebContentsImpl@" << this;
1125 DCHECK_LE(0, capturer_count_);
1126
[email protected]5a652232013-02-12 06:15:251127 if (is_being_destroyed_)
1128 return;
1129
[email protected]222f5822014-02-05 23:40:491130 if (capturer_count_ == 0) {
1131 const gfx::Size old_size = preferred_size_for_capture_;
1132 preferred_size_for_capture_ = gfx::Size();
1133 OnPreferredSizeChanged(old_size);
1134 }
1135
[email protected]1ac10dca2013-08-20 20:47:041136 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551137 DVLOG(1) << "Executing delayed WasHidden().";
1138 WasHidden();
1139 }
[email protected]be1f56ab2011-12-22 06:55:311140}
1141
[email protected]f2bd40812013-07-20 04:30:441142int WebContentsImpl::GetCapturerCount() const {
1143 return capturer_count_;
1144}
1145
miu50f97892014-09-22 22:49:521146bool WebContentsImpl::IsAudioMuted() const {
1147 return audio_muter_.get() && audio_muter_->is_muting();
1148}
1149
1150void WebContentsImpl::SetAudioMuted(bool mute) {
1151 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1152 << " for WebContentsImpl@" << this;
1153
1154 if (mute == IsAudioMuted())
1155 return;
1156
1157 if (mute) {
1158 if (!audio_muter_)
1159 audio_muter_.reset(new WebContentsAudioMuter(this));
1160 audio_muter_->StartMuting();
1161 } else {
1162 DCHECK(audio_muter_);
1163 audio_muter_->StopMuting();
1164 }
1165
wjmaclean2f797c782016-01-07 14:52:031166 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1167 DidUpdateAudioMutingState(mute));
1168
miu50f97892014-09-22 22:49:521169 // Notification for UI updates in response to the changed muting state.
1170 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1171}
1172
ortunodf4d7982016-04-08 02:33:351173void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
1174 // Notify for UI updates if the state changes.
1175 bluetooth_connected_device_count_++;
1176 if (bluetooth_connected_device_count_ == 1) {
1177 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1178 }
ortuno32e7db3c2016-03-29 16:14:201179}
1180
ortunodf4d7982016-04-08 02:33:351181void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
1182 // Notify for UI updates if the state changes.
1183 DCHECK(bluetooth_connected_device_count_ != 0);
1184 bluetooth_connected_device_count_--;
1185 if (bluetooth_connected_device_count_ == 0) {
1186 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1187 }
1188}
1189
1190bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1191 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201192}
1193
[email protected]b172aee2012-04-10 17:05:261194bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311195 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1196 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581197 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271198#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581199 crashed_status_ ==
1200 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271201#endif
wfh0d9532a2015-09-02 23:18:581202 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271203 );
[email protected]3c9e1872010-11-18 16:17:491204}
1205
[email protected]b172aee2012-04-10 17:05:261206void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1207 int error_code) {
[email protected]443b80e2010-12-14 00:42:231208 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341209 return;
1210
[email protected]443b80e2010-12-14 00:42:231211 crashed_status_ = status;
1212 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211213 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341214}
1215
[email protected]b172aee2012-04-10 17:05:261216base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311217 return crashed_status_;
1218}
1219
afakhry98241832016-03-11 19:27:471220int WebContentsImpl::GetCrashedErrorCode() const {
1221 return crashed_error_code_;
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311225 return is_being_destroyed_;
1226}
1227
[email protected]7f924832014-08-09 05:57:221228void WebContentsImpl::NotifyNavigationStateChanged(
1229 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541230 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1231 // is fixed.
1232 tracked_objects::ScopedTracker tracking_profile(
1233 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1234 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181235 // Notify the media observer of potential audibility changes.
1236 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271237 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301238 }
1239
[email protected]d5f942ba2008-09-26 19:30:341240 if (delegate_)
1241 delegate_->NavigationStateChanged(this, changed_flags);
1242}
1243
gab0dccfef2015-05-20 18:43:391244base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021245 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331246}
1247
georgesak5582cbe2015-05-22 22:08:071248void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1249 last_active_time_ = last_active_time;
1250}
1251
[email protected]9e2e4632012-07-27 16:38:411252void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541253 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591254
ccameron8807c38f2015-01-17 00:29:191255 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1256 if (view) {
1257 view->Show();
[email protected]789e9152009-08-04 21:59:431258#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191259 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431260#endif
[email protected]de3c5d82014-05-28 22:12:591261 }
[email protected]789e9152009-08-04 21:59:431262 }
[email protected]96d185d2009-04-24 03:28:541263
gab0dccfef2015-05-20 18:43:391264 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381265
[email protected]b9769d82012-02-10 00:23:591266 // The resize rect might have changed while this was inactive -- send the new
1267 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451268 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221269 if (rvh) {
1270 rvh->GetWidget()->ResizeRectChanged(
1271 GetRootWindowResizerRect(rvh->GetWidget()));
1272 }
[email protected]96d185d2009-04-24 03:28:541273
[email protected]c0d9d5672013-10-09 07:38:031274 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1275
[email protected]54597982013-02-06 01:59:551276 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311277}
1278
[email protected]b172aee2012-04-10 17:05:261279void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551280 // If there are entities capturing screenshots or video (e.g., mirroring),
1281 // don't activate the "disable rendering" optimization.
1282 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521283 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551284 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261285 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521286 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331287 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521288 // calls us).
ccameron8807c38f2015-01-17 00:29:191289 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1290 if (view)
1291 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591292 }
[email protected]96d185d2009-04-24 03:28:541293 }
1294
[email protected]c0d9d5672013-10-09 07:38:031295 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1296
[email protected]54597982013-02-06 01:59:551297 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371298}
1299
ccameron8807c38f2015-01-17 00:29:191300void WebContentsImpl::WasOccluded() {
1301 if (capturer_count_ > 0)
1302 return;
1303
1304 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1305 if (view)
1306 view->WasOccluded();
1307 }
1308}
1309
1310void WebContentsImpl::WasUnOccluded() {
1311 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1312 if (view)
1313 view->WasUnOccluded();
1314 }
1315}
1316
[email protected]b172aee2012-04-10 17:05:261317bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311318 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451319 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1320 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311321}
1322
[email protected]1c3f80bd2014-04-08 23:02:061323void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451324 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061325}
1326
lazyboy6ec48b2a2015-06-29 15:18:141327void WebContentsImpl::AttachToOuterWebContentsFrame(
1328 WebContents* outer_web_contents,
1329 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081330 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lfg91a79e12016-04-01 23:52:191331 RenderFrameHostManager* render_manager = GetRenderManager();
1332
1333 // When the WebContents being initialized has an opener, the browser side
1334 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1335 // created. This is needed because the usual initialization happens during
1336 // the first navigation, but when attaching a new window we don't navigate
1337 // before attaching. If the browser side is already initialized, the calls
1338 // below will just early return.
1339 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1340 GetMainFrame()->Init();
1341 if (!render_manager->GetRenderWidgetHostView())
1342 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1343
lazyboy6ec48b2a2015-06-29 15:18:141344 // Create a link to our outer WebContents.
1345 node_.reset(new WebContentsTreeNode());
1346 node_->ConnectToOuterWebContents(
1347 static_cast<WebContentsImpl*>(outer_web_contents),
1348 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1349
1350 DCHECK(outer_contents_frame);
1351
1352 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1353 // SiteInstance of the outer WebContents. The proxy will be used to send
1354 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191355 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141356 outer_contents_frame->GetSiteInstance(),
1357 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1358
lfg91a79e12016-04-01 23:52:191359 render_manager->SetRWHViewForInnerContents(
1360 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391361
1362 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191363 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391364 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141365}
1366
[email protected]b172aee2012-04-10 17:05:261367void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381368 for (FrameTreeNode* node : frame_tree_.Nodes())
1369 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401370 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271371}
1372
[email protected]b172aee2012-04-10 17:05:261373WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441374 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211375 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451376 // before.
[email protected]54944cde2012-12-09 09:24:591377 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451378 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211379 WebContentsImpl* tc =
1380 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191381 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221382 FOR_EACH_OBSERVER(WebContentsObserver,
1383 observers_,
1384 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271385 return tc;
1386}
1387
[email protected]14392a52012-05-02 20:28:441388void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211389 const NotificationSource& source,
1390 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441391 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211392 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1393 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031394 RenderWidgetHostView* view = host->GetView();
1395 if (view == GetFullscreenRenderWidgetHostView()) {
1396 // We cannot just call view_->RestoreFocus() here. On some platforms,
1397 // attempting to focus the currently-invisible WebContentsView will be
1398 // flat-out ignored. Therefore, this boolean is used to track whether
1399 // we will request focus after the fullscreen widget has been
1400 // destroyed.
1401 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1402 } else {
1403 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1404 i != pending_widget_views_.end(); ++i) {
1405 if (host->GetView() == i->second) {
1406 pending_widget_views_.erase(i);
1407 break;
1408 }
[email protected]bafe6cd2012-05-23 23:09:501409 }
1410 }
1411 break;
1412 }
[email protected]14392a52012-05-02 20:28:441413 default:
1414 NOTREACHED();
1415 }
1416}
1417
[email protected]ec6c05f2013-10-23 18:41:571418WebContents* WebContentsImpl::GetWebContents() {
1419 return this;
1420}
1421
[email protected]54944cde2012-12-09 09:24:591422void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211423 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361424 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211425 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431426 should_normally_be_visible_ = !params.initially_hidden;
1427
dcheng3ce04b62015-10-26 23:30:551428 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541429 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551430 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1431 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541432 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551433 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1434 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1435
1436 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1437 if (!site_instance)
1438 site_instance = SiteInstance::Create(params.browser_context);
1439
1440 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1441 // local root by definition.
1442 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1443 // longer be necessary to eagerly grab a routing ID for the view.
1444 // https://crbug.com/545684
1445 int32_t view_routing_id = params.routing_id;
1446 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1447 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1448 view_routing_id = main_frame_widget_routing_id =
1449 site_instance->GetProcess()->GetNextRoutingID();
1450 }
1451
1452 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1453 params.main_frame_routing_id,
1454 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321455
1456 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1457 // frame - let's do the same thing here.
1458 std::string unique_name = params.main_frame_name;
1459 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191460
[email protected]fc2b46b2014-05-03 16:33:451461 WebContentsViewDelegate* delegate =
1462 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1463
fsamueladb0033602015-12-09 19:20:411464#if defined(MOJO_SHELL_CLIENT)
1465 if (MojoShellConnection::Get() &&
1466 base::CommandLine::ForCurrentProcess()->HasSwitch(
1467 switches::kUseMusInRenderer)) {
1468 mus::Window* mus_window = aura::GetMusWindow(params.context);
1469 if (mus_window) {
1470 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1471 &render_view_host_delegate_view_));
1472 }
1473 }
1474#endif
1475
1476 if (!view_) {
1477 view_.reset(CreateWebContentsView(this, delegate,
1478 &render_view_host_delegate_view_));
1479 }
fsamuel9cf7bdf2015-11-20 02:19:321480
lazyboy6ec48b2a2015-06-29 15:18:141481 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081482 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321483 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361484 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321485 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191486 }
[email protected]fc2b46b2014-05-03 16:33:451487 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191488 CHECK(view_.get());
1489
[email protected]ed245db2012-12-18 08:00:451490 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591491 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191492
tommyclieb25b2a2014-11-03 19:45:091493#if defined(ENABLE_PLUGINS)
1494 plugin_content_origin_whitelist_.reset(
1495 new PluginContentOriginWhitelist(this));
1496#endif
1497
[email protected]d1198fd2012-08-13 22:50:191498 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211499 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1500 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101501
[email protected]01f83f92014-06-17 14:41:541502 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091503 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541504
mlamouriefdca9d2014-09-16 16:55:401505 manifest_manager_host_.reset(new ManifestManagerHost(this));
1506
mfomitchev2b8b066a2016-01-28 19:23:151507#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101508 date_time_chooser_.reset(new DateTimeChooserAndroid());
1509#endif
fsamuel7310a4262014-12-05 05:06:441510
1511 // BrowserPluginGuest::Init needs to be called after this WebContents has
1512 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1513 if (browser_plugin_guest_)
1514 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371515
1516 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1517 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561518
1519 // If the WebContents creation was renderer-initiated, it means that the
1520 // corresponding RenderView and main RenderFrame have already been created.
1521 // Ensure observers are notified about this.
1522 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431523 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561524 RenderViewCreated(GetRenderViewHost());
1525 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1526 }
naskof5940b9f2015-03-02 23:04:051527
1528 // Ensure that observers are notified of the creation of this WebContents's
1529 // main RenderFrameHost. It must be done here for main frames, since the
1530 // NotifySwappedFromRenderManager expects view_ to already be created and that
1531 // happens after RenderFrameHostManager::Init.
1532 NotifySwappedFromRenderManager(
1533 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191534}
1535
[email protected]7fff43e2013-05-21 20:21:101536void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1537 RemoveDestructionObserver(web_contents);
1538
[email protected]ceee8cd2013-03-08 04:59:511539 // Clear a pending contents that has been closed before being shown.
1540 for (PendingContents::iterator iter = pending_contents_.begin();
1541 iter != pending_contents_.end();
1542 ++iter) {
1543 if (iter->second != web_contents)
1544 continue;
1545 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511546 return;
1547 }
1548 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441549}
1550
[email protected]7fff43e2013-05-21 20:21:101551void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1552 if (!ContainsKey(destruction_observers_, web_contents)) {
1553 destruction_observers_[web_contents] =
1554 new DestructionObserver(this, web_contents);
1555 }
1556}
1557
1558void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1559 DestructionObservers::iterator iter =
1560 destruction_observers_.find(web_contents);
1561 if (iter != destruction_observers_.end()) {
1562 delete destruction_observers_[web_contents];
1563 destruction_observers_.erase(iter);
1564 }
1565}
1566
[email protected]b172aee2012-04-10 17:05:261567void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311568 observers_.AddObserver(observer);
1569}
1570
[email protected]b172aee2012-04-10 17:05:261571void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311572 observers_.RemoveObserver(observer);
1573}
1574
[email protected]948481d2014-06-11 18:32:221575std::set<RenderWidgetHostView*>
1576WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1577 std::set<RenderWidgetHostView*> set;
1578 if (ShowingInterstitialPage()) {
1579 set.insert(GetRenderWidgetHostView());
1580 } else {
dchengafb53e22016-02-04 08:11:081581 for (RenderFrameHost* rfh : GetAllFrames()) {
1582 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1583 ->frame_tree_node()
1584 ->render_manager()
1585 ->GetRenderWidgetHostView();
1586 set.insert(rwhv);
1587 }
[email protected]948481d2014-06-11 18:32:221588 }
[email protected]de3c5d82014-05-28 22:12:591589 return set;
1590}
1591
[email protected]b172aee2012-04-10 17:05:261592void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341593 if (delegate_)
1594 delegate_->ActivateContents(this);
1595}
1596
avi3e4b8512015-11-11 01:55:491597void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1598 if (!RenderViewHostImpl::From(render_widget_host))
1599 return;
1600
[email protected]63954792011-07-11 04:17:481601 if (delegate_)
1602 delegate_->LostCapture();
1603}
1604
lazyboy63f5b312015-11-23 20:19:521605void WebContentsImpl::RenderWidgetCreated(
1606 RenderWidgetHostImpl* render_widget_host) {
1607 created_widgets_.insert(render_widget_host);
1608}
1609
[email protected]b24b68a2012-09-24 21:57:261610void WebContentsImpl::RenderWidgetDeleted(
1611 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521612 // Note that |is_being_destroyed_| can be true at this point as
1613 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1614 // us here.
1615 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261616
lazyboy63f5b312015-11-23 20:19:521617 if (is_being_destroyed_)
1618 return;
[email protected]44470a22013-01-24 01:21:541619
1620 if (render_widget_host &&
1621 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491622 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531623 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541624 FOR_EACH_OBSERVER(WebContentsObserver,
1625 observers_,
1626 DidDestroyFullscreenWidget(
1627 fullscreen_widget_routing_id_));
1628 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031629 if (fullscreen_widget_had_focus_at_shutdown_)
1630 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541631 }
[email protected]b24b68a2012-09-24 21:57:261632}
1633
miu9e14e492014-10-25 02:39:041634void WebContentsImpl::RenderWidgetGotFocus(
1635 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371636 // Notify the observers if an embedded fullscreen widget was focused.
1637 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1638 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1639 NotifyWebContentsFocused();
1640 }
miu9e14e492014-10-25 02:39:041641}
1642
estaded0a0c992015-01-21 14:12:061643void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311644 RenderWidgetHostImpl* render_widget_host,
1645 bool width_changed) {
creisc014b402015-04-23 16:41:451646 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291647 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061648 return;
estaded0a0c992015-01-21 14:12:061649
rouslan2f5993f2015-01-29 00:18:311650 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1651 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061652}
1653
paulmeyer9ef6e4462015-02-24 19:15:101654void WebContentsImpl::ScreenInfoChanged() {
1655 if (browser_plugin_embedder_)
1656 browser_plugin_embedder_->ScreenInfoChanged();
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659bool WebContentsImpl::PreHandleKeyboardEvent(
1660 const NativeWebKeyboardEvent& event,
1661 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481662 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131663 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481664}
1665
[email protected]b172aee2012-04-10 17:05:261666void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101667 if (browser_plugin_embedder_ &&
1668 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1669 return;
1670 }
[email protected]63954792011-07-11 04:17:481671 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131672 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481673}
1674
[email protected]d92026ef2014-03-03 21:04:131675bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461676 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191677#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331678 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1679 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191680 // -the OS already has a gesture to do this through pinch-zoom
1681 // -if a user starts an inertial scroll, let's go, and presses control
1682 // (i.e. control+tab) then the OS's buffered scroll events will come in
1683 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331684 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551685 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331686 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221687 // Count only integer cumulative scrolls as zoom events; this handles
1688 // smooth scroll and regular scroll device behavior.
1689 zoom_scroll_remainder_ += event.wheelTicksY;
1690 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1691 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1692 if (whole_zoom_scroll_remainder_ != 0) {
1693 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1694 }
[email protected]fb3f066e2013-02-12 19:12:521695 return true;
1696 }
[email protected]bccc4472013-04-18 16:37:191697#endif
[email protected]fb3f066e2013-02-12 19:12:521698 return false;
1699}
1700
[email protected]04bce562014-01-30 05:34:541701bool WebContentsImpl::PreHandleGestureEvent(
1702 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031703 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541704}
1705
kenrb2a565f82015-09-02 20:24:591706RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451707 if (!is_being_destroyed_ && GetOuterWebContents())
1708 return GetOuterWebContents()->GetInputEventRouter();
1709
1710 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591711 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1712 return rwh_input_event_router_.get();
1713}
1714
alexmos3fcd0ca2015-10-23 18:18:331715void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1716 // Focus loss may occur while this WebContents is being destroyed. Don't
1717 // send the message in this case, as the main frame's RenderFrameHost and
1718 // other state has already been cleared.
1719 if (is_being_destroyed_)
1720 return;
1721
1722 frame_tree_.ReplicatePageFocus(is_focused);
1723}
1724
alexmosc4cbacb2015-11-21 01:29:221725RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1726 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521727 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221728 return receiving_widget;
1729
1730 // Events for widgets other than the main frame (e.g., popup menus) should be
1731 // forwarded directly to the widget they arrived on.
1732 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1733 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521734
1735 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1736 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221737 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521738
alexmos732ca3a2015-12-08 02:01:021739 // The view may be null if a subframe's renderer process has crashed while
1740 // the subframe has focus. Drop the event in that case. Do not give
1741 // it to the main frame, so that the user doesn't unexpectedly type into the
1742 // wrong frame if a focused subframe renderer crashes while they type.
1743 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1744 if (!view)
1745 return nullptr;
1746
1747 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521748}
1749
mlamouri7a78d6fd2015-01-17 13:23:531750void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1751 // This method is being called to enter renderer-initiated fullscreen mode.
1752 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491753 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371754 if (widget_view) {
1755 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1756 ->ShutdownAndDestroyWidget(true);
1757 }
[email protected]4aebbca2013-09-17 22:26:491758
[email protected]8a5e0ca2011-08-25 06:30:471759 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531760 delegate_->EnterFullscreenModeForTab(this, origin);
1761
1762 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461763 DidToggleFullscreenModeForTab(
1764 IsFullscreenForCurrentTab(
1765 GetRenderViewHost()->GetWidget()),
1766 false));
mlamouri7a78d6fd2015-01-17 13:23:531767}
1768
bokanece34a82016-01-28 19:49:461769void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531770 // This method is being called to leave renderer-initiated fullscreen mode.
1771 // Make sure any existing fullscreen widget is shut down first.
1772 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371773 if (widget_view) {
1774 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1775 ->ShutdownAndDestroyWidget(true);
1776 }
mlamouri7a78d6fd2015-01-17 13:23:531777
hugo.holgersson61288e6c2015-01-28 17:04:401778#if defined(OS_ANDROID)
1779 ContentVideoView* video_view = ContentVideoView::GetInstance();
1780 if (video_view != NULL)
watk98292292016-01-19 22:24:081781 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401782#endif
1783
mlamouri7a78d6fd2015-01-17 13:23:531784 if (delegate_)
1785 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371786
bokanece34a82016-01-28 19:49:461787 // The fullscreen state is communicated to the renderer through a resize
1788 // message. If the change in fullscreen state doesn't cause a view resize
1789 // then we must ensure web contents exit the fullscreen state by explicitly
1790 // sending a resize message. This is required for the situation of the browser
1791 // moving the view into a "browser fullscreen" state and then the contents
1792 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1793 // have the side effect of the view resizing, hence the explicit call here is
1794 // required.
1795 if (!will_cause_resize) {
1796 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1797 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1798 render_widget_host->WasResized();
1799 }
scheib3dcb6c932015-02-23 10:55:581800 }
1801
avibf58fa0c2015-11-11 01:45:521802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461803 DidToggleFullscreenModeForTab(
1804 IsFullscreenForCurrentTab(
1805 GetRenderViewHost()->GetWidget()),
1806 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471807}
1808
avibf58fa0c2015-11-11 01:45:521809bool WebContentsImpl::IsFullscreenForCurrentTab(
1810 RenderWidgetHostImpl* render_widget_host) const {
1811 if (!RenderViewHostImpl::From(render_widget_host))
1812 return false;
1813
[email protected]199bba6e2012-04-04 16:19:381814 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121815}
1816
avibf58fa0c2015-11-11 01:45:521817blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1818 RenderWidgetHostImpl* render_widget_host) const {
1819 if (!RenderViewHostImpl::From(render_widget_host))
1820 return blink::WebDisplayModeBrowser;
1821
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121822 return delegate_ ? delegate_->GetDisplayMode(this)
1823 : blink::WebDisplayModeBrowser;
1824}
1825
avic3aa8422015-11-09 20:57:221826void WebContentsImpl::RequestToLockMouse(
1827 RenderWidgetHostImpl* render_widget_host,
1828 bool user_gesture,
1829 bool last_unlocked_by_target) {
1830 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1831 render_widget_host->GotResponseToLockMouseRequest(false);
1832 return;
[email protected]e9621112011-10-17 05:38:371833 }
avic3aa8422015-11-09 20:57:221834
1835 if (delegate_)
1836 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1837 else
1838 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371839}
1840
avi3e4b8512015-11-11 01:55:491841void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1842 if (!RenderViewHostImpl::From(render_widget_host))
1843 return;
1844
[email protected]e9621112011-10-17 05:38:371845 if (delegate_)
1846 delegate_->LostMouseLock();
1847}
1848
dtrainor5ef644e2015-11-19 00:12:471849void WebContentsImpl::ForwardCompositorProto(
1850 RenderWidgetHostImpl* render_widget_host,
1851 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471852 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291853 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471854}
1855
ekaramada4f42692016-02-11 19:48:371856void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1857 if (visible)
1858 WasShown();
1859 else
1860 WasHidden();
1861}
1862
[email protected]bafe6cd2012-05-23 23:09:501863void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431864 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551865 int32_t route_id,
1866 int32_t main_frame_route_id,
1867 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131868 const ViewHostMsg_CreateWindow_Params& params,
1869 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501870 // We usually create the new window in the same BrowsingInstance (group of
1871 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551872 // if the opener is being suppressed (in a non-guest), we create a new
1873 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251874 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551875
[email protected]04cbd3d2013-12-04 04:58:201876 // If the opener is to be suppressed, the new window can be in any process.
1877 // Since routing ids are process specific, we must not have one passed in
1878 // as argument here.
1879 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1880
[email protected]bafe6cd2012-05-23 23:09:501881 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431882 params.opener_suppressed && !is_guest
1883 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1884 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501885
alexmos4cf2aa32015-07-15 23:40:431886 // A message to create a new window can only come from a process for a frame
1887 // in this WebContents' FrameTree. If any other process sends the request, it
1888 // is invalid and the process must be terminated.
1889 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381890 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431891 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351892 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201893 if (process_handle != base::kNullProcessHandle) {
1894 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391895 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351896 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201897 }
1898 return;
1899 }
1900
[email protected]d1198fd2012-08-13 22:50:191901 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341902 //
1903 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301904 const std::string& partition_id =
1905 GetContentClient()->browser()->
1906 GetStoragePartitionIdForSite(GetBrowserContext(),
1907 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461908 StoragePartition* partition = BrowserContext::GetStoragePartition(
1909 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411910 DOMStorageContextWrapper* dom_storage_context =
1911 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191912 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1913 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1914 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371915
1916 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551917 !delegate_->ShouldCreateWebContents(
1918 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1919 params.window_container_type, params.frame_name, params.target_url,
1920 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011921 if (route_id != MSG_ROUTING_NONE &&
1922 !RenderViewHost::FromID(render_process_id, route_id)) {
1923 // If the embedder didn't create a WebContents for this route, we need to
1924 // delete the RenderView that had already been created.
1925 Send(new ViewMsg_Close(route_id));
1926 }
csharrisona2280cd2016-02-03 23:21:151927 // It's safe to only target the frame because the render process will not
1928 // have a chance to create more frames at this point.
1929 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1930 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371931 return;
1932 }
1933
1934 // Create the new web contents. This will automatically create the new
1935 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461936 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591937 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041938 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551939 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121940 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431941 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211942 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061943 create_params.opener_suppressed = params.opener_suppressed;
1944 if (params.disposition == NEW_BACKGROUND_TAB)
1945 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191946 create_params.renderer_initiated_creation =
1947 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061948
[email protected]4858e432014-06-23 18:14:171949 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551950 if (!is_guest) {
1951 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451952 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171953 new_contents = static_cast<WebContentsImpl*>(
1954 WebContents::Create(create_params));
1955 } else {
1956 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551957 }
[email protected]50d326e2014-05-20 17:59:061958 new_contents->GetController().SetSessionStorageNamespace(
1959 partition_id,
1960 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191961
alexmos646fec02015-07-25 00:11:491962 // If the new frame has a name, make sure any SiteInstances that can find
1963 // this named frame have proxies for it. Must be called after
1964 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1965 // GetSessionStorageNamespace.
1966 if (!params.frame_name.empty())
1967 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1968
[email protected]c4538072013-03-18 02:17:551969 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341970 // will be shown immediately).
1971 if (!params.opener_suppressed) {
1972 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451973 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501974
[email protected]d70bea92013-04-05 04:23:341975 // TODO(brettw): It seems bogus that we have to call this function on the
1976 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431977 new_view->CreateViewForWidget(
1978 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341979 }
[email protected]bafe6cd2012-05-23 23:09:501980 // Save the created window associated with the route so we can show it
1981 // later.
1982 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1983 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101984 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501985 }
1986
1987 if (delegate_) {
1988 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071989 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131990 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501991 }
1992
1993 if (params.opener_suppressed) {
1994 // When the opener is suppressed, the original renderer cannot access the
1995 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001996 bool was_blocked = false;
1997 if (delegate_) {
bokan107a47f2015-02-03 23:23:391998 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001999 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392000 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002001 params.user_gesture, &was_blocked);
2002 }
2003 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:212004 OpenURLParams open_params(params.target_url,
2005 Referrer(),
2006 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352007 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212008 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302009 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372010
2011 if (delegate_ && !is_guest &&
2012 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2013 // We are in asynchronous add new contents path, delay opening url
2014 new_contents->delayed_open_url_params_.reset(
2015 new OpenURLParams(open_params));
2016 } else {
2017 new_contents->OpenURL(open_params);
2018 }
[email protected]eda238a12012-09-07 23:44:002019 }
[email protected]bafe6cd2012-05-23 23:09:502020 }
2021}
2022
avib7348942015-12-25 20:57:102023void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2024 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462025 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052026 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502027}
2028
avib7348942015-12-25 20:57:102029void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2030 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052031 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502032}
2033
avib7348942015-12-25 20:57:102034void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2035 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502036 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462037 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252038 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232039 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512040 // this WebContentsImpl instance. If any other process sends the request,
2041 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382042 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252043 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512044 if (process_handle != base::kNullProcessHandle) {
2045 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392046 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252047 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512048 }
2049 return;
2050 }
2051
[email protected]bafe6cd2012-05-23 23:09:502052 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052053 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262054
[email protected]cfd80b02014-05-01 17:46:482055 RenderWidgetHostViewBase* widget_view =
2056 static_cast<RenderWidgetHostViewBase*>(
2057 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192058 if (!widget_view)
2059 return;
[email protected]bafe6cd2012-05-23 23:09:502060 if (!is_fullscreen) {
2061 // Popups should not get activated.
2062 widget_view->SetPopupType(popup_type);
2063 }
2064 // Save the created widget associated with the route so we can show it later.
2065 pending_widget_views_[route_id] = widget_view;
2066
2067#if defined(OS_MACOSX)
2068 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2069 // to allow it to survive the trip without being hosted.
2070 base::mac::NSObjectRetain(widget_view->GetNativeView());
2071#endif
2072}
2073
2074void WebContentsImpl::ShowCreatedWindow(int route_id,
2075 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392076 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502077 bool user_gesture) {
2078 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002079 if (contents) {
2080 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162081 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382082 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2083 contents->ResumeLoadingCreatedWebContents();
2084
[email protected]eda238a12012-09-07 23:44:002085 if (delegate) {
2086 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392087 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002088 }
2089 }
[email protected]bafe6cd2012-05-23 23:09:502090}
2091
2092void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392093 const gfx::Rect& initial_rect) {
2094 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502095}
2096
2097void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2098 ShowCreatedWidget(route_id, true, gfx::Rect());
2099}
2100
2101void WebContentsImpl::ShowCreatedWidget(int route_id,
2102 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392103 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482104 RenderWidgetHostViewBase* widget_host_view =
2105 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502106 if (!widget_host_view)
2107 return;
[email protected]cfd80b02014-05-01 17:46:482108
2109 RenderWidgetHostView* view = NULL;
2110 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2111 if (guest && guest->embedder_web_contents()) {
2112 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2113 } else {
2114 view = GetRenderWidgetHostView();
2115 }
2116
[email protected]4aebbca2013-09-17 22:26:492117 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312118 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032119 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312120 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492121 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2122 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532123 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492124 } else {
[email protected]cfd80b02014-05-01 17:46:482125 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492126 }
[email protected]4aebbca2013-09-17 22:26:492127 FOR_EACH_OBSERVER(WebContentsObserver,
2128 observers_,
2129 DidShowFullscreenWidget(route_id));
2130 if (!widget_host_view->HasFocus())
2131 widget_host_view->Focus();
2132 } else {
bokan107a47f2015-02-03 23:23:392133 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492134 }
[email protected]89054502012-06-03 10:29:242135
2136 RenderWidgetHostImpl* render_widget_host_impl =
2137 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2138 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312139 // Only allow privileged mouse lock for fullscreen render widget, which is
2140 // used to implement Pepper Flash fullscreen.
2141 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502142
2143#if defined(OS_MACOSX)
2144 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2145 // properly embedded (or purposefully ignored) we can release the retain we
2146 // took in CreateNewWidget().
2147 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2148#endif
2149}
2150
2151WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2152 PendingContents::iterator iter = pending_contents_.find(route_id);
2153
2154 // Certain systems can block the creation of new windows. If we didn't succeed
2155 // in creating one, just return NULL.
2156 if (iter == pending_contents_.end()) {
2157 return NULL;
2158 }
2159
2160 WebContentsImpl* new_contents = iter->second;
2161 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102162 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502163
[email protected]d70bea92013-04-05 04:23:342164 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252165 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342166 return new_contents;
2167
[email protected]bafe6cd2012-05-23 23:09:502168 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432169 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502170 return NULL;
2171
[email protected]bafe6cd2012-05-23 23:09:502172 return new_contents;
2173}
2174
2175RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2176 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2177 if (iter == pending_widget_views_.end()) {
2178 DCHECK(false);
2179 return NULL;
2180 }
2181
2182 RenderWidgetHostView* widget_host_view = iter->second;
2183 pending_widget_views_.erase(route_id);
2184
2185 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2186 if (!widget_host->GetProcess()->HasConnection()) {
2187 // The view has gone away or the renderer crashed. Nothing to do.
2188 return NULL;
2189 }
2190
2191 return widget_host_view;
2192}
2193
[email protected]f13b4202012-06-12 23:53:232194void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092195 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212196 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372197 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232198 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372199 } else {
dcheng59716272016-04-09 05:19:082200 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2201 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372202 }
[email protected]f13b4202012-06-12 23:53:232203}
2204
grunell657d4d82014-09-18 00:09:432205bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2206 MediaStreamType type) {
2207 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2208 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2209 return delegate_ &&
2210 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2211}
2212
[email protected]cc9200432013-07-23 23:02:402213SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2214 SiteInstance* instance) {
2215 return controller_.GetSessionStorageNamespace(instance);
2216}
2217
[email protected]6de7fc482014-06-06 10:46:442218SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2219 return controller_.GetSessionStorageNamespaceMap();
2220}
2221
[email protected]9b159a52013-10-03 17:24:552222FrameTree* WebContentsImpl::GetFrameTree() {
2223 return &frame_tree_;
2224}
2225
lukendc35e7f2014-11-10 19:06:142226void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2227 virtual_keyboard_requested_ = requested;
2228}
2229
2230bool WebContentsImpl::IsVirtualKeyboardRequested() {
2231 return virtual_keyboard_requested_;
2232}
2233
aelias5252baa2016-04-10 01:18:022234bool WebContentsImpl::IsOverridingUserAgent() {
2235 return GetController().GetVisibleEntry() &&
2236 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2237}
2238
[email protected]95640212014-07-26 18:14:302239AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2240 return accessibility_mode_;
2241}
2242
[email protected]31a71eaf2014-03-13 01:47:362243void WebContentsImpl::AccessibilityEventReceived(
2244 const std::vector<AXEventNotificationDetails>& details) {
2245 FOR_EACH_OBSERVER(
2246 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2247}
2248
dmazzonia656928e2014-09-15 20:28:542249RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402250 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542251 int browser_plugin_instance_id) {
2252 BrowserPluginGuestManager* guest_manager =
2253 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202254 if (!guest_manager)
2255 return nullptr;
2256
dmazzonia656928e2014-09-15 20:28:542257 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442258 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542259 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202260 return nullptr;
2261
dmazzonia656928e2014-09-15 20:28:542262 return guest->GetMainFrame();
2263}
2264
blundellc57b93f2014-10-29 13:19:572265GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2266 return geolocation_service_context_.get();
2267}
2268
alogvinovf50445a2015-10-30 13:00:122269WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2270 return wake_lock_service_context_.get();
2271}
2272
[email protected]edc3af82013-12-12 21:24:072273void WebContentsImpl::OnShowValidationMessage(
2274 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292275 const base::string16& main_text,
2276 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072277 if (delegate_)
2278 delegate_->ShowValidationMessage(
2279 this, anchor_in_root_view, main_text, sub_text);
2280}
2281
2282void WebContentsImpl::OnHideValidationMessage() {
2283 if (delegate_)
2284 delegate_->HideValidationMessage(this);
2285}
2286
2287void WebContentsImpl::OnMoveValidationMessage(
2288 const gfx::Rect& anchor_in_root_view) {
2289 if (delegate_)
2290 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2291}
2292
lfgbb9c28a2016-03-01 03:19:492293void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372294 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2295 if (node->current_frame_host()->GetRenderWidgetHost())
2296 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2297 }
lfgbb9c28a2016-03-01 03:19:492298
lfgdb5c4ed2016-03-04 23:09:072299 RenderWidgetHostViewBase* rwhv =
2300 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2301 if (rwhv) {
2302 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2303 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2304 }
2305
[email protected]32deec62013-05-15 23:55:042306 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442307 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042308}
2309
ekaramad2bd4a2f2016-04-06 20:12:462310const TextInputState* WebContentsImpl::GetTextInputState() {
2311 if (GetOuterWebContents())
2312 return GetOuterWebContents()->GetTextInputState();
2313 // A RWHV should update WebContentsImpl in its destruction path so that state
2314 // type is reset to none.
2315 DCHECK(view_with_active_text_input_ ||
2316 text_input_state_->type == ui::TEXT_INPUT_TYPE_NONE);
2317 return text_input_state_.get();
2318}
2319
2320void WebContentsImpl::UpdateTextInputState(RenderWidgetHostViewBase* rwhv,
2321 bool text_input_state_changed) {
2322 // If there is an outer WebContents, let it process this update.
2323 if (GetOuterWebContents()) {
2324 return GetOuterWebContents()->UpdateTextInputState(
2325 rwhv, text_input_state_changed);
2326 }
2327
2328 // If this RWHV has a text input type of NONE, then there is nothing to
2329 // report to the tab RWHV.
2330 if (view_with_active_text_input_.get() != rwhv &&
2331 rwhv->text_input_state()->type == ui::TEXT_INPUT_TYPE_NONE)
2332 return;
2333
2334 if (rwhv->text_input_state()->type != ui::TEXT_INPUT_TYPE_NONE)
2335 view_with_active_text_input_ = rwhv->GetWeakPtr();
2336 else
2337 view_with_active_text_input_.reset();
2338
2339 *text_input_state_ = *rwhv->text_input_state();
2340
2341 // The top level RWHV should know about the change.
2342 RenderWidgetHostViewBase* tab_rwhv =
2343 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2344 if (tab_rwhv)
2345 tab_rwhv->UpdateInputMethodIfNecessary(text_input_state_changed);
2346}
2347
[email protected]95640212014-07-26 18:14:302348BrowserAccessibilityManager*
2349 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452350 RenderFrameHostImpl* rfh = GetMainFrame();
2351 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302352}
2353
2354BrowserAccessibilityManager*
2355 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452356 RenderFrameHostImpl* rfh = GetMainFrame();
2357 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302358}
2359
mohsen7ab1ec16ec2015-07-02 18:26:232360void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2361 RenderFrameHost* focused_frame = GetFocusedFrame();
2362 if (!focused_frame)
2363 return;
2364
2365 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2366 focused_frame->GetRoutingID(), extent));
2367}
2368
2369void WebContentsImpl::SelectRange(const gfx::Point& base,
2370 const gfx::Point& extent) {
2371 RenderFrameHost* focused_frame = GetFocusedFrame();
2372 if (!focused_frame)
2373 return;
2374
2375 focused_frame->Send(
2376 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2377}
2378
aurimasab0319022015-07-10 21:57:382379void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2380 int end_adjust) {
2381 RenderFrameHost* focused_frame = GetFocusedFrame();
2382 if (!focused_frame)
2383 return;
2384
2385 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2386 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492390 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232391 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492392 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332393}
2394
avic3aa8422015-11-09 20:57:222395void WebContentsImpl::ResizeDueToAutoResize(
2396 RenderWidgetHostImpl* render_widget_host,
2397 const gfx::Size& new_size) {
2398 if (render_widget_host != GetRenderViewHost()->GetWidget())
2399 return;
2400
[email protected]61e2b3cc2012-03-02 16:13:342401 if (delegate_)
2402 delegate_->ResizeDueToAutoResize(this, new_size);
2403}
2404
[email protected]b172aee2012-04-10 17:05:262405WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202406 if (!delegate_)
2407 return NULL;
[email protected]00c37fc2011-08-02 00:22:502408
[email protected]e5d549d2011-12-28 01:29:202409 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202410 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342411}
2412
[email protected]6b618e62012-08-16 12:59:182413bool WebContentsImpl::Send(IPC::Message* message) {
2414 if (!GetRenderViewHost()) {
2415 delete message;
2416 return false;
2417 }
2418
2419 return GetRenderViewHost()->Send(message);
2420}
2421
[email protected]a86c0e962013-12-17 17:10:392422void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2423 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392425 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442426}
2427
[email protected]20ca0382013-02-28 19:50:072428void WebContentsImpl::AttachInterstitialPage(
2429 InterstitialPageImpl* interstitial_page) {
2430 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212431 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292432
2433 // Cancel any visible dialogs so that they don't interfere with the
2434 // interstitial.
creis89a0f782015-05-27 16:13:172435 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292436
[email protected]20ca0382013-02-28 19:50:072437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2438 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252439
2440 // Stop the throbber if needed while the interstitial page is shown.
2441 if (frame_tree_.IsLoading())
2442 LoadingStateChanged(true, true, nullptr);
2443}
2444
2445void WebContentsImpl::DidProceedOnInterstitial() {
2446 // The interstitial page should no longer be pausing the throbber.
2447 DCHECK(!(ShowingInterstitialPage() &&
2448 GetRenderManager()->interstitial_page()->pause_throbber()));
2449
2450 // Restart the throbber now that the interstitial page no longer pauses it.
2451 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2452 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072453}
2454
2455void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252456 bool interstitial_pausing_throbber =
2457 ShowingInterstitialPage() &&
2458 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572459 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212460 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2462 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252463
2464 // Restart the throbber if needed now that the interstitial page is going
2465 // away.
2466 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2467 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072468}
2469
avi2b177592014-12-10 02:08:022470void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2471 int history_length) {
2472 SetHistoryOffsetAndLengthForView(
2473 GetRenderViewHost(), history_offset, history_length);
2474}
2475
2476void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2477 RenderViewHost* render_view_host,
2478 int history_offset,
2479 int history_length) {
2480 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2481 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142482}
2483
toyoshim24a4c7ab2016-04-05 09:24:142484void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172485 RenderFrameHost* focused_frame = GetFocusedFrame();
2486 if (!focused_frame)
2487 return;
2488
[email protected]959be4c2014-04-08 15:01:332489 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142490 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332491}
2492
megjablon3f5941072016-02-04 23:27:522493void WebContentsImpl::ReloadLoFiImages() {
2494 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2495}
2496
[email protected]959be4c2014-04-08 15:01:332497void WebContentsImpl::Undo() {
2498 RenderFrameHost* focused_frame = GetFocusedFrame();
2499 if (!focused_frame)
2500 return;
2501
2502 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2503 RecordAction(base::UserMetricsAction("Undo"));
2504}
2505
2506void WebContentsImpl::Redo() {
2507 RenderFrameHost* focused_frame = GetFocusedFrame();
2508 if (!focused_frame)
2509 return;
2510 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2511 RecordAction(base::UserMetricsAction("Redo"));
2512}
2513
2514void WebContentsImpl::Cut() {
2515 RenderFrameHost* focused_frame = GetFocusedFrame();
2516 if (!focused_frame)
2517 return;
2518
2519 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2520 RecordAction(base::UserMetricsAction("Cut"));
2521}
2522
2523void WebContentsImpl::Copy() {
2524 RenderFrameHost* focused_frame = GetFocusedFrame();
2525 if (!focused_frame)
2526 return;
2527
2528 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2529 RecordAction(base::UserMetricsAction("Copy"));
2530}
2531
2532void WebContentsImpl::CopyToFindPboard() {
2533#if defined(OS_MACOSX)
2534 RenderFrameHost* focused_frame = GetFocusedFrame();
2535 if (!focused_frame)
2536 return;
2537
2538 // Windows/Linux don't have the concept of a find pasteboard.
2539 focused_frame->Send(
2540 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2541 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2542#endif
2543}
2544
2545void WebContentsImpl::Paste() {
2546 RenderFrameHost* focused_frame = GetFocusedFrame();
2547 if (!focused_frame)
2548 return;
2549
2550 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2551 RecordAction(base::UserMetricsAction("Paste"));
2552}
2553
2554void WebContentsImpl::PasteAndMatchStyle() {
2555 RenderFrameHost* focused_frame = GetFocusedFrame();
2556 if (!focused_frame)
2557 return;
2558
2559 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2560 focused_frame->GetRoutingID()));
2561 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2562}
2563
2564void WebContentsImpl::Delete() {
2565 RenderFrameHost* focused_frame = GetFocusedFrame();
2566 if (!focused_frame)
2567 return;
2568
2569 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2570 RecordAction(base::UserMetricsAction("DeleteSelection"));
2571}
2572
2573void WebContentsImpl::SelectAll() {
2574 RenderFrameHost* focused_frame = GetFocusedFrame();
2575 if (!focused_frame)
2576 return;
2577
2578 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2579 RecordAction(base::UserMetricsAction("SelectAll"));
2580}
2581
2582void WebContentsImpl::Unselect() {
2583 RenderFrameHost* focused_frame = GetFocusedFrame();
2584 if (!focused_frame)
2585 return;
2586
2587 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2588 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172589}
2590
2591void WebContentsImpl::Replace(const base::string16& word) {
2592 RenderFrameHost* focused_frame = GetFocusedFrame();
2593 if (!focused_frame)
2594 return;
2595
[email protected]959be4c2014-04-08 15:01:332596 focused_frame->Send(new InputMsg_Replace(
2597 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172598}
2599
2600void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2601 RenderFrameHost* focused_frame = GetFocusedFrame();
2602 if (!focused_frame)
2603 return;
2604
[email protected]959be4c2014-04-08 15:01:332605 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2606 focused_frame->GetRoutingID(), word));
2607}
2608
2609void WebContentsImpl::NotifyContextMenuClosed(
2610 const CustomContextMenuContext& context) {
2611 RenderFrameHost* focused_frame = GetFocusedFrame();
2612 if (!focused_frame)
2613 return;
2614
2615 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2616 focused_frame->GetRoutingID(), context));
2617}
2618
2619void WebContentsImpl::ExecuteCustomContextMenuCommand(
2620 int action, const CustomContextMenuContext& context) {
2621 RenderFrameHost* focused_frame = GetFocusedFrame();
2622 if (!focused_frame)
2623 return;
2624
2625 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2626 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002627}
2628
[email protected]fc2b46b2014-05-03 16:33:452629gfx::NativeView WebContentsImpl::GetNativeView() {
2630 return view_->GetNativeView();
2631}
2632
2633gfx::NativeView WebContentsImpl::GetContentNativeView() {
2634 return view_->GetContentNativeView();
2635}
2636
2637gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2638 return view_->GetTopLevelNativeWindow();
2639}
2640
2641gfx::Rect WebContentsImpl::GetViewBounds() {
2642 return view_->GetViewBounds();
2643}
2644
2645gfx::Rect WebContentsImpl::GetContainerBounds() {
2646 gfx::Rect rv;
2647 view_->GetContainerBounds(&rv);
2648 return rv;
2649}
2650
2651DropData* WebContentsImpl::GetDropData() {
2652 return view_->GetDropData();
2653}
2654
2655void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042656 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452657}
2658
2659void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042660 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452661}
2662
2663void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042664 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452665}
2666
2667void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042668 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452669}
2670
[email protected]b172aee2012-04-10 17:05:262671void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272672 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212673 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542674 return;
2675 }
[email protected]0b431992014-06-24 00:08:032676 RenderWidgetHostView* const fullscreen_view =
2677 GetFullscreenRenderWidgetHostView();
2678 if (fullscreen_view) {
2679 fullscreen_view->Focus();
2680 return;
2681 }
creisc014b402015-04-23 16:41:452682 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542683}
2684
[email protected]b172aee2012-04-10 17:05:262685bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212686 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542687}
2688
[email protected]b172aee2012-04-10 17:05:262689InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212690 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222691}
2692
[email protected]b172aee2012-04-10 17:05:262693bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162694 // WebKit creates Document object when MIME type is application/xhtml+xml,
2695 // so we also support this MIME type.
2696 return contents_mime_type_ == "text/html" ||
2697 contents_mime_type_ == "text/xml" ||
2698 contents_mime_type_ == "application/xhtml+xml" ||
2699 contents_mime_type_ == "text/plain" ||
2700 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252701 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162702}
2703
[email protected]b172aee2012-04-10 17:05:262704void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592705 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162706 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552707 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192708 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142709 return;
[email protected]c7dd2f62011-07-18 15:57:592710 }
2711
2712 Stop();
2713
2714 // Create the save package and possibly prompt the user for the name to save
2715 // the page as. The user prompt is an asynchronous operation that runs on
2716 // another thread.
2717 save_package_ = new SavePackage(this);
2718 save_package_->GetSaveInfo();
2719}
2720
2721// Used in automated testing to bypass prompting the user for file names.
2722// Instead, the names and paths are hard coded rather than running them through
2723// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342724bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2725 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212726 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592727 // Stop the page from navigating.
2728 Stop();
2729
2730 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212731 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592732}
2733
[email protected]3c71576ce2013-07-23 02:00:012734void WebContentsImpl::SaveFrame(const GURL& url,
2735 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372736 SaveFrameWithHeaders(url, referrer, std::string());
2737}
2738
2739void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2740 const Referrer& referrer,
2741 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192742 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012743 return;
sammc92af61552014-11-19 23:27:402744 if (delegate_ && delegate_->SaveFrame(url, referrer))
2745 return;
2746
nasko89ad7742015-03-05 22:14:192747 // TODO(nasko): This check for main frame is incorrect and should be fixed
2748 // by explicitly passing in which frame this method should target.
2749 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012750
2751 DownloadManager* dlm =
2752 BrowserContext::GetDownloadManager(GetBrowserContext());
2753 if (!dlm)
2754 return;
avib7348942015-12-25 20:57:102755 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012756 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272757 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012758 if (entry)
2759 post_id = entry->GetPostID();
2760 }
dcheng59716272016-04-09 05:19:082761 std::unique_ptr<DownloadUrlParameters> params(
[email protected]3c71576ce2013-07-23 02:00:012762 DownloadUrlParameters::FromWebContents(this, url));
2763 params->set_referrer(referrer);
2764 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012765 if (post_id >= 0)
2766 params->set_method("POST");
2767 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372768
2769 if (headers.empty()) {
2770 params->set_prefer_cache(true);
2771 } else {
brettw26dab8f02015-08-08 00:28:472772 for (const base::StringPiece& key_value :
2773 base::SplitStringPiece(
2774 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2775 std::vector<std::string> pair = base::SplitString(
2776 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372777 DCHECK_EQ(2ul, pair.size());
2778 params->add_request_header(pair[0], pair[1]);
2779 }
2780 }
dcheng36b6aec92015-12-26 06:16:362781 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012782}
2783
[email protected]b172aee2012-04-10 17:05:262784void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342785 const base::FilePath& file,
avib7348942015-12-25 20:57:102786 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482787 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122788}
2789
[email protected]b172aee2012-04-10 17:05:262790const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272791 return contents_mime_type_;
2792}
2793
[email protected]b172aee2012-04-10 17:05:262794bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272795 return notify_disconnection_;
2796}
2797
[email protected]b172aee2012-04-10 17:05:262798void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312799 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182800 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542804 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182805 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162806}
2807
[email protected]8ff00d72012-10-23 19:12:212808RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272809 return &renderer_preferences_;
2810}
2811
[email protected]e35ccd52012-05-23 16:22:472812void WebContentsImpl::Close() {
2813 Close(GetRenderViewHost());
2814}
2815
[email protected]cf200a562013-05-03 16:24:292816void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462817 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292818 if (browser_plugin_embedder_.get())
2819 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2820 screen_x, screen_y, operation);
2821 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452822 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2823 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292824}
2825
[email protected]d60f3702013-12-26 16:30:242826void WebContentsImpl::DidGetResourceResponseStart(
2827 const ResourceRequestDetails& details) {
2828 controller_.ssl_manager()->DidStartResourceResponse(details);
2829
2830 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2831 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242832}
2833
2834void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462835 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242836 const ResourceRedirectDetails& details) {
2837 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2838
2839 FOR_EACH_OBSERVER(
2840 WebContentsObserver,
2841 observers_,
creis114ca1b2014-11-13 23:51:462842 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242843
2844 // TODO(avi): Remove. http://crbug.com/170921
2845 NotificationService::current()->Notify(
2846 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2847 Source<WebContents>(this),
2848 Details<const ResourceRedirectDetails>(&details));
2849}
2850
calamity7fe55ce2015-04-10 03:59:372851void WebContentsImpl::NotifyWebContentsFocused() {
2852 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2853}
2854
[email protected]b172aee2012-04-10 17:05:262855void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522856 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452857 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292858 if (browser_plugin_embedder_.get())
2859 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342860}
2861
[email protected]e35ccd52012-05-23 16:22:472862void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532863 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2864 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472865}
2866
[email protected]b172aee2012-04-10 17:05:262867void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272868 closed_by_user_gesture_ = value;
2869}
2870
[email protected]b172aee2012-04-10 17:05:262871bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272872 return closed_by_user_gesture_;
2873}
2874
[email protected]b172aee2012-04-10 17:05:262875void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502876 if (!delegate_)
2877 return;
2878
[email protected]6286a372013-10-09 04:03:272879 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2880 if (!entry)
[email protected]1788e772010-12-15 16:40:502881 return;
2882
[email protected]6286a372013-10-09 04:03:272883 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122884}
2885
[email protected]b172aee2012-04-10 17:05:262886void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042887 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272888 if (!delegate_)
2889 return;
2890
[email protected]691aa2f2013-05-28 22:52:042891 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272892}
2893
[email protected]b172aee2012-04-10 17:05:262894int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272895 return minimum_zoom_percent_;
2896}
2897
[email protected]b172aee2012-04-10 17:05:262898int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272899 return maximum_zoom_percent_;
2900}
2901
mcnee432e47d2015-11-09 19:37:462902void WebContentsImpl::SetPageScale(float page_scale_factor) {
2903 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242904}
2905
[email protected]b172aee2012-04-10 17:05:262906gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492907 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232908}
2909
[email protected]b172aee2012-04-10 17:05:262910bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052911 if (GetBrowserPluginGuest())
2912 return GetBrowserPluginGuest()->LockMouse(allowed);
2913
creisc014b402015-04-23 16:41:452914 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432915 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2916 allowed)
creisc014b402015-04-23 16:41:452917 : false;
[email protected]0bfbf882011-12-22 18:19:272918}
2919
[email protected]b172aee2012-04-10 17:05:262920bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212921 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502922}
2923
alexmose201c7cd2015-06-10 17:14:212924WebContentsImpl* WebContentsImpl::GetOpener() const {
2925 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2926 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572927}
2928
[email protected]cb805452013-05-22 15:16:212929void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482930 if (!color_chooser_info_.get())
2931 return;
2932 RenderFrameHost* rfh = RenderFrameHost::FromID(
2933 color_chooser_info_->render_process_id,
2934 color_chooser_info_->render_frame_id);
2935 if (!rfh)
2936 return;
2937
2938 rfh->Send(new FrameMsg_DidChooseColorResponse(
2939 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202940}
2941
[email protected]cb805452013-05-22 15:16:212942void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482943 if (!color_chooser_info_.get())
2944 return;
2945 RenderFrameHost* rfh = RenderFrameHost::FromID(
2946 color_chooser_info_->render_process_id,
2947 color_chooser_info_->render_frame_id);
2948 if (!rfh)
2949 return;
2950
2951 rfh->Send(new FrameMsg_DidEndColorChooser(
2952 rfh->GetRoutingID(), color_chooser_info_->identifier));
2953 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202954}
2955
halton.huoca2eabd2015-07-06 08:17:402956int WebContentsImpl::DownloadImage(
2957 const GURL& url,
2958 bool is_favicon,
2959 uint32_t max_bitmap_size,
2960 bool bypass_cache,
2961 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552962 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402963 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062964 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402965 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552966 const int download_id = ++next_image_download_id;
2967 if (!mojo_image_downloader) {
2968 // If the renderer process is dead (i.e. crash, or memory pressure on
2969 // Android), the downloader service will be invalid. Pre-Mojo, this would
2970 // hang the callback indefinetly since the IPC would be dropped. Now,
2971 // respond with a 400 HTTP error code to indicate that something went wrong.
2972 BrowserThread::PostTask(
2973 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192974 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522975 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2976 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552977 return download_id;
2978 }
2979
halton.huoca2eabd2015-07-06 08:17:402980 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522981 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2982 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2983 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552984 return download_id;
[email protected]795c28972012-12-06 06:13:392985}
2986
[email protected]5dcaf8e2013-12-28 01:31:422987bool WebContentsImpl::IsSubframe() const {
2988 return is_subframe_;
2989}
2990
[email protected]36ec24f2014-01-09 00:32:082991void WebContentsImpl::Find(int request_id,
2992 const base::string16& search_text,
2993 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332994 // Cowardly refuse to search for no text.
2995 if (search_text.empty()) {
2996 NOTREACHED();
2997 return;
2998 }
2999
raymes0fa0be52014-10-13 20:38:093000 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173001 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473002 if (browser_plugin_embedder_ &&
3003 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3004 return;
raymes0fa0be52014-10-13 20:38:093005 }
paulmeyerc0b762b2016-04-13 11:55:173006
3007 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083008}
3009
3010void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013011 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173012 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473013 if (browser_plugin_embedder_ &&
3014 browser_plugin_embedder_->StopFinding(action)) {
3015 return;
raymes2bc64182015-02-06 01:23:013016 }
paulmeyerc0b762b2016-04-13 11:55:173017
3018 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083019}
3020
[email protected]4fe53add2014-04-08 19:53:363021void WebContentsImpl::InsertCSS(const std::string& css) {
3022 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
3023 GetMainFrame()->GetRoutingID(), css));
3024}
3025
dalecurtisbc6572e12014-09-12 19:22:303026bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:153027 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:303028}
3029
mlamouriefdca9d2014-09-16 16:55:403030void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3031 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3032}
3033
dominickn6919ce32015-10-15 01:52:283034void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
3035 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
3036}
3037
bokanece34a82016-01-28 19:49:463038void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533039 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433040 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463041 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533042}
3043
mariakhomenko44bdc4732015-04-29 01:55:383044void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373045 if (delayed_open_url_params_.get()) {
3046 OpenURL(*delayed_open_url_params_.get());
3047 delayed_open_url_params_.reset(nullptr);
3048 return;
3049 }
3050
mariakhomenko44bdc4732015-04-29 01:55:383051 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3052 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163053 if (is_resume_pending_) {
3054 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133055 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163056 GetMainFrame()->Init();
3057 }
mariakhomenko44bdc4732015-04-29 01:55:383058}
3059
[email protected]b172aee2012-04-10 17:05:263060bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263061 // When the browser is started with about:blank as the startup URL, focus
3062 // the location bar (which will also select its contents) so people can
3063 // simply begin typing to navigate elsewhere.
3064 //
3065 // We need to be careful not to trigger this for anything other than the
3066 // startup navigation. In particular, if we allow an attacker to open a
3067 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3068 // end of the new URL to be scrolled into view instead of the start,
3069 // allowing the attacker to spoof other URLs. The conditions checked here
3070 // are all aimed at ensuring no such attacker-controlled navigation can
3071 // trigger this.
3072 //
3073 // Note that we check the pending entry instead of the visible one; for the
3074 // startup URL case these are the same, but for the attacker-controlled
3075 // navigation case the visible entry is the committed "about:blank" URL and
3076 // the pending entry is the problematic navigation elsewhere.
3077 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3078 if (controller_.IsInitialNavigation() && entry &&
3079 !entry->is_renderer_initiated() &&
3080 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333081 return true;
palmerc70cb1f2016-03-04 23:41:263082 }
[email protected]0c9406632013-02-08 01:13:333083 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273084}
3085
[email protected]b172aee2012-04-10 17:05:263086void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273087 if (delegate_)
3088 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213089}
3090
clamy0e119882015-07-31 16:12:333091void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3092 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3093 DidStartNavigation(navigation_handle));
3094}
3095
3096void WebContentsImpl::DidRedirectNavigation(
3097 NavigationHandle* navigation_handle) {
3098 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3099 DidRedirectNavigation(navigation_handle));
3100}
3101
clamyefca29e2015-09-17 00:22:113102void WebContentsImpl::ReadyToCommitNavigation(
3103 NavigationHandle* navigation_handle) {
3104 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3105 ReadyToCommitNavigation(navigation_handle));
3106}
3107
clamy0e119882015-07-31 16:12:333108void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3109 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3110 DidFinishNavigation(navigation_handle));
3111}
3112
[email protected]52913802013-12-10 05:52:183113void WebContentsImpl::DidStartProvisionalLoad(
3114 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183115 const GURL& validated_url,
3116 bool is_error_page,
3117 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103118 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483119 FOR_EACH_OBSERVER(
3120 WebContentsObserver,
3121 observers_,
3122 DidStartProvisionalLoadForFrame(
3123 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083124
3125 // Notify accessibility if this is a reload.
3126 NavigationEntry* entry = controller_.GetVisibleEntry();
3127 if (entry && ui::PageTransitionCoreTypeIs(
3128 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3129 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3130 BrowserAccessibilityManager* manager =
3131 ftn->current_frame_host()->browser_accessibility_manager();
3132 if (manager)
3133 manager->UserIsReloading();
3134 }
[email protected]400992b2012-06-14 00:03:543135}
3136
[email protected]3109fbb72014-01-06 23:57:153137void WebContentsImpl::DidFailProvisionalLoadWithError(
3138 RenderFrameHostImpl* render_frame_host,
3139 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3140 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313141 FOR_EACH_OBSERVER(WebContentsObserver,
3142 observers_,
3143 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313144 validated_url,
3145 params.error_code,
gsennton6fbb38692015-06-24 19:23:553146 params.error_description,
3147 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083148
3149 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3150 BrowserAccessibilityManager* manager =
3151 ftn->current_frame_host()->browser_accessibility_manager();
3152 if (manager)
3153 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153154}
3155
[email protected]b80624c2014-02-09 02:46:553156void WebContentsImpl::DidFailLoadWithError(
3157 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553158 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553159 int error_code,
gsennton6fbb38692015-06-24 19:23:553160 const base::string16& error_description,
3161 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143162 FOR_EACH_OBSERVER(
3163 WebContentsObserver,
3164 observers_,
gsennton6fbb38692015-06-24 19:23:553165 DidFailLoad(render_frame_host, url, error_code, error_description,
3166 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553167}
3168
[email protected]52913802013-12-10 05:52:183169void WebContentsImpl::NotifyChangedNavigationState(
3170 InvalidateTypes changed_flags) {
3171 NotifyNavigationStateChanged(changed_flags);
3172}
3173
[email protected]3691e5cf2014-01-22 10:16:203174void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203175 const GURL& url,
3176 NavigationController::ReloadType reload_type) {
3177 // Notify observers about navigation.
3178 FOR_EACH_OBSERVER(
3179 WebContentsObserver,
3180 observers_,
3181 DidStartNavigationToPendingEntry(url, reload_type));
3182}
3183
[email protected]8cb834e2014-03-06 14:23:233184void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3185 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503186 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3187 // weak pointer of sorts.
3188 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3189 const int32_t frame_id = render_frame_host->GetRoutingID();
3190
[email protected]65920f332014-03-04 21:14:183191 WebContents* new_contents = OpenURL(params);
3192
dchengb907f7332015-01-07 20:35:503193 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183194 // Notify observers.
3195 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3196 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463197 render_frame_host,
[email protected]65920f332014-03-04 21:14:183198 params.url,
3199 params.referrer,
3200 params.disposition,
creis114ca1b2014-11-13 23:51:463201 params.transition));
[email protected]65920f332014-03-04 21:14:183202 }
3203}
3204
creis29460272015-12-16 04:38:223205bool WebContentsImpl::ShouldTransferNavigation() {
3206 if (!delegate_)
3207 return true;
3208 return delegate_->ShouldTransferNavigation();
3209}
3210
[email protected]aa62afd2014-04-22 19:22:463211bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3212 if (!delegate_)
3213 return false;
3214 return delegate_->ShouldPreserveAbortedURLs(this);
3215}
3216
[email protected]37567b432014-02-12 01:12:223217void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433218 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223219 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353220 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223221 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483222 FOR_EACH_OBSERVER(WebContentsObserver,
3223 observers_,
3224 DidCommitProvisionalLoadForFrame(
3225 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083226
3227 BrowserAccessibilityManager* manager =
3228 render_frame_host->browser_accessibility_manager();
3229 if (manager)
3230 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223231}
3232
[email protected]0d0f4c492014-04-02 06:42:573233void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233234 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573235 // Ensure fullscreen mode is exited before committing the navigation to a
3236 // different page. The next page will not start out assuming it is in
3237 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233238 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193239 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573240 return;
3241 }
avibf58fa0c2015-11-11 01:45:523242 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463243 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523244 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573245}
3246
[email protected]37567b432014-02-12 01:12:223247void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283248 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223249 const LoadCommittedDetails& details,
3250 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3251 if (details.is_navigation_to_different_page()) {
3252 // Clear the status bubble. This is a workaround for a bug where WebKit
3253 // doesn't let us know that the cursor left an element during a
3254 // transition (this is also why the mouse cursor remains as a hand after
3255 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3256 // clear the bubble when a user navigates to a named anchor in the same
3257 // page.
sky8b00392d2015-01-10 00:30:283258 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003259
3260 RenderWidgetHostViewBase* rwhvb =
3261 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3262 if (rwhvb)
3263 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283264
peter90afaba2015-06-01 12:05:293265 did_first_visually_non_empty_paint_ = false;
3266
yusufod41c5f92015-03-06 00:14:283267 // Reset theme color on navigation to new page.
3268 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223269 }
3270
3271 if (!details.is_in_page) {
3272 // Once the main frame is navigated, we're no longer considered to have
3273 // displayed insecure content.
3274 displayed_insecure_content_ = false;
3275 SSLManager::NotifySSLInternalStateChanged(
3276 GetController().GetBrowserContext());
3277 }
3278
3279 // Notify observers about navigation.
3280 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3281 DidNavigateMainFrame(details, params));
3282
[email protected]e85165c642014-06-10 14:34:313283 if (delegate_)
[email protected]37567b432014-02-12 01:12:223284 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313285 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223286}
3287
3288void WebContentsImpl::DidNavigateAnyFramePostCommit(
3289 RenderFrameHostImpl* render_frame_host,
3290 const LoadCommittedDetails& details,
3291 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103292 // Now that something has committed, we don't need to track whether the
3293 // initial page has been accessed.
3294 has_accessed_initial_document_ = false;
3295
[email protected]37567b432014-02-12 01:12:223296 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173297 if (!details.is_in_page)
3298 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223299
avid53461d2016-02-25 17:15:043300 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3301 // again.
3302 if (params.gesture == NavigationGestureUser && dialog_manager_)
3303 dialog_manager_->ResetDialogState(this);
3304
[email protected]37567b432014-02-12 01:12:223305 // Notify observers about navigation.
3306 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093307 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223308}
3309
3310void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3311 contents_mime_type_ = mime_type;
3312}
3313
[email protected]277857a2014-06-03 10:38:013314bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313315 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053316 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313317 return false;
3318
[email protected]37567b432014-02-12 01:12:223319 if (delegate_)
3320 return delegate_->CanOverscrollContent();
3321
3322 return false;
3323}
3324
[email protected]37b64c52014-07-11 21:14:053325void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293326 // Update the theme color. This is to be published to observers after the
3327 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283328 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293329
3330 if (did_first_visually_non_empty_paint_ &&
3331 last_sent_theme_color_ != theme_color_) {
3332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3333 DidChangeThemeColor(theme_color_));
3334 last_sent_theme_color_ = theme_color_;
3335 }
[email protected]e7104762014-06-20 19:17:253336}
3337
[email protected]b172aee2012-04-10 17:05:263338void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183339 const GURL& url,
[email protected]70435962011-08-02 20:13:283340 const std::string& security_info,
3341 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183342 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403343 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533344 SSLStatus status;
3345 if (!DeserializeSecurityInfo(security_info, &status)) {
3346 bad_message::ReceivedBadMessage(
3347 GetRenderProcessHost(),
3348 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3349 return;
3350 }
[email protected]724159a2010-12-30 01:11:183351
3352 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593353 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213354 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263355 url, status.cert_id, status.cert_status, http_method, mime_type,
3356 resource_type);
[email protected]724159a2010-12-30 01:11:183357
[email protected]b0f724c2013-09-05 04:21:133358 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3359
3360 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3361 DidLoadResourceFromMemoryCache(details));
3362
[email protected]8bfc8272013-09-09 20:10:533363 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3364 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403365 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533366 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3367 GetRenderProcessHost()->GetID()) :
jam608f2992016-03-31 16:35:343368 GetRenderProcessHost()->GetStoragePartition()->
3369 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533370 BrowserThread::PostTask(
3371 BrowserThread::IO,
3372 FROM_HERE,
3373 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3374 }
[email protected]724159a2010-12-30 01:11:183375}
3376
[email protected]b172aee2012-04-10 17:05:263377void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393378 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183379 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193380 SSLManager::NotifySSLInternalStateChanged(
3381 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183382}
3383
estark910b4572015-12-09 20:55:413384void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3385 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583386 LOG(WARNING) << security_origin << " ran insecure content from "
3387 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393388 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413389 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293390 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393391 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183392 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193393 SSLManager::NotifySSLInternalStateChanged(
3394 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183395}
3396
estark910b4572015-12-09 20:55:413397void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3398 const GURL& url,
3399 const std::string& security_info) {
3400 SSLStatus ssl;
3401 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3402 bad_message::ReceivedBadMessage(
3403 GetRenderProcessHost(),
3404 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3405 return;
3406 }
3407
3408 displayed_insecure_content_ = true;
3409 SSLManager::NotifySSLInternalStateChanged(
3410 GetController().GetBrowserContext());
3411}
3412
3413void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3414 const GURL& security_origin,
3415 const GURL& url,
3416 const std::string& security_info) {
3417 SSLStatus ssl;
3418 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3419 bad_message::ReceivedBadMessage(
3420 GetRenderProcessHost(),
3421 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3422 return;
3423 }
3424
3425 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3426 SSLManager::NotifySSLInternalStateChanged(
3427 GetController().GetBrowserContext());
3428}
3429
[email protected]501052ff2014-02-21 22:19:073430void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113431 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473432 return;
naskofbd033392015-01-27 02:34:473433
[email protected]1d62cf72014-02-07 21:31:573434 RenderFrameHostImpl* rfh =
3435 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143436 FOR_EACH_OBSERVER(
3437 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183438}
3439
naskofbd033392015-01-27 02:34:473440void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113441 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123442 return;
[email protected]a1b99262013-12-27 21:56:223443
[email protected]8b3af1e2014-01-24 13:29:123444 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443445 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373446 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423447 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373448
[email protected]61ac9e242014-03-21 20:55:263449 RenderFrameHostImpl* rfh =
3450 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143451 FOR_EACH_OBSERVER(
3452 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313453}
3454
[email protected]b172aee2012-04-10 17:05:263455void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573456 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3457 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263458}
3459
[email protected]b172aee2012-04-10 17:05:263460void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303461 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263462 minimum_zoom_percent_ = minimum_percent;
3463 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263464}
3465
mcnee432e47d2015-11-09 19:37:463466void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3467 bool is_one = page_scale_factor == 1.f;
3468 if (is_one != page_scale_factor_is_one_) {
3469 page_scale_factor_is_one_ = is_one;
3470
3471 HostZoomMapImpl* host_zoom_map =
3472 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3473
3474 if (host_zoom_map && GetRenderProcessHost()) {
3475 host_zoom_map->SetPageScaleFactorIsOneForView(
3476 GetRenderProcessHost()->GetID(), GetRoutingID(),
3477 page_scale_factor_is_one_);
3478 }
3479 }
3480
3481 FOR_EACH_OBSERVER(WebContentsObserver,
3482 observers_,
3483 OnPageScaleFactorChanged(page_scale_factor));
3484}
3485
[email protected]b172aee2012-04-10 17:05:263486void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343487 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433488 if (!delegate_)
3489 return;
3490
[email protected]b9535422012-02-09 01:47:593491 ChildProcessSecurityPolicyImpl* policy =
3492 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223493 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593494 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213495}
3496
[email protected]b172aee2012-04-10 17:05:263497void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3498 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263499 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363500 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433501 if (!delegate_)
3502 return;
3503
[email protected]b9535422012-02-09 01:47:593504 ChildProcessSecurityPolicyImpl* policy =
3505 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323506 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593507 return;
[email protected]8f810632013-06-06 22:33:323508
[email protected]c125e532014-05-10 20:39:063509 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203510}
3511
[email protected]f5273e52014-07-14 16:30:203512void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3513 const GURL& url,
3514 bool user_gesture) {
3515 if (!delegate_)
3516 return;
3517
3518 ChildProcessSecurityPolicyImpl* policy =
3519 ChildProcessSecurityPolicyImpl::GetInstance();
3520 if (policy->IsPseudoScheme(protocol))
3521 return;
3522
3523 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3524}
3525
kouhei40f03cb2015-09-24 07:47:013526void WebContentsImpl::OnUpdatePageImportanceSignals(
3527 const PageImportanceSignals& signals) {
3528 page_importance_signals_ = signals;
3529}
3530
[email protected]b172aee2012-04-10 17:05:263531void WebContentsImpl::OnFindReply(int request_id,
3532 int number_of_matches,
3533 const gfx::Rect& selection_rect,
3534 int active_match_ordinal,
3535 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173536 // Forward the find reply to the FindRequestManager, along with the
3537 // RenderFrameHost associated with the frame that the reply came from.
3538 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3539 request_id,
3540 number_of_matches,
3541 selection_rect,
3542 active_match_ordinal,
3543 final_update);
[email protected]b888919c2011-09-02 00:32:163544}
3545
mfomitchev2b8b066a2016-01-28 19:23:153546#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313547void WebContentsImpl::OnFindMatchRectsReply(
3548 int version,
3549 const std::vector<gfx::RectF>& rects,
3550 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173551 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3552 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313553}
[email protected]583418cc2013-01-17 14:01:103554
[email protected]1ff427972013-02-07 21:14:073555void WebContentsImpl::OnOpenDateTimeDialog(
3556 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173557 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093558 GetRenderViewHost(),
3559 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133560 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093561 value.minimum,
3562 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173563 value.step,
3564 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103565}
[email protected]59363fc92012-09-05 03:46:313566#endif
3567
avi60bd4902015-09-23 20:39:243568void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3569 std::string json = json_string;
3570 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3571 Source<WebContents>(this),
3572 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403573}
3574
[email protected]b172aee2012-04-10 17:05:263575void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3576 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103577 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253578 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103579 AppCacheAccessed(manifest_url, blocked_by_policy));
3580}
3581
[email protected]8bc5ff02013-11-29 06:34:033582void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483583 int color_chooser_id,
3584 SkColor color,
3585 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113586 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003587 return;
nasko907fcb62015-01-28 04:24:113588
[email protected]aa62afd2014-04-22 19:22:463589 ColorChooser* new_color_chooser = delegate_ ?
3590 delegate_->OpenColorChooser(this, color, suggestions) :
3591 NULL;
[email protected]820957a2014-01-14 14:56:303592 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213593 return;
[email protected]8ed16472014-04-11 19:02:483594 if (color_chooser_info_.get())
3595 color_chooser_info_->chooser->End();
3596
3597 color_chooser_info_.reset(new ColorChooserInfo(
3598 render_frame_message_source_->GetProcess()->GetID(),
3599 render_frame_message_source_->GetRoutingID(),
3600 new_color_chooser,
3601 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203602}
3603
[email protected]b172aee2012-04-10 17:05:263604void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483605 if (color_chooser_info_ &&
3606 color_chooser_id == color_chooser_info_->identifier)
3607 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323611 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483612 if (color_chooser_info_ &&
3613 color_chooser_id == color_chooser_info_->identifier)
3614 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203615}
3616
[email protected]d0759f492012-04-19 22:50:503617// This exists for render views that don't have a WebUI, but do have WebUI
3618// bindings enabled.
3619void WebContentsImpl::OnWebUISend(const GURL& source_url,
3620 const std::string& name,
3621 const base::ListValue& args) {
3622 if (delegate_)
3623 delegate_->WebUISend(this, source_url, name, args);
3624}
3625
thestigc4cac8f2014-09-04 21:17:503626#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003627void WebContentsImpl::OnPepperInstanceCreated() {
3628 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3629}
3630
3631void WebContentsImpl::OnPepperInstanceDeleted() {
3632 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3633}
3634
tommyclie6633ca72014-10-31 00:40:423635void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3636 const base::FilePath& path,
3637 bool is_hung) {
3638 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3639
3640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3641 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3642}
3643
3644void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3645 base::ProcessId plugin_pid) {
3646 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3647 PluginCrashed(plugin_path, plugin_pid));
3648}
3649
[email protected]d8415ad92012-08-23 14:40:503650void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443651 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503652 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343653 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163654 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443655 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163656 return;
[email protected]d8415ad92012-08-23 14:40:503657 }
3658
[email protected]8c8fc292012-11-23 18:57:163659 if (!delegate_->RequestPpapiBrokerPermission(
3660 this, url, plugin_path,
3661 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443662 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163663 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443664 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163665 }
[email protected]d8415ad92012-08-23 14:40:503666}
3667
[email protected]ea0309c2013-08-06 19:35:443668void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503669 bool result) {
[email protected]ea0309c2013-08-06 19:35:443670 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503671}
3672
fsamuel833ee7c2015-02-13 23:40:403673void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3674 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393675 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143676 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403677 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373678}
tommyclie6633ca72014-10-31 00:40:423679#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373680
[email protected]795c28972012-12-06 06:13:393681void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393682 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063683 // We get updated favicon URLs after the page stops loading. If a cross-site
3684 // navigation occurs while a page is still loading, the initial page
3685 // may stop loading and send us updated favicon URLs after the navigation
3686 // for the new page has committed.
3687 RenderViewHostImpl* rvhi =
3688 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3689 if (!rvhi->is_active())
3690 return;
3691
[email protected]795c28972012-12-06 06:13:393692 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293693 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393694}
3695
avayvod41634b12015-07-08 17:07:053696void WebContentsImpl::OnMediaSessionStateChanged() {
3697 MediaSession* session = MediaSession::Get(this);
3698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3699 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543700 session->IsSuspended(),
3701 session->metadata()));
avayvod41634b12015-07-08 17:07:053702}
3703
3704void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523705 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053706}
3707
3708void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523709 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053710}
3711
mlamouri4c4fbed2015-08-17 15:51:013712void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523713 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013714}
3715
[email protected]50279492014-05-05 23:24:293716void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153717 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293718 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283719
peter90afaba2015-06-01 12:05:293720 did_first_visually_non_empty_paint_ = true;
3721
yusufod41c5f92015-03-06 00:14:283722 if (theme_color_ != last_sent_theme_color_) {
3723 // Theme color should have updated by now if there was one.
3724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3725 DidChangeThemeColor(theme_color_));
3726 last_sent_theme_color_ = theme_color_;
3727 }
[email protected]9f268072013-11-07 00:02:153728}
[email protected]d9030b82013-07-19 08:26:063729
[email protected]e67ebf32013-02-13 11:07:193730void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013731 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073732 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013733
estark5ea80e52015-06-19 18:43:123734 SecurityStyleExplanations security_style_explanations;
3735 SecurityStyle security_style =
3736 delegate_->GetSecurityStyle(this, &security_style_explanations);
3737 FOR_EACH_OBSERVER(
3738 WebContentsObserver, observers_,
3739 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013740 }
[email protected]e67ebf32013-02-13 11:07:193741}
3742
[email protected]17e286e2013-03-01 23:29:393743void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3745 BeforeFormRepostWarningShow());
3746}
3747
[email protected]ec6c05f2013-10-23 18:41:573748void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3749 Activate();
3750 if (delegate_)
3751 delegate_->ShowRepostFormWarningDialog(this);
3752}
3753
[email protected]b4c84012014-04-28 19:51:103754bool WebContentsImpl::HasAccessedInitialDocument() {
3755 return has_accessed_initial_document_;
3756}
3757
[email protected]b172aee2012-04-10 17:05:263758void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463759 // If we are creating a RVH for a restored controller, then we need to make
3760 // sure the RenderView starts with a next_page_id_ larger than the number
3761 // of restored entries. This must be called before the RenderView starts
3762 // navigating (to avoid a race between the browser updating max_page_id and
3763 // the renderer updating next_page_id_). Because of this, we only call this
3764 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563765 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583766 if (max_restored_page_id >
3767 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3768 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3769 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323770}
3771
[email protected]b172aee2012-04-10 17:05:263772bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263773 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323774 // For file URLs without a title, use the pathname instead. In the case of a
3775 // synthesized title, we don't want the update to count toward the "one set
3776 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263777 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323778 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513779 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243780 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323781 explicit_set = false; // Don't count synthetic titles toward the set limit.
3782 } else {
[email protected]8af69c6c2014-03-03 19:05:313783 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323784 explicit_set = true;
3785 }
3786
[email protected]987fc3a2011-05-26 14:18:093787 // If a page is created via window.open and never navigated,
3788 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553789 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093790 if (entry) {
[email protected]36fc0392011-12-25 03:59:513791 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093792 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323793
[email protected]36fc0392011-12-25 03:59:513794 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093795 } else {
3796 if (page_title_when_no_navigation_entry_ == final_title)
3797 return false; // Nothing changed, don't bother.
3798
3799 page_title_when_no_navigation_entry_ = final_title;
3800 }
[email protected]420ae012009-04-24 05:16:323801
[email protected]420ae012009-04-24 05:16:323802 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233803 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323804
[email protected]66798902013-10-01 18:40:163805 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533806 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163807
[email protected]420ae012009-04-24 05:16:323808 return true;
3809}
3810
fdegansa696e5112015-04-17 01:57:593811void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003812 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003813 if (delegate_)
fdegansa696e5112015-04-17 01:57:593814 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003815}
3816
3817void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343818 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003819 loading_weak_factory_.InvalidateWeakPtrs();
3820 loading_last_progress_update_ = base::TimeTicks();
3821}
3822
clamy44e84ce2016-02-22 15:38:253823// Notifies the RenderWidgetHost instance about the fact that the page is
3824// loading, or done loading.
3825void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3826 bool due_to_interstitial,
3827 LoadNotificationDetails* details) {
3828 // Do not send notifications about loading changes in the FrameTree while the
3829 // interstitial page is pausing the throbber.
3830 if (ShowingInterstitialPage() &&
3831 GetRenderManager()->interstitial_page()->pause_throbber() &&
3832 !due_to_interstitial) {
3833 return;
3834 }
3835
3836 bool is_loading = IsLoading();
3837
3838 if (!is_loading) {
3839 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3840 base::string16());
3841 load_state_host_.clear();
3842 upload_size_ = 0;
3843 upload_position_ = 0;
3844 }
3845
3846 GetRenderManager()->SetIsLoading(is_loading);
3847
3848 waiting_for_response_ = is_loading;
3849 is_load_to_different_document_ = to_different_document;
3850
3851 if (delegate_)
3852 delegate_->LoadingStateChanged(this, to_different_document);
3853 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3854
3855 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3856 if (is_loading) {
3857 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3858 this, "URL", url, "Main FrameTreeNode id",
3859 GetFrameTree()->root()->frame_tree_node_id());
3860 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3861 } else {
3862 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3863 this, "URL", url);
3864 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3865 }
3866
3867 // TODO(avi): Remove. http://crbug.com/170921
3868 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3869 NotificationDetails det = NotificationService::NoDetails();
3870 if (details)
3871 det = Details<LoadNotificationDetails>(details);
3872 NotificationService::current()->Notify(
3873 type, Source<NavigationController>(&controller_), det);
3874}
3875
[email protected]02d7b6e2014-06-24 21:01:503876void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3877 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323878 // After sending out a swap notification, we need to send a disconnect
3879 // notification so that clients that pick up a pointer to |this| can NULL the
3880 // pointer. See Bug 1230284.
3881 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113882 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283883 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113884
[email protected]7a846df2012-09-20 19:17:393885 // Ensure that the associated embedder gets cleared after a RenderViewHost
3886 // gets swapped, so we don't reuse the same embedder next time a
3887 // RenderViewHost is attached to this WebContents.
3888 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323889}
3890
[email protected]02d7b6e2014-06-24 21:01:503891void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3892 RenderFrameHost* new_host) {
3893 FOR_EACH_OBSERVER(WebContentsObserver,
3894 observers_,
3895 RenderFrameHostChanged(old_host, new_host));
3896}
3897
[email protected]da7a7182013-09-06 08:11:113898// TODO(avi): Remove this entire function because this notification is already
3899// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263900void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323901 if (!notify_disconnection_)
3902 return;
3903
3904 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213905 NotificationService::current()->Notify(
3906 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3907 Source<WebContents>(this),
3908 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323909}
3910
[email protected]cbb1ef592013-06-05 19:49:463911void WebContentsImpl::NotifyNavigationEntryCommitted(
3912 const LoadCommittedDetails& load_details) {
3913 FOR_EACH_OBSERVER(
3914 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3915}
3916
[email protected]f114fa42013-12-06 17:06:443917bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3918 const IPC::Message& message) {
3919 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313920}
3921
[email protected]c31a84802014-04-03 15:55:493922const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3923 return GetLastCommittedURL();
3924}
3925
[email protected]b849847b2013-12-10 21:57:583926void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583927 FOR_EACH_OBSERVER(WebContentsObserver,
3928 observers_,
3929 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303930 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453931
3932 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3933 return;
3934
3935 NavigationEntry* entry = controller_.GetPendingEntry();
3936 if (entry && entry->IsViewSourceMode()) {
3937 // Put the renderer in view source mode.
3938 render_frame_host->Send(
3939 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3940 }
[email protected]b849847b2013-12-10 21:57:583941}
3942
3943void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3944 FOR_EACH_OBSERVER(WebContentsObserver,
3945 observers_,
3946 RenderFrameDeleted(render_frame_host));
3947}
3948
[email protected]a09d53ce2014-01-31 00:46:423949void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3950 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103951 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423952 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103953 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423954 return;
3955
[email protected]077e704b2014-05-23 19:24:103956 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3957 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423958}
3959
[email protected]87de04b02014-04-08 22:14:493960void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013961 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493962 const base::string16& message,
3963 const base::string16& default_prompt,
3964 const GURL& frame_url,
3965 JavaScriptMessageType javascript_message_type,
3966 IPC::Message* reply_msg) {
3967 // Suppress JavaScript dialogs when requested. Also suppress messages when
3968 // showing an interstitial as it's shown over the previous page and we don't
3969 // want the hidden page's dialogs to interfere with the interstitial.
3970 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503971 ShowingInterstitialPage() || !delegate_ ||
3972 delegate_->ShouldSuppressDialogs(this) ||
3973 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493974
3975 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:503976 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493977 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:033978 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:413979 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013980 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413981 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493982 &suppress_this_message);
3983 }
3984
3985 if (suppress_this_message) {
3986 // If we are suppressing messages, just reply as if the user immediately
3987 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013988 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3989 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283990 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493991 }
3992
3993 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3994 // http://crbug.com/288961 ). The only safe thing to do here is return.
3995}
3996
3997void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013998 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493999 bool is_reload,
4000 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014001 RenderFrameHostImpl* rfhi =
4002 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494003 if (delegate_)
4004 delegate_->WillRunBeforeUnloadConfirm();
4005
4006 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454007 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024008 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504009 delegate_->ShouldSuppressDialogs(this) ||
4010 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494011 if (suppress_this_message) {
4012 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4013 return;
4014 }
4015
4016 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504017 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494018 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424019 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494020 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014021 render_frame_host->GetProcess()->GetID(),
4022 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284023 false));
[email protected]87de04b02014-04-08 22:14:494024}
4025
[email protected]a86c0e962013-12-17 17:10:394026WebContents* WebContentsImpl::GetAsWebContents() {
4027 return this;
4028}
4029
[email protected]7912e822014-04-16 02:37:034030bool WebContentsImpl::IsNeverVisible() {
4031 if (!delegate_)
4032 return false;
4033 return delegate_->IsNeverVisible(this);
4034}
4035
[email protected]5a3bdf52012-05-24 15:12:574036RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4037 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324038}
4039
[email protected]8ff00d72012-10-23 19:12:214040RendererPreferences WebContentsImpl::GetRendererPrefs(
4041 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464042 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514043}
4044
avic3aa8422015-11-09 20:57:224045gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
4046 RenderWidgetHostImpl* render_widget_host) const {
4047 if (!RenderViewHostImpl::From(render_widget_host))
4048 return gfx::Rect();
4049
[email protected]b7a756d42012-01-23 18:08:174050 if (delegate_)
4051 return delegate_->GetRootWindowResizerRect();
4052 return gfx::Rect();
4053}
4054
[email protected]7a846df2012-09-20 19:17:394055void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274056 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394057 browser_plugin_embedder_.reset();
4058}
4059
[email protected]b172aee2012-04-10 17:05:264060void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444061 // Don't send notifications if we are just creating a swapped-out RVH for
4062 // the opener chain. These won't be used for view-source or WebUI, so it's
4063 // ok to return early.
creiscce56cd2014-09-29 22:45:224064 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444065 return;
4066
[email protected]86f98a22013-03-20 14:35:004067 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314068 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084069
[email protected]8ff00d72012-10-23 19:12:214070 NotificationService::current()->Notify(
4071 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4072 Source<WebContents>(this),
4073 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324074
[email protected]60780f412013-02-25 16:34:104075 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264076
4077 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254078 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324079}
4080
[email protected]b172aee2012-04-10 17:05:264081void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524082 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324083 // Don't notify the world, since this came from a renderer in the
4084 // background.
4085 return;
4086 }
4087
[email protected]da7a7182013-09-06 08:11:114088 notify_disconnection_ = true;
4089 // TODO(avi): Remove. http://crbug.com/170921
4090 NotificationService::current()->Notify(
4091 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4092 Source<WebContents>(this),
4093 NotificationService::NoDetails());
4094
[email protected]be1f56ab2011-12-22 06:55:314095 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234096 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304097
4098 // Restore the focus to the tab (otherwise the focus will be on the top
4099 // window).
[email protected]484ae5912010-09-29 19:16:144100 if (was_crashed && !FocusLocationBarByDefault() &&
4101 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064102 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144103 }
[email protected]32ded2212011-11-10 18:51:434104
[email protected]d8c660432011-12-22 20:51:254105 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324106}
4107
[email protected]ec6a7eb2013-04-22 17:34:224108void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4109 base::TerminationStatus status,
4110 int error_code) {
[email protected]151a63d2011-12-20 22:32:524111 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324112 // The pending page's RenderViewHost is gone.
4113 return;
4114 }
4115
[email protected]2fcdcc32014-03-05 02:14:074116 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4117 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524118 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464119 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074120
[email protected]698191dc2014-02-25 01:06:134121 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174122 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134123
[email protected]f738bdcb2014-07-11 20:40:444124 if (delegate_)
4125 delegate_->HideValidationMessage(this);
4126
[email protected]960b0372014-05-19 18:01:004127 // Reset the loading progress. TODO(avi): What does it mean to have a
4128 // "renderer crash" when there is more than one renderer process serving a
4129 // webpage? Once this function is called at a more granular frame level, we
4130 // probably will need to more granularly reset the state here.
4131 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254132 NotifyDisconnected();
4133 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004134
[email protected]d8c660432011-12-22 20:51:254135 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274136 observers_,
[email protected]58d5cfe2013-07-10 02:40:524137 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324138}
4139
[email protected]b172aee2012-04-10 17:05:264140void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254141 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064142}
4143
[email protected]b172aee2012-04-10 17:05:264144void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104145 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044146 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384147 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4148
creise1d3e5b2014-12-01 18:21:574149 // Ensure that this state update comes from a RenderViewHost that belongs to
4150 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414151 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574152 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414153 return;
[email protected]420ae012009-04-24 05:16:324154
avi286019ce2015-07-29 01:26:584155 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324156 // when the user is scrolling and entering form data, as well as when we're
4157 // leaving a page, in which case our state may have already been moved to
4158 // the next page. The navigation controller will look up the appropriate
4159 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584160 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114161 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584162 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114163 if (!entry)
[email protected]420ae012009-04-24 05:16:324164 return;
[email protected]420ae012009-04-24 05:16:324165
nasko346969912015-12-16 22:36:474166 // Sanity check that ensures nav_entry_id and page_id point to the same
4167 // navigation entry.
4168 if (rvhi->GetMainFrame()) {
4169 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4170 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4171 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534172
nasko346969912015-12-16 22:36:474173 DCHECK_EQ(entry, new_entry);
4174 }
creisd63f6c4a2015-11-06 19:05:534175
[email protected]691aa2f2013-05-28 22:52:044176 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324177 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044178 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114179 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324180}
4181
sky8b00392d2015-01-10 00:30:284182void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4183 const GURL& url) {
4184 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4185 // If we're fullscreen only update the url if it's from the fullscreen
4186 // renderer.
4187 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444188 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284189 return;
4190 }
[email protected]6934a702011-12-20 00:04:514191 if (delegate_)
avi450ce00e2014-09-24 01:58:524192 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324193}
4194
[email protected]b172aee2012-04-10 17:05:264195void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104196#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294197 // The UI may be in an event-tracking loop, such as between the
4198 // mouse-down and mouse-up in text selection or a button click.
4199 // Defer the close until after tracking is complete, so that we
4200 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294201 // TODO(shess): This could get more fine-grained. For instance,
4202 // closing a tab in another window while selecting text in the
4203 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104204 if (view_->IsEventTracking()) {
4205 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294206 return;
4207 }
[email protected]60780f412013-02-25 16:34:104208#endif
[email protected]07707302009-11-06 00:50:294209
[email protected]420ae012009-04-24 05:16:324210 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524211 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514212 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324213}
4214
[email protected]66bbadaf2014-03-28 16:25:544215void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574216 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4217 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574218}
4219
[email protected]b172aee2012-04-10 17:05:264220void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514221 if (delegate_ && delegate_->IsPopupOrPanel(this))
4222 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324223}
4224
fdegansa696e5112015-04-17 01:57:594225void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094226 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254227 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084228
4229 // Notify accessibility that the user is navigating away from the
4230 // current document.
4231 //
4232 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084233 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594234 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084235 if (manager)
4236 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324237}
4238
fdegansc73eec22015-03-19 14:47:544239void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084240 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324241
[email protected]9595fd82013-04-19 21:28:494242 // Use the last committed entry rather than the active one, in case a
4243 // pending entry has been created.
4244 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204245 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494246
[email protected]420ae012009-04-24 05:16:324247 // An entry may not exist for a stop when loading an initial blank page or
4248 // if an iframe injected by script into a blank page finishes loading.
4249 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204250 base::TimeDelta elapsed =
4251 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324252
4253 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514254 entry->GetVirtualURL(),
4255 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324256 elapsed,
4257 &controller_,
4258 controller_.GetCurrentEntryIndex()));
4259 }
4260
clamy44e84ce2016-02-22 15:38:254261 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324262}
4263
fdegansa696e5112015-04-17 01:57:594264void WebContentsImpl::DidChangeLoadProgress() {
4265 double load_progress = frame_tree_.load_progress();
4266
4267 // The delegate is notified immediately for the first and last updates. Also,
4268 // since the message loop may be pretty busy when a page is loaded, it might
4269 // not execute a posted task in a timely manner so the progress report is sent
4270 // immediately if enough time has passed.
4271 base::TimeDelta min_delay =
4272 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4273 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4274 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4275
4276 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4277 // If there is a pending task to send progress, it is now obsolete.
4278 loading_weak_factory_.InvalidateWeakPtrs();
4279
4280 // Notify the load progress change.
4281 SendChangeLoadProgress();
4282
4283 // Clean-up the states if needed.
4284 if (load_progress == 1.0)
4285 ResetLoadProgressState();
4286 return;
4287 }
4288
4289 if (loading_weak_factory_.HasWeakPtrs())
4290 return;
4291
skyostil95082a62015-06-05 19:53:074292 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4293 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4294 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594295 min_delay);
4296}
4297
[email protected]b172aee2012-04-10 17:05:264298void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164299 controller_.DiscardNonCommittedEntries();
4300
4301 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214302 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164303}
4304
[email protected]59167c22013-06-03 18:07:324305void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104306 has_accessed_initial_document_ = true;
4307
[email protected]d1371bf8e2014-04-19 03:26:244308 // We may have left a failed browser-initiated navigation in the address bar
4309 // to let the user edit it and try again. Clear it now that content might
4310 // show up underneath it.
4311 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454312 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244313
[email protected]59167c22013-06-03 18:07:324314 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504315 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324316}
4317
alexmosbe2f4c32015-03-10 02:30:234318void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4319 const std::string& name) {
4320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4321 FrameNameChanged(render_frame_host, name));
4322}
4323
[email protected]39f2f9252014-05-03 00:54:014324void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294325 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094326 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294327 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094328
4329 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214330 NotificationService::current()->Notify(
4331 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4332 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294333 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084334}
4335
creis8eb8ef22015-11-04 22:51:384336void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4337 const PageState& page_state) {
4338 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4339
4340 // The state update affects the last NavigationEntry associated with the given
4341 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4342 // in the case of an UpdateState from a frame being swapped out). We track
4343 // which entry this is in the RenderFrameHost's nav_entry_id.
4344 RenderFrameHostImpl* rfhi =
4345 static_cast<RenderFrameHostImpl*>(render_frame_host);
4346 NavigationEntryImpl* entry =
4347 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4348 if (!entry)
4349 return;
4350
4351 FrameNavigationEntry* frame_entry =
4352 entry->GetFrameEntry(rfhi->frame_tree_node());
4353 if (!frame_entry)
4354 return;
4355
creisd06a9422015-11-11 03:08:454356 // The SiteInstance might not match if we do a cross-process navigation with
4357 // replacement (e.g., auto-subframe), in which case the swap out of the old
4358 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4359 // has already been replaced and destroyed.
4360 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4361 return;
4362
creis8eb8ef22015-11-04 22:51:384363 if (page_state == frame_entry->page_state())
4364 return; // Nothing to update.
4365
4366 frame_entry->set_page_state(page_state);
4367 controller_.NotifyEntryChanged(entry);
4368}
4369
[email protected]ef3adfc2014-05-11 00:04:544370void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104371 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544372 const base::string16& title,
4373 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544374 // If we have a title, that's a pretty good indication that we've started
4375 // getting useful data.
4376 SetNotWaitingForResponse();
4377
4378 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584379 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544380 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584381 render_frame_host->GetSiteInstance(), page_id);
4382
creis081bc102016-02-26 00:56:274383 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4384 // and intentionally skip updates when the most recent commit was ignored.
4385 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544386
4387 // We can handle title updates when we don't have an entry in
4388 // UpdateTitleForEntry, but only if the update is from the current RVH.
4389 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584390 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544391 return;
4392
4393 // TODO(evan): make use of title_direction.
4394 // http://code.google.com/p/chromium/issues/detail?id=27094
4395 if (!UpdateTitleForEntry(entry, title))
4396 return;
4397
4398 // Broadcast notifications when the UI should be updated.
4399 if (entry == controller_.GetEntryAtOffset(0))
4400 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4401}
4402
4403void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4404 const std::string& encoding) {
4405 SetEncoding(encoding);
4406}
4407
[email protected]39f2f9252014-05-03 00:54:014408void WebContentsImpl::DocumentAvailableInMainFrame(
4409 RenderViewHost* render_view_host) {
4410 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4411 DocumentAvailableInMainFrame());
4412}
naskoc0fceff2015-04-30 15:53:524413
[email protected]e1c3a552012-05-04 20:51:324414void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4415 // Tell the active RenderViewHost to run unload handlers and close, as long
4416 // as the request came from a RenderViewHost in the same BrowsingInstance.
4417 // In most cases, we receive this from a swapped out RenderViewHost.
4418 // It is possible to receive it from one that has just been swapped in,
4419 // in which case we might as well deliver the message anyway.
4420 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524421 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324422}
4423
alexmose7da5a12015-04-09 02:22:164424bool WebContentsImpl::ShouldRouteMessageEvent(
4425 RenderFrameHost* target_rfh,
4426 SiteInstance* source_site_instance) const {
4427 // Allow the message if this WebContents is dedicated to a browser plugin
4428 // guest.
[email protected]0eba810b2012-10-18 03:19:364429 // Note: This check means that an embedder could theoretically receive a
4430 // postMessage from anyone (not just its own guests). However, this is
4431 // probably not a risk for apps since other pages won't have references
4432 // to App windows.
alexmose7da5a12015-04-09 02:22:164433 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4434}
[email protected]f546640b2012-05-15 00:03:494435
alexmos58729042015-06-18 23:20:004436void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164437 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4438 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494439
alexmose7da5a12015-04-09 02:22:164440 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144441 // If this message is going to outer WebContents from inner WebContents,
4442 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4443 // already created a RenderFrameProxyHost for that purpose.
4444 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084445 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144446 return;
4447 }
4448
lfg812874d2016-02-09 22:26:134449 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064450 // We create a RenderFrameProxyHost for the embedder in the guest's render
4451 // process but we intentionally do not expose the embedder's opener chain
4452 // to it.
4453 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4454 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494455 } else {
alexmos58729042015-06-18 23:20:004456 RenderFrameHostImpl* source_rfhi =
4457 static_cast<RenderFrameHostImpl*>(source_rfh);
4458 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394459 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494460 }
4461 }
[email protected]f546640b2012-05-15 00:03:494462}
4463
avib7348942015-12-25 20:57:104464bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264465 const base::string16& message,
avib7348942015-12-25 20:57:104466 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264467 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254468 if (!delegate_)
4469 return false;
4470 return delegate_->AddMessageToConsole(this, level, message, line_no,
4471 source_id);
4472}
4473
dominickn9c7ceaa32016-02-27 01:52:534474void WebContentsImpl::OnUserInteraction(
4475 RenderWidgetHostImpl* render_widget_host,
4476 const blink::WebInputEvent::Type type) {
4477 // Ignore when the renderer is swapped out.
4478 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224479 if (render_widget_host != GetRenderViewHost()->GetWidget())
4480 return;
4481
dominickn2dd142dd2015-10-29 05:30:504482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4483 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534484
4485 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4486 // Exclude scroll events as user gestures for resource load dispatches.
4487 // rdh is NULL in unittests.
4488 if (rdh && type != blink::WebInputEvent::MouseWheel)
4489 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504490}
4491
[email protected]b172aee2012-04-10 17:05:264492void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444493 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254494 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444495}
4496
avic3aa8422015-11-09 20:57:224497void WebContentsImpl::RendererUnresponsive(
4498 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474499 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4500 OnRendererUnresponsive(render_widget_host));
4501
[email protected]992db4c2011-05-12 15:37:154502 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224503 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154504 return;
4505
creiscce56cd2014-09-29 22:45:224506 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224507 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584508
[email protected]e5fc1632011-08-08 07:51:534509 // Ignore renderer unresponsive event if debugger is attached to the tab
4510 // since the event may be a result of the renderer sitting on a breakpoint.
4511 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364512 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534513 return;
4514
clamy226727e2015-06-29 10:28:474515 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224516 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324517 // Hang occurred while firing the beforeunload/unload handler.
4518 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224519 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324520
[email protected]fa944cb82013-11-15 17:51:214521 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324522 return;
4523
4524 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564525 // nothing we can do to recover. If the hang is in the beforeunload handler,
4526 // pretend the beforeunload listeners have all fired and allow the delegate
4527 // to continue closing; the user will not have the option of cancelling the
4528 // close. Otherwise, pretend the unload listeners have all fired and close
4529 // the tab.
4530 bool close = true;
clamy226727e2015-06-29 10:28:474531 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564532 delegate_->BeforeUnloadFired(this, true, &close);
4533 }
4534 if (close)
avic3aa8422015-11-09 20:57:224535 Close();
[email protected]420ae012009-04-24 05:16:324536 return;
4537 }
4538
creisc014b402015-04-23 16:41:454539 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474540 return;
4541
[email protected]6934a702011-12-20 00:04:514542 if (delegate_)
4543 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324544}
4545
avic3aa8422015-11-09 20:57:224546void WebContentsImpl::RendererResponsive(
4547 RenderWidgetHostImpl* render_widget_host) {
4548 if (render_widget_host != GetRenderViewHost()->GetWidget())
4549 return;
4550
[email protected]6934a702011-12-20 00:04:514551 if (delegate_)
4552 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324553}
4554
[email protected]b172aee2012-04-10 17:05:264555void WebContentsImpl::LoadStateChanged(
4556 const GURL& url,
4557 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104558 uint64_t upload_position,
4559 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544560 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4561 // is fixed.
4562 tracked_objects::ScopedTracker tracking_profile1(
4563 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4564 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324565 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564566 upload_position_ = upload_position;
4567 upload_size_ = upload_size;
jshin1fb76462016-04-05 22:13:034568 load_state_host_ = url_formatter::IDNToUnicode(url.host());
[email protected]9c235f042011-08-10 22:28:214569 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324570 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464571 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224572 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4573 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464574 }
[email protected]420ae012009-04-24 05:16:324575}
4576
[email protected]b172aee2012-04-10 17:05:264577void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554578 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324579 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124580 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4581 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514582 if (delegate_)
4583 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094584 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324585}
4586
[email protected]58d5cfe2013-07-10 02:40:524587void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544588 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234589 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224590 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544591}
4592
[email protected]b172aee2012-04-10 17:05:264593void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104594 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214595 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264596 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4597 // here during container initialization and normal window size will be set
4598 // later. In case of tab duplication this resizing to 0x0 prevents setting
4599 // normal size later so just ignore it.
4600 if (!size.IsEmpty())
4601 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324602}
4603
[email protected]af905902013-10-01 21:38:514604void WebContentsImpl::CancelModalDialogsForRenderManager() {
4605 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544606 // deferrer would prevent us from swapping out. We also clear the state
4607 // because this is a cross-process navigation, which means that it's a new
4608 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174609 //
4610 // Note that we don't bother telling browser_plugin_embedder_ because the
4611 // cross-process navigation will either destroy the browser plugins or not
4612 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514613 if (dialog_manager_)
avi2460c762015-04-17 15:21:544614 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514615}
4616
[email protected]02d7b6e2014-06-24 21:01:504617void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4618 RenderFrameHost* new_host,
4619 bool is_main_frame) {
4620 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054621 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504622 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084623
[email protected]02d7b6e2014-06-24 21:01:504624 // Make sure the visible RVH reflects the new delegate's preferences.
4625 if (delegate_)
4626 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394627
[email protected]02d7b6e2014-06-24 21:01:504628 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4629 }
4630
4631 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544632}
4633
naskof5940b9f2015-03-02 23:04:054634void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4635 RenderViewHost* old_host,
4636 RenderViewHost* new_host) {
4637 NotifyViewSwapped(old_host, new_host);
4638}
4639
[email protected]b172aee2012-04-10 17:05:264640NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194641 return GetController();
[email protected]3a3d47472010-07-15 21:03:544642}
4643
dcheng59716272016-04-09 05:19:084644std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294645 const GURL& url) {
dcheng59716272016-04-09 05:19:084646 return std::unique_ptr<WebUIImpl>(
4647 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324648}
4649
[email protected]10f417c52011-12-28 21:04:234650NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264651 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324652 return controller_.GetLastCommittedEntry();
4653}
4654
lfgbede6392015-09-11 21:54:064655void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4656 RenderViewHost* render_view_host) {
4657 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144658 bool is_guest_in_site_per_process =
4659 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084660 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064661 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164662 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444663 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164664 rwh_view = rwh_view_child;
4665 } else {
avif9ab5d942015-10-15 14:05:444666 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164667 }
[email protected]1a98a932009-11-17 00:12:524668
[email protected]420ae012009-04-24 05:16:324669 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444670 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214671 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064672}
4673
4674bool WebContentsImpl::CreateRenderViewForRenderManager(
4675 RenderViewHost* render_view_host,
4676 int opener_frame_routing_id,
4677 int proxy_routing_id,
4678 const FrameReplicationState& replicated_frame_state) {
4679 TRACE_EVENT0("browser,navigation",
4680 "WebContentsImpl::CreateRenderViewForRenderManager");
4681
4682 if (proxy_routing_id == MSG_ROUTING_NONE)
4683 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324684
[email protected]74ce1ad2011-12-16 21:51:464685 // Make sure we use the correct starting page_id in the new RenderView.
4686 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104687 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584688 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464689
alexmos5ac402d2015-07-09 07:51:104690 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4691 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4692 max_page_id, replicated_frame_state,
4693 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524694 return false;
[email protected]14392a52012-05-02 20:28:444695 }
[email protected]a4127722011-04-27 23:13:524696
avi2b177592014-12-10 02:08:024697 SetHistoryOffsetAndLengthForView(render_view_host,
4698 controller_.GetLastCommittedEntryIndex(),
4699 controller_.GetEntryCount());
4700
[email protected]a220b5932013-09-21 03:47:444701#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504702 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4703 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444704 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444705 if (rwh_view) {
4706 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4707 render_widget_host->WasResized();
4708 }
[email protected]f8233cc2011-05-31 20:24:504709#endif
4710
[email protected]420ae012009-04-24 05:16:324711 return true;
4712}
4713
[email protected]82307f6b2014-08-07 03:30:124714bool WebContentsImpl::CreateRenderFrameForRenderManager(
4715 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044716 int proxy_routing_id,
4717 int opener_routing_id,
japhete6adf142014-10-31 00:01:494718 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044719 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434720 TRACE_EVENT0("browser,navigation",
4721 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124722
4723 RenderFrameHostImpl* rfh =
4724 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044725 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4726 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124727 return false;
4728
4729 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4730 // RenderFrameHost will have to be associated with the appropriate
4731 // RenderWidgetHostView or a new one should be created here.
4732
4733 return true;
4734}
4735
mfomitchev2b8b066a2016-01-28 19:23:154736#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454737
[email protected]155c7f22013-12-09 17:07:184738base::android::ScopedJavaLocalRef<jobject>
4739WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404740 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564741 return GetWebContentsAndroid()->GetJavaObject();
4742}
[email protected]155c7f22013-12-09 17:07:184743
[email protected]0e813a52014-08-13 10:34:564744WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184745 WebContentsAndroid* web_contents_android =
4746 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4747 if (!web_contents_android) {
4748 web_contents_android = new WebContentsAndroid(this);
4749 SetUserData(kWebContentsAndroidKey, web_contents_android);
4750 }
[email protected]0e813a52014-08-13 10:34:564751 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184752}
4753
paulmeyerc0b762b2016-04-13 11:55:174754void WebContentsImpl::ActivateNearestFindResult(float x,
4755 float y) {
4756 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4757}
4758
4759void WebContentsImpl::RequestFindMatchRects(int current_version) {
4760 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4761}
4762
[email protected]7d244f12013-08-22 21:41:514763bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064764 return CreateRenderViewForRenderManager(
4765 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064766 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514767}
[email protected]fc2b46b2014-05-03 16:33:454768
4769#elif defined(OS_MACOSX)
4770
[email protected]75f4df72014-07-16 22:39:424771void WebContentsImpl::SetAllowOtherViews(bool allow) {
4772 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454773}
4774
[email protected]75f4df72014-07-16 22:39:424775bool WebContentsImpl::GetAllowOtherViews() {
4776 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454777}
4778
[email protected]7d244f12013-08-22 21:41:514779#endif
4780
pkotwicz75ca8ffd2016-02-16 23:10:194781void WebContentsImpl::OnDidDownloadImage(
4782 const ImageDownloadCallback& callback,
4783 int id,
4784 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524785 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044786 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524787 mojo::Array<mojo::SizePtr> original_image_sizes) {
4788 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4789 const std::vector<gfx::Size> sizes =
4790 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194791
leon.hancbc4bc3c2016-02-26 07:08:524792 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194793}
4794
[email protected]6fba26d2014-04-29 09:38:284795void WebContentsImpl::OnDialogClosed(int render_process_id,
4796 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264797 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494798 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264799 bool success,
[email protected]fcf75d42013-12-03 20:11:264800 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284801 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4802 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494803 last_dialog_suppressed_ = dialog_was_suppressed;
4804
[email protected]beb440c2009-11-06 04:08:544805 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:234806 // It is possible for the current RenderFrameHost to have changed in the
4807 // meantime. Do not reset the navigation state in that case.
4808 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:254809 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:234810 controller_.DiscardNonCommittedEntries();
4811 }
[email protected]ec8e8b02013-06-19 04:57:104812
[email protected]6d65a462013-06-21 21:29:124813 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4814 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544815 }
[email protected]87de04b02014-04-08 22:14:494816
[email protected]beb440c2009-11-06 04:08:544817 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284818 if (rfh) {
4819 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4820 dialog_was_suppressed);
4821 } else {
4822 // Don't leak the sync IPC reply if the RFH or process is gone.
4823 delete reply_msg;
4824 }
[email protected]beb440c2009-11-06 04:08:544825}
4826
[email protected]b172aee2012-04-10 17:05:264827void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544828 if (encoding == last_reported_encoding_)
4829 return;
4830 last_reported_encoding_ = encoding;
4831
4832 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124833 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104834}
[email protected]f45d2a72010-03-08 23:28:354835
[email protected]1ac10dca2013-08-20 20:47:044836bool WebContentsImpl::IsHidden() {
4837 return capturer_count_ == 0 && !should_normally_be_visible_;
4838}
4839
rob97250742015-12-10 17:45:154840int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144841 if (node_ && node_->outer_web_contents())
4842 return node_->outer_contents_frame_tree_node_id();
4843
nick2482a2d2015-12-18 01:39:374844 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144845}
4846
[email protected]b0936d22013-11-28 06:47:364847RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214848 return frame_tree_.root()->render_manager();
4849}
4850
lazyboy8e16ddfd2015-09-28 03:41:564851WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4852 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4853 if (node_)
4854 return node_->outer_web_contents();
4855 } else {
4856 if (GetBrowserPluginGuest())
4857 return GetBrowserPluginGuest()->embedder_web_contents();
4858 }
4859 return nullptr;
4860}
4861
[email protected]f8497342013-02-05 22:15:024862BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394863 return browser_plugin_guest_.get();
4864}
4865
[email protected]738f57a2013-06-29 21:06:544866void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4867 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144868 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544869 browser_plugin_guest_.reset(guest);
4870}
4871
[email protected]f8497342013-02-05 22:15:024872BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394873 return browser_plugin_embedder_.get();
4874}
[email protected]8ff00d72012-10-23 19:12:214875
fsamuel60b42282015-03-10 03:29:144876void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4877 if (browser_plugin_embedder_)
4878 return;
4879 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4880}
4881
[email protected]fc2b46b2014-05-03 16:33:454882gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214883 gfx::Size size;
4884 if (delegate_)
4885 size = delegate_->GetSizeForNewRenderView(this);
4886 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454887 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214888 return size;
4889}
4890
[email protected]ae7eeda2014-07-04 01:53:264891void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4892 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024893 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554894}
4895
[email protected]222f5822014-02-05 23:40:494896void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4897 if (!delegate_)
4898 return;
4899 const gfx::Size new_size = GetPreferredSize();
4900 if (new_size != old_size)
4901 delegate_->UpdatePreferredSize(this, new_size);
4902}
4903
dbeama1b926a2015-08-31 23:17:514904WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4905 const std::string& frame_name) {
4906 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4907 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4908 CreateWebUIControllerForURL(web_ui, url);
4909 if (controller) {
4910 web_ui->AddMessageHandler(new GenericHandler());
4911 web_ui->SetController(controller);
4912 return web_ui;
4913 }
4914
4915 delete web_ui;
4916 return NULL;
4917}
4918
paulmeyerc0b762b2016-04-13 11:55:174919FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
4920 // TODO(paulmeyer): This method will need to access (or potentially create)
4921 // the FindRequestManager in the outermost WebContents once find-in-page
4922 // across GuestViews is implemented.
4923 if (!find_request_manager_)
4924 find_request_manager_.reset(new FindRequestManager(this));
4925
4926 return find_request_manager_.get();
4927}
4928
4929void WebContentsImpl::NotifyFindReply(int request_id,
4930 int number_of_matches,
4931 const gfx::Rect& selection_rect,
4932 int active_match_ordinal,
4933 bool final_update) {
4934 if (delegate_) {
4935 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
4936 active_match_ordinal, final_update);
4937 }
4938}
4939
4940#if defined(OS_ANDROID)
4941void WebContentsImpl::NotifyFindMatchRectsReply(
4942 int version,
4943 const std::vector<gfx::RectF>& rects,
4944 const gfx::RectF& active_rect) {
4945 if (delegate_)
4946 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
4947}
4948#endif
4949
[email protected]34ff1cfc2014-08-20 06:16:054950void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4951 force_disable_overscroll_content_ = force_disable;
4952 if (view_)
4953 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4954}
4955
dalecurtis88c240072015-12-09 02:11:184956void WebContentsImpl::MediaStartedPlaying(
4957 const WebContentsObserver::MediaPlayerId& id) {
4958 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4959}
4960
4961void WebContentsImpl::MediaStoppedPlaying(
4962 const WebContentsObserver::MediaPlayerId& id) {
4963 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4964}
4965
tapted65ff2ea72016-03-01 23:39:004966void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4967 if (!did_first_set_visible_) {
4968 // If this WebContents has not yet been set to be visible for the first
4969 // time, ignore any requests to make it hidden, since resources would
4970 // immediately be destroyed and only re-created after content loaded. In
4971 // this state the window content is undefined and can show garbage.
4972 // However, the page load mechanism requires an activation call through a
4973 // visibility call to (re)load.
4974 if (visible) {
4975 did_first_set_visible_ = true;
4976 WasShown();
4977 }
4978 return;
4979 }
4980 if (visible == should_normally_be_visible_)
4981 return;
4982
4983 if (visible)
4984 WasShown();
4985 else
4986 WasHidden();
4987}
4988
aelias5252baa2016-04-10 01:18:024989void WebContentsImpl::UpdateOverridingUserAgent() {
4990 std::set<RenderViewHost*> render_view_host_set;
4991 for (FrameTreeNode* node : frame_tree_.Nodes()) {
4992 RenderWidgetHost* render_widget_host =
4993 node->current_frame_host()->GetRenderWidgetHost();
4994 if (!render_widget_host)
4995 continue;
4996 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
4997 if (!render_view_host)
4998 continue;
4999 render_view_host_set.insert(render_view_host);
5000 }
5001 for (RenderViewHost* render_view_host : render_view_host_set)
5002 render_view_host->OnWebkitPreferencesChanged();
5003}
5004
avid53461d2016-02-25 17:15:045005void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5006 JavaScriptDialogManager* dialog_manager) {
5007 dialog_manager_ = dialog_manager;
5008}
5009
[email protected]8ff00d72012-10-23 19:12:215010} // namespace content