blob: 37e888778c1307e392997a508432cf75cda71c15 [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"
creisfafed882016-07-29 00:03:0913#include "base/debug/dump_without_crashing.h"
zqzhang181047e62016-07-01 13:37:1714#include "base/feature_list.h"
[email protected]cbb1ef592013-06-05 19:49:4615#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0716#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5617#include "base/logging.h"
avib7348942015-12-25 20:57:1018#include "base/macros.h"
fdorayba121422016-12-23 19:51:4819#include "base/memory/ptr_util.h"
dmazzonid95ae842016-04-12 21:17:3920#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4321#include "base/metrics/histogram_macros.h"
[email protected]04cbd3d2013-12-04 04:58:2022#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2223#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0724#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5125#include "base/strings/string16.h"
26#include "base/strings/string_number_conversions.h"
27#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0028#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5529#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3730#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4231#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1032#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2533#include "components/mime_util/mime_util.h"
nzolghadrd87a308d2016-12-07 15:45:5634#include "components/rappor/public/rappor_utils.h"
rsleevi24f64dc22015-08-07 21:39:2135#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3036#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1837#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3938#include "content/browser/browser_plugin/browser_plugin_embedder.h"
39#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5940#include "content/browser/child_process_security_policy_impl.h"
dgozmanf00c4f72016-10-19 17:45:1541#include "content/browser/devtools/render_frame_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4142#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0443#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4644#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1245#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1646#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1747#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3849#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4050#include "content/browser/frame_host/interstitial_page_impl.h"
51#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3352#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0153#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1854#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0755#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1656#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0557#include "content/browser/host_zoom_map_impl.h"
scottmg276753cf2016-10-27 18:25:2258#include "content/browser/host_zoom_map_observer.h"
csharrison2e8c98e2016-08-01 23:56:2559#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4460#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4061#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3062#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5263#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1864#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4565#include "content/browser/media/session/media_session_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5366#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0967#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3068#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5069#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3270#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5071#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5972#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4873#include "content/browser/renderer_host/render_widget_host_view_base.h"
ekaramadadd882292016-06-08 15:22:5674#include "content/browser/renderer_host/text_input_manager.h"
lunalud4a2cc82016-11-22 00:27:2375#include "content/browser/screen_orientation/screen_orientation.h"
[email protected]b6583592012-01-25 19:52:3376#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3377#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1178#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5879#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0380#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5681#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1482#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4283#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5184#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4485#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1786#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0787#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0688#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1889#include "content/common/render_message_filter.mojom.h"
avi286019ce2015-07-29 01:26:5890#include "content/common/site_isolation_policy.h"
[email protected]2c5569662011-03-22 20:45:0291#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3692#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1193#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2894#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4495#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:1796#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1497#include "content/public/browser/download_url_parameters.h"
ekaramada110f642016-12-21 19:47:2898#include "content/public/browser/focused_node_details.h"
ekaramad1beabecc2016-09-23 20:18:1799#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:46100#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15101#include "content/public/browser/javascript_dialog_manager.h"
[email protected]09d31d52012-03-11 22:30:27102#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00103#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37104#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14105#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08106#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30107#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32108#include "content/public/browser/resource_request_details.h"
lunalud4a2cc82016-11-22 00:27:23109#include "content/public/browser/screen_orientation_provider.h"
estark5ea80e52015-06-19 18:43:12110#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40111#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34112#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38113#include "content/public/browser/user_metrics.h"
rockotf62002a2016-09-15 00:08:59114#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42115#include "content/public/browser/web_contents_delegate.h"
dtapuskae99ec6e52016-10-18 00:15:42116#include "content/public/browser/web_contents_unresponsive_state.h"
[email protected]e091df82011-10-11 18:13:21117#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35118#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37119#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48120#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54121#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49122#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20123#include "content/public/common/result_codes.h"
[email protected]f16cc6782013-12-16 23:42:57124#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05125#include "content/public/common/web_preferences.h"
mcasas4e216e72016-07-28 21:28:38126#include "device/geolocation/geolocation_service_context.h"
sammc5a139ba2016-09-29 01:49:14127#include "device/nfc/nfc.mojom.h"
blundelld46e8832016-10-07 10:34:27128#include "device/wake_lock/wake_lock_service_context.h"
wjmaclean64951902016-04-29 20:59:12129#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53130#include "net/http/http_cache.h"
131#include "net/http/http_transaction_factory.h"
132#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34133#include "net/url_request/url_request_context_getter.h"
brettw4b461082016-11-19 18:55:16134#include "ppapi/features/features.h"
rockot734fb662016-10-15 16:41:30135#include "services/service_manager/public/cpp/interface_provider.h"
estark47ba9c7d2016-10-11 15:40:11136#include "third_party/WebKit/public/platform/WebSecurityStyle.h"
alexmosaedfc6f2016-01-21 23:57:38137#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40138#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39139#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56140#include "ui/base/layout.h"
chongz4a9751942016-08-17 17:49:39141#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52142#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31143
ekaramada110f642016-12-21 19:47:28144#if defined(OS_WIN)
145#include "content/browser/renderer_host/dip_util.h"
146#include "ui/gfx/geometry/dip_util.h"
147#endif
148
[email protected]583418cc2013-01-17 14:01:10149#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40150#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15151#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11152#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46153#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18154#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15155#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10156
[email protected]f66df822012-05-18 16:52:17157#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50158#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57159#endif
[email protected]3e45ba92009-02-20 21:09:00160
sadrul943e3b32016-08-04 18:22:59161#if defined(USE_AURA)
bend32292b2016-10-07 00:21:58162#include "content/public/common/service_manager_connection.h"
fsamuel6c6da0232015-11-26 05:13:46163#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32164#endif
165
brettw4b461082016-11-19 18:55:16166#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17167#include "content/browser/media/session/pepper_playback_observer.h"
168#endif // ENABLE_PLUGINS
169
[email protected]8ff00d72012-10-23 19:12:21170namespace content {
[email protected]420ae012009-04-24 05:16:32171namespace {
172
[email protected]960b0372014-05-19 18:01:00173const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41174const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05175
[email protected]155c7f22013-12-09 17:07:18176#if defined(OS_ANDROID)
177const char kWebContentsAndroidKey[] = "web_contents_android";
178#endif // OS_ANDROID
179
[email protected]e4abd3b42013-11-12 18:28:47180base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46181g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
182
[email protected]8bfc8272013-09-09 20:10:53183void NotifyCacheOnIO(
184 scoped_refptr<net::URLRequestContextGetter> request_context,
185 const GURL& url,
186 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58187 net::HttpCache* cache = request_context->GetURLRequestContext()->
188 http_transaction_factory()->GetCache();
189 if (cache)
190 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53191}
192
dcheng57e39e22016-01-21 00:25:38193bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
194 for (FrameTreeNode* node : tree->Nodes()) {
195 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
196 return true;
alexmos4cf2aa32015-07-15 23:40:43197 }
dcheng57e39e22016-01-21 00:25:38198 return false;
[email protected]95640212014-07-26 18:14:30199}
200
kenrb19221852016-04-29 17:21:40201bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
202 // This method scans the frame tree rather than checking whether
203 // host->delegate() == this, which allows it to return false when the host
204 // for a frame that is pending or pending deletion.
205 if (!host)
206 return false;
207
208 for (FrameTreeNode* node : tree->Nodes()) {
209 if (node->current_frame_host()->GetRenderWidgetHost() == host)
210 return true;
211 }
212 return false;
213}
214
dmazzonif8a31042016-12-03 00:52:13215void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
216 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30217}
218
dtseng0dd3fa12015-07-22 19:00:52219void ResetAccessibility(RenderFrameHost* rfh) {
220 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
221}
222
dmazzonid95ae842016-04-12 21:17:39223using AXTreeSnapshotCallback =
224 base::Callback<void(const ui::AXTreeUpdate&)>;
225
226// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
227// Handles the callbacks from parallel snapshot requests to each frame,
228// and feeds the results to an AXTreeCombiner, which converts them into a
229// single combined accessibility tree.
230class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
231 public:
232 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
233 : callback_(callback) {
234 }
235
236 AXTreeSnapshotCallback AddFrame(bool is_root) {
237 // Adds a reference to |this|.
238 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
239 this,
240 is_root);
241 }
242
243 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
244 combiner_.AddTree(snapshot, is_root);
245 }
246
247 private:
248 friend class base::RefCounted<AXTreeSnapshotCombiner>;
249
250 // This is called automatically after the last call to ReceiveSnapshot
251 // when there are no more references to this object.
252 ~AXTreeSnapshotCombiner() {
253 combiner_.Combine();
254 callback_.Run(combiner_.combined());
255 }
256
257 ui::AXTreeCombiner combiner_;
258 AXTreeSnapshotCallback callback_;
259};
260
[email protected]420ae012009-04-24 05:16:32261} // namespace
262
[email protected]54944cde2012-12-09 09:24:59263WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21264 FrameTreeNode* opener_node = nullptr;
265 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
266 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
267 params.opener_render_process_id, params.opener_render_frame_id);
268 if (opener_rfh)
269 opener_node = opener_rfh->frame_tree_node();
270 }
271 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19272}
273
274WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59275 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30276 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21277 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30278
279 for (SessionStorageNamespaceMap::const_iterator it =
280 session_storage_namespace_map.begin();
281 it != session_storage_namespace_map.end();
282 ++it) {
283 new_contents->GetController()
284 .SetSessionStorageNamespace(it->first, it->second.get());
285 }
286
[email protected]54944cde2012-12-09 09:24:59287 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19288 return new_contents;
[email protected]a81343d232011-12-27 07:39:20289}
[email protected]746d3052012-05-22 15:15:47290
nickf9acfbe2014-12-23 19:12:37291void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
292 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46293 g_created_callbacks.Get().push_back(callback);
294}
295
nickf9acfbe2014-12-23 19:12:37296void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
297 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46298 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
299 if (g_created_callbacks.Get().at(i).Equals(callback)) {
300 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
301 return;
302 }
303 }
304}
305
avidf38c952015-10-27 13:45:13306WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
307 if (!rvh)
308 return nullptr;
[email protected]746d3052012-05-22 15:15:47309 return rvh->GetDelegate()->GetAsWebContents();
310}
311
[email protected]a86c0e962013-12-17 17:10:39312WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13313 if (!rfh)
314 return nullptr;
315 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39316}
317
ananta4b7467a52016-09-23 01:42:38318WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
319 FrameTreeNode* frame_tree_node =
320 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19321 if (!frame_tree_node)
322 return nullptr;
ananta4b7467a52016-09-23 01:42:38323 return FromRenderFrameHost(frame_tree_node->current_frame_host());
324}
325
[email protected]7fff43e2013-05-21 20:21:10326// WebContentsImpl::DestructionObserver ----------------------------------------
327
328class WebContentsImpl::DestructionObserver : public WebContentsObserver {
329 public:
330 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
331 : WebContentsObserver(watched_contents),
332 owner_(owner) {
333 }
334
335 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58336 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58337 owner_->OnWebContentsDestroyed(
338 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10339 }
340
341 private:
342 WebContentsImpl* owner_;
343
344 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
345};
346
[email protected]8ed16472014-04-11 19:02:48347WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
348 int render_frame_id,
349 ColorChooser* chooser,
350 int identifier)
351 : render_process_id(render_process_id),
352 render_frame_id(render_frame_id),
353 chooser(chooser),
354 identifier(identifier) {
355}
356
357WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
358}
359
nicka0ac8382016-12-15 23:59:23360bool WebContentsImpl::ColorChooserInfo::Matches(
361 RenderFrameHostImpl* render_frame_host,
362 int color_chooser_id) {
363 return this->render_process_id == render_frame_host->GetProcess()->GetID() &&
364 this->render_frame_id == render_frame_host->GetRoutingID() &&
365 this->identifier == color_chooser_id;
366}
367
lazyboy6ec48b2a2015-06-29 15:18:14368// WebContentsImpl::WebContentsTreeNode ----------------------------------------
369WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
370 : outer_web_contents_(nullptr),
371 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33372 FrameTreeNode::kFrameTreeNodeInvalidId),
373 focused_web_contents_(nullptr) {}
lazyboy6ec48b2a2015-06-29 15:18:14374
375WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
376 // Remove child pointer from our parent.
377 if (outer_web_contents_) {
378 ChildrenSet& child_ptrs_in_parent =
379 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
380 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
381 DCHECK(iter != child_ptrs_in_parent.end());
avallee0206f782016-07-28 18:55:33382 child_ptrs_in_parent.erase(iter);
lazyboy6ec48b2a2015-06-29 15:18:14383 }
384
385 // Remove parent pointers from our children.
386 // TODO(lazyboy): We should destroy the children WebContentses too. If the
387 // children do not manage their own lifetime, then we would leak their
388 // WebContentses.
389 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
390 child->outer_web_contents_ = nullptr;
391}
392
393void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
394 WebContentsImpl* outer_web_contents,
395 RenderFrameHostImpl* outer_contents_frame) {
avallee0206f782016-07-28 18:55:33396 DCHECK(!focused_web_contents_) << "Should not attach a root node.";
lazyboy6ec48b2a2015-06-29 15:18:14397 outer_web_contents_ = outer_web_contents;
398 outer_contents_frame_tree_node_id_ =
399 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
400
avallee0206f782016-07-28 18:55:33401 if (!outer_web_contents_->node_) {
402 // This will only be reached when creating a new WebContents tree.
403 // Initialize the root of this tree and set it as focused.
lazyboy6ec48b2a2015-06-29 15:18:14404 outer_web_contents_->node_.reset(new WebContentsTreeNode());
avallee0206f782016-07-28 18:55:33405 outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_);
406 }
lazyboy6ec48b2a2015-06-29 15:18:14407
408 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
409}
410
avallee0206f782016-07-28 18:55:33411void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
412 WebContentsImpl* web_contents) {
413 DCHECK(!outer_web_contents())
414 << "Only the outermost WebContents tracks focus.";
415 focused_web_contents_ = web_contents;
416}
417
[email protected]b172aee2012-04-10 17:05:26418// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32419
alexmose201c7cd2015-06-10 17:14:21420WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42421 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22422 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57423 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21424 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01425 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57426 this,
427 this,
428 this,
429 this),
[email protected]6dfed692014-05-22 04:18:03430 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23431 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
432 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34433 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26434 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56435 upload_size_(0),
436 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16437 is_resume_pending_(false),
[email protected]b4c84012014-04-28 19:51:10438 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28439 theme_color_(SK_ColorTRANSPARENT),
440 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29441 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55442 capturer_count_(0),
443 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00444 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57445 is_being_destroyed_(false),
446 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15447 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01448 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39449 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38450 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21451 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
452 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22453 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37454 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42455 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03456 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49457 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05458 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30459 last_dialog_suppressed_(false),
mcasas4e216e72016-07-28 21:28:38460 geolocation_service_context_(new device::GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48461 accessibility_mode_(
462 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15463 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35464 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50465 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46466 page_scale_factor_is_one_(true),
lfgbee1e0a2016-06-08 21:24:21467 mouse_lock_widget_(nullptr),
qinmin72e8bd02016-10-21 19:35:37468 is_overlay_content_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19469 loading_weak_factory_(this),
470 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55471 frame_tree_.SetFrameRemoveListener(
472 base::Bind(&WebContentsImpl::OnFrameRemoved,
473 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46474#if defined(OS_ANDROID)
475 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
476#else
qinmin58567c82015-01-07 21:00:20477 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46478#endif
brettw4b461082016-11-19 18:55:16479#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17480 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
481#endif
csharrisona2280cd2016-02-03 23:21:15482 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
blundelld46e8832016-10-07 10:34:27483 wake_lock_service_context_.reset(new device::WakeLockServiceContext(
blundellebd75172016-10-03 10:41:43484 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
485 base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this))));
scottmg276753cf2016-10-27 18:25:22486 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
[email protected]332af7732009-03-11 13:21:35487}
initial.commit09911bf2008-07-26 23:55:29488
[email protected]b172aee2012-04-10 17:05:26489WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32490 is_being_destroyed_ = true;
491
kenrb2a565f82015-09-02 20:24:59492 rwh_input_event_router_.reset();
493
rockotf62002a2016-09-15 00:08:59494 for (auto& entry : binding_sets_)
495 entry.second->CloseAllBindings();
496
avallee0206f782016-07-28 18:55:33497 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50498 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33499 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50500 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33501 }
502
dcheng72be33c2016-01-21 04:11:31503 for (FrameTreeNode* node : frame_tree_.Nodes()) {
504 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
505 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38506 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38507 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31508 }
carlosk35f35af2015-12-01 10:55:40509
dcheng57e39e22016-01-21 00:25:38510 for (RenderWidgetHostImpl* widget : created_widgets_)
511 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26512 created_widgets_.clear();
513
[email protected]3ab9cb82011-06-03 18:02:07514 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46515 if (dialog_manager_) {
516 // This object is being destructed, so make sure that no callbacks happen.
517 dialog_manager_->CancelDialogs(this,
518 true, // suppress_callbacks,
519 true); // reset_state
520 }
[email protected]3ab9cb82011-06-03 18:02:07521
[email protected]8ed16472014-04-11 19:02:48522 if (color_chooser_info_.get())
523 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20524
[email protected]420ae012009-04-24 05:16:32525 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32526
[email protected]ca13a442012-04-17 14:00:12527 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21528 NotificationService::current()->Notify(
529 NOTIFICATION_WEB_CONTENTS_DESTROYED,
530 Source<WebContents>(this),
531 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32532
[email protected]df0c843f2014-05-23 20:37:23533 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14534 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23535 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59536
clamy0e119882015-07-31 16:12:33537 // Manually call the observer methods for the root frame tree node. It is
538 // necessary to manually delete all objects tracking navigations
539 // (NavigationHandle, NavigationRequest) for observers to be properly
540 // notified of these navigations stopping before the WebContents is
541 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23542 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56543
clamy0e119882015-07-31 16:12:33544 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56545 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33546 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08547 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33548 }
naskob21fe4872015-02-24 14:15:56549 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33550 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08551 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33552
553 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35554 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41555 // Do not update state as the WebContents is being destroyed.
556 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33557 if (root->speculative_frame_host()) {
558 root->speculative_frame_host()->SetRenderFrameCreated(false);
559 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08560 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33561 }
562 }
[email protected]f273ee52013-10-18 16:05:27563
brettw4b461082016-11-19 18:55:16564#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17565 // Call this before WebContentsDestroyed() is broadcasted since
566 // AudioFocusManager will be destroyed after that.
567 pepper_playback_observer_.reset();
568#endif // defined(ENABLED_PLUGINS)
569
ericwilligersde386342016-10-19 02:35:09570 for (auto& observer : observers_)
571 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10572
[email protected]df0c843f2014-05-23 20:37:23573 if (root->pending_render_view_host()) {
ericwilligersde386342016-10-19 02:35:09574 for (auto& observer : observers_)
575 observer.RenderViewDeleted(root->pending_render_view_host());
[email protected]df0c843f2014-05-23 20:37:23576 }
[email protected]c06c58c2014-03-12 20:31:59577
ericwilligersde386342016-10-19 02:35:09578 for (auto& observer : observers_)
579 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27580
ericwilligersde386342016-10-19 02:35:09581 for (auto& observer : observers_)
582 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58583
ericwilligersde386342016-10-19 02:35:09584 for (auto& observer : observers_)
585 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08586
[email protected]6934a702011-12-20 00:04:51587 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42588}
589
[email protected]d1198fd2012-08-13 22:50:19590WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59591 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21592 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03593 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21594 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19595
alexmosaedfc6f2016-01-21 23:57:38596 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
597
alexmose201c7cd2015-06-10 17:14:21598 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38599 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21600 new_contents->created_with_opener_ = true;
601 }
602
alexmosaedfc6f2016-01-21 23:57:38603 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
604 // flags, and these flags take effect immediately. An exception is if the
605 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
606 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
607 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
608 if (opener) {
609 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
610 const blink::WebSandboxFlags inherit_flag =
611 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
612 if ((opener_flags & inherit_flag) == inherit_flag) {
613 new_root->SetPendingSandboxFlags(opener_flags);
614 new_root->CommitPendingSandboxFlags();
615 }
616 }
617
alexmose201c7cd2015-06-10 17:14:21618 // This may be true even when opener is null, such as when opening blocked
619 // popups.
alexmos090fae8e2015-05-28 17:09:28620 if (params.created_with_opener)
621 new_contents->created_with_opener_ = true;
622
[email protected]4858e432014-06-23 18:14:17623 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06624 // This makes |new_contents| act as a guest.
625 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16626 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06627 // We are instantiating a WebContents for browser plugin. Set its subframe
628 // bit to true.
629 new_contents->is_subframe_ = true;
630 }
[email protected]54944cde2012-12-09 09:24:59631 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19632 return new_contents;
633}
634
[email protected]95640212014-07-26 18:14:30635// static
636std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
637 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08638 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30639 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30640 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30641 RenderViewHost* rvh = RenderViewHost::From(rwh);
642 if (!rvh)
643 continue;
644 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
645 if (!web_contents)
646 continue;
avidf38c952015-10-27 13:45:13647 if (web_contents->GetRenderViewHost() != rvh)
648 continue;
649 // Because a WebContents can only have one current RVH at a time, there will
650 // be no duplicate WebContents here.
651 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30652 }
653 return result;
654}
655
clamya16aa8172015-05-26 13:07:25656// static
657WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
658 FrameTreeNode* frame_tree_node) {
659 return static_cast<WebContentsImpl*>(
660 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
661}
662
clamy0d32d6d2015-11-24 11:16:26663// static
664WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
665 int render_frame_host_id) {
666 DCHECK_CURRENTLY_ON(BrowserThread::UI);
667 RenderFrameHost* render_frame_host =
668 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
669 if (!render_frame_host)
670 return nullptr;
671
672 return WebContents::FromRenderFrameHost(render_frame_host);
673}
674
[email protected]b0936d22013-11-28 06:47:36675RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21676 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28677}
678
nicka0ac8382016-12-15 23:59:23679bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47680 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23681 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
682 if (main_frame) {
683 WebUIImpl* web_ui = static_cast<RenderFrameHostImpl*>(main_frame)->web_ui();
684 if (web_ui && web_ui->OnMessageReceived(message))
685 return true;
[email protected]d2353452012-01-19 19:53:56686 }
[email protected]f82d57b52011-04-27 19:13:17687
nicka0ac8382016-12-15 23:59:23688 for (auto& observer : observers_) {
689 // TODO(nick, creis): Replace all uses of this variant of OnMessageReceived
690 // with the version that takes a RenderFrameHost, and delete it.
691 if (observer.OnMessageReceived(message))
692 return true;
[email protected]64ffefa2014-05-10 12:06:33693 }
[email protected]403415a2011-01-10 18:57:53694
[email protected]724159a2010-12-30 01:11:18695 bool handled = true;
nicka0ac8382016-12-15 23:59:23696 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
697 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
698 OnFirstVisuallyNonEmptyPaint)
699 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
700 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
701 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
702 OnPageScaleFactorChanged)
703 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
704 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
705 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
706#if BUILDFLAG(ENABLE_PLUGINS)
707 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
708 OnRequestPpapiBrokerPermission)
709#endif
710 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
711 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
712 OnShowValidationMessage)
713 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
714 OnHideValidationMessage)
715 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
716 OnMoveValidationMessage)
717#if defined(OS_ANDROID)
718 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog)
719#endif
720 IPC_MESSAGE_UNHANDLED(handled = false)
721 IPC_END_MESSAGE_MAP()
722
723 return handled;
724}
725
726bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
727 const IPC::Message& message) {
728 for (auto& observer : observers_) {
729 if (observer.OnMessageReceived(message, render_frame_host))
730 return true;
731 }
732
733 bool handled = true;
734 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40735 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
736 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05737 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
738 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48739 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
740 OnDocumentLoadedInFrame)
741 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
742 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
743 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
744 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
745 OnSetSelectedColorInColorChooser)
avi7830c852015-08-31 23:46:25746 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18747 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54748 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18749 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54750 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18751 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41752 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
753 OnDidDisplayContentWithCertificateErrors)
754 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
755 OnDidRunContentWithCertificateErrors)
avia23e16b2015-07-09 14:18:48756 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
757 OnRegisterProtocolHandler)
758 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
759 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01760 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
761 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52762 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
brettw4b461082016-11-19 18:55:16763#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00764 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
765 OnPepperInstanceCreated)
766 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
767 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42768 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17769 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
770 OnPepperStartsPlayback)
771 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
772 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42773 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]c4538072013-03-18 02:17:55774 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40775 OnBrowserPluginMessage(render_frame_host,
776 message))
thestigc4cac8f2014-09-04 21:17:50777#endif
mfomitchev2b8b066a2016-01-28 19:23:15778#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52779 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48780 OnFindMatchRectsReply)
paulmeyerc8cb7cb2016-06-07 01:14:19781 IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply,
782 OnGetNearestFindResultReply)
[email protected]8ed16472014-04-11 19:02:48783#endif
[email protected]724159a2010-12-30 01:11:18784 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33785 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18786
[email protected]724159a2010-12-30 01:11:18787 return handled;
788}
789
[email protected]d1198fd2012-08-13 22:50:19790NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56791 return controller_;
792}
793
[email protected]d1198fd2012-08-13 22:50:19794const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56795 return controller_;
796}
797
[email protected]8ff00d72012-10-23 19:12:21798BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55799 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30800}
801
[email protected]b172aee2012-04-10 17:05:26802const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24803 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32804 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51805 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31806}
807
[email protected]a093ce02013-07-22 20:53:14808const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24809 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32810 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24811 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
812}
813
814const GURL& WebContentsImpl::GetLastCommittedURL() const {
815 // We may not have a navigation entry yet.
816 NavigationEntry* entry = controller_.GetLastCommittedEntry();
817 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
818}
819
[email protected]8ff00d72012-10-23 19:12:21820WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31821 return delegate_;
822}
823
[email protected]8ff00d72012-10-23 19:12:21824void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31825 // TODO(cbentzel): remove this debugging code?
826 if (delegate == delegate_)
827 return;
828 if (delegate_)
829 delegate_->Detach(this);
830 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08831 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31832 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08833 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00834 if (view_)
[email protected]e85165c642014-06-10 14:34:31835 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08836 }
[email protected]be1f56ab2011-12-22 06:55:31837}
838
[email protected]8ff00d72012-10-23 19:12:21839RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21840 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41841 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16842}
843
clamydf1975e2015-02-05 19:12:24844RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41845 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16846}
847
nick53d5cbf2015-04-23 22:50:14848RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
849 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
850 if (!focused_node)
851 return nullptr;
852 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07853}
854
rob3e2a0732016-01-06 21:22:09855RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
856 int frame_tree_node_id) {
857 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
858 return frame ? frame->current_frame_host() : nullptr;
859}
860
[email protected]a86c0e962013-12-17 17:10:39861void WebContentsImpl::ForEachFrame(
862 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38863 for (FrameTreeNode* node : frame_tree_.Nodes()) {
864 on_frame.Run(node->current_frame_host());
865 }
[email protected]a86c0e962013-12-17 17:10:39866}
867
dchengafb53e22016-02-04 08:11:08868std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
869 std::vector<RenderFrameHost*> frame_hosts;
870 for (FrameTreeNode* node : frame_tree_.Nodes())
871 frame_hosts.push_back(node->current_frame_host());
872 return frame_hosts;
873}
874
lukaszacbdf52e2016-01-15 21:19:51875int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
876 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08877 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25878 if (!rfh->IsRenderFrameLive())
879 continue;
880
dchengafb53e22016-02-04 08:11:08881 ++number_of_messages;
882 IPC::Message* message_copy = new IPC::Message(*message);
883 message_copy->set_routing_id(rfh->GetRoutingID());
884 rfh->Send(message_copy);
885 }
[email protected]a86c0e962013-12-17 17:10:39886 delete message;
lukaszacbdf52e2016-01-15 21:19:51887 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39888}
889
lfgdb5c4ed2016-03-04 23:09:07890void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:41891 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:07892}
893
creisc014b402015-04-23 16:41:45894RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21895 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31896}
897
creis89a0f782015-05-27 16:13:17898void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:46899 if (dialog_manager_) {
900 dialog_manager_->CancelDialogs(this,
901 false, // suppress_callbacks,
902 false); // reset_state
903 }
creis89a0f782015-05-27 16:13:17904 if (browser_plugin_embedder_)
905 browser_plugin_embedder_->CancelGuestDialogs();
906}
907
naskoc0fceff2015-04-30 15:53:52908void WebContentsImpl::ClosePage() {
909 GetRenderViewHost()->ClosePage();
910}
911
[email protected]b172aee2012-04-10 17:05:26912RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21913 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31914}
915
lfg265a2672016-04-23 03:11:02916RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
917 if (GetOuterWebContents())
918 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
919 return GetRenderManager()->GetRenderWidgetHostView();
920}
921
[email protected]4aebbca2013-09-17 22:26:49922RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
923 const {
ekaramadaeb3c5c2016-11-09 03:22:35924 if (auto widget_host = GetFullscreenRenderWidgetHost())
925 return widget_host->GetView();
926 return nullptr;
[email protected]4aebbca2013-09-17 22:26:49927}
928
[email protected]8ff00d72012-10-23 19:12:21929WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return view_.get();
931}
932
yusufod41c5f92015-03-06 00:14:28933SkColor WebContentsImpl::GetThemeColor() const {
934 return theme_color_;
935}
936
[email protected]95640212014-07-26 18:14:30937void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
938 if (mode == accessibility_mode_)
939 return;
940
dmazzonif8a31042016-12-03 00:52:13941 // Don't allow accessibility to be enabled for WebContents that are never
942 // visible, like background pages.
943 if (IsNeverVisible())
944 return;
945
[email protected]95640212014-07-26 18:14:30946 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38947
948 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:13949 UpdateAccessibilityModeOnFrame(node->current_frame_host());
dcheng57e39e22016-01-21 00:25:38950 RenderFrameHost* pending_frame_host =
951 node->render_manager()->pending_frame_host();
952 if (pending_frame_host)
dmazzonif8a31042016-12-03 00:52:13953 UpdateAccessibilityModeOnFrame(pending_frame_host);
dcheng57e39e22016-01-21 00:25:38954 }
[email protected]95640212014-07-26 18:14:30955}
956
957void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
dmazzonidd3d51a72016-12-14 18:41:01958 SetAccessibilityMode(accessibility_mode_ | mode);
[email protected]95640212014-07-26 18:14:30959}
960
dmazzoni83ba5c82015-04-14 07:11:51961void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39962 // Send a request to each of the frames in parallel. Each one will return
963 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
964 // them into a single tree and call |callback| with that result, then
965 // delete |combiner|.
966 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
967 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
968 bool is_root = frame_tree_node->parent() == nullptr;
969 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
970 combiner->AddFrame(is_root));
971 }
dmazzoni83ba5c82015-04-14 07:11:51972}
973
wjmaclean64951902016-04-29 20:59:12974void WebContentsImpl::SetTemporaryZoomLevel(double level,
975 bool temporary_zoom_enabled) {
976 SendPageMessage(new PageMsg_SetZoomLevel(
977 MSG_ROUTING_NONE,
978 temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY
979 : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY,
980 level));
981}
982
983void WebContentsImpl::UpdateZoom(double level) {
984 // Individual frames may still ignore the new zoom level if their RenderView
985 // contains a plugin document or if it uses a temporary zoom level.
986 SendPageMessage(new PageMsg_SetZoomLevel(
987 MSG_ROUTING_NONE,
988 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level));
989}
990
991void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
992 const std::string& host,
993 double level) {
994 NavigationEntry* entry = GetController().GetLastCommittedEntry();
995 if (!entry)
996 return;
997
998 GURL url = HostZoomMap::GetURLFromEntry(entry);
999 if (host != net::GetHostOrSpecFromURL(url) ||
1000 (!scheme.empty() && !url.SchemeIs(scheme))) {
1001 return;
1002 }
1003
1004 UpdateZoom(level);
1005}
1006
rockotf62002a2016-09-15 00:08:591007base::Closure WebContentsImpl::AddBindingSet(
1008 const std::string& interface_name,
1009 WebContentsBindingSet* binding_set) {
1010 auto result =
1011 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1012 DCHECK(result.second);
1013 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1014 weak_factory_.GetWeakPtr(), interface_name);
1015}
1016
wjmaclean8a795f32016-08-11 23:49:581017void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1018 SendPageMessage(
1019 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1020}
1021
ccameron2f451532016-09-07 21:49:271022void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
wjmaclean8a795f32016-08-11 23:49:581023 if (GetView())
ccameron2f451532016-09-07 21:49:271024 GetView()->GetScreenInfo(screen_info);
wjmaclean8a795f32016-08-11 23:49:581025}
1026
avie865b1d2016-10-24 19:42:591027std::unique_ptr<WebUI> WebContentsImpl::CreateSubframeWebUI(
1028 const GURL& url,
1029 const std::string& frame_name) {
dbeama1b926a2015-08-31 23:17:511030 DCHECK(!frame_name.empty());
1031 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:221032}
1033
[email protected]8ff00d72012-10-23 19:12:211034WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401035 WebUI* commited_web_ui = GetCommittedWebUI();
1036 return commited_web_ui ? commited_web_ui
1037 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311038}
1039
[email protected]8ff00d72012-10-23 19:12:211040WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401041 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341042}
1043
[email protected]86ef6a392012-05-11 22:03:111044void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:221045 if (GetUserAgentOverride() == override)
1046 return;
1047
1048 renderer_preferences_.user_agent_override = override;
1049
1050 // Send the new override string to the renderer.
1051 RenderViewHost* host = GetRenderViewHost();
1052 if (host)
1053 host->SyncRendererPrefs();
1054
1055 // Reload the page if a load is currently in progress to avoid having
1056 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271057 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:251058 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251059 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531060
ericwilligersde386342016-10-19 02:35:091061 for (auto& observer : observers_)
1062 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111063}
1064
1065const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221066 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111067}
1068
dmazzonidd3d51a72016-12-14 18:41:011069void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:081070 if (GetAccessibilityMode() != AccessibilityModeOff) {
1071 for (RenderFrameHost* rfh : GetAllFrames())
1072 ResetAccessibility(rfh);
1073 } else {
dmazzonidd3d51a72016-12-14 18:41:011074 AddAccessibilityMode(ACCESSIBILITY_MODE_WEB_CONTENTS_ONLY);
dchengafb53e22016-02-04 08:11:081075 }
[email protected]95640212014-07-26 18:14:301076}
1077
dmazzonidd3d51a72016-12-14 18:41:011078bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const {
1079 return accessibility_mode_ == ACCESSIBILITY_MODE_WEB_CONTENTS_ONLY;
[email protected]95640212014-07-26 18:14:301080}
1081
1082bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
dmazzonidd3d51a72016-12-14 18:41:011083 return accessibility_mode_ == ACCESSIBILITY_MODE_COMPLETE;
[email protected]95640212014-07-26 18:14:301084}
1085
kouhei40f03cb2015-09-24 07:47:011086const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1087 return page_importance_signals_;
1088}
1089
[email protected]fcf75d42013-12-03 20:11:261090const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551091 // Transient entries take precedence. They are used for interstitial pages
1092 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231093 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231094 if (entry) {
jshin1fb76462016-04-05 22:13:031095 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231096 }
carlosk35f35af2015-12-01 10:55:401097
1098 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1099 WebUI* our_web_ui = navigating_web_ui
1100 ? navigating_web_ui
1101 : GetRenderManager()->current_frame_host()->web_ui();
1102
[email protected]7ade2732011-02-10 00:13:581103 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541104 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321105 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541106 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351107 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261108 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541109 if (!title.empty())
1110 return title;
1111 }
1112 }
1113
1114 // We use the title for the last committed entry rather than a pending
1115 // navigation entry. For example, when the user types in a URL, we want to
1116 // keep the old page's title until the new load has committed and we get a new
1117 // title.
[email protected]96d185d2009-04-24 03:28:541118 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321119
creis072b61f2015-09-28 20:52:241120 // We make an exception for initial navigations. We only want to use the title
1121 // from the visible entry if:
1122 // 1. The pending entry has been explicitly assigned a title to display.
1123 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1124 // which case there is a pending entry index other than -1.
1125 //
1126 // Otherwise, we want to stick with the last committed entry's title during
1127 // new navigations, which have pending entries at index -1 with no title.
1128 if (controller_.IsInitialNavigation() &&
1129 ((controller_.GetVisibleEntry() &&
1130 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1131 controller_.GetPendingEntryIndex() != -1)) {
1132 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471133 }
[email protected]59167c22013-06-03 18:07:321134
[email protected]45d0ef7f2011-01-05 13:46:231135 if (entry) {
jshin1fb76462016-04-05 22:13:031136 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231137 }
[email protected]987fc3a2011-05-26 14:18:091138
1139 // |page_title_when_no_navigation_entry_| is finally used
1140 // if no title cannot be retrieved.
1141 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541142}
1143
creiscce56cd2014-09-29 22:45:221144SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211145 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541146}
1147
creiscce56cd2014-09-29 22:45:221148SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1149 RenderViewHostImpl* dest_rvh =
1150 GetRenderManager()->pending_render_view_host() ?
1151 GetRenderManager()->pending_render_view_host() :
1152 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581153 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381154}
1155
[email protected]b172aee2012-04-10 17:05:261156bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251157 return frame_tree_.IsLoading() &&
1158 !(ShowingInterstitialPage() &&
1159 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491160}
1161
[email protected]6dfed692014-05-22 04:18:031162bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251163 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031164}
1165
[email protected]b172aee2012-04-10 17:05:261166bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031167 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311168}
1169
[email protected]b172aee2012-04-10 17:05:261170const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311171 return load_state_;
1172}
1173
[email protected]fcf75d42013-12-03 20:11:261174const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311175 return load_state_host_;
1176}
1177
avib7348942015-12-25 20:57:101178uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311179 return upload_size_;
1180}
1181
avib7348942015-12-25 20:57:101182uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311183 return upload_position_;
1184}
1185
[email protected]b172aee2012-04-10 17:05:261186const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541187 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311188}
1189
[email protected]222f5822014-02-05 23:40:491190void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251191 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551192 ++capturer_count_;
1193 DVLOG(1) << "There are now " << capturer_count_
1194 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491195
1196 // Note: This provides a hint to upstream code to size the views optimally
1197 // for quality (e.g., to avoid scaling).
1198 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1199 preferred_size_for_capture_ = capture_size;
1200 OnPreferredSizeChanged(preferred_size_);
1201 }
ccameron8807c38f2015-01-17 00:29:191202
1203 // Ensure that all views are un-occluded before capture begins.
1204 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551205}
1206
1207void WebContentsImpl::DecrementCapturerCount() {
1208 --capturer_count_;
1209 DVLOG(1) << "There are now " << capturer_count_
1210 << " capturing(s) of WebContentsImpl@" << this;
1211 DCHECK_LE(0, capturer_count_);
1212
[email protected]5a652232013-02-12 06:15:251213 if (is_being_destroyed_)
1214 return;
1215
[email protected]222f5822014-02-05 23:40:491216 if (capturer_count_ == 0) {
1217 const gfx::Size old_size = preferred_size_for_capture_;
1218 preferred_size_for_capture_ = gfx::Size();
1219 OnPreferredSizeChanged(old_size);
1220 }
1221
[email protected]1ac10dca2013-08-20 20:47:041222 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551223 DVLOG(1) << "Executing delayed WasHidden().";
1224 WasHidden();
1225 }
[email protected]be1f56ab2011-12-22 06:55:311226}
1227
[email protected]f2bd40812013-07-20 04:30:441228int WebContentsImpl::GetCapturerCount() const {
1229 return capturer_count_;
1230}
1231
miu50f97892014-09-22 22:49:521232bool WebContentsImpl::IsAudioMuted() const {
1233 return audio_muter_.get() && audio_muter_->is_muting();
1234}
1235
1236void WebContentsImpl::SetAudioMuted(bool mute) {
1237 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1238 << " for WebContentsImpl@" << this;
1239
1240 if (mute == IsAudioMuted())
1241 return;
1242
1243 if (mute) {
1244 if (!audio_muter_)
1245 audio_muter_.reset(new WebContentsAudioMuter(this));
1246 audio_muter_->StartMuting();
1247 } else {
1248 DCHECK(audio_muter_);
1249 audio_muter_->StopMuting();
1250 }
1251
ericwilligersde386342016-10-19 02:35:091252 for (auto& observer : observers_)
1253 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031254
altimind8bd26c2016-11-04 11:44:541255 OnAudioStateChanged(!mute && audio_stream_monitor_.IsCurrentlyAudible());
miu50f97892014-09-22 22:49:521256}
1257
ortunodf4d7982016-04-08 02:33:351258bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1259 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201260}
1261
[email protected]b172aee2012-04-10 17:05:261262bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311263 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1264 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581265 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271266#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581267 crashed_status_ ==
1268 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271269#endif
wfh0d9532a2015-09-02 23:18:581270 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271271 );
[email protected]3c9e1872010-11-18 16:17:491272}
1273
[email protected]b172aee2012-04-10 17:05:261274void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1275 int error_code) {
[email protected]443b80e2010-12-14 00:42:231276 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341277 return;
1278
[email protected]443b80e2010-12-14 00:42:231279 crashed_status_ = status;
1280 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211281 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341282}
1283
[email protected]b172aee2012-04-10 17:05:261284base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311285 return crashed_status_;
1286}
1287
afakhry98241832016-03-11 19:27:471288int WebContentsImpl::GetCrashedErrorCode() const {
1289 return crashed_error_code_;
1290}
1291
[email protected]b172aee2012-04-10 17:05:261292bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311293 return is_being_destroyed_;
1294}
1295
[email protected]7f924832014-08-09 05:57:221296void WebContentsImpl::NotifyNavigationStateChanged(
1297 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541298 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1299 // is fixed.
1300 tracked_objects::ScopedTracker tracking_profile(
1301 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1302 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181303 // Notify the media observer of potential audibility changes.
1304 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271305 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301306 }
1307
[email protected]d5f942ba2008-09-26 19:30:341308 if (delegate_)
1309 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441310
1311 if (GetOuterWebContents())
1312 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341313}
1314
altiminec87fd1f2016-11-17 20:22:491315void WebContentsImpl::OnAudioStateChanged(bool is_audible) {
1316 SendPageMessage(new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_audible));
altimind8bd26c2016-11-04 11:44:541317
altiminec87fd1f2016-11-17 20:22:491318 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541319 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1320}
1321
gab0dccfef2015-05-20 18:43:391322base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021323 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331324}
1325
georgesak5582cbe2015-05-22 22:08:071326void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1327 last_active_time_ = last_active_time;
1328}
1329
hajimehoshic4f226a2016-10-21 09:01:571330base::TimeTicks WebContentsImpl::GetLastHiddenTime() const {
1331 return last_hidden_time_;
1332}
1333
[email protected]9e2e4632012-07-27 16:38:411334void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541335 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591336
ccameron8807c38f2015-01-17 00:29:191337 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1338 if (view) {
1339 view->Show();
[email protected]789e9152009-08-04 21:59:431340#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191341 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431342#endif
[email protected]de3c5d82014-05-28 22:12:591343 }
[email protected]789e9152009-08-04 21:59:431344 }
[email protected]96d185d2009-04-24 03:28:541345
lfg717154072016-06-30 15:04:161346 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1347
gab0dccfef2015-05-20 18:43:391348 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381349
ericwilligersde386342016-10-19 02:35:091350 for (auto& observer : observers_)
1351 observer.WasShown();
[email protected]c0d9d5672013-10-09 07:38:031352
[email protected]54597982013-02-06 01:59:551353 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311354}
1355
[email protected]b172aee2012-04-10 17:05:261356void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551357 // If there are entities capturing screenshots or video (e.g., mirroring),
1358 // don't activate the "disable rendering" optimization.
1359 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521360 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551361 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261362 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521363 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331364 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521365 // calls us).
ccameron8807c38f2015-01-17 00:29:191366 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1367 if (view)
1368 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591369 }
lfg717154072016-06-30 15:04:161370
1371 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541372 }
1373
hajimehoshic4f226a2016-10-21 09:01:571374 last_hidden_time_ = base::TimeTicks::Now();
1375
ericwilligersde386342016-10-19 02:35:091376 for (auto& observer : observers_)
1377 observer.WasHidden();
[email protected]c0d9d5672013-10-09 07:38:031378
[email protected]54597982013-02-06 01:59:551379 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371380}
1381
ccameron8807c38f2015-01-17 00:29:191382void WebContentsImpl::WasOccluded() {
1383 if (capturer_count_ > 0)
1384 return;
1385
1386 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1387 if (view)
1388 view->WasOccluded();
1389 }
1390}
1391
1392void WebContentsImpl::WasUnOccluded() {
1393 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1394 if (view)
1395 view->WasUnOccluded();
1396 }
1397}
1398
[email protected]b172aee2012-04-10 17:05:261399bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311400 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451401 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1402 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311403}
1404
nasko148bb0b92016-05-10 21:03:191405void WebContentsImpl::DispatchBeforeUnload() {
1406 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171407 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061408}
1409
lazyboy6ec48b2a2015-06-29 15:18:141410void WebContentsImpl::AttachToOuterWebContentsFrame(
1411 WebContents* outer_web_contents,
1412 RenderFrameHost* outer_contents_frame) {
ekaramad1beabecc2016-09-23 20:18:171413 CHECK(GuestMode::IsCrossProcessFrameGuest(this));
lfg91a79e12016-04-01 23:52:191414 RenderFrameHostManager* render_manager = GetRenderManager();
1415
1416 // When the WebContents being initialized has an opener, the browser side
1417 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1418 // created. This is needed because the usual initialization happens during
1419 // the first navigation, but when attaching a new window we don't navigate
1420 // before attaching. If the browser side is already initialized, the calls
1421 // below will just early return.
1422 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1423 GetMainFrame()->Init();
1424 if (!render_manager->GetRenderWidgetHostView())
1425 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1426
lazyboy6ec48b2a2015-06-29 15:18:141427 // Create a link to our outer WebContents.
1428 node_.reset(new WebContentsTreeNode());
1429 node_->ConnectToOuterWebContents(
1430 static_cast<WebContentsImpl*>(outer_web_contents),
1431 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1432
1433 DCHECK(outer_contents_frame);
1434
1435 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1436 // SiteInstance of the outer WebContents. The proxy will be used to send
1437 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191438 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141439 outer_contents_frame->GetSiteInstance(),
1440 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1441
lfg91a79e12016-04-01 23:52:191442 render_manager->SetRWHViewForInnerContents(
1443 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391444
1445 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191446 render_manager->GetRenderWidgetHostView())
fsamuelb6acafa2016-10-04 03:21:521447 ->RegisterFrameSinkId();
ekaramadadd882292016-06-08 15:22:561448
1449 // At this point, we should destroy the TextInputManager which will notify all
1450 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1451 // TextInputManager owned by the outer WebContents.
1452 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1453 // outer WebContents? In such a case, is this still the right way to hand off
1454 // state tracking from inner WebContents's TextInputManager to that of the
1455 // outer WebContent (crbug.com/609846)?
1456 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141457}
1458
dalecurtis6c58ed02016-10-28 23:02:371459void WebContentsImpl::DidChangeVisibleSecurityState() {
1460 if (delegate_) {
1461 delegate_->VisibleSecurityStateChanged(this);
cjgrant6d1d727a2016-12-09 21:16:571462 for (auto& observer : observers_)
1463 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371464 }
1465}
1466
[email protected]b172aee2012-04-10 17:05:261467void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381468 for (FrameTreeNode* node : frame_tree_.Nodes())
1469 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091470 for (auto& observer : observers_)
1471 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271472}
1473
[email protected]b172aee2012-04-10 17:05:261474WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441475 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211476 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451477 // before.
[email protected]54944cde2012-12-09 09:24:591478 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451479 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211480 WebContentsImpl* tc =
1481 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191482 tc->GetController().CopyStateFrom(controller_);
ericwilligersde386342016-10-19 02:35:091483 for (auto& observer : observers_)
1484 observer.DidCloneToNewWebContents(this, tc);
[email protected]0bfbf882011-12-22 18:19:271485 return tc;
1486}
1487
[email protected]14392a52012-05-02 20:28:441488void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211489 const NotificationSource& source,
1490 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441491 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211492 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1493 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031494 RenderWidgetHostView* view = host->GetView();
1495 if (view == GetFullscreenRenderWidgetHostView()) {
1496 // We cannot just call view_->RestoreFocus() here. On some platforms,
1497 // attempting to focus the currently-invisible WebContentsView will be
1498 // flat-out ignored. Therefore, this boolean is used to track whether
1499 // we will request focus after the fullscreen widget has been
1500 // destroyed.
1501 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1502 } else {
alexmosc2a8cec2016-05-23 22:19:531503 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031504 i != pending_widget_views_.end(); ++i) {
1505 if (host->GetView() == i->second) {
1506 pending_widget_views_.erase(i);
1507 break;
1508 }
[email protected]bafe6cd2012-05-23 23:09:501509 }
1510 }
1511 break;
1512 }
[email protected]14392a52012-05-02 20:28:441513 default:
1514 NOTREACHED();
1515 }
1516}
1517
[email protected]ec6c05f2013-10-23 18:41:571518WebContents* WebContentsImpl::GetWebContents() {
1519 return this;
1520}
1521
[email protected]54944cde2012-12-09 09:24:591522void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211523 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361524 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211525 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431526 should_normally_be_visible_ = !params.initially_hidden;
1527
dcheng3ce04b62015-10-26 23:30:551528 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541529 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551530 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1531 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541532 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551533 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1534 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1535
1536 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1537 if (!site_instance)
1538 site_instance = SiteInstance::Create(params.browser_context);
1539
1540 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1541 // local root by definition.
1542 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1543 // longer be necessary to eagerly grab a routing ID for the view.
1544 // https://crbug.com/545684
1545 int32_t view_routing_id = params.routing_id;
1546 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1547 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1548 view_routing_id = main_frame_widget_routing_id =
1549 site_instance->GetProcess()->GetNextRoutingID();
1550 }
1551
1552 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1553 params.main_frame_routing_id,
jambaaab3a2016-11-05 00:46:181554 main_frame_widget_routing_id,
1555 params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:321556
lukasza5140a412016-09-15 21:12:301557 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1558 // main frame - let's do the same thing here.
1559 std::string unique_name;
lukasza464d8692016-02-22 19:26:321560 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191561
[email protected]fc2b46b2014-05-03 16:33:451562 WebContentsViewDelegate* delegate =
1563 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1564
sky52a39e342016-12-17 17:23:221565 if (GuestMode::IsCrossProcessFrameGuest(this)) {
1566 view_.reset(new WebContentsViewChildFrame(
1567 this, delegate, &render_view_host_delegate_view_));
1568 } else {
1569 view_.reset(CreateWebContentsView(this, delegate,
1570 &render_view_host_delegate_view_));
fsamueladb0033602015-12-09 19:20:411571 }
fsamuel9cf7bdf2015-11-20 02:19:321572
ekaramad1beabecc2016-09-23 20:18:171573 if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) {
fsamuel9cf7bdf2015-11-20 02:19:321574 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361575 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321576 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191577 }
[email protected]fc2b46b2014-05-03 16:33:451578 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191579 CHECK(view_.get());
1580
[email protected]ed245db2012-12-18 08:00:451581 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591582 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191583
brettw4b461082016-11-19 18:55:161584#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:091585 plugin_content_origin_whitelist_.reset(
1586 new PluginContentOriginWhitelist(this));
1587#endif
1588
[email protected]d1198fd2012-08-13 22:50:191589 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211590 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1591 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101592
lunalud4a2cc82016-11-22 00:27:231593 screen_orientation_.reset(new ScreenOrientation(this));
[email protected]01f83f92014-06-17 14:41:541594
mlamouriefdca9d2014-09-16 16:55:401595 manifest_manager_host_.reset(new ManifestManagerHost(this));
1596
mfomitchev2b8b066a2016-01-28 19:23:151597#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101598 date_time_chooser_.reset(new DateTimeChooserAndroid());
1599#endif
fsamuel7310a4262014-12-05 05:06:441600
1601 // BrowserPluginGuest::Init needs to be called after this WebContents has
1602 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1603 if (browser_plugin_guest_)
1604 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371605
1606 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1607 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561608
1609 // If the WebContents creation was renderer-initiated, it means that the
1610 // corresponding RenderView and main RenderFrame have already been created.
1611 // Ensure observers are notified about this.
1612 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431613 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561614 RenderViewCreated(GetRenderViewHost());
1615 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1616 }
naskof5940b9f2015-03-02 23:04:051617
lof84501da082016-05-23 21:22:541618 // Create the renderer process in advance if requested.
1619 if (params.initialize_renderer) {
1620 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
1621 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
1622 }
1623 }
1624
naskof5940b9f2015-03-02 23:04:051625 // Ensure that observers are notified of the creation of this WebContents's
1626 // main RenderFrameHost. It must be done here for main frames, since the
1627 // NotifySwappedFromRenderManager expects view_ to already be created and that
1628 // happens after RenderFrameHostManager::Init.
1629 NotifySwappedFromRenderManager(
1630 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191631}
1632
[email protected]7fff43e2013-05-21 20:21:101633void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1634 RemoveDestructionObserver(web_contents);
1635
[email protected]ceee8cd2013-03-08 04:59:511636 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:531637 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:511638 ++iter) {
1639 if (iter->second != web_contents)
1640 continue;
1641 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511642 return;
1643 }
1644 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441645}
1646
[email protected]7fff43e2013-05-21 20:21:101647void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1648 if (!ContainsKey(destruction_observers_, web_contents)) {
1649 destruction_observers_[web_contents] =
avia8cf81982016-08-12 20:28:461650 base::MakeUnique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:101651 }
1652}
1653
1654void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:461655 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:101656}
1657
[email protected]b172aee2012-04-10 17:05:261658void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311659 observers_.AddObserver(observer);
1660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311663 observers_.RemoveObserver(observer);
1664}
1665
[email protected]948481d2014-06-11 18:32:221666std::set<RenderWidgetHostView*>
1667WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1668 std::set<RenderWidgetHostView*> set;
1669 if (ShowingInterstitialPage()) {
1670 set.insert(GetRenderWidgetHostView());
1671 } else {
dchengafb53e22016-02-04 08:11:081672 for (RenderFrameHost* rfh : GetAllFrames()) {
1673 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1674 ->frame_tree_node()
1675 ->render_manager()
1676 ->GetRenderWidgetHostView();
1677 set.insert(rwhv);
1678 }
[email protected]948481d2014-06-11 18:32:221679 }
[email protected]de3c5d82014-05-28 22:12:591680 return set;
1681}
1682
[email protected]b172aee2012-04-10 17:05:261683void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341684 if (delegate_)
1685 delegate_->ActivateContents(this);
1686}
1687
avi3e4b8512015-11-11 01:55:491688void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1689 if (!RenderViewHostImpl::From(render_widget_host))
1690 return;
1691
[email protected]63954792011-07-11 04:17:481692 if (delegate_)
1693 delegate_->LostCapture();
1694}
1695
lazyboy63f5b312015-11-23 20:19:521696void WebContentsImpl::RenderWidgetCreated(
1697 RenderWidgetHostImpl* render_widget_host) {
1698 created_widgets_.insert(render_widget_host);
1699}
1700
[email protected]b24b68a2012-09-24 21:57:261701void WebContentsImpl::RenderWidgetDeleted(
1702 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521703 // Note that |is_being_destroyed_| can be true at this point as
1704 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1705 // us here.
1706 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261707
lazyboy63f5b312015-11-23 20:19:521708 if (is_being_destroyed_)
1709 return;
[email protected]44470a22013-01-24 01:21:541710
1711 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:371712 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
1713 render_widget_host->GetProcess()->GetID() ==
1714 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:491715 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531716 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:091717 for (auto& observer : observers_)
1718 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:371719 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:541720 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031721 if (fullscreen_widget_had_focus_at_shutdown_)
1722 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541723 }
lfgbee1e0a2016-06-08 21:24:211724
lfgff8dfc8d2016-10-21 17:42:321725 if (mouse_lock_widget_)
1726 LostMouseLock(mouse_lock_widget_);
[email protected]b24b68a2012-09-24 21:57:261727}
1728
miu9e14e492014-10-25 02:39:041729void WebContentsImpl::RenderWidgetGotFocus(
1730 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371731 // Notify the observers if an embedded fullscreen widget was focused.
1732 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1733 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1734 NotifyWebContentsFocused();
1735 }
miu9e14e492014-10-25 02:39:041736}
1737
estaded0a0c992015-01-21 14:12:061738void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311739 RenderWidgetHostImpl* render_widget_host,
1740 bool width_changed) {
creisc014b402015-04-23 16:41:451741 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291742 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061743 return;
estaded0a0c992015-01-21 14:12:061744
ericwilligersde386342016-10-19 02:35:091745 for (auto& observer : observers_)
1746 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:061747}
1748
paulmeyer9ef6e4462015-02-24 19:15:101749void WebContentsImpl::ScreenInfoChanged() {
1750 if (browser_plugin_embedder_)
1751 browser_plugin_embedder_->ScreenInfoChanged();
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754bool WebContentsImpl::PreHandleKeyboardEvent(
1755 const NativeWebKeyboardEvent& event,
1756 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481757 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131758 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481759}
1760
[email protected]b172aee2012-04-10 17:05:261761void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101762 if (browser_plugin_embedder_ &&
1763 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1764 return;
1765 }
[email protected]63954792011-07-11 04:17:481766 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131767 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481768}
1769
[email protected]d92026ef2014-03-03 21:04:131770bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461771 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191772#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331773 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1774 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191775 // -the OS already has a gesture to do this through pinch-zoom
1776 // -if a user starts an inertial scroll, let's go, and presses control
1777 // (i.e. control+tab) then the OS's buffered scroll events will come in
1778 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331779 if (delegate_ && event.wheelTicksY &&
chongz4a9751942016-08-17 17:49:391780 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:221781 // Count only integer cumulative scrolls as zoom events; this handles
1782 // smooth scroll and regular scroll device behavior.
1783 zoom_scroll_remainder_ += event.wheelTicksY;
1784 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1785 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1786 if (whole_zoom_scroll_remainder_ != 0) {
1787 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1788 }
[email protected]fb3f066e2013-02-12 19:12:521789 return true;
1790 }
[email protected]bccc4472013-04-18 16:37:191791#endif
[email protected]fb3f066e2013-02-12 19:12:521792 return false;
1793}
1794
[email protected]04bce562014-01-30 05:34:541795bool WebContentsImpl::PreHandleGestureEvent(
1796 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031797 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541798}
1799
kenrb2a565f82015-09-02 20:24:591800RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451801 if (!is_being_destroyed_ && GetOuterWebContents())
1802 return GetOuterWebContents()->GetInputEventRouter();
1803
1804 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591805 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1806 return rwh_input_event_router_.get();
1807}
1808
alexmos3fcd0ca2015-10-23 18:18:331809void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1810 // Focus loss may occur while this WebContents is being destroyed. Don't
1811 // send the message in this case, as the main frame's RenderFrameHost and
1812 // other state has already been cleared.
1813 if (is_being_destroyed_)
1814 return;
1815
1816 frame_tree_.ReplicatePageFocus(is_focused);
1817}
1818
alexmosc4cbacb2015-11-21 01:29:221819RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1820 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521821 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221822 return receiving_widget;
1823
1824 // Events for widgets other than the main frame (e.g., popup menus) should be
1825 // forwarded directly to the widget they arrived on.
1826 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1827 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521828
avallee0206f782016-07-28 18:55:331829 FrameTreeNode* focused_frame =
1830 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
alexmosc4d183e2015-11-06 00:46:521831 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221832 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521833
alexmos732ca3a2015-12-08 02:01:021834 // The view may be null if a subframe's renderer process has crashed while
1835 // the subframe has focus. Drop the event in that case. Do not give
1836 // it to the main frame, so that the user doesn't unexpectedly type into the
1837 // wrong frame if a focused subframe renderer crashes while they type.
1838 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1839 if (!view)
1840 return nullptr;
1841
1842 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521843}
1844
avallee9993fca2016-11-17 06:16:501845RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
1846 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost();
1847}
1848
mlamouri7a78d6fd2015-01-17 13:23:531849void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1850 // This method is being called to enter renderer-initiated fullscreen mode.
1851 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491852 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371853 if (widget_view) {
1854 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1855 ->ShutdownAndDestroyWidget(true);
1856 }
[email protected]4aebbca2013-09-17 22:26:491857
[email protected]8a5e0ca2011-08-25 06:30:471858 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531859 delegate_->EnterFullscreenModeForTab(this, origin);
1860
ericwilligersde386342016-10-19 02:35:091861 for (auto& observer : observers_)
1862 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:531863}
1864
bokanece34a82016-01-28 19:49:461865void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531866 // This method is being called to leave renderer-initiated fullscreen mode.
1867 // Make sure any existing fullscreen widget is shut down first.
1868 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371869 if (widget_view) {
1870 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1871 ->ShutdownAndDestroyWidget(true);
1872 }
mlamouri7a78d6fd2015-01-17 13:23:531873
hugo.holgersson61288e6c2015-01-28 17:04:401874#if defined(OS_ANDROID)
1875 ContentVideoView* video_view = ContentVideoView::GetInstance();
1876 if (video_view != NULL)
watk98292292016-01-19 22:24:081877 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401878#endif
1879
mlamouri7a78d6fd2015-01-17 13:23:531880 if (delegate_)
1881 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371882
bokanece34a82016-01-28 19:49:461883 // The fullscreen state is communicated to the renderer through a resize
1884 // message. If the change in fullscreen state doesn't cause a view resize
1885 // then we must ensure web contents exit the fullscreen state by explicitly
1886 // sending a resize message. This is required for the situation of the browser
1887 // moving the view into a "browser fullscreen" state and then the contents
1888 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1889 // have the side effect of the view resizing, hence the explicit call here is
1890 // required.
1891 if (!will_cause_resize) {
1892 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1893 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1894 render_widget_host->WasResized();
1895 }
scheib3dcb6c932015-02-23 10:55:581896 }
1897
ericwilligersde386342016-10-19 02:35:091898 for (auto& observer : observers_) {
1899 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
1900 will_cause_resize);
1901 }
[email protected]8a5e0ca2011-08-25 06:30:471902}
1903
alexmos5dd617d2016-06-07 04:21:151904bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381905 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121906}
1907
billorr21c005d2016-11-17 03:57:041908bool WebContentsImpl::IsFullscreen() {
1909 return IsFullscreenForCurrentTab();
1910}
1911
avibf58fa0c2015-11-11 01:45:521912blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1913 RenderWidgetHostImpl* render_widget_host) const {
1914 if (!RenderViewHostImpl::From(render_widget_host))
1915 return blink::WebDisplayModeBrowser;
1916
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121917 return delegate_ ? delegate_->GetDisplayMode(this)
1918 : blink::WebDisplayModeBrowser;
1919}
1920
avic3aa8422015-11-09 20:57:221921void WebContentsImpl::RequestToLockMouse(
1922 RenderWidgetHostImpl* render_widget_host,
1923 bool user_gesture,
lfgad8244352016-07-13 16:55:511924 bool last_unlocked_by_target,
1925 bool privileged) {
lfgbee1e0a2016-06-08 21:24:211926 if (mouse_lock_widget_) {
avic3aa8422015-11-09 20:57:221927 render_widget_host->GotResponseToLockMouseRequest(false);
1928 return;
[email protected]e9621112011-10-17 05:38:371929 }
avic3aa8422015-11-09 20:57:221930
lfgad8244352016-07-13 16:55:511931 if (privileged) {
1932 mouse_lock_widget_ = render_widget_host;
1933 render_widget_host->GotResponseToLockMouseRequest(true);
1934 return;
1935 }
1936
lfgbee1e0a2016-06-08 21:24:211937 bool widget_in_frame_tree = false;
1938 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1939 if (node->current_frame_host()->GetRenderWidgetHost() ==
1940 render_widget_host) {
1941 widget_in_frame_tree = true;
1942 break;
1943 }
1944 }
1945
1946 if (widget_in_frame_tree && delegate_) {
1947 mouse_lock_widget_ = render_widget_host;
avic3aa8422015-11-09 20:57:221948 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:211949 } else {
1950 render_widget_host->GotResponseToLockMouseRequest(false);
1951 }
[email protected]e9621112011-10-17 05:38:371952}
1953
avi3e4b8512015-11-11 01:55:491954void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:211955 CHECK(mouse_lock_widget_);
1956 mouse_lock_widget_->SendMouseLockLost();
1957 mouse_lock_widget_ = nullptr;
avi3e4b8512015-11-11 01:55:491958
[email protected]e9621112011-10-17 05:38:371959 if (delegate_)
1960 delegate_->LostMouseLock();
1961}
1962
lfgad8244352016-07-13 16:55:511963bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1964 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1965 // assigned to the widget that requested the mouse lock, and the top-level
1966 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1967 return mouse_lock_widget_ == render_widget_host &&
1968 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
1969}
1970
dtrainor5ef644e2015-11-19 00:12:471971void WebContentsImpl::ForwardCompositorProto(
1972 RenderWidgetHostImpl* render_widget_host,
1973 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471974 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291975 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471976}
1977
ekaramada4f42692016-02-11 19:48:371978void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:061979 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:371980 WasShown();
lfg9462cef2016-07-18 23:51:061981 else if (!visible)
ekaramada4f42692016-02-11 19:48:371982 WasHidden();
1983}
1984
[email protected]bafe6cd2012-05-23 23:09:501985void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431986 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551987 int32_t route_id,
1988 int32_t main_frame_route_id,
1989 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:181990 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:131991 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501992 // We usually create the new window in the same BrowsingInstance (group of
1993 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551994 // if the opener is being suppressed (in a non-guest), we create a new
1995 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251996 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551997
[email protected]04cbd3d2013-12-04 04:58:201998 // If the opener is to be suppressed, the new window can be in any process.
1999 // Since routing ids are process specific, we must not have one passed in
2000 // as argument here.
2001 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
2002
[email protected]bafe6cd2012-05-23 23:09:502003 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432004 params.opener_suppressed && !is_guest
2005 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2006 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502007
alexmos4cf2aa32015-07-15 23:40:432008 // A message to create a new window can only come from a process for a frame
2009 // in this WebContents' FrameTree. If any other process sends the request, it
2010 // is invalid and the process must be terminated.
2011 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:382012 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:432013 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:352014 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:202015 if (process_handle != base::kNullProcessHandle) {
2016 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392017 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:352018 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:202019 }
2020 return;
2021 }
2022
[email protected]d1198fd2012-08-13 22:50:192023 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342024 //
2025 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302026 const std::string& partition_id =
2027 GetContentClient()->browser()->
2028 GetStoragePartitionIdForSite(GetBrowserContext(),
2029 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462030 StoragePartition* partition = BrowserContext::GetStoragePartition(
2031 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412032 DOMStorageContextWrapper* dom_storage_context =
2033 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192034 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2035 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2036 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372037
2038 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552039 !delegate_->ShouldCreateWebContents(
nickf5e618c2016-11-28 22:38:372040 this, source_site_instance, route_id, main_frame_route_id,
2041 main_frame_widget_route_id, params.window_container_type,
2042 params.opener_url, params.frame_name, params.target_url, partition_id,
2043 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:012044 if (route_id != MSG_ROUTING_NONE &&
2045 !RenderViewHost::FromID(render_process_id, route_id)) {
2046 // If the embedder didn't create a WebContents for this route, we need to
2047 // delete the RenderView that had already been created.
2048 Send(new ViewMsg_Close(route_id));
2049 }
jambaaab3a2016-11-05 00:46:182050 // Note: even though we're not creating a WebContents here, it could have
2051 // been created by the embedder so ensure that the RenderFrameHost is
2052 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152053 // It's safe to only target the frame because the render process will not
2054 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182055 RenderFrameHostImpl* rfh =
2056 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
2057 if (rfh)
2058 rfh->Init();
[email protected]dd6730412013-08-14 15:03:372059 return;
2060 }
2061
2062 // Create the new web contents. This will automatically create the new
2063 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462064 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:592065 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:042066 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552067 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122068 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432069 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:212070 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:062071 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192072 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062073 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192074 create_params.renderer_initiated_creation =
2075 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062076
[email protected]4858e432014-06-23 18:14:172077 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:552078 if (!is_guest) {
2079 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452080 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:172081 new_contents = static_cast<WebContentsImpl*>(
2082 WebContents::Create(create_params));
2083 } else {
2084 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:552085 }
[email protected]50d326e2014-05-20 17:59:062086 new_contents->GetController().SetSessionStorageNamespace(
2087 partition_id,
2088 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192089
alexmos646fec02015-07-25 00:11:492090 // If the new frame has a name, make sure any SiteInstances that can find
2091 // this named frame have proxies for it. Must be called after
2092 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2093 // GetSessionStorageNamespace.
2094 if (!params.frame_name.empty())
2095 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
2096
[email protected]c4538072013-03-18 02:17:552097 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342098 // will be shown immediately).
2099 if (!params.opener_suppressed) {
2100 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:452101 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502102
[email protected]d70bea92013-04-05 04:23:342103 // TODO(brettw): It seems bogus that we have to call this function on the
2104 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432105 new_view->CreateViewForWidget(
2106 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342107 }
[email protected]bafe6cd2012-05-23 23:09:502108 // Save the created window associated with the route so we can show it
2109 // later.
2110 DCHECK_NE(MSG_ROUTING_NONE, route_id);
alexmosc2a8cec2016-05-23 22:19:532111 pending_contents_[std::make_pair(render_process_id, route_id)] =
2112 new_contents;
[email protected]7fff43e2013-05-21 20:21:102113 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502114 }
2115
2116 if (delegate_) {
2117 delegate_->WebContentsCreated(
naskoe2df1d72016-10-04 00:20:172118 this, render_process_id, params.opener_render_frame_id,
2119 params.frame_name, params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:502120 }
2121
2122 if (params.opener_suppressed) {
2123 // When the opener is suppressed, the original renderer cannot access the
2124 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002125 bool was_blocked = false;
2126 if (delegate_) {
bokan107a47f2015-02-03 23:23:392127 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002128 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392129 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002130 params.user_gesture, &was_blocked);
2131 }
2132 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192133 OpenURLParams open_params(params.target_url, params.referrer,
2134 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352135 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212136 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302137 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372138
2139 if (delegate_ && !is_guest &&
2140 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2141 // We are in asynchronous add new contents path, delay opening url
2142 new_contents->delayed_open_url_params_.reset(
2143 new OpenURLParams(open_params));
2144 } else {
2145 new_contents->OpenURL(open_params);
2146 }
[email protected]eda238a12012-09-07 23:44:002147 }
[email protected]bafe6cd2012-05-23 23:09:502148 }
2149}
2150
avib7348942015-12-25 20:57:102151void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2152 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462153 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052154 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502155}
2156
avib7348942015-12-25 20:57:102157void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2158 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052159 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502160}
2161
avib7348942015-12-25 20:57:102162void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2163 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502164 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462165 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252166 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232167 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512168 // this WebContentsImpl instance. If any other process sends the request,
2169 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382170 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252171 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512172 if (process_handle != base::kNullProcessHandle) {
2173 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392174 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252175 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512176 }
2177 return;
2178 }
2179
[email protected]bafe6cd2012-05-23 23:09:502180 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052181 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262182
[email protected]cfd80b02014-05-01 17:46:482183 RenderWidgetHostViewBase* widget_view =
2184 static_cast<RenderWidgetHostViewBase*>(
2185 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192186 if (!widget_view)
2187 return;
[email protected]bafe6cd2012-05-23 23:09:502188 if (!is_fullscreen) {
2189 // Popups should not get activated.
2190 widget_view->SetPopupType(popup_type);
2191 }
2192 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532193 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2194 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502195
2196#if defined(OS_MACOSX)
2197 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2198 // to allow it to survive the trip without being hosted.
2199 base::mac::NSObjectRetain(widget_view->GetNativeView());
2200#endif
2201}
2202
alexmosc2a8cec2016-05-23 22:19:532203void WebContentsImpl::ShowCreatedWindow(int process_id,
2204 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502205 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392206 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502207 bool user_gesture) {
alexmosc2a8cec2016-05-23 22:19:532208 WebContentsImpl* contents = GetCreatedWindow(process_id, route_id);
[email protected]eda238a12012-09-07 23:44:002209 if (contents) {
2210 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162211 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382212 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2213 contents->ResumeLoadingCreatedWebContents();
2214
[email protected]eda238a12012-09-07 23:44:002215 if (delegate) {
2216 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392217 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002218 }
2219 }
[email protected]bafe6cd2012-05-23 23:09:502220}
2221
alexmosc2a8cec2016-05-23 22:19:532222void WebContentsImpl::ShowCreatedWidget(int process_id,
2223 int route_id,
bokan107a47f2015-02-03 23:23:392224 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532225 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502226}
2227
alexmosc2a8cec2016-05-23 22:19:532228void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2229 int route_id) {
2230 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502231}
2232
alexmosc2a8cec2016-05-23 22:19:532233void WebContentsImpl::ShowCreatedWidget(int process_id,
2234 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502235 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392236 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482237 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532238 static_cast<RenderWidgetHostViewBase*>(
2239 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502240 if (!widget_host_view)
2241 return;
[email protected]cfd80b02014-05-01 17:46:482242
2243 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332244 if (GetOuterWebContents()) {
2245 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482246 } else {
2247 view = GetRenderWidgetHostView();
2248 }
2249
[email protected]4aebbca2013-09-17 22:26:492250 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312251 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032252 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372253 fullscreen_widget_process_id_ =
2254 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312255 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492256 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2257 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532258 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492259 } else {
[email protected]cfd80b02014-05-01 17:46:482260 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492261 }
ericwilligersde386342016-10-19 02:35:092262 for (auto& observer : observers_)
2263 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492264 if (!widget_host_view->HasFocus())
2265 widget_host_view->Focus();
2266 } else {
bokan107a47f2015-02-03 23:23:392267 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492268 }
[email protected]89054502012-06-03 10:29:242269
2270 RenderWidgetHostImpl* render_widget_host_impl =
2271 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2272 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312273 // Only allow privileged mouse lock for fullscreen render widget, which is
2274 // used to implement Pepper Flash fullscreen.
2275 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502276
2277#if defined(OS_MACOSX)
2278 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2279 // properly embedded (or purposefully ignored) we can release the retain we
2280 // took in CreateNewWidget().
2281 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2282#endif
2283}
2284
alexmosc2a8cec2016-05-23 22:19:532285WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id,
2286 int route_id) {
2287 auto iter = pending_contents_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502288
2289 // Certain systems can block the creation of new windows. If we didn't succeed
2290 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532291 if (iter == pending_contents_.end())
2292 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502293
2294 WebContentsImpl* new_contents = iter->second;
alexmosc2a8cec2016-05-23 22:19:532295 pending_contents_.erase(std::make_pair(process_id, route_id));
[email protected]7fff43e2013-05-21 20:21:102296 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502297
[email protected]d70bea92013-04-05 04:23:342298 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252299 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342300 return new_contents;
2301
[email protected]bafe6cd2012-05-23 23:09:502302 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432303 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
alexmosc2a8cec2016-05-23 22:19:532304 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502305
[email protected]bafe6cd2012-05-23 23:09:502306 return new_contents;
2307}
2308
alexmosc2a8cec2016-05-23 22:19:532309RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2310 int route_id) {
2311 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502312 if (iter == pending_widget_views_.end()) {
2313 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532314 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502315 }
2316
2317 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532318 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502319
2320 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2321 if (!widget_host->GetProcess()->HasConnection()) {
2322 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532323 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502324 }
2325
2326 return widget_host_view;
2327}
2328
[email protected]f13b4202012-06-12 23:53:232329void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092330 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212331 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372332 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232333 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372334 } else {
dcheng59716272016-04-09 05:19:082335 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2336 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372337 }
[email protected]f13b4202012-06-12 23:53:232338}
2339
grunell657d4d82014-09-18 00:09:432340bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2341 MediaStreamType type) {
2342 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2343 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2344 return delegate_ &&
2345 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2346}
2347
[email protected]cc9200432013-07-23 23:02:402348SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2349 SiteInstance* instance) {
2350 return controller_.GetSessionStorageNamespace(instance);
2351}
2352
[email protected]6de7fc482014-06-06 10:46:442353SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2354 return controller_.GetSessionStorageNamespaceMap();
2355}
2356
[email protected]9b159a52013-10-03 17:24:552357FrameTree* WebContentsImpl::GetFrameTree() {
2358 return &frame_tree_;
2359}
2360
lukendc35e7f2014-11-10 19:06:142361void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2362 virtual_keyboard_requested_ = requested;
2363}
2364
2365bool WebContentsImpl::IsVirtualKeyboardRequested() {
2366 return virtual_keyboard_requested_;
2367}
2368
aelias5252baa2016-04-10 01:18:022369bool WebContentsImpl::IsOverridingUserAgent() {
2370 return GetController().GetVisibleEntry() &&
2371 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2372}
2373
avi85ee8362016-10-08 02:09:082374bool WebContentsImpl::IsJavaScriptDialogShowing() const {
2375 return is_showing_javascript_dialog_;
2376}
2377
[email protected]95640212014-07-26 18:14:302378AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2379 return accessibility_mode_;
2380}
2381
[email protected]31a71eaf2014-03-13 01:47:362382void WebContentsImpl::AccessibilityEventReceived(
2383 const std::vector<AXEventNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:092384 for (auto& observer : observers_)
2385 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:362386}
2387
dmazzoni2400c462016-08-23 15:07:132388void WebContentsImpl::AccessibilityLocationChangesReceived(
2389 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:092390 for (auto& observer : observers_)
2391 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:132392}
2393
dmazzonia656928e2014-09-15 20:28:542394RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402395 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542396 int browser_plugin_instance_id) {
2397 BrowserPluginGuestManager* guest_manager =
2398 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202399 if (!guest_manager)
2400 return nullptr;
2401
dmazzonia656928e2014-09-15 20:28:542402 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442403 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542404 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202405 return nullptr;
2406
dmazzonia656928e2014-09-15 20:28:542407 return guest->GetMainFrame();
2408}
2409
mcasas4e216e72016-07-28 21:28:382410device::GeolocationServiceContext*
2411WebContentsImpl::GetGeolocationServiceContext() {
blundellc57b93f2014-10-29 13:19:572412 return geolocation_service_context_.get();
2413}
2414
blundelld46e8832016-10-07 10:34:272415device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
alogvinovf50445a2015-10-30 13:00:122416 return wake_lock_service_context_.get();
2417}
2418
lunalud4a2cc82016-11-22 00:27:232419ScreenOrientationProvider* WebContentsImpl::GetScreenOrientationProvider() {
2420 return screen_orientation_.get()->GetScreenOrientationProvider();
2421}
2422
[email protected]edc3af82013-12-12 21:24:072423void WebContentsImpl::OnShowValidationMessage(
nicka0ac8382016-12-15 23:59:232424 RenderViewHostImpl* source,
[email protected]edc3af82013-12-12 21:24:072425 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292426 const base::string16& main_text,
2427 const base::string16& sub_text) {
nicka0ac8382016-12-15 23:59:232428 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072429 if (delegate_)
2430 delegate_->ShowValidationMessage(
2431 this, anchor_in_root_view, main_text, sub_text);
2432}
2433
nicka0ac8382016-12-15 23:59:232434void WebContentsImpl::OnHideValidationMessage(RenderViewHostImpl* source) {
2435 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072436 if (delegate_)
2437 delegate_->HideValidationMessage(this);
2438}
2439
2440void WebContentsImpl::OnMoveValidationMessage(
nicka0ac8382016-12-15 23:59:232441 RenderViewHostImpl* source,
[email protected]edc3af82013-12-12 21:24:072442 const gfx::Rect& anchor_in_root_view) {
nicka0ac8382016-12-15 23:59:232443 // TODO(nick): Should we consider |source| here or pass it to the delegate?
[email protected]edc3af82013-12-12 21:24:072444 if (delegate_)
2445 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2446}
2447
lfgbb9c28a2016-03-01 03:19:492448void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372449 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:402450 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:372451 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2452 }
lfgbb9c28a2016-03-01 03:19:492453
lfgdb5c4ed2016-03-04 23:09:072454 RenderWidgetHostViewBase* rwhv =
2455 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2456 if (rwhv) {
2457 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2458 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2459 }
2460
avallee9f43b012016-11-26 07:02:102461 if (browser_plugin_embedder_ && !is_being_destroyed_)
[email protected]a7568e62013-06-14 07:50:442462 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042463}
2464
khushalsagarf3b62b62016-05-26 21:54:232465void WebContentsImpl::OnFirstPaintAfterLoad(
2466 RenderWidgetHostImpl* render_widget_host) {
ericwilligersde386342016-10-19 02:35:092467 for (auto& observer : observers_)
2468 observer.DidFirstPaintAfterLoad(render_widget_host);
khushalsagarf3b62b62016-05-26 21:54:232469}
2470
ekaramadadd882292016-06-08 15:22:562471TextInputManager* WebContentsImpl::GetTextInputManager() {
2472 if (GetOuterWebContents())
2473 return GetOuterWebContents()->GetTextInputManager();
2474
2475 if (!text_input_manager_)
2476 text_input_manager_.reset(new TextInputManager());
2477
2478 return text_input_manager_.get();
2479}
2480
paulmeyer7f6f1d4f2016-11-15 00:00:272481bool WebContentsImpl::OnUpdateDragCursor() {
2482 if (browser_plugin_embedder_)
2483 return browser_plugin_embedder_->OnUpdateDragCursor();
2484 return false;
2485}
2486
[email protected]95640212014-07-26 18:14:302487BrowserAccessibilityManager*
2488 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452489 RenderFrameHostImpl* rfh = GetMainFrame();
2490 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302491}
2492
2493BrowserAccessibilityManager*
2494 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452495 RenderFrameHostImpl* rfh = GetMainFrame();
2496 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302497}
2498
mohsen7ab1ec16ec2015-07-02 18:26:232499void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2500 RenderFrameHost* focused_frame = GetFocusedFrame();
2501 if (!focused_frame)
2502 return;
2503
2504 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2505 focused_frame->GetRoutingID(), extent));
2506}
2507
2508void WebContentsImpl::SelectRange(const gfx::Point& base,
2509 const gfx::Point& extent) {
2510 RenderFrameHost* focused_frame = GetFocusedFrame();
2511 if (!focused_frame)
2512 return;
2513
2514 focused_frame->Send(
2515 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2516}
2517
aurimasab0319022015-07-10 21:57:382518void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2519 int end_adjust) {
2520 RenderFrameHost* focused_frame = GetFocusedFrame();
2521 if (!focused_frame)
2522 return;
2523
2524 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2525 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2526}
2527
[email protected]b172aee2012-04-10 17:05:262528void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492529 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232530 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492531 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332532}
2533
avic3aa8422015-11-09 20:57:222534void WebContentsImpl::ResizeDueToAutoResize(
2535 RenderWidgetHostImpl* render_widget_host,
2536 const gfx::Size& new_size) {
2537 if (render_widget_host != GetRenderViewHost()->GetWidget())
2538 return;
2539
[email protected]61e2b3cc2012-03-02 16:13:342540 if (delegate_)
2541 delegate_->ResizeDueToAutoResize(this, new_size);
2542}
2543
[email protected]b172aee2012-04-10 17:05:262544WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202545 if (!delegate_)
2546 return NULL;
[email protected]00c37fc2011-08-02 00:22:502547
[email protected]e5d549d2011-12-28 01:29:202548 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202549 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342550}
2551
[email protected]6b618e62012-08-16 12:59:182552bool WebContentsImpl::Send(IPC::Message* message) {
2553 if (!GetRenderViewHost()) {
2554 delete message;
2555 return false;
2556 }
2557
2558 return GetRenderViewHost()->Send(message);
2559}
2560
[email protected]a86c0e962013-12-17 17:10:392561void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2562 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:092563 for (auto& observer : observers_)
2564 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:442565}
2566
[email protected]20ca0382013-02-28 19:50:072567void WebContentsImpl::AttachInterstitialPage(
2568 InterstitialPageImpl* interstitial_page) {
2569 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212570 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292571
2572 // Cancel any visible dialogs so that they don't interfere with the
2573 // interstitial.
creis89a0f782015-05-27 16:13:172574 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292575
ericwilligersde386342016-10-19 02:35:092576 for (auto& observer : observers_)
2577 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:252578
2579 // Stop the throbber if needed while the interstitial page is shown.
2580 if (frame_tree_.IsLoading())
2581 LoadingStateChanged(true, true, nullptr);
2582}
2583
2584void WebContentsImpl::DidProceedOnInterstitial() {
2585 // The interstitial page should no longer be pausing the throbber.
2586 DCHECK(!(ShowingInterstitialPage() &&
2587 GetRenderManager()->interstitial_page()->pause_throbber()));
2588
2589 // Restart the throbber now that the interstitial page no longer pauses it.
2590 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2591 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072592}
2593
2594void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252595 bool interstitial_pausing_throbber =
2596 ShowingInterstitialPage() &&
2597 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572598 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212599 GetRenderManager()->remove_interstitial_page();
ericwilligersde386342016-10-19 02:35:092600 for (auto& observer : observers_)
2601 observer.DidDetachInterstitialPage();
clamy44e84ce2016-02-22 15:38:252602
2603 // Restart the throbber if needed now that the interstitial page is going
2604 // away.
2605 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2606 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072607}
2608
avi2b177592014-12-10 02:08:022609void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2610 int history_length) {
alexmos136fd6e62016-08-15 20:58:412611 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
2612 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:022613}
2614
2615void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2616 RenderViewHost* render_view_host,
2617 int history_offset,
2618 int history_length) {
alexmos136fd6e62016-08-15 20:58:412619 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:022620 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142621}
2622
toyoshim24a4c7ab2016-04-05 09:24:142623void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172624 RenderFrameHost* focused_frame = GetFocusedFrame();
2625 if (!focused_frame)
2626 return;
2627
[email protected]959be4c2014-04-08 15:01:332628 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142629 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332630}
2631
megjablon3f5941072016-02-04 23:27:522632void WebContentsImpl::ReloadLoFiImages() {
2633 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2634}
2635
[email protected]959be4c2014-04-08 15:01:332636void WebContentsImpl::Undo() {
2637 RenderFrameHost* focused_frame = GetFocusedFrame();
2638 if (!focused_frame)
2639 return;
2640
2641 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2642 RecordAction(base::UserMetricsAction("Undo"));
2643}
2644
2645void WebContentsImpl::Redo() {
2646 RenderFrameHost* focused_frame = GetFocusedFrame();
2647 if (!focused_frame)
2648 return;
2649 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2650 RecordAction(base::UserMetricsAction("Redo"));
2651}
2652
2653void WebContentsImpl::Cut() {
2654 RenderFrameHost* focused_frame = GetFocusedFrame();
2655 if (!focused_frame)
2656 return;
2657
2658 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2659 RecordAction(base::UserMetricsAction("Cut"));
2660}
2661
2662void WebContentsImpl::Copy() {
2663 RenderFrameHost* focused_frame = GetFocusedFrame();
2664 if (!focused_frame)
2665 return;
2666
2667 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2668 RecordAction(base::UserMetricsAction("Copy"));
2669}
2670
2671void WebContentsImpl::CopyToFindPboard() {
2672#if defined(OS_MACOSX)
2673 RenderFrameHost* focused_frame = GetFocusedFrame();
2674 if (!focused_frame)
2675 return;
2676
2677 // Windows/Linux don't have the concept of a find pasteboard.
2678 focused_frame->Send(
2679 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2680 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2681#endif
2682}
2683
2684void WebContentsImpl::Paste() {
2685 RenderFrameHost* focused_frame = GetFocusedFrame();
2686 if (!focused_frame)
2687 return;
2688
2689 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2690 RecordAction(base::UserMetricsAction("Paste"));
2691}
2692
2693void WebContentsImpl::PasteAndMatchStyle() {
2694 RenderFrameHost* focused_frame = GetFocusedFrame();
2695 if (!focused_frame)
2696 return;
2697
2698 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2699 focused_frame->GetRoutingID()));
2700 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2701}
2702
2703void WebContentsImpl::Delete() {
2704 RenderFrameHost* focused_frame = GetFocusedFrame();
2705 if (!focused_frame)
2706 return;
2707
2708 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2709 RecordAction(base::UserMetricsAction("DeleteSelection"));
2710}
2711
2712void WebContentsImpl::SelectAll() {
2713 RenderFrameHost* focused_frame = GetFocusedFrame();
2714 if (!focused_frame)
2715 return;
2716
2717 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2718 RecordAction(base::UserMetricsAction("SelectAll"));
2719}
2720
2721void WebContentsImpl::Unselect() {
2722 RenderFrameHost* focused_frame = GetFocusedFrame();
2723 if (!focused_frame)
2724 return;
2725
2726 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2727 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172728}
2729
2730void WebContentsImpl::Replace(const base::string16& word) {
2731 RenderFrameHost* focused_frame = GetFocusedFrame();
2732 if (!focused_frame)
2733 return;
2734
[email protected]959be4c2014-04-08 15:01:332735 focused_frame->Send(new InputMsg_Replace(
2736 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172737}
2738
2739void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2740 RenderFrameHost* focused_frame = GetFocusedFrame();
2741 if (!focused_frame)
2742 return;
2743
[email protected]959be4c2014-04-08 15:01:332744 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2745 focused_frame->GetRoutingID(), word));
2746}
2747
2748void WebContentsImpl::NotifyContextMenuClosed(
2749 const CustomContextMenuContext& context) {
2750 RenderFrameHost* focused_frame = GetFocusedFrame();
2751 if (!focused_frame)
2752 return;
2753
2754 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2755 focused_frame->GetRoutingID(), context));
2756}
2757
2758void WebContentsImpl::ExecuteCustomContextMenuCommand(
2759 int action, const CustomContextMenuContext& context) {
2760 RenderFrameHost* focused_frame = GetFocusedFrame();
2761 if (!focused_frame)
2762 return;
2763
2764 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2765 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002766}
2767
[email protected]fc2b46b2014-05-03 16:33:452768gfx::NativeView WebContentsImpl::GetNativeView() {
2769 return view_->GetNativeView();
2770}
2771
2772gfx::NativeView WebContentsImpl::GetContentNativeView() {
2773 return view_->GetContentNativeView();
2774}
2775
2776gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2777 return view_->GetTopLevelNativeWindow();
2778}
2779
2780gfx::Rect WebContentsImpl::GetViewBounds() {
2781 return view_->GetViewBounds();
2782}
2783
2784gfx::Rect WebContentsImpl::GetContainerBounds() {
2785 gfx::Rect rv;
2786 view_->GetContainerBounds(&rv);
2787 return rv;
2788}
2789
2790DropData* WebContentsImpl::GetDropData() {
2791 return view_->GetDropData();
2792}
2793
2794void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042795 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452796}
2797
2798void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042799 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452800}
2801
2802void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042803 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452804}
2805
2806void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042807 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452808}
2809
[email protected]b172aee2012-04-10 17:05:262810void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272811 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212812 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542813 return;
2814 }
[email protected]0b431992014-06-24 00:08:032815 RenderWidgetHostView* const fullscreen_view =
2816 GetFullscreenRenderWidgetHostView();
2817 if (fullscreen_view) {
2818 fullscreen_view->Focus();
2819 return;
2820 }
creisc014b402015-04-23 16:41:452821 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542822}
2823
[email protected]b172aee2012-04-10 17:05:262824bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212825 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542826}
2827
[email protected]b172aee2012-04-10 17:05:262828InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212829 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222830}
2831
[email protected]b172aee2012-04-10 17:05:262832bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162833 // WebKit creates Document object when MIME type is application/xhtml+xml,
2834 // so we also support this MIME type.
2835 return contents_mime_type_ == "text/html" ||
2836 contents_mime_type_ == "text/xml" ||
2837 contents_mime_type_ == "application/xhtml+xml" ||
2838 contents_mime_type_ == "text/plain" ||
2839 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252840 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162841}
2842
[email protected]b172aee2012-04-10 17:05:262843void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592844 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162845 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552846 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192847 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142848 return;
[email protected]c7dd2f62011-07-18 15:57:592849 }
2850
2851 Stop();
2852
2853 // Create the save package and possibly prompt the user for the name to save
2854 // the page as. The user prompt is an asynchronous operation that runs on
2855 // another thread.
2856 save_package_ = new SavePackage(this);
2857 save_package_->GetSaveInfo();
2858}
2859
2860// Used in automated testing to bypass prompting the user for file names.
2861// Instead, the names and paths are hard coded rather than running them through
2862// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342863bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2864 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212865 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592866 // Stop the page from navigating.
2867 Stop();
2868
2869 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212870 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592871}
2872
[email protected]3c71576ce2013-07-23 02:00:012873void WebContentsImpl::SaveFrame(const GURL& url,
2874 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372875 SaveFrameWithHeaders(url, referrer, std::string());
2876}
2877
2878void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2879 const Referrer& referrer,
2880 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192881 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012882 return;
sammc92af61552014-11-19 23:27:402883 if (delegate_ && delegate_->SaveFrame(url, referrer))
2884 return;
2885
nasko89ad7742015-03-05 22:14:192886 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:222887 // by explicitly passing in which frame this method should target. This would
2888 // indicate whether it's the main frame, and also tell us the frame pointer
2889 // to use for routing.
nasko89ad7742015-03-05 22:14:192890 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:222891 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:012892
brettw760f7442016-05-23 21:19:222893 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
2894 GetBrowserContext(), frame_host->GetSiteInstance());
[email protected]3c71576ce2013-07-23 02:00:012895 DownloadManager* dlm =
2896 BrowserContext::GetDownloadManager(GetBrowserContext());
2897 if (!dlm)
2898 return;
avib7348942015-12-25 20:57:102899 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012900 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272901 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012902 if (entry)
2903 post_id = entry->GetPostID();
2904 }
brettw760f7442016-05-23 21:19:222905 std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
2906 url, frame_host->GetProcess()->GetID(),
2907 frame_host->GetRenderViewHost()->GetRoutingID(),
2908 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext()));
[email protected]3c71576ce2013-07-23 02:00:012909 params->set_referrer(referrer);
2910 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012911 if (post_id >= 0)
2912 params->set_method("POST");
2913 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372914
2915 if (headers.empty()) {
2916 params->set_prefer_cache(true);
2917 } else {
brettw26dab8f02015-08-08 00:28:472918 for (const base::StringPiece& key_value :
2919 base::SplitStringPiece(
2920 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2921 std::vector<std::string> pair = base::SplitString(
2922 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372923 DCHECK_EQ(2ul, pair.size());
2924 params->add_request_header(pair[0], pair[1]);
2925 }
2926 }
dcheng36b6aec92015-12-26 06:16:362927 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012928}
2929
[email protected]b172aee2012-04-10 17:05:262930void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:472931 const MHTMLGenerationParams& params,
avib7348942015-12-25 20:57:102932 const base::Callback<void(int64_t)>& callback) {
dewittj6dc5747a2016-05-17 01:48:472933 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
[email protected]aa4f3972012-03-01 18:12:122934}
2935
[email protected]b172aee2012-04-10 17:05:262936const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272937 return contents_mime_type_;
2938}
2939
[email protected]b172aee2012-04-10 17:05:262940bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272941 return notify_disconnection_;
2942}
2943
[email protected]8ff00d72012-10-23 19:12:212944RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272945 return &renderer_preferences_;
2946}
2947
[email protected]e35ccd52012-05-23 16:22:472948void WebContentsImpl::Close() {
2949 Close(GetRenderViewHost());
2950}
2951
paulmeyer8fc8ea92016-11-15 05:12:212952void WebContentsImpl::DragSourceEndedAt(int client_x,
2953 int client_y,
2954 int screen_x,
2955 int screen_y,
Paul Meyer0c58c3712016-11-17 22:59:512956 blink::WebDragOperation operation,
2957 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:292958 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:212959 browser_plugin_embedder_->DragSourceEndedAt(
2960 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:512961 if (source_rwh) {
2962 source_rwh->DragSourceEndedAt(gfx::Point(client_x, client_y),
2963 gfx::Point(screen_x, screen_y),
2964 operation);
2965 }
[email protected]cf200a562013-05-03 16:24:292966}
2967
jam73f892642016-09-11 06:04:062968void WebContentsImpl::LoadStateChanged(
2969 const GURL& url,
2970 const net::LoadStateWithParam& load_state,
2971 uint64_t upload_position,
2972 uint64_t upload_size) {
2973 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2974 // is fixed.
2975 tracked_objects::ScopedTracker tracking_profile1(
2976 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2977 "466285 WebContentsImpl::LoadStateChanged::Start"));
2978 load_state_ = load_state;
2979 upload_position_ = upload_position;
2980 upload_size_ = upload_size;
2981 load_state_host_ = url_formatter::IDNToUnicode(url.host());
2982 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
2983 SetNotWaitingForResponse();
2984 if (IsLoading()) {
2985 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
2986 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
2987 }
2988}
2989
[email protected]d60f3702013-12-26 16:30:242990void WebContentsImpl::DidGetResourceResponseStart(
2991 const ResourceRequestDetails& details) {
estarkf83ac122016-10-05 19:06:062992 controller_.ssl_manager()->DidStartResourceResponse(
2993 details.url, details.has_certificate, details.ssl_cert_status);
[email protected]d60f3702013-12-26 16:30:242994
ericwilligersde386342016-10-19 02:35:092995 for (auto& observer : observers_)
2996 observer.DidGetResourceResponseStart(details);
[email protected]d60f3702013-12-26 16:30:242997}
2998
2999void WebContentsImpl::DidGetRedirectForResourceRequest(
[email protected]d60f3702013-12-26 16:30:243000 const ResourceRedirectDetails& details) {
ericwilligersde386342016-10-19 02:35:093001 for (auto& observer : observers_)
3002 observer.DidGetRedirectForResourceRequest(details);
[email protected]d60f3702013-12-26 16:30:243003
3004 // TODO(avi): Remove. http://crbug.com/170921
3005 NotificationService::current()->Notify(
3006 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
3007 Source<WebContents>(this),
3008 Details<const ResourceRedirectDetails>(&details));
3009}
3010
calamity7fe55ce2015-04-10 03:59:373011void WebContentsImpl::NotifyWebContentsFocused() {
ericwilligersde386342016-10-19 02:35:093012 for (auto& observer : observers_)
3013 observer.OnWebContentsFocused();
calamity7fe55ce2015-04-10 03:59:373014}
3015
Paul Meyer0c58c3712016-11-17 22:59:513016void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3017 if (source_rwh)
3018 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293019 if (browser_plugin_embedder_.get())
3020 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343021}
3022
[email protected]e35ccd52012-05-23 16:22:473023void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:533024 OnUserInteraction(GetRenderViewHost()->GetWidget(),
3025 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:473026}
3027
[email protected]b172aee2012-04-10 17:05:263028void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273029 closed_by_user_gesture_ = value;
3030}
3031
[email protected]b172aee2012-04-10 17:05:263032bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273033 return closed_by_user_gesture_;
3034}
3035
[email protected]b172aee2012-04-10 17:05:263036void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:503037 if (!delegate_)
3038 return;
3039
[email protected]6286a372013-10-09 04:03:273040 NavigationEntry* entry = GetController().GetLastCommittedEntry();
3041 if (!entry)
[email protected]1788e772010-12-15 16:40:503042 return;
3043
[email protected]6286a372013-10-09 04:03:273044 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:123045}
3046
[email protected]b172aee2012-04-10 17:05:263047void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:043048 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:273049 if (!delegate_)
3050 return;
3051
[email protected]691aa2f2013-05-28 22:52:043052 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:273053}
3054
[email protected]b172aee2012-04-10 17:05:263055int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273056 return minimum_zoom_percent_;
3057}
3058
[email protected]b172aee2012-04-10 17:05:263059int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273060 return maximum_zoom_percent_;
3061}
3062
mcnee432e47d2015-11-09 19:37:463063void WebContentsImpl::SetPageScale(float page_scale_factor) {
davidsac996be112016-11-30 08:56:383064 Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(),
3065 page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243066}
3067
[email protected]b172aee2012-04-10 17:05:263068gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:493069 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:233070}
3071
[email protected]b172aee2012-04-10 17:05:263072bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:053073 if (GetBrowserPluginGuest())
3074 return GetBrowserPluginGuest()->LockMouse(allowed);
3075
lfgad8244352016-07-13 16:55:513076 if (mouse_lock_widget_ &&
3077 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3078 return true;
3079
3080 mouse_lock_widget_ = nullptr;
lfgbee1e0a2016-06-08 21:24:213081 return false;
[email protected]0bfbf882011-12-22 18:19:273082}
3083
[email protected]b172aee2012-04-10 17:05:263084bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:213085 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:503086}
3087
alexmose201c7cd2015-06-10 17:14:213088WebContentsImpl* WebContentsImpl::GetOpener() const {
3089 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3090 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:573091}
3092
[email protected]cb805452013-05-22 15:16:213093void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:483094 if (!color_chooser_info_.get())
3095 return;
3096 RenderFrameHost* rfh = RenderFrameHost::FromID(
3097 color_chooser_info_->render_process_id,
3098 color_chooser_info_->render_frame_id);
3099 if (!rfh)
3100 return;
3101
3102 rfh->Send(new FrameMsg_DidChooseColorResponse(
3103 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:203104}
3105
[email protected]cb805452013-05-22 15:16:213106void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:483107 if (!color_chooser_info_.get())
3108 return;
3109 RenderFrameHost* rfh = RenderFrameHost::FromID(
3110 color_chooser_info_->render_process_id,
3111 color_chooser_info_->render_frame_id);
3112 if (!rfh)
3113 return;
3114
3115 rfh->Send(new FrameMsg_DidEndColorChooser(
3116 rfh->GetRoutingID(), color_chooser_info_->identifier));
3117 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:203118}
3119
halton.huoca2eabd2015-07-06 08:17:403120int WebContentsImpl::DownloadImage(
3121 const GURL& url,
3122 bool is_favicon,
3123 uint32_t max_bitmap_size,
3124 bool bypass_cache,
3125 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:553126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403127 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063128 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403129 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553130 const int download_id = ++next_image_download_id;
3131 if (!mojo_image_downloader) {
3132 // If the renderer process is dead (i.e. crash, or memory pressure on
3133 // Android), the downloader service will be invalid. Pre-Mojo, this would
3134 // hang the callback indefinetly since the IPC would be dropped. Now,
3135 // respond with a 400 HTTP error code to indicate that something went wrong.
3136 BrowserThread::PostTask(
3137 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:193138 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:523139 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
leon.hanc2228532016-08-16 05:59:183140 std::vector<SkBitmap>(), std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553141 return download_id;
3142 }
3143
halton.huoca2eabd2015-07-06 08:17:403144 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393145 url, is_favicon, max_bitmap_size, bypass_cache,
leon.hancbc4bc3c2016-02-26 07:08:523146 base::Bind(&WebContentsImpl::OnDidDownloadImage,
3147 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:553148 return download_id;
[email protected]795c28972012-12-06 06:13:393149}
3150
[email protected]5dcaf8e2013-12-28 01:31:423151bool WebContentsImpl::IsSubframe() const {
3152 return is_subframe_;
3153}
3154
[email protected]36ec24f2014-01-09 00:32:083155void WebContentsImpl::Find(int request_id,
3156 const base::string16& search_text,
3157 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333158 // Cowardly refuse to search for no text.
3159 if (search_text.empty()) {
3160 NOTREACHED();
3161 return;
3162 }
3163
raymes0fa0be52014-10-13 20:38:093164 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173165 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473166 if (browser_plugin_embedder_ &&
3167 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3168 return;
raymes0fa0be52014-10-13 20:38:093169 }
paulmeyerc0b762b2016-04-13 11:55:173170
3171 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083172}
3173
3174void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013175 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173176 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473177 if (browser_plugin_embedder_ &&
3178 browser_plugin_embedder_->StopFinding(action)) {
3179 return;
raymes2bc64182015-02-06 01:23:013180 }
paulmeyerc0b762b2016-04-13 11:55:173181
3182 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083183}
3184
dalecurtisbc6572e12014-09-12 19:22:303185bool WebContentsImpl::WasRecentlyAudible() {
wjmaclean1dabf3e32016-05-13 23:34:443186 return audio_stream_monitor_.WasRecentlyAudible() ||
3187 (browser_plugin_embedder_ &&
3188 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:303189}
3190
mlamouriefdca9d2014-09-16 16:55:403191void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3192 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3193}
3194
bokanece34a82016-01-28 19:49:463195void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533196 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433197 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463198 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533199}
3200
mariakhomenko44bdc4732015-04-29 01:55:383201void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373202 if (delayed_open_url_params_.get()) {
3203 OpenURL(*delayed_open_url_params_.get());
3204 delayed_open_url_params_.reset(nullptr);
3205 return;
3206 }
3207
mariakhomenko44bdc4732015-04-29 01:55:383208 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3209 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163210 if (is_resume_pending_) {
3211 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133212 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163213 GetMainFrame()->Init();
3214 }
mariakhomenko44bdc4732015-04-29 01:55:383215}
3216
[email protected]b172aee2012-04-10 17:05:263217bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263218 // When the browser is started with about:blank as the startup URL, focus
3219 // the location bar (which will also select its contents) so people can
3220 // simply begin typing to navigate elsewhere.
3221 //
3222 // We need to be careful not to trigger this for anything other than the
3223 // startup navigation. In particular, if we allow an attacker to open a
3224 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3225 // end of the new URL to be scrolled into view instead of the start,
3226 // allowing the attacker to spoof other URLs. The conditions checked here
3227 // are all aimed at ensuring no such attacker-controlled navigation can
3228 // trigger this.
3229 //
3230 // Note that we check the pending entry instead of the visible one; for the
3231 // startup URL case these are the same, but for the attacker-controlled
3232 // navigation case the visible entry is the committed "about:blank" URL and
3233 // the pending entry is the problematic navigation elsewhere.
3234 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3235 if (controller_.IsInitialNavigation() && entry &&
3236 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:483237 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:333238 return true;
palmerc70cb1f2016-03-04 23:41:263239 }
[email protected]0c9406632013-02-08 01:13:333240 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273241}
3242
[email protected]b172aee2012-04-10 17:05:263243void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273244 if (delegate_)
3245 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213246}
3247
clamy0e119882015-07-31 16:12:333248void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093249 for (auto& observer : observers_)
3250 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333251}
3252
3253void WebContentsImpl::DidRedirectNavigation(
3254 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093255 for (auto& observer : observers_)
3256 observer.DidRedirectNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333257}
3258
clamyefca29e2015-09-17 00:22:113259void WebContentsImpl::ReadyToCommitNavigation(
3260 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093261 for (auto& observer : observers_)
3262 observer.ReadyToCommitNavigation(navigation_handle);
clamyefca29e2015-09-17 00:22:113263}
3264
clamy0e119882015-07-31 16:12:333265void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093266 for (auto& observer : observers_)
3267 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333268}
3269
[email protected]52913802013-12-10 05:52:183270void WebContentsImpl::DidStartProvisionalLoad(
3271 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183272 const GURL& validated_url,
arthursonzogniee7f43b2016-12-06 10:52:293273 bool is_error_page) {
[email protected]0d60f0192011-04-14 12:40:103274 // Notify observers about the start of the provisional load.
ericwilligersde386342016-10-19 02:35:093275 for (auto& observer : observers_) {
3276 observer.DidStartProvisionalLoadForFrame(render_frame_host, validated_url,
arthursonzogniee7f43b2016-12-06 10:52:293277 is_error_page);
ericwilligersde386342016-10-19 02:35:093278 }
dmazzonibf8cec42015-02-08 08:28:083279
3280 // Notify accessibility if this is a reload.
3281 NavigationEntry* entry = controller_.GetVisibleEntry();
arthursonzogniee7f43b2016-12-06 10:52:293282 if (entry && ui::PageTransitionCoreTypeIs(entry->GetTransitionType(),
3283 ui::PAGE_TRANSITION_RELOAD)) {
dmazzonibf8cec42015-02-08 08:28:083284 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3285 BrowserAccessibilityManager* manager =
3286 ftn->current_frame_host()->browser_accessibility_manager();
3287 if (manager)
3288 manager->UserIsReloading();
3289 }
[email protected]400992b2012-06-14 00:03:543290}
3291
[email protected]3109fbb72014-01-06 23:57:153292void WebContentsImpl::DidFailProvisionalLoadWithError(
3293 RenderFrameHostImpl* render_frame_host,
lazyboy552a9382016-07-14 20:38:373294 const GURL& validated_url,
3295 int error_code,
3296 const base::string16& error_description,
3297 bool was_ignored_by_handler) {
ericwilligersde386342016-10-19 02:35:093298 for (auto& observer : observers_) {
3299 observer.DidFailProvisionalLoad(render_frame_host, validated_url,
3300 error_code, error_description,
3301 was_ignored_by_handler);
3302 }
dmazzonibf8cec42015-02-08 08:28:083303
3304 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3305 BrowserAccessibilityManager* manager =
3306 ftn->current_frame_host()->browser_accessibility_manager();
3307 if (manager)
3308 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153309}
3310
[email protected]b80624c2014-02-09 02:46:553311void WebContentsImpl::DidFailLoadWithError(
3312 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553313 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553314 int error_code,
gsennton6fbb38692015-06-24 19:23:553315 const base::string16& error_description,
3316 bool was_ignored_by_handler) {
ericwilligersde386342016-10-19 02:35:093317 for (auto& observer : observers_) {
3318 observer.DidFailLoad(render_frame_host, url, error_code, error_description,
3319 was_ignored_by_handler);
3320 }
[email protected]b80624c2014-02-09 02:46:553321}
3322
[email protected]52913802013-12-10 05:52:183323void WebContentsImpl::NotifyChangedNavigationState(
3324 InvalidateTypes changed_flags) {
3325 NotifyNavigationStateChanged(changed_flags);
3326}
3327
toyoshim0df1d3a2016-09-09 09:52:483328void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
3329 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:203330 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093331 for (auto& observer : observers_)
3332 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:203333}
3334
[email protected]8cb834e2014-03-06 14:23:233335void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3336 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503337 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3338 // weak pointer of sorts.
3339 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3340 const int32_t frame_id = render_frame_host->GetRoutingID();
3341
[email protected]65920f332014-03-04 21:14:183342 WebContents* new_contents = OpenURL(params);
3343
dchengb907f7332015-01-07 20:35:503344 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183345 // Notify observers.
ericwilligersde386342016-10-19 02:35:093346 for (auto& observer : observers_) {
3347 observer.DidOpenRequestedURL(new_contents, render_frame_host, params.url,
3348 params.referrer, params.disposition,
3349 params.transition);
3350 }
[email protected]65920f332014-03-04 21:14:183351 }
3352}
3353
lukasza1d025732016-09-28 21:36:083354bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:223355 if (!delegate_)
3356 return true;
lukasza1d025732016-09-28 21:36:083357 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:223358}
3359
[email protected]aa62afd2014-04-22 19:22:463360bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3361 if (!delegate_)
3362 return false;
3363 return delegate_->ShouldPreserveAbortedURLs(this);
3364}
3365
[email protected]37567b432014-02-12 01:12:223366void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433367 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223368 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353369 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223370 // Notify observers about the commit of the provisional load.
ericwilligersde386342016-10-19 02:35:093371 for (auto& observer : observers_) {
3372 observer.DidCommitProvisionalLoadForFrame(render_frame_host, url,
3373 transition_type);
3374 }
dmazzonibf8cec42015-02-08 08:28:083375
3376 BrowserAccessibilityManager* manager =
3377 render_frame_host->browser_accessibility_manager();
3378 if (manager)
3379 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223380}
3381
[email protected]0d0f4c492014-04-02 06:42:573382void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233383 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573384 // Ensure fullscreen mode is exited before committing the navigation to a
3385 // different page. The next page will not start out assuming it is in
3386 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233387 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193388 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573389 return;
3390 }
alexmos5dd617d2016-06-07 04:21:153391 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:463392 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:153393 DCHECK(!IsFullscreenForCurrentTab());
[email protected]0d0f4c492014-04-02 06:42:573394}
3395
[email protected]37567b432014-02-12 01:12:223396void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283397 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223398 const LoadCommittedDetails& details,
3399 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3400 if (details.is_navigation_to_different_page()) {
3401 // Clear the status bubble. This is a workaround for a bug where WebKit
3402 // doesn't let us know that the cursor left an element during a
3403 // transition (this is also why the mouse cursor remains as a hand after
3404 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3405 // clear the bubble when a user navigates to a named anchor in the same
3406 // page.
sky8b00392d2015-01-10 00:30:283407 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003408
3409 RenderWidgetHostViewBase* rwhvb =
3410 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3411 if (rwhvb)
3412 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283413
peter90afaba2015-06-01 12:05:293414 did_first_visually_non_empty_paint_ = false;
3415
yusufod41c5f92015-03-06 00:14:283416 // Reset theme color on navigation to new page.
3417 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223418 }
3419
[email protected]37567b432014-02-12 01:12:223420 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093421 for (auto& observer : observers_)
3422 observer.DidNavigateMainFrame(details, params);
[email protected]37567b432014-02-12 01:12:223423
[email protected]e85165c642014-06-10 14:34:313424 if (delegate_)
[email protected]37567b432014-02-12 01:12:223425 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313426 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223427}
3428
3429void WebContentsImpl::DidNavigateAnyFramePostCommit(
3430 RenderFrameHostImpl* render_frame_host,
3431 const LoadCommittedDetails& details,
3432 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103433 // Now that something has committed, we don't need to track whether the
3434 // initial page has been accessed.
3435 has_accessed_initial_document_ = false;
3436
[email protected]37567b432014-02-12 01:12:223437 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173438 if (!details.is_in_page)
3439 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223440
avid53461d2016-02-25 17:15:043441 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3442 // again.
avi5d3b8692016-10-12 22:00:463443 if (params.gesture == NavigationGestureUser && dialog_manager_) {
3444 dialog_manager_->CancelDialogs(this,
3445 false, // suppress_callbacks,
3446 true); // reset_state
3447 }
avid53461d2016-02-25 17:15:043448
[email protected]37567b432014-02-12 01:12:223449 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093450 for (auto& observer : observers_)
3451 observer.DidNavigateAnyFrame(render_frame_host, details, params);
[email protected]37567b432014-02-12 01:12:223452}
3453
3454void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3455 contents_mime_type_ = mime_type;
3456}
3457
[email protected]277857a2014-06-03 10:38:013458bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313459 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053460 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313461 return false;
3462
[email protected]37567b432014-02-12 01:12:223463 if (delegate_)
3464 return delegate_->CanOverscrollContent();
3465
3466 return false;
3467}
3468
nicka0ac8382016-12-15 23:59:233469void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source,
3470 SkColor theme_color) {
3471 if (source != GetMainFrame()) {
3472 // Only the main frame may control the theme.
3473 return;
3474 }
3475
peter90afaba2015-06-01 12:05:293476 // Update the theme color. This is to be published to observers after the
3477 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283478 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293479
3480 if (did_first_visually_non_empty_paint_ &&
3481 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:093482 for (auto& observer : observers_)
3483 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:293484 last_sent_theme_color_ = theme_color_;
3485 }
[email protected]e7104762014-06-20 19:17:253486}
3487
[email protected]b172aee2012-04-10 17:05:263488void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:233489 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:183490 const GURL& url,
[email protected]70435962011-08-02 20:13:283491 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183492 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403493 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:093494 for (auto& observer : observers_)
3495 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:133496
[email protected]8bfc8272013-09-09 20:10:533497 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:233498 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
[email protected]8bfc8272013-09-09 20:10:533499 scoped_refptr<net::URLRequestContextGetter> request_context(
nicka0ac8382016-12-15 23:59:233500 resource_type == RESOURCE_TYPE_MEDIA
3501 ? partition->GetMediaURLRequestContext()
3502 : partition->GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533503 BrowserThread::PostTask(
nicka0ac8382016-12-15 23:59:233504 BrowserThread::IO, FROM_HERE,
[email protected]8bfc8272013-09-09 20:10:533505 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3506 }
[email protected]724159a2010-12-30 01:11:183507}
3508
nicka0ac8382016-12-15 23:59:233509void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) {
3510 // Any frame can trigger display of insecure content, so we don't check
3511 // |source| here.
[email protected]e6e30ac2014-01-13 21:24:393512 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
estarkc2273502016-10-12 22:03:023513 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:183514}
3515
nicka0ac8382016-12-15 23:59:233516void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
3517 const GURL& security_origin,
estark910b4572015-12-09 20:55:413518 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:233519 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
3520 // these parameters? |target_url| seems unused, except for a log message. And
3521 // |security_origin| might be replaceable with the origin of the main frame.
[email protected]9450c462013-11-23 01:22:583522 LOG(WARNING) << security_origin << " ran insecure content from "
3523 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393524 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413525 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293526 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393527 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:023528 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:183529}
3530
estark910b4572015-12-09 20:55:413531void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
nicka0ac8382016-12-15 23:59:233532 RenderFrameHostImpl* source,
jama385e112016-07-22 00:07:583533 const GURL& url) {
nicka0ac8382016-12-15 23:59:233534 // TODO(nick): |url| is unused; get rid of it.
estarkc2273502016-10-12 22:03:023535 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:413536}
3537
3538void WebContentsImpl::OnDidRunContentWithCertificateErrors(
nicka0ac8382016-12-15 23:59:233539 RenderFrameHostImpl* source,
jama385e112016-07-22 00:07:583540 const GURL& url) {
nicka0ac8382016-12-15 23:59:233541 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:153542 NavigationEntry* entry = controller_.GetVisibleEntry();
3543 if (!entry)
estarkaeda1422016-05-10 02:31:123544 return;
3545
estarkaeda1422016-05-10 02:31:123546 // TODO(estark): check that this does something reasonable for
3547 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:153548 controller_.ssl_manager()->DidRunContentWithCertErrors(
3549 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:413550}
3551
nicka0ac8382016-12-15 23:59:233552void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) {
ericwilligersde386342016-10-19 02:35:093553 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:233554 observer.DocumentLoadedInFrame(source);
[email protected]724159a2010-12-30 01:11:183555}
3556
nicka0ac8382016-12-15 23:59:233557void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
3558 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:123559 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:233560 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373561
ericwilligersde386342016-10-19 02:35:093562 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:233563 observer.DidFinishLoad(source, validated_url);
[email protected]1a55c5be2011-11-29 11:36:313564}
3565
nicka0ac8382016-12-15 23:59:233566void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source,
3567 int offset) {
3568 // All frames are allowed to navigate the global history.
avi6ddfcae2015-06-30 15:50:573569 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3570 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263571}
3572
nicka0ac8382016-12-15 23:59:233573void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source,
3574 int minimum_percent,
[email protected]fce823222014-05-30 16:24:303575 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263576 minimum_zoom_percent_ = minimum_percent;
3577 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263578}
3579
nicka0ac8382016-12-15 23:59:233580void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
3581 float page_scale_factor) {
mcnee432e47d2015-11-09 19:37:463582 bool is_one = page_scale_factor == 1.f;
3583 if (is_one != page_scale_factor_is_one_) {
3584 page_scale_factor_is_one_ = is_one;
3585
3586 HostZoomMapImpl* host_zoom_map =
3587 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3588
nicka0ac8382016-12-15 23:59:233589 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:463590 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:233591 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:463592 page_scale_factor_is_one_);
3593 }
3594 }
3595
ericwilligersde386342016-10-19 02:35:093596 for (auto& observer : observers_)
3597 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:463598}
3599
nicka0ac8382016-12-15 23:59:233600void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source,
3601 int request_id,
[email protected]2dec8ec2013-02-07 19:20:343602 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433603 if (!delegate_)
3604 return;
3605
[email protected]b9535422012-02-09 01:47:593606 ChildProcessSecurityPolicyImpl* policy =
3607 ChildProcessSecurityPolicyImpl::GetInstance();
nicka0ac8382016-12-15 23:59:233608 if (policy->CanReadFile(source->GetProcess()->GetID(), path)) {
3609 // TODO(nick): |this| param in the call below ought to be a RenderFrameHost.
[email protected]b9535422012-02-09 01:47:593610 delegate_->EnumerateDirectory(this, request_id, path);
nicka0ac8382016-12-15 23:59:233611 }
[email protected]3a29a6e2011-08-24 18:26:213612}
3613
nicka0ac8382016-12-15 23:59:233614void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source,
3615 const std::string& protocol,
[email protected]b172aee2012-04-10 17:05:263616 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263617 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363618 bool user_gesture) {
nicka0ac8382016-12-15 23:59:233619 // TODO(nick): Should we consider |source| here or pass it to the delegate?
3620 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:433621 if (!delegate_)
3622 return;
3623
[email protected]b9535422012-02-09 01:47:593624 ChildProcessSecurityPolicyImpl* policy =
3625 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323626 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593627 return;
[email protected]8f810632013-06-06 22:33:323628
[email protected]c125e532014-05-10 20:39:063629 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203630}
3631
nicka0ac8382016-12-15 23:59:233632void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source,
3633 const std::string& protocol,
[email protected]f5273e52014-07-14 16:30:203634 const GURL& url,
3635 bool user_gesture) {
nicka0ac8382016-12-15 23:59:233636 // TODO(nick): Should we consider |source| here or pass it to the delegate?
3637 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:203638 if (!delegate_)
3639 return;
3640
3641 ChildProcessSecurityPolicyImpl* policy =
3642 ChildProcessSecurityPolicyImpl::GetInstance();
3643 if (policy->IsPseudoScheme(protocol))
3644 return;
3645
3646 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3647}
3648
kouhei40f03cb2015-09-24 07:47:013649void WebContentsImpl::OnUpdatePageImportanceSignals(
nicka0ac8382016-12-15 23:59:233650 RenderFrameHostImpl* source,
kouhei40f03cb2015-09-24 07:47:013651 const PageImportanceSignals& signals) {
nicka0ac8382016-12-15 23:59:233652 // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets
3653 // written to this one field.
kouhei40f03cb2015-09-24 07:47:013654 page_importance_signals_ = signals;
3655}
3656
nicka0ac8382016-12-15 23:59:233657void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
3658 int request_id,
[email protected]b172aee2012-04-10 17:05:263659 int number_of_matches,
3660 const gfx::Rect& selection_rect,
3661 int active_match_ordinal,
3662 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173663 // Forward the find reply to the FindRequestManager, along with the
3664 // RenderFrameHost associated with the frame that the reply came from.
nicka0ac8382016-12-15 23:59:233665 GetOrCreateFindRequestManager()->OnFindReply(
3666 source, request_id, number_of_matches, selection_rect,
3667 active_match_ordinal, final_update);
[email protected]b888919c2011-09-02 00:32:163668}
3669
mfomitchev2b8b066a2016-01-28 19:23:153670#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313671void WebContentsImpl::OnFindMatchRectsReply(
nicka0ac8382016-12-15 23:59:233672 RenderFrameHostImpl* source,
[email protected]59363fc92012-09-05 03:46:313673 int version,
3674 const std::vector<gfx::RectF>& rects,
3675 const gfx::RectF& active_rect) {
nicka0ac8382016-12-15 23:59:233676 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(source, version, rects,
3677 active_rect);
[email protected]59363fc92012-09-05 03:46:313678}
[email protected]583418cc2013-01-17 14:01:103679
nicka0ac8382016-12-15 23:59:233680void WebContentsImpl::OnGetNearestFindResultReply(RenderFrameHostImpl* source,
3681 int request_id,
paulmeyerc8cb7cb2016-06-07 01:14:193682 float distance) {
3683 GetOrCreateFindRequestManager()->OnGetNearestFindResultReply(
nicka0ac8382016-12-15 23:59:233684 source, request_id, distance);
paulmeyerc8cb7cb2016-06-07 01:14:193685}
3686
[email protected]1ff427972013-02-07 21:14:073687void WebContentsImpl::OnOpenDateTimeDialog(
nicka0ac8382016-12-15 23:59:233688 RenderViewHostImpl* source,
[email protected]1ff427972013-02-07 21:14:073689 const ViewHostMsg_DateTimeDialogValue_Params& value) {
nicka0ac8382016-12-15 23:59:233690 date_time_chooser_->ShowDialog(
3691 GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value,
3692 value.minimum, value.maximum, value.step, value.suggestions);
[email protected]583418cc2013-01-17 14:01:103693}
[email protected]59363fc92012-09-05 03:46:313694#endif
3695
nicka0ac8382016-12-15 23:59:233696void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
3697 const std::string& json_string) {
3698 // TODO(nick, lukasza): The notification below should probably be updated to
3699 // include |source|.
avi60bd4902015-09-23 20:39:243700 std::string json = json_string;
3701 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3702 Source<WebContents>(this),
3703 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403704}
3705
nicka0ac8382016-12-15 23:59:233706void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source,
3707 const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:263708 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:233709 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
3710 // |manifest_url|?
3711
[email protected]7fc4bbb2011-09-08 21:23:103712 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093713 for (auto& observer : observers_)
3714 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:103715}
3716
[email protected]8bc5ff02013-11-29 06:34:033717void WebContentsImpl::OnOpenColorChooser(
nicka0ac8382016-12-15 23:59:233718 RenderFrameHostImpl* source,
[email protected]8ed16472014-04-11 19:02:483719 int color_chooser_id,
3720 SkColor color,
3721 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:463722 ColorChooser* new_color_chooser = delegate_ ?
3723 delegate_->OpenColorChooser(this, color, suggestions) :
3724 NULL;
[email protected]820957a2014-01-14 14:56:303725 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213726 return;
[email protected]8ed16472014-04-11 19:02:483727 if (color_chooser_info_.get())
3728 color_chooser_info_->chooser->End();
3729
3730 color_chooser_info_.reset(new ColorChooserInfo(
nicka0ac8382016-12-15 23:59:233731 source->GetProcess()->GetID(), source->GetRoutingID(), new_color_chooser,
[email protected]8ed16472014-04-11 19:02:483732 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203733}
3734
nicka0ac8382016-12-15 23:59:233735void WebContentsImpl::OnEndColorChooser(RenderFrameHostImpl* source,
3736 int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483737 if (color_chooser_info_ &&
nicka0ac8382016-12-15 23:59:233738 color_chooser_info_->Matches(source, color_chooser_id))
[email protected]8ed16472014-04-11 19:02:483739 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203740}
3741
nicka0ac8382016-12-15 23:59:233742void WebContentsImpl::OnSetSelectedColorInColorChooser(
3743 RenderFrameHostImpl* source,
3744 int color_chooser_id,
3745 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483746 if (color_chooser_info_ &&
nicka0ac8382016-12-15 23:59:233747 color_chooser_info_->Matches(source, color_chooser_id))
[email protected]8ed16472014-04-11 19:02:483748 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203749}
3750
[email protected]d0759f492012-04-19 22:50:503751// This exists for render views that don't have a WebUI, but do have WebUI
3752// bindings enabled.
nicka0ac8382016-12-15 23:59:233753void WebContentsImpl::OnWebUISend(RenderViewHostImpl* source,
3754 const GURL& source_url,
[email protected]d0759f492012-04-19 22:50:503755 const std::string& name,
3756 const base::ListValue& args) {
nicka0ac8382016-12-15 23:59:233757 // TODO(nick): Should we consider |source| here or pass it to the delegate?
3758 // TODO(nick): Should FilterURL be applied to |source_url|?
3759 // TODO(nick): This IPC should be ported to FrameHostMsg_, and |source_url|
3760 // should be eliminated (use last_committed_url() on the RFH instead).
[email protected]d0759f492012-04-19 22:50:503761 if (delegate_)
3762 delegate_->WebUISend(this, source_url, name, args);
3763}
3764
brettw4b461082016-11-19 18:55:163765#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:233766void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
3767 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:093768 for (auto& observer : observers_)
3769 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:233770 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:003771}
3772
nicka0ac8382016-12-15 23:59:233773void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
3774 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:093775 for (auto& observer : observers_)
3776 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:233777 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:003778}
3779
nicka0ac8382016-12-15 23:59:233780void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
3781 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:423782 const base::FilePath& path,
3783 bool is_hung) {
3784 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3785
ericwilligersde386342016-10-19 02:35:093786 for (auto& observer : observers_)
3787 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:423788}
3789
nicka0ac8382016-12-15 23:59:233790void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
3791 int32_t pp_instance) {
3792 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:173793}
3794
nicka0ac8382016-12-15 23:59:233795void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
3796 int32_t pp_instance) {
3797 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:173798}
3799
nicka0ac8382016-12-15 23:59:233800void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
3801 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:423802 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:233803 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
3804 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:093805 for (auto& observer : observers_)
3806 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:423807}
3808
[email protected]d8415ad92012-08-23 14:40:503809void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:233810 RenderViewHostImpl* source,
3811 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:503812 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343813 const base::FilePath& plugin_path) {
nicka0ac8382016-12-15 23:59:233814 base::Callback<void(bool)> permission_result_callback = base::Bind(
3815 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
3816 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:163817 if (!delegate_) {
nicka0ac8382016-12-15 23:59:233818 permission_result_callback.Run(false);
[email protected]8c8fc292012-11-23 18:57:163819 return;
[email protected]d8415ad92012-08-23 14:40:503820 }
3821
nicka0ac8382016-12-15 23:59:233822 if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path,
3823 permission_result_callback)) {
[email protected]8c8fc292012-11-23 18:57:163824 NOTIMPLEMENTED();
nicka0ac8382016-12-15 23:59:233825 permission_result_callback.Run(false);
[email protected]8c8fc292012-11-23 18:57:163826 }
[email protected]d8415ad92012-08-23 14:40:503827}
3828
nicka0ac8382016-12-15 23:59:233829void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
3830 int ppb_broker_route_id,
3831 bool result) {
3832 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
3833 if (rph) {
3834 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
3835 // is not routed to a RenderView.
3836 rph->Send(
3837 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
3838 }
[email protected]d8415ad92012-08-23 14:40:503839}
3840
fsamuel833ee7c2015-02-13 23:40:403841void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3842 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393843 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143844 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403845 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373846}
brettw4b461082016-11-19 18:55:163847#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373848
[email protected]795c28972012-12-06 06:13:393849void WebContentsImpl::OnUpdateFaviconURL(
nicka0ac8382016-12-15 23:59:233850 RenderViewHostImpl* source,
[email protected]795c28972012-12-06 06:13:393851 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063852 // We get updated favicon URLs after the page stops loading. If a cross-site
3853 // navigation occurs while a page is still loading, the initial page
3854 // may stop loading and send us updated favicon URLs after the navigation
3855 // for the new page has committed.
nicka0ac8382016-12-15 23:59:233856 if (!source->is_active())
pkotwiczf9bc20592015-04-21 18:57:063857 return;
3858
ericwilligersde386342016-10-19 02:35:093859 for (auto& observer : observers_)
3860 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:393861}
3862
estark703f1b42016-10-10 21:37:153863void WebContentsImpl::OnPasswordInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023864 controller_.ssl_manager()->DidShowPasswordInputOnHttp();
estark703f1b42016-10-10 21:37:153865}
3866
estarkfae6b5872016-11-04 05:20:313867void WebContentsImpl::OnAllPasswordInputsHiddenOnHttp() {
3868 controller_.ssl_manager()->DidHideAllPasswordInputsOnHttp();
3869}
3870
estark703f1b42016-10-10 21:37:153871void WebContentsImpl::OnCreditCardInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023872 controller_.ssl_manager()->DidShowCreditCardInputOnHttp();
estark703f1b42016-10-10 21:37:153873}
3874
qinmin72e8bd02016-10-21 19:35:373875void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
3876 is_overlay_content_ = is_overlay_content;
3877}
3878
nicka0ac8382016-12-15 23:59:233879void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) {
3880 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
3881 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:093882 for (auto& observer : observers_)
3883 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:283884
peter90afaba2015-06-01 12:05:293885 did_first_visually_non_empty_paint_ = true;
3886
yusufod41c5f92015-03-06 00:14:283887 if (theme_color_ != last_sent_theme_color_) {
3888 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:093889 for (auto& observer : observers_)
3890 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:283891 last_sent_theme_color_ = theme_color_;
3892 }
[email protected]9f268072013-11-07 00:02:153893}
[email protected]d9030b82013-07-19 08:26:063894
[email protected]17e286e2013-03-01 23:29:393895void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:093896 for (auto& observer : observers_)
3897 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:393898}
3899
[email protected]ec6c05f2013-10-23 18:41:573900void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3901 Activate();
3902 if (delegate_)
3903 delegate_->ShowRepostFormWarningDialog(this);
3904}
3905
[email protected]b4c84012014-04-28 19:51:103906bool WebContentsImpl::HasAccessedInitialDocument() {
3907 return has_accessed_initial_document_;
3908}
3909
afakhry6f0c1ec22016-07-14 13:55:133910void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:263911 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323912 // For file URLs without a title, use the pathname instead. In the case of a
3913 // synthesized title, we don't want the update to count toward the "one set
3914 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263915 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323916 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513917 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243918 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323919 explicit_set = false; // Don't count synthetic titles toward the set limit.
3920 } else {
[email protected]8af69c6c2014-03-03 19:05:313921 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323922 explicit_set = true;
3923 }
3924
[email protected]987fc3a2011-05-26 14:18:093925 // If a page is created via window.open and never navigated,
3926 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553927 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093928 if (entry) {
[email protected]36fc0392011-12-25 03:59:513929 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:133930 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323931
[email protected]36fc0392011-12-25 03:59:513932 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093933 } else {
3934 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:133935 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:093936
3937 page_title_when_no_navigation_entry_ = final_title;
3938 }
[email protected]420ae012009-04-24 05:16:323939
[email protected]420ae012009-04-24 05:16:323940 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233941 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323942
ericwilligersde386342016-10-19 02:35:093943 for (auto& observer : observers_)
3944 observer.TitleWasSet(entry, explicit_set);
[email protected]66798902013-10-01 18:40:163945
afakhry6f0c1ec22016-07-14 13:55:133946 // Broadcast notifications when the UI should be updated.
3947 if (entry == controller_.GetEntryAtOffset(0))
3948 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323949}
3950
fdegansa696e5112015-04-17 01:57:593951void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003952 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003953 if (delegate_)
fdegansa696e5112015-04-17 01:57:593954 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003955}
3956
3957void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343958 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003959 loading_weak_factory_.InvalidateWeakPtrs();
3960 loading_last_progress_update_ = base::TimeTicks();
3961}
3962
clamy44e84ce2016-02-22 15:38:253963// Notifies the RenderWidgetHost instance about the fact that the page is
3964// loading, or done loading.
3965void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3966 bool due_to_interstitial,
3967 LoadNotificationDetails* details) {
3968 // Do not send notifications about loading changes in the FrameTree while the
3969 // interstitial page is pausing the throbber.
3970 if (ShowingInterstitialPage() &&
3971 GetRenderManager()->interstitial_page()->pause_throbber() &&
3972 !due_to_interstitial) {
3973 return;
3974 }
3975
3976 bool is_loading = IsLoading();
3977
3978 if (!is_loading) {
3979 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3980 base::string16());
3981 load_state_host_.clear();
3982 upload_size_ = 0;
3983 upload_position_ = 0;
3984 }
3985
3986 GetRenderManager()->SetIsLoading(is_loading);
3987
3988 waiting_for_response_ = is_loading;
3989 is_load_to_different_document_ = to_different_document;
3990
3991 if (delegate_)
3992 delegate_->LoadingStateChanged(this, to_different_document);
3993 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3994
3995 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3996 if (is_loading) {
3997 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3998 this, "URL", url, "Main FrameTreeNode id",
3999 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:094000 for (auto& observer : observers_)
4001 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:254002 } else {
4003 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4004 this, "URL", url);
ericwilligersde386342016-10-19 02:35:094005 for (auto& observer : observers_)
4006 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:254007 }
4008
4009 // TODO(avi): Remove. http://crbug.com/170921
4010 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4011 NotificationDetails det = NotificationService::NoDetails();
4012 if (details)
4013 det = Details<LoadNotificationDetails>(details);
4014 NotificationService::current()->Notify(
4015 type, Source<NavigationController>(&controller_), det);
4016}
4017
[email protected]02d7b6e2014-06-24 21:01:504018void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4019 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324020 // After sending out a swap notification, we need to send a disconnect
4021 // notification so that clients that pick up a pointer to |this| can NULL the
4022 // pointer. See Bug 1230284.
4023 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094024 for (auto& observer : observers_)
4025 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114026
[email protected]7a846df2012-09-20 19:17:394027 // Ensure that the associated embedder gets cleared after a RenderViewHost
4028 // gets swapped, so we don't reuse the same embedder next time a
4029 // RenderViewHost is attached to this WebContents.
4030 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324031}
4032
[email protected]02d7b6e2014-06-24 21:01:504033void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4034 RenderFrameHost* new_host) {
chrishtr95e39532016-11-10 00:05:214035 // Copies the background color from an old WebContents to a new one that
4036 // replaces it on the screen. This allows the new WebContents to use the
4037 // old one's background color as the starting background color, before having
4038 // loaded any contents. As a result, we avoid flashing white when navigating
4039 // from a site whith a dark background to another site with a dark background.
4040 if (old_host && new_host) {
4041 RenderWidgetHostView* old_view = old_host->GetView();
4042 RenderWidgetHostView* new_view = new_host->GetView();
4043 if (old_view && new_view)
4044 new_view->SetBackgroundColor(old_view->background_color());
4045 }
4046
ericwilligersde386342016-10-19 02:35:094047 for (auto& observer : observers_)
4048 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:504049}
4050
[email protected]da7a7182013-09-06 08:11:114051// TODO(avi): Remove this entire function because this notification is already
4052// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264053void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324054 if (!notify_disconnection_)
4055 return;
4056
4057 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214058 NotificationService::current()->Notify(
4059 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4060 Source<WebContents>(this),
4061 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324062}
4063
[email protected]cbb1ef592013-06-05 19:49:464064void WebContentsImpl::NotifyNavigationEntryCommitted(
4065 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:094066 for (auto& observer : observers_)
4067 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:464068}
4069
rockotf62002a2016-09-15 00:08:594070void WebContentsImpl::OnAssociatedInterfaceRequest(
4071 RenderFrameHost* render_frame_host,
4072 const std::string& interface_name,
4073 mojo::ScopedInterfaceEndpointHandle handle) {
4074 auto it = binding_sets_.find(interface_name);
4075 if (it != binding_sets_.end())
4076 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
4077}
4078
[email protected]c31a84802014-04-03 15:55:494079const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
4080 return GetLastCommittedURL();
4081}
4082
[email protected]b849847b2013-12-10 21:57:584083void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094084 for (auto& observer : observers_)
4085 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:134086 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:454087
4088 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
4089 return;
4090
4091 NavigationEntry* entry = controller_.GetPendingEntry();
4092 if (entry && entry->IsViewSourceMode()) {
4093 // Put the renderer in view source mode.
4094 render_frame_host->Send(
4095 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
4096 }
sammc5a139ba2016-09-29 01:49:144097#if defined(OS_ANDROID)
4098 render_frame_host->GetInterfaceRegistry()->AddInterface(
4099 GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>());
4100#endif
[email protected]b849847b2013-12-10 21:57:584101}
4102
4103void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094104 for (auto& observer : observers_)
4105 observer.RenderFrameDeleted(render_frame_host);
zqzhang7b6f4f02016-12-07 22:10:224106#if BUILDFLAG(ENABLE_PLUGINS)
4107 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
4108#endif
[email protected]b849847b2013-12-10 21:57:584109}
4110
[email protected]a09d53ce2014-01-31 00:46:424111void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
4112 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:104113 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:424114 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:104115 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:424116 return;
4117
[email protected]077e704b2014-05-23 19:24:104118 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
4119 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:424120}
4121
[email protected]87de04b02014-04-08 22:14:494122void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:014123 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494124 const base::string16& message,
4125 const base::string16& default_prompt,
4126 const GURL& frame_url,
4127 JavaScriptMessageType javascript_message_type,
4128 IPC::Message* reply_msg) {
4129 // Suppress JavaScript dialogs when requested. Also suppress messages when
4130 // showing an interstitial as it's shown over the previous page and we don't
4131 // want the hidden page's dialogs to interfere with the interstitial.
4132 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:504133 ShowingInterstitialPage() || !delegate_ ||
4134 delegate_->ShouldSuppressDialogs(this) ||
4135 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494136
4137 if (!suppress_this_message) {
avi85ee8362016-10-08 02:09:084138 is_showing_javascript_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504139 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494140 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:034141 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:414142 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014143 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:414144 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:494145 &suppress_this_message);
4146 }
4147
4148 if (suppress_this_message) {
4149 // If we are suppressing messages, just reply as if the user immediately
4150 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:014151 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
4152 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284153 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:494154 }
4155
4156 // OnDialogClosed (two lines up) may have caused deletion of this object (see
4157 // http://crbug.com/288961 ). The only safe thing to do here is return.
4158}
4159
4160void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014161 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494162 bool is_reload,
4163 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014164 RenderFrameHostImpl* rfhi =
4165 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494166 if (delegate_)
4167 delegate_->WillRunBeforeUnloadConfirm();
4168
4169 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454170 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024171 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504172 delegate_->ShouldSuppressDialogs(this) ||
4173 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494174 if (suppress_this_message) {
4175 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4176 return;
4177 }
4178
4179 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504180 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494181 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424182 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494183 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014184 render_frame_host->GetProcess()->GetID(),
4185 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284186 false));
[email protected]87de04b02014-04-08 22:14:494187}
4188
naskoada75b22016-06-11 16:09:464189void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
4190 const FileChooserParams& params) {
4191 if (delegate_)
4192 delegate_->RunFileChooser(render_frame_host, params);
4193}
4194
[email protected]a86c0e962013-12-17 17:10:394195WebContents* WebContentsImpl::GetAsWebContents() {
4196 return this;
4197}
4198
wjmaclean64951902016-04-29 20:59:124199double WebContentsImpl::GetPendingPageZoomLevel() {
4200 NavigationEntry* pending_entry = GetController().GetPendingEntry();
4201 if (!pending_entry)
4202 return HostZoomMap::GetZoomLevel(this);
4203
4204 GURL url = pending_entry->GetURL();
4205 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
4206 url.scheme(), net::GetHostOrSpecFromURL(url));
4207}
4208
qinmin72e8bd02016-10-21 19:35:374209bool WebContentsImpl::HideDownloadUI() const {
4210 return is_overlay_content_;
4211}
4212
ekaramada110f642016-12-21 19:47:284213bool WebContentsImpl::IsFocusedElementEditable() {
4214 RenderFrameHostImpl* frame = GetFocusedFrame();
4215 return frame && frame->has_focused_editable_element();
4216}
4217
4218void WebContentsImpl::ClearFocusedElement() {
4219 if (auto* frame = GetFocusedFrame())
4220 frame->ClearFocusedElement();
4221}
4222
[email protected]7912e822014-04-16 02:37:034223bool WebContentsImpl::IsNeverVisible() {
4224 if (!delegate_)
4225 return false;
4226 return delegate_->IsNeverVisible(this);
4227}
4228
[email protected]5a3bdf52012-05-24 15:12:574229RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4230 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324231}
4232
[email protected]8ff00d72012-10-23 19:12:214233RendererPreferences WebContentsImpl::GetRendererPrefs(
4234 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464235 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514236}
4237
[email protected]7a846df2012-09-20 19:17:394238void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274239 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394240 browser_plugin_embedder_.reset();
4241}
4242
avallee0206f782016-07-28 18:55:334243WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
ekaramad1beabecc2016-09-23 20:18:174244 if (GuestMode::IsCrossProcessFrameGuest(this) && node_)
4245 return node_->outer_web_contents();
4246
4247 if (browser_plugin_guest_)
4248 return browser_plugin_guest_->embedder_web_contents();
4249
avallee0206f782016-07-28 18:55:334250 return nullptr;
4251}
4252
4253WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
4254 // There is no inner or outer web contents.
4255 if (!node_ && !GetBrowserPluginGuest())
4256 return this;
4257
4258 // We may need to create a node_ on the outermost contents in the
4259 // BrowserPlugin case.
4260 WebContentsImpl* outermost = GetOutermostWebContents();
4261 if (!outermost->node_) {
4262 outermost->node_.reset(new WebContentsTreeNode());
4263 outermost->node_->SetFocusedWebContents(outermost);
4264 }
4265 return outermost->node_->focused_web_contents();
4266}
4267
avallee9993fca2016-11-17 06:16:504268bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
4269 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
4270 focused_contents;
4271 focused_contents = focused_contents->GetOuterWebContents()) {
4272 if (focused_contents == this)
4273 return true;
4274 }
4275
4276 return false;
4277}
4278
avallee0206f782016-07-28 18:55:334279WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
4280 WebContentsImpl* root = this;
4281 while (root->GetOuterWebContents())
4282 root = root->GetOuterWebContents();
4283 return root;
4284}
4285
[email protected]b172aee2012-04-10 17:05:264286void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444287 // Don't send notifications if we are just creating a swapped-out RVH for
4288 // the opener chain. These won't be used for view-source or WebUI, so it's
4289 // ok to return early.
creiscce56cd2014-09-29 22:45:224290 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444291 return;
4292
[email protected]86f98a22013-03-20 14:35:004293 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314294 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084295
[email protected]8ff00d72012-10-23 19:12:214296 NotificationService::current()->Notify(
4297 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4298 Source<WebContents>(this),
4299 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324300
[email protected]60780f412013-02-25 16:34:104301 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264302
ericwilligersde386342016-10-19 02:35:094303 for (auto& observer : observers_)
4304 observer.RenderViewCreated(render_view_host);
dgozmanf00c4f72016-10-19 17:45:154305 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:324306}
4307
[email protected]b172aee2012-04-10 17:05:264308void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524309 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324310 // Don't notify the world, since this came from a renderer in the
4311 // background.
4312 return;
4313 }
4314
[email protected]da7a7182013-09-06 08:11:114315 notify_disconnection_ = true;
4316 // TODO(avi): Remove. http://crbug.com/170921
4317 NotificationService::current()->Notify(
4318 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4319 Source<WebContents>(this),
4320 NotificationService::NoDetails());
4321
[email protected]be1f56ab2011-12-22 06:55:314322 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234323 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304324
4325 // Restore the focus to the tab (otherwise the focus will be on the top
4326 // window).
[email protected]484ae5912010-09-29 19:16:144327 if (was_crashed && !FocusLocationBarByDefault() &&
4328 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064329 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144330 }
[email protected]32ded2212011-11-10 18:51:434331
ericwilligersde386342016-10-19 02:35:094332 for (auto& observer : observers_)
4333 observer.RenderViewReady();
[email protected]420ae012009-04-24 05:16:324334}
4335
[email protected]ec6a7eb2013-04-22 17:34:224336void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4337 base::TerminationStatus status,
4338 int error_code) {
[email protected]151a63d2011-12-20 22:32:524339 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324340 // The pending page's RenderViewHost is gone.
4341 return;
4342 }
4343
[email protected]2fcdcc32014-03-05 02:14:074344 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4345 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:154346 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464347 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074348
[email protected]698191dc2014-02-25 01:06:134349 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174350 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134351
[email protected]f738bdcb2014-07-11 20:40:444352 if (delegate_)
4353 delegate_->HideValidationMessage(this);
4354
[email protected]960b0372014-05-19 18:01:004355 // Reset the loading progress. TODO(avi): What does it mean to have a
4356 // "renderer crash" when there is more than one renderer process serving a
4357 // webpage? Once this function is called at a more granular frame level, we
4358 // probably will need to more granularly reset the state here.
4359 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254360 NotifyDisconnected();
4361 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004362
ericwilligersde386342016-10-19 02:35:094363 for (auto& observer : observers_)
4364 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:324365}
4366
[email protected]b172aee2012-04-10 17:05:264367void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:094368 for (auto& observer : observers_)
4369 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:064370}
4371
[email protected]b172aee2012-04-10 17:05:264372void WebContentsImpl::UpdateState(RenderViewHost* rvh,
[email protected]691aa2f2013-05-28 22:52:044373 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384374 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4375
creise1d3e5b2014-12-01 18:21:574376 // Ensure that this state update comes from a RenderViewHost that belongs to
4377 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414378 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574379 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414380 return;
[email protected]420ae012009-04-24 05:16:324381
avi1edc8552016-10-13 21:37:164382 if (!rvh->GetMainFrame()) {
4383 // When UseSubframeNavigationEntries is turned off, state updates only come
4384 // in on main frames. When UseSubframeNavigationEntries is turned on,
4385 // UpdateStateForFrame() should have been called rather than this function.
4386 NOTREACHED();
[email protected]420ae012009-04-24 05:16:324387 return;
nasko346969912015-12-16 22:36:474388 }
creisd63f6c4a2015-11-06 19:05:534389
avi1edc8552016-10-13 21:37:164390 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
4391 static_cast<RenderFrameHostImpl*>(rvh->GetMainFrame())->nav_entry_id());
4392
[email protected]691aa2f2013-05-28 22:52:044393 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324394 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044395 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114396 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324397}
4398
sky8b00392d2015-01-10 00:30:284399void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4400 const GURL& url) {
4401 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4402 // If we're fullscreen only update the url if it's from the fullscreen
4403 // renderer.
4404 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444405 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284406 return;
4407 }
[email protected]6934a702011-12-20 00:04:514408 if (delegate_)
avi450ce00e2014-09-24 01:58:524409 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324410}
4411
[email protected]b172aee2012-04-10 17:05:264412void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104413#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294414 // The UI may be in an event-tracking loop, such as between the
4415 // mouse-down and mouse-up in text selection or a button click.
4416 // Defer the close until after tracking is complete, so that we
4417 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294418 // TODO(shess): This could get more fine-grained. For instance,
4419 // closing a tab in another window while selecting text in the
4420 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104421 if (view_->IsEventTracking()) {
4422 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294423 return;
4424 }
[email protected]60780f412013-02-25 16:34:104425#endif
[email protected]07707302009-11-06 00:50:294426
[email protected]420ae012009-04-24 05:16:324427 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524428 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514429 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324430}
4431
[email protected]b172aee2012-04-10 17:05:264432void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514433 if (delegate_ && delegate_->IsPopupOrPanel(this))
4434 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324435}
4436
fdegansa696e5112015-04-17 01:57:594437void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094438 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254439 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084440
4441 // Notify accessibility that the user is navigating away from the
4442 // current document.
4443 //
4444 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084445 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594446 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084447 if (manager)
4448 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324449}
4450
fdegansc73eec22015-03-19 14:47:544451void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084452 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324453
[email protected]9595fd82013-04-19 21:28:494454 // Use the last committed entry rather than the active one, in case a
4455 // pending entry has been created.
4456 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204457 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494458
[email protected]420ae012009-04-24 05:16:324459 // An entry may not exist for a stop when loading an initial blank page or
4460 // if an iframe injected by script into a blank page finishes loading.
4461 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204462 base::TimeDelta elapsed =
4463 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324464
4465 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514466 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324467 elapsed,
4468 &controller_,
4469 controller_.GetCurrentEntryIndex()));
4470 }
4471
clamy44e84ce2016-02-22 15:38:254472 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324473}
4474
fdegansa696e5112015-04-17 01:57:594475void WebContentsImpl::DidChangeLoadProgress() {
4476 double load_progress = frame_tree_.load_progress();
4477
4478 // The delegate is notified immediately for the first and last updates. Also,
4479 // since the message loop may be pretty busy when a page is loaded, it might
4480 // not execute a posted task in a timely manner so the progress report is sent
4481 // immediately if enough time has passed.
4482 base::TimeDelta min_delay =
4483 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4484 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4485 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4486
4487 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4488 // If there is a pending task to send progress, it is now obsolete.
4489 loading_weak_factory_.InvalidateWeakPtrs();
4490
4491 // Notify the load progress change.
4492 SendChangeLoadProgress();
4493
4494 // Clean-up the states if needed.
4495 if (load_progress == 1.0)
4496 ResetLoadProgressState();
4497 return;
4498 }
4499
4500 if (loading_weak_factory_.HasWeakPtrs())
4501 return;
4502
skyostil95082a62015-06-05 19:53:074503 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4504 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4505 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594506 min_delay);
4507}
4508
clamycbf524d42016-09-27 12:48:354509ScopedVector<NavigationThrottle> WebContentsImpl::CreateThrottlesForNavigation(
4510 NavigationHandle* navigation_handle) {
4511 return GetContentClient()->browser()->CreateThrottlesForNavigation(
4512 navigation_handle);
4513}
4514
clamy1e5574e2016-09-29 16:48:444515std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
4516 NavigationHandle* navigation_handle) {
4517 DCHECK(IsBrowserSideNavigationEnabled());
4518 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
4519}
4520
[email protected]b172aee2012-04-10 17:05:264521void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164522 controller_.DiscardNonCommittedEntries();
4523
4524 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214525 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164526}
4527
[email protected]59167c22013-06-03 18:07:324528void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104529 has_accessed_initial_document_ = true;
4530
[email protected]d1371bf8e2014-04-19 03:26:244531 // We may have left a failed browser-initiated navigation in the address bar
4532 // to let the user edit it and try again. Clear it now that content might
4533 // show up underneath it.
4534 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454535 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244536
[email protected]59167c22013-06-03 18:07:324537 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504538 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324539}
4540
alexmosbe2f4c32015-03-10 02:30:234541void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4542 const std::string& name) {
ericwilligersde386342016-10-19 02:35:094543 for (auto& observer : observers_)
4544 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:234545}
4546
[email protected]39f2f9252014-05-03 00:54:014547void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294548 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:404549 ShowInsecureLocalhostWarningIfNeeded();
4550
ericwilligersde386342016-10-19 02:35:094551 for (auto& observer : observers_)
4552 observer.DocumentOnLoadCompletedInMainFrame();
[email protected]6578fef2013-10-14 02:35:094553
4554 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214555 NotificationService::current()->Notify(
4556 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4557 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294558 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084559}
4560
creis8eb8ef22015-11-04 22:51:384561void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4562 const PageState& page_state) {
4563 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4564
4565 // The state update affects the last NavigationEntry associated with the given
4566 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4567 // in the case of an UpdateState from a frame being swapped out). We track
4568 // which entry this is in the RenderFrameHost's nav_entry_id.
4569 RenderFrameHostImpl* rfhi =
4570 static_cast<RenderFrameHostImpl*>(render_frame_host);
4571 NavigationEntryImpl* entry =
4572 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4573 if (!entry)
4574 return;
4575
4576 FrameNavigationEntry* frame_entry =
4577 entry->GetFrameEntry(rfhi->frame_tree_node());
4578 if (!frame_entry)
4579 return;
4580
creisd06a9422015-11-11 03:08:454581 // The SiteInstance might not match if we do a cross-process navigation with
4582 // replacement (e.g., auto-subframe), in which case the swap out of the old
4583 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4584 // has already been replaced and destroyed.
4585 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4586 return;
4587
creis8eb8ef22015-11-04 22:51:384588 if (page_state == frame_entry->page_state())
4589 return; // Nothing to update.
4590
creisfafed882016-07-29 00:03:094591 if (!page_state.IsValid()) {
4592 // Temporarily generate a minidump to diagnose https://crbug.com/568703.
4593 base::debug::DumpWithoutCrashing();
4594 NOTREACHED() << "Shouldn't set an empty PageState.";
4595 }
nasko34634672016-07-29 18:46:064596
4597 // The document_sequence_number and item_sequence_number recorded in the
4598 // FrameNavigationEntry should not differ from the one coming with the update,
4599 // since it must come from the same document. Do not update it if a difference
4600 // is detected, as this indicates that |frame_entry| is not the correct one.
4601 ExplodedPageState exploded_state;
4602 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
4603 return;
4604
4605 if (exploded_state.top.document_sequence_number !=
4606 frame_entry->document_sequence_number() ||
4607 exploded_state.top.item_sequence_number !=
4608 frame_entry->item_sequence_number()) {
4609 return;
4610 }
4611
nasko04a322f25a2016-09-01 00:00:344612 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:384613 controller_.NotifyEntryChanged(entry);
4614}
4615
[email protected]ef3adfc2014-05-11 00:04:544616void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:544617 const base::string16& title,
4618 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544619 // If we have a title, that's a pretty good indication that we've started
4620 // getting useful data.
4621 SetNotWaitingForResponse();
4622
4623 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584624 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:164625 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:044626 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:544627
4628 // We can handle title updates when we don't have an entry in
4629 // UpdateTitleForEntry, but only if the update is from the current RVH.
4630 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584631 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544632 return;
4633
4634 // TODO(evan): make use of title_direction.
4635 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:134636 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:544637}
4638
4639void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4640 const std::string& encoding) {
4641 SetEncoding(encoding);
4642}
4643
[email protected]39f2f9252014-05-03 00:54:014644void WebContentsImpl::DocumentAvailableInMainFrame(
4645 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:094646 for (auto& observer : observers_)
4647 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:014648}
naskoc0fceff2015-04-30 15:53:524649
[email protected]e1c3a552012-05-04 20:51:324650void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4651 // Tell the active RenderViewHost to run unload handlers and close, as long
4652 // as the request came from a RenderViewHost in the same BrowsingInstance.
4653 // In most cases, we receive this from a swapped out RenderViewHost.
4654 // It is possible to receive it from one that has just been swapped in,
4655 // in which case we might as well deliver the message anyway.
4656 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524657 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324658}
4659
alexmose7da5a12015-04-09 02:22:164660bool WebContentsImpl::ShouldRouteMessageEvent(
4661 RenderFrameHost* target_rfh,
4662 SiteInstance* source_site_instance) const {
4663 // Allow the message if this WebContents is dedicated to a browser plugin
4664 // guest.
[email protected]0eba810b2012-10-18 03:19:364665 // Note: This check means that an embedder could theoretically receive a
4666 // postMessage from anyone (not just its own guests). However, this is
4667 // probably not a risk for apps since other pages won't have references
4668 // to App windows.
alexmose7da5a12015-04-09 02:22:164669 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4670}
[email protected]f546640b2012-05-15 00:03:494671
alexmos58729042015-06-18 23:20:004672void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164673 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4674 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494675
alexmose7da5a12015-04-09 02:22:164676 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144677 // If this message is going to outer WebContents from inner WebContents,
4678 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4679 // already created a RenderFrameProxyHost for that purpose.
4680 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:174681 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:144682 return;
4683 }
4684
lfg812874d2016-02-09 22:26:134685 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064686 // We create a RenderFrameProxyHost for the embedder in the guest's render
4687 // process but we intentionally do not expose the embedder's opener chain
4688 // to it.
4689 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4690 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494691 } else {
alexmos58729042015-06-18 23:20:004692 RenderFrameHostImpl* source_rfhi =
4693 static_cast<RenderFrameHostImpl*>(source_rfh);
4694 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394695 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494696 }
4697 }
[email protected]f546640b2012-05-15 00:03:494698}
4699
avallee9993fca2016-11-17 06:16:504700void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
4701 // Only change focus if we are not currently focused.
4702 WebContentsImpl* old_contents = GetFocusedWebContents();
4703 if (old_contents == this)
4704 return;
4705
4706 // Send a page level blur to the old contents so that it displays inactive UI
4707 // and focus this contents to activate it.
4708 if (old_contents)
4709 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
4710 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
4711 GetOutermostWebContents()->node_->SetFocusedWebContents(this);
4712}
4713
avallee0206f782016-07-28 18:55:334714void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4715 SiteInstance* source) {
avallee9993fca2016-11-17 06:16:504716 // The PDF plugin still runs as a BrowserPlugin and must go through the
4717 // input redirection mechanism. It must not become focused direcly.
ekaramad1beabecc2016-09-23 20:18:174718 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
avallee0206f782016-07-28 18:55:334719 frame_tree_.SetFocusedFrame(node, source);
4720 return;
4721 }
4722
avallee9993fca2016-11-17 06:16:504723 SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:334724
4725 frame_tree_.SetFocusedFrame(node, source);
avallee0206f782016-07-28 18:55:334726}
4727
ekaramada110f642016-12-21 19:47:284728void WebContentsImpl::OnFocusedElementChangedInFrame(
4729 RenderFrameHostImpl* frame,
4730 const gfx::Rect& bounds_in_root_view) {
4731 RenderWidgetHostViewBase* root_view =
4732 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4733 if (!root_view || !frame->GetView())
4734 return;
4735
4736 // Converting to screen coordinates.
4737 gfx::Point origin = bounds_in_root_view.origin();
4738 origin += root_view->GetViewBounds().OffsetFromOrigin();
4739 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
4740
4741 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
4742 bounds_in_screen);
4743
4744 FocusedNodeDetails details = {frame->has_focused_editable_element(),
4745 bounds_in_screen};
4746
4747 // TODO(ekaramad): We should replace this with an observer notification
4748 // (https://crbug.com/675975).
4749 NotificationService::current()->Notify(
4750 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
4751 Source<RenderViewHost>(GetRenderViewHost()),
4752 Details<FocusedNodeDetails>(&details));
4753}
4754
avia90ae4e2016-11-11 20:49:334755bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
4756 const base::string16& message,
4757 int32_t line_no,
4758 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254759 if (!delegate_)
4760 return false;
avia90ae4e2016-11-11 20:49:334761 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
4762 source_id);
[email protected]a796f202012-05-30 14:14:254763}
4764
dominickn9c7ceaa32016-02-27 01:52:534765void WebContentsImpl::OnUserInteraction(
4766 RenderWidgetHostImpl* render_widget_host,
4767 const blink::WebInputEvent::Type type) {
kenrb19221852016-04-29 17:21:404768 // Ignore unless the widget is currently in the frame tree.
4769 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:224770 return;
4771
ericwilligersde386342016-10-19 02:35:094772 for (auto& observer : observers_)
4773 observer.DidGetUserInteraction(type);
dominickn9c7ceaa32016-02-27 01:52:534774
4775 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4776 // Exclude scroll events as user gestures for resource load dispatches.
4777 // rdh is NULL in unittests.
4778 if (rdh && type != blink::WebInputEvent::MouseWheel)
scottmge22a5e52016-06-30 00:36:514779 rdh->OnUserGesture();
dominickn2dd142dd2015-10-29 05:30:504780}
4781
avallee9993fca2016-11-17 06:16:504782void WebContentsImpl::FocusOwningWebContents(
4783 RenderWidgetHostImpl* render_widget_host) {
4784 // The PDF plugin still runs as a BrowserPlugin and must go through the
4785 // input redirection mechanism. It must not become focused direcly.
4786 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
4787 return;
4788
4789 RenderWidgetHostImpl* focused_widget =
4790 GetFocusedRenderWidgetHost(render_widget_host);
4791
4792 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:304793 (!focused_widget ||
4794 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:504795 SetAsFocusedWebContentsIfNecessary();
4796 }
4797}
4798
[email protected]b172aee2012-04-10 17:05:264799void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444800 // Notify observers.
ericwilligersde386342016-10-19 02:35:094801 for (auto& observer : observers_)
4802 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:444803}
4804
avic3aa8422015-11-09 20:57:224805void WebContentsImpl::RendererUnresponsive(
clamy639fdffb2016-07-18 18:13:324806 RenderWidgetHostImpl* render_widget_host,
dtapuskae99ec6e52016-10-18 00:15:424807 RendererUnresponsiveType type) {
ericwilligersde386342016-10-19 02:35:094808 for (auto& observer : observers_)
4809 observer.OnRendererUnresponsive(render_widget_host);
afakhry98241832016-03-11 19:27:474810
[email protected]992db4c2011-05-12 15:37:154811 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224812 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154813 return;
4814
creiscce56cd2014-09-29 22:45:224815 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224816 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584817
[email protected]e5fc1632011-08-08 07:51:534818 // Ignore renderer unresponsive event if debugger is attached to the tab
4819 // since the event may be a result of the renderer sitting on a breakpoint.
4820 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364821 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534822 return;
4823
clamy639fdffb2016-07-18 18:13:324824 // Record histograms about the type of renderer hang.
4825 UMA_HISTOGRAM_ENUMERATION(
4826 "ChildProcess.HangRendererType", type,
dtapuskae99ec6e52016-10-18 00:15:424827 RendererUnresponsiveType::RENDERER_UNRESPONSIVE_MAX);
clamy639fdffb2016-07-18 18:13:324828
metaflow73fc9552016-05-23 18:26:484829 // We might have been waiting for both beforeunload and unload ACK.
4830 // Check if tab is to be unloaded first.
4831 if (rfhi->IsWaitingForUnloadACK()) {
4832 // Hang occurred while firing the unload handler.
[email protected]420ae012009-04-24 05:16:324833 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224834 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324835
[email protected]fa944cb82013-11-15 17:51:214836 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324837 return;
4838
metaflow73fc9552016-05-23 18:26:484839 // If the tab hangs in the unload handler there's really nothing we can do
4840 // to recover. Pretend the unload listeners have all fired and close
[email protected]2e9d79f2013-08-16 05:45:564841 // the tab.
metaflow73fc9552016-05-23 18:26:484842 Close();
4843 return;
4844 }
4845
4846 if (rfhi->is_waiting_for_beforeunload_ack()) {
4847 // If the hang is in the beforeunload handler, pretend the beforeunload
4848 // listeners have all fired and allow the delegate to continue closing;
4849 // the user will not have the option of cancelling the close.
4850 rfhi->SimulateBeforeUnloadAck();
[email protected]420ae012009-04-24 05:16:324851 return;
4852 }
4853
creisc014b402015-04-23 16:41:454854 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474855 return;
4856
dtapuskae99ec6e52016-10-18 00:15:424857 if (delegate_) {
4858 WebContentsUnresponsiveState unresponsive_state;
4859 unresponsive_state.reason = type;
4860 unresponsive_state.outstanding_ack_count =
4861 render_widget_host->in_flight_event_count();
4862 unresponsive_state.outstanding_event_type =
4863 render_widget_host->hang_monitor_event_type();
4864 unresponsive_state.last_event_type = render_widget_host->last_event_type();
4865 delegate_->RendererUnresponsive(this, unresponsive_state);
4866 }
[email protected]420ae012009-04-24 05:16:324867}
4868
avic3aa8422015-11-09 20:57:224869void WebContentsImpl::RendererResponsive(
4870 RenderWidgetHostImpl* render_widget_host) {
4871 if (render_widget_host != GetRenderViewHost()->GetWidget())
4872 return;
4873
[email protected]6934a702011-12-20 00:04:514874 if (delegate_)
4875 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324876}
4877
[email protected]b172aee2012-04-10 17:05:264878void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554879 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324880 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:094881 for (auto& observer : observers_)
4882 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:514883 if (delegate_)
4884 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094885 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324886}
4887
[email protected]58d5cfe2013-07-10 02:40:524888void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544889 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234890 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224891 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544892}
4893
[email protected]b172aee2012-04-10 17:05:264894void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104895 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214896 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264897 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4898 // here during container initialization and normal window size will be set
4899 // later. In case of tab duplication this resizing to 0x0 prevents setting
4900 // normal size later so just ignore it.
4901 if (!size.IsEmpty())
4902 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324903}
4904
[email protected]af905902013-10-01 21:38:514905void WebContentsImpl::CancelModalDialogsForRenderManager() {
4906 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544907 // deferrer would prevent us from swapping out. We also clear the state
4908 // because this is a cross-process navigation, which means that it's a new
4909 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174910 //
4911 // Note that we don't bother telling browser_plugin_embedder_ because the
4912 // cross-process navigation will either destroy the browser plugins or not
4913 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:464914 if (dialog_manager_) {
4915 dialog_manager_->CancelDialogs(this,
4916 false, // suppress_callbacks,
4917 true); // reset_state
4918 }
[email protected]af905902013-10-01 21:38:514919}
4920
[email protected]02d7b6e2014-06-24 21:01:504921void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4922 RenderFrameHost* new_host,
4923 bool is_main_frame) {
4924 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054925 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504926 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084927
[email protected]02d7b6e2014-06-24 21:01:504928 // Make sure the visible RVH reflects the new delegate's preferences.
4929 if (delegate_)
4930 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394931
[email protected]02d7b6e2014-06-24 21:01:504932 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4933 }
4934
4935 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544936}
4937
naskof5940b9f2015-03-02 23:04:054938void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4939 RenderViewHost* old_host,
4940 RenderViewHost* new_host) {
4941 NotifyViewSwapped(old_host, new_host);
4942}
4943
[email protected]b172aee2012-04-10 17:05:264944NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194945 return GetController();
[email protected]3a3d47472010-07-15 21:03:544946}
4947
dcheng59716272016-04-09 05:19:084948std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294949 const GURL& url) {
avie865b1d2016-10-24 19:42:594950 return CreateWebUI(url, std::string());
[email protected]420ae012009-04-24 05:16:324951}
4952
[email protected]10f417c52011-12-28 21:04:234953NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264954 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324955 return controller_.GetLastCommittedEntry();
4956}
4957
lfgbede6392015-09-11 21:54:064958void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4959 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334960 RenderWidgetHostViewBase* rwh_view =
4961 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524962
[email protected]420ae012009-04-24 05:16:324963 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444964 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214965 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064966}
4967
4968bool WebContentsImpl::CreateRenderViewForRenderManager(
4969 RenderViewHost* render_view_host,
4970 int opener_frame_routing_id,
4971 int proxy_routing_id,
4972 const FrameReplicationState& replicated_frame_state) {
4973 TRACE_EVENT0("browser,navigation",
4974 "WebContentsImpl::CreateRenderViewForRenderManager");
4975
lfg9431efd2016-12-14 14:45:264976 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
[email protected]420ae012009-04-24 05:16:324977
lfg9431efd2016-12-14 14:45:264978 // We only create a RWHV for active RenderViewHosts. When an inactive RVH is
4979 // reused, the RWHV is created in RenderFrameHostManager::CommitPending.
4980 if (rvhi->is_active()) {
4981 DCHECK_EQ(MSG_ROUTING_NONE, proxy_routing_id);
4982 CreateRenderWidgetHostViewForRenderManager(render_view_host);
4983 }
4984
4985 if (!rvhi->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4986 replicated_frame_state, created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524987 return false;
[email protected]14392a52012-05-02 20:28:444988 }
[email protected]a4127722011-04-27 23:13:524989
avi2b177592014-12-10 02:08:024990 SetHistoryOffsetAndLengthForView(render_view_host,
4991 controller_.GetLastCommittedEntryIndex(),
4992 controller_.GetEntryCount());
4993
[email protected]a220b5932013-09-21 03:47:444994#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504995 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4996 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444997 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444998 if (rwh_view) {
4999 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
5000 render_widget_host->WasResized();
5001 }
[email protected]f8233cc2011-05-31 20:24:505002#endif
5003
[email protected]420ae012009-04-24 05:16:325004 return true;
5005}
5006
[email protected]82307f6b2014-08-07 03:30:125007bool WebContentsImpl::CreateRenderFrameForRenderManager(
5008 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:045009 int proxy_routing_id,
5010 int opener_routing_id,
japhete6adf142014-10-31 00:01:495011 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:045012 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:435013 TRACE_EVENT0("browser,navigation",
5014 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:125015
5016 RenderFrameHostImpl* rfh =
5017 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:045018 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
5019 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:125020 return false;
5021
5022 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
5023 // RenderFrameHost will have to be associated with the appropriate
5024 // RenderWidgetHostView or a new one should be created here.
5025
5026 return true;
5027}
5028
mfomitchev2b8b066a2016-01-28 19:23:155029#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:455030
[email protected]155c7f22013-12-09 17:07:185031base::android::ScopedJavaLocalRef<jobject>
5032WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:405033 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:565034 return GetWebContentsAndroid()->GetJavaObject();
5035}
[email protected]155c7f22013-12-09 17:07:185036
[email protected]0e813a52014-08-13 10:34:565037WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:185038 WebContentsAndroid* web_contents_android =
5039 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
5040 if (!web_contents_android) {
5041 web_contents_android = new WebContentsAndroid(this);
5042 SetUserData(kWebContentsAndroidKey, web_contents_android);
5043 }
[email protected]0e813a52014-08-13 10:34:565044 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:185045}
5046
paulmeyerc0b762b2016-04-13 11:55:175047void WebContentsImpl::ActivateNearestFindResult(float x,
5048 float y) {
5049 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
5050}
5051
5052void WebContentsImpl::RequestFindMatchRects(int current_version) {
5053 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
5054}
5055
[email protected]7d244f12013-08-22 21:41:515056bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:065057 return CreateRenderViewForRenderManager(
5058 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:065059 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:515060}
[email protected]fc2b46b2014-05-03 16:33:455061
rockot400ea35b2016-10-15 19:15:325062service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:115063 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:325064 service_manager::mojom::InterfaceProviderPtr provider;
blundelle0a9f1582016-12-20 11:23:325065 BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this);
rockot400ea35b2016-10-15 19:15:325066 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:115067 java_interfaces_->Bind(std::move(provider));
5068 }
5069 return java_interfaces_.get();
5070}
5071
[email protected]fc2b46b2014-05-03 16:33:455072#elif defined(OS_MACOSX)
5073
[email protected]75f4df72014-07-16 22:39:425074void WebContentsImpl::SetAllowOtherViews(bool allow) {
5075 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:455076}
5077
[email protected]75f4df72014-07-16 22:39:425078bool WebContentsImpl::GetAllowOtherViews() {
5079 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:455080}
5081
[email protected]7d244f12013-08-22 21:41:515082#endif
5083
pkotwicz75ca8ffd2016-02-16 23:10:195084void WebContentsImpl::OnDidDownloadImage(
5085 const ImageDownloadCallback& callback,
5086 int id,
5087 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:525088 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:185089 const std::vector<SkBitmap>& images,
5090 const std::vector<gfx::Size>& original_image_sizes) {
5091 callback.Run(id, http_status_code, image_url, images, original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:195092}
5093
[email protected]6fba26d2014-04-29 09:38:285094void WebContentsImpl::OnDialogClosed(int render_process_id,
5095 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:265096 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:495097 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:265098 bool success,
[email protected]fcf75d42013-12-03 20:11:265099 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:285100 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
5101 render_frame_id);
[email protected]87de04b02014-04-08 22:14:495102 last_dialog_suppressed_ = dialog_was_suppressed;
5103
[email protected]beb440c2009-11-06 04:08:545104 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:235105 // It is possible for the current RenderFrameHost to have changed in the
5106 // meantime. Do not reset the navigation state in that case.
5107 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:255108 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:235109 controller_.DiscardNonCommittedEntries();
5110 }
[email protected]ec8e8b02013-06-19 04:57:105111
ericwilligersde386342016-10-19 02:35:095112 for (auto& observer : observers_)
5113 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:545114 }
[email protected]87de04b02014-04-08 22:14:495115
avi85ee8362016-10-08 02:09:085116 is_showing_javascript_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:545117 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:285118 if (rfh) {
5119 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
5120 dialog_was_suppressed);
5121 } else {
5122 // Don't leak the sync IPC reply if the RFH or process is gone.
5123 delete reply_msg;
5124 }
[email protected]beb440c2009-11-06 04:08:545125}
5126
[email protected]b172aee2012-04-10 17:05:265127void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:545128 if (encoding == last_reported_encoding_)
5129 return;
5130 last_reported_encoding_ = encoding;
5131
5132 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:125133 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:105134}
[email protected]f45d2a72010-03-08 23:28:355135
[email protected]1ac10dca2013-08-20 20:47:045136bool WebContentsImpl::IsHidden() {
5137 return capturer_count_ == 0 && !should_normally_be_visible_;
5138}
5139
rob97250742015-12-10 17:45:155140int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:145141 if (node_ && node_->outer_web_contents())
5142 return node_->outer_contents_frame_tree_node_id();
5143
nick2482a2d2015-12-18 01:39:375144 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:145145}
5146
ekaramadaeb3c5c2016-11-09 03:22:355147RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
5148 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
5149 fullscreen_widget_routing_id_);
5150}
5151
[email protected]b0936d22013-11-28 06:47:365152RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:215153 return frame_tree_.root()->render_manager();
5154}
5155
[email protected]f8497342013-02-05 22:15:025156BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:395157 return browser_plugin_guest_.get();
5158}
5159
[email protected]738f57a2013-06-29 21:06:545160void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
5161 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:145162 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:545163 browser_plugin_guest_.reset(guest);
5164}
5165
[email protected]f8497342013-02-05 22:15:025166BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:395167 return browser_plugin_embedder_.get();
5168}
[email protected]8ff00d72012-10-23 19:12:215169
fsamuel60b42282015-03-10 03:29:145170void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
5171 if (browser_plugin_embedder_)
5172 return;
5173 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
5174}
5175
[email protected]fc2b46b2014-05-03 16:33:455176gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:215177 gfx::Size size;
5178 if (delegate_)
5179 size = delegate_->GetSizeForNewRenderView(this);
5180 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:455181 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:215182 return size;
5183}
5184
[email protected]ae7eeda2014-07-04 01:53:265185void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095186 for (auto& observer : observers_)
5187 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:555188}
5189
[email protected]222f5822014-02-05 23:40:495190void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
5191 if (!delegate_)
5192 return;
5193 const gfx::Size new_size = GetPreferredSize();
5194 if (new_size != old_size)
5195 delegate_->UpdatePreferredSize(this, new_size);
5196}
5197
avie865b1d2016-10-24 19:42:595198std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(
5199 const GURL& url,
5200 const std::string& frame_name) {
5201 std::unique_ptr<WebUIImpl> web_ui =
5202 base::MakeUnique<WebUIImpl>(this, frame_name);
5203 WebUIController* controller =
5204 WebUIControllerFactoryRegistry::GetInstance()
5205 ->CreateWebUIControllerForURL(web_ui.get(), url);
dbeama1b926a2015-08-31 23:17:515206 if (controller) {
5207 web_ui->AddMessageHandler(new GenericHandler());
5208 web_ui->SetController(controller);
5209 return web_ui;
5210 }
5211
avie865b1d2016-10-24 19:42:595212 return nullptr;
dbeama1b926a2015-08-31 23:17:515213}
5214
paulmeyerc0b762b2016-04-13 11:55:175215FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
5216 // TODO(paulmeyer): This method will need to access (or potentially create)
5217 // the FindRequestManager in the outermost WebContents once find-in-page
5218 // across GuestViews is implemented.
5219 if (!find_request_manager_)
5220 find_request_manager_.reset(new FindRequestManager(this));
5221
5222 return find_request_manager_.get();
5223}
5224
5225void WebContentsImpl::NotifyFindReply(int request_id,
5226 int number_of_matches,
5227 const gfx::Rect& selection_rect,
5228 int active_match_ordinal,
5229 bool final_update) {
paulmeyer60b5d832016-08-31 18:46:345230 if (delegate_ && !is_being_destroyed_) {
paulmeyerc0b762b2016-04-13 11:55:175231 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
5232 active_match_ordinal, final_update);
5233 }
5234}
5235
ortuno467e5792016-06-10 04:32:395236void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
5237 // Trying to invalidate the tab state while being destroyed could result in a
5238 // use after free.
5239 if (IsBeingDestroyed()) {
5240 return;
5241 }
5242 // Notify for UI updates if the state changes.
5243 bluetooth_connected_device_count_++;
5244 if (bluetooth_connected_device_count_ == 1) {
5245 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5246 }
5247}
5248
5249void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
5250 // Trying to invalidate the tab state while being destroyed could result in a
5251 // use after free.
5252 if (IsBeingDestroyed()) {
5253 return;
5254 }
5255 // Notify for UI updates if the state changes.
5256 DCHECK(bluetooth_connected_device_count_ != 0);
5257 bluetooth_connected_device_count_--;
5258 if (bluetooth_connected_device_count_ == 0) {
5259 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5260 }
5261}
5262
paulmeyerc0b762b2016-04-13 11:55:175263#if defined(OS_ANDROID)
5264void WebContentsImpl::NotifyFindMatchRectsReply(
5265 int version,
5266 const std::vector<gfx::RectF>& rects,
5267 const gfx::RectF& active_rect) {
5268 if (delegate_)
5269 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
5270}
5271#endif
5272
[email protected]34ff1cfc2014-08-20 06:16:055273void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
5274 force_disable_overscroll_content_ = force_disable;
5275 if (view_)
5276 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
5277}
5278
dalecurtis88c240072015-12-09 02:11:185279void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:045280 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185281 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045282 if (media_info.has_video)
5283 currently_playing_video_count_++;
5284
ericwilligersde386342016-10-19 02:35:095285 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045286 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:185287}
5288
5289void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:045290 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185291 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045292 if (media_info.has_video)
5293 currently_playing_video_count_--;
5294
ericwilligersde386342016-10-19 02:35:095295 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045296 observer.MediaStoppedPlaying(media_info, id);
5297}
5298
5299int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
5300 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:185301}
5302
tapted65ff2ea72016-03-01 23:39:005303void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
5304 if (!did_first_set_visible_) {
5305 // If this WebContents has not yet been set to be visible for the first
5306 // time, ignore any requests to make it hidden, since resources would
5307 // immediately be destroyed and only re-created after content loaded. In
5308 // this state the window content is undefined and can show garbage.
5309 // However, the page load mechanism requires an activation call through a
5310 // visibility call to (re)load.
5311 if (visible) {
5312 did_first_set_visible_ = true;
5313 WasShown();
5314 }
5315 return;
5316 }
5317 if (visible == should_normally_be_visible_)
5318 return;
5319
5320 if (visible)
5321 WasShown();
5322 else
5323 WasHidden();
5324}
5325
aelias5252baa2016-04-10 01:18:025326void WebContentsImpl::UpdateOverridingUserAgent() {
5327 std::set<RenderViewHost*> render_view_host_set;
5328 for (FrameTreeNode* node : frame_tree_.Nodes()) {
5329 RenderWidgetHost* render_widget_host =
5330 node->current_frame_host()->GetRenderWidgetHost();
5331 if (!render_widget_host)
5332 continue;
5333 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5334 if (!render_view_host)
5335 continue;
5336 render_view_host_set.insert(render_view_host);
5337 }
5338 for (RenderViewHost* render_view_host : render_view_host_set)
5339 render_view_host->OnWebkitPreferencesChanged();
5340}
5341
avid53461d2016-02-25 17:15:045342void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5343 JavaScriptDialogManager* dialog_manager) {
5344 dialog_manager_ = dialog_manager;
5345}
5346
rockotf62002a2016-09-15 00:08:595347void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
5348 auto it = binding_sets_.find(interface_name);
5349 if (it != binding_sets_.end())
5350 binding_sets_.erase(it);
5351}
5352
nzolghadrd87a308d2016-12-07 15:45:565353bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
5354 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
5355 GetLastCommittedURL()));
5356
5357 return true;
5358}
5359
ekaramada110f642016-12-21 19:47:285360void WebContentsImpl::FocusedNodeTouched(bool editable) {
5361#if defined(OS_WIN)
5362 // We use the cursor position to determine where the touch occurred.
5363 RenderWidgetHostView* view = GetRenderWidgetHostView();
5364 if (!view)
5365 return;
5366 POINT cursor_pos = {};
5367 ::GetCursorPos(&cursor_pos);
5368 float scale = GetScaleFactorForView(view);
5369 gfx::Point location_dips_screen =
5370 gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos));
5371 view->FocusedNodeTouched(location_dips_screen, editable);
5372#endif
5373}
5374
falken52a56e32016-12-08 05:02:405375void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
5376 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
5377 switches::kAllowInsecureLocalhost);
5378 if (!allow_localhost)
5379 return;
5380
5381 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
5382 if (!entry || !net::IsLocalhost(entry->GetURL().host()))
5383 return;
5384
5385 content::SSLStatus ssl_status = entry->GetSSL();
5386 bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) &&
5387 !net::IsCertStatusMinorError(ssl_status.cert_status);
5388 if (!is_cert_error)
5389 return;
5390
5391 GetMainFrame()->AddMessageToConsole(
5392 content::CONSOLE_MESSAGE_LEVEL_WARNING,
5393 base::StringPrintf("This site does not have a valid SSL "
5394 "certificate! Without SSL, your site's and "
5395 "visitors' data is vulnerable to theft and "
5396 "tampering. Get a valid SSL certificate before"
5397 " releasing your website to the public."));
5398}
5399
[email protected]8ff00d72012-10-23 19:12:215400} // namespace content