blob: a03508a11e4c31482ab613edb89af2aca396dd6e [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"
[email protected]5f2aa722013-08-07 16:59:4140#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0441#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4642#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1243#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1644#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1745#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1646#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3847#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4048#include "content/browser/frame_host/interstitial_page_impl.h"
49#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3350#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0151#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1852#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0753#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1654#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0555#include "content/browser/host_zoom_map_impl.h"
csharrison2e8c98e2016-08-01 23:56:2556#include "content/browser/loader/loader_io_thread_notifier.h"
[email protected]678c0362012-12-05 08:02:4457#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4058#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3059#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5260#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1861#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5262#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5363#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0964#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3065#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5066#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3267#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5068#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5969#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4870#include "content/browser/renderer_host/render_widget_host_view_base.h"
ekaramadadd882292016-06-08 15:22:5671#include "content/browser/renderer_host/text_input_manager.h"
jonross74971522014-09-15 14:16:0972#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3373#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1274#include "content/browser/wake_lock/wake_lock_service_context.h"
lfgc740d4b22016-04-15 16:45:3375#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1176#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5877#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0378#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5679#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1480#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4281#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4482#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1783#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0784#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0685#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1886#include "content/common/render_message_filter.mojom.h"
avi286019ce2015-07-29 01:26:5887#include "content/common/site_isolation_policy.h"
[email protected]2c5569662011-03-22 20:45:0288#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3689#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1190#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2891#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4492#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3693#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1794#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1495#include "content/public/browser/download_url_parameters.h"
ekaramad1beabecc2016-09-23 20:18:1796#include "content/public/browser/guest_mode.h"
[email protected]d9083482012-01-06 00:38:4697#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1598#include "content/public/browser/javascript_dialog_manager.h"
[email protected]09d31d52012-03-11 22:30:2799#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00100#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37101#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14102#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08103#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30104#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32105#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:09106#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:12107#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34108#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38109#include "content/public/browser/user_metrics.h"
rockotf62002a2016-09-15 00:08:59110#include "content/public/browser/web_contents_binding_set.h"
[email protected]674bc592011-12-20 23:00:42111#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21112#include "content/public/common/bindings_policy.h"
carloskd80262f52015-12-16 14:40:35113#include "content/public/common/browser_side_navigation_policy.h"
alexmosc9e76ec2016-05-16 22:59:37114#include "content/public/common/child_process_host.h"
[email protected]54087fe2011-10-28 22:02:48115#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54116#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49117#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20118#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:03119#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57120#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05121#include "content/public/common/web_preferences.h"
mcasas4e216e72016-07-28 21:28:38122#include "device/geolocation/geolocation_service_context.h"
sammc5a139ba2016-09-29 01:49:14123#include "device/nfc/nfc.mojom.h"
wjmaclean64951902016-04-29 20:59:12124#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53125#include "net/http/http_cache.h"
126#include "net/http/http_transaction_factory.h"
127#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34128#include "net/url_request/url_request_context_getter.h"
sammcf5f1b0f2016-09-20 23:05:11129#include "services/shell/public/cpp/interface_provider.h"
alexmosaedfc6f2016-01-21 23:57:38130#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40131#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39132#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56133#include "ui/base/layout.h"
chongz4a9751942016-08-17 17:49:39134#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52135#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31136
[email protected]583418cc2013-01-17 14:01:10137#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40138#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15139#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11140#include "content/browser/android/java_interfaces_impl.h"
dalecurtisc85ed632016-01-13 00:22:46141#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18142#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15143#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10144
[email protected]f66df822012-05-18 16:52:17145#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50146#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57147#endif
[email protected]3e45ba92009-02-20 21:09:00148
sadrul943e3b32016-08-04 18:22:59149#if defined(USE_AURA)
fsamuel9cf7bdf2015-11-20 02:19:32150#include "content/browser/web_contents/web_contents_view_mus.h"
151#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46152#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32153#endif
154
zqzhang181047e62016-07-01 13:37:17155#if defined(ENABLE_PLUGINS)
156#include "content/browser/media/session/pepper_playback_observer.h"
157#endif // ENABLE_PLUGINS
158
[email protected]8ff00d72012-10-23 19:12:21159namespace content {
[email protected]420ae012009-04-24 05:16:32160namespace {
161
[email protected]960b0372014-05-19 18:01:00162const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41163const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05164
[email protected]155c7f22013-12-09 17:07:18165#if defined(OS_ANDROID)
166const char kWebContentsAndroidKey[] = "web_contents_android";
167#endif // OS_ANDROID
168
[email protected]e4abd3b42013-11-12 18:28:47169base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46170g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
171
[email protected]8bfc8272013-09-09 20:10:53172void NotifyCacheOnIO(
173 scoped_refptr<net::URLRequestContextGetter> request_context,
174 const GURL& url,
175 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58176 net::HttpCache* cache = request_context->GetURLRequestContext()->
177 http_transaction_factory()->GetCache();
178 if (cache)
179 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53180}
181
dcheng57e39e22016-01-21 00:25:38182bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
183 for (FrameTreeNode* node : tree->Nodes()) {
184 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
185 return true;
alexmos4cf2aa32015-07-15 23:40:43186 }
dcheng57e39e22016-01-21 00:25:38187 return false;
[email protected]95640212014-07-26 18:14:30188}
189
kenrb19221852016-04-29 17:21:40190bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
191 // This method scans the frame tree rather than checking whether
192 // host->delegate() == this, which allows it to return false when the host
193 // for a frame that is pending or pending deletion.
194 if (!host)
195 return false;
196
197 for (FrameTreeNode* node : tree->Nodes()) {
198 if (node->current_frame_host()->GetRenderWidgetHost() == host)
199 return true;
200 }
201 return false;
202}
203
[email protected]95640212014-07-26 18:14:30204void SetAccessibilityModeOnFrame(AccessibilityMode mode,
205 RenderFrameHost* frame_host) {
206 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
207}
208
dtseng0dd3fa12015-07-22 19:00:52209void ResetAccessibility(RenderFrameHost* rfh) {
210 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
211}
212
dmazzonid95ae842016-04-12 21:17:39213using AXTreeSnapshotCallback =
214 base::Callback<void(const ui::AXTreeUpdate&)>;
215
216// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
217// Handles the callbacks from parallel snapshot requests to each frame,
218// and feeds the results to an AXTreeCombiner, which converts them into a
219// single combined accessibility tree.
220class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
221 public:
222 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
223 : callback_(callback) {
224 }
225
226 AXTreeSnapshotCallback AddFrame(bool is_root) {
227 // Adds a reference to |this|.
228 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
229 this,
230 is_root);
231 }
232
233 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
234 combiner_.AddTree(snapshot, is_root);
235 }
236
237 private:
238 friend class base::RefCounted<AXTreeSnapshotCombiner>;
239
240 // This is called automatically after the last call to ReceiveSnapshot
241 // when there are no more references to this object.
242 ~AXTreeSnapshotCombiner() {
243 combiner_.Combine();
244 callback_.Run(combiner_.combined());
245 }
246
247 ui::AXTreeCombiner combiner_;
248 AXTreeSnapshotCallback callback_;
249};
250
[email protected]420ae012009-04-24 05:16:32251} // namespace
252
[email protected]54944cde2012-12-09 09:24:59253WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21254 FrameTreeNode* opener_node = nullptr;
255 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
256 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
257 params.opener_render_process_id, params.opener_render_frame_id);
258 if (opener_rfh)
259 opener_node = opener_rfh->frame_tree_node();
260 }
261 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19262}
263
264WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59265 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30266 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21267 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30268
269 for (SessionStorageNamespaceMap::const_iterator it =
270 session_storage_namespace_map.begin();
271 it != session_storage_namespace_map.end();
272 ++it) {
273 new_contents->GetController()
274 .SetSessionStorageNamespace(it->first, it->second.get());
275 }
276
[email protected]54944cde2012-12-09 09:24:59277 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19278 return new_contents;
[email protected]a81343d232011-12-27 07:39:20279}
[email protected]746d3052012-05-22 15:15:47280
nickf9acfbe2014-12-23 19:12:37281void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
282 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46283 g_created_callbacks.Get().push_back(callback);
284}
285
nickf9acfbe2014-12-23 19:12:37286void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
287 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46288 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
289 if (g_created_callbacks.Get().at(i).Equals(callback)) {
290 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
291 return;
292 }
293 }
294}
295
avidf38c952015-10-27 13:45:13296WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
297 if (!rvh)
298 return nullptr;
[email protected]746d3052012-05-22 15:15:47299 return rvh->GetDelegate()->GetAsWebContents();
300}
301
[email protected]a86c0e962013-12-17 17:10:39302WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13303 if (!rfh)
304 return nullptr;
305 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39306}
307
ananta4b7467a52016-09-23 01:42:38308WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
309 FrameTreeNode* frame_tree_node =
310 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
311 return FromRenderFrameHost(frame_tree_node->current_frame_host());
312}
313
[email protected]7fff43e2013-05-21 20:21:10314// WebContentsImpl::DestructionObserver ----------------------------------------
315
316class WebContentsImpl::DestructionObserver : public WebContentsObserver {
317 public:
318 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
319 : WebContentsObserver(watched_contents),
320 owner_(owner) {
321 }
322
323 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58324 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58325 owner_->OnWebContentsDestroyed(
326 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10327 }
328
329 private:
330 WebContentsImpl* owner_;
331
332 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
333};
334
[email protected]8ed16472014-04-11 19:02:48335WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
336 int render_frame_id,
337 ColorChooser* chooser,
338 int identifier)
339 : render_process_id(render_process_id),
340 render_frame_id(render_frame_id),
341 chooser(chooser),
342 identifier(identifier) {
343}
344
345WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
346}
347
lazyboy6ec48b2a2015-06-29 15:18:14348// WebContentsImpl::WebContentsTreeNode ----------------------------------------
349WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
350 : outer_web_contents_(nullptr),
351 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33352 FrameTreeNode::kFrameTreeNodeInvalidId),
353 focused_web_contents_(nullptr) {}
lazyboy6ec48b2a2015-06-29 15:18:14354
355WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
356 // Remove child pointer from our parent.
357 if (outer_web_contents_) {
358 ChildrenSet& child_ptrs_in_parent =
359 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
360 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
361 DCHECK(iter != child_ptrs_in_parent.end());
avallee0206f782016-07-28 18:55:33362 child_ptrs_in_parent.erase(iter);
lazyboy6ec48b2a2015-06-29 15:18:14363 }
364
365 // Remove parent pointers from our children.
366 // TODO(lazyboy): We should destroy the children WebContentses too. If the
367 // children do not manage their own lifetime, then we would leak their
368 // WebContentses.
369 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
370 child->outer_web_contents_ = nullptr;
371}
372
373void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
374 WebContentsImpl* outer_web_contents,
375 RenderFrameHostImpl* outer_contents_frame) {
avallee0206f782016-07-28 18:55:33376 DCHECK(!focused_web_contents_) << "Should not attach a root node.";
lazyboy6ec48b2a2015-06-29 15:18:14377 outer_web_contents_ = outer_web_contents;
378 outer_contents_frame_tree_node_id_ =
379 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
380
avallee0206f782016-07-28 18:55:33381 if (!outer_web_contents_->node_) {
382 // This will only be reached when creating a new WebContents tree.
383 // Initialize the root of this tree and set it as focused.
lazyboy6ec48b2a2015-06-29 15:18:14384 outer_web_contents_->node_.reset(new WebContentsTreeNode());
avallee0206f782016-07-28 18:55:33385 outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_);
386 }
lazyboy6ec48b2a2015-06-29 15:18:14387
388 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
389}
390
avallee0206f782016-07-28 18:55:33391void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
392 WebContentsImpl* web_contents) {
393 DCHECK(!outer_web_contents())
394 << "Only the outermost WebContents tracks focus.";
395 focused_web_contents_ = web_contents;
396}
397
[email protected]b172aee2012-04-10 17:05:26398// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32399
alexmose201c7cd2015-06-10 17:14:21400WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42401 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22402 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57403 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21404 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01405 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57406 this,
407 this,
408 this,
409 this),
[email protected]6dfed692014-05-22 04:18:03410 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23411 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
412 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34413 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26414 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56415 upload_size_(0),
416 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16417 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47418 displayed_insecure_content_(false),
estarkcd2e30c2016-08-12 06:51:15419 displayed_content_with_cert_errors_(false),
[email protected]b4c84012014-04-28 19:51:10420 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28421 theme_color_(SK_ColorTRANSPARENT),
422 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29423 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55424 capturer_count_(0),
425 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00426 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57427 is_being_destroyed_(false),
428 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15429 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01430 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39431 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38432 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21433 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
434 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22435 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44436 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55437 render_frame_message_source_(NULL),
alexmosc9e76ec2016-05-16 22:59:37438 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42439 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03440 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49441 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05442 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30443 last_dialog_suppressed_(false),
mcasas4e216e72016-07-28 21:28:38444 geolocation_service_context_(new device::GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48445 accessibility_mode_(
446 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15447 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35448 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50449 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46450 page_scale_factor_is_one_(true),
lfgbee1e0a2016-06-08 21:24:21451 mouse_lock_widget_(nullptr),
pkotwicz75ca8ffd2016-02-16 23:10:19452 loading_weak_factory_(this),
453 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55454 frame_tree_.SetFrameRemoveListener(
455 base::Bind(&WebContentsImpl::OnFrameRemoved,
456 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46457#if defined(OS_ANDROID)
458 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
459#else
qinmin58567c82015-01-07 21:00:20460 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46461#endif
zqzhang181047e62016-07-01 13:37:17462#if defined (ENABLE_PLUGINS)
463 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
464#endif
csharrisona2280cd2016-02-03 23:21:15465 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
blundellebd75172016-10-03 10:41:43466 wake_lock_service_context_.reset(new WakeLockServiceContext(
467 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
468 base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this))));
[email protected]332af7732009-03-11 13:21:35469}
initial.commit09911bf2008-07-26 23:55:29470
[email protected]b172aee2012-04-10 17:05:26471WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32472 is_being_destroyed_ = true;
473
kenrb2a565f82015-09-02 20:24:59474 rwh_input_event_router_.reset();
475
rockotf62002a2016-09-15 00:08:59476 for (auto& entry : binding_sets_)
477 entry.second->CloseAllBindings();
478
avallee0206f782016-07-28 18:55:33479 WebContentsImpl* outermost = GetOutermostWebContents();
480 if (GetFocusedWebContents() == this && this != outermost) {
481 // If the current WebContents is in focus, unset it.
482 outermost->node_->SetFocusedWebContents(outermost);
483 }
484
dcheng72be33c2016-01-21 04:11:31485 for (FrameTreeNode* node : frame_tree_.Nodes()) {
486 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
487 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38488 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38489 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31490 }
carlosk35f35af2015-12-01 10:55:40491
dcheng57e39e22016-01-21 00:25:38492 for (RenderWidgetHostImpl* widget : created_widgets_)
493 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26494 created_widgets_.clear();
495
[email protected]3ab9cb82011-06-03 18:02:07496 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15497 if (dialog_manager_)
avi2460c762015-04-17 15:21:54498 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07499
[email protected]8ed16472014-04-11 19:02:48500 if (color_chooser_info_.get())
501 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20502
[email protected]420ae012009-04-24 05:16:32503 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32504
[email protected]ca13a442012-04-17 14:00:12505 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21506 NotificationService::current()->Notify(
507 NOTIFICATION_WEB_CONTENTS_DESTROYED,
508 Source<WebContents>(this),
509 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32510
[email protected]df0c843f2014-05-23 20:37:23511 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14512 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23513 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59514
clamy0e119882015-07-31 16:12:33515 // Manually call the observer methods for the root frame tree node. It is
516 // necessary to manually delete all objects tracking navigations
517 // (NavigationHandle, NavigationRequest) for observers to be properly
518 // notified of these navigations stopping before the WebContents is
519 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23520 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56521
clamy0e119882015-07-31 16:12:33522 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56523 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33524 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08525 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33526 }
naskob21fe4872015-02-24 14:15:56527 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33528 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08529 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33530
531 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35532 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41533 // Do not update state as the WebContents is being destroyed.
534 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33535 if (root->speculative_frame_host()) {
536 root->speculative_frame_host()->SetRenderFrameCreated(false);
537 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08538 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33539 }
540 }
[email protected]f273ee52013-10-18 16:05:27541
zqzhang181047e62016-07-01 13:37:17542#if defined(ENABLE_PLUGINS)
543 // Call this before WebContentsDestroyed() is broadcasted since
544 // AudioFocusManager will be destroyed after that.
545 pepper_playback_observer_.reset();
546#endif // defined(ENABLED_PLUGINS)
547
naskoa83483fb2015-02-27 16:57:10548 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
549 FrameDeleted(root->current_frame_host()));
550
[email protected]df0c843f2014-05-23 20:37:23551 if (root->pending_render_view_host()) {
552 FOR_EACH_OBSERVER(WebContentsObserver,
553 observers_,
554 RenderViewDeleted(root->pending_render_view_host()));
555 }
[email protected]c06c58c2014-03-12 20:31:59556
[email protected]f273ee52013-10-18 16:05:27557 FOR_EACH_OBSERVER(WebContentsObserver,
558 observers_,
[email protected]df0c843f2014-05-23 20:37:23559 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27560
[email protected]2db9bd72012-04-13 20:20:56561 FOR_EACH_OBSERVER(WebContentsObserver,
562 observers_,
[email protected]12a46832014-05-09 13:35:58563 WebContentsDestroyed());
564
565 FOR_EACH_OBSERVER(WebContentsObserver,
566 observers_,
567 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08568
[email protected]6934a702011-12-20 00:04:51569 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42570}
571
[email protected]d1198fd2012-08-13 22:50:19572WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59573 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21574 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03575 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21576 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19577
alexmosaedfc6f2016-01-21 23:57:38578 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
579
alexmose201c7cd2015-06-10 17:14:21580 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38581 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21582 new_contents->created_with_opener_ = true;
583 }
584
alexmosaedfc6f2016-01-21 23:57:38585 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
586 // flags, and these flags take effect immediately. An exception is if the
587 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
588 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
589 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
590 if (opener) {
591 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
592 const blink::WebSandboxFlags inherit_flag =
593 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
594 if ((opener_flags & inherit_flag) == inherit_flag) {
595 new_root->SetPendingSandboxFlags(opener_flags);
596 new_root->CommitPendingSandboxFlags();
597 }
598 }
599
alexmose201c7cd2015-06-10 17:14:21600 // This may be true even when opener is null, such as when opening blocked
601 // popups.
alexmos090fae8e2015-05-28 17:09:28602 if (params.created_with_opener)
603 new_contents->created_with_opener_ = true;
604
[email protected]4858e432014-06-23 18:14:17605 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06606 // This makes |new_contents| act as a guest.
607 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16608 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06609 // We are instantiating a WebContents for browser plugin. Set its subframe
610 // bit to true.
611 new_contents->is_subframe_ = true;
612 }
[email protected]54944cde2012-12-09 09:24:59613 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19614 return new_contents;
615}
616
[email protected]95640212014-07-26 18:14:30617// static
618std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
619 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08620 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30621 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30622 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30623 RenderViewHost* rvh = RenderViewHost::From(rwh);
624 if (!rvh)
625 continue;
626 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
627 if (!web_contents)
628 continue;
avidf38c952015-10-27 13:45:13629 if (web_contents->GetRenderViewHost() != rvh)
630 continue;
631 // Because a WebContents can only have one current RVH at a time, there will
632 // be no duplicate WebContents here.
633 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30634 }
635 return result;
636}
637
clamya16aa8172015-05-26 13:07:25638// static
639WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
640 FrameTreeNode* frame_tree_node) {
641 return static_cast<WebContentsImpl*>(
642 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
643}
644
clamy0d32d6d2015-11-24 11:16:26645// static
646WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
647 int render_frame_host_id) {
648 DCHECK_CURRENTLY_ON(BrowserThread::UI);
649 RenderFrameHost* render_frame_host =
650 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
651 if (!render_frame_host)
652 return nullptr;
653
654 return WebContents::FromRenderFrameHost(render_frame_host);
655}
656
[email protected]b0936d22013-11-28 06:47:36657RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21658 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28659}
660
[email protected]7bb761892012-07-20 09:32:47661bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
662 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44663 return OnMessageReceived(render_view_host, NULL, message);
664}
665
666bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
667 RenderFrameHost* render_frame_host,
668 const IPC::Message& message) {
669 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56670 if (GetWebUI() &&
671 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17672 return true;
[email protected]d2353452012-01-19 19:53:56673 }
[email protected]f82d57b52011-04-27 19:13:17674
brettw5a1613dc2015-06-02 05:34:43675 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25676 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33677 if (render_frame_host) {
678 while ((observer = it.GetNext()) != NULL)
679 if (observer->OnMessageReceived(message, render_frame_host))
680 return true;
681 } else {
682 while ((observer = it.GetNext()) != NULL)
683 if (observer->OnMessageReceived(message))
684 return true;
685 }
[email protected]403415a2011-01-10 18:57:53686
[email protected]1d62cf72014-02-07 21:31:57687 // Message handlers should be aware of which
688 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
689 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02690 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57691 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02692 else
[email protected]1d62cf72014-02-07 21:31:57693 render_view_message_source_ = render_view_host;
694
[email protected]724159a2010-12-30 01:11:18695 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33696 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40697 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
698 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05699 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
700 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48701 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
702 OnDocumentLoadedInFrame)
703 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
704 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
705 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
706 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
707 OnSetSelectedColorInColorChooser)
dglazkov79c426102015-08-31 21:22:43708 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11709 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25710 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18711 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54712 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18713 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54714 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18715 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41716 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
717 OnDidDisplayContentWithCertificateErrors)
718 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
719 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25720 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26721 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46722 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
723 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21724 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48725 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
726 OnRegisterProtocolHandler)
727 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
728 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01729 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
730 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52731 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10732 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50733 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50734#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00735 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
736 OnPepperInstanceCreated)
737 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
738 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42739 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17740 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
741 OnPepperStartsPlayback)
742 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
743 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42744 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50745 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
746 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55747 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40748 OnBrowserPluginMessage(render_frame_host,
749 message))
thestigc4cac8f2014-09-04 21:17:50750#endif
[email protected]41225fe2013-03-29 05:32:02751 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07752 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
753 OnShowValidationMessage)
754 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
755 OnHideValidationMessage)
756 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
757 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15758#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52759 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48760 OnFindMatchRectsReply)
paulmeyerc8cb7cb2016-06-07 01:14:19761 IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply,
762 OnGetNearestFindResultReply)
[email protected]8ed16472014-04-11 19:02:48763 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
764 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48765#endif
[email protected]724159a2010-12-30 01:11:18766 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33767 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44768 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57769 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18770
[email protected]724159a2010-12-30 01:11:18771 return handled;
772}
773
nasko907fcb62015-01-28 04:24:11774bool WebContentsImpl::HasValidFrameSource() {
775 if (!render_frame_message_source_) {
776 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18777 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
778 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11779 return false;
780 }
781
782 return true;
783}
784
[email protected]d1198fd2012-08-13 22:50:19785NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56786 return controller_;
787}
788
[email protected]d1198fd2012-08-13 22:50:19789const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56790 return controller_;
791}
792
[email protected]8ff00d72012-10-23 19:12:21793BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55794 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30795}
796
[email protected]b172aee2012-04-10 17:05:26797const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24798 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32799 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51800 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31801}
802
[email protected]a093ce02013-07-22 20:53:14803const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24804 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32805 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24806 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
807}
808
809const GURL& WebContentsImpl::GetLastCommittedURL() const {
810 // We may not have a navigation entry yet.
811 NavigationEntry* entry = controller_.GetLastCommittedEntry();
812 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
813}
814
[email protected]8ff00d72012-10-23 19:12:21815WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31816 return delegate_;
817}
818
[email protected]8ff00d72012-10-23 19:12:21819void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31820 // TODO(cbentzel): remove this debugging code?
821 if (delegate == delegate_)
822 return;
823 if (delegate_)
824 delegate_->Detach(this);
825 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08826 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31827 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08828 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00829 if (view_)
[email protected]e85165c642014-06-10 14:34:31830 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08831 }
[email protected]be1f56ab2011-12-22 06:55:31832}
833
[email protected]8ff00d72012-10-23 19:12:21834RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21835 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41836 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16837}
838
clamydf1975e2015-02-05 19:12:24839RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41840 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16841}
842
nick53d5cbf2015-04-23 22:50:14843RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
844 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
845 if (!focused_node)
846 return nullptr;
847 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07848}
849
rob3e2a0732016-01-06 21:22:09850RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
851 int frame_tree_node_id) {
852 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
853 return frame ? frame->current_frame_host() : nullptr;
854}
855
[email protected]a86c0e962013-12-17 17:10:39856void WebContentsImpl::ForEachFrame(
857 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38858 for (FrameTreeNode* node : frame_tree_.Nodes()) {
859 on_frame.Run(node->current_frame_host());
860 }
[email protected]a86c0e962013-12-17 17:10:39861}
862
dchengafb53e22016-02-04 08:11:08863std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
864 std::vector<RenderFrameHost*> frame_hosts;
865 for (FrameTreeNode* node : frame_tree_.Nodes())
866 frame_hosts.push_back(node->current_frame_host());
867 return frame_hosts;
868}
869
lukaszacbdf52e2016-01-15 21:19:51870int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
871 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08872 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25873 if (!rfh->IsRenderFrameLive())
874 continue;
875
dchengafb53e22016-02-04 08:11:08876 ++number_of_messages;
877 IPC::Message* message_copy = new IPC::Message(*message);
878 message_copy->set_routing_id(rfh->GetRoutingID());
879 rfh->Send(message_copy);
880 }
[email protected]a86c0e962013-12-17 17:10:39881 delete message;
lukaszacbdf52e2016-01-15 21:19:51882 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39883}
884
lfgdb5c4ed2016-03-04 23:09:07885void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:41886 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:07887}
888
creisc014b402015-04-23 16:41:45889RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21890 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31891}
892
[email protected]6b618e62012-08-16 12:59:18893int WebContentsImpl::GetRoutingID() const {
894 if (!GetRenderViewHost())
895 return MSG_ROUTING_NONE;
896
897 return GetRenderViewHost()->GetRoutingID();
898}
899
creis89a0f782015-05-27 16:13:17900void WebContentsImpl::CancelActiveAndPendingDialogs() {
901 if (dialog_manager_)
902 dialog_manager_->CancelActiveAndPendingDialogs(this);
903 if (browser_plugin_embedder_)
904 browser_plugin_embedder_->CancelGuestDialogs();
905}
906
naskoc0fceff2015-04-30 15:53:52907void WebContentsImpl::ClosePage() {
908 GetRenderViewHost()->ClosePage();
909}
910
[email protected]b172aee2012-04-10 17:05:26911RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21912 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31913}
914
lfg265a2672016-04-23 03:11:02915RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
916 if (GetOuterWebContents())
917 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
918 return GetRenderManager()->GetRenderWidgetHostView();
919}
920
[email protected]4aebbca2013-09-17 22:26:49921RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
922 const {
923 RenderWidgetHost* const widget_host =
alexmosc9e76ec2016-05-16 22:59:37924 RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
925 fullscreen_widget_routing_id_);
[email protected]4aebbca2013-09-17 22:26:49926 return widget_host ? widget_host->GetView() : NULL;
927}
928
[email protected]8ff00d72012-10-23 19:12:21929WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return view_.get();
931}
932
yusufod41c5f92015-03-06 00:14:28933SkColor WebContentsImpl::GetThemeColor() const {
934 return theme_color_;
935}
936
[email protected]95640212014-07-26 18:14:30937void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
938 if (mode == accessibility_mode_)
939 return;
940
941 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38942
943 for (FrameTreeNode* node : frame_tree_.Nodes()) {
944 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
945 RenderFrameHost* pending_frame_host =
946 node->render_manager()->pending_frame_host();
947 if (pending_frame_host)
948 SetAccessibilityModeOnFrame(mode, pending_frame_host);
949 }
[email protected]95640212014-07-26 18:14:30950}
951
952void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50953 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30954}
955
956void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50957 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30958}
959
dmazzoni83ba5c82015-04-14 07:11:51960void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39961 // Send a request to each of the frames in parallel. Each one will return
962 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
963 // them into a single tree and call |callback| with that result, then
964 // delete |combiner|.
965 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
966 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
967 bool is_root = frame_tree_node->parent() == nullptr;
968 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
969 combiner->AddFrame(is_root));
970 }
dmazzoni83ba5c82015-04-14 07:11:51971}
972
wjmaclean64951902016-04-29 20:59:12973void WebContentsImpl::SetTemporaryZoomLevel(double level,
974 bool temporary_zoom_enabled) {
975 SendPageMessage(new PageMsg_SetZoomLevel(
976 MSG_ROUTING_NONE,
977 temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY
978 : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY,
979 level));
980}
981
982void WebContentsImpl::UpdateZoom(double level) {
983 // Individual frames may still ignore the new zoom level if their RenderView
984 // contains a plugin document or if it uses a temporary zoom level.
985 SendPageMessage(new PageMsg_SetZoomLevel(
986 MSG_ROUTING_NONE,
987 PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level));
988}
989
990void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
991 const std::string& host,
992 double level) {
993 NavigationEntry* entry = GetController().GetLastCommittedEntry();
994 if (!entry)
995 return;
996
997 GURL url = HostZoomMap::GetURLFromEntry(entry);
998 if (host != net::GetHostOrSpecFromURL(url) ||
999 (!scheme.empty() && !url.SchemeIs(scheme))) {
1000 return;
1001 }
1002
1003 UpdateZoom(level);
1004}
1005
rockotf62002a2016-09-15 00:08:591006base::Closure WebContentsImpl::AddBindingSet(
1007 const std::string& interface_name,
1008 WebContentsBindingSet* binding_set) {
1009 auto result =
1010 binding_sets_.insert(std::make_pair(interface_name, binding_set));
1011 DCHECK(result.second);
1012 return base::Bind(&WebContentsImpl::RemoveBindingSet,
1013 weak_factory_.GetWeakPtr(), interface_name);
1014}
1015
wjmaclean8a795f32016-08-11 23:49:581016void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1017 SendPageMessage(
1018 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1019}
1020
ccameron2f451532016-09-07 21:49:271021void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
wjmaclean8a795f32016-08-11 23:49:581022 if (GetView())
ccameron2f451532016-09-07 21:49:271023 GetView()->GetScreenInfo(screen_info);
wjmaclean8a795f32016-08-11 23:49:581024}
1025
dbeama1b926a2015-08-31 23:17:511026WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
1027 const std::string& frame_name) {
1028 DCHECK(!frame_name.empty());
1029 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:221030}
1031
[email protected]8ff00d72012-10-23 19:12:211032WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:401033 WebUI* commited_web_ui = GetCommittedWebUI();
1034 return commited_web_ui ? commited_web_ui
1035 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:311036}
1037
[email protected]8ff00d72012-10-23 19:12:211038WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:401039 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341040}
1041
[email protected]86ef6a392012-05-11 22:03:111042void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:221043 if (GetUserAgentOverride() == override)
1044 return;
1045
1046 renderer_preferences_.user_agent_override = override;
1047
1048 // Send the new override string to the renderer.
1049 RenderViewHost* host = GetRenderViewHost();
1050 if (host)
1051 host->SyncRendererPrefs();
1052
1053 // Reload the page if a load is currently in progress to avoid having
1054 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271055 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:251056 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:051057 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:531058
1059 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1060 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:111061}
1062
1063const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:221064 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111065}
1066
[email protected]95640212014-07-26 18:14:301067void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:081068 if (GetAccessibilityMode() != AccessibilityModeOff) {
1069 for (RenderFrameHost* rfh : GetAllFrames())
1070 ResetAccessibility(rfh);
1071 } else {
dtseng0dd3fa12015-07-22 19:00:521072 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:081073 }
[email protected]95640212014-07-26 18:14:301074}
1075
1076bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
1077 return accessibility_mode_ == AccessibilityModeTreeOnly;
1078}
1079
1080bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
1081 return accessibility_mode_ == AccessibilityModeComplete;
1082}
1083
kouhei40f03cb2015-09-24 07:47:011084const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
1085 return page_importance_signals_;
1086}
1087
[email protected]fcf75d42013-12-03 20:11:261088const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:551089 // Transient entries take precedence. They are used for interstitial pages
1090 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231091 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231092 if (entry) {
jshin1fb76462016-04-05 22:13:031093 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231094 }
carlosk35f35af2015-12-01 10:55:401095
1096 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
1097 WebUI* our_web_ui = navigating_web_ui
1098 ? navigating_web_ui
1099 : GetRenderManager()->current_frame_host()->web_ui();
1100
[email protected]7ade2732011-02-10 00:13:581101 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541102 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321103 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541104 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351105 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261106 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541107 if (!title.empty())
1108 return title;
1109 }
1110 }
1111
1112 // We use the title for the last committed entry rather than a pending
1113 // navigation entry. For example, when the user types in a URL, we want to
1114 // keep the old page's title until the new load has committed and we get a new
1115 // title.
[email protected]96d185d2009-04-24 03:28:541116 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321117
creis072b61f2015-09-28 20:52:241118 // We make an exception for initial navigations. We only want to use the title
1119 // from the visible entry if:
1120 // 1. The pending entry has been explicitly assigned a title to display.
1121 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1122 // which case there is a pending entry index other than -1.
1123 //
1124 // Otherwise, we want to stick with the last committed entry's title during
1125 // new navigations, which have pending entries at index -1 with no title.
1126 if (controller_.IsInitialNavigation() &&
1127 ((controller_.GetVisibleEntry() &&
1128 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1129 controller_.GetPendingEntryIndex() != -1)) {
1130 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471131 }
[email protected]59167c22013-06-03 18:07:321132
[email protected]45d0ef7f2011-01-05 13:46:231133 if (entry) {
jshin1fb76462016-04-05 22:13:031134 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231135 }
[email protected]987fc3a2011-05-26 14:18:091136
1137 // |page_title_when_no_navigation_entry_| is finally used
1138 // if no title cannot be retrieved.
1139 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541140}
1141
avib7348942015-12-25 20:57:101142int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461143 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1144}
1145
avib7348942015-12-25 20:57:101146int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261147 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331148 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1149 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461150
[email protected]b6583592012-01-25 19:52:331151 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341152}
1153
avib7348942015-12-25 20:57:101154void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461155 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1156}
1157
[email protected]b172aee2012-04-10 17:05:261158void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101159 SiteInstance* site_instance,
1160 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461161 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331162 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341163}
1164
[email protected]ec6c05f2013-10-23 18:41:571165void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1166 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1167 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571168}
1169
creiscce56cd2014-09-29 22:45:221170SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211171 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541172}
1173
creiscce56cd2014-09-29 22:45:221174SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1175 RenderViewHostImpl* dest_rvh =
1176 GetRenderManager()->pending_render_view_host() ?
1177 GetRenderManager()->pending_render_view_host() :
1178 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581179 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381180}
1181
[email protected]b172aee2012-04-10 17:05:261182bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251183 return frame_tree_.IsLoading() &&
1184 !(ShowingInterstitialPage() &&
1185 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491186}
1187
[email protected]6dfed692014-05-22 04:18:031188bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251189 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031190}
1191
[email protected]b172aee2012-04-10 17:05:261192bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031193 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311194}
1195
[email protected]b172aee2012-04-10 17:05:261196const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311197 return load_state_;
1198}
1199
[email protected]fcf75d42013-12-03 20:11:261200const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311201 return load_state_host_;
1202}
1203
avib7348942015-12-25 20:57:101204uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311205 return upload_size_;
1206}
1207
avib7348942015-12-25 20:57:101208uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311209 return upload_position_;
1210}
1211
[email protected]b172aee2012-04-10 17:05:261212const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541213 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311214}
1215
[email protected]222f5822014-02-05 23:40:491216void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251217 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551218 ++capturer_count_;
1219 DVLOG(1) << "There are now " << capturer_count_
1220 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491221
1222 // Note: This provides a hint to upstream code to size the views optimally
1223 // for quality (e.g., to avoid scaling).
1224 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1225 preferred_size_for_capture_ = capture_size;
1226 OnPreferredSizeChanged(preferred_size_);
1227 }
ccameron8807c38f2015-01-17 00:29:191228
1229 // Ensure that all views are un-occluded before capture begins.
1230 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551231}
1232
1233void WebContentsImpl::DecrementCapturerCount() {
1234 --capturer_count_;
1235 DVLOG(1) << "There are now " << capturer_count_
1236 << " capturing(s) of WebContentsImpl@" << this;
1237 DCHECK_LE(0, capturer_count_);
1238
[email protected]5a652232013-02-12 06:15:251239 if (is_being_destroyed_)
1240 return;
1241
[email protected]222f5822014-02-05 23:40:491242 if (capturer_count_ == 0) {
1243 const gfx::Size old_size = preferred_size_for_capture_;
1244 preferred_size_for_capture_ = gfx::Size();
1245 OnPreferredSizeChanged(old_size);
1246 }
1247
[email protected]1ac10dca2013-08-20 20:47:041248 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551249 DVLOG(1) << "Executing delayed WasHidden().";
1250 WasHidden();
1251 }
[email protected]be1f56ab2011-12-22 06:55:311252}
1253
[email protected]f2bd40812013-07-20 04:30:441254int WebContentsImpl::GetCapturerCount() const {
1255 return capturer_count_;
1256}
1257
miu50f97892014-09-22 22:49:521258bool WebContentsImpl::IsAudioMuted() const {
1259 return audio_muter_.get() && audio_muter_->is_muting();
1260}
1261
1262void WebContentsImpl::SetAudioMuted(bool mute) {
1263 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1264 << " for WebContentsImpl@" << this;
1265
1266 if (mute == IsAudioMuted())
1267 return;
1268
1269 if (mute) {
1270 if (!audio_muter_)
1271 audio_muter_.reset(new WebContentsAudioMuter(this));
1272 audio_muter_->StartMuting();
1273 } else {
1274 DCHECK(audio_muter_);
1275 audio_muter_->StopMuting();
1276 }
1277
wjmaclean2f797c782016-01-07 14:52:031278 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1279 DidUpdateAudioMutingState(mute));
1280
miu50f97892014-09-22 22:49:521281 // Notification for UI updates in response to the changed muting state.
1282 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1283}
1284
ortunodf4d7982016-04-08 02:33:351285bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1286 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201287}
1288
[email protected]b172aee2012-04-10 17:05:261289bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311290 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1291 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581292 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271293#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581294 crashed_status_ ==
1295 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271296#endif
wfh0d9532a2015-09-02 23:18:581297 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271298 );
[email protected]3c9e1872010-11-18 16:17:491299}
1300
[email protected]b172aee2012-04-10 17:05:261301void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1302 int error_code) {
[email protected]443b80e2010-12-14 00:42:231303 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341304 return;
1305
[email protected]443b80e2010-12-14 00:42:231306 crashed_status_ = status;
1307 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211308 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341309}
1310
[email protected]b172aee2012-04-10 17:05:261311base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311312 return crashed_status_;
1313}
1314
afakhry98241832016-03-11 19:27:471315int WebContentsImpl::GetCrashedErrorCode() const {
1316 return crashed_error_code_;
1317}
1318
[email protected]b172aee2012-04-10 17:05:261319bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311320 return is_being_destroyed_;
1321}
1322
[email protected]7f924832014-08-09 05:57:221323void WebContentsImpl::NotifyNavigationStateChanged(
1324 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541325 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1326 // is fixed.
1327 tracked_objects::ScopedTracker tracking_profile(
1328 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1329 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181330 // Notify the media observer of potential audibility changes.
1331 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271332 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301333 }
1334
[email protected]d5f942ba2008-09-26 19:30:341335 if (delegate_)
1336 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441337
1338 if (GetOuterWebContents())
1339 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341340}
1341
gab0dccfef2015-05-20 18:43:391342base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021343 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331344}
1345
georgesak5582cbe2015-05-22 22:08:071346void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1347 last_active_time_ = last_active_time;
1348}
1349
[email protected]9e2e4632012-07-27 16:38:411350void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541351 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591352
ccameron8807c38f2015-01-17 00:29:191353 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1354 if (view) {
1355 view->Show();
[email protected]789e9152009-08-04 21:59:431356#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191357 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431358#endif
[email protected]de3c5d82014-05-28 22:12:591359 }
[email protected]789e9152009-08-04 21:59:431360 }
[email protected]96d185d2009-04-24 03:28:541361
lfg717154072016-06-30 15:04:161362 SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE));
1363
gab0dccfef2015-05-20 18:43:391364 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381365
[email protected]b9769d82012-02-10 00:23:591366 // The resize rect might have changed while this was inactive -- send the new
1367 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451368 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221369 if (rvh) {
1370 rvh->GetWidget()->ResizeRectChanged(
1371 GetRootWindowResizerRect(rvh->GetWidget()));
1372 }
[email protected]96d185d2009-04-24 03:28:541373
[email protected]c0d9d5672013-10-09 07:38:031374 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1375
[email protected]54597982013-02-06 01:59:551376 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311377}
1378
[email protected]b172aee2012-04-10 17:05:261379void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551380 // If there are entities capturing screenshots or video (e.g., mirroring),
1381 // don't activate the "disable rendering" optimization.
1382 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521383 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551384 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261385 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521386 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331387 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521388 // calls us).
ccameron8807c38f2015-01-17 00:29:191389 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1390 if (view)
1391 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591392 }
lfg717154072016-06-30 15:04:161393
1394 SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE));
[email protected]96d185d2009-04-24 03:28:541395 }
1396
[email protected]c0d9d5672013-10-09 07:38:031397 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1398
[email protected]54597982013-02-06 01:59:551399 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371400}
1401
ccameron8807c38f2015-01-17 00:29:191402void WebContentsImpl::WasOccluded() {
1403 if (capturer_count_ > 0)
1404 return;
1405
1406 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1407 if (view)
1408 view->WasOccluded();
1409 }
1410}
1411
1412void WebContentsImpl::WasUnOccluded() {
1413 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1414 if (view)
1415 view->WasUnOccluded();
1416 }
1417}
1418
[email protected]b172aee2012-04-10 17:05:261419bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311420 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451421 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1422 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311423}
1424
nasko148bb0b92016-05-10 21:03:191425void WebContentsImpl::DispatchBeforeUnload() {
1426 bool for_cross_site_transition = false;
clamybfd6a812016-05-30 16:25:171427 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false);
[email protected]1c3f80bd2014-04-08 23:02:061428}
1429
lazyboy6ec48b2a2015-06-29 15:18:141430void WebContentsImpl::AttachToOuterWebContentsFrame(
1431 WebContents* outer_web_contents,
1432 RenderFrameHost* outer_contents_frame) {
ekaramad1beabecc2016-09-23 20:18:171433 CHECK(GuestMode::IsCrossProcessFrameGuest(this));
lfg91a79e12016-04-01 23:52:191434 RenderFrameHostManager* render_manager = GetRenderManager();
1435
1436 // When the WebContents being initialized has an opener, the browser side
1437 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1438 // created. This is needed because the usual initialization happens during
1439 // the first navigation, but when attaching a new window we don't navigate
1440 // before attaching. If the browser side is already initialized, the calls
1441 // below will just early return.
1442 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1443 GetMainFrame()->Init();
1444 if (!render_manager->GetRenderWidgetHostView())
1445 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1446
lazyboy6ec48b2a2015-06-29 15:18:141447 // Create a link to our outer WebContents.
1448 node_.reset(new WebContentsTreeNode());
1449 node_->ConnectToOuterWebContents(
1450 static_cast<WebContentsImpl*>(outer_web_contents),
1451 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1452
1453 DCHECK(outer_contents_frame);
1454
1455 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1456 // SiteInstance of the outer WebContents. The proxy will be used to send
1457 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191458 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141459 outer_contents_frame->GetSiteInstance(),
1460 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1461
lfg91a79e12016-04-01 23:52:191462 render_manager->SetRWHViewForInnerContents(
1463 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391464
1465 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191466 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391467 ->RegisterSurfaceNamespaceId();
ekaramadadd882292016-06-08 15:22:561468
1469 // At this point, we should destroy the TextInputManager which will notify all
1470 // the RWHV in this WebContents. The RWHV in this WebContents should use the
1471 // TextInputManager owned by the outer WebContents.
1472 // TODO(ekaramad): Is it possible to have TextInputState before attaching to
1473 // outer WebContents? In such a case, is this still the right way to hand off
1474 // state tracking from inner WebContents's TextInputManager to that of the
1475 // outer WebContent (crbug.com/609846)?
1476 text_input_manager_.reset(nullptr);
lazyboy6ec48b2a2015-06-29 15:18:141477}
1478
[email protected]b172aee2012-04-10 17:05:261479void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381480 for (FrameTreeNode* node : frame_tree_.Nodes())
1481 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401482 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271483}
1484
[email protected]b172aee2012-04-10 17:05:261485WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441486 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211487 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451488 // before.
[email protected]54944cde2012-12-09 09:24:591489 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451490 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211491 WebContentsImpl* tc =
1492 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191493 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221494 FOR_EACH_OBSERVER(WebContentsObserver,
1495 observers_,
1496 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271497 return tc;
1498}
1499
[email protected]14392a52012-05-02 20:28:441500void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211501 const NotificationSource& source,
1502 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441503 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211504 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1505 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031506 RenderWidgetHostView* view = host->GetView();
1507 if (view == GetFullscreenRenderWidgetHostView()) {
1508 // We cannot just call view_->RestoreFocus() here. On some platforms,
1509 // attempting to focus the currently-invisible WebContentsView will be
1510 // flat-out ignored. Therefore, this boolean is used to track whether
1511 // we will request focus after the fullscreen widget has been
1512 // destroyed.
1513 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1514 } else {
alexmosc2a8cec2016-05-23 22:19:531515 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:031516 i != pending_widget_views_.end(); ++i) {
1517 if (host->GetView() == i->second) {
1518 pending_widget_views_.erase(i);
1519 break;
1520 }
[email protected]bafe6cd2012-05-23 23:09:501521 }
1522 }
1523 break;
1524 }
[email protected]14392a52012-05-02 20:28:441525 default:
1526 NOTREACHED();
1527 }
1528}
1529
[email protected]ec6c05f2013-10-23 18:41:571530WebContents* WebContentsImpl::GetWebContents() {
1531 return this;
1532}
1533
[email protected]54944cde2012-12-09 09:24:591534void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211535 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361536 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211537 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431538 should_normally_be_visible_ = !params.initially_hidden;
1539
dcheng3ce04b62015-10-26 23:30:551540 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541541 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551542 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1543 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541544 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551545 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1546 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1547
1548 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1549 if (!site_instance)
1550 site_instance = SiteInstance::Create(params.browser_context);
1551
1552 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1553 // local root by definition.
1554 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1555 // longer be necessary to eagerly grab a routing ID for the view.
1556 // https://crbug.com/545684
1557 int32_t view_routing_id = params.routing_id;
1558 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1559 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1560 view_routing_id = main_frame_widget_routing_id =
1561 site_instance->GetProcess()->GetNextRoutingID();
1562 }
1563
1564 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1565 params.main_frame_routing_id,
1566 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321567
lukasza5140a412016-09-15 21:12:301568 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
1569 // main frame - let's do the same thing here.
1570 std::string unique_name;
lukasza464d8692016-02-22 19:26:321571 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191572
[email protected]fc2b46b2014-05-03 16:33:451573 WebContentsViewDelegate* delegate =
1574 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1575
sadrul943e3b32016-08-04 18:22:591576#if defined(USE_AURA)
ben6c85c4492016-06-16 20:40:511577 if (MojoShellConnection::GetForProcess() &&
fsamueladb0033602015-12-09 19:20:411578 base::CommandLine::ForCurrentProcess()->HasSwitch(
1579 switches::kUseMusInRenderer)) {
ben3a06a272016-07-04 05:00:101580 ui::Window* mus_window = aura::GetMusWindow(params.context);
fsamueladb0033602015-12-09 19:20:411581 if (mus_window) {
1582 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1583 &render_view_host_delegate_view_));
1584 }
1585 }
1586#endif
1587
1588 if (!view_) {
ekaramad1beabecc2016-09-23 20:18:171589 if (GuestMode::IsCrossProcessFrameGuest(this)) {
lfgc740d4b22016-04-15 16:45:331590 view_.reset(new WebContentsViewChildFrame(
1591 this, delegate, &render_view_host_delegate_view_));
1592 } else {
1593 view_.reset(CreateWebContentsView(this, delegate,
1594 &render_view_host_delegate_view_));
1595 }
fsamueladb0033602015-12-09 19:20:411596 }
fsamuel9cf7bdf2015-11-20 02:19:321597
ekaramad1beabecc2016-09-23 20:18:171598 if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) {
fsamuel9cf7bdf2015-11-20 02:19:321599 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361600 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321601 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191602 }
[email protected]fc2b46b2014-05-03 16:33:451603 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191604 CHECK(view_.get());
1605
[email protected]ed245db2012-12-18 08:00:451606 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591607 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191608
tommyclieb25b2a2014-11-03 19:45:091609#if defined(ENABLE_PLUGINS)
1610 plugin_content_origin_whitelist_.reset(
1611 new PluginContentOriginWhitelist(this));
1612#endif
1613
[email protected]d1198fd2012-08-13 22:50:191614 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211615 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1616 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101617
[email protected]01f83f92014-06-17 14:41:541618 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091619 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541620
mlamouriefdca9d2014-09-16 16:55:401621 manifest_manager_host_.reset(new ManifestManagerHost(this));
1622
mfomitchev2b8b066a2016-01-28 19:23:151623#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101624 date_time_chooser_.reset(new DateTimeChooserAndroid());
1625#endif
fsamuel7310a4262014-12-05 05:06:441626
1627 // BrowserPluginGuest::Init needs to be called after this WebContents has
1628 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1629 if (browser_plugin_guest_)
1630 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371631
1632 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1633 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561634
1635 // If the WebContents creation was renderer-initiated, it means that the
1636 // corresponding RenderView and main RenderFrame have already been created.
1637 // Ensure observers are notified about this.
1638 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431639 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561640 RenderViewCreated(GetRenderViewHost());
1641 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1642 }
naskof5940b9f2015-03-02 23:04:051643
lof84501da082016-05-23 21:22:541644 // Create the renderer process in advance if requested.
1645 if (params.initialize_renderer) {
1646 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
1647 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
1648 }
1649 }
1650
naskof5940b9f2015-03-02 23:04:051651 // Ensure that observers are notified of the creation of this WebContents's
1652 // main RenderFrameHost. It must be done here for main frames, since the
1653 // NotifySwappedFromRenderManager expects view_ to already be created and that
1654 // happens after RenderFrameHostManager::Init.
1655 NotifySwappedFromRenderManager(
1656 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191657}
1658
[email protected]7fff43e2013-05-21 20:21:101659void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1660 RemoveDestructionObserver(web_contents);
1661
[email protected]ceee8cd2013-03-08 04:59:511662 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:531663 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:511664 ++iter) {
1665 if (iter->second != web_contents)
1666 continue;
1667 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511668 return;
1669 }
1670 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441671}
1672
[email protected]7fff43e2013-05-21 20:21:101673void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1674 if (!ContainsKey(destruction_observers_, web_contents)) {
1675 destruction_observers_[web_contents] =
avia8cf81982016-08-12 20:28:461676 base::MakeUnique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:101677 }
1678}
1679
1680void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:461681 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:101682}
1683
[email protected]b172aee2012-04-10 17:05:261684void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311685 observers_.AddObserver(observer);
1686}
1687
[email protected]b172aee2012-04-10 17:05:261688void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311689 observers_.RemoveObserver(observer);
1690}
1691
[email protected]948481d2014-06-11 18:32:221692std::set<RenderWidgetHostView*>
1693WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1694 std::set<RenderWidgetHostView*> set;
1695 if (ShowingInterstitialPage()) {
1696 set.insert(GetRenderWidgetHostView());
1697 } else {
dchengafb53e22016-02-04 08:11:081698 for (RenderFrameHost* rfh : GetAllFrames()) {
1699 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1700 ->frame_tree_node()
1701 ->render_manager()
1702 ->GetRenderWidgetHostView();
1703 set.insert(rwhv);
1704 }
[email protected]948481d2014-06-11 18:32:221705 }
[email protected]de3c5d82014-05-28 22:12:591706 return set;
1707}
1708
[email protected]b172aee2012-04-10 17:05:261709void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341710 if (delegate_)
1711 delegate_->ActivateContents(this);
1712}
1713
avi3e4b8512015-11-11 01:55:491714void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1715 if (!RenderViewHostImpl::From(render_widget_host))
1716 return;
1717
[email protected]63954792011-07-11 04:17:481718 if (delegate_)
1719 delegate_->LostCapture();
1720}
1721
lazyboy63f5b312015-11-23 20:19:521722void WebContentsImpl::RenderWidgetCreated(
1723 RenderWidgetHostImpl* render_widget_host) {
1724 created_widgets_.insert(render_widget_host);
1725}
1726
[email protected]b24b68a2012-09-24 21:57:261727void WebContentsImpl::RenderWidgetDeleted(
1728 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521729 // Note that |is_being_destroyed_| can be true at this point as
1730 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1731 // us here.
1732 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261733
lazyboy63f5b312015-11-23 20:19:521734 if (is_being_destroyed_)
1735 return;
[email protected]44470a22013-01-24 01:21:541736
1737 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:371738 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
1739 render_widget_host->GetProcess()->GetID() ==
1740 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:491741 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531742 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541743 FOR_EACH_OBSERVER(WebContentsObserver,
1744 observers_,
alexmos899e06f2016-05-13 23:08:091745 DidDestroyFullscreenWidget());
alexmosc9e76ec2016-05-16 22:59:371746 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:541747 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031748 if (fullscreen_widget_had_focus_at_shutdown_)
1749 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541750 }
lfgbee1e0a2016-06-08 21:24:211751
lfgad8244352016-07-13 16:55:511752 CHECK(mouse_lock_widget_ != render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261753}
1754
miu9e14e492014-10-25 02:39:041755void WebContentsImpl::RenderWidgetGotFocus(
1756 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371757 // Notify the observers if an embedded fullscreen widget was focused.
1758 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1759 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1760 NotifyWebContentsFocused();
1761 }
miu9e14e492014-10-25 02:39:041762}
1763
estaded0a0c992015-01-21 14:12:061764void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311765 RenderWidgetHostImpl* render_widget_host,
1766 bool width_changed) {
creisc014b402015-04-23 16:41:451767 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291768 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061769 return;
estaded0a0c992015-01-21 14:12:061770
rouslan2f5993f2015-01-29 00:18:311771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1772 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061773}
1774
paulmeyer9ef6e4462015-02-24 19:15:101775void WebContentsImpl::ScreenInfoChanged() {
1776 if (browser_plugin_embedder_)
1777 browser_plugin_embedder_->ScreenInfoChanged();
1778}
1779
[email protected]b172aee2012-04-10 17:05:261780bool WebContentsImpl::PreHandleKeyboardEvent(
1781 const NativeWebKeyboardEvent& event,
1782 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481783 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131784 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481785}
1786
[email protected]b172aee2012-04-10 17:05:261787void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101788 if (browser_plugin_embedder_ &&
1789 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1790 return;
1791 }
[email protected]63954792011-07-11 04:17:481792 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131793 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481794}
1795
[email protected]d92026ef2014-03-03 21:04:131796bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461797 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191798#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331799 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1800 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191801 // -the OS already has a gesture to do this through pinch-zoom
1802 // -if a user starts an inertial scroll, let's go, and presses control
1803 // (i.e. control+tab) then the OS's buffered scroll events will come in
1804 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331805 if (delegate_ && event.wheelTicksY &&
chongz4a9751942016-08-17 17:49:391806 !ui::WebInputEventTraits::CanCauseScroll(event)) {
w.shackleton49bcd392016-01-06 17:38:221807 // Count only integer cumulative scrolls as zoom events; this handles
1808 // smooth scroll and regular scroll device behavior.
1809 zoom_scroll_remainder_ += event.wheelTicksY;
1810 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1811 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1812 if (whole_zoom_scroll_remainder_ != 0) {
1813 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1814 }
[email protected]fb3f066e2013-02-12 19:12:521815 return true;
1816 }
[email protected]bccc4472013-04-18 16:37:191817#endif
[email protected]fb3f066e2013-02-12 19:12:521818 return false;
1819}
1820
[email protected]04bce562014-01-30 05:34:541821bool WebContentsImpl::PreHandleGestureEvent(
1822 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031823 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541824}
1825
kenrb2a565f82015-09-02 20:24:591826RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451827 if (!is_being_destroyed_ && GetOuterWebContents())
1828 return GetOuterWebContents()->GetInputEventRouter();
1829
1830 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591831 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1832 return rwh_input_event_router_.get();
1833}
1834
alexmos3fcd0ca2015-10-23 18:18:331835void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1836 // Focus loss may occur while this WebContents is being destroyed. Don't
1837 // send the message in this case, as the main frame's RenderFrameHost and
1838 // other state has already been cleared.
1839 if (is_being_destroyed_)
1840 return;
1841
1842 frame_tree_.ReplicatePageFocus(is_focused);
1843}
1844
alexmosc4cbacb2015-11-21 01:29:221845RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1846 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521847 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221848 return receiving_widget;
1849
1850 // Events for widgets other than the main frame (e.g., popup menus) should be
1851 // forwarded directly to the widget they arrived on.
1852 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1853 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521854
avallee0206f782016-07-28 18:55:331855 FrameTreeNode* focused_frame =
1856 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
alexmosc4d183e2015-11-06 00:46:521857 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221858 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521859
alexmos732ca3a2015-12-08 02:01:021860 // The view may be null if a subframe's renderer process has crashed while
1861 // the subframe has focus. Drop the event in that case. Do not give
1862 // it to the main frame, so that the user doesn't unexpectedly type into the
1863 // wrong frame if a focused subframe renderer crashes while they type.
1864 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1865 if (!view)
1866 return nullptr;
1867
1868 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521869}
1870
mlamouri7a78d6fd2015-01-17 13:23:531871void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1872 // This method is being called to enter renderer-initiated fullscreen mode.
1873 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491874 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371875 if (widget_view) {
1876 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1877 ->ShutdownAndDestroyWidget(true);
1878 }
[email protected]4aebbca2013-09-17 22:26:491879
[email protected]8a5e0ca2011-08-25 06:30:471880 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531881 delegate_->EnterFullscreenModeForTab(this, origin);
1882
alexmos5dd617d2016-06-07 04:21:151883 FOR_EACH_OBSERVER(
1884 WebContentsObserver, observers_,
1885 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false));
mlamouri7a78d6fd2015-01-17 13:23:531886}
1887
bokanece34a82016-01-28 19:49:461888void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531889 // This method is being called to leave renderer-initiated fullscreen mode.
1890 // Make sure any existing fullscreen widget is shut down first.
1891 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371892 if (widget_view) {
1893 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1894 ->ShutdownAndDestroyWidget(true);
1895 }
mlamouri7a78d6fd2015-01-17 13:23:531896
hugo.holgersson61288e6c2015-01-28 17:04:401897#if defined(OS_ANDROID)
1898 ContentVideoView* video_view = ContentVideoView::GetInstance();
1899 if (video_view != NULL)
watk98292292016-01-19 22:24:081900 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401901#endif
1902
mlamouri7a78d6fd2015-01-17 13:23:531903 if (delegate_)
1904 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371905
bokanece34a82016-01-28 19:49:461906 // The fullscreen state is communicated to the renderer through a resize
1907 // message. If the change in fullscreen state doesn't cause a view resize
1908 // then we must ensure web contents exit the fullscreen state by explicitly
1909 // sending a resize message. This is required for the situation of the browser
1910 // moving the view into a "browser fullscreen" state and then the contents
1911 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1912 // have the side effect of the view resizing, hence the explicit call here is
1913 // required.
1914 if (!will_cause_resize) {
1915 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1916 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1917 render_widget_host->WasResized();
1918 }
scheib3dcb6c932015-02-23 10:55:581919 }
1920
avibf58fa0c2015-11-11 01:45:521921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
alexmos5dd617d2016-06-07 04:21:151922 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
1923 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471924}
1925
alexmos5dd617d2016-06-07 04:21:151926bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381927 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121928}
1929
avibf58fa0c2015-11-11 01:45:521930blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1931 RenderWidgetHostImpl* render_widget_host) const {
1932 if (!RenderViewHostImpl::From(render_widget_host))
1933 return blink::WebDisplayModeBrowser;
1934
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121935 return delegate_ ? delegate_->GetDisplayMode(this)
1936 : blink::WebDisplayModeBrowser;
1937}
1938
avic3aa8422015-11-09 20:57:221939void WebContentsImpl::RequestToLockMouse(
1940 RenderWidgetHostImpl* render_widget_host,
1941 bool user_gesture,
lfgad8244352016-07-13 16:55:511942 bool last_unlocked_by_target,
1943 bool privileged) {
lfgbee1e0a2016-06-08 21:24:211944 if (mouse_lock_widget_) {
avic3aa8422015-11-09 20:57:221945 render_widget_host->GotResponseToLockMouseRequest(false);
1946 return;
[email protected]e9621112011-10-17 05:38:371947 }
avic3aa8422015-11-09 20:57:221948
lfgad8244352016-07-13 16:55:511949 if (privileged) {
1950 mouse_lock_widget_ = render_widget_host;
1951 render_widget_host->GotResponseToLockMouseRequest(true);
1952 return;
1953 }
1954
lfgbee1e0a2016-06-08 21:24:211955 bool widget_in_frame_tree = false;
1956 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1957 if (node->current_frame_host()->GetRenderWidgetHost() ==
1958 render_widget_host) {
1959 widget_in_frame_tree = true;
1960 break;
1961 }
1962 }
1963
1964 if (widget_in_frame_tree && delegate_) {
1965 mouse_lock_widget_ = render_widget_host;
avic3aa8422015-11-09 20:57:221966 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:211967 } else {
1968 render_widget_host->GotResponseToLockMouseRequest(false);
1969 }
[email protected]e9621112011-10-17 05:38:371970}
1971
avi3e4b8512015-11-11 01:55:491972void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:211973 CHECK(mouse_lock_widget_);
1974 mouse_lock_widget_->SendMouseLockLost();
1975 mouse_lock_widget_ = nullptr;
avi3e4b8512015-11-11 01:55:491976
[email protected]e9621112011-10-17 05:38:371977 if (delegate_)
1978 delegate_->LostMouseLock();
1979}
1980
lfgad8244352016-07-13 16:55:511981bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
1982 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
1983 // assigned to the widget that requested the mouse lock, and the top-level
1984 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
1985 return mouse_lock_widget_ == render_widget_host &&
1986 GetTopLevelRenderWidgetHostView()->IsMouseLocked();
1987}
1988
dtrainor5ef644e2015-11-19 00:12:471989void WebContentsImpl::ForwardCompositorProto(
1990 RenderWidgetHostImpl* render_widget_host,
1991 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471992 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291993 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471994}
1995
ekaramada4f42692016-02-11 19:48:371996void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
lfg9462cef2016-07-18 23:51:061997 if (visible && !GetOuterWebContents()->IsHidden())
ekaramada4f42692016-02-11 19:48:371998 WasShown();
lfg9462cef2016-07-18 23:51:061999 else if (!visible)
ekaramada4f42692016-02-11 19:48:372000 WasHidden();
2001}
2002
[email protected]bafe6cd2012-05-23 23:09:502003void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:432004 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:552005 int32_t route_id,
2006 int32_t main_frame_route_id,
2007 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:182008 const mojom::CreateNewWindowParams& params,
[email protected]97714c82012-06-06 10:15:132009 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:502010 // We usually create the new window in the same BrowsingInstance (group of
2011 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:552012 // if the opener is being suppressed (in a non-guest), we create a new
2013 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:252014 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:552015
[email protected]04cbd3d2013-12-04 04:58:202016 // If the opener is to be suppressed, the new window can be in any process.
2017 // Since routing ids are process specific, we must not have one passed in
2018 // as argument here.
2019 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
2020
[email protected]bafe6cd2012-05-23 23:09:502021 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:432022 params.opener_suppressed && !is_guest
2023 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
2024 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:502025
alexmos4cf2aa32015-07-15 23:40:432026 // A message to create a new window can only come from a process for a frame
2027 // in this WebContents' FrameTree. If any other process sends the request, it
2028 // is invalid and the process must be terminated.
2029 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:382030 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:432031 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:352032 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:202033 if (process_handle != base::kNullProcessHandle) {
2034 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392035 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:352036 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:202037 }
2038 return;
2039 }
2040
[email protected]d1198fd2012-08-13 22:50:192041 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:342042 //
2043 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:302044 const std::string& partition_id =
2045 GetContentClient()->browser()->
2046 GetStoragePartitionIdForSite(GetBrowserContext(),
2047 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:462048 StoragePartition* partition = BrowserContext::GetStoragePartition(
2049 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:412050 DOMStorageContextWrapper* dom_storage_context =
2051 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:192052 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2053 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2054 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:372055
2056 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:552057 !delegate_->ShouldCreateWebContents(
2058 this, route_id, main_frame_route_id, main_frame_widget_route_id,
2059 params.window_container_type, params.frame_name, params.target_url,
2060 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:012061 if (route_id != MSG_ROUTING_NONE &&
2062 !RenderViewHost::FromID(render_process_id, route_id)) {
2063 // If the embedder didn't create a WebContents for this route, we need to
2064 // delete the RenderView that had already been created.
2065 Send(new ViewMsg_Close(route_id));
2066 }
csharrisona2280cd2016-02-03 23:21:152067 // It's safe to only target the frame because the render process will not
2068 // have a chance to create more frames at this point.
2069 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
2070 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:372071 return;
2072 }
2073
2074 // Create the new web contents. This will automatically create the new
2075 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462076 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:592077 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:042078 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:552079 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:122080 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432081 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:212082 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:062083 create_params.opener_suppressed = params.opener_suppressed;
nick3b04f322016-08-31 19:29:192084 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
[email protected]50d326e2014-05-20 17:59:062085 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:192086 create_params.renderer_initiated_creation =
2087 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:062088
[email protected]4858e432014-06-23 18:14:172089 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:552090 if (!is_guest) {
2091 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:452092 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:172093 new_contents = static_cast<WebContentsImpl*>(
2094 WebContents::Create(create_params));
2095 } else {
2096 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:552097 }
[email protected]50d326e2014-05-20 17:59:062098 new_contents->GetController().SetSessionStorageNamespace(
2099 partition_id,
2100 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192101
alexmos646fec02015-07-25 00:11:492102 // If the new frame has a name, make sure any SiteInstances that can find
2103 // this named frame have proxies for it. Must be called after
2104 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2105 // GetSessionStorageNamespace.
2106 if (!params.frame_name.empty())
2107 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
2108
[email protected]c4538072013-03-18 02:17:552109 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342110 // will be shown immediately).
2111 if (!params.opener_suppressed) {
2112 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:452113 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502114
[email protected]d70bea92013-04-05 04:23:342115 // TODO(brettw): It seems bogus that we have to call this function on the
2116 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:432117 new_view->CreateViewForWidget(
2118 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:342119 }
[email protected]bafe6cd2012-05-23 23:09:502120 // Save the created window associated with the route so we can show it
2121 // later.
2122 DCHECK_NE(MSG_ROUTING_NONE, route_id);
alexmosc2a8cec2016-05-23 22:19:532123 pending_contents_[std::make_pair(render_process_id, route_id)] =
2124 new_contents;
[email protected]7fff43e2013-05-21 20:21:102125 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502126 }
2127
2128 if (delegate_) {
2129 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:072130 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:132131 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:502132 }
2133
2134 if (params.opener_suppressed) {
2135 // When the opener is suppressed, the original renderer cannot access the
2136 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002137 bool was_blocked = false;
2138 if (delegate_) {
bokan107a47f2015-02-03 23:23:392139 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002140 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392141 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002142 params.user_gesture, &was_blocked);
2143 }
2144 if (!was_blocked) {
nick3b04f322016-08-31 19:29:192145 OpenURLParams open_params(params.target_url, params.referrer,
2146 WindowOpenDisposition::CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352147 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212148 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302149 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372150
2151 if (delegate_ && !is_guest &&
2152 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2153 // We are in asynchronous add new contents path, delay opening url
2154 new_contents->delayed_open_url_params_.reset(
2155 new OpenURLParams(open_params));
2156 } else {
2157 new_contents->OpenURL(open_params);
2158 }
[email protected]eda238a12012-09-07 23:44:002159 }
[email protected]bafe6cd2012-05-23 23:09:502160 }
2161}
2162
avib7348942015-12-25 20:57:102163void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2164 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462165 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052166 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502167}
2168
avib7348942015-12-25 20:57:102169void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2170 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052171 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502172}
2173
avib7348942015-12-25 20:57:102174void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2175 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502176 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462177 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252178 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232179 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512180 // this WebContentsImpl instance. If any other process sends the request,
2181 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382182 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252183 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512184 if (process_handle != base::kNullProcessHandle) {
2185 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392186 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252187 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512188 }
2189 return;
2190 }
2191
[email protected]bafe6cd2012-05-23 23:09:502192 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052193 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262194
[email protected]cfd80b02014-05-01 17:46:482195 RenderWidgetHostViewBase* widget_view =
2196 static_cast<RenderWidgetHostViewBase*>(
2197 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192198 if (!widget_view)
2199 return;
[email protected]bafe6cd2012-05-23 23:09:502200 if (!is_fullscreen) {
2201 // Popups should not get activated.
2202 widget_view->SetPopupType(popup_type);
2203 }
2204 // Save the created widget associated with the route so we can show it later.
alexmosc2a8cec2016-05-23 22:19:532205 pending_widget_views_[std::make_pair(render_process_id, route_id)] =
2206 widget_view;
[email protected]bafe6cd2012-05-23 23:09:502207
2208#if defined(OS_MACOSX)
2209 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2210 // to allow it to survive the trip without being hosted.
2211 base::mac::NSObjectRetain(widget_view->GetNativeView());
2212#endif
2213}
2214
alexmosc2a8cec2016-05-23 22:19:532215void WebContentsImpl::ShowCreatedWindow(int process_id,
2216 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502217 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392218 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502219 bool user_gesture) {
alexmosc2a8cec2016-05-23 22:19:532220 WebContentsImpl* contents = GetCreatedWindow(process_id, route_id);
[email protected]eda238a12012-09-07 23:44:002221 if (contents) {
2222 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162223 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382224 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2225 contents->ResumeLoadingCreatedWebContents();
2226
[email protected]eda238a12012-09-07 23:44:002227 if (delegate) {
2228 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392229 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002230 }
2231 }
[email protected]bafe6cd2012-05-23 23:09:502232}
2233
alexmosc2a8cec2016-05-23 22:19:532234void WebContentsImpl::ShowCreatedWidget(int process_id,
2235 int route_id,
bokan107a47f2015-02-03 23:23:392236 const gfx::Rect& initial_rect) {
alexmosc2a8cec2016-05-23 22:19:532237 ShowCreatedWidget(process_id, route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502238}
2239
alexmosc2a8cec2016-05-23 22:19:532240void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
2241 int route_id) {
2242 ShowCreatedWidget(process_id, route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:502243}
2244
alexmosc2a8cec2016-05-23 22:19:532245void WebContentsImpl::ShowCreatedWidget(int process_id,
2246 int route_id,
[email protected]bafe6cd2012-05-23 23:09:502247 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392248 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482249 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:532250 static_cast<RenderWidgetHostViewBase*>(
2251 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502252 if (!widget_host_view)
2253 return;
[email protected]cfd80b02014-05-01 17:46:482254
2255 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332256 if (GetOuterWebContents()) {
2257 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482258 } else {
2259 view = GetRenderWidgetHostView();
2260 }
2261
[email protected]4aebbca2013-09-17 22:26:492262 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312263 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032264 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:372265 fullscreen_widget_process_id_ =
2266 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:312267 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492268 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2269 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532270 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492271 } else {
[email protected]cfd80b02014-05-01 17:46:482272 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492273 }
[email protected]4aebbca2013-09-17 22:26:492274 FOR_EACH_OBSERVER(WebContentsObserver,
2275 observers_,
alexmos899e06f2016-05-13 23:08:092276 DidShowFullscreenWidget());
[email protected]4aebbca2013-09-17 22:26:492277 if (!widget_host_view->HasFocus())
2278 widget_host_view->Focus();
2279 } else {
bokan107a47f2015-02-03 23:23:392280 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492281 }
[email protected]89054502012-06-03 10:29:242282
2283 RenderWidgetHostImpl* render_widget_host_impl =
2284 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2285 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312286 // Only allow privileged mouse lock for fullscreen render widget, which is
2287 // used to implement Pepper Flash fullscreen.
2288 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502289
2290#if defined(OS_MACOSX)
2291 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2292 // properly embedded (or purposefully ignored) we can release the retain we
2293 // took in CreateNewWidget().
2294 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2295#endif
2296}
2297
alexmosc2a8cec2016-05-23 22:19:532298WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id,
2299 int route_id) {
2300 auto iter = pending_contents_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502301
2302 // Certain systems can block the creation of new windows. If we didn't succeed
2303 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:532304 if (iter == pending_contents_.end())
2305 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502306
2307 WebContentsImpl* new_contents = iter->second;
alexmosc2a8cec2016-05-23 22:19:532308 pending_contents_.erase(std::make_pair(process_id, route_id));
[email protected]7fff43e2013-05-21 20:21:102309 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502310
[email protected]d70bea92013-04-05 04:23:342311 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252312 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342313 return new_contents;
2314
[email protected]bafe6cd2012-05-23 23:09:502315 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432316 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
alexmosc2a8cec2016-05-23 22:19:532317 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502318
[email protected]bafe6cd2012-05-23 23:09:502319 return new_contents;
2320}
2321
alexmosc2a8cec2016-05-23 22:19:532322RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
2323 int route_id) {
2324 auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502325 if (iter == pending_widget_views_.end()) {
2326 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:532327 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502328 }
2329
2330 RenderWidgetHostView* widget_host_view = iter->second;
alexmosc2a8cec2016-05-23 22:19:532331 pending_widget_views_.erase(std::make_pair(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:502332
2333 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2334 if (!widget_host->GetProcess()->HasConnection()) {
2335 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:532336 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:502337 }
2338
2339 return widget_host_view;
2340}
2341
[email protected]f13b4202012-06-12 23:53:232342void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092343 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212344 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372345 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232346 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372347 } else {
dcheng59716272016-04-09 05:19:082348 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2349 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372350 }
[email protected]f13b4202012-06-12 23:53:232351}
2352
grunell657d4d82014-09-18 00:09:432353bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2354 MediaStreamType type) {
2355 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2356 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2357 return delegate_ &&
2358 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2359}
2360
[email protected]cc9200432013-07-23 23:02:402361SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2362 SiteInstance* instance) {
2363 return controller_.GetSessionStorageNamespace(instance);
2364}
2365
[email protected]6de7fc482014-06-06 10:46:442366SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2367 return controller_.GetSessionStorageNamespaceMap();
2368}
2369
[email protected]9b159a52013-10-03 17:24:552370FrameTree* WebContentsImpl::GetFrameTree() {
2371 return &frame_tree_;
2372}
2373
lukendc35e7f2014-11-10 19:06:142374void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2375 virtual_keyboard_requested_ = requested;
2376}
2377
2378bool WebContentsImpl::IsVirtualKeyboardRequested() {
2379 return virtual_keyboard_requested_;
2380}
2381
aelias5252baa2016-04-10 01:18:022382bool WebContentsImpl::IsOverridingUserAgent() {
2383 return GetController().GetVisibleEntry() &&
2384 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2385}
2386
[email protected]95640212014-07-26 18:14:302387AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2388 return accessibility_mode_;
2389}
2390
[email protected]31a71eaf2014-03-13 01:47:362391void WebContentsImpl::AccessibilityEventReceived(
2392 const std::vector<AXEventNotificationDetails>& details) {
2393 FOR_EACH_OBSERVER(
2394 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2395}
2396
dmazzoni2400c462016-08-23 15:07:132397void WebContentsImpl::AccessibilityLocationChangesReceived(
2398 const std::vector<AXLocationChangeNotificationDetails>& details) {
2399 FOR_EACH_OBSERVER(WebContentsObserver,
2400 observers_,
2401 AccessibilityLocationChangesReceived(details));
2402}
2403
dmazzonia656928e2014-09-15 20:28:542404RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402405 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542406 int browser_plugin_instance_id) {
2407 BrowserPluginGuestManager* guest_manager =
2408 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202409 if (!guest_manager)
2410 return nullptr;
2411
dmazzonia656928e2014-09-15 20:28:542412 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442413 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542414 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202415 return nullptr;
2416
dmazzonia656928e2014-09-15 20:28:542417 return guest->GetMainFrame();
2418}
2419
mcasas4e216e72016-07-28 21:28:382420device::GeolocationServiceContext*
2421WebContentsImpl::GetGeolocationServiceContext() {
blundellc57b93f2014-10-29 13:19:572422 return geolocation_service_context_.get();
2423}
2424
alogvinovf50445a2015-10-30 13:00:122425WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2426 return wake_lock_service_context_.get();
2427}
2428
[email protected]edc3af82013-12-12 21:24:072429void WebContentsImpl::OnShowValidationMessage(
2430 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292431 const base::string16& main_text,
2432 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072433 if (delegate_)
2434 delegate_->ShowValidationMessage(
2435 this, anchor_in_root_view, main_text, sub_text);
2436}
2437
2438void WebContentsImpl::OnHideValidationMessage() {
2439 if (delegate_)
2440 delegate_->HideValidationMessage(this);
2441}
2442
2443void WebContentsImpl::OnMoveValidationMessage(
2444 const gfx::Rect& anchor_in_root_view) {
2445 if (delegate_)
2446 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2447}
2448
lfgbb9c28a2016-03-01 03:19:492449void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372450 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:402451 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:372452 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2453 }
lfgbb9c28a2016-03-01 03:19:492454
lfgdb5c4ed2016-03-04 23:09:072455 RenderWidgetHostViewBase* rwhv =
2456 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2457 if (rwhv) {
2458 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2459 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2460 }
2461
[email protected]32deec62013-05-15 23:55:042462 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442463 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042464}
2465
khushalsagarf3b62b62016-05-26 21:54:232466void WebContentsImpl::OnFirstPaintAfterLoad(
2467 RenderWidgetHostImpl* render_widget_host) {
2468 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2469 DidFirstPaintAfterLoad(render_widget_host));
2470}
2471
ekaramadadd882292016-06-08 15:22:562472TextInputManager* WebContentsImpl::GetTextInputManager() {
2473 if (GetOuterWebContents())
2474 return GetOuterWebContents()->GetTextInputManager();
2475
2476 if (!text_input_manager_)
2477 text_input_manager_.reset(new TextInputManager());
2478
2479 return text_input_manager_.get();
2480}
2481
[email protected]95640212014-07-26 18:14:302482BrowserAccessibilityManager*
2483 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452484 RenderFrameHostImpl* rfh = GetMainFrame();
2485 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302486}
2487
2488BrowserAccessibilityManager*
2489 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452490 RenderFrameHostImpl* rfh = GetMainFrame();
2491 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302492}
2493
mohsen7ab1ec16ec2015-07-02 18:26:232494void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2495 RenderFrameHost* focused_frame = GetFocusedFrame();
2496 if (!focused_frame)
2497 return;
2498
2499 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2500 focused_frame->GetRoutingID(), extent));
2501}
2502
2503void WebContentsImpl::SelectRange(const gfx::Point& base,
2504 const gfx::Point& extent) {
2505 RenderFrameHost* focused_frame = GetFocusedFrame();
2506 if (!focused_frame)
2507 return;
2508
2509 focused_frame->Send(
2510 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2511}
2512
aurimasab0319022015-07-10 21:57:382513void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2514 int end_adjust) {
2515 RenderFrameHost* focused_frame = GetFocusedFrame();
2516 if (!focused_frame)
2517 return;
2518
2519 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2520 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2521}
2522
[email protected]b172aee2012-04-10 17:05:262523void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492524 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232525 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492526 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332527}
2528
avic3aa8422015-11-09 20:57:222529void WebContentsImpl::ResizeDueToAutoResize(
2530 RenderWidgetHostImpl* render_widget_host,
2531 const gfx::Size& new_size) {
2532 if (render_widget_host != GetRenderViewHost()->GetWidget())
2533 return;
2534
[email protected]61e2b3cc2012-03-02 16:13:342535 if (delegate_)
2536 delegate_->ResizeDueToAutoResize(this, new_size);
2537}
2538
estarkcd2e30c2016-08-12 06:51:152539bool WebContentsImpl::DisplayedInsecureContent() const {
2540 return displayed_insecure_content_;
2541}
2542
2543bool WebContentsImpl::DisplayedContentWithCertErrors() const {
2544 return displayed_content_with_cert_errors_;
2545}
2546
[email protected]b172aee2012-04-10 17:05:262547WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202548 if (!delegate_)
2549 return NULL;
[email protected]00c37fc2011-08-02 00:22:502550
[email protected]e5d549d2011-12-28 01:29:202551 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202552 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342553}
2554
[email protected]6b618e62012-08-16 12:59:182555bool WebContentsImpl::Send(IPC::Message* message) {
2556 if (!GetRenderViewHost()) {
2557 delete message;
2558 return false;
2559 }
2560
2561 return GetRenderViewHost()->Send(message);
2562}
2563
[email protected]a86c0e962013-12-17 17:10:392564void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2565 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442566 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392567 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442568}
2569
[email protected]20ca0382013-02-28 19:50:072570void WebContentsImpl::AttachInterstitialPage(
2571 InterstitialPageImpl* interstitial_page) {
2572 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212573 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292574
2575 // Cancel any visible dialogs so that they don't interfere with the
2576 // interstitial.
creis89a0f782015-05-27 16:13:172577 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292578
[email protected]20ca0382013-02-28 19:50:072579 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2580 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252581
2582 // Stop the throbber if needed while the interstitial page is shown.
2583 if (frame_tree_.IsLoading())
2584 LoadingStateChanged(true, true, nullptr);
2585}
2586
2587void WebContentsImpl::DidProceedOnInterstitial() {
2588 // The interstitial page should no longer be pausing the throbber.
2589 DCHECK(!(ShowingInterstitialPage() &&
2590 GetRenderManager()->interstitial_page()->pause_throbber()));
2591
2592 // Restart the throbber now that the interstitial page no longer pauses it.
2593 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2594 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072595}
2596
2597void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252598 bool interstitial_pausing_throbber =
2599 ShowingInterstitialPage() &&
2600 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572601 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212602 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072603 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2604 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252605
2606 // Restart the throbber if needed now that the interstitial page is going
2607 // away.
2608 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2609 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072610}
2611
avi2b177592014-12-10 02:08:022612void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2613 int history_length) {
alexmos136fd6e62016-08-15 20:58:412614 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
2615 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:022616}
2617
2618void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2619 RenderViewHost* render_view_host,
2620 int history_offset,
2621 int history_length) {
alexmos136fd6e62016-08-15 20:58:412622 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:022623 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142624}
2625
toyoshim24a4c7ab2016-04-05 09:24:142626void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172627 RenderFrameHost* focused_frame = GetFocusedFrame();
2628 if (!focused_frame)
2629 return;
2630
[email protected]959be4c2014-04-08 15:01:332631 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142632 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332633}
2634
megjablon3f5941072016-02-04 23:27:522635void WebContentsImpl::ReloadLoFiImages() {
2636 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2637}
2638
[email protected]959be4c2014-04-08 15:01:332639void WebContentsImpl::Undo() {
2640 RenderFrameHost* focused_frame = GetFocusedFrame();
2641 if (!focused_frame)
2642 return;
2643
2644 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2645 RecordAction(base::UserMetricsAction("Undo"));
2646}
2647
2648void WebContentsImpl::Redo() {
2649 RenderFrameHost* focused_frame = GetFocusedFrame();
2650 if (!focused_frame)
2651 return;
2652 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2653 RecordAction(base::UserMetricsAction("Redo"));
2654}
2655
2656void WebContentsImpl::Cut() {
2657 RenderFrameHost* focused_frame = GetFocusedFrame();
2658 if (!focused_frame)
2659 return;
2660
2661 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2662 RecordAction(base::UserMetricsAction("Cut"));
2663}
2664
2665void WebContentsImpl::Copy() {
2666 RenderFrameHost* focused_frame = GetFocusedFrame();
2667 if (!focused_frame)
2668 return;
2669
2670 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2671 RecordAction(base::UserMetricsAction("Copy"));
2672}
2673
2674void WebContentsImpl::CopyToFindPboard() {
2675#if defined(OS_MACOSX)
2676 RenderFrameHost* focused_frame = GetFocusedFrame();
2677 if (!focused_frame)
2678 return;
2679
2680 // Windows/Linux don't have the concept of a find pasteboard.
2681 focused_frame->Send(
2682 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2683 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2684#endif
2685}
2686
2687void WebContentsImpl::Paste() {
2688 RenderFrameHost* focused_frame = GetFocusedFrame();
2689 if (!focused_frame)
2690 return;
2691
2692 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2693 RecordAction(base::UserMetricsAction("Paste"));
2694}
2695
2696void WebContentsImpl::PasteAndMatchStyle() {
2697 RenderFrameHost* focused_frame = GetFocusedFrame();
2698 if (!focused_frame)
2699 return;
2700
2701 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2702 focused_frame->GetRoutingID()));
2703 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2704}
2705
2706void WebContentsImpl::Delete() {
2707 RenderFrameHost* focused_frame = GetFocusedFrame();
2708 if (!focused_frame)
2709 return;
2710
2711 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2712 RecordAction(base::UserMetricsAction("DeleteSelection"));
2713}
2714
2715void WebContentsImpl::SelectAll() {
2716 RenderFrameHost* focused_frame = GetFocusedFrame();
2717 if (!focused_frame)
2718 return;
2719
2720 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2721 RecordAction(base::UserMetricsAction("SelectAll"));
2722}
2723
2724void WebContentsImpl::Unselect() {
2725 RenderFrameHost* focused_frame = GetFocusedFrame();
2726 if (!focused_frame)
2727 return;
2728
2729 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2730 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172731}
2732
2733void WebContentsImpl::Replace(const base::string16& word) {
2734 RenderFrameHost* focused_frame = GetFocusedFrame();
2735 if (!focused_frame)
2736 return;
2737
[email protected]959be4c2014-04-08 15:01:332738 focused_frame->Send(new InputMsg_Replace(
2739 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172740}
2741
2742void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2743 RenderFrameHost* focused_frame = GetFocusedFrame();
2744 if (!focused_frame)
2745 return;
2746
[email protected]959be4c2014-04-08 15:01:332747 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2748 focused_frame->GetRoutingID(), word));
2749}
2750
2751void WebContentsImpl::NotifyContextMenuClosed(
2752 const CustomContextMenuContext& context) {
2753 RenderFrameHost* focused_frame = GetFocusedFrame();
2754 if (!focused_frame)
2755 return;
2756
2757 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2758 focused_frame->GetRoutingID(), context));
2759}
2760
2761void WebContentsImpl::ExecuteCustomContextMenuCommand(
2762 int action, const CustomContextMenuContext& context) {
2763 RenderFrameHost* focused_frame = GetFocusedFrame();
2764 if (!focused_frame)
2765 return;
2766
2767 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2768 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002769}
2770
[email protected]fc2b46b2014-05-03 16:33:452771gfx::NativeView WebContentsImpl::GetNativeView() {
2772 return view_->GetNativeView();
2773}
2774
2775gfx::NativeView WebContentsImpl::GetContentNativeView() {
2776 return view_->GetContentNativeView();
2777}
2778
2779gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2780 return view_->GetTopLevelNativeWindow();
2781}
2782
2783gfx::Rect WebContentsImpl::GetViewBounds() {
2784 return view_->GetViewBounds();
2785}
2786
2787gfx::Rect WebContentsImpl::GetContainerBounds() {
2788 gfx::Rect rv;
2789 view_->GetContainerBounds(&rv);
2790 return rv;
2791}
2792
2793DropData* WebContentsImpl::GetDropData() {
2794 return view_->GetDropData();
2795}
2796
2797void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042798 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452799}
2800
2801void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042802 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452803}
2804
2805void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042806 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452807}
2808
2809void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042810 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452811}
2812
[email protected]b172aee2012-04-10 17:05:262813void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272814 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212815 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542816 return;
2817 }
[email protected]0b431992014-06-24 00:08:032818 RenderWidgetHostView* const fullscreen_view =
2819 GetFullscreenRenderWidgetHostView();
2820 if (fullscreen_view) {
2821 fullscreen_view->Focus();
2822 return;
2823 }
creisc014b402015-04-23 16:41:452824 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542825}
2826
[email protected]b172aee2012-04-10 17:05:262827bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212828 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542829}
2830
[email protected]b172aee2012-04-10 17:05:262831InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212832 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222833}
2834
[email protected]b172aee2012-04-10 17:05:262835bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162836 // WebKit creates Document object when MIME type is application/xhtml+xml,
2837 // so we also support this MIME type.
2838 return contents_mime_type_ == "text/html" ||
2839 contents_mime_type_ == "text/xml" ||
2840 contents_mime_type_ == "application/xhtml+xml" ||
2841 contents_mime_type_ == "text/plain" ||
2842 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252843 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162844}
2845
[email protected]b172aee2012-04-10 17:05:262846void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592847 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162848 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552849 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192850 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142851 return;
[email protected]c7dd2f62011-07-18 15:57:592852 }
2853
2854 Stop();
2855
2856 // Create the save package and possibly prompt the user for the name to save
2857 // the page as. The user prompt is an asynchronous operation that runs on
2858 // another thread.
2859 save_package_ = new SavePackage(this);
2860 save_package_->GetSaveInfo();
2861}
2862
2863// Used in automated testing to bypass prompting the user for file names.
2864// Instead, the names and paths are hard coded rather than running them through
2865// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342866bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2867 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212868 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592869 // Stop the page from navigating.
2870 Stop();
2871
2872 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212873 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592874}
2875
[email protected]3c71576ce2013-07-23 02:00:012876void WebContentsImpl::SaveFrame(const GURL& url,
2877 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372878 SaveFrameWithHeaders(url, referrer, std::string());
2879}
2880
2881void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2882 const Referrer& referrer,
2883 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192884 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012885 return;
sammc92af61552014-11-19 23:27:402886 if (delegate_ && delegate_->SaveFrame(url, referrer))
2887 return;
2888
nasko89ad7742015-03-05 22:14:192889 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:222890 // by explicitly passing in which frame this method should target. This would
2891 // indicate whether it's the main frame, and also tell us the frame pointer
2892 // to use for routing.
nasko89ad7742015-03-05 22:14:192893 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:222894 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:012895
brettw760f7442016-05-23 21:19:222896 StoragePartition* storage_partition = BrowserContext::GetStoragePartition(
2897 GetBrowserContext(), frame_host->GetSiteInstance());
[email protected]3c71576ce2013-07-23 02:00:012898 DownloadManager* dlm =
2899 BrowserContext::GetDownloadManager(GetBrowserContext());
2900 if (!dlm)
2901 return;
avib7348942015-12-25 20:57:102902 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012903 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272904 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012905 if (entry)
2906 post_id = entry->GetPostID();
2907 }
brettw760f7442016-05-23 21:19:222908 std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters(
2909 url, frame_host->GetProcess()->GetID(),
2910 frame_host->GetRenderViewHost()->GetRoutingID(),
2911 frame_host->GetRoutingID(), storage_partition->GetURLRequestContext()));
[email protected]3c71576ce2013-07-23 02:00:012912 params->set_referrer(referrer);
2913 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012914 if (post_id >= 0)
2915 params->set_method("POST");
2916 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372917
2918 if (headers.empty()) {
2919 params->set_prefer_cache(true);
2920 } else {
brettw26dab8f02015-08-08 00:28:472921 for (const base::StringPiece& key_value :
2922 base::SplitStringPiece(
2923 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2924 std::vector<std::string> pair = base::SplitString(
2925 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372926 DCHECK_EQ(2ul, pair.size());
2927 params->add_request_header(pair[0], pair[1]);
2928 }
2929 }
dcheng36b6aec92015-12-26 06:16:362930 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012931}
2932
[email protected]b172aee2012-04-10 17:05:262933void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:472934 const MHTMLGenerationParams& params,
avib7348942015-12-25 20:57:102935 const base::Callback<void(int64_t)>& callback) {
dewittj6dc5747a2016-05-17 01:48:472936 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback);
[email protected]aa4f3972012-03-01 18:12:122937}
2938
[email protected]b172aee2012-04-10 17:05:262939const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272940 return contents_mime_type_;
2941}
2942
[email protected]b172aee2012-04-10 17:05:262943bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272944 return notify_disconnection_;
2945}
2946
[email protected]8ff00d72012-10-23 19:12:212947RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272948 return &renderer_preferences_;
2949}
2950
[email protected]e35ccd52012-05-23 16:22:472951void WebContentsImpl::Close() {
2952 Close(GetRenderViewHost());
2953}
2954
[email protected]cf200a562013-05-03 16:24:292955void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462956 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292957 if (browser_plugin_embedder_.get())
2958 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2959 screen_x, screen_y, operation);
2960 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452961 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2962 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292963}
2964
jam73f892642016-09-11 06:04:062965void WebContentsImpl::LoadStateChanged(
2966 const GURL& url,
2967 const net::LoadStateWithParam& load_state,
2968 uint64_t upload_position,
2969 uint64_t upload_size) {
2970 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
2971 // is fixed.
2972 tracked_objects::ScopedTracker tracking_profile1(
2973 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2974 "466285 WebContentsImpl::LoadStateChanged::Start"));
2975 load_state_ = load_state;
2976 upload_position_ = upload_position;
2977 upload_size_ = upload_size;
2978 load_state_host_ = url_formatter::IDNToUnicode(url.host());
2979 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
2980 SetNotWaitingForResponse();
2981 if (IsLoading()) {
2982 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
2983 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
2984 }
2985}
2986
[email protected]d60f3702013-12-26 16:30:242987void WebContentsImpl::DidGetResourceResponseStart(
2988 const ResourceRequestDetails& details) {
2989 controller_.ssl_manager()->DidStartResourceResponse(details);
2990
2991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2992 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242993}
2994
2995void WebContentsImpl::DidGetRedirectForResourceRequest(
[email protected]d60f3702013-12-26 16:30:242996 const ResourceRedirectDetails& details) {
2997 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2998
2999 FOR_EACH_OBSERVER(
3000 WebContentsObserver,
3001 observers_,
jam73f892642016-09-11 06:04:063002 DidGetRedirectForResourceRequest(details));
[email protected]d60f3702013-12-26 16:30:243003
3004 // TODO(avi): Remove. http://crbug.com/170921
3005 NotificationService::current()->Notify(
3006 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
3007 Source<WebContents>(this),
3008 Details<const ResourceRedirectDetails>(&details));
3009}
3010
calamity7fe55ce2015-04-10 03:59:373011void WebContentsImpl::NotifyWebContentsFocused() {
3012 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:523016 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:453017 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:293018 if (browser_plugin_embedder_.get())
3019 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:343020}
3021
[email protected]e35ccd52012-05-23 16:22:473022void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:533023 OnUserInteraction(GetRenderViewHost()->GetWidget(),
3024 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:473025}
3026
[email protected]b172aee2012-04-10 17:05:263027void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:273028 closed_by_user_gesture_ = value;
3029}
3030
[email protected]b172aee2012-04-10 17:05:263031bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:273032 return closed_by_user_gesture_;
3033}
3034
[email protected]b172aee2012-04-10 17:05:263035void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:503036 if (!delegate_)
3037 return;
3038
[email protected]6286a372013-10-09 04:03:273039 NavigationEntry* entry = GetController().GetLastCommittedEntry();
3040 if (!entry)
[email protected]1788e772010-12-15 16:40:503041 return;
3042
[email protected]6286a372013-10-09 04:03:273043 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:123044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:043047 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:273048 if (!delegate_)
3049 return;
3050
[email protected]691aa2f2013-05-28 22:52:043051 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:273052}
3053
[email protected]b172aee2012-04-10 17:05:263054int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273055 return minimum_zoom_percent_;
3056}
3057
[email protected]b172aee2012-04-10 17:05:263058int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:273059 return maximum_zoom_percent_;
3060}
3061
mcnee432e47d2015-11-09 19:37:463062void WebContentsImpl::SetPageScale(float page_scale_factor) {
3063 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:243064}
3065
[email protected]b172aee2012-04-10 17:05:263066gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:493067 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:233068}
3069
[email protected]b172aee2012-04-10 17:05:263070bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:053071 if (GetBrowserPluginGuest())
3072 return GetBrowserPluginGuest()->LockMouse(allowed);
3073
lfgad8244352016-07-13 16:55:513074 if (mouse_lock_widget_ &&
3075 mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
3076 return true;
3077
3078 mouse_lock_widget_ = nullptr;
lfgbee1e0a2016-06-08 21:24:213079 return false;
[email protected]0bfbf882011-12-22 18:19:273080}
3081
[email protected]b172aee2012-04-10 17:05:263082bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:213083 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:503084}
3085
alexmose201c7cd2015-06-10 17:14:213086WebContentsImpl* WebContentsImpl::GetOpener() const {
3087 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
3088 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:573089}
3090
[email protected]cb805452013-05-22 15:16:213091void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:483092 if (!color_chooser_info_.get())
3093 return;
3094 RenderFrameHost* rfh = RenderFrameHost::FromID(
3095 color_chooser_info_->render_process_id,
3096 color_chooser_info_->render_frame_id);
3097 if (!rfh)
3098 return;
3099
3100 rfh->Send(new FrameMsg_DidChooseColorResponse(
3101 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:203102}
3103
[email protected]cb805452013-05-22 15:16:213104void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:483105 if (!color_chooser_info_.get())
3106 return;
3107 RenderFrameHost* rfh = RenderFrameHost::FromID(
3108 color_chooser_info_->render_process_id,
3109 color_chooser_info_->render_frame_id);
3110 if (!rfh)
3111 return;
3112
3113 rfh->Send(new FrameMsg_DidEndColorChooser(
3114 rfh->GetRoutingID(), color_chooser_info_->identifier));
3115 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:203116}
3117
halton.huoca2eabd2015-07-06 08:17:403118int WebContentsImpl::DownloadImage(
3119 const GURL& url,
3120 bool is_favicon,
3121 uint32_t max_bitmap_size,
3122 bool bypass_cache,
3123 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:553124 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:403125 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:063126 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:403127 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:553128 const int download_id = ++next_image_download_id;
3129 if (!mojo_image_downloader) {
3130 // If the renderer process is dead (i.e. crash, or memory pressure on
3131 // Android), the downloader service will be invalid. Pre-Mojo, this would
3132 // hang the callback indefinetly since the IPC would be dropped. Now,
3133 // respond with a 400 HTTP error code to indicate that something went wrong.
3134 BrowserThread::PostTask(
3135 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:193136 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:523137 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
leon.hanc2228532016-08-16 05:59:183138 std::vector<SkBitmap>(), std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:553139 return download_id;
3140 }
3141
halton.huoca2eabd2015-07-06 08:17:403142 mojo_image_downloader->DownloadImage(
sammcf6f4fcf2016-06-21 05:39:393143 url, is_favicon, max_bitmap_size, bypass_cache,
leon.hancbc4bc3c2016-02-26 07:08:523144 base::Bind(&WebContentsImpl::OnDidDownloadImage,
3145 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:553146 return download_id;
[email protected]795c28972012-12-06 06:13:393147}
3148
[email protected]5dcaf8e2013-12-28 01:31:423149bool WebContentsImpl::IsSubframe() const {
3150 return is_subframe_;
3151}
3152
[email protected]36ec24f2014-01-09 00:32:083153void WebContentsImpl::Find(int request_id,
3154 const base::string16& search_text,
3155 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333156 // Cowardly refuse to search for no text.
3157 if (search_text.empty()) {
3158 NOTREACHED();
3159 return;
3160 }
3161
raymes0fa0be52014-10-13 20:38:093162 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173163 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473164 if (browser_plugin_embedder_ &&
3165 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3166 return;
raymes0fa0be52014-10-13 20:38:093167 }
paulmeyerc0b762b2016-04-13 11:55:173168
3169 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083170}
3171
3172void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013173 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173174 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473175 if (browser_plugin_embedder_ &&
3176 browser_plugin_embedder_->StopFinding(action)) {
3177 return;
raymes2bc64182015-02-06 01:23:013178 }
paulmeyerc0b762b2016-04-13 11:55:173179
3180 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083181}
3182
dalecurtisbc6572e12014-09-12 19:22:303183bool WebContentsImpl::WasRecentlyAudible() {
wjmaclean1dabf3e32016-05-13 23:34:443184 return audio_stream_monitor_.WasRecentlyAudible() ||
3185 (browser_plugin_embedder_ &&
3186 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:303187}
3188
mlamouriefdca9d2014-09-16 16:55:403189void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3190 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3191}
3192
bokanece34a82016-01-28 19:49:463193void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533194 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433195 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463196 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533197}
3198
mariakhomenko44bdc4732015-04-29 01:55:383199void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373200 if (delayed_open_url_params_.get()) {
3201 OpenURL(*delayed_open_url_params_.get());
3202 delayed_open_url_params_.reset(nullptr);
3203 return;
3204 }
3205
mariakhomenko44bdc4732015-04-29 01:55:383206 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3207 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163208 if (is_resume_pending_) {
3209 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133210 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163211 GetMainFrame()->Init();
3212 }
mariakhomenko44bdc4732015-04-29 01:55:383213}
3214
[email protected]b172aee2012-04-10 17:05:263215bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263216 // When the browser is started with about:blank as the startup URL, focus
3217 // the location bar (which will also select its contents) so people can
3218 // simply begin typing to navigate elsewhere.
3219 //
3220 // We need to be careful not to trigger this for anything other than the
3221 // startup navigation. In particular, if we allow an attacker to open a
3222 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3223 // end of the new URL to be scrolled into view instead of the start,
3224 // allowing the attacker to spoof other URLs. The conditions checked here
3225 // are all aimed at ensuring no such attacker-controlled navigation can
3226 // trigger this.
3227 //
3228 // Note that we check the pending entry instead of the visible one; for the
3229 // startup URL case these are the same, but for the attacker-controlled
3230 // navigation case the visible entry is the committed "about:blank" URL and
3231 // the pending entry is the problematic navigation elsewhere.
3232 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3233 if (controller_.IsInitialNavigation() && entry &&
3234 !entry->is_renderer_initiated() &&
3235 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333236 return true;
palmerc70cb1f2016-03-04 23:41:263237 }
[email protected]0c9406632013-02-08 01:13:333238 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273239}
3240
[email protected]b172aee2012-04-10 17:05:263241void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273242 if (delegate_)
3243 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213244}
3245
clamy0e119882015-07-31 16:12:333246void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3247 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3248 DidStartNavigation(navigation_handle));
3249}
3250
3251void WebContentsImpl::DidRedirectNavigation(
3252 NavigationHandle* navigation_handle) {
3253 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3254 DidRedirectNavigation(navigation_handle));
3255}
3256
clamyefca29e2015-09-17 00:22:113257void WebContentsImpl::ReadyToCommitNavigation(
3258 NavigationHandle* navigation_handle) {
3259 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3260 ReadyToCommitNavigation(navigation_handle));
3261}
3262
clamy0e119882015-07-31 16:12:333263void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3264 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3265 DidFinishNavigation(navigation_handle));
3266}
3267
[email protected]52913802013-12-10 05:52:183268void WebContentsImpl::DidStartProvisionalLoad(
3269 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183270 const GURL& validated_url,
3271 bool is_error_page,
3272 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103273 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483274 FOR_EACH_OBSERVER(
3275 WebContentsObserver,
3276 observers_,
3277 DidStartProvisionalLoadForFrame(
3278 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083279
3280 // Notify accessibility if this is a reload.
3281 NavigationEntry* entry = controller_.GetVisibleEntry();
3282 if (entry && ui::PageTransitionCoreTypeIs(
3283 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3284 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3285 BrowserAccessibilityManager* manager =
3286 ftn->current_frame_host()->browser_accessibility_manager();
3287 if (manager)
3288 manager->UserIsReloading();
3289 }
[email protected]400992b2012-06-14 00:03:543290}
3291
[email protected]3109fbb72014-01-06 23:57:153292void WebContentsImpl::DidFailProvisionalLoadWithError(
3293 RenderFrameHostImpl* render_frame_host,
lazyboy552a9382016-07-14 20:38:373294 const GURL& validated_url,
3295 int error_code,
3296 const base::string16& error_description,
3297 bool was_ignored_by_handler) {
3298 FOR_EACH_OBSERVER(
3299 WebContentsObserver, observers_,
3300 DidFailProvisionalLoad(render_frame_host, validated_url, error_code,
3301 error_description, was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083302
3303 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3304 BrowserAccessibilityManager* manager =
3305 ftn->current_frame_host()->browser_accessibility_manager();
3306 if (manager)
3307 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153308}
3309
[email protected]b80624c2014-02-09 02:46:553310void WebContentsImpl::DidFailLoadWithError(
3311 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553312 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553313 int error_code,
gsennton6fbb38692015-06-24 19:23:553314 const base::string16& error_description,
3315 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143316 FOR_EACH_OBSERVER(
3317 WebContentsObserver,
3318 observers_,
gsennton6fbb38692015-06-24 19:23:553319 DidFailLoad(render_frame_host, url, error_code, error_description,
3320 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553321}
3322
[email protected]52913802013-12-10 05:52:183323void WebContentsImpl::NotifyChangedNavigationState(
3324 InvalidateTypes changed_flags) {
3325 NotifyNavigationStateChanged(changed_flags);
3326}
3327
toyoshim0df1d3a2016-09-09 09:52:483328void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
3329 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:203330 // Notify observers about navigation.
3331 FOR_EACH_OBSERVER(
3332 WebContentsObserver,
3333 observers_,
3334 DidStartNavigationToPendingEntry(url, reload_type));
3335}
3336
[email protected]8cb834e2014-03-06 14:23:233337void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3338 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503339 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3340 // weak pointer of sorts.
3341 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3342 const int32_t frame_id = render_frame_host->GetRoutingID();
3343
[email protected]65920f332014-03-04 21:14:183344 WebContents* new_contents = OpenURL(params);
3345
dchengb907f7332015-01-07 20:35:503346 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183347 // Notify observers.
3348 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3349 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463350 render_frame_host,
[email protected]65920f332014-03-04 21:14:183351 params.url,
3352 params.referrer,
3353 params.disposition,
creis114ca1b2014-11-13 23:51:463354 params.transition));
[email protected]65920f332014-03-04 21:14:183355 }
3356}
3357
lukasza1d025732016-09-28 21:36:083358bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:223359 if (!delegate_)
3360 return true;
lukasza1d025732016-09-28 21:36:083361 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:223362}
3363
[email protected]aa62afd2014-04-22 19:22:463364bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3365 if (!delegate_)
3366 return false;
3367 return delegate_->ShouldPreserveAbortedURLs(this);
3368}
3369
[email protected]37567b432014-02-12 01:12:223370void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433371 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223372 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353373 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223374 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483375 FOR_EACH_OBSERVER(WebContentsObserver,
3376 observers_,
3377 DidCommitProvisionalLoadForFrame(
3378 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083379
3380 BrowserAccessibilityManager* manager =
3381 render_frame_host->browser_accessibility_manager();
3382 if (manager)
3383 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223384}
3385
[email protected]0d0f4c492014-04-02 06:42:573386void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233387 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573388 // Ensure fullscreen mode is exited before committing the navigation to a
3389 // different page. The next page will not start out assuming it is in
3390 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233391 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193392 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573393 return;
3394 }
alexmos5dd617d2016-06-07 04:21:153395 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:463396 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:153397 DCHECK(!IsFullscreenForCurrentTab());
[email protected]0d0f4c492014-04-02 06:42:573398}
3399
[email protected]37567b432014-02-12 01:12:223400void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283401 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223402 const LoadCommittedDetails& details,
3403 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3404 if (details.is_navigation_to_different_page()) {
3405 // Clear the status bubble. This is a workaround for a bug where WebKit
3406 // doesn't let us know that the cursor left an element during a
3407 // transition (this is also why the mouse cursor remains as a hand after
3408 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3409 // clear the bubble when a user navigates to a named anchor in the same
3410 // page.
sky8b00392d2015-01-10 00:30:283411 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003412
3413 RenderWidgetHostViewBase* rwhvb =
3414 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3415 if (rwhvb)
3416 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283417
peter90afaba2015-06-01 12:05:293418 did_first_visually_non_empty_paint_ = false;
3419
yusufod41c5f92015-03-06 00:14:283420 // Reset theme color on navigation to new page.
3421 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223422 }
3423
3424 if (!details.is_in_page) {
3425 // Once the main frame is navigated, we're no longer considered to have
3426 // displayed insecure content.
3427 displayed_insecure_content_ = false;
estark73583c02016-08-30 17:52:253428 displayed_content_with_cert_errors_ = false;
[email protected]37567b432014-02-12 01:12:223429 SSLManager::NotifySSLInternalStateChanged(
3430 GetController().GetBrowserContext());
3431 }
3432
3433 // Notify observers about navigation.
3434 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3435 DidNavigateMainFrame(details, params));
3436
[email protected]e85165c642014-06-10 14:34:313437 if (delegate_)
[email protected]37567b432014-02-12 01:12:223438 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313439 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223440}
3441
3442void WebContentsImpl::DidNavigateAnyFramePostCommit(
3443 RenderFrameHostImpl* render_frame_host,
3444 const LoadCommittedDetails& details,
3445 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103446 // Now that something has committed, we don't need to track whether the
3447 // initial page has been accessed.
3448 has_accessed_initial_document_ = false;
3449
[email protected]37567b432014-02-12 01:12:223450 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173451 if (!details.is_in_page)
3452 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223453
avid53461d2016-02-25 17:15:043454 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3455 // again.
3456 if (params.gesture == NavigationGestureUser && dialog_manager_)
3457 dialog_manager_->ResetDialogState(this);
3458
[email protected]37567b432014-02-12 01:12:223459 // Notify observers about navigation.
3460 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093461 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223462}
3463
3464void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3465 contents_mime_type_ = mime_type;
3466}
3467
[email protected]277857a2014-06-03 10:38:013468bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313469 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053470 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313471 return false;
3472
[email protected]37567b432014-02-12 01:12:223473 if (delegate_)
3474 return delegate_->CanOverscrollContent();
3475
3476 return false;
3477}
3478
[email protected]37b64c52014-07-11 21:14:053479void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293480 // Update the theme color. This is to be published to observers after the
3481 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283482 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293483
3484 if (did_first_visually_non_empty_paint_ &&
3485 last_sent_theme_color_ != theme_color_) {
3486 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3487 DidChangeThemeColor(theme_color_));
3488 last_sent_theme_color_ = theme_color_;
3489 }
[email protected]e7104762014-06-20 19:17:253490}
3491
[email protected]b172aee2012-04-10 17:05:263492void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183493 const GURL& url,
[email protected]70435962011-08-02 20:13:283494 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183495 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403496 ResourceType resource_type) {
[email protected]b0f724c2013-09-05 04:21:133497 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
jam91dd24e2016-08-12 17:16:423498 DidLoadResourceFromMemoryCache(url, mime_type,
3499 resource_type));
[email protected]b0f724c2013-09-05 04:21:133500
[email protected]8bfc8272013-09-09 20:10:533501 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3502 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403503 resource_type == RESOURCE_TYPE_MEDIA ?
jam2503f932016-04-15 20:08:303504 GetRenderProcessHost()->GetStoragePartition()->
3505 GetMediaURLRequestContext() :
jam608f2992016-03-31 16:35:343506 GetRenderProcessHost()->GetStoragePartition()->
3507 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533508 BrowserThread::PostTask(
3509 BrowserThread::IO,
3510 FROM_HERE,
3511 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3512 }
[email protected]724159a2010-12-30 01:11:183513}
3514
[email protected]b172aee2012-04-10 17:05:263515void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393516 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183517 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193518 SSLManager::NotifySSLInternalStateChanged(
3519 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183520}
3521
estark910b4572015-12-09 20:55:413522void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3523 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583524 LOG(WARNING) << security_origin << " ran insecure content from "
3525 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393526 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413527 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293528 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393529 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183530 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193531 SSLManager::NotifySSLInternalStateChanged(
3532 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183533}
3534
estark910b4572015-12-09 20:55:413535void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
jama385e112016-07-22 00:07:583536 const GURL& url) {
estarkcd2e30c2016-08-12 06:51:153537 displayed_content_with_cert_errors_ = true;
estark910b4572015-12-09 20:55:413538 SSLManager::NotifySSLInternalStateChanged(
3539 GetController().GetBrowserContext());
3540}
3541
3542void WebContentsImpl::OnDidRunContentWithCertificateErrors(
jama385e112016-07-22 00:07:583543 const GURL& url) {
estarkcd2e30c2016-08-12 06:51:153544 NavigationEntry* entry = controller_.GetVisibleEntry();
3545 if (!entry)
estarkaeda1422016-05-10 02:31:123546 return;
3547
estarkaeda1422016-05-10 02:31:123548 // TODO(estark): check that this does something reasonable for
3549 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:153550 controller_.ssl_manager()->DidRunContentWithCertErrors(
3551 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:413552 SSLManager::NotifySSLInternalStateChanged(
3553 GetController().GetBrowserContext());
3554}
3555
[email protected]501052ff2014-02-21 22:19:073556void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113557 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473558 return;
naskofbd033392015-01-27 02:34:473559
[email protected]1d62cf72014-02-07 21:31:573560 RenderFrameHostImpl* rfh =
3561 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143562 FOR_EACH_OBSERVER(
3563 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183564}
3565
naskofbd033392015-01-27 02:34:473566void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113567 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123568 return;
[email protected]a1b99262013-12-27 21:56:223569
[email protected]8b3af1e2014-01-24 13:29:123570 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443571 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373572 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423573 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373574
[email protected]61ac9e242014-03-21 20:55:263575 RenderFrameHostImpl* rfh =
3576 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143577 FOR_EACH_OBSERVER(
3578 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313579}
3580
[email protected]b172aee2012-04-10 17:05:263581void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573582 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3583 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263584}
3585
[email protected]b172aee2012-04-10 17:05:263586void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303587 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263588 minimum_zoom_percent_ = minimum_percent;
3589 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263590}
3591
mcnee432e47d2015-11-09 19:37:463592void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3593 bool is_one = page_scale_factor == 1.f;
3594 if (is_one != page_scale_factor_is_one_) {
3595 page_scale_factor_is_one_ = is_one;
3596
3597 HostZoomMapImpl* host_zoom_map =
3598 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3599
3600 if (host_zoom_map && GetRenderProcessHost()) {
3601 host_zoom_map->SetPageScaleFactorIsOneForView(
3602 GetRenderProcessHost()->GetID(), GetRoutingID(),
3603 page_scale_factor_is_one_);
3604 }
3605 }
3606
3607 FOR_EACH_OBSERVER(WebContentsObserver,
3608 observers_,
3609 OnPageScaleFactorChanged(page_scale_factor));
3610}
3611
[email protected]b172aee2012-04-10 17:05:263612void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343613 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433614 if (!delegate_)
3615 return;
3616
[email protected]b9535422012-02-09 01:47:593617 ChildProcessSecurityPolicyImpl* policy =
3618 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223619 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593620 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213621}
3622
[email protected]b172aee2012-04-10 17:05:263623void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3624 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263625 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363626 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433627 if (!delegate_)
3628 return;
3629
[email protected]b9535422012-02-09 01:47:593630 ChildProcessSecurityPolicyImpl* policy =
3631 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323632 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593633 return;
[email protected]8f810632013-06-06 22:33:323634
[email protected]c125e532014-05-10 20:39:063635 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203636}
3637
[email protected]f5273e52014-07-14 16:30:203638void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3639 const GURL& url,
3640 bool user_gesture) {
3641 if (!delegate_)
3642 return;
3643
3644 ChildProcessSecurityPolicyImpl* policy =
3645 ChildProcessSecurityPolicyImpl::GetInstance();
3646 if (policy->IsPseudoScheme(protocol))
3647 return;
3648
3649 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3650}
3651
kouhei40f03cb2015-09-24 07:47:013652void WebContentsImpl::OnUpdatePageImportanceSignals(
3653 const PageImportanceSignals& signals) {
3654 page_importance_signals_ = signals;
3655}
3656
[email protected]b172aee2012-04-10 17:05:263657void WebContentsImpl::OnFindReply(int request_id,
3658 int number_of_matches,
3659 const gfx::Rect& selection_rect,
3660 int active_match_ordinal,
3661 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173662 // Forward the find reply to the FindRequestManager, along with the
3663 // RenderFrameHost associated with the frame that the reply came from.
3664 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3665 request_id,
3666 number_of_matches,
3667 selection_rect,
3668 active_match_ordinal,
3669 final_update);
[email protected]b888919c2011-09-02 00:32:163670}
3671
mfomitchev2b8b066a2016-01-28 19:23:153672#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313673void WebContentsImpl::OnFindMatchRectsReply(
3674 int version,
3675 const std::vector<gfx::RectF>& rects,
3676 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173677 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3678 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313679}
[email protected]583418cc2013-01-17 14:01:103680
paulmeyerc8cb7cb2016-06-07 01:14:193681void WebContentsImpl::OnGetNearestFindResultReply(int request_id,
3682 float distance) {
3683 GetOrCreateFindRequestManager()->OnGetNearestFindResultReply(
3684 render_frame_message_source_, request_id, distance);
3685}
3686
[email protected]1ff427972013-02-07 21:14:073687void WebContentsImpl::OnOpenDateTimeDialog(
3688 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173689 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093690 GetRenderViewHost(),
3691 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133692 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093693 value.minimum,
3694 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173695 value.step,
3696 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103697}
[email protected]59363fc92012-09-05 03:46:313698#endif
3699
avi60bd4902015-09-23 20:39:243700void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3701 std::string json = json_string;
3702 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3703 Source<WebContents>(this),
3704 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403705}
3706
[email protected]b172aee2012-04-10 17:05:263707void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3708 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103709 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253710 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103711 AppCacheAccessed(manifest_url, blocked_by_policy));
3712}
3713
[email protected]8bc5ff02013-11-29 06:34:033714void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483715 int color_chooser_id,
3716 SkColor color,
3717 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113718 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003719 return;
nasko907fcb62015-01-28 04:24:113720
[email protected]aa62afd2014-04-22 19:22:463721 ColorChooser* new_color_chooser = delegate_ ?
3722 delegate_->OpenColorChooser(this, color, suggestions) :
3723 NULL;
[email protected]820957a2014-01-14 14:56:303724 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213725 return;
[email protected]8ed16472014-04-11 19:02:483726 if (color_chooser_info_.get())
3727 color_chooser_info_->chooser->End();
3728
3729 color_chooser_info_.reset(new ColorChooserInfo(
3730 render_frame_message_source_->GetProcess()->GetID(),
3731 render_frame_message_source_->GetRoutingID(),
3732 new_color_chooser,
3733 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203734}
3735
[email protected]b172aee2012-04-10 17:05:263736void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483737 if (color_chooser_info_ &&
3738 color_chooser_id == color_chooser_info_->identifier)
3739 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203740}
3741
[email protected]b172aee2012-04-10 17:05:263742void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323743 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483744 if (color_chooser_info_ &&
3745 color_chooser_id == color_chooser_info_->identifier)
3746 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203747}
3748
[email protected]d0759f492012-04-19 22:50:503749// This exists for render views that don't have a WebUI, but do have WebUI
3750// bindings enabled.
3751void WebContentsImpl::OnWebUISend(const GURL& source_url,
3752 const std::string& name,
3753 const base::ListValue& args) {
3754 if (delegate_)
3755 delegate_->WebUISend(this, source_url, name, args);
3756}
3757
thestigc4cac8f2014-09-04 21:17:503758#if defined(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:173759void WebContentsImpl::OnPepperInstanceCreated(int32_t pp_instance) {
3760 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3761 PepperInstanceCreated());
3762 pepper_playback_observer_->PepperInstanceCreated(pp_instance);
emaxxe70f5e12015-05-29 11:26:003763}
3764
zqzhang181047e62016-07-01 13:37:173765void WebContentsImpl::OnPepperInstanceDeleted(int32_t pp_instance) {
3766 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3767 PepperInstanceDeleted());
3768 pepper_playback_observer_->PepperInstanceDeleted(pp_instance);
emaxxe70f5e12015-05-29 11:26:003769}
3770
tommyclie6633ca72014-10-31 00:40:423771void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3772 const base::FilePath& path,
3773 bool is_hung) {
3774 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3775
3776 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3777 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3778}
3779
zqzhang181047e62016-07-01 13:37:173780void WebContentsImpl::OnPepperStartsPlayback(int32_t pp_instance) {
3781 pepper_playback_observer_->PepperStartsPlayback(pp_instance);
3782}
3783
3784void WebContentsImpl::OnPepperStopsPlayback(int32_t pp_instance) {
3785 pepper_playback_observer_->PepperStopsPlayback(pp_instance);
3786}
3787
tommyclie6633ca72014-10-31 00:40:423788void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3789 base::ProcessId plugin_pid) {
3790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3791 PluginCrashed(plugin_path, plugin_pid));
3792}
3793
[email protected]d8415ad92012-08-23 14:40:503794void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443795 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503796 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343797 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163798 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443799 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163800 return;
[email protected]d8415ad92012-08-23 14:40:503801 }
3802
[email protected]8c8fc292012-11-23 18:57:163803 if (!delegate_->RequestPpapiBrokerPermission(
3804 this, url, plugin_path,
3805 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443806 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163807 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443808 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163809 }
[email protected]d8415ad92012-08-23 14:40:503810}
3811
[email protected]ea0309c2013-08-06 19:35:443812void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503813 bool result) {
[email protected]ea0309c2013-08-06 19:35:443814 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503815}
3816
fsamuel833ee7c2015-02-13 23:40:403817void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3818 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393819 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143820 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403821 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373822}
tommyclie6633ca72014-10-31 00:40:423823#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373824
[email protected]795c28972012-12-06 06:13:393825void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393826 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063827 // We get updated favicon URLs after the page stops loading. If a cross-site
3828 // navigation occurs while a page is still loading, the initial page
3829 // may stop loading and send us updated favicon URLs after the navigation
3830 // for the new page has committed.
3831 RenderViewHostImpl* rvhi =
3832 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3833 if (!rvhi->is_active())
3834 return;
3835
[email protected]795c28972012-12-06 06:13:393836 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293837 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393838}
3839
avayvod41634b12015-07-08 17:07:053840void WebContentsImpl::OnMediaSessionStateChanged() {
3841 MediaSession* session = MediaSession::Get(this);
3842 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3843 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543844 session->IsSuspended(),
3845 session->metadata()));
avayvod41634b12015-07-08 17:07:053846}
3847
3848void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523849 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053850}
3851
3852void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523853 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053854}
3855
mlamouri4c4fbed2015-08-17 15:51:013856void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523857 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013858}
3859
[email protected]50279492014-05-05 23:24:293860void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153861 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293862 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283863
peter90afaba2015-06-01 12:05:293864 did_first_visually_non_empty_paint_ = true;
3865
yusufod41c5f92015-03-06 00:14:283866 if (theme_color_ != last_sent_theme_color_) {
3867 // Theme color should have updated by now if there was one.
3868 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3869 DidChangeThemeColor(theme_color_));
3870 last_sent_theme_color_ = theme_color_;
3871 }
[email protected]9f268072013-11-07 00:02:153872}
[email protected]d9030b82013-07-19 08:26:063873
[email protected]e67ebf32013-02-13 11:07:193874void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013875 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073876 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013877
estark5ea80e52015-06-19 18:43:123878 SecurityStyleExplanations security_style_explanations;
3879 SecurityStyle security_style =
3880 delegate_->GetSecurityStyle(this, &security_style_explanations);
3881 FOR_EACH_OBSERVER(
3882 WebContentsObserver, observers_,
3883 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013884 }
[email protected]e67ebf32013-02-13 11:07:193885}
3886
[email protected]17e286e2013-03-01 23:29:393887void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3888 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3889 BeforeFormRepostWarningShow());
3890}
3891
[email protected]ec6c05f2013-10-23 18:41:573892void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3893 Activate();
3894 if (delegate_)
3895 delegate_->ShowRepostFormWarningDialog(this);
3896}
3897
[email protected]b4c84012014-04-28 19:51:103898bool WebContentsImpl::HasAccessedInitialDocument() {
3899 return has_accessed_initial_document_;
3900}
3901
[email protected]b172aee2012-04-10 17:05:263902void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463903 // If we are creating a RVH for a restored controller, then we need to make
3904 // sure the RenderView starts with a next_page_id_ larger than the number
3905 // of restored entries. This must be called before the RenderView starts
3906 // navigating (to avoid a race between the browser updating max_page_id and
3907 // the renderer updating next_page_id_). Because of this, we only call this
3908 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563909 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583910 if (max_restored_page_id >
3911 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3912 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3913 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323914}
3915
afakhry6f0c1ec22016-07-14 13:55:133916void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:263917 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323918 // For file URLs without a title, use the pathname instead. In the case of a
3919 // synthesized title, we don't want the update to count toward the "one set
3920 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263921 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323922 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513923 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243924 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323925 explicit_set = false; // Don't count synthetic titles toward the set limit.
3926 } else {
[email protected]8af69c6c2014-03-03 19:05:313927 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323928 explicit_set = true;
3929 }
3930
[email protected]987fc3a2011-05-26 14:18:093931 // If a page is created via window.open and never navigated,
3932 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553933 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093934 if (entry) {
[email protected]36fc0392011-12-25 03:59:513935 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:133936 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323937
[email protected]36fc0392011-12-25 03:59:513938 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093939 } else {
3940 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:133941 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:093942
3943 page_title_when_no_navigation_entry_ = final_title;
3944 }
[email protected]420ae012009-04-24 05:16:323945
[email protected]420ae012009-04-24 05:16:323946 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233947 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323948
[email protected]66798902013-10-01 18:40:163949 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533950 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163951
afakhry6f0c1ec22016-07-14 13:55:133952 // Broadcast notifications when the UI should be updated.
3953 if (entry == controller_.GetEntryAtOffset(0))
3954 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323955}
3956
fdegansa696e5112015-04-17 01:57:593957void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003958 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003959 if (delegate_)
fdegansa696e5112015-04-17 01:57:593960 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003961}
3962
3963void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343964 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003965 loading_weak_factory_.InvalidateWeakPtrs();
3966 loading_last_progress_update_ = base::TimeTicks();
3967}
3968
clamy44e84ce2016-02-22 15:38:253969// Notifies the RenderWidgetHost instance about the fact that the page is
3970// loading, or done loading.
3971void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3972 bool due_to_interstitial,
3973 LoadNotificationDetails* details) {
3974 // Do not send notifications about loading changes in the FrameTree while the
3975 // interstitial page is pausing the throbber.
3976 if (ShowingInterstitialPage() &&
3977 GetRenderManager()->interstitial_page()->pause_throbber() &&
3978 !due_to_interstitial) {
3979 return;
3980 }
3981
3982 bool is_loading = IsLoading();
3983
3984 if (!is_loading) {
3985 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3986 base::string16());
3987 load_state_host_.clear();
3988 upload_size_ = 0;
3989 upload_position_ = 0;
3990 }
3991
3992 GetRenderManager()->SetIsLoading(is_loading);
3993
3994 waiting_for_response_ = is_loading;
3995 is_load_to_different_document_ = to_different_document;
3996
3997 if (delegate_)
3998 delegate_->LoadingStateChanged(this, to_different_document);
3999 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
4000
4001 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
4002 if (is_loading) {
4003 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
4004 this, "URL", url, "Main FrameTreeNode id",
4005 GetFrameTree()->root()->frame_tree_node_id());
4006 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
4007 } else {
4008 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
4009 this, "URL", url);
4010 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
4011 }
4012
4013 // TODO(avi): Remove. http://crbug.com/170921
4014 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
4015 NotificationDetails det = NotificationService::NoDetails();
4016 if (details)
4017 det = Details<LoadNotificationDetails>(details);
4018 NotificationService::current()->Notify(
4019 type, Source<NavigationController>(&controller_), det);
4020}
4021
[email protected]02d7b6e2014-06-24 21:01:504022void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
4023 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:324024 // After sending out a swap notification, we need to send a disconnect
4025 // notification so that clients that pick up a pointer to |this| can NULL the
4026 // pointer. See Bug 1230284.
4027 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:114028 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:284029 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:114030
[email protected]7a846df2012-09-20 19:17:394031 // Ensure that the associated embedder gets cleared after a RenderViewHost
4032 // gets swapped, so we don't reuse the same embedder next time a
4033 // RenderViewHost is attached to this WebContents.
4034 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:324035}
4036
[email protected]02d7b6e2014-06-24 21:01:504037void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
4038 RenderFrameHost* new_host) {
4039 FOR_EACH_OBSERVER(WebContentsObserver,
4040 observers_,
4041 RenderFrameHostChanged(old_host, new_host));
4042}
4043
[email protected]da7a7182013-09-06 08:11:114044// TODO(avi): Remove this entire function because this notification is already
4045// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:264046void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:324047 if (!notify_disconnection_)
4048 return;
4049
4050 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:214051 NotificationService::current()->Notify(
4052 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
4053 Source<WebContents>(this),
4054 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:324055}
4056
[email protected]cbb1ef592013-06-05 19:49:464057void WebContentsImpl::NotifyNavigationEntryCommitted(
4058 const LoadCommittedDetails& load_details) {
4059 FOR_EACH_OBSERVER(
4060 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
4061}
4062
[email protected]f114fa42013-12-06 17:06:444063bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
4064 const IPC::Message& message) {
4065 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:314066}
4067
rockotf62002a2016-09-15 00:08:594068void WebContentsImpl::OnAssociatedInterfaceRequest(
4069 RenderFrameHost* render_frame_host,
4070 const std::string& interface_name,
4071 mojo::ScopedInterfaceEndpointHandle handle) {
4072 auto it = binding_sets_.find(interface_name);
4073 if (it != binding_sets_.end())
4074 it->second->OnRequestForFrame(render_frame_host, std::move(handle));
4075}
4076
[email protected]c31a84802014-04-03 15:55:494077const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
4078 return GetLastCommittedURL();
4079}
4080
[email protected]b849847b2013-12-10 21:57:584081void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:584082 FOR_EACH_OBSERVER(WebContentsObserver,
4083 observers_,
4084 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:304085 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:454086
4087 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
4088 return;
4089
4090 NavigationEntry* entry = controller_.GetPendingEntry();
4091 if (entry && entry->IsViewSourceMode()) {
4092 // Put the renderer in view source mode.
4093 render_frame_host->Send(
4094 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
4095 }
sammc5a139ba2016-09-29 01:49:144096#if defined(OS_ANDROID)
4097 render_frame_host->GetInterfaceRegistry()->AddInterface(
4098 GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>());
4099#endif
[email protected]b849847b2013-12-10 21:57:584100}
4101
4102void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
4103 FOR_EACH_OBSERVER(WebContentsObserver,
4104 observers_,
4105 RenderFrameDeleted(render_frame_host));
4106}
4107
[email protected]a09d53ce2014-01-31 00:46:424108void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
4109 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:104110 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:424111 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:104112 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:424113 return;
4114
[email protected]077e704b2014-05-23 19:24:104115 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
4116 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:424117}
4118
[email protected]87de04b02014-04-08 22:14:494119void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:014120 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494121 const base::string16& message,
4122 const base::string16& default_prompt,
4123 const GURL& frame_url,
4124 JavaScriptMessageType javascript_message_type,
4125 IPC::Message* reply_msg) {
4126 // Suppress JavaScript dialogs when requested. Also suppress messages when
4127 // showing an interstitial as it's shown over the previous page and we don't
4128 // want the hidden page's dialogs to interfere with the interstitial.
4129 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:504130 ShowingInterstitialPage() || !delegate_ ||
4131 delegate_->ShouldSuppressDialogs(this) ||
4132 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494133
4134 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:504135 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494136 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:034137 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:414138 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014139 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:414140 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:494141 &suppress_this_message);
4142 }
4143
4144 if (suppress_this_message) {
4145 // If we are suppressing messages, just reply as if the user immediately
4146 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:014147 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
4148 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284149 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:494150 }
4151
4152 // OnDialogClosed (two lines up) may have caused deletion of this object (see
4153 // http://crbug.com/288961 ). The only safe thing to do here is return.
4154}
4155
4156void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014157 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494158 bool is_reload,
4159 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014160 RenderFrameHostImpl* rfhi =
4161 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494162 if (delegate_)
4163 delegate_->WillRunBeforeUnloadConfirm();
4164
4165 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454166 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024167 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504168 delegate_->ShouldSuppressDialogs(this) ||
4169 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494170 if (suppress_this_message) {
4171 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4172 return;
4173 }
4174
4175 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504176 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494177 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424178 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494179 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014180 render_frame_host->GetProcess()->GetID(),
4181 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284182 false));
[email protected]87de04b02014-04-08 22:14:494183}
4184
naskoada75b22016-06-11 16:09:464185void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host,
4186 const FileChooserParams& params) {
4187 if (delegate_)
4188 delegate_->RunFileChooser(render_frame_host, params);
4189}
4190
[email protected]a86c0e962013-12-17 17:10:394191WebContents* WebContentsImpl::GetAsWebContents() {
4192 return this;
4193}
4194
wjmaclean64951902016-04-29 20:59:124195double WebContentsImpl::GetPendingPageZoomLevel() {
4196 NavigationEntry* pending_entry = GetController().GetPendingEntry();
4197 if (!pending_entry)
4198 return HostZoomMap::GetZoomLevel(this);
4199
4200 GURL url = pending_entry->GetURL();
4201 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
4202 url.scheme(), net::GetHostOrSpecFromURL(url));
4203}
4204
[email protected]7912e822014-04-16 02:37:034205bool WebContentsImpl::IsNeverVisible() {
4206 if (!delegate_)
4207 return false;
4208 return delegate_->IsNeverVisible(this);
4209}
4210
[email protected]5a3bdf52012-05-24 15:12:574211RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4212 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324213}
4214
[email protected]8ff00d72012-10-23 19:12:214215RendererPreferences WebContentsImpl::GetRendererPrefs(
4216 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464217 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514218}
4219
avic3aa8422015-11-09 20:57:224220gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
4221 RenderWidgetHostImpl* render_widget_host) const {
4222 if (!RenderViewHostImpl::From(render_widget_host))
4223 return gfx::Rect();
4224
[email protected]b7a756d42012-01-23 18:08:174225 if (delegate_)
4226 return delegate_->GetRootWindowResizerRect();
4227 return gfx::Rect();
4228}
4229
[email protected]7a846df2012-09-20 19:17:394230void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274231 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394232 browser_plugin_embedder_.reset();
4233}
4234
avallee0206f782016-07-28 18:55:334235WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
ekaramad1beabecc2016-09-23 20:18:174236 if (GuestMode::IsCrossProcessFrameGuest(this) && node_)
4237 return node_->outer_web_contents();
4238
4239 if (browser_plugin_guest_)
4240 return browser_plugin_guest_->embedder_web_contents();
4241
avallee0206f782016-07-28 18:55:334242 return nullptr;
4243}
4244
4245WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
4246 // There is no inner or outer web contents.
4247 if (!node_ && !GetBrowserPluginGuest())
4248 return this;
4249
4250 // We may need to create a node_ on the outermost contents in the
4251 // BrowserPlugin case.
4252 WebContentsImpl* outermost = GetOutermostWebContents();
4253 if (!outermost->node_) {
4254 outermost->node_.reset(new WebContentsTreeNode());
4255 outermost->node_->SetFocusedWebContents(outermost);
4256 }
4257 return outermost->node_->focused_web_contents();
4258}
4259
4260WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
4261 WebContentsImpl* root = this;
4262 while (root->GetOuterWebContents())
4263 root = root->GetOuterWebContents();
4264 return root;
4265}
4266
[email protected]b172aee2012-04-10 17:05:264267void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444268 // Don't send notifications if we are just creating a swapped-out RVH for
4269 // the opener chain. These won't be used for view-source or WebUI, so it's
4270 // ok to return early.
creiscce56cd2014-09-29 22:45:224271 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444272 return;
4273
[email protected]86f98a22013-03-20 14:35:004274 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314275 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084276
[email protected]8ff00d72012-10-23 19:12:214277 NotificationService::current()->Notify(
4278 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4279 Source<WebContents>(this),
4280 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324281
[email protected]60780f412013-02-25 16:34:104282 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264283
4284 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254285 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324286}
4287
[email protected]b172aee2012-04-10 17:05:264288void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524289 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324290 // Don't notify the world, since this came from a renderer in the
4291 // background.
4292 return;
4293 }
4294
[email protected]da7a7182013-09-06 08:11:114295 notify_disconnection_ = true;
4296 // TODO(avi): Remove. http://crbug.com/170921
4297 NotificationService::current()->Notify(
4298 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4299 Source<WebContents>(this),
4300 NotificationService::NoDetails());
4301
[email protected]be1f56ab2011-12-22 06:55:314302 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234303 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304304
4305 // Restore the focus to the tab (otherwise the focus will be on the top
4306 // window).
[email protected]484ae5912010-09-29 19:16:144307 if (was_crashed && !FocusLocationBarByDefault() &&
4308 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064309 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144310 }
[email protected]32ded2212011-11-10 18:51:434311
[email protected]d8c660432011-12-22 20:51:254312 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324313}
4314
[email protected]ec6a7eb2013-04-22 17:34:224315void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4316 base::TerminationStatus status,
4317 int error_code) {
[email protected]151a63d2011-12-20 22:32:524318 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324319 // The pending page's RenderViewHost is gone.
4320 return;
4321 }
4322
[email protected]2fcdcc32014-03-05 02:14:074323 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4324 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:154325 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464326 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074327
[email protected]698191dc2014-02-25 01:06:134328 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174329 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134330
[email protected]f738bdcb2014-07-11 20:40:444331 if (delegate_)
4332 delegate_->HideValidationMessage(this);
4333
[email protected]960b0372014-05-19 18:01:004334 // Reset the loading progress. TODO(avi): What does it mean to have a
4335 // "renderer crash" when there is more than one renderer process serving a
4336 // webpage? Once this function is called at a more granular frame level, we
4337 // probably will need to more granularly reset the state here.
4338 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254339 NotifyDisconnected();
4340 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004341
[email protected]d8c660432011-12-22 20:51:254342 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274343 observers_,
[email protected]58d5cfe2013-07-10 02:40:524344 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324345}
4346
[email protected]b172aee2012-04-10 17:05:264347void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254348 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064349}
4350
[email protected]b172aee2012-04-10 17:05:264351void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104352 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044353 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384354 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4355
creise1d3e5b2014-12-01 18:21:574356 // Ensure that this state update comes from a RenderViewHost that belongs to
4357 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414358 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574359 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414360 return;
[email protected]420ae012009-04-24 05:16:324361
avi286019ce2015-07-29 01:26:584362 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324363 // when the user is scrolling and entering form data, as well as when we're
4364 // leaving a page, in which case our state may have already been moved to
4365 // the next page. The navigation controller will look up the appropriate
4366 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584367 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114368 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584369 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114370 if (!entry)
[email protected]420ae012009-04-24 05:16:324371 return;
[email protected]420ae012009-04-24 05:16:324372
nasko346969912015-12-16 22:36:474373 // Sanity check that ensures nav_entry_id and page_id point to the same
4374 // navigation entry.
4375 if (rvhi->GetMainFrame()) {
4376 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4377 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4378 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534379
nasko346969912015-12-16 22:36:474380 DCHECK_EQ(entry, new_entry);
4381 }
creisd63f6c4a2015-11-06 19:05:534382
[email protected]691aa2f2013-05-28 22:52:044383 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324384 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044385 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114386 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324387}
4388
sky8b00392d2015-01-10 00:30:284389void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4390 const GURL& url) {
4391 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4392 // If we're fullscreen only update the url if it's from the fullscreen
4393 // renderer.
4394 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444395 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284396 return;
4397 }
[email protected]6934a702011-12-20 00:04:514398 if (delegate_)
avi450ce00e2014-09-24 01:58:524399 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324400}
4401
[email protected]b172aee2012-04-10 17:05:264402void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104403#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294404 // The UI may be in an event-tracking loop, such as between the
4405 // mouse-down and mouse-up in text selection or a button click.
4406 // Defer the close until after tracking is complete, so that we
4407 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294408 // TODO(shess): This could get more fine-grained. For instance,
4409 // closing a tab in another window while selecting text in the
4410 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104411 if (view_->IsEventTracking()) {
4412 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294413 return;
4414 }
[email protected]60780f412013-02-25 16:34:104415#endif
[email protected]07707302009-11-06 00:50:294416
[email protected]420ae012009-04-24 05:16:324417 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524418 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514419 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324420}
4421
[email protected]b172aee2012-04-10 17:05:264422void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514423 if (delegate_ && delegate_->IsPopupOrPanel(this))
4424 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324425}
4426
fdegansa696e5112015-04-17 01:57:594427void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094428 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254429 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084430
4431 // Notify accessibility that the user is navigating away from the
4432 // current document.
4433 //
4434 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084435 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594436 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084437 if (manager)
4438 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324439}
4440
fdegansc73eec22015-03-19 14:47:544441void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084442 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324443
[email protected]9595fd82013-04-19 21:28:494444 // Use the last committed entry rather than the active one, in case a
4445 // pending entry has been created.
4446 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204447 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494448
[email protected]420ae012009-04-24 05:16:324449 // An entry may not exist for a stop when loading an initial blank page or
4450 // if an iframe injected by script into a blank page finishes loading.
4451 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204452 base::TimeDelta elapsed =
4453 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324454
4455 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514456 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:324457 elapsed,
4458 &controller_,
4459 controller_.GetCurrentEntryIndex()));
4460 }
4461
clamy44e84ce2016-02-22 15:38:254462 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324463}
4464
fdegansa696e5112015-04-17 01:57:594465void WebContentsImpl::DidChangeLoadProgress() {
4466 double load_progress = frame_tree_.load_progress();
4467
4468 // The delegate is notified immediately for the first and last updates. Also,
4469 // since the message loop may be pretty busy when a page is loaded, it might
4470 // not execute a posted task in a timely manner so the progress report is sent
4471 // immediately if enough time has passed.
4472 base::TimeDelta min_delay =
4473 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4474 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4475 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4476
4477 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4478 // If there is a pending task to send progress, it is now obsolete.
4479 loading_weak_factory_.InvalidateWeakPtrs();
4480
4481 // Notify the load progress change.
4482 SendChangeLoadProgress();
4483
4484 // Clean-up the states if needed.
4485 if (load_progress == 1.0)
4486 ResetLoadProgressState();
4487 return;
4488 }
4489
4490 if (loading_weak_factory_.HasWeakPtrs())
4491 return;
4492
skyostil95082a62015-06-05 19:53:074493 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4494 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4495 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594496 min_delay);
4497}
4498
clamycbf524d42016-09-27 12:48:354499ScopedVector<NavigationThrottle> WebContentsImpl::CreateThrottlesForNavigation(
4500 NavigationHandle* navigation_handle) {
4501 return GetContentClient()->browser()->CreateThrottlesForNavigation(
4502 navigation_handle);
4503}
4504
clamy1e5574e2016-09-29 16:48:444505std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
4506 NavigationHandle* navigation_handle) {
4507 DCHECK(IsBrowserSideNavigationEnabled());
4508 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
4509}
4510
[email protected]b172aee2012-04-10 17:05:264511void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164512 controller_.DiscardNonCommittedEntries();
4513
4514 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214515 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164516}
4517
[email protected]59167c22013-06-03 18:07:324518void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104519 has_accessed_initial_document_ = true;
4520
[email protected]d1371bf8e2014-04-19 03:26:244521 // We may have left a failed browser-initiated navigation in the address bar
4522 // to let the user edit it and try again. Clear it now that content might
4523 // show up underneath it.
4524 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454525 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244526
[email protected]59167c22013-06-03 18:07:324527 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504528 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324529}
4530
alexmosbe2f4c32015-03-10 02:30:234531void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4532 const std::string& name) {
4533 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4534 FrameNameChanged(render_frame_host, name));
4535}
4536
[email protected]39f2f9252014-05-03 00:54:014537void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294538 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094539 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294540 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094541
4542 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214543 NotificationService::current()->Notify(
4544 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4545 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294546 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084547}
4548
creis8eb8ef22015-11-04 22:51:384549void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4550 const PageState& page_state) {
4551 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4552
4553 // The state update affects the last NavigationEntry associated with the given
4554 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4555 // in the case of an UpdateState from a frame being swapped out). We track
4556 // which entry this is in the RenderFrameHost's nav_entry_id.
4557 RenderFrameHostImpl* rfhi =
4558 static_cast<RenderFrameHostImpl*>(render_frame_host);
4559 NavigationEntryImpl* entry =
4560 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4561 if (!entry)
4562 return;
4563
4564 FrameNavigationEntry* frame_entry =
4565 entry->GetFrameEntry(rfhi->frame_tree_node());
4566 if (!frame_entry)
4567 return;
4568
creisd06a9422015-11-11 03:08:454569 // The SiteInstance might not match if we do a cross-process navigation with
4570 // replacement (e.g., auto-subframe), in which case the swap out of the old
4571 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4572 // has already been replaced and destroyed.
4573 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4574 return;
4575
creis8eb8ef22015-11-04 22:51:384576 if (page_state == frame_entry->page_state())
4577 return; // Nothing to update.
4578
creisfafed882016-07-29 00:03:094579 if (!page_state.IsValid()) {
4580 // Temporarily generate a minidump to diagnose https://crbug.com/568703.
4581 base::debug::DumpWithoutCrashing();
4582 NOTREACHED() << "Shouldn't set an empty PageState.";
4583 }
nasko34634672016-07-29 18:46:064584
4585 // The document_sequence_number and item_sequence_number recorded in the
4586 // FrameNavigationEntry should not differ from the one coming with the update,
4587 // since it must come from the same document. Do not update it if a difference
4588 // is detected, as this indicates that |frame_entry| is not the correct one.
4589 ExplodedPageState exploded_state;
4590 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
4591 return;
4592
4593 if (exploded_state.top.document_sequence_number !=
4594 frame_entry->document_sequence_number() ||
4595 exploded_state.top.item_sequence_number !=
4596 frame_entry->item_sequence_number()) {
4597 return;
4598 }
4599
nasko04a322f25a2016-09-01 00:00:344600 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:384601 controller_.NotifyEntryChanged(entry);
4602}
4603
[email protected]ef3adfc2014-05-11 00:04:544604void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104605 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544606 const base::string16& title,
4607 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544608 // If we have a title, that's a pretty good indication that we've started
4609 // getting useful data.
4610 SetNotWaitingForResponse();
4611
4612 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584613 // For example, it might be from a recently swapped out RFH.
creisad8c31a2016-05-24 17:07:044614 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
creise64343ae2016-05-23 20:02:404615 render_frame_host->GetSiteInstance(), page_id);
creisad8c31a2016-05-24 17:07:044616
creisad8c31a2016-05-24 17:07:044617 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4618 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
creis0bfe5282016-06-02 06:46:204619 if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) {
4620 // In out-of-process iframe enabled modes, page_id can't keep track of
4621 // navigations in other processes, so we must use nav_entry_id.
4622 // TODO(creis): Switch to use this as the default.
4623 entry = new_entry;
4624 } else {
4625 // In modes that have no out-of-process iframes, nav_entry_id and page_id
4626 // should agree on which entry to update.
4627 DCHECK_EQ(entry, new_entry);
4628 }
[email protected]ef3adfc2014-05-11 00:04:544629
4630 // We can handle title updates when we don't have an entry in
4631 // UpdateTitleForEntry, but only if the update is from the current RVH.
4632 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584633 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544634 return;
4635
4636 // TODO(evan): make use of title_direction.
4637 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:134638 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:544639}
4640
4641void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4642 const std::string& encoding) {
4643 SetEncoding(encoding);
4644}
4645
[email protected]39f2f9252014-05-03 00:54:014646void WebContentsImpl::DocumentAvailableInMainFrame(
4647 RenderViewHost* render_view_host) {
4648 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4649 DocumentAvailableInMainFrame());
4650}
naskoc0fceff2015-04-30 15:53:524651
[email protected]e1c3a552012-05-04 20:51:324652void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4653 // Tell the active RenderViewHost to run unload handlers and close, as long
4654 // as the request came from a RenderViewHost in the same BrowsingInstance.
4655 // In most cases, we receive this from a swapped out RenderViewHost.
4656 // It is possible to receive it from one that has just been swapped in,
4657 // in which case we might as well deliver the message anyway.
4658 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524659 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324660}
4661
alexmose7da5a12015-04-09 02:22:164662bool WebContentsImpl::ShouldRouteMessageEvent(
4663 RenderFrameHost* target_rfh,
4664 SiteInstance* source_site_instance) const {
4665 // Allow the message if this WebContents is dedicated to a browser plugin
4666 // guest.
[email protected]0eba810b2012-10-18 03:19:364667 // Note: This check means that an embedder could theoretically receive a
4668 // postMessage from anyone (not just its own guests). However, this is
4669 // probably not a risk for apps since other pages won't have references
4670 // to App windows.
alexmose7da5a12015-04-09 02:22:164671 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4672}
[email protected]f546640b2012-05-15 00:03:494673
alexmos58729042015-06-18 23:20:004674void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164675 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4676 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494677
alexmose7da5a12015-04-09 02:22:164678 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144679 // If this message is going to outer WebContents from inner WebContents,
4680 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4681 // already created a RenderFrameProxyHost for that purpose.
4682 if (GetBrowserPluginEmbedder() &&
ekaramad1beabecc2016-09-23 20:18:174683 GuestMode::IsCrossProcessFrameGuest(source_web_contents)) {
lazyboy6ec48b2a2015-06-29 15:18:144684 return;
4685 }
4686
lfg812874d2016-02-09 22:26:134687 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064688 // We create a RenderFrameProxyHost for the embedder in the guest's render
4689 // process but we intentionally do not expose the embedder's opener chain
4690 // to it.
4691 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4692 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494693 } else {
alexmos58729042015-06-18 23:20:004694 RenderFrameHostImpl* source_rfhi =
4695 static_cast<RenderFrameHostImpl*>(source_rfh);
4696 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394697 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494698 }
4699 }
[email protected]f546640b2012-05-15 00:03:494700}
4701
avallee0206f782016-07-28 18:55:334702void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4703 SiteInstance* source) {
ekaramad1beabecc2016-09-23 20:18:174704 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
avallee0206f782016-07-28 18:55:334705 frame_tree_.SetFocusedFrame(node, source);
4706 return;
4707 }
4708
4709 // 1. Find old focused frame and unfocus it.
4710 // 2. Focus the new frame in the current FrameTree.
4711 // 3. Set current WebContents as focused.
4712 WebContentsImpl* old_focused_contents = GetFocusedWebContents();
4713 if (old_focused_contents != this) {
4714 // Focus is moving between frame trees, unfocus the frame in the old tree.
4715 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source);
4716 GetOutermostWebContents()->node_->SetFocusedWebContents(this);
4717 }
4718
4719 frame_tree_.SetFocusedFrame(node, source);
4720
4721 // TODO(avallee): Remove this once page focus is fixed.
4722 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost();
ekaramad1beabecc2016-09-23 20:18:174723 if (rwh && old_focused_contents != this)
avallee0206f782016-07-28 18:55:334724 rwh->Focus();
4725}
4726
avib7348942015-12-25 20:57:104727bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264728 const base::string16& message,
avib7348942015-12-25 20:57:104729 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264730 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254731 if (!delegate_)
4732 return false;
4733 return delegate_->AddMessageToConsole(this, level, message, line_no,
4734 source_id);
4735}
4736
dominickn9c7ceaa32016-02-27 01:52:534737void WebContentsImpl::OnUserInteraction(
4738 RenderWidgetHostImpl* render_widget_host,
4739 const blink::WebInputEvent::Type type) {
kenrb19221852016-04-29 17:21:404740 // Ignore unless the widget is currently in the frame tree.
4741 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:224742 return;
4743
dominickn2dd142dd2015-10-29 05:30:504744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4745 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534746
4747 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4748 // Exclude scroll events as user gestures for resource load dispatches.
4749 // rdh is NULL in unittests.
4750 if (rdh && type != blink::WebInputEvent::MouseWheel)
scottmge22a5e52016-06-30 00:36:514751 rdh->OnUserGesture();
dominickn2dd142dd2015-10-29 05:30:504752}
4753
[email protected]b172aee2012-04-10 17:05:264754void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444755 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254756 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444757}
4758
avic3aa8422015-11-09 20:57:224759void WebContentsImpl::RendererUnresponsive(
clamy639fdffb2016-07-18 18:13:324760 RenderWidgetHostImpl* render_widget_host,
4761 RenderWidgetHostDelegate::RendererUnresponsiveType type) {
afakhry98241832016-03-11 19:27:474762 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4763 OnRendererUnresponsive(render_widget_host));
4764
[email protected]992db4c2011-05-12 15:37:154765 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224766 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154767 return;
4768
creiscce56cd2014-09-29 22:45:224769 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224770 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584771
[email protected]e5fc1632011-08-08 07:51:534772 // Ignore renderer unresponsive event if debugger is attached to the tab
4773 // since the event may be a result of the renderer sitting on a breakpoint.
4774 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364775 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534776 return;
4777
clamy639fdffb2016-07-18 18:13:324778 // Record histograms about the type of renderer hang.
4779 UMA_HISTOGRAM_ENUMERATION(
4780 "ChildProcess.HangRendererType", type,
4781 RenderWidgetHostDelegate::RENDERER_UNRESPONSIVE_MAX);
4782
metaflow73fc9552016-05-23 18:26:484783 // We might have been waiting for both beforeunload and unload ACK.
4784 // Check if tab is to be unloaded first.
4785 if (rfhi->IsWaitingForUnloadACK()) {
4786 // Hang occurred while firing the unload handler.
[email protected]420ae012009-04-24 05:16:324787 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224788 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324789
[email protected]fa944cb82013-11-15 17:51:214790 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324791 return;
4792
metaflow73fc9552016-05-23 18:26:484793 // If the tab hangs in the unload handler there's really nothing we can do
4794 // to recover. Pretend the unload listeners have all fired and close
[email protected]2e9d79f2013-08-16 05:45:564795 // the tab.
metaflow73fc9552016-05-23 18:26:484796 Close();
4797 return;
4798 }
4799
4800 if (rfhi->is_waiting_for_beforeunload_ack()) {
4801 // If the hang is in the beforeunload handler, pretend the beforeunload
4802 // listeners have all fired and allow the delegate to continue closing;
4803 // the user will not have the option of cancelling the close.
4804 rfhi->SimulateBeforeUnloadAck();
[email protected]420ae012009-04-24 05:16:324805 return;
4806 }
4807
creisc014b402015-04-23 16:41:454808 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474809 return;
4810
[email protected]6934a702011-12-20 00:04:514811 if (delegate_)
4812 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324813}
4814
avic3aa8422015-11-09 20:57:224815void WebContentsImpl::RendererResponsive(
4816 RenderWidgetHostImpl* render_widget_host) {
4817 if (render_widget_host != GetRenderViewHost()->GetWidget())
4818 return;
4819
[email protected]6934a702011-12-20 00:04:514820 if (delegate_)
4821 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324822}
4823
[email protected]b172aee2012-04-10 17:05:264824void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554825 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324826 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124827 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4828 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514829 if (delegate_)
4830 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094831 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324832}
4833
[email protected]58d5cfe2013-07-10 02:40:524834void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544835 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234836 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224837 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544838}
4839
[email protected]b172aee2012-04-10 17:05:264840void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104841 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214842 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264843 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4844 // here during container initialization and normal window size will be set
4845 // later. In case of tab duplication this resizing to 0x0 prevents setting
4846 // normal size later so just ignore it.
4847 if (!size.IsEmpty())
4848 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324849}
4850
[email protected]af905902013-10-01 21:38:514851void WebContentsImpl::CancelModalDialogsForRenderManager() {
4852 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544853 // deferrer would prevent us from swapping out. We also clear the state
4854 // because this is a cross-process navigation, which means that it's a new
4855 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174856 //
4857 // Note that we don't bother telling browser_plugin_embedder_ because the
4858 // cross-process navigation will either destroy the browser plugins or not
4859 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514860 if (dialog_manager_)
avi2460c762015-04-17 15:21:544861 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514862}
4863
[email protected]02d7b6e2014-06-24 21:01:504864void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4865 RenderFrameHost* new_host,
4866 bool is_main_frame) {
4867 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054868 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504869 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084870
[email protected]02d7b6e2014-06-24 21:01:504871 // Make sure the visible RVH reflects the new delegate's preferences.
4872 if (delegate_)
4873 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394874
[email protected]02d7b6e2014-06-24 21:01:504875 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4876 }
4877
4878 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544879}
4880
naskof5940b9f2015-03-02 23:04:054881void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4882 RenderViewHost* old_host,
4883 RenderViewHost* new_host) {
4884 NotifyViewSwapped(old_host, new_host);
4885}
4886
[email protected]b172aee2012-04-10 17:05:264887NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194888 return GetController();
[email protected]3a3d47472010-07-15 21:03:544889}
4890
dcheng59716272016-04-09 05:19:084891std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294892 const GURL& url) {
dcheng59716272016-04-09 05:19:084893 return std::unique_ptr<WebUIImpl>(
4894 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324895}
4896
[email protected]10f417c52011-12-28 21:04:234897NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264898 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324899 return controller_.GetLastCommittedEntry();
4900}
4901
lfgbede6392015-09-11 21:54:064902void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4903 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334904 RenderWidgetHostViewBase* rwh_view =
4905 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524906
[email protected]420ae012009-04-24 05:16:324907 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444908 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214909 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064910}
4911
4912bool WebContentsImpl::CreateRenderViewForRenderManager(
4913 RenderViewHost* render_view_host,
4914 int opener_frame_routing_id,
4915 int proxy_routing_id,
4916 const FrameReplicationState& replicated_frame_state) {
4917 TRACE_EVENT0("browser,navigation",
4918 "WebContentsImpl::CreateRenderViewForRenderManager");
4919
4920 if (proxy_routing_id == MSG_ROUTING_NONE)
4921 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324922
[email protected]74ce1ad2011-12-16 21:51:464923 // Make sure we use the correct starting page_id in the new RenderView.
4924 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104925 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584926 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464927
alexmos5ac402d2015-07-09 07:51:104928 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4929 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4930 max_page_id, replicated_frame_state,
4931 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524932 return false;
[email protected]14392a52012-05-02 20:28:444933 }
[email protected]a4127722011-04-27 23:13:524934
avi2b177592014-12-10 02:08:024935 SetHistoryOffsetAndLengthForView(render_view_host,
4936 controller_.GetLastCommittedEntryIndex(),
4937 controller_.GetEntryCount());
4938
[email protected]a220b5932013-09-21 03:47:444939#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504940 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4941 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444942 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444943 if (rwh_view) {
4944 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4945 render_widget_host->WasResized();
4946 }
[email protected]f8233cc2011-05-31 20:24:504947#endif
4948
[email protected]420ae012009-04-24 05:16:324949 return true;
4950}
4951
[email protected]82307f6b2014-08-07 03:30:124952bool WebContentsImpl::CreateRenderFrameForRenderManager(
4953 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044954 int proxy_routing_id,
4955 int opener_routing_id,
japhete6adf142014-10-31 00:01:494956 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044957 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434958 TRACE_EVENT0("browser,navigation",
4959 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124960
4961 RenderFrameHostImpl* rfh =
4962 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044963 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4964 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124965 return false;
4966
4967 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4968 // RenderFrameHost will have to be associated with the appropriate
4969 // RenderWidgetHostView or a new one should be created here.
4970
4971 return true;
4972}
4973
mfomitchev2b8b066a2016-01-28 19:23:154974#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454975
[email protected]155c7f22013-12-09 17:07:184976base::android::ScopedJavaLocalRef<jobject>
4977WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404978 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564979 return GetWebContentsAndroid()->GetJavaObject();
4980}
[email protected]155c7f22013-12-09 17:07:184981
[email protected]0e813a52014-08-13 10:34:564982WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184983 WebContentsAndroid* web_contents_android =
4984 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4985 if (!web_contents_android) {
4986 web_contents_android = new WebContentsAndroid(this);
4987 SetUserData(kWebContentsAndroidKey, web_contents_android);
4988 }
[email protected]0e813a52014-08-13 10:34:564989 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184990}
4991
paulmeyerc0b762b2016-04-13 11:55:174992void WebContentsImpl::ActivateNearestFindResult(float x,
4993 float y) {
4994 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4995}
4996
4997void WebContentsImpl::RequestFindMatchRects(int current_version) {
4998 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4999}
5000
[email protected]7d244f12013-08-22 21:41:515001bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:065002 return CreateRenderViewForRenderManager(
5003 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:065004 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:515005}
[email protected]fc2b46b2014-05-03 16:33:455006
sammcf5f1b0f2016-09-20 23:05:115007shell::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
5008 if (!java_interfaces_) {
5009 shell::mojom::InterfaceProviderPtr provider;
5010 BindInterfaceRegistryForWebContents(mojo::GetProxy(&provider), this);
5011 java_interfaces_.reset(new shell::InterfaceProvider);
5012 java_interfaces_->Bind(std::move(provider));
5013 }
5014 return java_interfaces_.get();
5015}
5016
[email protected]fc2b46b2014-05-03 16:33:455017#elif defined(OS_MACOSX)
5018
[email protected]75f4df72014-07-16 22:39:425019void WebContentsImpl::SetAllowOtherViews(bool allow) {
5020 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:455021}
5022
[email protected]75f4df72014-07-16 22:39:425023bool WebContentsImpl::GetAllowOtherViews() {
5024 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:455025}
5026
[email protected]7d244f12013-08-22 21:41:515027#endif
5028
pkotwicz75ca8ffd2016-02-16 23:10:195029void WebContentsImpl::OnDidDownloadImage(
5030 const ImageDownloadCallback& callback,
5031 int id,
5032 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:525033 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:185034 const std::vector<SkBitmap>& images,
5035 const std::vector<gfx::Size>& original_image_sizes) {
5036 callback.Run(id, http_status_code, image_url, images, original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:195037}
5038
[email protected]6fba26d2014-04-29 09:38:285039void WebContentsImpl::OnDialogClosed(int render_process_id,
5040 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:265041 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:495042 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:265043 bool success,
[email protected]fcf75d42013-12-03 20:11:265044 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:285045 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
5046 render_frame_id);
[email protected]87de04b02014-04-08 22:14:495047 last_dialog_suppressed_ = dialog_was_suppressed;
5048
[email protected]beb440c2009-11-06 04:08:545049 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:235050 // It is possible for the current RenderFrameHost to have changed in the
5051 // meantime. Do not reset the navigation state in that case.
5052 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:255053 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:235054 controller_.DiscardNonCommittedEntries();
5055 }
[email protected]ec8e8b02013-06-19 04:57:105056
[email protected]6d65a462013-06-21 21:29:125057 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
5058 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:545059 }
[email protected]87de04b02014-04-08 22:14:495060
[email protected]beb440c2009-11-06 04:08:545061 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:285062 if (rfh) {
5063 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
5064 dialog_was_suppressed);
5065 } else {
5066 // Don't leak the sync IPC reply if the RFH or process is gone.
5067 delete reply_msg;
5068 }
[email protected]beb440c2009-11-06 04:08:545069}
5070
[email protected]b172aee2012-04-10 17:05:265071void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:545072 if (encoding == last_reported_encoding_)
5073 return;
5074 last_reported_encoding_ = encoding;
5075
5076 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:125077 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:105078}
[email protected]f45d2a72010-03-08 23:28:355079
[email protected]1ac10dca2013-08-20 20:47:045080bool WebContentsImpl::IsHidden() {
5081 return capturer_count_ == 0 && !should_normally_be_visible_;
5082}
5083
rob97250742015-12-10 17:45:155084int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:145085 if (node_ && node_->outer_web_contents())
5086 return node_->outer_contents_frame_tree_node_id();
5087
nick2482a2d2015-12-18 01:39:375088 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:145089}
5090
[email protected]b0936d22013-11-28 06:47:365091RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:215092 return frame_tree_.root()->render_manager();
5093}
5094
[email protected]f8497342013-02-05 22:15:025095BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:395096 return browser_plugin_guest_.get();
5097}
5098
[email protected]738f57a2013-06-29 21:06:545099void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
5100 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:145101 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:545102 browser_plugin_guest_.reset(guest);
5103}
5104
[email protected]f8497342013-02-05 22:15:025105BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:395106 return browser_plugin_embedder_.get();
5107}
[email protected]8ff00d72012-10-23 19:12:215108
fsamuel60b42282015-03-10 03:29:145109void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
5110 if (browser_plugin_embedder_)
5111 return;
5112 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
5113}
5114
[email protected]fc2b46b2014-05-03 16:33:455115gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:215116 gfx::Size size;
5117 if (delegate_)
5118 size = delegate_->GetSizeForNewRenderView(this);
5119 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:455120 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:215121 return size;
5122}
5123
[email protected]ae7eeda2014-07-04 01:53:265124void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
5125 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:025126 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:555127}
5128
[email protected]222f5822014-02-05 23:40:495129void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
5130 if (!delegate_)
5131 return;
5132 const gfx::Size new_size = GetPreferredSize();
5133 if (new_size != old_size)
5134 delegate_->UpdatePreferredSize(this, new_size);
5135}
5136
dbeama1b926a2015-08-31 23:17:515137WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
5138 const std::string& frame_name) {
5139 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
5140 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
5141 CreateWebUIControllerForURL(web_ui, url);
5142 if (controller) {
5143 web_ui->AddMessageHandler(new GenericHandler());
5144 web_ui->SetController(controller);
5145 return web_ui;
5146 }
5147
5148 delete web_ui;
5149 return NULL;
5150}
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(
5217 const WebContentsObserver::MediaPlayerId& id) {
5218 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
5219}
5220
5221void WebContentsImpl::MediaStoppedPlaying(
5222 const WebContentsObserver::MediaPlayerId& id) {
5223 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
5224}
5225
tapted65ff2ea72016-03-01 23:39:005226void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
5227 if (!did_first_set_visible_) {
5228 // If this WebContents has not yet been set to be visible for the first
5229 // time, ignore any requests to make it hidden, since resources would
5230 // immediately be destroyed and only re-created after content loaded. In
5231 // this state the window content is undefined and can show garbage.
5232 // However, the page load mechanism requires an activation call through a
5233 // visibility call to (re)load.
5234 if (visible) {
5235 did_first_set_visible_ = true;
5236 WasShown();
5237 }
5238 return;
5239 }
5240 if (visible == should_normally_be_visible_)
5241 return;
5242
5243 if (visible)
5244 WasShown();
5245 else
5246 WasHidden();
5247}
5248
aelias5252baa2016-04-10 01:18:025249void WebContentsImpl::UpdateOverridingUserAgent() {
5250 std::set<RenderViewHost*> render_view_host_set;
5251 for (FrameTreeNode* node : frame_tree_.Nodes()) {
5252 RenderWidgetHost* render_widget_host =
5253 node->current_frame_host()->GetRenderWidgetHost();
5254 if (!render_widget_host)
5255 continue;
5256 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5257 if (!render_view_host)
5258 continue;
5259 render_view_host_set.insert(render_view_host);
5260 }
5261 for (RenderViewHost* render_view_host : render_view_host_set)
5262 render_view_host->OnWebkitPreferencesChanged();
5263}
5264
avid53461d2016-02-25 17:15:045265void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5266 JavaScriptDialogManager* dialog_manager) {
5267 dialog_manager_ = dialog_manager;
5268}
5269
rockotf62002a2016-09-15 00:08:595270void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) {
5271 auto it = binding_sets_.find(interface_name);
5272 if (it != binding_sets_.end())
5273 binding_sets_.erase(it);
5274}
5275
[email protected]8ff00d72012-10-23 19:12:215276} // namespace content