blob: b22bfdaa29fea8982f715fce1d99644b77d2ee72 [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"
dmazzonid95ae842016-04-12 21:17:3919#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4320#include "base/metrics/histogram_macros.h"
[email protected]04cbd3d2013-12-04 04:58:2021#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2222#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0723#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5124#include "base/strings/string16.h"
25#include "base/strings/string_number_conversions.h"
26#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0027#include "base/strings/utf_string_conversions.h"
gab30f26df2016-05-11 19:37:5528#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3729#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4230#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1031#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2532#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2133#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3034#include "content/browser/accessibility/accessibility_mode_helper.h"
35#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1836#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3937#include "content/browser/browser_plugin/browser_plugin_embedder.h"
38#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5939#include "content/browser/child_process_security_policy_impl.h"
dgozmanf00c4f72016-10-19 17:45:1540#include "content/browser/devtools/render_frame_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4141#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0442#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4643#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1244#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1645#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1746#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1647#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3848#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4049#include "content/browser/frame_host/interstitial_page_impl.h"
50#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3351#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0152#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1853#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0754#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1655#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0556#include "content/browser/host_zoom_map_impl.h"
scottmg276753cf2016-10-27 18:25:2257#include "content/browser/host_zoom_map_observer.h"
csharrison2e8c98e2016-08-01 23:56:2558#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4459#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4060#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3061#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5262#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1863#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4564#include "content/browser/media/session/media_session_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5365#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0966#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3067#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5068#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3269#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5070#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5971#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4872#include "content/browser/renderer_host/render_widget_host_view_base.h"
ekaramadadd882292016-06-08 15:22:5673#include "content/browser/renderer_host/text_input_manager.h"
lunalud4a2cc82016-11-22 00:27:2374#include "content/browser/screen_orientation/screen_orientation.h"
[email protected]b6583592012-01-25 19:52:3375#include "content/browser/site_instance_impl.h"
lfgc740d4b22016-04-15 16:45:3376#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1177#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5878#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0379#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5680#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1481#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4282#include "content/common/browser_plugin/browser_plugin_messages.h"
Paul Meyer0c58c3712016-11-17 22:59:5183#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4484#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1785#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0786#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0687#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1888#include "content/common/render_message_filter.mojom.h"
avi286019ce2015-07-29 01:26:5889#include "content/common/site_isolation_policy.h"
[email protected]2c5569662011-03-22 20:45:0290#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3691#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1192#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2893#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4494#include "content/public/browser/content_browser_client.h"
[email protected]e582fdd2011-12-20 16:48:1795#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1496#include "content/public/browser/download_url_parameters.h"
ekaramad1beabecc2016-09-23 20:18:1797#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:4698#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1599#include "content/public/browser/javascript_dialog_manager.h"
[email protected]09d31d52012-03-11 22:30:27100#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00101#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37102#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14103#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08104#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30105#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32106#include "content/public/browser/resource_request_details.h"
lunalud4a2cc82016-11-22 00:27:23107#include "content/public/browser/screen_orientation_provider.h"
estark5ea80e52015-06-19 18:43:12108#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34109#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38110#include "content/public/browser/user_metrics.h"
rockotf62002a2016-09-15 00:08:59111#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42112#include "content/public/browser/web_contents_delegate.h"
dtapuskae99ec6e52016-10-18 00:15:42113#include "content/public/browser/web_contents_unresponsive_state.h"
[email protected]e091df82011-10-11 18:13:21114#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35115#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37116#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48117#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54118#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49119#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20120#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:03121#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57122#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05123#include "content/public/common/web_preferences.h"
mcasas4e216e72016-07-28 21:28:38124#include "device/geolocation/geolocation_service_context.h"
sammc5a139ba2016-09-29 01:49:14125#include "device/nfc/nfc.mojom.h"
blundelld46e8832016-10-07 10:34:27126#include "device/wake_lock/wake_lock_service_context.h"
wjmaclean64951902016-04-29 20:59:12127#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53128#include "net/http/http_cache.h"
129#include "net/http/http_transaction_factory.h"
130#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34131#include "net/url_request/url_request_context_getter.h"
brettw4b461082016-11-19 18:55:16132#include "ppapi/features/features.h"
rockot734fb662016-10-15 16:41:30133#include "services/service_manager/public/cpp/interface_provider.h"
estark47ba9c7d2016-10-11 15:40:11134#include "third_party/WebKit/public/platform/WebSecurityStyle.h"
alexmosaedfc6f2016-01-21 23:57:38135#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40136#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39137#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56138#include "ui/base/layout.h"
chongz4a9751942016-08-17 17:49:39139#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52140#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31141
[email protected]583418cc2013-01-17 14:01:10142#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40143#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15144#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11145#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46146#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18147#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15148#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10149
[email protected]f66df822012-05-18 16:52:17150#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50151#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57152#endif
[email protected]3e45ba92009-02-20 21:09:00153
sadrul943e3b32016-08-04 18:22:59154#if defined(USE_AURA)
fsamuel9cf7bdf2015-11-20 02:19:32155#include "content/browser/web_contents/web_contents_view_mus.h"
bend32292b2016-10-07 00:21:58156#include "content/public/common/service_manager_connection.h"
fsamuel6c6da0232015-11-26 05:13:46157#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32158#endif
159
brettw4b461082016-11-19 18:55:16160#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17161#include "content/browser/media/session/pepper_playback_observer.h"
162#endif // ENABLE_PLUGINS
163
[email protected]8ff00d72012-10-23 19:12:21164namespace content {
[email protected]420ae012009-04-24 05:16:32165namespace {
166
[email protected]960b0372014-05-19 18:01:00167const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]155c7f22013-12-09 17:07:18170#if defined(OS_ANDROID)
171const char kWebContentsAndroidKey[] = "web_contents_android";
172#endif // OS_ANDROID
173
[email protected]e4abd3b42013-11-12 18:28:47174base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46175g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
176
[email protected]8bfc8272013-09-09 20:10:53177void NotifyCacheOnIO(
178 scoped_refptr<net::URLRequestContextGetter> request_context,
179 const GURL& url,
180 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58181 net::HttpCache* cache = request_context->GetURLRequestContext()->
182 http_transaction_factory()->GetCache();
183 if (cache)
184 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53185}
186
dcheng57e39e22016-01-21 00:25:38187bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
188 for (FrameTreeNode* node : tree->Nodes()) {
189 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
190 return true;
alexmos4cf2aa32015-07-15 23:40:43191 }
dcheng57e39e22016-01-21 00:25:38192 return false;
[email protected]95640212014-07-26 18:14:30193}
194
kenrb19221852016-04-29 17:21:40195bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
196 // This method scans the frame tree rather than checking whether
197 // host->delegate() == this, which allows it to return false when the host
198 // for a frame that is pending or pending deletion.
199 if (!host)
200 return false;
201
202 for (FrameTreeNode* node : tree->Nodes()) {
203 if (node->current_frame_host()->GetRenderWidgetHost() == host)
204 return true;
205 }
206 return false;
207}
208
[email protected]95640212014-07-26 18:14:30209void SetAccessibilityModeOnFrame(AccessibilityMode mode,
210 RenderFrameHost* frame_host) {
211 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
212}
213
dtseng0dd3fa12015-07-22 19:00:52214void ResetAccessibility(RenderFrameHost* rfh) {
215 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
216}
217
dmazzonid95ae842016-04-12 21:17:39218using AXTreeSnapshotCallback =
219 base::Callback<void(const ui::AXTreeUpdate&)>;
220
221// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
222// Handles the callbacks from parallel snapshot requests to each frame,
223// and feeds the results to an AXTreeCombiner, which converts them into a
224// single combined accessibility tree.
225class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
226 public:
227 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
228 : callback_(callback) {
229 }
230
231 AXTreeSnapshotCallback AddFrame(bool is_root) {
232 // Adds a reference to |this|.
233 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
234 this,
235 is_root);
236 }
237
238 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
239 combiner_.AddTree(snapshot, is_root);
240 }
241
242 private:
243 friend class base::RefCounted<AXTreeSnapshotCombiner>;
244
245 // This is called automatically after the last call to ReceiveSnapshot
246 // when there are no more references to this object.
247 ~AXTreeSnapshotCombiner() {
248 combiner_.Combine();
249 callback_.Run(combiner_.combined());
250 }
251
252 ui::AXTreeCombiner combiner_;
253 AXTreeSnapshotCallback callback_;
254};
255
[email protected]420ae012009-04-24 05:16:32256} // namespace
257
[email protected]54944cde2012-12-09 09:24:59258WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21259 FrameTreeNode* opener_node = nullptr;
260 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
261 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
262 params.opener_render_process_id, params.opener_render_frame_id);
263 if (opener_rfh)
264 opener_node = opener_rfh->frame_tree_node();
265 }
266 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19267}
268
269WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59270 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30271 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21272 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30273
274 for (SessionStorageNamespaceMap::const_iterator it =
275 session_storage_namespace_map.begin();
276 it != session_storage_namespace_map.end();
277 ++it) {
278 new_contents->GetController()
279 .SetSessionStorageNamespace(it->first, it->second.get());
280 }
281
[email protected]54944cde2012-12-09 09:24:59282 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19283 return new_contents;
[email protected]a81343d232011-12-27 07:39:20284}
[email protected]746d3052012-05-22 15:15:47285
nickf9acfbe2014-12-23 19:12:37286void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
287 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46288 g_created_callbacks.Get().push_back(callback);
289}
290
nickf9acfbe2014-12-23 19:12:37291void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
292 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46293 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
294 if (g_created_callbacks.Get().at(i).Equals(callback)) {
295 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
296 return;
297 }
298 }
299}
300
avidf38c952015-10-27 13:45:13301WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
302 if (!rvh)
303 return nullptr;
[email protected]746d3052012-05-22 15:15:47304 return rvh->GetDelegate()->GetAsWebContents();
305}
306
[email protected]a86c0e962013-12-17 17:10:39307WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13308 if (!rfh)
309 return nullptr;
310 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39311}
312
ananta4b7467a52016-09-23 01:42:38313WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
314 FrameTreeNode* frame_tree_node =
315 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19316 if (!frame_tree_node)
317 return nullptr;
ananta4b7467a52016-09-23 01:42:38318 return FromRenderFrameHost(frame_tree_node->current_frame_host());
319}
320
[email protected]7fff43e2013-05-21 20:21:10321// WebContentsImpl::DestructionObserver ----------------------------------------
322
323class WebContentsImpl::DestructionObserver : public WebContentsObserver {
324 public:
325 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
326 : WebContentsObserver(watched_contents),
327 owner_(owner) {
328 }
329
330 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58331 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58332 owner_->OnWebContentsDestroyed(
333 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10334 }
335
336 private:
337 WebContentsImpl* owner_;
338
339 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
340};
341
[email protected]8ed16472014-04-11 19:02:48342WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
343 int render_frame_id,
344 ColorChooser* chooser,
345 int identifier)
346 : render_process_id(render_process_id),
347 render_frame_id(render_frame_id),
348 chooser(chooser),
349 identifier(identifier) {
350}
351
352WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
353}
354
lazyboy6ec48b2a2015-06-29 15:18:14355// WebContentsImpl::WebContentsTreeNode ----------------------------------------
356WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
357 : outer_web_contents_(nullptr),
358 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33359 FrameTreeNode::kFrameTreeNodeInvalidId),
360 focused_web_contents_(nullptr) {}
lazyboy6ec48b2a2015-06-29 15:18:14361
362WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
363 // Remove child pointer from our parent.
364 if (outer_web_contents_) {
365 ChildrenSet& child_ptrs_in_parent =
366 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
367 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
368 DCHECK(iter != child_ptrs_in_parent.end());
avallee0206f782016-07-28 18:55:33369 child_ptrs_in_parent.erase(iter);
lazyboy6ec48b2a2015-06-29 15:18:14370 }
371
372 // Remove parent pointers from our children.
373 // TODO(lazyboy): We should destroy the children WebContentses too. If the
374 // children do not manage their own lifetime, then we would leak their
375 // WebContentses.
376 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
377 child->outer_web_contents_ = nullptr;
378}
379
380void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
381 WebContentsImpl* outer_web_contents,
382 RenderFrameHostImpl* outer_contents_frame) {
avallee0206f782016-07-28 18:55:33383 DCHECK(!focused_web_contents_) << "Should not attach a root node.";
lazyboy6ec48b2a2015-06-29 15:18:14384 outer_web_contents_ = outer_web_contents;
385 outer_contents_frame_tree_node_id_ =
386 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
387
avallee0206f782016-07-28 18:55:33388 if (!outer_web_contents_->node_) {
389 // This will only be reached when creating a new WebContents tree.
390 // Initialize the root of this tree and set it as focused.
lazyboy6ec48b2a2015-06-29 15:18:14391 outer_web_contents_->node_.reset(new WebContentsTreeNode());
avallee0206f782016-07-28 18:55:33392 outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_);
393 }
lazyboy6ec48b2a2015-06-29 15:18:14394
395 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
396}
397
avallee0206f782016-07-28 18:55:33398void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
399 WebContentsImpl* web_contents) {
400 DCHECK(!outer_web_contents())
401 << "Only the outermost WebContents tracks focus.";
402 focused_web_contents_ = web_contents;
403}
404
[email protected]b172aee2012-04-10 17:05:26405// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32406
alexmose201c7cd2015-06-10 17:14:21407WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42408 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22409 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57410 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21411 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01412 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57413 this,
414 this,
415 this,
416 this),
[email protected]6dfed692014-05-22 04:18:03417 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23418 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
419 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34420 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26421 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56422 upload_size_(0),
423 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16424 is_resume_pending_(false),
[email protected]b4c84012014-04-28 19:51:10425 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28426 theme_color_(SK_ColorTRANSPARENT),
427 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29428 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55429 capturer_count_(0),
430 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00431 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57432 is_being_destroyed_(false),
433 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15434 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01435 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39436 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38437 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21438 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
439 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22440 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44441 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55442 render_frame_message_source_(NULL),
alexmosc9e76ec2016-05-16 22:59:37443 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42444 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03445 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49446 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05447 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30448 last_dialog_suppressed_(false),
mcasas4e216e72016-07-28 21:28:38449 geolocation_service_context_(new device::GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48450 accessibility_mode_(
451 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15452 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35453 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50454 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46455 page_scale_factor_is_one_(true),
lfgbee1e0a2016-06-08 21:24:21456 mouse_lock_widget_(nullptr),
qinmin72e8bd02016-10-21 19:35:37457 is_overlay_content_(false),
pkotwicz75ca8ffd2016-02-16 23:10:19458 loading_weak_factory_(this),
459 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55460 frame_tree_.SetFrameRemoveListener(
461 base::Bind(&WebContentsImpl::OnFrameRemoved,
462 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46463#if defined(OS_ANDROID)
464 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
465#else
qinmin58567c82015-01-07 21:00:20466 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46467#endif
brettw4b461082016-11-19 18:55:16468#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17469 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
470#endif
csharrisona2280cd2016-02-03 23:21:15471 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
blundelld46e8832016-10-07 10:34:27472 wake_lock_service_context_.reset(new device::WakeLockServiceContext(
blundellebd75172016-10-03 10:41:43473 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
474 base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this))));
scottmg276753cf2016-10-27 18:25:22475 host_zoom_map_observer_.reset(new HostZoomMapObserver(this));
[email protected]332af7732009-03-11 13:21:35476}
initial.commit09911bf2008-07-26 23:55:29477
[email protected]b172aee2012-04-10 17:05:26478WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32479 is_being_destroyed_ = true;
480
kenrb2a565f82015-09-02 20:24:59481 rwh_input_event_router_.reset();
482
rockotf62002a2016-09-15 00:08:59483 for (auto& entry : binding_sets_)
484 entry.second->CloseAllBindings();
485
avallee0206f782016-07-28 18:55:33486 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50487 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33488 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50489 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33490 }
491
dcheng72be33c2016-01-21 04:11:31492 for (FrameTreeNode* node : frame_tree_.Nodes()) {
493 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
494 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38495 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38496 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31497 }
carlosk35f35af2015-12-01 10:55:40498
dcheng57e39e22016-01-21 00:25:38499 for (RenderWidgetHostImpl* widget : created_widgets_)
500 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26501 created_widgets_.clear();
502
[email protected]3ab9cb82011-06-03 18:02:07503 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46504 if (dialog_manager_) {
505 // This object is being destructed, so make sure that no callbacks happen.
506 dialog_manager_->CancelDialogs(this,
507 true, // suppress_callbacks,
508 true); // reset_state
509 }
[email protected]3ab9cb82011-06-03 18:02:07510
[email protected]8ed16472014-04-11 19:02:48511 if (color_chooser_info_.get())
512 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20513
[email protected]420ae012009-04-24 05:16:32514 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32515
[email protected]ca13a442012-04-17 14:00:12516 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21517 NotificationService::current()->Notify(
518 NOTIFICATION_WEB_CONTENTS_DESTROYED,
519 Source<WebContents>(this),
520 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32521
[email protected]df0c843f2014-05-23 20:37:23522 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14523 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23524 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59525
clamy0e119882015-07-31 16:12:33526 // Manually call the observer methods for the root frame tree node. It is
527 // necessary to manually delete all objects tracking navigations
528 // (NavigationHandle, NavigationRequest) for observers to be properly
529 // notified of these navigations stopping before the WebContents is
530 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23531 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56532
clamy0e119882015-07-31 16:12:33533 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56534 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33535 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08536 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33537 }
naskob21fe4872015-02-24 14:15:56538 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33539 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08540 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33541
542 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35543 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41544 // Do not update state as the WebContents is being destroyed.
545 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33546 if (root->speculative_frame_host()) {
547 root->speculative_frame_host()->SetRenderFrameCreated(false);
548 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08549 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33550 }
551 }
[email protected]f273ee52013-10-18 16:05:27552
brettw4b461082016-11-19 18:55:16553#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17554 // Call this before WebContentsDestroyed() is broadcasted since
555 // AudioFocusManager will be destroyed after that.
556 pepper_playback_observer_.reset();
557#endif // defined(ENABLED_PLUGINS)
558
ericwilligersde386342016-10-19 02:35:09559 for (auto& observer : observers_)
560 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10561
[email protected]df0c843f2014-05-23 20:37:23562 if (root->pending_render_view_host()) {
ericwilligersde386342016-10-19 02:35:09563 for (auto& observer : observers_)
564 observer.RenderViewDeleted(root->pending_render_view_host());
[email protected]df0c843f2014-05-23 20:37:23565 }
[email protected]c06c58c2014-03-12 20:31:59566
ericwilligersde386342016-10-19 02:35:09567 for (auto& observer : observers_)
568 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27569
ericwilligersde386342016-10-19 02:35:09570 for (auto& observer : observers_)
571 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58572
ericwilligersde386342016-10-19 02:35:09573 for (auto& observer : observers_)
574 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08575
[email protected]6934a702011-12-20 00:04:51576 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42577}
578
[email protected]d1198fd2012-08-13 22:50:19579WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59580 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21581 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03582 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21583 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19584
alexmosaedfc6f2016-01-21 23:57:38585 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
586
alexmose201c7cd2015-06-10 17:14:21587 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38588 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21589 new_contents->created_with_opener_ = true;
590 }
591
alexmosaedfc6f2016-01-21 23:57:38592 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
593 // flags, and these flags take effect immediately. An exception is if the
594 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
595 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
596 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
597 if (opener) {
598 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
599 const blink::WebSandboxFlags inherit_flag =
600 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
601 if ((opener_flags & inherit_flag) == inherit_flag) {
602 new_root->SetPendingSandboxFlags(opener_flags);
603 new_root->CommitPendingSandboxFlags();
604 }
605 }
606
alexmose201c7cd2015-06-10 17:14:21607 // This may be true even when opener is null, such as when opening blocked
608 // popups.
alexmos090fae8e2015-05-28 17:09:28609 if (params.created_with_opener)
610 new_contents->created_with_opener_ = true;
611
[email protected]4858e432014-06-23 18:14:17612 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06613 // This makes |new_contents| act as a guest.
614 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16615 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06616 // We are instantiating a WebContents for browser plugin. Set its subframe
617 // bit to true.
618 new_contents->is_subframe_ = true;
619 }
[email protected]54944cde2012-12-09 09:24:59620 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19621 return new_contents;
622}
623
[email protected]95640212014-07-26 18:14:30624// static
625std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
626 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08627 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30628 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30629 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30630 RenderViewHost* rvh = RenderViewHost::From(rwh);
631 if (!rvh)
632 continue;
633 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
634 if (!web_contents)
635 continue;
avidf38c952015-10-27 13:45:13636 if (web_contents->GetRenderViewHost() != rvh)
637 continue;
638 // Because a WebContents can only have one current RVH at a time, there will
639 // be no duplicate WebContents here.
640 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30641 }
642 return result;
643}
644
clamya16aa8172015-05-26 13:07:25645// static
646WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
647 FrameTreeNode* frame_tree_node) {
648 return static_cast<WebContentsImpl*>(
649 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
650}
651
clamy0d32d6d2015-11-24 11:16:26652// static
653WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
654 int render_frame_host_id) {
655 DCHECK_CURRENTLY_ON(BrowserThread::UI);
656 RenderFrameHost* render_frame_host =
657 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
658 if (!render_frame_host)
659 return nullptr;
660
661 return WebContents::FromRenderFrameHost(render_frame_host);
662}
663
[email protected]b0936d22013-11-28 06:47:36664RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21665 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28666}
667
[email protected]7bb761892012-07-20 09:32:47668bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
669 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44670 return OnMessageReceived(render_view_host, NULL, message);
671}
672
673bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
674 RenderFrameHost* render_frame_host,
675 const IPC::Message& message) {
676 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56677 if (GetWebUI() &&
678 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17679 return true;
[email protected]d2353452012-01-19 19:53:56680 }
[email protected]f82d57b52011-04-27 19:13:17681
[email protected]64ffefa2014-05-10 12:06:33682 if (render_frame_host) {
dchenga2d442c22016-10-13 15:39:21683 for (auto& observer : observers_) {
684 if (observer.OnMessageReceived(message, render_frame_host))
[email protected]64ffefa2014-05-10 12:06:33685 return true;
dchenga2d442c22016-10-13 15:39:21686 }
[email protected]64ffefa2014-05-10 12:06:33687 } else {
dchenga2d442c22016-10-13 15:39:21688 for (auto& observer : observers_) {
689 if (observer.OnMessageReceived(message))
[email protected]64ffefa2014-05-10 12:06:33690 return true;
dchenga2d442c22016-10-13 15:39:21691 }
[email protected]64ffefa2014-05-10 12:06:33692 }
[email protected]403415a2011-01-10 18:57:53693
[email protected]1d62cf72014-02-07 21:31:57694 // Message handlers should be aware of which
695 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
696 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02697 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57698 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02699 else
[email protected]1d62cf72014-02-07 21:31:57700 render_view_message_source_ = render_view_host;
701
[email protected]724159a2010-12-30 01:11:18702 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33703 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40704 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
705 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05706 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
707 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48708 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
709 OnDocumentLoadedInFrame)
710 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
711 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
712 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
713 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
714 OnSetSelectedColorInColorChooser)
dglazkov79c426102015-08-31 21:22:43715 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11716 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25717 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18718 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54719 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18720 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54721 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18722 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41723 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
724 OnDidDisplayContentWithCertificateErrors)
725 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
726 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25727 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26728 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46729 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
730 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21731 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48732 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
733 OnRegisterProtocolHandler)
734 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
735 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01736 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
737 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52738 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10739 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50740 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
brettw4b461082016-11-19 18:55:16741#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00742 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
743 OnPepperInstanceCreated)
744 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
745 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42746 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17747 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
748 OnPepperStartsPlayback)
749 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
750 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42751 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50752 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
753 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55754 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40755 OnBrowserPluginMessage(render_frame_host,
756 message))
thestigc4cac8f2014-09-04 21:17:50757#endif
[email protected]41225fe2013-03-29 05:32:02758 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07759 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
760 OnShowValidationMessage)
761 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
762 OnHideValidationMessage)
763 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
764 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15765#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52766 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48767 OnFindMatchRectsReply)
paulmeyerc8cb7cb2016-06-07 01:14:19768 IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply,
769 OnGetNearestFindResultReply)
[email protected]8ed16472014-04-11 19:02:48770 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
771 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48772#endif
[email protected]724159a2010-12-30 01:11:18773 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33774 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44775 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57776 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18777
[email protected]724159a2010-12-30 01:11:18778 return handled;
779}
780
nasko907fcb62015-01-28 04:24:11781bool WebContentsImpl::HasValidFrameSource() {
782 if (!render_frame_message_source_) {
783 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18784 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
785 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11786 return false;
787 }
788
789 return true;
790}
791
[email protected]d1198fd2012-08-13 22:50:19792NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56793 return controller_;
794}
795
[email protected]d1198fd2012-08-13 22:50:19796const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56797 return controller_;
798}
799
[email protected]8ff00d72012-10-23 19:12:21800BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55801 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30802}
803
[email protected]b172aee2012-04-10 17:05:26804const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24805 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32806 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51807 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31808}
809
[email protected]a093ce02013-07-22 20:53:14810const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24811 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32812 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24813 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
814}
815
816const GURL& WebContentsImpl::GetLastCommittedURL() const {
817 // We may not have a navigation entry yet.
818 NavigationEntry* entry = controller_.GetLastCommittedEntry();
819 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
820}
821
[email protected]8ff00d72012-10-23 19:12:21822WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31823 return delegate_;
824}
825
[email protected]8ff00d72012-10-23 19:12:21826void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31827 // TODO(cbentzel): remove this debugging code?
828 if (delegate == delegate_)
829 return;
830 if (delegate_)
831 delegate_->Detach(this);
832 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08833 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31834 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08835 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00836 if (view_)
[email protected]e85165c642014-06-10 14:34:31837 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08838 }
[email protected]be1f56ab2011-12-22 06:55:31839}
840
[email protected]8ff00d72012-10-23 19:12:21841RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21842 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41843 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16844}
845
clamydf1975e2015-02-05 19:12:24846RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41847 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16848}
849
nick53d5cbf2015-04-23 22:50:14850RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
851 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
852 if (!focused_node)
853 return nullptr;
854 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07855}
856
rob3e2a0732016-01-06 21:22:09857RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
858 int frame_tree_node_id) {
859 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
860 return frame ? frame->current_frame_host() : nullptr;
861}
862
[email protected]a86c0e962013-12-17 17:10:39863void WebContentsImpl::ForEachFrame(
864 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38865 for (FrameTreeNode* node : frame_tree_.Nodes()) {
866 on_frame.Run(node->current_frame_host());
867 }
[email protected]a86c0e962013-12-17 17:10:39868}
869
dchengafb53e22016-02-04 08:11:08870std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
871 std::vector<RenderFrameHost*> frame_hosts;
872 for (FrameTreeNode* node : frame_tree_.Nodes())
873 frame_hosts.push_back(node->current_frame_host());
874 return frame_hosts;
875}
876
lukaszacbdf52e2016-01-15 21:19:51877int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
878 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08879 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25880 if (!rfh->IsRenderFrameLive())
881 continue;
882
dchengafb53e22016-02-04 08:11:08883 ++number_of_messages;
884 IPC::Message* message_copy = new IPC::Message(*message);
885 message_copy->set_routing_id(rfh->GetRoutingID());
886 rfh->Send(message_copy);
887 }
[email protected]a86c0e962013-12-17 17:10:39888 delete message;
lukaszacbdf52e2016-01-15 21:19:51889 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39890}
891
lfgdb5c4ed2016-03-04 23:09:07892void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:41893 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:07894}
895
creisc014b402015-04-23 16:41:45896RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21897 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31898}
899
[email protected]6b618e62012-08-16 12:59:18900int WebContentsImpl::GetRoutingID() const {
901 if (!GetRenderViewHost())
902 return MSG_ROUTING_NONE;
903
904 return GetRenderViewHost()->GetRoutingID();
905}
906
creis89a0f782015-05-27 16:13:17907void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:46908 if (dialog_manager_) {
909 dialog_manager_->CancelDialogs(this,
910 false, // suppress_callbacks,
911 false); // reset_state
912 }
creis89a0f782015-05-27 16:13:17913 if (browser_plugin_embedder_)
914 browser_plugin_embedder_->CancelGuestDialogs();
915}
916
naskoc0fceff2015-04-30 15:53:52917void WebContentsImpl::ClosePage() {
918 GetRenderViewHost()->ClosePage();
919}
920
[email protected]b172aee2012-04-10 17:05:26921RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21922 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31923}
924
lfg265a2672016-04-23 03:11:02925RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
926 if (GetOuterWebContents())
927 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
928 return GetRenderManager()->GetRenderWidgetHostView();
929}
930
[email protected]4aebbca2013-09-17 22:26:49931RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
932 const {
ekaramadaeb3c5c2016-11-09 03:22:35933 if (auto widget_host = GetFullscreenRenderWidgetHost())
934 return widget_host->GetView();
935 return nullptr;
[email protected]4aebbca2013-09-17 22:26:49936}
937
[email protected]8ff00d72012-10-23 19:12:21938WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31939 return view_.get();
940}
941
yusufod41c5f92015-03-06 00:14:28942SkColor WebContentsImpl::GetThemeColor() const {
943 return theme_color_;
944}
945
[email protected]95640212014-07-26 18:14:30946void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
947 if (mode == accessibility_mode_)
948 return;
949
950 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38951
952 for (FrameTreeNode* node : frame_tree_.Nodes()) {
953 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
954 RenderFrameHost* pending_frame_host =
955 node->render_manager()->pending_frame_host();
956 if (pending_frame_host)
957 SetAccessibilityModeOnFrame(mode, pending_frame_host);
958 }
[email protected]95640212014-07-26 18:14:30959}
960
961void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50962 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30963}
964
965void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50966 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30967}
968
dmazzoni83ba5c82015-04-14 07:11:51969void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39970 // Send a request to each of the frames in parallel. Each one will return
971 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
972 // them into a single tree and call |callback| with that result, then
973 // delete |combiner|.
974 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
975 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
976 bool is_root = frame_tree_node->parent() == nullptr;
977 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
978 combiner->AddFrame(is_root));
979 }
dmazzoni83ba5c82015-04-14 07:11:51980}
981
wjmaclean64951902016-04-29 20:59:12982void WebContentsImpl::SetTemporaryZoomLevel(double level,
983 bool temporary_zoom_enabled) {
984 SendPageMessage(new PageMsg_SetZoomLevel(
985 MSG_ROUTING_NONE,
986 temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY
987 : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY,
988 level));
989}
990
991void WebContentsImpl::UpdateZoom(double level) {
992 // Individual frames may still ignore the new zoom level if their RenderView
993 // contains a plugin document or if it uses a temporary zoom level.
994 SendPageMessage(new PageMsg_SetZoomLevel(
995 MSG_ROUTING_NONE,
996 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level));
997}
998
999void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
1000 const std::string& host,
1001 double level) {
1002 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1003 if (!entry)
1004 return;
1005
1006 GURL url = HostZoomMap::GetURLFromEntry(entry);
1007 if (host != net::GetHostOrSpecFromURL(url) ||
1008 (!scheme.empty() && !url.SchemeIs(scheme))) {
1009 return;
1010 }
1011
1012 UpdateZoom(level);
1013}
1014
rockotf62002a2016-09-15 00:08:591015base::Closure WebContentsImpl::AddBindingSet(
1016 const std::string& interface_name,
1017 WebContentsBindingSet* binding_set) {
1018 auto result =
1019 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1020 DCHECK(result.second);
1021 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1022 weak_factory_.GetWeakPtr(), interface_name);
1023}
1024
wjmaclean8a795f32016-08-11 23:49:581025void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1026 SendPageMessage(
1027 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1028}
1029
ccameron2f451532016-09-07 21:49:271030void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
wjmaclean8a795f32016-08-11 23:49:581031 if (GetView())
ccameron2f451532016-09-07 21:49:271032 GetView()->GetScreenInfo(screen_info);
wjmaclean8a795f32016-08-11 23:49:581033}
1034
avie865b1d2016-10-24 19:42:591035std::unique_ptr<WebUI> WebContentsImpl::CreateSubframeWebUI(
1036 const GURL& url,
1037 const std::string& frame_name) {
dbeama1b926a2015-08-31 23:17:511038 DCHECK(!frame_name.empty());
1039 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:221040}
1041
[email protected]8ff00d72012-10-23 19:12:211042WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401043 WebUI* commited_web_ui = GetCommittedWebUI();
1044 return commited_web_ui ? commited_web_ui
1045 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311046}
1047
[email protected]8ff00d72012-10-23 19:12:211048WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401049 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341050}
1051
[email protected]86ef6a392012-05-11 22:03:111052void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:221053 if (GetUserAgentOverride() == override)
1054 return;
1055
1056 renderer_preferences_.user_agent_override = override;
1057
1058 // Send the new override string to the renderer.
1059 RenderViewHost* host = GetRenderViewHost();
1060 if (host)
1061 host->SyncRendererPrefs();
1062
1063 // Reload the page if a load is currently in progress to avoid having
1064 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271065 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:251066 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:051067 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:531068
ericwilligersde386342016-10-19 02:35:091069 for (auto& observer : observers_)
1070 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111071}
1072
1073const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221074 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111075}
1076
[email protected]95640212014-07-26 18:14:301077void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:081078 if (GetAccessibilityMode() != AccessibilityModeOff) {
1079 for (RenderFrameHost* rfh : GetAllFrames())
1080 ResetAccessibility(rfh);
1081 } else {
dtseng0dd3fa12015-07-22 19:00:521082 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:081083 }
[email protected]95640212014-07-26 18:14:301084}
1085
1086bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
1087 return accessibility_mode_ == AccessibilityModeTreeOnly;
1088}
1089
1090bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
1091 return accessibility_mode_ == AccessibilityModeComplete;
1092}
1093
kouhei40f03cb2015-09-24 07:47:011094const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1095 return page_importance_signals_;
1096}
1097
[email protected]fcf75d42013-12-03 20:11:261098const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551099 // Transient entries take precedence. They are used for interstitial pages
1100 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231101 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231102 if (entry) {
jshin1fb76462016-04-05 22:13:031103 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231104 }
carlosk35f35af2015-12-01 10:55:401105
1106 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1107 WebUI* our_web_ui = navigating_web_ui
1108 ? navigating_web_ui
1109 : GetRenderManager()->current_frame_host()->web_ui();
1110
[email protected]7ade2732011-02-10 00:13:581111 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541112 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321113 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541114 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351115 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261116 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541117 if (!title.empty())
1118 return title;
1119 }
1120 }
1121
1122 // We use the title for the last committed entry rather than a pending
1123 // navigation entry. For example, when the user types in a URL, we want to
1124 // keep the old page's title until the new load has committed and we get a new
1125 // title.
[email protected]96d185d2009-04-24 03:28:541126 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321127
creis072b61f2015-09-28 20:52:241128 // We make an exception for initial navigations. We only want to use the title
1129 // from the visible entry if:
1130 // 1. The pending entry has been explicitly assigned a title to display.
1131 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1132 // which case there is a pending entry index other than -1.
1133 //
1134 // Otherwise, we want to stick with the last committed entry's title during
1135 // new navigations, which have pending entries at index -1 with no title.
1136 if (controller_.IsInitialNavigation() &&
1137 ((controller_.GetVisibleEntry() &&
1138 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1139 controller_.GetPendingEntryIndex() != -1)) {
1140 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471141 }
[email protected]59167c22013-06-03 18:07:321142
[email protected]45d0ef7f2011-01-05 13:46:231143 if (entry) {
jshin1fb76462016-04-05 22:13:031144 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231145 }
[email protected]987fc3a2011-05-26 14:18:091146
1147 // |page_title_when_no_navigation_entry_| is finally used
1148 // if no title cannot be retrieved.
1149 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541150}
1151
creiscce56cd2014-09-29 22:45:221152SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211153 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541154}
1155
creiscce56cd2014-09-29 22:45:221156SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1157 RenderViewHostImpl* dest_rvh =
1158 GetRenderManager()->pending_render_view_host() ?
1159 GetRenderManager()->pending_render_view_host() :
1160 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581161 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381162}
1163
[email protected]b172aee2012-04-10 17:05:261164bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251165 return frame_tree_.IsLoading() &&
1166 !(ShowingInterstitialPage() &&
1167 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491168}
1169
[email protected]6dfed692014-05-22 04:18:031170bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251171 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031172}
1173
[email protected]b172aee2012-04-10 17:05:261174bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031175 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311176}
1177
[email protected]b172aee2012-04-10 17:05:261178const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311179 return load_state_;
1180}
1181
[email protected]fcf75d42013-12-03 20:11:261182const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311183 return load_state_host_;
1184}
1185
avib7348942015-12-25 20:57:101186uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311187 return upload_size_;
1188}
1189
avib7348942015-12-25 20:57:101190uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311191 return upload_position_;
1192}
1193
[email protected]b172aee2012-04-10 17:05:261194const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541195 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311196}
1197
[email protected]222f5822014-02-05 23:40:491198void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251199 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551200 ++capturer_count_;
1201 DVLOG(1) << "There are now " << capturer_count_
1202 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491203
1204 // Note: This provides a hint to upstream code to size the views optimally
1205 // for quality (e.g., to avoid scaling).
1206 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1207 preferred_size_for_capture_ = capture_size;
1208 OnPreferredSizeChanged(preferred_size_);
1209 }
ccameron8807c38f2015-01-17 00:29:191210
1211 // Ensure that all views are un-occluded before capture begins.
1212 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551213}
1214
1215void WebContentsImpl::DecrementCapturerCount() {
1216 --capturer_count_;
1217 DVLOG(1) << "There are now " << capturer_count_
1218 << " capturing(s) of WebContentsImpl@" << this;
1219 DCHECK_LE(0, capturer_count_);
1220
[email protected]5a652232013-02-12 06:15:251221 if (is_being_destroyed_)
1222 return;
1223
[email protected]222f5822014-02-05 23:40:491224 if (capturer_count_ == 0) {
1225 const gfx::Size old_size = preferred_size_for_capture_;
1226 preferred_size_for_capture_ = gfx::Size();
1227 OnPreferredSizeChanged(old_size);
1228 }
1229
[email protected]1ac10dca2013-08-20 20:47:041230 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551231 DVLOG(1) << "Executing delayed WasHidden().";
1232 WasHidden();
1233 }
[email protected]be1f56ab2011-12-22 06:55:311234}
1235
[email protected]f2bd40812013-07-20 04:30:441236int WebContentsImpl::GetCapturerCount() const {
1237 return capturer_count_;
1238}
1239
miu50f97892014-09-22 22:49:521240bool WebContentsImpl::IsAudioMuted() const {
1241 return audio_muter_.get() && audio_muter_->is_muting();
1242}
1243
1244void WebContentsImpl::SetAudioMuted(bool mute) {
1245 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1246 << " for WebContentsImpl@" << this;
1247
1248 if (mute == IsAudioMuted())
1249 return;
1250
1251 if (mute) {
1252 if (!audio_muter_)
1253 audio_muter_.reset(new WebContentsAudioMuter(this));
1254 audio_muter_->StartMuting();
1255 } else {
1256 DCHECK(audio_muter_);
1257 audio_muter_->StopMuting();
1258 }
1259
ericwilligersde386342016-10-19 02:35:091260 for (auto& observer : observers_)
1261 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031262
altimind8bd26c2016-11-04 11:44:541263 OnAudioStateChanged(!mute && audio_stream_monitor_.IsCurrentlyAudible());
miu50f97892014-09-22 22:49:521264}
1265
ortunodf4d7982016-04-08 02:33:351266bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1267 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201268}
1269
[email protected]b172aee2012-04-10 17:05:261270bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311271 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1272 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581273 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271274#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581275 crashed_status_ ==
1276 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271277#endif
wfh0d9532a2015-09-02 23:18:581278 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271279 );
[email protected]3c9e1872010-11-18 16:17:491280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1283 int error_code) {
[email protected]443b80e2010-12-14 00:42:231284 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341285 return;
1286
[email protected]443b80e2010-12-14 00:42:231287 crashed_status_ = status;
1288 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211289 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341290}
1291
[email protected]b172aee2012-04-10 17:05:261292base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311293 return crashed_status_;
1294}
1295
afakhry98241832016-03-11 19:27:471296int WebContentsImpl::GetCrashedErrorCode() const {
1297 return crashed_error_code_;
1298}
1299
[email protected]b172aee2012-04-10 17:05:261300bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311301 return is_being_destroyed_;
1302}
1303
[email protected]7f924832014-08-09 05:57:221304void WebContentsImpl::NotifyNavigationStateChanged(
1305 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541306 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1307 // is fixed.
1308 tracked_objects::ScopedTracker tracking_profile(
1309 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1310 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181311 // Notify the media observer of potential audibility changes.
1312 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271313 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301314 }
1315
[email protected]d5f942ba2008-09-26 19:30:341316 if (delegate_)
1317 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441318
1319 if (GetOuterWebContents())
1320 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341321}
1322
altiminec87fd1f2016-11-17 20:22:491323void WebContentsImpl::OnAudioStateChanged(bool is_audible) {
1324 SendPageMessage(new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_audible));
altimind8bd26c2016-11-04 11:44:541325
altiminec87fd1f2016-11-17 20:22:491326 // Notification for UI updates in response to the changed audio state.
altimind8bd26c2016-11-04 11:44:541327 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1328}
1329
gab0dccfef2015-05-20 18:43:391330base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021331 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331332}
1333
georgesak5582cbe2015-05-22 22:08:071334void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1335 last_active_time_ = last_active_time;
1336}
1337
hajimehoshic4f226a2016-10-21 09:01:571338base::TimeTicks WebContentsImpl::GetLastHiddenTime() const {
1339 return last_hidden_time_;
1340}
1341
[email protected]9e2e4632012-07-27 16:38:411342void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541343 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591344
ccameron8807c38f2015-01-17 00:29:191345 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1346 if (view) {
1347 view->Show();
[email protected]789e9152009-08-04 21:59:431348#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191349 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431350#endif
[email protected]de3c5d82014-05-28 22:12:591351 }
[email protected]789e9152009-08-04 21:59:431352 }
[email protected]96d185d2009-04-24 03:28:541353
lfg717154072016-06-30 15:04:161354 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1355
gab0dccfef2015-05-20 18:43:391356 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381357
ericwilligersde386342016-10-19 02:35:091358 for (auto& observer : observers_)
1359 observer.WasShown();
[email protected]c0d9d5672013-10-09 07:38:031360
[email protected]54597982013-02-06 01:59:551361 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311362}
1363
[email protected]b172aee2012-04-10 17:05:261364void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551365 // If there are entities capturing screenshots or video (e.g., mirroring),
1366 // don't activate the "disable rendering" optimization.
1367 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521368 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551369 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261370 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521371 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331372 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521373 // calls us).
ccameron8807c38f2015-01-17 00:29:191374 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1375 if (view)
1376 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591377 }
lfg717154072016-06-30 15:04:161378
1379 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541380 }
1381
hajimehoshic4f226a2016-10-21 09:01:571382 last_hidden_time_ = base::TimeTicks::Now();
1383
ericwilligersde386342016-10-19 02:35:091384 for (auto& observer : observers_)
1385 observer.WasHidden();
[email protected]c0d9d5672013-10-09 07:38:031386
[email protected]54597982013-02-06 01:59:551387 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371388}
1389
ccameron8807c38f2015-01-17 00:29:191390void WebContentsImpl::WasOccluded() {
1391 if (capturer_count_ > 0)
1392 return;
1393
1394 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1395 if (view)
1396 view->WasOccluded();
1397 }
1398}
1399
1400void WebContentsImpl::WasUnOccluded() {
1401 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1402 if (view)
1403 view->WasUnOccluded();
1404 }
1405}
1406
[email protected]b172aee2012-04-10 17:05:261407bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311408 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451409 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1410 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311411}
1412
nasko148bb0b92016-05-10 21:03:191413void WebContentsImpl::DispatchBeforeUnload() {
1414 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171415 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061416}
1417
lazyboy6ec48b2a2015-06-29 15:18:141418void WebContentsImpl::AttachToOuterWebContentsFrame(
1419 WebContents* outer_web_contents,
1420 RenderFrameHost* outer_contents_frame) {
ekaramad1beabecc2016-09-23 20:18:171421 CHECK(GuestMode::IsCrossProcessFrameGuest(this));
lfg91a79e12016-04-01 23:52:191422 RenderFrameHostManager* render_manager = GetRenderManager();
1423
1424 // When the WebContents being initialized has an opener, the browser side
1425 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1426 // created. This is needed because the usual initialization happens during
1427 // the first navigation, but when attaching a new window we don't navigate
1428 // before attaching. If the browser side is already initialized, the calls
1429 // below will just early return.
1430 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1431 GetMainFrame()->Init();
1432 if (!render_manager->GetRenderWidgetHostView())
1433 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1434
lazyboy6ec48b2a2015-06-29 15:18:141435 // Create a link to our outer WebContents.
1436 node_.reset(new WebContentsTreeNode());
1437 node_->ConnectToOuterWebContents(
1438 static_cast<WebContentsImpl*>(outer_web_contents),
1439 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1440
1441 DCHECK(outer_contents_frame);
1442
1443 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1444 // SiteInstance of the outer WebContents. The proxy will be used to send
1445 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191446 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141447 outer_contents_frame->GetSiteInstance(),
1448 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1449
lfg91a79e12016-04-01 23:52:191450 render_manager->SetRWHViewForInnerContents(
1451 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391452
1453 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191454 render_manager->GetRenderWidgetHostView())
fsamuelb6acafa2016-10-04 03:21:521455 ->RegisterFrameSinkId();
ekaramadadd882292016-06-08 15:22:561456
1457 // At this point, we should destroy the TextInputManager which will notify all
1458 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1459 // TextInputManager owned by the outer WebContents.
1460 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1461 // outer WebContents? In such a case, is this still the right way to hand off
1462 // state tracking from inner WebContents's TextInputManager to that of the
1463 // outer WebContent (crbug.com/609846)?
1464 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141465}
1466
dalecurtis6c58ed02016-10-28 23:02:371467void WebContentsImpl::DidChangeVisibleSecurityState() {
1468 if (delegate_) {
1469 delegate_->VisibleSecurityStateChanged(this);
1470
1471 SecurityStyleExplanations security_style_explanations;
1472 blink::WebSecurityStyle security_style =
1473 delegate_->GetSecurityStyle(this, &security_style_explanations);
1474 for (auto& observer : observers_) {
1475 observer.SecurityStyleChanged(security_style,
1476 security_style_explanations);
1477 }
1478 }
1479}
1480
[email protected]b172aee2012-04-10 17:05:261481void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381482 for (FrameTreeNode* node : frame_tree_.Nodes())
1483 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091484 for (auto& observer : observers_)
1485 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271486}
1487
[email protected]b172aee2012-04-10 17:05:261488WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441489 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211490 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451491 // before.
[email protected]54944cde2012-12-09 09:24:591492 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451493 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211494 WebContentsImpl* tc =
1495 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191496 tc->GetController().CopyStateFrom(controller_);
ericwilligersde386342016-10-19 02:35:091497 for (auto& observer : observers_)
1498 observer.DidCloneToNewWebContents(this, tc);
[email protected]0bfbf882011-12-22 18:19:271499 return tc;
1500}
1501
[email protected]14392a52012-05-02 20:28:441502void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211503 const NotificationSource& source,
1504 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441505 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211506 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1507 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031508 RenderWidgetHostView* view = host->GetView();
1509 if (view == GetFullscreenRenderWidgetHostView()) {
1510 // We cannot just call view_->RestoreFocus() here. On some platforms,
1511 // attempting to focus the currently-invisible WebContentsView will be
1512 // flat-out ignored. Therefore, this boolean is used to track whether
1513 // we will request focus after the fullscreen widget has been
1514 // destroyed.
1515 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1516 } else {
alexmosc2a8cec2016-05-23 22:19:531517 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031518 i != pending_widget_views_.end(); ++i) {
1519 if (host->GetView() == i->second) {
1520 pending_widget_views_.erase(i);
1521 break;
1522 }
[email protected]bafe6cd2012-05-23 23:09:501523 }
1524 }
1525 break;
1526 }
[email protected]14392a52012-05-02 20:28:441527 default:
1528 NOTREACHED();
1529 }
1530}
1531
[email protected]ec6c05f2013-10-23 18:41:571532WebContents* WebContentsImpl::GetWebContents() {
1533 return this;
1534}
1535
[email protected]54944cde2012-12-09 09:24:591536void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211537 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361538 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211539 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431540 should_normally_be_visible_ = !params.initially_hidden;
1541
dcheng3ce04b62015-10-26 23:30:551542 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541543 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551544 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1545 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541546 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551547 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1548 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1549
1550 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1551 if (!site_instance)
1552 site_instance = SiteInstance::Create(params.browser_context);
1553
1554 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1555 // local root by definition.
1556 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1557 // longer be necessary to eagerly grab a routing ID for the view.
1558 // https://crbug.com/545684
1559 int32_t view_routing_id = params.routing_id;
1560 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1561 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1562 view_routing_id = main_frame_widget_routing_id =
1563 site_instance->GetProcess()->GetNextRoutingID();
1564 }
1565
1566 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1567 params.main_frame_routing_id,
jambaaab3a2016-11-05 00:46:181568 main_frame_widget_routing_id,
1569 params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:321570
lukasza5140a412016-09-15 21:12:301571 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1572 // main frame - let's do the same thing here.
1573 std::string unique_name;
lukasza464d8692016-02-22 19:26:321574 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191575
[email protected]fc2b46b2014-05-03 16:33:451576 WebContentsViewDelegate* delegate =
1577 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1578
sadrul943e3b32016-08-04 18:22:591579#if defined(USE_AURA)
bend32292b2016-10-07 00:21:581580 if (ServiceManagerConnection::GetForProcess() &&
fsamueladb0033602015-12-09 19:20:411581 base::CommandLine::ForCurrentProcess()->HasSwitch(
1582 switches::kUseMusInRenderer)) {
ben3a06a272016-07-04 05:00:101583 ui::Window* mus_window = aura::GetMusWindow(params.context);
fsamueladb0033602015-12-09 19:20:411584 if (mus_window) {
1585 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1586 &render_view_host_delegate_view_));
1587 }
1588 }
1589#endif
1590
1591 if (!view_) {
ekaramad1beabecc2016-09-23 20:18:171592 if (GuestMode::IsCrossProcessFrameGuest(this)) {
lfgc740d4b22016-04-15 16:45:331593 view_.reset(new WebContentsViewChildFrame(
1594 this, delegate, &render_view_host_delegate_view_));
1595 } else {
1596 view_.reset(CreateWebContentsView(this, delegate,
1597 &render_view_host_delegate_view_));
1598 }
fsamueladb0033602015-12-09 19:20:411599 }
fsamuel9cf7bdf2015-11-20 02:19:321600
ekaramad1beabecc2016-09-23 20:18:171601 if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) {
fsamuel9cf7bdf2015-11-20 02:19:321602 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361603 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321604 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191605 }
[email protected]fc2b46b2014-05-03 16:33:451606 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191607 CHECK(view_.get());
1608
[email protected]ed245db2012-12-18 08:00:451609 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591610 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191611
brettw4b461082016-11-19 18:55:161612#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:091613 plugin_content_origin_whitelist_.reset(
1614 new PluginContentOriginWhitelist(this));
1615#endif
1616
[email protected]d1198fd2012-08-13 22:50:191617 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211618 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1619 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101620
lunalud4a2cc82016-11-22 00:27:231621 screen_orientation_.reset(new ScreenOrientation(this));
[email protected]01f83f92014-06-17 14:41:541622
mlamouriefdca9d2014-09-16 16:55:401623 manifest_manager_host_.reset(new ManifestManagerHost(this));
1624
mfomitchev2b8b066a2016-01-28 19:23:151625#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101626 date_time_chooser_.reset(new DateTimeChooserAndroid());
1627#endif
fsamuel7310a4262014-12-05 05:06:441628
1629 // BrowserPluginGuest::Init needs to be called after this WebContents has
1630 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1631 if (browser_plugin_guest_)
1632 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371633
1634 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1635 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561636
1637 // If the WebContents creation was renderer-initiated, it means that the
1638 // corresponding RenderView and main RenderFrame have already been created.
1639 // Ensure observers are notified about this.
1640 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431641 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561642 RenderViewCreated(GetRenderViewHost());
1643 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1644 }
naskof5940b9f2015-03-02 23:04:051645
lof84501da082016-05-23 21:22:541646 // Create the renderer process in advance if requested.
1647 if (params.initialize_renderer) {
1648 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
1649 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
1650 }
1651 }
1652
naskof5940b9f2015-03-02 23:04:051653 // Ensure that observers are notified of the creation of this WebContents's
1654 // main RenderFrameHost. It must be done here for main frames, since the
1655 // NotifySwappedFromRenderManager expects view_ to already be created and that
1656 // happens after RenderFrameHostManager::Init.
1657 NotifySwappedFromRenderManager(
1658 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191659}
1660
[email protected]7fff43e2013-05-21 20:21:101661void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1662 RemoveDestructionObserver(web_contents);
1663
[email protected]ceee8cd2013-03-08 04:59:511664 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:531665 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:511666 ++iter) {
1667 if (iter->second != web_contents)
1668 continue;
1669 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511670 return;
1671 }
1672 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441673}
1674
[email protected]7fff43e2013-05-21 20:21:101675void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1676 if (!ContainsKey(destruction_observers_, web_contents)) {
1677 destruction_observers_[web_contents] =
avia8cf81982016-08-12 20:28:461678 base::MakeUnique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:101679 }
1680}
1681
1682void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:461683 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:101684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311687 observers_.AddObserver(observer);
1688}
1689
[email protected]b172aee2012-04-10 17:05:261690void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311691 observers_.RemoveObserver(observer);
1692}
1693
[email protected]948481d2014-06-11 18:32:221694std::set<RenderWidgetHostView*>
1695WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1696 std::set<RenderWidgetHostView*> set;
1697 if (ShowingInterstitialPage()) {
1698 set.insert(GetRenderWidgetHostView());
1699 } else {
dchengafb53e22016-02-04 08:11:081700 for (RenderFrameHost* rfh : GetAllFrames()) {
1701 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1702 ->frame_tree_node()
1703 ->render_manager()
1704 ->GetRenderWidgetHostView();
1705 set.insert(rwhv);
1706 }
[email protected]948481d2014-06-11 18:32:221707 }
[email protected]de3c5d82014-05-28 22:12:591708 return set;
1709}
1710
[email protected]b172aee2012-04-10 17:05:261711void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341712 if (delegate_)
1713 delegate_->ActivateContents(this);
1714}
1715
avi3e4b8512015-11-11 01:55:491716void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1717 if (!RenderViewHostImpl::From(render_widget_host))
1718 return;
1719
[email protected]63954792011-07-11 04:17:481720 if (delegate_)
1721 delegate_->LostCapture();
1722}
1723
lazyboy63f5b312015-11-23 20:19:521724void WebContentsImpl::RenderWidgetCreated(
1725 RenderWidgetHostImpl* render_widget_host) {
1726 created_widgets_.insert(render_widget_host);
1727}
1728
[email protected]b24b68a2012-09-24 21:57:261729void WebContentsImpl::RenderWidgetDeleted(
1730 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521731 // Note that |is_being_destroyed_| can be true at this point as
1732 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1733 // us here.
1734 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261735
lazyboy63f5b312015-11-23 20:19:521736 if (is_being_destroyed_)
1737 return;
[email protected]44470a22013-01-24 01:21:541738
1739 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:371740 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
1741 render_widget_host->GetProcess()->GetID() ==
1742 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:491743 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531744 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:091745 for (auto& observer : observers_)
1746 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:371747 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:541748 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031749 if (fullscreen_widget_had_focus_at_shutdown_)
1750 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541751 }
lfgbee1e0a2016-06-08 21:24:211752
lfgff8dfc8d2016-10-21 17:42:321753 if (mouse_lock_widget_)
1754 LostMouseLock(mouse_lock_widget_);
[email protected]b24b68a2012-09-24 21:57:261755}
1756
miu9e14e492014-10-25 02:39:041757void WebContentsImpl::RenderWidgetGotFocus(
1758 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371759 // Notify the observers if an embedded fullscreen widget was focused.
1760 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1761 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1762 NotifyWebContentsFocused();
1763 }
miu9e14e492014-10-25 02:39:041764}
1765
estaded0a0c992015-01-21 14:12:061766void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311767 RenderWidgetHostImpl* render_widget_host,
1768 bool width_changed) {
creisc014b402015-04-23 16:41:451769 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291770 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061771 return;
estaded0a0c992015-01-21 14:12:061772
ericwilligersde386342016-10-19 02:35:091773 for (auto& observer : observers_)
1774 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:061775}
1776
paulmeyer9ef6e4462015-02-24 19:15:101777void WebContentsImpl::ScreenInfoChanged() {
1778 if (browser_plugin_embedder_)
1779 browser_plugin_embedder_->ScreenInfoChanged();
1780}
1781
[email protected]b172aee2012-04-10 17:05:261782bool WebContentsImpl::PreHandleKeyboardEvent(
1783 const NativeWebKeyboardEvent& event,
1784 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481785 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131786 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481787}
1788
[email protected]b172aee2012-04-10 17:05:261789void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101790 if (browser_plugin_embedder_ &&
1791 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1792 return;
1793 }
[email protected]63954792011-07-11 04:17:481794 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131795 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481796}
1797
[email protected]d92026ef2014-03-03 21:04:131798bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461799 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191800#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331801 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1802 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191803 // -the OS already has a gesture to do this through pinch-zoom
1804 // -if a user starts an inertial scroll, let's go, and presses control
1805 // (i.e. control+tab) then the OS's buffered scroll events will come in
1806 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331807 if (delegate_ && event.wheelTicksY &&
chongz4a9751942016-08-17 17:49:391808 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:221809 // Count only integer cumulative scrolls as zoom events; this handles
1810 // smooth scroll and regular scroll device behavior.
1811 zoom_scroll_remainder_ += event.wheelTicksY;
1812 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1813 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1814 if (whole_zoom_scroll_remainder_ != 0) {
1815 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1816 }
[email protected]fb3f066e2013-02-12 19:12:521817 return true;
1818 }
[email protected]bccc4472013-04-18 16:37:191819#endif
[email protected]fb3f066e2013-02-12 19:12:521820 return false;
1821}
1822
[email protected]04bce562014-01-30 05:34:541823bool WebContentsImpl::PreHandleGestureEvent(
1824 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031825 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541826}
1827
kenrb2a565f82015-09-02 20:24:591828RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451829 if (!is_being_destroyed_ && GetOuterWebContents())
1830 return GetOuterWebContents()->GetInputEventRouter();
1831
1832 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591833 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1834 return rwh_input_event_router_.get();
1835}
1836
alexmos3fcd0ca2015-10-23 18:18:331837void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1838 // Focus loss may occur while this WebContents is being destroyed. Don't
1839 // send the message in this case, as the main frame's RenderFrameHost and
1840 // other state has already been cleared.
1841 if (is_being_destroyed_)
1842 return;
1843
1844 frame_tree_.ReplicatePageFocus(is_focused);
1845}
1846
alexmosc4cbacb2015-11-21 01:29:221847RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1848 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521849 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221850 return receiving_widget;
1851
1852 // Events for widgets other than the main frame (e.g., popup menus) should be
1853 // forwarded directly to the widget they arrived on.
1854 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1855 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521856
avallee0206f782016-07-28 18:55:331857 FrameTreeNode* focused_frame =
1858 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
alexmosc4d183e2015-11-06 00:46:521859 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221860 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521861
alexmos732ca3a2015-12-08 02:01:021862 // The view may be null if a subframe's renderer process has crashed while
1863 // the subframe has focus. Drop the event in that case. Do not give
1864 // it to the main frame, so that the user doesn't unexpectedly type into the
1865 // wrong frame if a focused subframe renderer crashes while they type.
1866 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1867 if (!view)
1868 return nullptr;
1869
1870 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521871}
1872
avallee9993fca2016-11-17 06:16:501873RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
1874 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost();
1875}
1876
mlamouri7a78d6fd2015-01-17 13:23:531877void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1878 // This method is being called to enter renderer-initiated fullscreen mode.
1879 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491880 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371881 if (widget_view) {
1882 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1883 ->ShutdownAndDestroyWidget(true);
1884 }
[email protected]4aebbca2013-09-17 22:26:491885
[email protected]8a5e0ca2011-08-25 06:30:471886 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531887 delegate_->EnterFullscreenModeForTab(this, origin);
1888
ericwilligersde386342016-10-19 02:35:091889 for (auto& observer : observers_)
1890 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:531891}
1892
bokanece34a82016-01-28 19:49:461893void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531894 // This method is being called to leave renderer-initiated fullscreen mode.
1895 // Make sure any existing fullscreen widget is shut down first.
1896 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371897 if (widget_view) {
1898 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1899 ->ShutdownAndDestroyWidget(true);
1900 }
mlamouri7a78d6fd2015-01-17 13:23:531901
hugo.holgersson61288e6c2015-01-28 17:04:401902#if defined(OS_ANDROID)
1903 ContentVideoView* video_view = ContentVideoView::GetInstance();
1904 if (video_view != NULL)
watk98292292016-01-19 22:24:081905 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401906#endif
1907
mlamouri7a78d6fd2015-01-17 13:23:531908 if (delegate_)
1909 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371910
bokanece34a82016-01-28 19:49:461911 // The fullscreen state is communicated to the renderer through a resize
1912 // message. If the change in fullscreen state doesn't cause a view resize
1913 // then we must ensure web contents exit the fullscreen state by explicitly
1914 // sending a resize message. This is required for the situation of the browser
1915 // moving the view into a "browser fullscreen" state and then the contents
1916 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1917 // have the side effect of the view resizing, hence the explicit call here is
1918 // required.
1919 if (!will_cause_resize) {
1920 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1921 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1922 render_widget_host->WasResized();
1923 }
scheib3dcb6c932015-02-23 10:55:581924 }
1925
ericwilligersde386342016-10-19 02:35:091926 for (auto& observer : observers_) {
1927 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
1928 will_cause_resize);
1929 }
[email protected]8a5e0ca2011-08-25 06:30:471930}
1931
alexmos5dd617d2016-06-07 04:21:151932bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381933 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121934}
1935
billorr21c005d2016-11-17 03:57:041936bool WebContentsImpl::IsFullscreen() {
1937 return IsFullscreenForCurrentTab();
1938}
1939
avibf58fa0c2015-11-11 01:45:521940blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1941 RenderWidgetHostImpl* render_widget_host) const {
1942 if (!RenderViewHostImpl::From(render_widget_host))
1943 return blink::WebDisplayModeBrowser;
1944
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121945 return delegate_ ? delegate_->GetDisplayMode(this)
1946 : blink::WebDisplayModeBrowser;
1947}
1948
avic3aa8422015-11-09 20:57:221949void WebContentsImpl::RequestToLockMouse(
1950 RenderWidgetHostImpl* render_widget_host,
1951 bool user_gesture,
lfgad8244352016-07-13 16:55:511952 bool last_unlocked_by_target,
1953 bool privileged) {
lfgbee1e0a2016-06-08 21:24:211954 if (mouse_lock_widget_) {
avic3aa8422015-11-09 20:57:221955 render_widget_host->GotResponseToLockMouseRequest(false);
1956 return;
[email protected]e9621112011-10-17 05:38:371957 }
avic3aa8422015-11-09 20:57:221958
lfgad8244352016-07-13 16:55:511959 if (privileged) {
1960 mouse_lock_widget_ = render_widget_host;
1961 render_widget_host->GotResponseToLockMouseRequest(true);
1962 return;
1963 }
1964
lfgbee1e0a2016-06-08 21:24:211965 bool widget_in_frame_tree = false;
1966 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1967 if (node->current_frame_host()->GetRenderWidgetHost() ==
1968 render_widget_host) {
1969 widget_in_frame_tree = true;
1970 break;
1971 }
1972 }
1973
1974 if (widget_in_frame_tree && delegate_) {
1975 mouse_lock_widget_ = render_widget_host;
avic3aa8422015-11-09 20:57:221976 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:211977 } else {
1978 render_widget_host->GotResponseToLockMouseRequest(false);
1979 }
[email protected]e9621112011-10-17 05:38:371980}
1981
avi3e4b8512015-11-11 01:55:491982void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:211983 CHECK(mouse_lock_widget_);
1984 mouse_lock_widget_->SendMouseLockLost();
1985 mouse_lock_widget_ = nullptr;
avi3e4b8512015-11-11 01:55:491986
[email protected]e9621112011-10-17 05:38:371987 if (delegate_)
1988 delegate_->LostMouseLock();
1989}
1990
lfgad8244352016-07-13 16:55:511991bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1992 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1993 // assigned to the widget that requested the mouse lock, and the top-level
1994 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1995 return mouse_lock_widget_ == render_widget_host &&
1996 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
1997}
1998
dtrainor5ef644e2015-11-19 00:12:471999void WebContentsImpl::ForwardCompositorProto(
2000 RenderWidgetHostImpl* render_widget_host,
2001 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:472002 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:292003 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:472004}
2005
ekaramada4f42692016-02-11 19:48:372006void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:062007 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:372008 WasShown();
lfg9462cef2016-07-18 23:51:062009 else if (!visible)
ekaramada4f42692016-02-11 19:48:372010 WasHidden();
2011}
2012
[email protected]bafe6cd2012-05-23 23:09:502013void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:432014 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:552015 int32_t route_id,
2016 int32_t main_frame_route_id,
2017 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182018 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132019 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:502020 // We usually create the new window in the same BrowsingInstance (group of
2021 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552022 // if the opener is being suppressed (in a non-guest), we create a new
2023 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252024 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552025
[email protected]04cbd3d2013-12-04 04:58:202026 // If the opener is to be suppressed, the new window can be in any process.
2027 // Since routing ids are process specific, we must not have one passed in
2028 // as argument here.
2029 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
2030
[email protected]bafe6cd2012-05-23 23:09:502031 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432032 params.opener_suppressed && !is_guest
2033 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2034 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502035
alexmos4cf2aa32015-07-15 23:40:432036 // A message to create a new window can only come from a process for a frame
2037 // in this WebContents' FrameTree. If any other process sends the request, it
2038 // is invalid and the process must be terminated.
2039 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:382040 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:432041 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:352042 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:202043 if (process_handle != base::kNullProcessHandle) {
2044 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392045 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:352046 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:202047 }
2048 return;
2049 }
2050
[email protected]d1198fd2012-08-13 22:50:192051 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342052 //
2053 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302054 const std::string& partition_id =
2055 GetContentClient()->browser()->
2056 GetStoragePartitionIdForSite(GetBrowserContext(),
2057 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462058 StoragePartition* partition = BrowserContext::GetStoragePartition(
2059 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412060 DOMStorageContextWrapper* dom_storage_context =
2061 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192062 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2063 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2064 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372065
2066 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552067 !delegate_->ShouldCreateWebContents(
2068 this, route_id, main_frame_route_id, main_frame_widget_route_id,
2069 params.window_container_type, params.frame_name, params.target_url,
2070 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:012071 if (route_id != MSG_ROUTING_NONE &&
2072 !RenderViewHost::FromID(render_process_id, route_id)) {
2073 // If the embedder didn't create a WebContents for this route, we need to
2074 // delete the RenderView that had already been created.
2075 Send(new ViewMsg_Close(route_id));
2076 }
jambaaab3a2016-11-05 00:46:182077 // Note: even though we're not creating a WebContents here, it could have
2078 // been created by the embedder so ensure that the RenderFrameHost is
2079 // properly initialized.
csharrisona2280cd2016-02-03 23:21:152080 // It's safe to only target the frame because the render process will not
2081 // have a chance to create more frames at this point.
jambaaab3a2016-11-05 00:46:182082 RenderFrameHostImpl* rfh =
2083 RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id);
2084 if (rfh)
2085 rfh->Init();
[email protected]dd6730412013-08-14 15:03:372086 return;
2087 }
2088
2089 // Create the new web contents. This will automatically create the new
2090 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462091 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:592092 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:042093 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552094 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122095 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432096 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:212097 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:062098 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192099 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062100 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192101 create_params.renderer_initiated_creation =
2102 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062103
[email protected]4858e432014-06-23 18:14:172104 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:552105 if (!is_guest) {
2106 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452107 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:172108 new_contents = static_cast<WebContentsImpl*>(
2109 WebContents::Create(create_params));
2110 } else {
2111 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:552112 }
[email protected]50d326e2014-05-20 17:59:062113 new_contents->GetController().SetSessionStorageNamespace(
2114 partition_id,
2115 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192116
alexmos646fec02015-07-25 00:11:492117 // If the new frame has a name, make sure any SiteInstances that can find
2118 // this named frame have proxies for it. Must be called after
2119 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2120 // GetSessionStorageNamespace.
2121 if (!params.frame_name.empty())
2122 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
2123
[email protected]c4538072013-03-18 02:17:552124 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342125 // will be shown immediately).
2126 if (!params.opener_suppressed) {
2127 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:452128 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502129
[email protected]d70bea92013-04-05 04:23:342130 // TODO(brettw): It seems bogus that we have to call this function on the
2131 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432132 new_view->CreateViewForWidget(
2133 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342134 }
[email protected]bafe6cd2012-05-23 23:09:502135 // Save the created window associated with the route so we can show it
2136 // later.
2137 DCHECK_NE(MSG_ROUTING_NONE, route_id);
alexmosc2a8cec2016-05-23 22:19:532138 pending_contents_[std::make_pair(render_process_id, route_id)] =
2139 new_contents;
[email protected]7fff43e2013-05-21 20:21:102140 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502141 }
2142
2143 if (delegate_) {
2144 delegate_->WebContentsCreated(
naskoe2df1d72016-10-04 00:20:172145 this, render_process_id, params.opener_render_frame_id,
2146 params.frame_name, params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:502147 }
2148
2149 if (params.opener_suppressed) {
2150 // When the opener is suppressed, the original renderer cannot access the
2151 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002152 bool was_blocked = false;
2153 if (delegate_) {
bokan107a47f2015-02-03 23:23:392154 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002155 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392156 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002157 params.user_gesture, &was_blocked);
2158 }
2159 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192160 OpenURLParams open_params(params.target_url, params.referrer,
2161 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352162 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212163 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302164 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372165
2166 if (delegate_ && !is_guest &&
2167 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2168 // We are in asynchronous add new contents path, delay opening url
2169 new_contents->delayed_open_url_params_.reset(
2170 new OpenURLParams(open_params));
2171 } else {
2172 new_contents->OpenURL(open_params);
2173 }
[email protected]eda238a12012-09-07 23:44:002174 }
[email protected]bafe6cd2012-05-23 23:09:502175 }
2176}
2177
avib7348942015-12-25 20:57:102178void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2179 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462180 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052181 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502182}
2183
avib7348942015-12-25 20:57:102184void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2185 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052186 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502187}
2188
avib7348942015-12-25 20:57:102189void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2190 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502191 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462192 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252193 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232194 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512195 // this WebContentsImpl instance. If any other process sends the request,
2196 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382197 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252198 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512199 if (process_handle != base::kNullProcessHandle) {
2200 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392201 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252202 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512203 }
2204 return;
2205 }
2206
[email protected]bafe6cd2012-05-23 23:09:502207 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052208 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262209
[email protected]cfd80b02014-05-01 17:46:482210 RenderWidgetHostViewBase* widget_view =
2211 static_cast<RenderWidgetHostViewBase*>(
2212 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192213 if (!widget_view)
2214 return;
[email protected]bafe6cd2012-05-23 23:09:502215 if (!is_fullscreen) {
2216 // Popups should not get activated.
2217 widget_view->SetPopupType(popup_type);
2218 }
2219 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532220 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2221 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502222
2223#if defined(OS_MACOSX)
2224 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2225 // to allow it to survive the trip without being hosted.
2226 base::mac::NSObjectRetain(widget_view->GetNativeView());
2227#endif
2228}
2229
alexmosc2a8cec2016-05-23 22:19:532230void WebContentsImpl::ShowCreatedWindow(int process_id,
2231 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502232 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392233 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502234 bool user_gesture) {
alexmosc2a8cec2016-05-23 22:19:532235 WebContentsImpl* contents = GetCreatedWindow(process_id, route_id);
[email protected]eda238a12012-09-07 23:44:002236 if (contents) {
2237 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162238 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382239 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2240 contents->ResumeLoadingCreatedWebContents();
2241
[email protected]eda238a12012-09-07 23:44:002242 if (delegate) {
2243 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392244 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002245 }
2246 }
[email protected]bafe6cd2012-05-23 23:09:502247}
2248
alexmosc2a8cec2016-05-23 22:19:532249void WebContentsImpl::ShowCreatedWidget(int process_id,
2250 int route_id,
bokan107a47f2015-02-03 23:23:392251 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532252 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502253}
2254
alexmosc2a8cec2016-05-23 22:19:532255void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2256 int route_id) {
2257 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502258}
2259
alexmosc2a8cec2016-05-23 22:19:532260void WebContentsImpl::ShowCreatedWidget(int process_id,
2261 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502262 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392263 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482264 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532265 static_cast<RenderWidgetHostViewBase*>(
2266 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502267 if (!widget_host_view)
2268 return;
[email protected]cfd80b02014-05-01 17:46:482269
2270 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332271 if (GetOuterWebContents()) {
2272 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482273 } else {
2274 view = GetRenderWidgetHostView();
2275 }
2276
[email protected]4aebbca2013-09-17 22:26:492277 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312278 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032279 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372280 fullscreen_widget_process_id_ =
2281 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312282 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492283 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2284 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532285 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492286 } else {
[email protected]cfd80b02014-05-01 17:46:482287 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492288 }
ericwilligersde386342016-10-19 02:35:092289 for (auto& observer : observers_)
2290 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:492291 if (!widget_host_view->HasFocus())
2292 widget_host_view->Focus();
2293 } else {
bokan107a47f2015-02-03 23:23:392294 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492295 }
[email protected]89054502012-06-03 10:29:242296
2297 RenderWidgetHostImpl* render_widget_host_impl =
2298 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2299 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312300 // Only allow privileged mouse lock for fullscreen render widget, which is
2301 // used to implement Pepper Flash fullscreen.
2302 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502303
2304#if defined(OS_MACOSX)
2305 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2306 // properly embedded (or purposefully ignored) we can release the retain we
2307 // took in CreateNewWidget().
2308 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2309#endif
2310}
2311
alexmosc2a8cec2016-05-23 22:19:532312WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id,
2313 int route_id) {
2314 auto iter = pending_contents_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502315
2316 // Certain systems can block the creation of new windows. If we didn't succeed
2317 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532318 if (iter == pending_contents_.end())
2319 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502320
2321 WebContentsImpl* new_contents = iter->second;
alexmosc2a8cec2016-05-23 22:19:532322 pending_contents_.erase(std::make_pair(process_id, route_id));
[email protected]7fff43e2013-05-21 20:21:102323 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502324
[email protected]d70bea92013-04-05 04:23:342325 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252326 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342327 return new_contents;
2328
[email protected]bafe6cd2012-05-23 23:09:502329 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432330 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
alexmosc2a8cec2016-05-23 22:19:532331 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502332
[email protected]bafe6cd2012-05-23 23:09:502333 return new_contents;
2334}
2335
alexmosc2a8cec2016-05-23 22:19:532336RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2337 int route_id) {
2338 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502339 if (iter == pending_widget_views_.end()) {
2340 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532341 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502342 }
2343
2344 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532345 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502346
2347 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2348 if (!widget_host->GetProcess()->HasConnection()) {
2349 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532350 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502351 }
2352
2353 return widget_host_view;
2354}
2355
[email protected]f13b4202012-06-12 23:53:232356void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092357 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212358 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372359 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232360 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372361 } else {
dcheng59716272016-04-09 05:19:082362 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2363 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372364 }
[email protected]f13b4202012-06-12 23:53:232365}
2366
grunell657d4d82014-09-18 00:09:432367bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2368 MediaStreamType type) {
2369 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2370 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2371 return delegate_ &&
2372 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2373}
2374
[email protected]cc9200432013-07-23 23:02:402375SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2376 SiteInstance* instance) {
2377 return controller_.GetSessionStorageNamespace(instance);
2378}
2379
[email protected]6de7fc482014-06-06 10:46:442380SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2381 return controller_.GetSessionStorageNamespaceMap();
2382}
2383
[email protected]9b159a52013-10-03 17:24:552384FrameTree* WebContentsImpl::GetFrameTree() {
2385 return &frame_tree_;
2386}
2387
lukendc35e7f2014-11-10 19:06:142388void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2389 virtual_keyboard_requested_ = requested;
2390}
2391
2392bool WebContentsImpl::IsVirtualKeyboardRequested() {
2393 return virtual_keyboard_requested_;
2394}
2395
aelias5252baa2016-04-10 01:18:022396bool WebContentsImpl::IsOverridingUserAgent() {
2397 return GetController().GetVisibleEntry() &&
2398 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2399}
2400
avi85ee8362016-10-08 02:09:082401bool WebContentsImpl::IsJavaScriptDialogShowing() const {
2402 return is_showing_javascript_dialog_;
2403}
2404
[email protected]95640212014-07-26 18:14:302405AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2406 return accessibility_mode_;
2407}
2408
[email protected]31a71eaf2014-03-13 01:47:362409void WebContentsImpl::AccessibilityEventReceived(
2410 const std::vector<AXEventNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:092411 for (auto& observer : observers_)
2412 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:362413}
2414
dmazzoni2400c462016-08-23 15:07:132415void WebContentsImpl::AccessibilityLocationChangesReceived(
2416 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:092417 for (auto& observer : observers_)
2418 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:132419}
2420
dmazzonia656928e2014-09-15 20:28:542421RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402422 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542423 int browser_plugin_instance_id) {
2424 BrowserPluginGuestManager* guest_manager =
2425 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202426 if (!guest_manager)
2427 return nullptr;
2428
dmazzonia656928e2014-09-15 20:28:542429 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442430 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542431 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202432 return nullptr;
2433
dmazzonia656928e2014-09-15 20:28:542434 return guest->GetMainFrame();
2435}
2436
mcasas4e216e72016-07-28 21:28:382437device::GeolocationServiceContext*
2438WebContentsImpl::GetGeolocationServiceContext() {
blundellc57b93f2014-10-29 13:19:572439 return geolocation_service_context_.get();
2440}
2441
blundelld46e8832016-10-07 10:34:272442device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
alogvinovf50445a2015-10-30 13:00:122443 return wake_lock_service_context_.get();
2444}
2445
lunalud4a2cc82016-11-22 00:27:232446ScreenOrientationProvider* WebContentsImpl::GetScreenOrientationProvider() {
2447 return screen_orientation_.get()->GetScreenOrientationProvider();
2448}
2449
[email protected]edc3af82013-12-12 21:24:072450void WebContentsImpl::OnShowValidationMessage(
2451 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292452 const base::string16& main_text,
2453 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072454 if (delegate_)
2455 delegate_->ShowValidationMessage(
2456 this, anchor_in_root_view, main_text, sub_text);
2457}
2458
2459void WebContentsImpl::OnHideValidationMessage() {
2460 if (delegate_)
2461 delegate_->HideValidationMessage(this);
2462}
2463
2464void WebContentsImpl::OnMoveValidationMessage(
2465 const gfx::Rect& anchor_in_root_view) {
2466 if (delegate_)
2467 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2468}
2469
lfgbb9c28a2016-03-01 03:19:492470void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372471 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:402472 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:372473 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2474 }
lfgbb9c28a2016-03-01 03:19:492475
lfgdb5c4ed2016-03-04 23:09:072476 RenderWidgetHostViewBase* rwhv =
2477 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2478 if (rwhv) {
2479 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2480 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2481 }
2482
[email protected]32deec62013-05-15 23:55:042483 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442484 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042485}
2486
khushalsagarf3b62b62016-05-26 21:54:232487void WebContentsImpl::OnFirstPaintAfterLoad(
2488 RenderWidgetHostImpl* render_widget_host) {
ericwilligersde386342016-10-19 02:35:092489 for (auto& observer : observers_)
2490 observer.DidFirstPaintAfterLoad(render_widget_host);
khushalsagarf3b62b62016-05-26 21:54:232491}
2492
ekaramadadd882292016-06-08 15:22:562493TextInputManager* WebContentsImpl::GetTextInputManager() {
2494 if (GetOuterWebContents())
2495 return GetOuterWebContents()->GetTextInputManager();
2496
2497 if (!text_input_manager_)
2498 text_input_manager_.reset(new TextInputManager());
2499
2500 return text_input_manager_.get();
2501}
2502
paulmeyer7f6f1d4f2016-11-15 00:00:272503bool WebContentsImpl::OnUpdateDragCursor() {
2504 if (browser_plugin_embedder_)
2505 return browser_plugin_embedder_->OnUpdateDragCursor();
2506 return false;
2507}
2508
[email protected]95640212014-07-26 18:14:302509BrowserAccessibilityManager*
2510 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452511 RenderFrameHostImpl* rfh = GetMainFrame();
2512 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302513}
2514
2515BrowserAccessibilityManager*
2516 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452517 RenderFrameHostImpl* rfh = GetMainFrame();
2518 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302519}
2520
mohsen7ab1ec16ec2015-07-02 18:26:232521void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2522 RenderFrameHost* focused_frame = GetFocusedFrame();
2523 if (!focused_frame)
2524 return;
2525
2526 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2527 focused_frame->GetRoutingID(), extent));
2528}
2529
2530void WebContentsImpl::SelectRange(const gfx::Point& base,
2531 const gfx::Point& extent) {
2532 RenderFrameHost* focused_frame = GetFocusedFrame();
2533 if (!focused_frame)
2534 return;
2535
2536 focused_frame->Send(
2537 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2538}
2539
aurimasab0319022015-07-10 21:57:382540void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2541 int end_adjust) {
2542 RenderFrameHost* focused_frame = GetFocusedFrame();
2543 if (!focused_frame)
2544 return;
2545
2546 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2547 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2548}
2549
[email protected]b172aee2012-04-10 17:05:262550void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492551 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232552 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492553 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332554}
2555
avic3aa8422015-11-09 20:57:222556void WebContentsImpl::ResizeDueToAutoResize(
2557 RenderWidgetHostImpl* render_widget_host,
2558 const gfx::Size& new_size) {
2559 if (render_widget_host != GetRenderViewHost()->GetWidget())
2560 return;
2561
[email protected]61e2b3cc2012-03-02 16:13:342562 if (delegate_)
2563 delegate_->ResizeDueToAutoResize(this, new_size);
2564}
2565
[email protected]b172aee2012-04-10 17:05:262566WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202567 if (!delegate_)
2568 return NULL;
[email protected]00c37fc2011-08-02 00:22:502569
[email protected]e5d549d2011-12-28 01:29:202570 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202571 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342572}
2573
[email protected]6b618e62012-08-16 12:59:182574bool WebContentsImpl::Send(IPC::Message* message) {
2575 if (!GetRenderViewHost()) {
2576 delete message;
2577 return false;
2578 }
2579
2580 return GetRenderViewHost()->Send(message);
2581}
2582
[email protected]a86c0e962013-12-17 17:10:392583void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2584 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:092585 for (auto& observer : observers_)
2586 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:442587}
2588
[email protected]20ca0382013-02-28 19:50:072589void WebContentsImpl::AttachInterstitialPage(
2590 InterstitialPageImpl* interstitial_page) {
2591 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212592 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292593
2594 // Cancel any visible dialogs so that they don't interfere with the
2595 // interstitial.
creis89a0f782015-05-27 16:13:172596 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292597
ericwilligersde386342016-10-19 02:35:092598 for (auto& observer : observers_)
2599 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:252600
2601 // Stop the throbber if needed while the interstitial page is shown.
2602 if (frame_tree_.IsLoading())
2603 LoadingStateChanged(true, true, nullptr);
2604}
2605
2606void WebContentsImpl::DidProceedOnInterstitial() {
2607 // The interstitial page should no longer be pausing the throbber.
2608 DCHECK(!(ShowingInterstitialPage() &&
2609 GetRenderManager()->interstitial_page()->pause_throbber()));
2610
2611 // Restart the throbber now that the interstitial page no longer pauses it.
2612 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2613 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072614}
2615
2616void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252617 bool interstitial_pausing_throbber =
2618 ShowingInterstitialPage() &&
2619 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572620 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212621 GetRenderManager()->remove_interstitial_page();
ericwilligersde386342016-10-19 02:35:092622 for (auto& observer : observers_)
2623 observer.DidDetachInterstitialPage();
clamy44e84ce2016-02-22 15:38:252624
2625 // Restart the throbber if needed now that the interstitial page is going
2626 // away.
2627 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2628 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072629}
2630
avi2b177592014-12-10 02:08:022631void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2632 int history_length) {
alexmos136fd6e62016-08-15 20:58:412633 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
2634 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:022635}
2636
2637void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2638 RenderViewHost* render_view_host,
2639 int history_offset,
2640 int history_length) {
alexmos136fd6e62016-08-15 20:58:412641 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:022642 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142643}
2644
toyoshim24a4c7ab2016-04-05 09:24:142645void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172646 RenderFrameHost* focused_frame = GetFocusedFrame();
2647 if (!focused_frame)
2648 return;
2649
[email protected]959be4c2014-04-08 15:01:332650 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142651 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332652}
2653
megjablon3f5941072016-02-04 23:27:522654void WebContentsImpl::ReloadLoFiImages() {
2655 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2656}
2657
[email protected]959be4c2014-04-08 15:01:332658void WebContentsImpl::Undo() {
2659 RenderFrameHost* focused_frame = GetFocusedFrame();
2660 if (!focused_frame)
2661 return;
2662
2663 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2664 RecordAction(base::UserMetricsAction("Undo"));
2665}
2666
2667void WebContentsImpl::Redo() {
2668 RenderFrameHost* focused_frame = GetFocusedFrame();
2669 if (!focused_frame)
2670 return;
2671 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2672 RecordAction(base::UserMetricsAction("Redo"));
2673}
2674
2675void WebContentsImpl::Cut() {
2676 RenderFrameHost* focused_frame = GetFocusedFrame();
2677 if (!focused_frame)
2678 return;
2679
2680 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2681 RecordAction(base::UserMetricsAction("Cut"));
2682}
2683
2684void WebContentsImpl::Copy() {
2685 RenderFrameHost* focused_frame = GetFocusedFrame();
2686 if (!focused_frame)
2687 return;
2688
2689 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2690 RecordAction(base::UserMetricsAction("Copy"));
2691}
2692
2693void WebContentsImpl::CopyToFindPboard() {
2694#if defined(OS_MACOSX)
2695 RenderFrameHost* focused_frame = GetFocusedFrame();
2696 if (!focused_frame)
2697 return;
2698
2699 // Windows/Linux don't have the concept of a find pasteboard.
2700 focused_frame->Send(
2701 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2702 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2703#endif
2704}
2705
2706void WebContentsImpl::Paste() {
2707 RenderFrameHost* focused_frame = GetFocusedFrame();
2708 if (!focused_frame)
2709 return;
2710
2711 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2712 RecordAction(base::UserMetricsAction("Paste"));
2713}
2714
2715void WebContentsImpl::PasteAndMatchStyle() {
2716 RenderFrameHost* focused_frame = GetFocusedFrame();
2717 if (!focused_frame)
2718 return;
2719
2720 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2721 focused_frame->GetRoutingID()));
2722 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2723}
2724
2725void WebContentsImpl::Delete() {
2726 RenderFrameHost* focused_frame = GetFocusedFrame();
2727 if (!focused_frame)
2728 return;
2729
2730 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2731 RecordAction(base::UserMetricsAction("DeleteSelection"));
2732}
2733
2734void WebContentsImpl::SelectAll() {
2735 RenderFrameHost* focused_frame = GetFocusedFrame();
2736 if (!focused_frame)
2737 return;
2738
2739 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2740 RecordAction(base::UserMetricsAction("SelectAll"));
2741}
2742
2743void WebContentsImpl::Unselect() {
2744 RenderFrameHost* focused_frame = GetFocusedFrame();
2745 if (!focused_frame)
2746 return;
2747
2748 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2749 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172750}
2751
2752void WebContentsImpl::Replace(const base::string16& word) {
2753 RenderFrameHost* focused_frame = GetFocusedFrame();
2754 if (!focused_frame)
2755 return;
2756
[email protected]959be4c2014-04-08 15:01:332757 focused_frame->Send(new InputMsg_Replace(
2758 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172759}
2760
2761void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2762 RenderFrameHost* focused_frame = GetFocusedFrame();
2763 if (!focused_frame)
2764 return;
2765
[email protected]959be4c2014-04-08 15:01:332766 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2767 focused_frame->GetRoutingID(), word));
2768}
2769
2770void WebContentsImpl::NotifyContextMenuClosed(
2771 const CustomContextMenuContext& context) {
2772 RenderFrameHost* focused_frame = GetFocusedFrame();
2773 if (!focused_frame)
2774 return;
2775
2776 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2777 focused_frame->GetRoutingID(), context));
2778}
2779
2780void WebContentsImpl::ExecuteCustomContextMenuCommand(
2781 int action, const CustomContextMenuContext& context) {
2782 RenderFrameHost* focused_frame = GetFocusedFrame();
2783 if (!focused_frame)
2784 return;
2785
2786 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2787 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002788}
2789
[email protected]fc2b46b2014-05-03 16:33:452790gfx::NativeView WebContentsImpl::GetNativeView() {
2791 return view_->GetNativeView();
2792}
2793
2794gfx::NativeView WebContentsImpl::GetContentNativeView() {
2795 return view_->GetContentNativeView();
2796}
2797
2798gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2799 return view_->GetTopLevelNativeWindow();
2800}
2801
2802gfx::Rect WebContentsImpl::GetViewBounds() {
2803 return view_->GetViewBounds();
2804}
2805
2806gfx::Rect WebContentsImpl::GetContainerBounds() {
2807 gfx::Rect rv;
2808 view_->GetContainerBounds(&rv);
2809 return rv;
2810}
2811
2812DropData* WebContentsImpl::GetDropData() {
2813 return view_->GetDropData();
2814}
2815
2816void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042817 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452818}
2819
2820void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042821 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452822}
2823
2824void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042825 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452826}
2827
2828void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042829 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452830}
2831
[email protected]b172aee2012-04-10 17:05:262832void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272833 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212834 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542835 return;
2836 }
[email protected]0b431992014-06-24 00:08:032837 RenderWidgetHostView* const fullscreen_view =
2838 GetFullscreenRenderWidgetHostView();
2839 if (fullscreen_view) {
2840 fullscreen_view->Focus();
2841 return;
2842 }
creisc014b402015-04-23 16:41:452843 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542844}
2845
[email protected]b172aee2012-04-10 17:05:262846bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212847 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542848}
2849
[email protected]b172aee2012-04-10 17:05:262850InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212851 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222852}
2853
[email protected]b172aee2012-04-10 17:05:262854bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162855 // WebKit creates Document object when MIME type is application/xhtml+xml,
2856 // so we also support this MIME type.
2857 return contents_mime_type_ == "text/html" ||
2858 contents_mime_type_ == "text/xml" ||
2859 contents_mime_type_ == "application/xhtml+xml" ||
2860 contents_mime_type_ == "text/plain" ||
2861 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252862 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162863}
2864
[email protected]b172aee2012-04-10 17:05:262865void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592866 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162867 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552868 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192869 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142870 return;
[email protected]c7dd2f62011-07-18 15:57:592871 }
2872
2873 Stop();
2874
2875 // Create the save package and possibly prompt the user for the name to save
2876 // the page as. The user prompt is an asynchronous operation that runs on
2877 // another thread.
2878 save_package_ = new SavePackage(this);
2879 save_package_->GetSaveInfo();
2880}
2881
2882// Used in automated testing to bypass prompting the user for file names.
2883// Instead, the names and paths are hard coded rather than running them through
2884// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342885bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2886 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212887 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592888 // Stop the page from navigating.
2889 Stop();
2890
2891 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212892 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592893}
2894
[email protected]3c71576ce2013-07-23 02:00:012895void WebContentsImpl::SaveFrame(const GURL& url,
2896 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372897 SaveFrameWithHeaders(url, referrer, std::string());
2898}
2899
2900void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2901 const Referrer& referrer,
2902 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192903 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012904 return;
sammc92af61552014-11-19 23:27:402905 if (delegate_ && delegate_->SaveFrame(url, referrer))
2906 return;
2907
nasko89ad7742015-03-05 22:14:192908 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:222909 // by explicitly passing in which frame this method should target. This would
2910 // indicate whether it's the main frame, and also tell us the frame pointer
2911 // to use for routing.
nasko89ad7742015-03-05 22:14:192912 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:222913 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:012914
brettw760f7442016-05-23 21:19:222915 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
2916 GetBrowserContext(), frame_host->GetSiteInstance());
[email protected]3c71576ce2013-07-23 02:00:012917 DownloadManager* dlm =
2918 BrowserContext::GetDownloadManager(GetBrowserContext());
2919 if (!dlm)
2920 return;
avib7348942015-12-25 20:57:102921 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012922 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272923 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012924 if (entry)
2925 post_id = entry->GetPostID();
2926 }
brettw760f7442016-05-23 21:19:222927 std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
2928 url, frame_host->GetProcess()->GetID(),
2929 frame_host->GetRenderViewHost()->GetRoutingID(),
2930 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext()));
[email protected]3c71576ce2013-07-23 02:00:012931 params->set_referrer(referrer);
2932 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012933 if (post_id >= 0)
2934 params->set_method("POST");
2935 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372936
2937 if (headers.empty()) {
2938 params->set_prefer_cache(true);
2939 } else {
brettw26dab8f02015-08-08 00:28:472940 for (const base::StringPiece& key_value :
2941 base::SplitStringPiece(
2942 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2943 std::vector<std::string> pair = base::SplitString(
2944 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372945 DCHECK_EQ(2ul, pair.size());
2946 params->add_request_header(pair[0], pair[1]);
2947 }
2948 }
dcheng36b6aec92015-12-26 06:16:362949 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012950}
2951
[email protected]b172aee2012-04-10 17:05:262952void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:472953 const MHTMLGenerationParams& params,
avib7348942015-12-25 20:57:102954 const base::Callback<void(int64_t)>& callback) {
dewittj6dc5747a2016-05-17 01:48:472955 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
[email protected]aa4f3972012-03-01 18:12:122956}
2957
[email protected]b172aee2012-04-10 17:05:262958const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272959 return contents_mime_type_;
2960}
2961
[email protected]b172aee2012-04-10 17:05:262962bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272963 return notify_disconnection_;
2964}
2965
[email protected]8ff00d72012-10-23 19:12:212966RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272967 return &renderer_preferences_;
2968}
2969
[email protected]e35ccd52012-05-23 16:22:472970void WebContentsImpl::Close() {
2971 Close(GetRenderViewHost());
2972}
2973
paulmeyer8fc8ea92016-11-15 05:12:212974void WebContentsImpl::DragSourceEndedAt(int client_x,
2975 int client_y,
2976 int screen_x,
2977 int screen_y,
Paul Meyer0c58c3712016-11-17 22:59:512978 blink::WebDragOperation operation,
2979 RenderWidgetHost* source_rwh) {
[email protected]cf200a562013-05-03 16:24:292980 if (browser_plugin_embedder_.get())
paulmeyer8fc8ea92016-11-15 05:12:212981 browser_plugin_embedder_->DragSourceEndedAt(
2982 client_x, client_y, screen_x, screen_y, operation);
Paul Meyer0c58c3712016-11-17 22:59:512983 if (source_rwh) {
2984 source_rwh->DragSourceEndedAt(gfx::Point(client_x, client_y),
2985 gfx::Point(screen_x, screen_y),
2986 operation);
2987 }
[email protected]cf200a562013-05-03 16:24:292988}
2989
jam73f892642016-09-11 06:04:062990void WebContentsImpl::LoadStateChanged(
2991 const GURL& url,
2992 const net::LoadStateWithParam& load_state,
2993 uint64_t upload_position,
2994 uint64_t upload_size) {
2995 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2996 // is fixed.
2997 tracked_objects::ScopedTracker tracking_profile1(
2998 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2999 "466285 WebContentsImpl::LoadStateChanged::Start"));
3000 load_state_ = load_state;
3001 upload_position_ = upload_position;
3002 upload_size_ = upload_size;
3003 load_state_host_ = url_formatter::IDNToUnicode(url.host());
3004 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
3005 SetNotWaitingForResponse();
3006 if (IsLoading()) {
3007 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3008 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
3009 }
3010}
3011
[email protected]d60f3702013-12-26 16:30:243012void WebContentsImpl::DidGetResourceResponseStart(
3013 const ResourceRequestDetails& details) {
estarkf83ac122016-10-05 19:06:063014 controller_.ssl_manager()->DidStartResourceResponse(
3015 details.url, details.has_certificate, details.ssl_cert_status);
[email protected]d60f3702013-12-26 16:30:243016
ericwilligersde386342016-10-19 02:35:093017 for (auto& observer : observers_)
3018 observer.DidGetResourceResponseStart(details);
[email protected]d60f3702013-12-26 16:30:243019}
3020
3021void WebContentsImpl::DidGetRedirectForResourceRequest(
[email protected]d60f3702013-12-26 16:30:243022 const ResourceRedirectDetails& details) {
ericwilligersde386342016-10-19 02:35:093023 for (auto& observer : observers_)
3024 observer.DidGetRedirectForResourceRequest(details);
[email protected]d60f3702013-12-26 16:30:243025
3026 // TODO(avi): Remove. http://crbug.com/170921
3027 NotificationService::current()->Notify(
3028 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
3029 Source<WebContents>(this),
3030 Details<const ResourceRedirectDetails>(&details));
3031}
3032
calamity7fe55ce2015-04-10 03:59:373033void WebContentsImpl::NotifyWebContentsFocused() {
ericwilligersde386342016-10-19 02:35:093034 for (auto& observer : observers_)
3035 observer.OnWebContentsFocused();
calamity7fe55ce2015-04-10 03:59:373036}
3037
Paul Meyer0c58c3712016-11-17 22:59:513038void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
3039 if (source_rwh)
3040 source_rwh->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293041 if (browser_plugin_embedder_.get())
3042 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343043}
3044
[email protected]e35ccd52012-05-23 16:22:473045void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:533046 OnUserInteraction(GetRenderViewHost()->GetWidget(),
3047 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:473048}
3049
[email protected]b172aee2012-04-10 17:05:263050void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273051 closed_by_user_gesture_ = value;
3052}
3053
[email protected]b172aee2012-04-10 17:05:263054bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273055 return closed_by_user_gesture_;
3056}
3057
[email protected]b172aee2012-04-10 17:05:263058void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:503059 if (!delegate_)
3060 return;
3061
[email protected]6286a372013-10-09 04:03:273062 NavigationEntry* entry = GetController().GetLastCommittedEntry();
3063 if (!entry)
[email protected]1788e772010-12-15 16:40:503064 return;
3065
[email protected]6286a372013-10-09 04:03:273066 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:123067}
3068
[email protected]b172aee2012-04-10 17:05:263069void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:043070 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:273071 if (!delegate_)
3072 return;
3073
[email protected]691aa2f2013-05-28 22:52:043074 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:273075}
3076
[email protected]b172aee2012-04-10 17:05:263077int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273078 return minimum_zoom_percent_;
3079}
3080
[email protected]b172aee2012-04-10 17:05:263081int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273082 return maximum_zoom_percent_;
3083}
3084
mcnee432e47d2015-11-09 19:37:463085void WebContentsImpl::SetPageScale(float page_scale_factor) {
3086 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243087}
3088
[email protected]b172aee2012-04-10 17:05:263089gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:493090 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:233091}
3092
[email protected]b172aee2012-04-10 17:05:263093bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:053094 if (GetBrowserPluginGuest())
3095 return GetBrowserPluginGuest()->LockMouse(allowed);
3096
lfgad8244352016-07-13 16:55:513097 if (mouse_lock_widget_ &&
3098 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3099 return true;
3100
3101 mouse_lock_widget_ = nullptr;
lfgbee1e0a2016-06-08 21:24:213102 return false;
[email protected]0bfbf882011-12-22 18:19:273103}
3104
[email protected]b172aee2012-04-10 17:05:263105bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:213106 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:503107}
3108
alexmose201c7cd2015-06-10 17:14:213109WebContentsImpl* WebContentsImpl::GetOpener() const {
3110 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3111 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:573112}
3113
[email protected]cb805452013-05-22 15:16:213114void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:483115 if (!color_chooser_info_.get())
3116 return;
3117 RenderFrameHost* rfh = RenderFrameHost::FromID(
3118 color_chooser_info_->render_process_id,
3119 color_chooser_info_->render_frame_id);
3120 if (!rfh)
3121 return;
3122
3123 rfh->Send(new FrameMsg_DidChooseColorResponse(
3124 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:203125}
3126
[email protected]cb805452013-05-22 15:16:213127void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:483128 if (!color_chooser_info_.get())
3129 return;
3130 RenderFrameHost* rfh = RenderFrameHost::FromID(
3131 color_chooser_info_->render_process_id,
3132 color_chooser_info_->render_frame_id);
3133 if (!rfh)
3134 return;
3135
3136 rfh->Send(new FrameMsg_DidEndColorChooser(
3137 rfh->GetRoutingID(), color_chooser_info_->identifier));
3138 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:203139}
3140
halton.huoca2eabd2015-07-06 08:17:403141int WebContentsImpl::DownloadImage(
3142 const GURL& url,
3143 bool is_favicon,
3144 uint32_t max_bitmap_size,
3145 bool bypass_cache,
3146 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:553147 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403148 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063149 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403150 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553151 const int download_id = ++next_image_download_id;
3152 if (!mojo_image_downloader) {
3153 // If the renderer process is dead (i.e. crash, or memory pressure on
3154 // Android), the downloader service will be invalid. Pre-Mojo, this would
3155 // hang the callback indefinetly since the IPC would be dropped. Now,
3156 // respond with a 400 HTTP error code to indicate that something went wrong.
3157 BrowserThread::PostTask(
3158 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:193159 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:523160 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
leon.hanc2228532016-08-16 05:59:183161 std::vector<SkBitmap>(), std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553162 return download_id;
3163 }
3164
halton.huoca2eabd2015-07-06 08:17:403165 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393166 url, is_favicon, max_bitmap_size, bypass_cache,
leon.hancbc4bc3c2016-02-26 07:08:523167 base::Bind(&WebContentsImpl::OnDidDownloadImage,
3168 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:553169 return download_id;
[email protected]795c28972012-12-06 06:13:393170}
3171
[email protected]5dcaf8e2013-12-28 01:31:423172bool WebContentsImpl::IsSubframe() const {
3173 return is_subframe_;
3174}
3175
[email protected]36ec24f2014-01-09 00:32:083176void WebContentsImpl::Find(int request_id,
3177 const base::string16& search_text,
3178 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333179 // Cowardly refuse to search for no text.
3180 if (search_text.empty()) {
3181 NOTREACHED();
3182 return;
3183 }
3184
raymes0fa0be52014-10-13 20:38:093185 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173186 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473187 if (browser_plugin_embedder_ &&
3188 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3189 return;
raymes0fa0be52014-10-13 20:38:093190 }
paulmeyerc0b762b2016-04-13 11:55:173191
3192 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083193}
3194
3195void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013196 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173197 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473198 if (browser_plugin_embedder_ &&
3199 browser_plugin_embedder_->StopFinding(action)) {
3200 return;
raymes2bc64182015-02-06 01:23:013201 }
paulmeyerc0b762b2016-04-13 11:55:173202
3203 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083204}
3205
dalecurtisbc6572e12014-09-12 19:22:303206bool WebContentsImpl::WasRecentlyAudible() {
wjmaclean1dabf3e32016-05-13 23:34:443207 return audio_stream_monitor_.WasRecentlyAudible() ||
3208 (browser_plugin_embedder_ &&
3209 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:303210}
3211
mlamouriefdca9d2014-09-16 16:55:403212void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3213 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3214}
3215
bokanece34a82016-01-28 19:49:463216void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533217 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433218 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463219 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533220}
3221
mariakhomenko44bdc4732015-04-29 01:55:383222void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373223 if (delayed_open_url_params_.get()) {
3224 OpenURL(*delayed_open_url_params_.get());
3225 delayed_open_url_params_.reset(nullptr);
3226 return;
3227 }
3228
mariakhomenko44bdc4732015-04-29 01:55:383229 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3230 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163231 if (is_resume_pending_) {
3232 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133233 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163234 GetMainFrame()->Init();
3235 }
mariakhomenko44bdc4732015-04-29 01:55:383236}
3237
[email protected]b172aee2012-04-10 17:05:263238bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263239 // When the browser is started with about:blank as the startup URL, focus
3240 // the location bar (which will also select its contents) so people can
3241 // simply begin typing to navigate elsewhere.
3242 //
3243 // We need to be careful not to trigger this for anything other than the
3244 // startup navigation. In particular, if we allow an attacker to open a
3245 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3246 // end of the new URL to be scrolled into view instead of the start,
3247 // allowing the attacker to spoof other URLs. The conditions checked here
3248 // are all aimed at ensuring no such attacker-controlled navigation can
3249 // trigger this.
3250 //
3251 // Note that we check the pending entry instead of the visible one; for the
3252 // startup URL case these are the same, but for the attacker-controlled
3253 // navigation case the visible entry is the committed "about:blank" URL and
3254 // the pending entry is the problematic navigation elsewhere.
3255 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3256 if (controller_.IsInitialNavigation() && entry &&
3257 !entry->is_renderer_initiated() &&
csharrisona3bd0b32016-10-19 18:40:483258 entry->GetURL() == url::kAboutBlankURL) {
[email protected]0c9406632013-02-08 01:13:333259 return true;
palmerc70cb1f2016-03-04 23:41:263260 }
[email protected]0c9406632013-02-08 01:13:333261 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273262}
3263
[email protected]b172aee2012-04-10 17:05:263264void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273265 if (delegate_)
3266 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213267}
3268
clamy0e119882015-07-31 16:12:333269void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093270 for (auto& observer : observers_)
3271 observer.DidStartNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333272}
3273
3274void WebContentsImpl::DidRedirectNavigation(
3275 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093276 for (auto& observer : observers_)
3277 observer.DidRedirectNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333278}
3279
clamyefca29e2015-09-17 00:22:113280void WebContentsImpl::ReadyToCommitNavigation(
3281 NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093282 for (auto& observer : observers_)
3283 observer.ReadyToCommitNavigation(navigation_handle);
clamyefca29e2015-09-17 00:22:113284}
3285
clamy0e119882015-07-31 16:12:333286void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
ericwilligersde386342016-10-19 02:35:093287 for (auto& observer : observers_)
3288 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:333289}
3290
[email protected]52913802013-12-10 05:52:183291void WebContentsImpl::DidStartProvisionalLoad(
3292 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183293 const GURL& validated_url,
3294 bool is_error_page,
3295 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103296 // Notify observers about the start of the provisional load.
ericwilligersde386342016-10-19 02:35:093297 for (auto& observer : observers_) {
3298 observer.DidStartProvisionalLoadForFrame(render_frame_host, validated_url,
3299 is_error_page, is_iframe_srcdoc);
3300 }
dmazzonibf8cec42015-02-08 08:28:083301
3302 // Notify accessibility if this is a reload.
3303 NavigationEntry* entry = controller_.GetVisibleEntry();
3304 if (entry && ui::PageTransitionCoreTypeIs(
3305 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3306 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3307 BrowserAccessibilityManager* manager =
3308 ftn->current_frame_host()->browser_accessibility_manager();
3309 if (manager)
3310 manager->UserIsReloading();
3311 }
[email protected]400992b2012-06-14 00:03:543312}
3313
[email protected]3109fbb72014-01-06 23:57:153314void WebContentsImpl::DidFailProvisionalLoadWithError(
3315 RenderFrameHostImpl* render_frame_host,
lazyboy552a9382016-07-14 20:38:373316 const GURL& validated_url,
3317 int error_code,
3318 const base::string16& error_description,
3319 bool was_ignored_by_handler) {
ericwilligersde386342016-10-19 02:35:093320 for (auto& observer : observers_) {
3321 observer.DidFailProvisionalLoad(render_frame_host, validated_url,
3322 error_code, error_description,
3323 was_ignored_by_handler);
3324 }
dmazzonibf8cec42015-02-08 08:28:083325
3326 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3327 BrowserAccessibilityManager* manager =
3328 ftn->current_frame_host()->browser_accessibility_manager();
3329 if (manager)
3330 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153331}
3332
[email protected]b80624c2014-02-09 02:46:553333void WebContentsImpl::DidFailLoadWithError(
3334 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553335 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553336 int error_code,
gsennton6fbb38692015-06-24 19:23:553337 const base::string16& error_description,
3338 bool was_ignored_by_handler) {
ericwilligersde386342016-10-19 02:35:093339 for (auto& observer : observers_) {
3340 observer.DidFailLoad(render_frame_host, url, error_code, error_description,
3341 was_ignored_by_handler);
3342 }
[email protected]b80624c2014-02-09 02:46:553343}
3344
[email protected]52913802013-12-10 05:52:183345void WebContentsImpl::NotifyChangedNavigationState(
3346 InvalidateTypes changed_flags) {
3347 NotifyNavigationStateChanged(changed_flags);
3348}
3349
toyoshim0df1d3a2016-09-09 09:52:483350void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
3351 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:203352 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093353 for (auto& observer : observers_)
3354 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:203355}
3356
[email protected]8cb834e2014-03-06 14:23:233357void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3358 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503359 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3360 // weak pointer of sorts.
3361 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3362 const int32_t frame_id = render_frame_host->GetRoutingID();
3363
[email protected]65920f332014-03-04 21:14:183364 WebContents* new_contents = OpenURL(params);
3365
dchengb907f7332015-01-07 20:35:503366 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183367 // Notify observers.
ericwilligersde386342016-10-19 02:35:093368 for (auto& observer : observers_) {
3369 observer.DidOpenRequestedURL(new_contents, render_frame_host, params.url,
3370 params.referrer, params.disposition,
3371 params.transition);
3372 }
[email protected]65920f332014-03-04 21:14:183373 }
3374}
3375
lukasza1d025732016-09-28 21:36:083376bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:223377 if (!delegate_)
3378 return true;
lukasza1d025732016-09-28 21:36:083379 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:223380}
3381
[email protected]aa62afd2014-04-22 19:22:463382bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3383 if (!delegate_)
3384 return false;
3385 return delegate_->ShouldPreserveAbortedURLs(this);
3386}
3387
[email protected]37567b432014-02-12 01:12:223388void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433389 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223390 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353391 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223392 // Notify observers about the commit of the provisional load.
ericwilligersde386342016-10-19 02:35:093393 for (auto& observer : observers_) {
3394 observer.DidCommitProvisionalLoadForFrame(render_frame_host, url,
3395 transition_type);
3396 }
dmazzonibf8cec42015-02-08 08:28:083397
3398 BrowserAccessibilityManager* manager =
3399 render_frame_host->browser_accessibility_manager();
3400 if (manager)
3401 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223402}
3403
[email protected]0d0f4c492014-04-02 06:42:573404void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233405 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573406 // Ensure fullscreen mode is exited before committing the navigation to a
3407 // different page. The next page will not start out assuming it is in
3408 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233409 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193410 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573411 return;
3412 }
alexmos5dd617d2016-06-07 04:21:153413 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:463414 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:153415 DCHECK(!IsFullscreenForCurrentTab());
[email protected]0d0f4c492014-04-02 06:42:573416}
3417
[email protected]37567b432014-02-12 01:12:223418void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283419 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223420 const LoadCommittedDetails& details,
3421 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3422 if (details.is_navigation_to_different_page()) {
3423 // Clear the status bubble. This is a workaround for a bug where WebKit
3424 // doesn't let us know that the cursor left an element during a
3425 // transition (this is also why the mouse cursor remains as a hand after
3426 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3427 // clear the bubble when a user navigates to a named anchor in the same
3428 // page.
sky8b00392d2015-01-10 00:30:283429 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003430
3431 RenderWidgetHostViewBase* rwhvb =
3432 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3433 if (rwhvb)
3434 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283435
peter90afaba2015-06-01 12:05:293436 did_first_visually_non_empty_paint_ = false;
3437
yusufod41c5f92015-03-06 00:14:283438 // Reset theme color on navigation to new page.
3439 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223440 }
3441
[email protected]37567b432014-02-12 01:12:223442 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093443 for (auto& observer : observers_)
3444 observer.DidNavigateMainFrame(details, params);
[email protected]37567b432014-02-12 01:12:223445
[email protected]e85165c642014-06-10 14:34:313446 if (delegate_)
[email protected]37567b432014-02-12 01:12:223447 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313448 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223449}
3450
3451void WebContentsImpl::DidNavigateAnyFramePostCommit(
3452 RenderFrameHostImpl* render_frame_host,
3453 const LoadCommittedDetails& details,
3454 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103455 // Now that something has committed, we don't need to track whether the
3456 // initial page has been accessed.
3457 has_accessed_initial_document_ = false;
3458
[email protected]37567b432014-02-12 01:12:223459 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173460 if (!details.is_in_page)
3461 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223462
avid53461d2016-02-25 17:15:043463 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3464 // again.
avi5d3b8692016-10-12 22:00:463465 if (params.gesture == NavigationGestureUser && dialog_manager_) {
3466 dialog_manager_->CancelDialogs(this,
3467 false, // suppress_callbacks,
3468 true); // reset_state
3469 }
avid53461d2016-02-25 17:15:043470
[email protected]37567b432014-02-12 01:12:223471 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093472 for (auto& observer : observers_)
3473 observer.DidNavigateAnyFrame(render_frame_host, details, params);
[email protected]37567b432014-02-12 01:12:223474}
3475
3476void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3477 contents_mime_type_ = mime_type;
3478}
3479
[email protected]277857a2014-06-03 10:38:013480bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313481 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053482 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313483 return false;
3484
[email protected]37567b432014-02-12 01:12:223485 if (delegate_)
3486 return delegate_->CanOverscrollContent();
3487
3488 return false;
3489}
3490
[email protected]37b64c52014-07-11 21:14:053491void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293492 // Update the theme color. This is to be published to observers after the
3493 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283494 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293495
3496 if (did_first_visually_non_empty_paint_ &&
3497 last_sent_theme_color_ != theme_color_) {
ericwilligersde386342016-10-19 02:35:093498 for (auto& observer : observers_)
3499 observer.DidChangeThemeColor(theme_color_);
peter90afaba2015-06-01 12:05:293500 last_sent_theme_color_ = theme_color_;
3501 }
[email protected]e7104762014-06-20 19:17:253502}
3503
[email protected]b172aee2012-04-10 17:05:263504void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183505 const GURL& url,
[email protected]70435962011-08-02 20:13:283506 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183507 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403508 ResourceType resource_type) {
ericwilligersde386342016-10-19 02:35:093509 for (auto& observer : observers_)
3510 observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type);
[email protected]b0f724c2013-09-05 04:21:133511
[email protected]8bfc8272013-09-09 20:10:533512 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3513 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403514 resource_type == RESOURCE_TYPE_MEDIA ?
jam2503f932016-04-15 20:08:303515 GetRenderProcessHost()->GetStoragePartition()->
3516 GetMediaURLRequestContext() :
jam608f2992016-03-31 16:35:343517 GetRenderProcessHost()->GetStoragePartition()->
3518 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533519 BrowserThread::PostTask(
3520 BrowserThread::IO,
3521 FROM_HERE,
3522 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3523 }
[email protected]724159a2010-12-30 01:11:183524}
3525
[email protected]b172aee2012-04-10 17:05:263526void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393527 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
estarkc2273502016-10-12 22:03:023528 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:183529}
3530
estark910b4572015-12-09 20:55:413531void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3532 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583533 LOG(WARNING) << security_origin << " ran insecure content from "
3534 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393535 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413536 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293537 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393538 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:023539 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:183540}
3541
estark910b4572015-12-09 20:55:413542void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
jama385e112016-07-22 00:07:583543 const GURL& url) {
estarkc2273502016-10-12 22:03:023544 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:413545}
3546
3547void WebContentsImpl::OnDidRunContentWithCertificateErrors(
jama385e112016-07-22 00:07:583548 const GURL& url) {
estarkcd2e30c2016-08-12 06:51:153549 NavigationEntry* entry = controller_.GetVisibleEntry();
3550 if (!entry)
estarkaeda1422016-05-10 02:31:123551 return;
3552
estarkaeda1422016-05-10 02:31:123553 // TODO(estark): check that this does something reasonable for
3554 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:153555 controller_.ssl_manager()->DidRunContentWithCertErrors(
3556 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:413557}
3558
[email protected]501052ff2014-02-21 22:19:073559void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113560 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473561 return;
naskofbd033392015-01-27 02:34:473562
[email protected]1d62cf72014-02-07 21:31:573563 RenderFrameHostImpl* rfh =
3564 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
ericwilligersde386342016-10-19 02:35:093565 for (auto& observer : observers_)
3566 observer.DocumentLoadedInFrame(rfh);
[email protected]724159a2010-12-30 01:11:183567}
3568
naskofbd033392015-01-27 02:34:473569void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113570 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123571 return;
[email protected]a1b99262013-12-27 21:56:223572
[email protected]8b3af1e2014-01-24 13:29:123573 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443574 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373575 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423576 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373577
[email protected]61ac9e242014-03-21 20:55:263578 RenderFrameHostImpl* rfh =
3579 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
ericwilligersde386342016-10-19 02:35:093580 for (auto& observer : observers_)
3581 observer.DidFinishLoad(rfh, validated_url);
[email protected]1a55c5be2011-11-29 11:36:313582}
3583
[email protected]b172aee2012-04-10 17:05:263584void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573585 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3586 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263587}
3588
[email protected]b172aee2012-04-10 17:05:263589void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303590 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263591 minimum_zoom_percent_ = minimum_percent;
3592 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263593}
3594
mcnee432e47d2015-11-09 19:37:463595void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3596 bool is_one = page_scale_factor == 1.f;
3597 if (is_one != page_scale_factor_is_one_) {
3598 page_scale_factor_is_one_ = is_one;
3599
3600 HostZoomMapImpl* host_zoom_map =
3601 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3602
3603 if (host_zoom_map && GetRenderProcessHost()) {
3604 host_zoom_map->SetPageScaleFactorIsOneForView(
3605 GetRenderProcessHost()->GetID(), GetRoutingID(),
3606 page_scale_factor_is_one_);
3607 }
3608 }
3609
ericwilligersde386342016-10-19 02:35:093610 for (auto& observer : observers_)
3611 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:463612}
3613
[email protected]b172aee2012-04-10 17:05:263614void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343615 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433616 if (!delegate_)
3617 return;
3618
[email protected]b9535422012-02-09 01:47:593619 ChildProcessSecurityPolicyImpl* policy =
3620 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223621 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593622 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213623}
3624
[email protected]b172aee2012-04-10 17:05:263625void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3626 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263627 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363628 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433629 if (!delegate_)
3630 return;
3631
[email protected]b9535422012-02-09 01:47:593632 ChildProcessSecurityPolicyImpl* policy =
3633 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323634 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593635 return;
[email protected]8f810632013-06-06 22:33:323636
[email protected]c125e532014-05-10 20:39:063637 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203638}
3639
[email protected]f5273e52014-07-14 16:30:203640void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3641 const GURL& url,
3642 bool user_gesture) {
3643 if (!delegate_)
3644 return;
3645
3646 ChildProcessSecurityPolicyImpl* policy =
3647 ChildProcessSecurityPolicyImpl::GetInstance();
3648 if (policy->IsPseudoScheme(protocol))
3649 return;
3650
3651 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3652}
3653
kouhei40f03cb2015-09-24 07:47:013654void WebContentsImpl::OnUpdatePageImportanceSignals(
3655 const PageImportanceSignals& signals) {
3656 page_importance_signals_ = signals;
3657}
3658
[email protected]b172aee2012-04-10 17:05:263659void WebContentsImpl::OnFindReply(int request_id,
3660 int number_of_matches,
3661 const gfx::Rect& selection_rect,
3662 int active_match_ordinal,
3663 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173664 // Forward the find reply to the FindRequestManager, along with the
3665 // RenderFrameHost associated with the frame that the reply came from.
3666 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3667 request_id,
3668 number_of_matches,
3669 selection_rect,
3670 active_match_ordinal,
3671 final_update);
[email protected]b888919c2011-09-02 00:32:163672}
3673
mfomitchev2b8b066a2016-01-28 19:23:153674#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313675void WebContentsImpl::OnFindMatchRectsReply(
3676 int version,
3677 const std::vector<gfx::RectF>& rects,
3678 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173679 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3680 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313681}
[email protected]583418cc2013-01-17 14:01:103682
paulmeyerc8cb7cb2016-06-07 01:14:193683void WebContentsImpl::OnGetNearestFindResultReply(int request_id,
3684 float distance) {
3685 GetOrCreateFindRequestManager()->OnGetNearestFindResultReply(
3686 render_frame_message_source_, request_id, distance);
3687}
3688
[email protected]1ff427972013-02-07 21:14:073689void WebContentsImpl::OnOpenDateTimeDialog(
3690 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173691 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093692 GetRenderViewHost(),
3693 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133694 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093695 value.minimum,
3696 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173697 value.step,
3698 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103699}
[email protected]59363fc92012-09-05 03:46:313700#endif
3701
avi60bd4902015-09-23 20:39:243702void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3703 std::string json = json_string;
3704 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3705 Source<WebContents>(this),
3706 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403707}
3708
[email protected]b172aee2012-04-10 17:05:263709void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3710 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103711 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:093712 for (auto& observer : observers_)
3713 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:103714}
3715
[email protected]8bc5ff02013-11-29 06:34:033716void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483717 int color_chooser_id,
3718 SkColor color,
3719 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113720 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003721 return;
nasko907fcb62015-01-28 04:24:113722
[email protected]aa62afd2014-04-22 19:22:463723 ColorChooser* new_color_chooser = delegate_ ?
3724 delegate_->OpenColorChooser(this, color, suggestions) :
3725 NULL;
[email protected]820957a2014-01-14 14:56:303726 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213727 return;
[email protected]8ed16472014-04-11 19:02:483728 if (color_chooser_info_.get())
3729 color_chooser_info_->chooser->End();
3730
3731 color_chooser_info_.reset(new ColorChooserInfo(
3732 render_frame_message_source_->GetProcess()->GetID(),
3733 render_frame_message_source_->GetRoutingID(),
3734 new_color_chooser,
3735 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203736}
3737
[email protected]b172aee2012-04-10 17:05:263738void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483739 if (color_chooser_info_ &&
3740 color_chooser_id == color_chooser_info_->identifier)
3741 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203742}
3743
[email protected]b172aee2012-04-10 17:05:263744void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323745 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483746 if (color_chooser_info_ &&
3747 color_chooser_id == color_chooser_info_->identifier)
3748 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.
3753void WebContentsImpl::OnWebUISend(const GURL& source_url,
3754 const std::string& name,
3755 const base::ListValue& args) {
3756 if (delegate_)
3757 delegate_->WebUISend(this, source_url, name, args);
3758}
3759
brettw4b461082016-11-19 18:55:163760#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:173761void WebContentsImpl::OnPepperInstanceCreated(int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:093762 for (auto& observer : observers_)
3763 observer.PepperInstanceCreated();
zqzhang181047e62016-07-01 13:37:173764 pepper_playback_observer_->PepperInstanceCreated(pp_instance);
emaxxe70f5e12015-05-29 11:26:003765}
3766
zqzhang181047e62016-07-01 13:37:173767void WebContentsImpl::OnPepperInstanceDeleted(int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:093768 for (auto& observer : observers_)
3769 observer.PepperInstanceDeleted();
zqzhang181047e62016-07-01 13:37:173770 pepper_playback_observer_->PepperInstanceDeleted(pp_instance);
emaxxe70f5e12015-05-29 11:26:003771}
3772
tommyclie6633ca72014-10-31 00:40:423773void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3774 const base::FilePath& path,
3775 bool is_hung) {
3776 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3777
ericwilligersde386342016-10-19 02:35:093778 for (auto& observer : observers_)
3779 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:423780}
3781
zqzhang181047e62016-07-01 13:37:173782void WebContentsImpl::OnPepperStartsPlayback(int32_t pp_instance) {
3783 pepper_playback_observer_->PepperStartsPlayback(pp_instance);
3784}
3785
3786void WebContentsImpl::OnPepperStopsPlayback(int32_t pp_instance) {
3787 pepper_playback_observer_->PepperStopsPlayback(pp_instance);
3788}
3789
tommyclie6633ca72014-10-31 00:40:423790void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3791 base::ProcessId plugin_pid) {
ericwilligersde386342016-10-19 02:35:093792 for (auto& observer : observers_)
3793 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:423794}
3795
[email protected]d8415ad92012-08-23 14:40:503796void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443797 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503798 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343799 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163800 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443801 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163802 return;
[email protected]d8415ad92012-08-23 14:40:503803 }
3804
[email protected]8c8fc292012-11-23 18:57:163805 if (!delegate_->RequestPpapiBrokerPermission(
3806 this, url, plugin_path,
3807 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443808 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163809 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443810 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163811 }
[email protected]d8415ad92012-08-23 14:40:503812}
3813
[email protected]ea0309c2013-08-06 19:35:443814void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503815 bool result) {
[email protected]ea0309c2013-08-06 19:35:443816 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503817}
3818
fsamuel833ee7c2015-02-13 23:40:403819void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3820 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393821 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143822 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403823 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373824}
brettw4b461082016-11-19 18:55:163825#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373826
[email protected]795c28972012-12-06 06:13:393827void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393828 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063829 // We get updated favicon URLs after the page stops loading. If a cross-site
3830 // navigation occurs while a page is still loading, the initial page
3831 // may stop loading and send us updated favicon URLs after the navigation
3832 // for the new page has committed.
3833 RenderViewHostImpl* rvhi =
3834 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3835 if (!rvhi->is_active())
3836 return;
3837
ericwilligersde386342016-10-19 02:35:093838 for (auto& observer : observers_)
3839 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:393840}
3841
estark703f1b42016-10-10 21:37:153842void WebContentsImpl::OnPasswordInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023843 controller_.ssl_manager()->DidShowPasswordInputOnHttp();
estark703f1b42016-10-10 21:37:153844}
3845
estarkfae6b5872016-11-04 05:20:313846void WebContentsImpl::OnAllPasswordInputsHiddenOnHttp() {
3847 controller_.ssl_manager()->DidHideAllPasswordInputsOnHttp();
3848}
3849
estark703f1b42016-10-10 21:37:153850void WebContentsImpl::OnCreditCardInputShownOnHttp() {
estarkc2273502016-10-12 22:03:023851 controller_.ssl_manager()->DidShowCreditCardInputOnHttp();
estark703f1b42016-10-10 21:37:153852}
3853
qinmin72e8bd02016-10-21 19:35:373854void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
3855 is_overlay_content_ = is_overlay_content;
3856}
3857
[email protected]50279492014-05-05 23:24:293858void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
ericwilligersde386342016-10-19 02:35:093859 for (auto& observer : observers_)
3860 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:283861
peter90afaba2015-06-01 12:05:293862 did_first_visually_non_empty_paint_ = true;
3863
yusufod41c5f92015-03-06 00:14:283864 if (theme_color_ != last_sent_theme_color_) {
3865 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:093866 for (auto& observer : observers_)
3867 observer.DidChangeThemeColor(theme_color_);
yusufod41c5f92015-03-06 00:14:283868 last_sent_theme_color_ = theme_color_;
3869 }
[email protected]9f268072013-11-07 00:02:153870}
[email protected]d9030b82013-07-19 08:26:063871
[email protected]17e286e2013-03-01 23:29:393872void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:093873 for (auto& observer : observers_)
3874 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:393875}
3876
[email protected]ec6c05f2013-10-23 18:41:573877void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3878 Activate();
3879 if (delegate_)
3880 delegate_->ShowRepostFormWarningDialog(this);
3881}
3882
[email protected]b4c84012014-04-28 19:51:103883bool WebContentsImpl::HasAccessedInitialDocument() {
3884 return has_accessed_initial_document_;
3885}
3886
afakhry6f0c1ec22016-07-14 13:55:133887void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:263888 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323889 // For file URLs without a title, use the pathname instead. In the case of a
3890 // synthesized title, we don't want the update to count toward the "one set
3891 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263892 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323893 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513894 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243895 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323896 explicit_set = false; // Don't count synthetic titles toward the set limit.
3897 } else {
[email protected]8af69c6c2014-03-03 19:05:313898 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323899 explicit_set = true;
3900 }
3901
[email protected]987fc3a2011-05-26 14:18:093902 // If a page is created via window.open and never navigated,
3903 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553904 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093905 if (entry) {
[email protected]36fc0392011-12-25 03:59:513906 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:133907 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323908
[email protected]36fc0392011-12-25 03:59:513909 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093910 } else {
3911 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:133912 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:093913
3914 page_title_when_no_navigation_entry_ = final_title;
3915 }
[email protected]420ae012009-04-24 05:16:323916
[email protected]420ae012009-04-24 05:16:323917 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233918 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323919
ericwilligersde386342016-10-19 02:35:093920 for (auto& observer : observers_)
3921 observer.TitleWasSet(entry, explicit_set);
[email protected]66798902013-10-01 18:40:163922
afakhry6f0c1ec22016-07-14 13:55:133923 // Broadcast notifications when the UI should be updated.
3924 if (entry == controller_.GetEntryAtOffset(0))
3925 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323926}
3927
fdegansa696e5112015-04-17 01:57:593928void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003929 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003930 if (delegate_)
fdegansa696e5112015-04-17 01:57:593931 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003932}
3933
3934void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343935 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003936 loading_weak_factory_.InvalidateWeakPtrs();
3937 loading_last_progress_update_ = base::TimeTicks();
3938}
3939
clamy44e84ce2016-02-22 15:38:253940// Notifies the RenderWidgetHost instance about the fact that the page is
3941// loading, or done loading.
3942void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3943 bool due_to_interstitial,
3944 LoadNotificationDetails* details) {
3945 // Do not send notifications about loading changes in the FrameTree while the
3946 // interstitial page is pausing the throbber.
3947 if (ShowingInterstitialPage() &&
3948 GetRenderManager()->interstitial_page()->pause_throbber() &&
3949 !due_to_interstitial) {
3950 return;
3951 }
3952
3953 bool is_loading = IsLoading();
3954
3955 if (!is_loading) {
3956 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3957 base::string16());
3958 load_state_host_.clear();
3959 upload_size_ = 0;
3960 upload_position_ = 0;
3961 }
3962
3963 GetRenderManager()->SetIsLoading(is_loading);
3964
3965 waiting_for_response_ = is_loading;
3966 is_load_to_different_document_ = to_different_document;
3967
3968 if (delegate_)
3969 delegate_->LoadingStateChanged(this, to_different_document);
3970 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3971
3972 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3973 if (is_loading) {
3974 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3975 this, "URL", url, "Main FrameTreeNode id",
3976 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:093977 for (auto& observer : observers_)
3978 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:253979 } else {
3980 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3981 this, "URL", url);
ericwilligersde386342016-10-19 02:35:093982 for (auto& observer : observers_)
3983 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:253984 }
3985
3986 // TODO(avi): Remove. http://crbug.com/170921
3987 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3988 NotificationDetails det = NotificationService::NoDetails();
3989 if (details)
3990 det = Details<LoadNotificationDetails>(details);
3991 NotificationService::current()->Notify(
3992 type, Source<NavigationController>(&controller_), det);
3993}
3994
[email protected]02d7b6e2014-06-24 21:01:503995void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3996 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323997 // After sending out a swap notification, we need to send a disconnect
3998 // notification so that clients that pick up a pointer to |this| can NULL the
3999 // pointer. See Bug 1230284.
4000 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:094001 for (auto& observer : observers_)
4002 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:114003
[email protected]7a846df2012-09-20 19:17:394004 // Ensure that the associated embedder gets cleared after a RenderViewHost
4005 // gets swapped, so we don't reuse the same embedder next time a
4006 // RenderViewHost is attached to this WebContents.
4007 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324008}
4009
[email protected]02d7b6e2014-06-24 21:01:504010void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4011 RenderFrameHost* new_host) {
chrishtr95e39532016-11-10 00:05:214012 // Copies the background color from an old WebContents to a new one that
4013 // replaces it on the screen. This allows the new WebContents to use the
4014 // old one's background color as the starting background color, before having
4015 // loaded any contents. As a result, we avoid flashing white when navigating
4016 // from a site whith a dark background to another site with a dark background.
4017 if (old_host && new_host) {
4018 RenderWidgetHostView* old_view = old_host->GetView();
4019 RenderWidgetHostView* new_view = new_host->GetView();
4020 if (old_view && new_view)
4021 new_view->SetBackgroundColor(old_view->background_color());
4022 }
4023
ericwilligersde386342016-10-19 02:35:094024 for (auto& observer : observers_)
4025 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:504026}
4027
[email protected]da7a7182013-09-06 08:11:114028// TODO(avi): Remove this entire function because this notification is already
4029// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264030void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324031 if (!notify_disconnection_)
4032 return;
4033
4034 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214035 NotificationService::current()->Notify(
4036 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4037 Source<WebContents>(this),
4038 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324039}
4040
[email protected]cbb1ef592013-06-05 19:49:464041void WebContentsImpl::NotifyNavigationEntryCommitted(
4042 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:094043 for (auto& observer : observers_)
4044 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:464045}
4046
[email protected]f114fa42013-12-06 17:06:444047bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
4048 const IPC::Message& message) {
4049 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:314050}
4051
rockotf62002a2016-09-15 00:08:594052void WebContentsImpl::OnAssociatedInterfaceRequest(
4053 RenderFrameHost* render_frame_host,
4054 const std::string& interface_name,
4055 mojo::ScopedInterfaceEndpointHandle handle) {
4056 auto it = binding_sets_.find(interface_name);
4057 if (it != binding_sets_.end())
4058 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
4059}
4060
[email protected]c31a84802014-04-03 15:55:494061const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
4062 return GetLastCommittedURL();
4063}
4064
[email protected]b849847b2013-12-10 21:57:584065void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094066 for (auto& observer : observers_)
4067 observer.RenderFrameCreated(render_frame_host);
[email protected]95640212014-07-26 18:14:304068 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:454069
4070 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
4071 return;
4072
4073 NavigationEntry* entry = controller_.GetPendingEntry();
4074 if (entry && entry->IsViewSourceMode()) {
4075 // Put the renderer in view source mode.
4076 render_frame_host->Send(
4077 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
4078 }
sammc5a139ba2016-09-29 01:49:144079#if defined(OS_ANDROID)
4080 render_frame_host->GetInterfaceRegistry()->AddInterface(
4081 GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>());
4082#endif
[email protected]b849847b2013-12-10 21:57:584083}
4084
4085void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094086 for (auto& observer : observers_)
4087 observer.RenderFrameDeleted(render_frame_host);
[email protected]b849847b2013-12-10 21:57:584088}
4089
[email protected]a09d53ce2014-01-31 00:46:424090void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
4091 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:104092 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:424093 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:104094 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:424095 return;
4096
[email protected]077e704b2014-05-23 19:24:104097 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
4098 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:424099}
4100
[email protected]87de04b02014-04-08 22:14:494101void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:014102 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494103 const base::string16& message,
4104 const base::string16& default_prompt,
4105 const GURL& frame_url,
4106 JavaScriptMessageType javascript_message_type,
4107 IPC::Message* reply_msg) {
4108 // Suppress JavaScript dialogs when requested. Also suppress messages when
4109 // showing an interstitial as it's shown over the previous page and we don't
4110 // want the hidden page's dialogs to interfere with the interstitial.
4111 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:504112 ShowingInterstitialPage() || !delegate_ ||
4113 delegate_->ShouldSuppressDialogs(this) ||
4114 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494115
4116 if (!suppress_this_message) {
avi85ee8362016-10-08 02:09:084117 is_showing_javascript_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504118 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494119 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:034120 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:414121 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014122 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:414123 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:494124 &suppress_this_message);
4125 }
4126
4127 if (suppress_this_message) {
4128 // If we are suppressing messages, just reply as if the user immediately
4129 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:014130 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
4131 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284132 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:494133 }
4134
4135 // OnDialogClosed (two lines up) may have caused deletion of this object (see
4136 // http://crbug.com/288961 ). The only safe thing to do here is return.
4137}
4138
4139void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014140 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494141 bool is_reload,
4142 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014143 RenderFrameHostImpl* rfhi =
4144 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494145 if (delegate_)
4146 delegate_->WillRunBeforeUnloadConfirm();
4147
4148 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454149 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024150 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504151 delegate_->ShouldSuppressDialogs(this) ||
4152 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494153 if (suppress_this_message) {
4154 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4155 return;
4156 }
4157
4158 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504159 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494160 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424161 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494162 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014163 render_frame_host->GetProcess()->GetID(),
4164 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284165 false));
[email protected]87de04b02014-04-08 22:14:494166}
4167
naskoada75b22016-06-11 16:09:464168void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
4169 const FileChooserParams& params) {
4170 if (delegate_)
4171 delegate_->RunFileChooser(render_frame_host, params);
4172}
4173
[email protected]a86c0e962013-12-17 17:10:394174WebContents* WebContentsImpl::GetAsWebContents() {
4175 return this;
4176}
4177
wjmaclean64951902016-04-29 20:59:124178double WebContentsImpl::GetPendingPageZoomLevel() {
4179 NavigationEntry* pending_entry = GetController().GetPendingEntry();
4180 if (!pending_entry)
4181 return HostZoomMap::GetZoomLevel(this);
4182
4183 GURL url = pending_entry->GetURL();
4184 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
4185 url.scheme(), net::GetHostOrSpecFromURL(url));
4186}
4187
qinmin72e8bd02016-10-21 19:35:374188bool WebContentsImpl::HideDownloadUI() const {
4189 return is_overlay_content_;
4190}
4191
[email protected]7912e822014-04-16 02:37:034192bool WebContentsImpl::IsNeverVisible() {
4193 if (!delegate_)
4194 return false;
4195 return delegate_->IsNeverVisible(this);
4196}
4197
[email protected]5a3bdf52012-05-24 15:12:574198RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4199 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324200}
4201
[email protected]8ff00d72012-10-23 19:12:214202RendererPreferences WebContentsImpl::GetRendererPrefs(
4203 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464204 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514205}
4206
[email protected]7a846df2012-09-20 19:17:394207void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274208 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394209 browser_plugin_embedder_.reset();
4210}
4211
avallee0206f782016-07-28 18:55:334212WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
ekaramad1beabecc2016-09-23 20:18:174213 if (GuestMode::IsCrossProcessFrameGuest(this) && node_)
4214 return node_->outer_web_contents();
4215
4216 if (browser_plugin_guest_)
4217 return browser_plugin_guest_->embedder_web_contents();
4218
avallee0206f782016-07-28 18:55:334219 return nullptr;
4220}
4221
4222WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
4223 // There is no inner or outer web contents.
4224 if (!node_ && !GetBrowserPluginGuest())
4225 return this;
4226
4227 // We may need to create a node_ on the outermost contents in the
4228 // BrowserPlugin case.
4229 WebContentsImpl* outermost = GetOutermostWebContents();
4230 if (!outermost->node_) {
4231 outermost->node_.reset(new WebContentsTreeNode());
4232 outermost->node_->SetFocusedWebContents(outermost);
4233 }
4234 return outermost->node_->focused_web_contents();
4235}
4236
avallee9993fca2016-11-17 06:16:504237bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
4238 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
4239 focused_contents;
4240 focused_contents = focused_contents->GetOuterWebContents()) {
4241 if (focused_contents == this)
4242 return true;
4243 }
4244
4245 return false;
4246}
4247
avallee0206f782016-07-28 18:55:334248WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
4249 WebContentsImpl* root = this;
4250 while (root->GetOuterWebContents())
4251 root = root->GetOuterWebContents();
4252 return root;
4253}
4254
[email protected]b172aee2012-04-10 17:05:264255void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444256 // Don't send notifications if we are just creating a swapped-out RVH for
4257 // the opener chain. These won't be used for view-source or WebUI, so it's
4258 // ok to return early.
creiscce56cd2014-09-29 22:45:224259 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444260 return;
4261
[email protected]86f98a22013-03-20 14:35:004262 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314263 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084264
[email protected]8ff00d72012-10-23 19:12:214265 NotificationService::current()->Notify(
4266 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4267 Source<WebContents>(this),
4268 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324269
[email protected]60780f412013-02-25 16:34:104270 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264271
ericwilligersde386342016-10-19 02:35:094272 for (auto& observer : observers_)
4273 observer.RenderViewCreated(render_view_host);
dgozmanf00c4f72016-10-19 17:45:154274 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:324275}
4276
[email protected]b172aee2012-04-10 17:05:264277void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524278 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324279 // Don't notify the world, since this came from a renderer in the
4280 // background.
4281 return;
4282 }
4283
[email protected]da7a7182013-09-06 08:11:114284 notify_disconnection_ = true;
4285 // TODO(avi): Remove. http://crbug.com/170921
4286 NotificationService::current()->Notify(
4287 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4288 Source<WebContents>(this),
4289 NotificationService::NoDetails());
4290
[email protected]be1f56ab2011-12-22 06:55:314291 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234292 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304293
4294 // Restore the focus to the tab (otherwise the focus will be on the top
4295 // window).
[email protected]484ae5912010-09-29 19:16:144296 if (was_crashed && !FocusLocationBarByDefault() &&
4297 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064298 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144299 }
[email protected]32ded2212011-11-10 18:51:434300
ericwilligersde386342016-10-19 02:35:094301 for (auto& observer : observers_)
4302 observer.RenderViewReady();
[email protected]420ae012009-04-24 05:16:324303}
4304
[email protected]ec6a7eb2013-04-22 17:34:224305void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4306 base::TerminationStatus status,
4307 int error_code) {
[email protected]151a63d2011-12-20 22:32:524308 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324309 // The pending page's RenderViewHost is gone.
4310 return;
4311 }
4312
[email protected]2fcdcc32014-03-05 02:14:074313 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4314 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:154315 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464316 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074317
[email protected]698191dc2014-02-25 01:06:134318 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174319 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134320
[email protected]f738bdcb2014-07-11 20:40:444321 if (delegate_)
4322 delegate_->HideValidationMessage(this);
4323
[email protected]960b0372014-05-19 18:01:004324 // Reset the loading progress. TODO(avi): What does it mean to have a
4325 // "renderer crash" when there is more than one renderer process serving a
4326 // webpage? Once this function is called at a more granular frame level, we
4327 // probably will need to more granularly reset the state here.
4328 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254329 NotifyDisconnected();
4330 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004331
ericwilligersde386342016-10-19 02:35:094332 for (auto& observer : observers_)
4333 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:324334}
4335
[email protected]b172aee2012-04-10 17:05:264336void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:094337 for (auto& observer : observers_)
4338 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:064339}
4340
[email protected]b172aee2012-04-10 17:05:264341void WebContentsImpl::UpdateState(RenderViewHost* rvh,
[email protected]691aa2f2013-05-28 22:52:044342 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384343 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4344
creise1d3e5b2014-12-01 18:21:574345 // Ensure that this state update comes from a RenderViewHost that belongs to
4346 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414347 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574348 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414349 return;
[email protected]420ae012009-04-24 05:16:324350
avi1edc8552016-10-13 21:37:164351 if (!rvh->GetMainFrame()) {
4352 // When UseSubframeNavigationEntries is turned off, state updates only come
4353 // in on main frames. When UseSubframeNavigationEntries is turned on,
4354 // UpdateStateForFrame() should have been called rather than this function.
4355 NOTREACHED();
[email protected]420ae012009-04-24 05:16:324356 return;
nasko346969912015-12-16 22:36:474357 }
creisd63f6c4a2015-11-06 19:05:534358
avi1edc8552016-10-13 21:37:164359 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
4360 static_cast<RenderFrameHostImpl*>(rvh->GetMainFrame())->nav_entry_id());
4361
[email protected]691aa2f2013-05-28 22:52:044362 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324363 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044364 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114365 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324366}
4367
sky8b00392d2015-01-10 00:30:284368void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4369 const GURL& url) {
4370 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4371 // If we're fullscreen only update the url if it's from the fullscreen
4372 // renderer.
4373 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444374 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284375 return;
4376 }
[email protected]6934a702011-12-20 00:04:514377 if (delegate_)
avi450ce00e2014-09-24 01:58:524378 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324379}
4380
[email protected]b172aee2012-04-10 17:05:264381void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104382#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294383 // The UI may be in an event-tracking loop, such as between the
4384 // mouse-down and mouse-up in text selection or a button click.
4385 // Defer the close until after tracking is complete, so that we
4386 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294387 // TODO(shess): This could get more fine-grained. For instance,
4388 // closing a tab in another window while selecting text in the
4389 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104390 if (view_->IsEventTracking()) {
4391 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294392 return;
4393 }
[email protected]60780f412013-02-25 16:34:104394#endif
[email protected]07707302009-11-06 00:50:294395
[email protected]420ae012009-04-24 05:16:324396 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524397 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514398 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324399}
4400
[email protected]b172aee2012-04-10 17:05:264401void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514402 if (delegate_ && delegate_->IsPopupOrPanel(this))
4403 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324404}
4405
fdegansa696e5112015-04-17 01:57:594406void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094407 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254408 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084409
4410 // Notify accessibility that the user is navigating away from the
4411 // current document.
4412 //
4413 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084414 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594415 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084416 if (manager)
4417 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324418}
4419
fdegansc73eec22015-03-19 14:47:544420void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084421 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324422
[email protected]9595fd82013-04-19 21:28:494423 // Use the last committed entry rather than the active one, in case a
4424 // pending entry has been created.
4425 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204426 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494427
[email protected]420ae012009-04-24 05:16:324428 // An entry may not exist for a stop when loading an initial blank page or
4429 // if an iframe injected by script into a blank page finishes loading.
4430 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204431 base::TimeDelta elapsed =
4432 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324433
4434 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514435 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324436 elapsed,
4437 &controller_,
4438 controller_.GetCurrentEntryIndex()));
4439 }
4440
clamy44e84ce2016-02-22 15:38:254441 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324442}
4443
fdegansa696e5112015-04-17 01:57:594444void WebContentsImpl::DidChangeLoadProgress() {
4445 double load_progress = frame_tree_.load_progress();
4446
4447 // The delegate is notified immediately for the first and last updates. Also,
4448 // since the message loop may be pretty busy when a page is loaded, it might
4449 // not execute a posted task in a timely manner so the progress report is sent
4450 // immediately if enough time has passed.
4451 base::TimeDelta min_delay =
4452 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4453 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4454 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4455
4456 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4457 // If there is a pending task to send progress, it is now obsolete.
4458 loading_weak_factory_.InvalidateWeakPtrs();
4459
4460 // Notify the load progress change.
4461 SendChangeLoadProgress();
4462
4463 // Clean-up the states if needed.
4464 if (load_progress == 1.0)
4465 ResetLoadProgressState();
4466 return;
4467 }
4468
4469 if (loading_weak_factory_.HasWeakPtrs())
4470 return;
4471
skyostil95082a62015-06-05 19:53:074472 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4473 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4474 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594475 min_delay);
4476}
4477
clamycbf524d42016-09-27 12:48:354478ScopedVector<NavigationThrottle> WebContentsImpl::CreateThrottlesForNavigation(
4479 NavigationHandle* navigation_handle) {
4480 return GetContentClient()->browser()->CreateThrottlesForNavigation(
4481 navigation_handle);
4482}
4483
clamy1e5574e2016-09-29 16:48:444484std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
4485 NavigationHandle* navigation_handle) {
4486 DCHECK(IsBrowserSideNavigationEnabled());
4487 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
4488}
4489
[email protected]b172aee2012-04-10 17:05:264490void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164491 controller_.DiscardNonCommittedEntries();
4492
4493 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214494 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164495}
4496
[email protected]59167c22013-06-03 18:07:324497void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104498 has_accessed_initial_document_ = true;
4499
[email protected]d1371bf8e2014-04-19 03:26:244500 // We may have left a failed browser-initiated navigation in the address bar
4501 // to let the user edit it and try again. Clear it now that content might
4502 // show up underneath it.
4503 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454504 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244505
[email protected]59167c22013-06-03 18:07:324506 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504507 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324508}
4509
alexmosbe2f4c32015-03-10 02:30:234510void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4511 const std::string& name) {
ericwilligersde386342016-10-19 02:35:094512 for (auto& observer : observers_)
4513 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:234514}
4515
[email protected]39f2f9252014-05-03 00:54:014516void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294517 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094518 for (auto& observer : observers_)
4519 observer.DocumentOnLoadCompletedInMainFrame();
[email protected]6578fef2013-10-14 02:35:094520
4521 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214522 NotificationService::current()->Notify(
4523 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4524 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294525 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084526}
4527
creis8eb8ef22015-11-04 22:51:384528void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4529 const PageState& page_state) {
4530 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4531
4532 // The state update affects the last NavigationEntry associated with the given
4533 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4534 // in the case of an UpdateState from a frame being swapped out). We track
4535 // which entry this is in the RenderFrameHost's nav_entry_id.
4536 RenderFrameHostImpl* rfhi =
4537 static_cast<RenderFrameHostImpl*>(render_frame_host);
4538 NavigationEntryImpl* entry =
4539 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4540 if (!entry)
4541 return;
4542
4543 FrameNavigationEntry* frame_entry =
4544 entry->GetFrameEntry(rfhi->frame_tree_node());
4545 if (!frame_entry)
4546 return;
4547
creisd06a9422015-11-11 03:08:454548 // The SiteInstance might not match if we do a cross-process navigation with
4549 // replacement (e.g., auto-subframe), in which case the swap out of the old
4550 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4551 // has already been replaced and destroyed.
4552 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4553 return;
4554
creis8eb8ef22015-11-04 22:51:384555 if (page_state == frame_entry->page_state())
4556 return; // Nothing to update.
4557
creisfafed882016-07-29 00:03:094558 if (!page_state.IsValid()) {
4559 // Temporarily generate a minidump to diagnose https://crbug.com/568703.
4560 base::debug::DumpWithoutCrashing();
4561 NOTREACHED() << "Shouldn't set an empty PageState.";
4562 }
nasko34634672016-07-29 18:46:064563
4564 // The document_sequence_number and item_sequence_number recorded in the
4565 // FrameNavigationEntry should not differ from the one coming with the update,
4566 // since it must come from the same document. Do not update it if a difference
4567 // is detected, as this indicates that |frame_entry| is not the correct one.
4568 ExplodedPageState exploded_state;
4569 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
4570 return;
4571
4572 if (exploded_state.top.document_sequence_number !=
4573 frame_entry->document_sequence_number() ||
4574 exploded_state.top.item_sequence_number !=
4575 frame_entry->item_sequence_number()) {
4576 return;
4577 }
4578
nasko04a322f25a2016-09-01 00:00:344579 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:384580 controller_.NotifyEntryChanged(entry);
4581}
4582
[email protected]ef3adfc2014-05-11 00:04:544583void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:544584 const base::string16& title,
4585 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544586 // If we have a title, that's a pretty good indication that we've started
4587 // getting useful data.
4588 SetNotWaitingForResponse();
4589
4590 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584591 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:164592 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:044593 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:544594
4595 // We can handle title updates when we don't have an entry in
4596 // UpdateTitleForEntry, but only if the update is from the current RVH.
4597 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584598 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544599 return;
4600
4601 // TODO(evan): make use of title_direction.
4602 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:134603 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:544604}
4605
4606void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4607 const std::string& encoding) {
4608 SetEncoding(encoding);
4609}
4610
[email protected]39f2f9252014-05-03 00:54:014611void WebContentsImpl::DocumentAvailableInMainFrame(
4612 RenderViewHost* render_view_host) {
ericwilligersde386342016-10-19 02:35:094613 for (auto& observer : observers_)
4614 observer.DocumentAvailableInMainFrame();
[email protected]39f2f9252014-05-03 00:54:014615}
naskoc0fceff2015-04-30 15:53:524616
[email protected]e1c3a552012-05-04 20:51:324617void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4618 // Tell the active RenderViewHost to run unload handlers and close, as long
4619 // as the request came from a RenderViewHost in the same BrowsingInstance.
4620 // In most cases, we receive this from a swapped out RenderViewHost.
4621 // It is possible to receive it from one that has just been swapped in,
4622 // in which case we might as well deliver the message anyway.
4623 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524624 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324625}
4626
alexmose7da5a12015-04-09 02:22:164627bool WebContentsImpl::ShouldRouteMessageEvent(
4628 RenderFrameHost* target_rfh,
4629 SiteInstance* source_site_instance) const {
4630 // Allow the message if this WebContents is dedicated to a browser plugin
4631 // guest.
[email protected]0eba810b2012-10-18 03:19:364632 // Note: This check means that an embedder could theoretically receive a
4633 // postMessage from anyone (not just its own guests). However, this is
4634 // probably not a risk for apps since other pages won't have references
4635 // to App windows.
alexmose7da5a12015-04-09 02:22:164636 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4637}
[email protected]f546640b2012-05-15 00:03:494638
alexmos58729042015-06-18 23:20:004639void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164640 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4641 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494642
alexmose7da5a12015-04-09 02:22:164643 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144644 // If this message is going to outer WebContents from inner WebContents,
4645 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4646 // already created a RenderFrameProxyHost for that purpose.
4647 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:174648 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:144649 return;
4650 }
4651
lfg812874d2016-02-09 22:26:134652 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064653 // We create a RenderFrameProxyHost for the embedder in the guest's render
4654 // process but we intentionally do not expose the embedder's opener chain
4655 // to it.
4656 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4657 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494658 } else {
alexmos58729042015-06-18 23:20:004659 RenderFrameHostImpl* source_rfhi =
4660 static_cast<RenderFrameHostImpl*>(source_rfh);
4661 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394662 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494663 }
4664 }
[email protected]f546640b2012-05-15 00:03:494665}
4666
avallee9993fca2016-11-17 06:16:504667void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
4668 // Only change focus if we are not currently focused.
4669 WebContentsImpl* old_contents = GetFocusedWebContents();
4670 if (old_contents == this)
4671 return;
4672
4673 // Send a page level blur to the old contents so that it displays inactive UI
4674 // and focus this contents to activate it.
4675 if (old_contents)
4676 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
4677 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
4678 GetOutermostWebContents()->node_->SetFocusedWebContents(this);
4679}
4680
avallee0206f782016-07-28 18:55:334681void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4682 SiteInstance* source) {
avallee9993fca2016-11-17 06:16:504683 // The PDF plugin still runs as a BrowserPlugin and must go through the
4684 // input redirection mechanism. It must not become focused direcly.
ekaramad1beabecc2016-09-23 20:18:174685 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
avallee0206f782016-07-28 18:55:334686 frame_tree_.SetFocusedFrame(node, source);
4687 return;
4688 }
4689
avallee9993fca2016-11-17 06:16:504690 SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:334691
4692 frame_tree_.SetFocusedFrame(node, source);
avallee0206f782016-07-28 18:55:334693}
4694
avia90ae4e2016-11-11 20:49:334695bool WebContentsImpl::DidAddMessageToConsole(int32_t level,
4696 const base::string16& message,
4697 int32_t line_no,
4698 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254699 if (!delegate_)
4700 return false;
avia90ae4e2016-11-11 20:49:334701 return delegate_->DidAddMessageToConsole(this, level, message, line_no,
4702 source_id);
[email protected]a796f202012-05-30 14:14:254703}
4704
dominickn9c7ceaa32016-02-27 01:52:534705void WebContentsImpl::OnUserInteraction(
4706 RenderWidgetHostImpl* render_widget_host,
4707 const blink::WebInputEvent::Type type) {
kenrb19221852016-04-29 17:21:404708 // Ignore unless the widget is currently in the frame tree.
4709 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:224710 return;
4711
ericwilligersde386342016-10-19 02:35:094712 for (auto& observer : observers_)
4713 observer.DidGetUserInteraction(type);
dominickn9c7ceaa32016-02-27 01:52:534714
4715 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4716 // Exclude scroll events as user gestures for resource load dispatches.
4717 // rdh is NULL in unittests.
4718 if (rdh && type != blink::WebInputEvent::MouseWheel)
scottmge22a5e52016-06-30 00:36:514719 rdh->OnUserGesture();
dominickn2dd142dd2015-10-29 05:30:504720}
4721
avallee9993fca2016-11-17 06:16:504722void WebContentsImpl::FocusOwningWebContents(
4723 RenderWidgetHostImpl* render_widget_host) {
4724 // The PDF plugin still runs as a BrowserPlugin and must go through the
4725 // input redirection mechanism. It must not become focused direcly.
4726 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
4727 return;
4728
4729 RenderWidgetHostImpl* focused_widget =
4730 GetFocusedRenderWidgetHost(render_widget_host);
4731
4732 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:304733 (!focused_widget ||
4734 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:504735 SetAsFocusedWebContentsIfNecessary();
4736 }
4737}
4738
[email protected]b172aee2012-04-10 17:05:264739void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444740 // Notify observers.
ericwilligersde386342016-10-19 02:35:094741 for (auto& observer : observers_)
4742 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:444743}
4744
avic3aa8422015-11-09 20:57:224745void WebContentsImpl::RendererUnresponsive(
clamy639fdffb2016-07-18 18:13:324746 RenderWidgetHostImpl* render_widget_host,
dtapuskae99ec6e52016-10-18 00:15:424747 RendererUnresponsiveType type) {
ericwilligersde386342016-10-19 02:35:094748 for (auto& observer : observers_)
4749 observer.OnRendererUnresponsive(render_widget_host);
afakhry98241832016-03-11 19:27:474750
[email protected]992db4c2011-05-12 15:37:154751 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224752 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154753 return;
4754
creiscce56cd2014-09-29 22:45:224755 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224756 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584757
[email protected]e5fc1632011-08-08 07:51:534758 // Ignore renderer unresponsive event if debugger is attached to the tab
4759 // since the event may be a result of the renderer sitting on a breakpoint.
4760 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364761 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534762 return;
4763
clamy639fdffb2016-07-18 18:13:324764 // Record histograms about the type of renderer hang.
4765 UMA_HISTOGRAM_ENUMERATION(
4766 "ChildProcess.HangRendererType", type,
dtapuskae99ec6e52016-10-18 00:15:424767 RendererUnresponsiveType::RENDERER_UNRESPONSIVE_MAX);
clamy639fdffb2016-07-18 18:13:324768
metaflow73fc9552016-05-23 18:26:484769 // We might have been waiting for both beforeunload and unload ACK.
4770 // Check if tab is to be unloaded first.
4771 if (rfhi->IsWaitingForUnloadACK()) {
4772 // Hang occurred while firing the unload handler.
[email protected]420ae012009-04-24 05:16:324773 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224774 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324775
[email protected]fa944cb82013-11-15 17:51:214776 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324777 return;
4778
metaflow73fc9552016-05-23 18:26:484779 // If the tab hangs in the unload handler there's really nothing we can do
4780 // to recover. Pretend the unload listeners have all fired and close
[email protected]2e9d79f2013-08-16 05:45:564781 // the tab.
metaflow73fc9552016-05-23 18:26:484782 Close();
4783 return;
4784 }
4785
4786 if (rfhi->is_waiting_for_beforeunload_ack()) {
4787 // If the hang is in the beforeunload handler, pretend the beforeunload
4788 // listeners have all fired and allow the delegate to continue closing;
4789 // the user will not have the option of cancelling the close.
4790 rfhi->SimulateBeforeUnloadAck();
[email protected]420ae012009-04-24 05:16:324791 return;
4792 }
4793
creisc014b402015-04-23 16:41:454794 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474795 return;
4796
dtapuskae99ec6e52016-10-18 00:15:424797 if (delegate_) {
4798 WebContentsUnresponsiveState unresponsive_state;
4799 unresponsive_state.reason = type;
4800 unresponsive_state.outstanding_ack_count =
4801 render_widget_host->in_flight_event_count();
4802 unresponsive_state.outstanding_event_type =
4803 render_widget_host->hang_monitor_event_type();
4804 unresponsive_state.last_event_type = render_widget_host->last_event_type();
4805 delegate_->RendererUnresponsive(this, unresponsive_state);
4806 }
[email protected]420ae012009-04-24 05:16:324807}
4808
avic3aa8422015-11-09 20:57:224809void WebContentsImpl::RendererResponsive(
4810 RenderWidgetHostImpl* render_widget_host) {
4811 if (render_widget_host != GetRenderViewHost()->GetWidget())
4812 return;
4813
[email protected]6934a702011-12-20 00:04:514814 if (delegate_)
4815 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324816}
4817
[email protected]b172aee2012-04-10 17:05:264818void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554819 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324820 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:094821 for (auto& observer : observers_)
4822 observer.BeforeUnloadFired(proceed_time);
[email protected]6934a702011-12-20 00:04:514823 if (delegate_)
4824 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094825 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324826}
4827
[email protected]58d5cfe2013-07-10 02:40:524828void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544829 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234830 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224831 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544832}
4833
[email protected]b172aee2012-04-10 17:05:264834void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104835 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214836 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264837 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4838 // here during container initialization and normal window size will be set
4839 // later. In case of tab duplication this resizing to 0x0 prevents setting
4840 // normal size later so just ignore it.
4841 if (!size.IsEmpty())
4842 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324843}
4844
[email protected]af905902013-10-01 21:38:514845void WebContentsImpl::CancelModalDialogsForRenderManager() {
4846 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544847 // deferrer would prevent us from swapping out. We also clear the state
4848 // because this is a cross-process navigation, which means that it's a new
4849 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174850 //
4851 // Note that we don't bother telling browser_plugin_embedder_ because the
4852 // cross-process navigation will either destroy the browser plugins or not
4853 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:464854 if (dialog_manager_) {
4855 dialog_manager_->CancelDialogs(this,
4856 false, // suppress_callbacks,
4857 true); // reset_state
4858 }
[email protected]af905902013-10-01 21:38:514859}
4860
[email protected]02d7b6e2014-06-24 21:01:504861void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4862 RenderFrameHost* new_host,
4863 bool is_main_frame) {
4864 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054865 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504866 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084867
[email protected]02d7b6e2014-06-24 21:01:504868 // Make sure the visible RVH reflects the new delegate's preferences.
4869 if (delegate_)
4870 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394871
[email protected]02d7b6e2014-06-24 21:01:504872 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4873 }
4874
4875 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544876}
4877
naskof5940b9f2015-03-02 23:04:054878void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4879 RenderViewHost* old_host,
4880 RenderViewHost* new_host) {
4881 NotifyViewSwapped(old_host, new_host);
4882}
4883
[email protected]b172aee2012-04-10 17:05:264884NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194885 return GetController();
[email protected]3a3d47472010-07-15 21:03:544886}
4887
dcheng59716272016-04-09 05:19:084888std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294889 const GURL& url) {
avie865b1d2016-10-24 19:42:594890 return CreateWebUI(url, std::string());
[email protected]420ae012009-04-24 05:16:324891}
4892
[email protected]10f417c52011-12-28 21:04:234893NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264894 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324895 return controller_.GetLastCommittedEntry();
4896}
4897
lfgbede6392015-09-11 21:54:064898void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4899 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334900 RenderWidgetHostViewBase* rwh_view =
4901 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524902
[email protected]420ae012009-04-24 05:16:324903 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444904 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214905 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064906}
4907
4908bool WebContentsImpl::CreateRenderViewForRenderManager(
4909 RenderViewHost* render_view_host,
4910 int opener_frame_routing_id,
4911 int proxy_routing_id,
4912 const FrameReplicationState& replicated_frame_state) {
4913 TRACE_EVENT0("browser,navigation",
4914 "WebContentsImpl::CreateRenderViewForRenderManager");
4915
4916 if (proxy_routing_id == MSG_ROUTING_NONE)
4917 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324918
alexmos5ac402d2015-07-09 07:51:104919 if (!static_cast<RenderViewHostImpl*>(render_view_host)
avif9a94c7e2016-10-14 15:54:114920 ->CreateRenderView(opener_frame_routing_id,
4921 proxy_routing_id,
4922 replicated_frame_state,
alexmos5ac402d2015-07-09 07:51:104923 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524924 return false;
[email protected]14392a52012-05-02 20:28:444925 }
[email protected]a4127722011-04-27 23:13:524926
avi2b177592014-12-10 02:08:024927 SetHistoryOffsetAndLengthForView(render_view_host,
4928 controller_.GetLastCommittedEntryIndex(),
4929 controller_.GetEntryCount());
4930
[email protected]a220b5932013-09-21 03:47:444931#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504932 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4933 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444934 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444935 if (rwh_view) {
4936 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4937 render_widget_host->WasResized();
4938 }
[email protected]f8233cc2011-05-31 20:24:504939#endif
4940
[email protected]420ae012009-04-24 05:16:324941 return true;
4942}
4943
[email protected]82307f6b2014-08-07 03:30:124944bool WebContentsImpl::CreateRenderFrameForRenderManager(
4945 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044946 int proxy_routing_id,
4947 int opener_routing_id,
japhete6adf142014-10-31 00:01:494948 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044949 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434950 TRACE_EVENT0("browser,navigation",
4951 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124952
4953 RenderFrameHostImpl* rfh =
4954 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044955 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4956 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124957 return false;
4958
4959 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4960 // RenderFrameHost will have to be associated with the appropriate
4961 // RenderWidgetHostView or a new one should be created here.
4962
4963 return true;
4964}
4965
mfomitchev2b8b066a2016-01-28 19:23:154966#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454967
[email protected]155c7f22013-12-09 17:07:184968base::android::ScopedJavaLocalRef<jobject>
4969WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404970 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564971 return GetWebContentsAndroid()->GetJavaObject();
4972}
[email protected]155c7f22013-12-09 17:07:184973
[email protected]0e813a52014-08-13 10:34:564974WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184975 WebContentsAndroid* web_contents_android =
4976 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4977 if (!web_contents_android) {
4978 web_contents_android = new WebContentsAndroid(this);
4979 SetUserData(kWebContentsAndroidKey, web_contents_android);
4980 }
[email protected]0e813a52014-08-13 10:34:564981 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184982}
4983
paulmeyerc0b762b2016-04-13 11:55:174984void WebContentsImpl::ActivateNearestFindResult(float x,
4985 float y) {
4986 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4987}
4988
4989void WebContentsImpl::RequestFindMatchRects(int current_version) {
4990 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4991}
4992
[email protected]7d244f12013-08-22 21:41:514993bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064994 return CreateRenderViewForRenderManager(
4995 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064996 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514997}
[email protected]fc2b46b2014-05-03 16:33:454998
rockot400ea35b2016-10-15 19:15:324999service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:115000 if (!java_interfaces_) {
rockot400ea35b2016-10-15 19:15:325001 service_manager::mojom::InterfaceProviderPtr provider;
sammcf5f1b0f2016-09-20 23:05:115002 BindInterfaceRegistryForWebContents(mojo::GetProxy(&provider), this);
rockot400ea35b2016-10-15 19:15:325003 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:115004 java_interfaces_->Bind(std::move(provider));
5005 }
5006 return java_interfaces_.get();
5007}
5008
[email protected]fc2b46b2014-05-03 16:33:455009#elif defined(OS_MACOSX)
5010
[email protected]75f4df72014-07-16 22:39:425011void WebContentsImpl::SetAllowOtherViews(bool allow) {
5012 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:455013}
5014
[email protected]75f4df72014-07-16 22:39:425015bool WebContentsImpl::GetAllowOtherViews() {
5016 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:455017}
5018
[email protected]7d244f12013-08-22 21:41:515019#endif
5020
pkotwicz75ca8ffd2016-02-16 23:10:195021void WebContentsImpl::OnDidDownloadImage(
5022 const ImageDownloadCallback& callback,
5023 int id,
5024 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:525025 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:185026 const std::vector<SkBitmap>& images,
5027 const std::vector<gfx::Size>& original_image_sizes) {
5028 callback.Run(id, http_status_code, image_url, images, original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:195029}
5030
[email protected]6fba26d2014-04-29 09:38:285031void WebContentsImpl::OnDialogClosed(int render_process_id,
5032 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:265033 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:495034 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:265035 bool success,
[email protected]fcf75d42013-12-03 20:11:265036 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:285037 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
5038 render_frame_id);
[email protected]87de04b02014-04-08 22:14:495039 last_dialog_suppressed_ = dialog_was_suppressed;
5040
[email protected]beb440c2009-11-06 04:08:545041 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:235042 // It is possible for the current RenderFrameHost to have changed in the
5043 // meantime. Do not reset the navigation state in that case.
5044 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:255045 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:235046 controller_.DiscardNonCommittedEntries();
5047 }
[email protected]ec8e8b02013-06-19 04:57:105048
ericwilligersde386342016-10-19 02:35:095049 for (auto& observer : observers_)
5050 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:545051 }
[email protected]87de04b02014-04-08 22:14:495052
avi85ee8362016-10-08 02:09:085053 is_showing_javascript_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:545054 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:285055 if (rfh) {
5056 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
5057 dialog_was_suppressed);
5058 } else {
5059 // Don't leak the sync IPC reply if the RFH or process is gone.
5060 delete reply_msg;
5061 }
[email protected]beb440c2009-11-06 04:08:545062}
5063
[email protected]b172aee2012-04-10 17:05:265064void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:545065 if (encoding == last_reported_encoding_)
5066 return;
5067 last_reported_encoding_ = encoding;
5068
5069 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:125070 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:105071}
[email protected]f45d2a72010-03-08 23:28:355072
[email protected]1ac10dca2013-08-20 20:47:045073bool WebContentsImpl::IsHidden() {
5074 return capturer_count_ == 0 && !should_normally_be_visible_;
5075}
5076
rob97250742015-12-10 17:45:155077int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:145078 if (node_ && node_->outer_web_contents())
5079 return node_->outer_contents_frame_tree_node_id();
5080
nick2482a2d2015-12-18 01:39:375081 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:145082}
5083
ekaramadaeb3c5c2016-11-09 03:22:355084RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
5085 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
5086 fullscreen_widget_routing_id_);
5087}
5088
[email protected]b0936d22013-11-28 06:47:365089RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:215090 return frame_tree_.root()->render_manager();
5091}
5092
[email protected]f8497342013-02-05 22:15:025093BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:395094 return browser_plugin_guest_.get();
5095}
5096
[email protected]738f57a2013-06-29 21:06:545097void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
5098 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:145099 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:545100 browser_plugin_guest_.reset(guest);
5101}
5102
[email protected]f8497342013-02-05 22:15:025103BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:395104 return browser_plugin_embedder_.get();
5105}
[email protected]8ff00d72012-10-23 19:12:215106
fsamuel60b42282015-03-10 03:29:145107void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
5108 if (browser_plugin_embedder_)
5109 return;
5110 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
5111}
5112
[email protected]fc2b46b2014-05-03 16:33:455113gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:215114 gfx::Size size;
5115 if (delegate_)
5116 size = delegate_->GetSizeForNewRenderView(this);
5117 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:455118 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:215119 return size;
5120}
5121
[email protected]ae7eeda2014-07-04 01:53:265122void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095123 for (auto& observer : observers_)
5124 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:555125}
5126
[email protected]222f5822014-02-05 23:40:495127void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
5128 if (!delegate_)
5129 return;
5130 const gfx::Size new_size = GetPreferredSize();
5131 if (new_size != old_size)
5132 delegate_->UpdatePreferredSize(this, new_size);
5133}
5134
avie865b1d2016-10-24 19:42:595135std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(
5136 const GURL& url,
5137 const std::string& frame_name) {
5138 std::unique_ptr<WebUIImpl> web_ui =
5139 base::MakeUnique<WebUIImpl>(this, frame_name);
5140 WebUIController* controller =
5141 WebUIControllerFactoryRegistry::GetInstance()
5142 ->CreateWebUIControllerForURL(web_ui.get(), url);
dbeama1b926a2015-08-31 23:17:515143 if (controller) {
5144 web_ui->AddMessageHandler(new GenericHandler());
5145 web_ui->SetController(controller);
5146 return web_ui;
5147 }
5148
avie865b1d2016-10-24 19:42:595149 return nullptr;
dbeama1b926a2015-08-31 23:17:515150}
5151
paulmeyerc0b762b2016-04-13 11:55:175152FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
5153 // TODO(paulmeyer): This method will need to access (or potentially create)
5154 // the FindRequestManager in the outermost WebContents once find-in-page
5155 // across GuestViews is implemented.
5156 if (!find_request_manager_)
5157 find_request_manager_.reset(new FindRequestManager(this));
5158
5159 return find_request_manager_.get();
5160}
5161
5162void WebContentsImpl::NotifyFindReply(int request_id,
5163 int number_of_matches,
5164 const gfx::Rect& selection_rect,
5165 int active_match_ordinal,
5166 bool final_update) {
paulmeyer60b5d832016-08-31 18:46:345167 if (delegate_ && !is_being_destroyed_) {
paulmeyerc0b762b2016-04-13 11:55:175168 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
5169 active_match_ordinal, final_update);
5170 }
5171}
5172
ortuno467e5792016-06-10 04:32:395173void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
5174 // Trying to invalidate the tab state while being destroyed could result in a
5175 // use after free.
5176 if (IsBeingDestroyed()) {
5177 return;
5178 }
5179 // Notify for UI updates if the state changes.
5180 bluetooth_connected_device_count_++;
5181 if (bluetooth_connected_device_count_ == 1) {
5182 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5183 }
5184}
5185
5186void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
5187 // Trying to invalidate the tab state while being destroyed could result in a
5188 // use after free.
5189 if (IsBeingDestroyed()) {
5190 return;
5191 }
5192 // Notify for UI updates if the state changes.
5193 DCHECK(bluetooth_connected_device_count_ != 0);
5194 bluetooth_connected_device_count_--;
5195 if (bluetooth_connected_device_count_ == 0) {
5196 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
5197 }
5198}
5199
paulmeyerc0b762b2016-04-13 11:55:175200#if defined(OS_ANDROID)
5201void WebContentsImpl::NotifyFindMatchRectsReply(
5202 int version,
5203 const std::vector<gfx::RectF>& rects,
5204 const gfx::RectF& active_rect) {
5205 if (delegate_)
5206 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
5207}
5208#endif
5209
[email protected]34ff1cfc2014-08-20 06:16:055210void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
5211 force_disable_overscroll_content_ = force_disable;
5212 if (view_)
5213 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
5214}
5215
dalecurtis88c240072015-12-09 02:11:185216void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:045217 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185218 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045219 if (media_info.has_video)
5220 currently_playing_video_count_++;
5221
ericwilligersde386342016-10-19 02:35:095222 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045223 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:185224}
5225
5226void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:045227 const WebContentsObserver::MediaPlayerInfo& media_info,
dalecurtis88c240072015-12-09 02:11:185228 const WebContentsObserver::MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:045229 if (media_info.has_video)
5230 currently_playing_video_count_--;
5231
ericwilligersde386342016-10-19 02:35:095232 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:045233 observer.MediaStoppedPlaying(media_info, id);
5234}
5235
5236int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
5237 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:185238}
5239
tapted65ff2ea72016-03-01 23:39:005240void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
5241 if (!did_first_set_visible_) {
5242 // If this WebContents has not yet been set to be visible for the first
5243 // time, ignore any requests to make it hidden, since resources would
5244 // immediately be destroyed and only re-created after content loaded. In
5245 // this state the window content is undefined and can show garbage.
5246 // However, the page load mechanism requires an activation call through a
5247 // visibility call to (re)load.
5248 if (visible) {
5249 did_first_set_visible_ = true;
5250 WasShown();
5251 }
5252 return;
5253 }
5254 if (visible == should_normally_be_visible_)
5255 return;
5256
5257 if (visible)
5258 WasShown();
5259 else
5260 WasHidden();
5261}
5262
aelias5252baa2016-04-10 01:18:025263void WebContentsImpl::UpdateOverridingUserAgent() {
5264 std::set<RenderViewHost*> render_view_host_set;
5265 for (FrameTreeNode* node : frame_tree_.Nodes()) {
5266 RenderWidgetHost* render_widget_host =
5267 node->current_frame_host()->GetRenderWidgetHost();
5268 if (!render_widget_host)
5269 continue;
5270 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5271 if (!render_view_host)
5272 continue;
5273 render_view_host_set.insert(render_view_host);
5274 }
5275 for (RenderViewHost* render_view_host : render_view_host_set)
5276 render_view_host->OnWebkitPreferencesChanged();
5277}
5278
avid53461d2016-02-25 17:15:045279void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5280 JavaScriptDialogManager* dialog_manager) {
5281 dialog_manager_ = dialog_manager;
5282}
5283
rockotf62002a2016-09-15 00:08:595284void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
5285 auto it = binding_sets_.find(interface_name);
5286 if (it != binding_sets_.end())
5287 binding_sets_.erase(it);
5288}
5289
[email protected]8ff00d72012-10-23 19:12:215290} // namespace content