blob: 9b709d85dc1f3e7cf690350be803b180be80fb51 [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
[email protected]2bb171882012-03-07 02:09:469#include <utility>
[email protected]b75b8292010-10-01 07:28:2510
[email protected]36fb2c7c2011-04-04 15:49:0811#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4612#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0713#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5614#include "base/logging.h"
avib7348942015-12-25 20:57:1015#include "base/macros.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2017#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2218#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0719#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5120#include "base/strings/string16.h"
21#include "base/strings/string_number_conversions.h"
22#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0023#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0724#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3725#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4226#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1027#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2528#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2129#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3030#include "content/browser/accessibility/accessibility_mode_helper.h"
31#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1832#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3933#include "content/browser/browser_plugin/browser_plugin_embedder.h"
34#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5935#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4136#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0437#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4638#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1239#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1640#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1641#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4042#include "content/browser/frame_host/interstitial_page_impl.h"
43#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3344#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0145#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1846#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1647#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5748#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0549#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4450#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4051#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3052#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5253#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1854#include "content/browser/media/media_web_contents_observer.h"
[email protected]0bc7f3542013-10-21 15:05:5355#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0956#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3057#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5058#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3259#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5060#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5961#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4862#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0963#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3364#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1265#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1166#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5867#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0368#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5669#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1470#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4271#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4472#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1773#include "content/common/input_messages.h"
avi286019ce2015-07-29 01:26:5874#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5175#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0276#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3677#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1178#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2879#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4480#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3681#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1782#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1483#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4684#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1585#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0086#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2787#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0088#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3789#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1490#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3091#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3292#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0993#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1294#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3495#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3896#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4297#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:2198#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:0899#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35100#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48101#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54102#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49103#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20104#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01105#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03106#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57107#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05108#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40109#include "mojo/common/url_type_converters.h"
110#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53111#include "net/http/http_cache.h"
112#include "net/http/http_transaction_factory.h"
113#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34114#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40115#include "skia/public/type_converters.h"
116#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56117#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01118#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41119#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52120#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31121
[email protected]583418cc2013-01-17 14:01:10122#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40123#include "content/browser/android/content_video_view.h"
avayvod41634b12015-07-08 17:07:05124#include "content/browser/media/android/media_session.h"
mfomitchev841f8182015-11-07 02:03:19125#endif // OS_ANDROID
126
127#if defined(OS_ANDROID) && !defined(USE_AURA)
128#include "content/browser/android/date_time_chooser_android.h"
[email protected]155c7f22013-12-09 17:07:18129#include "content/browser/web_contents/web_contents_android.h"
mfomitchev841f8182015-11-07 02:03:19130#endif // OS_ANDROID && !USE_AURA
[email protected]583418cc2013-01-17 14:01:10131
[email protected]f66df822012-05-18 16:52:17132#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50133#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57134#endif
[email protected]3e45ba92009-02-20 21:09:00135
fsamuel9cf7bdf2015-11-20 02:19:32136#if defined(MOJO_SHELL_CLIENT)
137#include "content/browser/web_contents/web_contents_view_mus.h"
138#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46139#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32140#endif
141
[email protected]8ff00d72012-10-23 19:12:21142namespace content {
[email protected]420ae012009-04-24 05:16:32143namespace {
144
[email protected]960b0372014-05-19 18:01:00145const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41146const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05147
[email protected]155c7f22013-12-09 17:07:18148#if defined(OS_ANDROID)
149const char kWebContentsAndroidKey[] = "web_contents_android";
150#endif // OS_ANDROID
151
[email protected]e4abd3b42013-11-12 18:28:47152base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46153g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
154
halton.huoca2eabd2015-07-06 08:17:40155static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
156 int id,
157 const GURL& image_url,
158 image_downloader::DownloadResultPtr result) {
159 DCHECK(result);
160
161 const std::vector<SkBitmap> images =
162 result->images.To<std::vector<SkBitmap>>();
163 const std::vector<gfx::Size> original_image_sizes =
164 result->original_image_sizes.To<std::vector<gfx::Size>>();
165
166 callback.Run(id, result->http_status_code, image_url, images,
167 original_image_sizes);
[email protected]795c28972012-12-06 06:13:39168}
169
[email protected]8bfc8272013-09-09 20:10:53170void NotifyCacheOnIO(
171 scoped_refptr<net::URLRequestContextGetter> request_context,
172 const GURL& url,
173 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58174 net::HttpCache* cache = request_context->GetURLRequestContext()->
175 http_transaction_factory()->GetCache();
176 if (cache)
177 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53178}
179
alexmos4cf2aa32015-07-15 23:40:43180bool FindMatchingProcess(int render_process_id,
181 bool* did_match_process,
182 FrameTreeNode* node) {
183 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) {
184 *did_match_process = true;
185 return false;
186 }
187 return true;
188}
189
[email protected]a86c0e962013-12-17 17:10:39190bool ForEachFrameInternal(
191 const base::Callback<void(RenderFrameHost*)>& on_frame,
192 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41193 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39194 return true;
195}
196
[email protected]95640212014-07-26 18:14:30197bool ForEachPendingFrameInternal(
198 const base::Callback<void(RenderFrameHost*)>& on_frame,
199 FrameTreeNode* node) {
200 RenderFrameHost* pending_frame_host =
201 node->render_manager()->pending_frame_host();
202 if (pending_frame_host)
203 on_frame.Run(pending_frame_host);
204 return true;
205}
206
[email protected]a86c0e962013-12-17 17:10:39207void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
208 IPC::Message* message_copy = new IPC::Message(*message);
209 message_copy->set_routing_id(rfh->GetRoutingID());
210 rfh->Send(message_copy);
211}
212
[email protected]948481d2014-06-11 18:32:22213void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
214 RenderFrameHost* rfh) {
215 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
216 ->frame_tree_node()
217 ->render_manager()
218 ->GetRenderWidgetHostView();
219 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59220}
221
[email protected]95640212014-07-26 18:14:30222void SetAccessibilityModeOnFrame(AccessibilityMode mode,
223 RenderFrameHost* frame_host) {
224 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
225}
226
dtseng0dd3fa12015-07-22 19:00:52227void ResetAccessibility(RenderFrameHost* rfh) {
228 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
229}
230
[email protected]420ae012009-04-24 05:16:32231} // namespace
232
[email protected]54944cde2012-12-09 09:24:59233WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21234 FrameTreeNode* opener_node = nullptr;
235 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
236 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
237 params.opener_render_process_id, params.opener_render_frame_id);
238 if (opener_rfh)
239 opener_node = opener_rfh->frame_tree_node();
240 }
241 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19242}
243
244WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59245 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30246 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21247 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30248
249 for (SessionStorageNamespaceMap::const_iterator it =
250 session_storage_namespace_map.begin();
251 it != session_storage_namespace_map.end();
252 ++it) {
253 new_contents->GetController()
254 .SetSessionStorageNamespace(it->first, it->second.get());
255 }
256
[email protected]54944cde2012-12-09 09:24:59257 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19258 return new_contents;
[email protected]a81343d232011-12-27 07:39:20259}
[email protected]746d3052012-05-22 15:15:47260
nickf9acfbe2014-12-23 19:12:37261void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
262 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46263 g_created_callbacks.Get().push_back(callback);
264}
265
nickf9acfbe2014-12-23 19:12:37266void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
267 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46268 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
269 if (g_created_callbacks.Get().at(i).Equals(callback)) {
270 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
271 return;
272 }
273 }
274}
275
avidf38c952015-10-27 13:45:13276WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
277 if (!rvh)
278 return nullptr;
[email protected]746d3052012-05-22 15:15:47279 return rvh->GetDelegate()->GetAsWebContents();
280}
281
[email protected]a86c0e962013-12-17 17:10:39282WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13283 if (!rfh)
284 return nullptr;
285 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39286}
287
[email protected]7fff43e2013-05-21 20:21:10288// WebContentsImpl::DestructionObserver ----------------------------------------
289
290class WebContentsImpl::DestructionObserver : public WebContentsObserver {
291 public:
292 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
293 : WebContentsObserver(watched_contents),
294 owner_(owner) {
295 }
296
297 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58298 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58299 owner_->OnWebContentsDestroyed(
300 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10301 }
302
303 private:
304 WebContentsImpl* owner_;
305
306 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
307};
308
[email protected]8ed16472014-04-11 19:02:48309WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
310 int render_frame_id,
311 ColorChooser* chooser,
312 int identifier)
313 : render_process_id(render_process_id),
314 render_frame_id(render_frame_id),
315 chooser(chooser),
316 identifier(identifier) {
317}
318
319WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
320}
321
lazyboy6ec48b2a2015-06-29 15:18:14322// WebContentsImpl::WebContentsTreeNode ----------------------------------------
323WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
324 : outer_web_contents_(nullptr),
325 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37326 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14327}
328
329WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
330 // Remove child pointer from our parent.
331 if (outer_web_contents_) {
332 ChildrenSet& child_ptrs_in_parent =
333 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
334 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
335 DCHECK(iter != child_ptrs_in_parent.end());
336 child_ptrs_in_parent.erase(this);
337 }
338
339 // Remove parent pointers from our children.
340 // TODO(lazyboy): We should destroy the children WebContentses too. If the
341 // children do not manage their own lifetime, then we would leak their
342 // WebContentses.
343 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
344 child->outer_web_contents_ = nullptr;
345}
346
347void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
348 WebContentsImpl* outer_web_contents,
349 RenderFrameHostImpl* outer_contents_frame) {
350 outer_web_contents_ = outer_web_contents;
351 outer_contents_frame_tree_node_id_ =
352 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
353
354 if (!outer_web_contents_->node_)
355 outer_web_contents_->node_.reset(new WebContentsTreeNode());
356
357 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
358}
359
[email protected]b172aee2012-04-10 17:05:26360// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32361
alexmose201c7cd2015-06-10 17:14:21362WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42363 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22364 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57365 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21366 created_with_opener_(false),
[email protected]2ceee8f2014-01-14 18:02:08367#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41368 accessible_parent_(NULL),
369#endif
[email protected]6ea6bdf2013-12-06 13:35:01370 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57371 this,
372 this,
373 this,
374 this),
[email protected]d5f942ba2008-09-26 19:30:34375 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03376 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23377 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
378 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34379 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26380 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56381 upload_size_(0),
382 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16383 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47384 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10385 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28386 theme_color_(SK_ColorTRANSPARENT),
387 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29388 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55389 capturer_count_(0),
390 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57391 is_being_destroyed_(false),
392 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15393 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01394 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39395 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38396 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21397 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
398 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44399 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55400 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42401 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03402 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49403 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05404 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30405 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57406 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30407 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30408 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15409 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50410 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46411 page_scale_factor_is_one_(true),
mohan.reddy371ad9142014-09-17 08:01:46412 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55413 frame_tree_.SetFrameRemoveListener(
414 base::Bind(&WebContentsImpl::OnFrameRemoved,
415 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20416 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
alogvinovf50445a2015-10-30 13:00:12417 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35418}
initial.commit09911bf2008-07-26 23:55:29419
[email protected]b172aee2012-04-10 17:05:26420WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32421 is_being_destroyed_ = true;
422
kenrb2a565f82015-09-02 20:24:59423 rwh_input_event_router_.reset();
424
[email protected]21b41c7e892014-02-28 01:52:24425 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
426 // shutdown and be deleted as well.
427 frame_tree_.ForEach(
428 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
429
carlosk35f35af2015-12-01 10:55:40430 // Destroy all WebUI instances.
431 frame_tree_.ForEach(base::Bind(&RenderFrameHostManager::ClearWebUIInstances));
432
[email protected]b24b68a2012-09-24 21:57:26433 for (std::set<RenderWidgetHostImpl*>::iterator iter =
434 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
435 (*iter)->DetachDelegate();
436 }
437 created_widgets_.clear();
438
[email protected]3ab9cb82011-06-03 18:02:07439 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15440 if (dialog_manager_)
avi2460c762015-04-17 15:21:54441 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07442
[email protected]8ed16472014-04-11 19:02:48443 if (color_chooser_info_.get())
444 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20445
[email protected]420ae012009-04-24 05:16:32446 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32447
[email protected]ca13a442012-04-17 14:00:12448 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21449 NotificationService::current()->Notify(
450 NOTIFICATION_WEB_CONTENTS_DESTROYED,
451 Source<WebContents>(this),
452 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32453
[email protected]df0c843f2014-05-23 20:37:23454 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14455 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23456 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59457
clamy0e119882015-07-31 16:12:33458 // Manually call the observer methods for the root frame tree node. It is
459 // necessary to manually delete all objects tracking navigations
460 // (NavigationHandle, NavigationRequest) for observers to be properly
461 // notified of these navigations stopping before the WebContents is
462 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23463 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56464
clamy0e119882015-07-31 16:12:33465 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56466 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33467 root->pending_frame_host()->SetNavigationHandle(
468 scoped_ptr<NavigationHandleImpl>());
469 }
naskob21fe4872015-02-24 14:15:56470 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33471 root->current_frame_host()->SetNavigationHandle(
472 scoped_ptr<NavigationHandleImpl>());
473
474 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35475 if (IsBrowserSideNavigationEnabled()) {
clamy0e119882015-07-31 16:12:33476 frame_tree_.root()->ResetNavigationRequest(false);
477 if (root->speculative_frame_host()) {
478 root->speculative_frame_host()->SetRenderFrameCreated(false);
479 root->speculative_frame_host()->SetNavigationHandle(
480 scoped_ptr<NavigationHandleImpl>());
481 }
482 }
[email protected]f273ee52013-10-18 16:05:27483
naskoa83483fb2015-02-27 16:57:10484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
485 FrameDeleted(root->current_frame_host()));
486
[email protected]df0c843f2014-05-23 20:37:23487 if (root->pending_render_view_host()) {
488 FOR_EACH_OBSERVER(WebContentsObserver,
489 observers_,
490 RenderViewDeleted(root->pending_render_view_host()));
491 }
[email protected]c06c58c2014-03-12 20:31:59492
[email protected]f273ee52013-10-18 16:05:27493 FOR_EACH_OBSERVER(WebContentsObserver,
494 observers_,
[email protected]df0c843f2014-05-23 20:37:23495 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27496
[email protected]2db9bd72012-04-13 20:20:56497 FOR_EACH_OBSERVER(WebContentsObserver,
498 observers_,
[email protected]12a46832014-05-09 13:35:58499 WebContentsDestroyed());
500
501 FOR_EACH_OBSERVER(WebContentsObserver,
502 observers_,
503 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08504
[email protected]6934a702011-12-20 00:04:51505 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10506
507 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
508 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42509}
510
[email protected]d1198fd2012-08-13 22:50:19511WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59512 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21513 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03514 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21515 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19516
alexmose201c7cd2015-06-10 17:14:21517 if (!params.opener_suppressed && opener) {
518 new_contents->GetFrameTree()->root()->SetOpener(opener);
519 new_contents->created_with_opener_ = true;
520 }
521
522 // This may be true even when opener is null, such as when opening blocked
523 // popups.
alexmos090fae8e2015-05-28 17:09:28524 if (params.created_with_opener)
525 new_contents->created_with_opener_ = true;
526
[email protected]4858e432014-06-23 18:14:17527 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06528 // This makes |new_contents| act as a guest.
529 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16530 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06531 // We are instantiating a WebContents for browser plugin. Set its subframe
532 // bit to true.
533 new_contents->is_subframe_ = true;
534 }
[email protected]54944cde2012-12-09 09:24:59535 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19536 return new_contents;
537}
538
[email protected]95640212014-07-26 18:14:30539// static
540std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
541 std::vector<WebContentsImpl*> result;
542 scoped_ptr<RenderWidgetHostIterator> widgets(
543 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30544 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30545 RenderViewHost* rvh = RenderViewHost::From(rwh);
546 if (!rvh)
547 continue;
548 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
549 if (!web_contents)
550 continue;
avidf38c952015-10-27 13:45:13551 if (web_contents->GetRenderViewHost() != rvh)
552 continue;
553 // Because a WebContents can only have one current RVH at a time, there will
554 // be no duplicate WebContents here.
555 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30556 }
557 return result;
558}
559
clamya16aa8172015-05-26 13:07:25560// static
561WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
562 FrameTreeNode* frame_tree_node) {
563 return static_cast<WebContentsImpl*>(
564 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
565}
566
clamy0d32d6d2015-11-24 11:16:26567// static
568WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
569 int render_frame_host_id) {
570 DCHECK_CURRENTLY_ON(BrowserThread::UI);
571 RenderFrameHost* render_frame_host =
572 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
573 if (!render_frame_host)
574 return nullptr;
575
576 return WebContents::FromRenderFrameHost(render_frame_host);
577}
578
[email protected]b0936d22013-11-28 06:47:36579RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21580 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28581}
582
[email protected]7bb761892012-07-20 09:32:47583bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
584 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44585 return OnMessageReceived(render_view_host, NULL, message);
586}
587
588bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
589 RenderFrameHost* render_frame_host,
590 const IPC::Message& message) {
591 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56592 if (GetWebUI() &&
593 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17594 return true;
[email protected]d2353452012-01-19 19:53:56595 }
[email protected]f82d57b52011-04-27 19:13:17596
brettw5a1613dc2015-06-02 05:34:43597 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25598 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33599 if (render_frame_host) {
600 while ((observer = it.GetNext()) != NULL)
601 if (observer->OnMessageReceived(message, render_frame_host))
602 return true;
603 } else {
604 while ((observer = it.GetNext()) != NULL)
605 if (observer->OnMessageReceived(message))
606 return true;
607 }
[email protected]403415a2011-01-10 18:57:53608
[email protected]1d62cf72014-02-07 21:31:57609 // Message handlers should be aware of which
610 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
611 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02612 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57613 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02614 else
[email protected]1d62cf72014-02-07 21:31:57615 render_view_message_source_ = render_view_host;
616
[email protected]724159a2010-12-30 01:11:18617 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33618 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40619 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
620 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05621 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
622 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48623 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
624 OnDocumentLoadedInFrame)
625 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
626 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
627 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
628 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
629 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18630
dglazkov79c426102015-08-31 21:22:43631 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11632 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25633 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18634 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54635 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18636 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54637 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18638 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41639 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
640 OnDidDisplayContentWithCertificateErrors)
641 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
642 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25643 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26644 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46645 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
646 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21647 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48648 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
649 OnRegisterProtocolHandler)
650 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
651 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01652 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
653 OnUpdatePageImportanceSignals)
[email protected]b888919c2011-09-02 00:32:16654 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10655 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50656 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50657#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00658 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
659 OnPepperInstanceCreated)
660 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
661 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42662 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
663 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50664 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
665 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55666 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40667 OnBrowserPluginMessage(render_frame_host,
668 message))
thestigc4cac8f2014-09-04 21:17:50669#endif
[email protected]41225fe2013-03-29 05:32:02670 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07671 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
672 OnShowValidationMessage)
673 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
674 OnHideValidationMessage)
675 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
676 OnMoveValidationMessage)
mfomitchev841f8182015-11-07 02:03:19677#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]8ed16472014-04-11 19:02:48678 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
679 OnFindMatchRectsReply)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
681 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48682#endif
[email protected]724159a2010-12-30 01:11:18683 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33684 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44685 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57686 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18687
[email protected]724159a2010-12-30 01:11:18688 return handled;
689}
690
nasko907fcb62015-01-28 04:24:11691bool WebContentsImpl::HasValidFrameSource() {
692 if (!render_frame_message_source_) {
693 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18694 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
695 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11696 return false;
697 }
698
699 return true;
700}
701
[email protected]b172aee2012-04-10 17:05:26702void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18703 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21704 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43705 if (delegate_)
706 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18707}
708
[email protected]d1198fd2012-08-13 22:50:19709NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56710 return controller_;
711}
712
[email protected]d1198fd2012-08-13 22:50:19713const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56714 return controller_;
715}
716
[email protected]8ff00d72012-10-23 19:12:21717BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55718 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30719}
720
[email protected]b172aee2012-04-10 17:05:26721const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24722 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32723 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51724 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31725}
726
[email protected]a093ce02013-07-22 20:53:14727const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24728 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32729 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24730 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
731}
732
733const GURL& WebContentsImpl::GetLastCommittedURL() const {
734 // We may not have a navigation entry yet.
735 NavigationEntry* entry = controller_.GetLastCommittedEntry();
736 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
737}
738
[email protected]8ff00d72012-10-23 19:12:21739WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31740 return delegate_;
741}
742
[email protected]8ff00d72012-10-23 19:12:21743void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31744 // TODO(cbentzel): remove this debugging code?
745 if (delegate == delegate_)
746 return;
747 if (delegate_)
748 delegate_->Detach(this);
749 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08750 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31751 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08752 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00753 if (view_)
[email protected]e85165c642014-06-10 14:34:31754 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08755 }
[email protected]be1f56ab2011-12-22 06:55:31756}
757
[email protected]8ff00d72012-10-23 19:12:21758RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21759 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41760 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16761}
762
clamydf1975e2015-02-05 19:12:24763RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41764 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16765}
766
nick53d5cbf2015-04-23 22:50:14767RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
768 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
769 if (!focused_node)
770 return nullptr;
771 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07772}
773
[email protected]a86c0e962013-12-17 17:10:39774void WebContentsImpl::ForEachFrame(
775 const base::Callback<void(RenderFrameHost*)>& on_frame) {
776 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
777}
778
779void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
780 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
781 delete message;
782}
783
creisc014b402015-04-23 16:41:45784RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21785 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31786}
787
[email protected]6b618e62012-08-16 12:59:18788int WebContentsImpl::GetRoutingID() const {
789 if (!GetRenderViewHost())
790 return MSG_ROUTING_NONE;
791
792 return GetRenderViewHost()->GetRoutingID();
793}
794
creis89a0f782015-05-27 16:13:17795void WebContentsImpl::CancelActiveAndPendingDialogs() {
796 if (dialog_manager_)
797 dialog_manager_->CancelActiveAndPendingDialogs(this);
798 if (browser_plugin_embedder_)
799 browser_plugin_embedder_->CancelGuestDialogs();
800}
801
[email protected]44470a22013-01-24 01:21:54802int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
803 return fullscreen_widget_routing_id_;
804}
805
naskoc0fceff2015-04-30 15:53:52806void WebContentsImpl::ClosePage() {
807 GetRenderViewHost()->ClosePage();
808}
809
[email protected]b172aee2012-04-10 17:05:26810RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21811 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31812}
813
[email protected]4aebbca2013-09-17 22:26:49814RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
815 const {
816 RenderWidgetHost* const widget_host =
817 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
818 GetFullscreenWidgetRoutingID());
819 return widget_host ? widget_host->GetView() : NULL;
820}
821
[email protected]8ff00d72012-10-23 19:12:21822WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31823 return view_.get();
824}
825
yusufod41c5f92015-03-06 00:14:28826SkColor WebContentsImpl::GetThemeColor() const {
827 return theme_color_;
828}
829
[email protected]95640212014-07-26 18:14:30830void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
831 if (mode == accessibility_mode_)
832 return;
833
834 accessibility_mode_ = mode;
835 frame_tree_.ForEach(
836 base::Bind(&ForEachFrameInternal,
837 base::Bind(&SetAccessibilityModeOnFrame, mode)));
838 frame_tree_.ForEach(
839 base::Bind(&ForEachPendingFrameInternal,
840 base::Bind(&SetAccessibilityModeOnFrame, mode)));
841}
842
843void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50844 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30845}
846
847void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50848 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30849}
850
dmazzoni83ba5c82015-04-14 07:11:51851void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
852 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
853 // accessibility tree from the main frame and everything in the
854 // same site instance.
855 GetMainFrame()->RequestAXTreeSnapshot(callback);
856}
857
dbeama1b926a2015-08-31 23:17:51858WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
859 const std::string& frame_name) {
860 DCHECK(!frame_name.empty());
861 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22862}
863
[email protected]8ff00d72012-10-23 19:12:21864WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40865 WebUI* commited_web_ui = GetCommittedWebUI();
866 return commited_web_ui ? commited_web_ui
867 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31868}
869
[email protected]8ff00d72012-10-23 19:12:21870WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40871 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34872}
873
[email protected]86ef6a392012-05-11 22:03:11874void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22875 if (GetUserAgentOverride() == override)
876 return;
877
878 renderer_preferences_.user_agent_override = override;
879
880 // Send the new override string to the renderer.
881 RenderViewHost* host = GetRenderViewHost();
882 if (host)
883 host->SyncRendererPrefs();
884
885 // Reload the page if a load is currently in progress to avoid having
886 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27887 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22888 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
889 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53890
891 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
892 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11893}
894
895const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22896 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11897}
898
[email protected]95640212014-07-26 18:14:30899void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dtseng01e634a2015-11-19 01:48:24900 if (GetAccessibilityMode() != AccessibilityModeOff)
dtseng0dd3fa12015-07-22 19:00:52901 ForEachFrame(base::Bind(&ResetAccessibility));
902 else
903 AddAccessibilityMode(AccessibilityModeTreeOnly);
[email protected]95640212014-07-26 18:14:30904}
905
906bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
907 return accessibility_mode_ == AccessibilityModeTreeOnly;
908}
909
910bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
911 return accessibility_mode_ == AccessibilityModeComplete;
912}
913
[email protected]2ceee8f2014-01-14 18:02:08914#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41915void WebContentsImpl::SetParentNativeViewAccessible(
916gfx::NativeViewAccessible accessible_parent) {
917 accessible_parent_ = accessible_parent;
creisc014b402015-04-23 16:41:45918 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30919 if (rfh)
920 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41921}
922#endif
923
kouhei40f03cb2015-09-24 07:47:01924const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
925 return page_importance_signals_;
926}
927
[email protected]fcf75d42013-12-03 20:11:26928const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55929 // Transient entries take precedence. They are used for interstitial pages
930 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23931 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08932 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21933 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30934 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23935 if (entry) {
[email protected]b5cca982011-05-26 04:42:08936 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23937 }
carlosk35f35af2015-12-01 10:55:40938
939 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
940 WebUI* our_web_ui = navigating_web_ui
941 ? navigating_web_ui
942 : GetRenderManager()->current_frame_host()->web_ui();
943
[email protected]7ade2732011-02-10 00:13:58944 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54945 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32946 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54947 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35948 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26949 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54950 if (!title.empty())
951 return title;
952 }
953 }
954
955 // We use the title for the last committed entry rather than a pending
956 // navigation entry. For example, when the user types in a URL, we want to
957 // keep the old page's title until the new load has committed and we get a new
958 // title.
[email protected]96d185d2009-04-24 03:28:54959 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32960
creis072b61f2015-09-28 20:52:24961 // We make an exception for initial navigations. We only want to use the title
962 // from the visible entry if:
963 // 1. The pending entry has been explicitly assigned a title to display.
964 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
965 // which case there is a pending entry index other than -1.
966 //
967 // Otherwise, we want to stick with the last committed entry's title during
968 // new navigations, which have pending entries at index -1 with no title.
969 if (controller_.IsInitialNavigation() &&
970 ((controller_.GetVisibleEntry() &&
971 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
972 controller_.GetPendingEntryIndex() != -1)) {
973 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47974 }
[email protected]59167c22013-06-03 18:07:32975
[email protected]45d0ef7f2011-01-05 13:46:23976 if (entry) {
[email protected]b5cca982011-05-26 04:42:08977 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23978 }
[email protected]987fc3a2011-05-26 14:18:09979
980 // |page_title_when_no_navigation_entry_| is finally used
981 // if no title cannot be retrieved.
982 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54983}
984
avib7348942015-12-25 20:57:10985int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46986 return GetMaxPageIDForSiteInstance(GetSiteInstance());
987}
988
avib7348942015-12-25 20:57:10989int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:26990 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33991 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
992 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46993
[email protected]b6583592012-01-25 19:52:33994 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34995}
996
avib7348942015-12-25 20:57:10997void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:46998 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101002 SiteInstance* site_instance,
1003 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461004 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331005 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341006}
1007
[email protected]ec6c05f2013-10-23 18:41:571008void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1009 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1010 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571011}
1012
creiscce56cd2014-09-29 22:45:221013SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211014 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541015}
1016
creiscce56cd2014-09-29 22:45:221017SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1018 RenderViewHostImpl* dest_rvh =
1019 GetRenderManager()->pending_render_view_host() ?
1020 GetRenderManager()->pending_render_view_host() :
1021 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581022 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381023}
1024
[email protected]b172aee2012-04-10 17:05:261025bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:311026 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:491027}
1028
[email protected]6dfed692014-05-22 04:18:031029bool WebContentsImpl::IsLoadingToDifferentDocument() const {
1030 return is_loading_ && is_load_to_different_document_;
1031}
1032
[email protected]b172aee2012-04-10 17:05:261033bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031034 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311035}
1036
[email protected]b172aee2012-04-10 17:05:261037const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311038 return load_state_;
1039}
1040
[email protected]fcf75d42013-12-03 20:11:261041const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311042 return load_state_host_;
1043}
1044
avib7348942015-12-25 20:57:101045uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311046 return upload_size_;
1047}
1048
avib7348942015-12-25 20:57:101049uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311050 return upload_position_;
1051}
1052
[email protected]b172aee2012-04-10 17:05:261053const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541054 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311055}
1056
[email protected]b172aee2012-04-10 17:05:261057bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311058 return displayed_insecure_content_;
1059}
1060
[email protected]222f5822014-02-05 23:40:491061void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251062 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551063 ++capturer_count_;
1064 DVLOG(1) << "There are now " << capturer_count_
1065 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491066
1067 // Note: This provides a hint to upstream code to size the views optimally
1068 // for quality (e.g., to avoid scaling).
1069 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1070 preferred_size_for_capture_ = capture_size;
1071 OnPreferredSizeChanged(preferred_size_);
1072 }
ccameron8807c38f2015-01-17 00:29:191073
1074 // Ensure that all views are un-occluded before capture begins.
1075 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551076}
1077
1078void WebContentsImpl::DecrementCapturerCount() {
1079 --capturer_count_;
1080 DVLOG(1) << "There are now " << capturer_count_
1081 << " capturing(s) of WebContentsImpl@" << this;
1082 DCHECK_LE(0, capturer_count_);
1083
[email protected]5a652232013-02-12 06:15:251084 if (is_being_destroyed_)
1085 return;
1086
[email protected]222f5822014-02-05 23:40:491087 if (capturer_count_ == 0) {
1088 const gfx::Size old_size = preferred_size_for_capture_;
1089 preferred_size_for_capture_ = gfx::Size();
1090 OnPreferredSizeChanged(old_size);
1091 }
1092
[email protected]1ac10dca2013-08-20 20:47:041093 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551094 DVLOG(1) << "Executing delayed WasHidden().";
1095 WasHidden();
1096 }
[email protected]be1f56ab2011-12-22 06:55:311097}
1098
[email protected]f2bd40812013-07-20 04:30:441099int WebContentsImpl::GetCapturerCount() const {
1100 return capturer_count_;
1101}
1102
miu50f97892014-09-22 22:49:521103bool WebContentsImpl::IsAudioMuted() const {
1104 return audio_muter_.get() && audio_muter_->is_muting();
1105}
1106
1107void WebContentsImpl::SetAudioMuted(bool mute) {
1108 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1109 << " for WebContentsImpl@" << this;
1110
1111 if (mute == IsAudioMuted())
1112 return;
1113
1114 if (mute) {
1115 if (!audio_muter_)
1116 audio_muter_.reset(new WebContentsAudioMuter(this));
1117 audio_muter_->StartMuting();
1118 } else {
1119 DCHECK(audio_muter_);
1120 audio_muter_->StopMuting();
1121 }
1122
1123 // Notification for UI updates in response to the changed muting state.
1124 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1125}
1126
[email protected]b172aee2012-04-10 17:05:261127bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311128 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1129 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581130 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271131#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581132 crashed_status_ ==
1133 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271134#endif
wfh0d9532a2015-09-02 23:18:581135 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271136 );
[email protected]3c9e1872010-11-18 16:17:491137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1140 int error_code) {
[email protected]443b80e2010-12-14 00:42:231141 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341142 return;
1143
[email protected]443b80e2010-12-14 00:42:231144 crashed_status_ = status;
1145 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211146 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341147}
1148
[email protected]b172aee2012-04-10 17:05:261149base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311150 return crashed_status_;
1151}
1152
[email protected]b172aee2012-04-10 17:05:261153bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311154 return is_being_destroyed_;
1155}
1156
[email protected]7f924832014-08-09 05:57:221157void WebContentsImpl::NotifyNavigationStateChanged(
1158 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541159 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1160 // is fixed.
1161 tracked_objects::ScopedTracker tracking_profile(
1162 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1163 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181164 // Notify the media observer of potential audibility changes.
1165 if (changed_flags & INVALIDATE_TYPE_TAB) {
1166 media_web_contents_observer_->MaybeUpdateAudibleState(
1167 AudioStreamMonitor::monitoring_available() && WasRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:301168 }
1169
[email protected]d5f942ba2008-09-26 19:30:341170 if (delegate_)
1171 delegate_->NavigationStateChanged(this, changed_flags);
1172}
1173
gab0dccfef2015-05-20 18:43:391174base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021175 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331176}
1177
georgesak5582cbe2015-05-22 22:08:071178void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1179 last_active_time_ = last_active_time;
1180}
1181
[email protected]9e2e4632012-07-27 16:38:411182void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541183 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591184
ccameron8807c38f2015-01-17 00:29:191185 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1186 if (view) {
1187 view->Show();
[email protected]789e9152009-08-04 21:59:431188#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191189 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431190#endif
[email protected]de3c5d82014-05-28 22:12:591191 }
[email protected]789e9152009-08-04 21:59:431192 }
[email protected]96d185d2009-04-24 03:28:541193
gab0dccfef2015-05-20 18:43:391194 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381195
[email protected]b9769d82012-02-10 00:23:591196 // The resize rect might have changed while this was inactive -- send the new
1197 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451198 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221199 if (rvh) {
1200 rvh->GetWidget()->ResizeRectChanged(
1201 GetRootWindowResizerRect(rvh->GetWidget()));
1202 }
[email protected]96d185d2009-04-24 03:28:541203
[email protected]c0d9d5672013-10-09 07:38:031204 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1205
[email protected]54597982013-02-06 01:59:551206 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311207}
1208
[email protected]b172aee2012-04-10 17:05:261209void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551210 // If there are entities capturing screenshots or video (e.g., mirroring),
1211 // don't activate the "disable rendering" optimization.
1212 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521213 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551214 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261215 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521216 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331217 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521218 // calls us).
ccameron8807c38f2015-01-17 00:29:191219 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1220 if (view)
1221 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591222 }
[email protected]96d185d2009-04-24 03:28:541223 }
1224
[email protected]c0d9d5672013-10-09 07:38:031225 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1226
[email protected]54597982013-02-06 01:59:551227 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371228}
1229
ccameron8807c38f2015-01-17 00:29:191230void WebContentsImpl::WasOccluded() {
1231 if (capturer_count_ > 0)
1232 return;
1233
1234 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1235 if (view)
1236 view->WasOccluded();
1237 }
1238}
1239
1240void WebContentsImpl::WasUnOccluded() {
1241 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1242 if (view)
1243 view->WasUnOccluded();
1244 }
1245}
1246
[email protected]b172aee2012-04-10 17:05:261247bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311248 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451249 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1250 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311251}
1252
[email protected]1c3f80bd2014-04-08 23:02:061253void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451254 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061255}
1256
lazyboy6ec48b2a2015-06-29 15:18:141257void WebContentsImpl::AttachToOuterWebContentsFrame(
1258 WebContents* outer_web_contents,
1259 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081260 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141261 // Create a link to our outer WebContents.
1262 node_.reset(new WebContentsTreeNode());
1263 node_->ConnectToOuterWebContents(
1264 static_cast<WebContentsImpl*>(outer_web_contents),
1265 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1266
1267 DCHECK(outer_contents_frame);
1268
1269 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1270 // SiteInstance of the outer WebContents. The proxy will be used to send
1271 // postMessage to the inner WebContents.
1272 GetRenderManager()->CreateOuterDelegateProxy(
1273 outer_contents_frame->GetSiteInstance(),
1274 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1275
1276 GetRenderManager()->SetRWHViewForInnerContents(
1277 GetRenderManager()->GetRenderWidgetHostView());
1278}
1279
[email protected]b172aee2012-04-10 17:05:261280void WebContentsImpl::Stop() {
clamyf73862c42015-07-08 12:31:331281 frame_tree_.ForEach(base::Bind(&FrameTreeNode::StopLoading));
[email protected]d16609c2013-08-23 06:01:401282 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271283}
1284
[email protected]b172aee2012-04-10 17:05:261285WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441286 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211287 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451288 // before.
[email protected]54944cde2012-12-09 09:24:591289 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451290 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211291 WebContentsImpl* tc =
1292 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191293 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221294 FOR_EACH_OBSERVER(WebContentsObserver,
1295 observers_,
1296 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271297 return tc;
1298}
1299
[email protected]14392a52012-05-02 20:28:441300void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211301 const NotificationSource& source,
1302 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441303 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211304 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1305 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031306 RenderWidgetHostView* view = host->GetView();
1307 if (view == GetFullscreenRenderWidgetHostView()) {
1308 // We cannot just call view_->RestoreFocus() here. On some platforms,
1309 // attempting to focus the currently-invisible WebContentsView will be
1310 // flat-out ignored. Therefore, this boolean is used to track whether
1311 // we will request focus after the fullscreen widget has been
1312 // destroyed.
1313 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1314 } else {
1315 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1316 i != pending_widget_views_.end(); ++i) {
1317 if (host->GetView() == i->second) {
1318 pending_widget_views_.erase(i);
1319 break;
1320 }
[email protected]bafe6cd2012-05-23 23:09:501321 }
1322 }
1323 break;
1324 }
[email protected]14392a52012-05-02 20:28:441325 default:
1326 NOTREACHED();
1327 }
1328}
1329
[email protected]ec6c05f2013-10-23 18:41:571330WebContents* WebContentsImpl::GetWebContents() {
1331 return this;
1332}
1333
[email protected]54944cde2012-12-09 09:24:591334void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211335 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361336 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211337 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431338 should_normally_be_visible_ = !params.initially_hidden;
1339
dcheng3ce04b62015-10-26 23:30:551340 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541341 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551342 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1343 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541344 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551345 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1346 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1347
1348 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1349 if (!site_instance)
1350 site_instance = SiteInstance::Create(params.browser_context);
1351
1352 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1353 // local root by definition.
1354 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1355 // longer be necessary to eagerly grab a routing ID for the view.
1356 // https://crbug.com/545684
1357 int32_t view_routing_id = params.routing_id;
1358 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1359 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1360 view_routing_id = main_frame_widget_routing_id =
1361 site_instance->GetProcess()->GetNextRoutingID();
1362 }
1363
1364 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1365 params.main_frame_routing_id,
1366 main_frame_widget_routing_id);
naskoc9f51dd2015-05-13 00:39:281367 frame_tree_.root()->SetFrameName(params.main_frame_name);
[email protected]d1198fd2012-08-13 22:50:191368
[email protected]fc2b46b2014-05-03 16:33:451369 WebContentsViewDelegate* delegate =
1370 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1371
fsamueladb0033602015-12-09 19:20:411372#if defined(MOJO_SHELL_CLIENT)
1373 if (MojoShellConnection::Get() &&
1374 base::CommandLine::ForCurrentProcess()->HasSwitch(
1375 switches::kUseMusInRenderer)) {
1376 mus::Window* mus_window = aura::GetMusWindow(params.context);
1377 if (mus_window) {
1378 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1379 &render_view_host_delegate_view_));
1380 }
1381 }
1382#endif
1383
1384 if (!view_) {
1385 view_.reset(CreateWebContentsView(this, delegate,
1386 &render_view_host_delegate_view_));
1387 }
fsamuel9cf7bdf2015-11-20 02:19:321388
lazyboy6ec48b2a2015-06-29 15:18:141389 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081390 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321391 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361392 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321393 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191394 }
[email protected]fc2b46b2014-05-03 16:33:451395 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191396 CHECK(view_.get());
1397
[email protected]ed245db2012-12-18 08:00:451398 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591399 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191400
tommyclieb25b2a2014-11-03 19:45:091401#if defined(ENABLE_PLUGINS)
1402 plugin_content_origin_whitelist_.reset(
1403 new PluginContentOriginWhitelist(this));
1404#endif
1405
[email protected]d1198fd2012-08-13 22:50:191406 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211407 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1408 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101409
[email protected]01f83f92014-06-17 14:41:541410 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091411 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541412
mlamouriefdca9d2014-09-16 16:55:401413 manifest_manager_host_.reset(new ManifestManagerHost(this));
1414
mfomitchev841f8182015-11-07 02:03:191415#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]583418cc2013-01-17 14:01:101416 date_time_chooser_.reset(new DateTimeChooserAndroid());
1417#endif
fsamuel7310a4262014-12-05 05:06:441418
1419 // BrowserPluginGuest::Init needs to be called after this WebContents has
1420 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1421 if (browser_plugin_guest_)
1422 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371423
1424 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1425 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561426
1427 // If the WebContents creation was renderer-initiated, it means that the
1428 // corresponding RenderView and main RenderFrame have already been created.
1429 // Ensure observers are notified about this.
1430 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431431 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561432 RenderViewCreated(GetRenderViewHost());
1433 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1434 }
naskof5940b9f2015-03-02 23:04:051435
1436 // Ensure that observers are notified of the creation of this WebContents's
1437 // main RenderFrameHost. It must be done here for main frames, since the
1438 // NotifySwappedFromRenderManager expects view_ to already be created and that
1439 // happens after RenderFrameHostManager::Init.
1440 NotifySwappedFromRenderManager(
1441 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191442}
1443
[email protected]7fff43e2013-05-21 20:21:101444void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1445 RemoveDestructionObserver(web_contents);
1446
[email protected]ceee8cd2013-03-08 04:59:511447 // Clear a pending contents that has been closed before being shown.
1448 for (PendingContents::iterator iter = pending_contents_.begin();
1449 iter != pending_contents_.end();
1450 ++iter) {
1451 if (iter->second != web_contents)
1452 continue;
1453 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511454 return;
1455 }
1456 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441457}
1458
[email protected]7fff43e2013-05-21 20:21:101459void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1460 if (!ContainsKey(destruction_observers_, web_contents)) {
1461 destruction_observers_[web_contents] =
1462 new DestructionObserver(this, web_contents);
1463 }
1464}
1465
1466void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1467 DestructionObservers::iterator iter =
1468 destruction_observers_.find(web_contents);
1469 if (iter != destruction_observers_.end()) {
1470 delete destruction_observers_[web_contents];
1471 destruction_observers_.erase(iter);
1472 }
1473}
1474
[email protected]b172aee2012-04-10 17:05:261475void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311476 observers_.AddObserver(observer);
1477}
1478
[email protected]b172aee2012-04-10 17:05:261479void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311480 observers_.RemoveObserver(observer);
1481}
1482
[email protected]948481d2014-06-11 18:32:221483std::set<RenderWidgetHostView*>
1484WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1485 std::set<RenderWidgetHostView*> set;
1486 if (ShowingInterstitialPage()) {
1487 set.insert(GetRenderWidgetHostView());
1488 } else {
1489 ForEachFrame(
1490 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1491 }
[email protected]de3c5d82014-05-28 22:12:591492 return set;
1493}
1494
[email protected]b172aee2012-04-10 17:05:261495void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341496 if (delegate_)
1497 delegate_->ActivateContents(this);
1498}
1499
avi3e4b8512015-11-11 01:55:491500void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1501 if (!RenderViewHostImpl::From(render_widget_host))
1502 return;
1503
[email protected]63954792011-07-11 04:17:481504 if (delegate_)
1505 delegate_->LostCapture();
1506}
1507
lazyboy63f5b312015-11-23 20:19:521508void WebContentsImpl::RenderWidgetCreated(
1509 RenderWidgetHostImpl* render_widget_host) {
1510 created_widgets_.insert(render_widget_host);
1511}
1512
[email protected]b24b68a2012-09-24 21:57:261513void WebContentsImpl::RenderWidgetDeleted(
1514 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521515 // Note that |is_being_destroyed_| can be true at this point as
1516 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1517 // us here.
1518 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261519
lazyboy63f5b312015-11-23 20:19:521520 if (is_being_destroyed_)
1521 return;
[email protected]44470a22013-01-24 01:21:541522
1523 if (render_widget_host &&
1524 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491525 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531526 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541527 FOR_EACH_OBSERVER(WebContentsObserver,
1528 observers_,
1529 DidDestroyFullscreenWidget(
1530 fullscreen_widget_routing_id_));
1531 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031532 if (fullscreen_widget_had_focus_at_shutdown_)
1533 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541534 }
[email protected]b24b68a2012-09-24 21:57:261535}
1536
miu9e14e492014-10-25 02:39:041537void WebContentsImpl::RenderWidgetGotFocus(
1538 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371539 // Notify the observers if an embedded fullscreen widget was focused.
1540 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1541 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1542 NotifyWebContentsFocused();
1543 }
miu9e14e492014-10-25 02:39:041544}
1545
estaded0a0c992015-01-21 14:12:061546void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311547 RenderWidgetHostImpl* render_widget_host,
1548 bool width_changed) {
creisc014b402015-04-23 16:41:451549 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291550 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061551 return;
estaded0a0c992015-01-21 14:12:061552
rouslan2f5993f2015-01-29 00:18:311553 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1554 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061555}
1556
paulmeyer9ef6e4462015-02-24 19:15:101557void WebContentsImpl::ScreenInfoChanged() {
1558 if (browser_plugin_embedder_)
1559 browser_plugin_embedder_->ScreenInfoChanged();
1560}
1561
[email protected]b172aee2012-04-10 17:05:261562bool WebContentsImpl::PreHandleKeyboardEvent(
1563 const NativeWebKeyboardEvent& event,
1564 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481565 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131566 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481567}
1568
[email protected]b172aee2012-04-10 17:05:261569void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101570 if (browser_plugin_embedder_ &&
1571 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1572 return;
1573 }
[email protected]63954792011-07-11 04:17:481574 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131575 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481576}
1577
[email protected]d92026ef2014-03-03 21:04:131578bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461579 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191580#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331581 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1582 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191583 // -the OS already has a gesture to do this through pinch-zoom
1584 // -if a user starts an inertial scroll, let's go, and presses control
1585 // (i.e. control+tab) then the OS's buffered scroll events will come in
1586 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331587 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551588 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331589 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521590 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1591 return true;
1592 }
[email protected]bccc4472013-04-18 16:37:191593#endif
[email protected]fb3f066e2013-02-12 19:12:521594 return false;
1595}
1596
[email protected]04bce562014-01-30 05:34:541597bool WebContentsImpl::PreHandleGestureEvent(
1598 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031599 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541600}
1601
kenrb2a565f82015-09-02 20:24:591602RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451603 if (!is_being_destroyed_ && GetOuterWebContents())
1604 return GetOuterWebContents()->GetInputEventRouter();
1605
1606 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591607 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1608 return rwh_input_event_router_.get();
1609}
1610
alexmos3fcd0ca2015-10-23 18:18:331611void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1612 // Focus loss may occur while this WebContents is being destroyed. Don't
1613 // send the message in this case, as the main frame's RenderFrameHost and
1614 // other state has already been cleared.
1615 if (is_being_destroyed_)
1616 return;
1617
1618 frame_tree_.ReplicatePageFocus(is_focused);
1619}
1620
alexmosc4cbacb2015-11-21 01:29:221621RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1622 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521623 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221624 return receiving_widget;
1625
1626 // Events for widgets other than the main frame (e.g., popup menus) should be
1627 // forwarded directly to the widget they arrived on.
1628 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1629 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521630
1631 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1632 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221633 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521634
alexmos732ca3a2015-12-08 02:01:021635 // The view may be null if a subframe's renderer process has crashed while
1636 // the subframe has focus. Drop the event in that case. Do not give
1637 // it to the main frame, so that the user doesn't unexpectedly type into the
1638 // wrong frame if a focused subframe renderer crashes while they type.
1639 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1640 if (!view)
1641 return nullptr;
1642
1643 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521644}
1645
mlamouri7a78d6fd2015-01-17 13:23:531646void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1647 // This method is being called to enter renderer-initiated fullscreen mode.
1648 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491649 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371650 if (widget_view) {
1651 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1652 ->ShutdownAndDestroyWidget(true);
1653 }
[email protected]4aebbca2013-09-17 22:26:491654
[email protected]8a5e0ca2011-08-25 06:30:471655 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531656 delegate_->EnterFullscreenModeForTab(this, origin);
1657
1658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
avibf58fa0c2015-11-11 01:45:521659 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(
1660 GetRenderViewHost()->GetWidget())));
mlamouri7a78d6fd2015-01-17 13:23:531661}
1662
1663void WebContentsImpl::ExitFullscreenMode() {
1664 // This method is being called to leave renderer-initiated fullscreen mode.
1665 // Make sure any existing fullscreen widget is shut down first.
1666 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371667 if (widget_view) {
1668 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1669 ->ShutdownAndDestroyWidget(true);
1670 }
mlamouri7a78d6fd2015-01-17 13:23:531671
hugo.holgersson61288e6c2015-01-28 17:04:401672#if defined(OS_ANDROID)
1673 ContentVideoView* video_view = ContentVideoView::GetInstance();
1674 if (video_view != NULL)
1675 video_view->OnExitFullscreen();
1676#endif
1677
mlamouri7a78d6fd2015-01-17 13:23:531678 if (delegate_)
1679 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371680
scheib3dcb6c932015-02-23 10:55:581681 // Ensure web contents exit fullscreen state by sending a resize message,
1682 // which includes the fullscreen state. This is required for the situation
1683 // of the browser moving the view into a fullscreen state "browser fullscreen"
1684 // and then the contents entering "tab fullscreen". Exiting the contents
1685 // "tab fullscreen" then won't have the side effect of the view resizing,
1686 // hence the explicit call here is required.
1687 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1688 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1689 render_widget_host->WasResized();
1690 }
1691
avibf58fa0c2015-11-11 01:45:521692 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1693 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(
1694 GetRenderViewHost()->GetWidget())));
[email protected]8a5e0ca2011-08-25 06:30:471695}
1696
avibf58fa0c2015-11-11 01:45:521697bool WebContentsImpl::IsFullscreenForCurrentTab(
1698 RenderWidgetHostImpl* render_widget_host) const {
1699 if (!RenderViewHostImpl::From(render_widget_host))
1700 return false;
1701
[email protected]199bba6e2012-04-04 16:19:381702 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121703}
1704
avibf58fa0c2015-11-11 01:45:521705blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1706 RenderWidgetHostImpl* render_widget_host) const {
1707 if (!RenderViewHostImpl::From(render_widget_host))
1708 return blink::WebDisplayModeBrowser;
1709
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121710 return delegate_ ? delegate_->GetDisplayMode(this)
1711 : blink::WebDisplayModeBrowser;
1712}
1713
avic3aa8422015-11-09 20:57:221714void WebContentsImpl::RequestToLockMouse(
1715 RenderWidgetHostImpl* render_widget_host,
1716 bool user_gesture,
1717 bool last_unlocked_by_target) {
1718 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1719 render_widget_host->GotResponseToLockMouseRequest(false);
1720 return;
[email protected]e9621112011-10-17 05:38:371721 }
avic3aa8422015-11-09 20:57:221722
1723 if (delegate_)
1724 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1725 else
1726 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371727}
1728
avi3e4b8512015-11-11 01:55:491729void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1730 if (!RenderViewHostImpl::From(render_widget_host))
1731 return;
1732
[email protected]e9621112011-10-17 05:38:371733 if (delegate_)
1734 delegate_->LostMouseLock();
1735}
1736
dtrainor5ef644e2015-11-19 00:12:471737void WebContentsImpl::ForwardCompositorProto(
1738 RenderWidgetHostImpl* render_widget_host,
1739 const std::vector<uint8_t>& proto) {
1740 if (render_widget_host != GetRenderViewHost()->GetWidget())
1741 return;
1742
1743 if (delegate_)
1744 delegate_->ForwardCompositorProto(proto);
1745}
1746
[email protected]bafe6cd2012-05-23 23:09:501747void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431748 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551749 int32_t route_id,
1750 int32_t main_frame_route_id,
1751 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131752 const ViewHostMsg_CreateWindow_Params& params,
1753 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501754 // We usually create the new window in the same BrowsingInstance (group of
1755 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551756 // if the opener is being suppressed (in a non-guest), we create a new
1757 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251758 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551759
nickd30fd962015-07-27 21:51:081760 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141761 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1762 // yet.
1763 NOTREACHED();
1764 }
1765
[email protected]04cbd3d2013-12-04 04:58:201766 // If the opener is to be suppressed, the new window can be in any process.
1767 // Since routing ids are process specific, we must not have one passed in
1768 // as argument here.
1769 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1770
[email protected]bafe6cd2012-05-23 23:09:501771 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431772 params.opener_suppressed && !is_guest
1773 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1774 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501775
alexmos4cf2aa32015-07-15 23:40:431776 // A message to create a new window can only come from a process for a frame
1777 // in this WebContents' FrameTree. If any other process sends the request, it
1778 // is invalid and the process must be terminated.
1779 int render_process_id = source_site_instance->GetProcess()->GetID();
1780 bool did_match_process = false;
1781 frame_tree_.ForEach(
1782 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1783 if (!did_match_process) {
1784 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351785 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201786 if (process_handle != base::kNullProcessHandle) {
1787 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391788 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351789 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201790 }
1791 return;
1792 }
1793
[email protected]d1198fd2012-08-13 22:50:191794 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341795 //
1796 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301797 const std::string& partition_id =
1798 GetContentClient()->browser()->
1799 GetStoragePartitionIdForSite(GetBrowserContext(),
1800 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461801 StoragePartition* partition = BrowserContext::GetStoragePartition(
1802 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411803 DOMStorageContextWrapper* dom_storage_context =
1804 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191805 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1806 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1807 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371808
1809 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551810 !delegate_->ShouldCreateWebContents(
1811 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1812 params.window_container_type, params.frame_name, params.target_url,
1813 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011814 if (route_id != MSG_ROUTING_NONE &&
1815 !RenderViewHost::FromID(render_process_id, route_id)) {
1816 // If the embedder didn't create a WebContents for this route, we need to
1817 // delete the RenderView that had already been created.
1818 Send(new ViewMsg_Close(route_id));
1819 }
[email protected]dd6730412013-08-14 15:03:371820 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]dd6730412013-08-14 15:03:371821 return;
1822 }
1823
1824 // Create the new web contents. This will automatically create the new
1825 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461826 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591827 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041828 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551829 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121830 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431831 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211832 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061833 create_params.opener_suppressed = params.opener_suppressed;
1834 if (params.disposition == NEW_BACKGROUND_TAB)
1835 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191836 create_params.renderer_initiated_creation =
1837 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061838
[email protected]4858e432014-06-23 18:14:171839 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551840 if (!is_guest) {
1841 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451842 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171843 new_contents = static_cast<WebContentsImpl*>(
1844 WebContents::Create(create_params));
1845 } else {
1846 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551847 }
[email protected]50d326e2014-05-20 17:59:061848 new_contents->GetController().SetSessionStorageNamespace(
1849 partition_id,
1850 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191851
alexmos646fec02015-07-25 00:11:491852 // If the new frame has a name, make sure any SiteInstances that can find
1853 // this named frame have proxies for it. Must be called after
1854 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1855 // GetSessionStorageNamespace.
1856 if (!params.frame_name.empty())
1857 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1858
[email protected]c4538072013-03-18 02:17:551859 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341860 // will be shown immediately).
1861 if (!params.opener_suppressed) {
1862 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451863 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501864
[email protected]d70bea92013-04-05 04:23:341865 // TODO(brettw): It seems bogus that we have to call this function on the
1866 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431867 new_view->CreateViewForWidget(
1868 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341869 }
[email protected]bafe6cd2012-05-23 23:09:501870 // Save the created window associated with the route so we can show it
1871 // later.
1872 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1873 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101874 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501875 }
1876
1877 if (delegate_) {
1878 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071879 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131880 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501881 }
1882
1883 if (params.opener_suppressed) {
1884 // When the opener is suppressed, the original renderer cannot access the
1885 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001886 bool was_blocked = false;
1887 if (delegate_) {
bokan107a47f2015-02-03 23:23:391888 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001889 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391890 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001891 params.user_gesture, &was_blocked);
1892 }
1893 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211894 OpenURLParams open_params(params.target_url,
1895 Referrer(),
1896 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351897 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211898 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301899 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371900
1901 if (delegate_ && !is_guest &&
1902 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1903 // We are in asynchronous add new contents path, delay opening url
1904 new_contents->delayed_open_url_params_.reset(
1905 new OpenURLParams(open_params));
1906 } else {
1907 new_contents->OpenURL(open_params);
1908 }
[email protected]eda238a12012-09-07 23:44:001909 }
[email protected]bafe6cd2012-05-23 23:09:501910 }
1911}
1912
avib7348942015-12-25 20:57:101913void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1914 int32_t route_id,
[email protected]180ef242013-11-07 06:50:461915 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051916 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501917}
1918
avib7348942015-12-25 20:57:101919void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
1920 int32_t route_id) {
piman5d36dae2015-09-24 22:47:051921 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501922}
1923
avib7348942015-12-25 20:57:101924void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1925 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:501926 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461927 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211928 RenderProcessHost* process = GetRenderProcessHost();
kenrbb46f86a2015-12-07 07:53:231929 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:511930 // this WebContentsImpl instance. If any other process sends the request,
1931 // it is invalid and the process must be terminated.
kenrbb46f86a2015-12-07 07:53:231932 bool did_match_process = false;
1933 frame_tree_.ForEach(
1934 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1935 if (!did_match_process) {
jaekyun37e572a32014-12-04 23:33:351936 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1937 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511938 if (process_handle != base::kNullProcessHandle) {
1939 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391940 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351941 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511942 }
1943 return;
1944 }
1945
[email protected]bafe6cd2012-05-23 23:09:501946 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051947 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261948
[email protected]cfd80b02014-05-01 17:46:481949 RenderWidgetHostViewBase* widget_view =
1950 static_cast<RenderWidgetHostViewBase*>(
1951 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191952 if (!widget_view)
1953 return;
[email protected]bafe6cd2012-05-23 23:09:501954 if (!is_fullscreen) {
1955 // Popups should not get activated.
1956 widget_view->SetPopupType(popup_type);
1957 }
1958 // Save the created widget associated with the route so we can show it later.
1959 pending_widget_views_[route_id] = widget_view;
1960
1961#if defined(OS_MACOSX)
1962 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1963 // to allow it to survive the trip without being hosted.
1964 base::mac::NSObjectRetain(widget_view->GetNativeView());
1965#endif
1966}
1967
1968void WebContentsImpl::ShowCreatedWindow(int route_id,
1969 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391970 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501971 bool user_gesture) {
1972 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001973 if (contents) {
1974 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:161975 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:381976 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
1977 contents->ResumeLoadingCreatedWebContents();
1978
[email protected]eda238a12012-09-07 23:44:001979 if (delegate) {
1980 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391981 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001982 }
1983 }
[email protected]bafe6cd2012-05-23 23:09:501984}
1985
1986void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391987 const gfx::Rect& initial_rect) {
1988 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501989}
1990
1991void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1992 ShowCreatedWidget(route_id, true, gfx::Rect());
1993}
1994
1995void WebContentsImpl::ShowCreatedWidget(int route_id,
1996 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391997 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481998 RenderWidgetHostViewBase* widget_host_view =
1999 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502000 if (!widget_host_view)
2001 return;
[email protected]cfd80b02014-05-01 17:46:482002
2003 RenderWidgetHostView* view = NULL;
2004 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2005 if (guest && guest->embedder_web_contents()) {
2006 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2007 } else {
2008 view = GetRenderWidgetHostView();
2009 }
2010
[email protected]4aebbca2013-09-17 22:26:492011 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312012 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032013 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312014 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492015 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2016 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532017 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492018 } else {
[email protected]cfd80b02014-05-01 17:46:482019 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492020 }
[email protected]4aebbca2013-09-17 22:26:492021 FOR_EACH_OBSERVER(WebContentsObserver,
2022 observers_,
2023 DidShowFullscreenWidget(route_id));
2024 if (!widget_host_view->HasFocus())
2025 widget_host_view->Focus();
2026 } else {
bokan107a47f2015-02-03 23:23:392027 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492028 }
[email protected]89054502012-06-03 10:29:242029
2030 RenderWidgetHostImpl* render_widget_host_impl =
2031 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2032 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312033 // Only allow privileged mouse lock for fullscreen render widget, which is
2034 // used to implement Pepper Flash fullscreen.
2035 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502036
2037#if defined(OS_MACOSX)
2038 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2039 // properly embedded (or purposefully ignored) we can release the retain we
2040 // took in CreateNewWidget().
2041 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2042#endif
2043}
2044
2045WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2046 PendingContents::iterator iter = pending_contents_.find(route_id);
2047
2048 // Certain systems can block the creation of new windows. If we didn't succeed
2049 // in creating one, just return NULL.
2050 if (iter == pending_contents_.end()) {
2051 return NULL;
2052 }
2053
2054 WebContentsImpl* new_contents = iter->second;
2055 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102056 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502057
[email protected]d70bea92013-04-05 04:23:342058 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252059 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342060 return new_contents;
2061
[email protected]bafe6cd2012-05-23 23:09:502062 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432063 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502064 return NULL;
2065
[email protected]bafe6cd2012-05-23 23:09:502066 return new_contents;
2067}
2068
2069RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2070 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2071 if (iter == pending_widget_views_.end()) {
2072 DCHECK(false);
2073 return NULL;
2074 }
2075
2076 RenderWidgetHostView* widget_host_view = iter->second;
2077 pending_widget_views_.erase(route_id);
2078
2079 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2080 if (!widget_host->GetProcess()->HasConnection()) {
2081 // The view has gone away or the renderer crashed. Nothing to do.
2082 return NULL;
2083 }
2084
2085 return widget_host_view;
2086}
2087
[email protected]f13b4202012-06-12 23:53:232088void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092089 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212090 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372091 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232092 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372093 } else {
2094 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042095 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372096 scoped_ptr<MediaStreamUI>());
2097 }
[email protected]f13b4202012-06-12 23:53:232098}
2099
grunell657d4d82014-09-18 00:09:432100bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2101 MediaStreamType type) {
2102 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2103 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2104 return delegate_ &&
2105 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2106}
2107
[email protected]cc9200432013-07-23 23:02:402108SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2109 SiteInstance* instance) {
2110 return controller_.GetSessionStorageNamespace(instance);
2111}
2112
[email protected]6de7fc482014-06-06 10:46:442113SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2114 return controller_.GetSessionStorageNamespaceMap();
2115}
2116
[email protected]9b159a52013-10-03 17:24:552117FrameTree* WebContentsImpl::GetFrameTree() {
2118 return &frame_tree_;
2119}
2120
lukendc35e7f2014-11-10 19:06:142121void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2122 virtual_keyboard_requested_ = requested;
2123}
2124
2125bool WebContentsImpl::IsVirtualKeyboardRequested() {
2126 return virtual_keyboard_requested_;
2127}
2128
[email protected]95640212014-07-26 18:14:302129AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2130 return accessibility_mode_;
2131}
2132
[email protected]31a71eaf2014-03-13 01:47:362133void WebContentsImpl::AccessibilityEventReceived(
2134 const std::vector<AXEventNotificationDetails>& details) {
2135 FOR_EACH_OBSERVER(
2136 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2137}
2138
dmazzonia656928e2014-09-15 20:28:542139RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402140 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542141 int browser_plugin_instance_id) {
2142 BrowserPluginGuestManager* guest_manager =
2143 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202144 if (!guest_manager)
2145 return nullptr;
2146
dmazzonia656928e2014-09-15 20:28:542147 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442148 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542149 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202150 return nullptr;
2151
dmazzonia656928e2014-09-15 20:28:542152 return guest->GetMainFrame();
2153}
2154
blundellc57b93f2014-10-29 13:19:572155GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2156 return geolocation_service_context_.get();
2157}
2158
alogvinovf50445a2015-10-30 13:00:122159WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2160 return wake_lock_service_context_.get();
2161}
2162
[email protected]edc3af82013-12-12 21:24:072163void WebContentsImpl::OnShowValidationMessage(
2164 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292165 const base::string16& main_text,
2166 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072167 if (delegate_)
2168 delegate_->ShowValidationMessage(
2169 this, anchor_in_root_view, main_text, sub_text);
2170}
2171
2172void WebContentsImpl::OnHideValidationMessage() {
2173 if (delegate_)
2174 delegate_->HideValidationMessage(this);
2175}
2176
2177void WebContentsImpl::OnMoveValidationMessage(
2178 const gfx::Rect& anchor_in_root_view) {
2179 if (delegate_)
2180 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2181}
2182
[email protected]32deec62013-05-15 23:55:042183void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2184 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442185 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042186}
2187
[email protected]95640212014-07-26 18:14:302188BrowserAccessibilityManager*
2189 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452190 RenderFrameHostImpl* rfh = GetMainFrame();
2191 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302192}
2193
2194BrowserAccessibilityManager*
2195 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452196 RenderFrameHostImpl* rfh = GetMainFrame();
2197 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302198}
2199
mohsen7ab1ec16ec2015-07-02 18:26:232200void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2201 RenderFrameHost* focused_frame = GetFocusedFrame();
2202 if (!focused_frame)
2203 return;
2204
2205 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2206 focused_frame->GetRoutingID(), extent));
2207}
2208
2209void WebContentsImpl::SelectRange(const gfx::Point& base,
2210 const gfx::Point& extent) {
2211 RenderFrameHost* focused_frame = GetFocusedFrame();
2212 if (!focused_frame)
2213 return;
2214
2215 focused_frame->Send(
2216 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2217}
2218
aurimasab0319022015-07-10 21:57:382219void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2220 int end_adjust) {
2221 RenderFrameHost* focused_frame = GetFocusedFrame();
2222 if (!focused_frame)
2223 return;
2224
2225 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2226 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2227}
2228
[email protected]b172aee2012-04-10 17:05:262229void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492230 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232231 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492232 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332233}
2234
avic3aa8422015-11-09 20:57:222235void WebContentsImpl::ResizeDueToAutoResize(
2236 RenderWidgetHostImpl* render_widget_host,
2237 const gfx::Size& new_size) {
2238 if (render_widget_host != GetRenderViewHost()->GetWidget())
2239 return;
2240
[email protected]61e2b3cc2012-03-02 16:13:342241 if (delegate_)
2242 delegate_->ResizeDueToAutoResize(this, new_size);
2243}
2244
[email protected]b172aee2012-04-10 17:05:262245WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202246 if (!delegate_)
2247 return NULL;
[email protected]00c37fc2011-08-02 00:22:502248
[email protected]e5d549d2011-12-28 01:29:202249 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202250 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342251}
2252
[email protected]6b618e62012-08-16 12:59:182253bool WebContentsImpl::Send(IPC::Message* message) {
2254 if (!GetRenderViewHost()) {
2255 delete message;
2256 return false;
2257 }
2258
2259 return GetRenderViewHost()->Send(message);
2260}
2261
[email protected]a86c0e962013-12-17 17:10:392262void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2263 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442264 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392265 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442266}
2267
[email protected]20ca0382013-02-28 19:50:072268void WebContentsImpl::AttachInterstitialPage(
2269 InterstitialPageImpl* interstitial_page) {
2270 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212271 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292272
2273 // Cancel any visible dialogs so that they don't interfere with the
2274 // interstitial.
creis89a0f782015-05-27 16:13:172275 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292276
[email protected]20ca0382013-02-28 19:50:072277 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2278 DidAttachInterstitialPage());
2279}
2280
2281void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572282 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212283 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072284 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2285 DidDetachInterstitialPage());
2286}
2287
avi2b177592014-12-10 02:08:022288void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2289 int history_length) {
2290 SetHistoryOffsetAndLengthForView(
2291 GetRenderViewHost(), history_offset, history_length);
2292}
2293
2294void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2295 RenderViewHost* render_view_host,
2296 int history_offset,
2297 int history_length) {
2298 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2299 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142300}
2301
[email protected]4fed3702014-04-01 09:08:002302void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172303 RenderFrameHost* focused_frame = GetFocusedFrame();
2304 if (!focused_frame)
2305 return;
2306
[email protected]959be4c2014-04-08 15:01:332307 focused_frame->Send(new FrameMsg_Reload(
2308 focused_frame->GetRoutingID(), ignore_cache));
2309}
2310
2311void WebContentsImpl::Undo() {
2312 RenderFrameHost* focused_frame = GetFocusedFrame();
2313 if (!focused_frame)
2314 return;
2315
2316 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2317 RecordAction(base::UserMetricsAction("Undo"));
2318}
2319
2320void WebContentsImpl::Redo() {
2321 RenderFrameHost* focused_frame = GetFocusedFrame();
2322 if (!focused_frame)
2323 return;
2324 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2325 RecordAction(base::UserMetricsAction("Redo"));
2326}
2327
2328void WebContentsImpl::Cut() {
2329 RenderFrameHost* focused_frame = GetFocusedFrame();
2330 if (!focused_frame)
2331 return;
2332
2333 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2334 RecordAction(base::UserMetricsAction("Cut"));
2335}
2336
2337void WebContentsImpl::Copy() {
2338 RenderFrameHost* focused_frame = GetFocusedFrame();
2339 if (!focused_frame)
2340 return;
2341
2342 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2343 RecordAction(base::UserMetricsAction("Copy"));
2344}
2345
2346void WebContentsImpl::CopyToFindPboard() {
2347#if defined(OS_MACOSX)
2348 RenderFrameHost* focused_frame = GetFocusedFrame();
2349 if (!focused_frame)
2350 return;
2351
2352 // Windows/Linux don't have the concept of a find pasteboard.
2353 focused_frame->Send(
2354 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2355 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2356#endif
2357}
2358
2359void WebContentsImpl::Paste() {
2360 RenderFrameHost* focused_frame = GetFocusedFrame();
2361 if (!focused_frame)
2362 return;
2363
2364 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2365 RecordAction(base::UserMetricsAction("Paste"));
2366}
2367
2368void WebContentsImpl::PasteAndMatchStyle() {
2369 RenderFrameHost* focused_frame = GetFocusedFrame();
2370 if (!focused_frame)
2371 return;
2372
2373 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2374 focused_frame->GetRoutingID()));
2375 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2376}
2377
2378void WebContentsImpl::Delete() {
2379 RenderFrameHost* focused_frame = GetFocusedFrame();
2380 if (!focused_frame)
2381 return;
2382
2383 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2384 RecordAction(base::UserMetricsAction("DeleteSelection"));
2385}
2386
2387void WebContentsImpl::SelectAll() {
2388 RenderFrameHost* focused_frame = GetFocusedFrame();
2389 if (!focused_frame)
2390 return;
2391
2392 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2393 RecordAction(base::UserMetricsAction("SelectAll"));
2394}
2395
2396void WebContentsImpl::Unselect() {
2397 RenderFrameHost* focused_frame = GetFocusedFrame();
2398 if (!focused_frame)
2399 return;
2400
2401 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2402 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172403}
2404
2405void WebContentsImpl::Replace(const base::string16& word) {
2406 RenderFrameHost* focused_frame = GetFocusedFrame();
2407 if (!focused_frame)
2408 return;
2409
[email protected]959be4c2014-04-08 15:01:332410 focused_frame->Send(new InputMsg_Replace(
2411 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172412}
2413
2414void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2415 RenderFrameHost* focused_frame = GetFocusedFrame();
2416 if (!focused_frame)
2417 return;
2418
[email protected]959be4c2014-04-08 15:01:332419 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2420 focused_frame->GetRoutingID(), word));
2421}
2422
2423void WebContentsImpl::NotifyContextMenuClosed(
2424 const CustomContextMenuContext& context) {
2425 RenderFrameHost* focused_frame = GetFocusedFrame();
2426 if (!focused_frame)
2427 return;
2428
2429 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2430 focused_frame->GetRoutingID(), context));
2431}
2432
2433void WebContentsImpl::ExecuteCustomContextMenuCommand(
2434 int action, const CustomContextMenuContext& context) {
2435 RenderFrameHost* focused_frame = GetFocusedFrame();
2436 if (!focused_frame)
2437 return;
2438
2439 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2440 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002441}
2442
[email protected]fc2b46b2014-05-03 16:33:452443gfx::NativeView WebContentsImpl::GetNativeView() {
2444 return view_->GetNativeView();
2445}
2446
2447gfx::NativeView WebContentsImpl::GetContentNativeView() {
2448 return view_->GetContentNativeView();
2449}
2450
2451gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2452 return view_->GetTopLevelNativeWindow();
2453}
2454
2455gfx::Rect WebContentsImpl::GetViewBounds() {
2456 return view_->GetViewBounds();
2457}
2458
2459gfx::Rect WebContentsImpl::GetContainerBounds() {
2460 gfx::Rect rv;
2461 view_->GetContainerBounds(&rv);
2462 return rv;
2463}
2464
2465DropData* WebContentsImpl::GetDropData() {
2466 return view_->GetDropData();
2467}
2468
2469void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042470 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452471}
2472
2473void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042474 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452475}
2476
2477void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042478 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452479}
2480
2481void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042482 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452483}
2484
[email protected]b172aee2012-04-10 17:05:262485void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272486 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212487 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542488 return;
2489 }
[email protected]0b431992014-06-24 00:08:032490 RenderWidgetHostView* const fullscreen_view =
2491 GetFullscreenRenderWidgetHostView();
2492 if (fullscreen_view) {
2493 fullscreen_view->Focus();
2494 return;
2495 }
creisc014b402015-04-23 16:41:452496 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542497}
2498
[email protected]b172aee2012-04-10 17:05:262499bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212500 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542501}
2502
[email protected]b172aee2012-04-10 17:05:262503InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212504 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222505}
2506
[email protected]b172aee2012-04-10 17:05:262507bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162508 // WebKit creates Document object when MIME type is application/xhtml+xml,
2509 // so we also support this MIME type.
2510 return contents_mime_type_ == "text/html" ||
2511 contents_mime_type_ == "text/xml" ||
2512 contents_mime_type_ == "application/xhtml+xml" ||
2513 contents_mime_type_ == "text/plain" ||
2514 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252515 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592519 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162520 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552521 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192522 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142523 return;
[email protected]c7dd2f62011-07-18 15:57:592524 }
2525
2526 Stop();
2527
2528 // Create the save package and possibly prompt the user for the name to save
2529 // the page as. The user prompt is an asynchronous operation that runs on
2530 // another thread.
2531 save_package_ = new SavePackage(this);
2532 save_package_->GetSaveInfo();
2533}
2534
2535// Used in automated testing to bypass prompting the user for file names.
2536// Instead, the names and paths are hard coded rather than running them through
2537// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342538bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2539 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212540 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592541 // Stop the page from navigating.
2542 Stop();
2543
2544 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212545 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592546}
2547
[email protected]3c71576ce2013-07-23 02:00:012548void WebContentsImpl::SaveFrame(const GURL& url,
2549 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372550 SaveFrameWithHeaders(url, referrer, std::string());
2551}
2552
2553void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2554 const Referrer& referrer,
2555 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192556 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012557 return;
sammc92af61552014-11-19 23:27:402558 if (delegate_ && delegate_->SaveFrame(url, referrer))
2559 return;
2560
nasko89ad7742015-03-05 22:14:192561 // TODO(nasko): This check for main frame is incorrect and should be fixed
2562 // by explicitly passing in which frame this method should target.
2563 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012564
2565 DownloadManager* dlm =
2566 BrowserContext::GetDownloadManager(GetBrowserContext());
2567 if (!dlm)
2568 return;
avib7348942015-12-25 20:57:102569 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012570 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272571 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012572 if (entry)
2573 post_id = entry->GetPostID();
2574 }
2575 scoped_ptr<DownloadUrlParameters> params(
2576 DownloadUrlParameters::FromWebContents(this, url));
2577 params->set_referrer(referrer);
2578 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012579 if (post_id >= 0)
2580 params->set_method("POST");
2581 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372582
2583 if (headers.empty()) {
2584 params->set_prefer_cache(true);
2585 } else {
brettw26dab8f02015-08-08 00:28:472586 for (const base::StringPiece& key_value :
2587 base::SplitStringPiece(
2588 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2589 std::vector<std::string> pair = base::SplitString(
2590 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372591 DCHECK_EQ(2ul, pair.size());
2592 params->add_request_header(pair[0], pair[1]);
2593 }
2594 }
dcheng36b6aec92015-12-26 06:16:362595 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012596}
2597
[email protected]b172aee2012-04-10 17:05:262598void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342599 const base::FilePath& file,
avib7348942015-12-25 20:57:102600 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482601 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122602}
2603
[email protected]b172aee2012-04-10 17:05:262604const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272605 return contents_mime_type_;
2606}
2607
[email protected]b172aee2012-04-10 17:05:262608bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272609 return notify_disconnection_;
2610}
2611
[email protected]b172aee2012-04-10 17:05:262612void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312613 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182614 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162615}
2616
[email protected]b172aee2012-04-10 17:05:262617void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542618 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182619 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162620}
2621
[email protected]8ff00d72012-10-23 19:12:212622RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272623 return &renderer_preferences_;
2624}
2625
[email protected]e35ccd52012-05-23 16:22:472626void WebContentsImpl::Close() {
2627 Close(GetRenderViewHost());
2628}
2629
[email protected]cf200a562013-05-03 16:24:292630void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462631 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292632 if (browser_plugin_embedder_.get())
2633 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2634 screen_x, screen_y, operation);
2635 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452636 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2637 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292638}
2639
[email protected]d60f3702013-12-26 16:30:242640void WebContentsImpl::DidGetResourceResponseStart(
2641 const ResourceRequestDetails& details) {
2642 controller_.ssl_manager()->DidStartResourceResponse(details);
2643
2644 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2645 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242646}
2647
2648void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462649 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242650 const ResourceRedirectDetails& details) {
2651 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2652
2653 FOR_EACH_OBSERVER(
2654 WebContentsObserver,
2655 observers_,
creis114ca1b2014-11-13 23:51:462656 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242657
2658 // TODO(avi): Remove. http://crbug.com/170921
2659 NotificationService::current()->Notify(
2660 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2661 Source<WebContents>(this),
2662 Details<const ResourceRedirectDetails>(&details));
clamybd8f0432015-12-17 16:06:232663
2664 if (IsResourceTypeFrame(details.resource_type)) {
2665 NavigationHandleImpl* navigation_handle =
2666 static_cast<RenderFrameHostImpl*>(render_frame_host)
2667 ->navigation_handle();
2668 if (navigation_handle)
2669 navigation_handle->DidRedirectNavigation(details.new_url);
2670 }
[email protected]d60f3702013-12-26 16:30:242671}
2672
calamity7fe55ce2015-04-10 03:59:372673void WebContentsImpl::NotifyWebContentsFocused() {
2674 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2675}
2676
[email protected]b172aee2012-04-10 17:05:262677void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522678 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452679 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292680 if (browser_plugin_embedder_.get())
2681 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342682}
2683
[email protected]e35ccd52012-05-23 16:22:472684void WebContentsImpl::UserGestureDone() {
avic3aa8422015-11-09 20:57:222685 OnUserGesture(GetRenderViewHost()->GetWidget());
[email protected]e35ccd52012-05-23 16:22:472686}
2687
[email protected]b172aee2012-04-10 17:05:262688void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272689 closed_by_user_gesture_ = value;
2690}
2691
[email protected]b172aee2012-04-10 17:05:262692bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272693 return closed_by_user_gesture_;
2694}
2695
[email protected]b172aee2012-04-10 17:05:262696void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502697 if (!delegate_)
2698 return;
2699
[email protected]6286a372013-10-09 04:03:272700 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2701 if (!entry)
[email protected]1788e772010-12-15 16:40:502702 return;
2703
[email protected]6286a372013-10-09 04:03:272704 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122705}
2706
[email protected]b172aee2012-04-10 17:05:262707void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042708 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272709 if (!delegate_)
2710 return;
2711
[email protected]691aa2f2013-05-28 22:52:042712 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272713}
2714
[email protected]b172aee2012-04-10 17:05:262715int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272716 return minimum_zoom_percent_;
2717}
2718
[email protected]b172aee2012-04-10 17:05:262719int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272720 return maximum_zoom_percent_;
2721}
2722
mcnee432e47d2015-11-09 19:37:462723void WebContentsImpl::SetPageScale(float page_scale_factor) {
2724 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242725}
2726
[email protected]b172aee2012-04-10 17:05:262727gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492728 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232729}
2730
[email protected]b172aee2012-04-10 17:05:262731bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052732 if (GetBrowserPluginGuest())
2733 return GetBrowserPluginGuest()->LockMouse(allowed);
2734
creisc014b402015-04-23 16:41:452735 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432736 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2737 allowed)
creisc014b402015-04-23 16:41:452738 : false;
[email protected]0bfbf882011-12-22 18:19:272739}
2740
[email protected]b172aee2012-04-10 17:05:262741bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212742 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502743}
2744
alexmose201c7cd2015-06-10 17:14:212745WebContentsImpl* WebContentsImpl::GetOpener() const {
2746 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2747 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572748}
2749
[email protected]cb805452013-05-22 15:16:212750void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482751 if (!color_chooser_info_.get())
2752 return;
2753 RenderFrameHost* rfh = RenderFrameHost::FromID(
2754 color_chooser_info_->render_process_id,
2755 color_chooser_info_->render_frame_id);
2756 if (!rfh)
2757 return;
2758
2759 rfh->Send(new FrameMsg_DidChooseColorResponse(
2760 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202761}
2762
[email protected]cb805452013-05-22 15:16:212763void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482764 if (!color_chooser_info_.get())
2765 return;
2766 RenderFrameHost* rfh = RenderFrameHost::FromID(
2767 color_chooser_info_->render_process_id,
2768 color_chooser_info_->render_frame_id);
2769 if (!rfh)
2770 return;
2771
2772 rfh->Send(new FrameMsg_DidEndColorChooser(
2773 rfh->GetRoutingID(), color_chooser_info_->identifier));
2774 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202775}
2776
halton.huoca2eabd2015-07-06 08:17:402777int WebContentsImpl::DownloadImage(
2778 const GURL& url,
2779 bool is_favicon,
2780 uint32_t max_bitmap_size,
2781 bool bypass_cache,
2782 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552783 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402784 static int next_image_download_id = 0;
2785 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2786 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552787 const int download_id = ++next_image_download_id;
2788 if (!mojo_image_downloader) {
2789 // If the renderer process is dead (i.e. crash, or memory pressure on
2790 // Android), the downloader service will be invalid. Pre-Mojo, this would
2791 // hang the callback indefinetly since the IPC would be dropped. Now,
2792 // respond with a 400 HTTP error code to indicate that something went wrong.
2793 BrowserThread::PostTask(
2794 BrowserThread::UI, FROM_HERE,
2795 base::Bind(&WebContents::ImageDownloadCallback::Run,
2796 base::Owned(new ImageDownloadCallback(callback)),
2797 download_id, 400, url, std::vector<SkBitmap>(),
2798 std::vector<gfx::Size>()));
2799 return download_id;
2800 }
2801
halton.huoca2eabd2015-07-06 08:17:402802 image_downloader::DownloadRequestPtr req =
2803 image_downloader::DownloadRequest::New();
2804
2805 req->url = mojo::String::From(url);
2806 req->is_favicon = is_favicon;
2807 req->max_bitmap_size = max_bitmap_size;
2808 req->bypass_cache = bypass_cache;
2809
2810 mojo_image_downloader->DownloadImage(
dcheng36b6aec92015-12-26 06:16:362811 std::move(req),
amistry9f01b772015-07-29 01:54:552812 base::Bind(&DidDownloadImage, callback, download_id, url));
2813 return download_id;
[email protected]795c28972012-12-06 06:13:392814}
2815
[email protected]5dcaf8e2013-12-28 01:31:422816bool WebContentsImpl::IsSubframe() const {
2817 return is_subframe_;
2818}
2819
[email protected]36ec24f2014-01-09 00:32:082820void WebContentsImpl::Find(int request_id,
2821 const base::string16& search_text,
2822 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332823 // Cowardly refuse to search for no text.
2824 if (search_text.empty()) {
2825 NOTREACHED();
2826 return;
2827 }
2828
raymes0fa0be52014-10-13 20:38:092829 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472830 if (browser_plugin_embedder_ &&
2831 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2832 return;
raymes0fa0be52014-10-13 20:38:092833 }
[email protected]36ec24f2014-01-09 00:32:082834 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2835}
2836
2837void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012838 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472839 if (browser_plugin_embedder_ &&
2840 browser_plugin_embedder_->StopFinding(action)) {
2841 return;
raymes2bc64182015-02-06 01:23:012842 }
[email protected]36ec24f2014-01-09 00:32:082843 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2844}
2845
[email protected]4fe53add2014-04-08 19:53:362846void WebContentsImpl::InsertCSS(const std::string& css) {
2847 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2848 GetMainFrame()->GetRoutingID(), css));
2849}
2850
dalecurtisbc6572e12014-09-12 19:22:302851bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152852 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302853}
2854
mlamouriefdca9d2014-09-16 16:55:402855void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2856 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2857}
2858
dominickn6919ce32015-10-15 01:52:282859void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2860 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2861}
2862
mlamouri7a78d6fd2015-01-17 13:23:532863void WebContentsImpl::ExitFullscreen() {
2864 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432865 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
mlamouri7a78d6fd2015-01-17 13:23:532866 ExitFullscreenMode();
2867}
2868
mariakhomenko44bdc4732015-04-29 01:55:382869void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372870 if (delayed_open_url_params_.get()) {
2871 OpenURL(*delayed_open_url_params_.get());
2872 delayed_open_url_params_.reset(nullptr);
2873 return;
2874 }
2875
mariakhomenko44bdc4732015-04-29 01:55:382876 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2877 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162878 if (is_resume_pending_) {
2879 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:132880 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:162881 GetMainFrame()->Init();
2882 }
mariakhomenko44bdc4732015-04-29 01:55:382883}
2884
[email protected]b172aee2012-04-10 17:05:262885bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272886 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172887 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332888 return true;
2889 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272890}
2891
[email protected]b172aee2012-04-10 17:05:262892void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272893 if (delegate_)
2894 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212895}
2896
clamy0e119882015-07-31 16:12:332897void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2898 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2899 DidStartNavigation(navigation_handle));
2900}
2901
2902void WebContentsImpl::DidRedirectNavigation(
2903 NavigationHandle* navigation_handle) {
2904 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2905 DidRedirectNavigation(navigation_handle));
2906}
2907
clamyefca29e2015-09-17 00:22:112908void WebContentsImpl::ReadyToCommitNavigation(
2909 NavigationHandle* navigation_handle) {
2910 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2911 ReadyToCommitNavigation(navigation_handle));
2912}
2913
clamy0e119882015-07-31 16:12:332914void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
2915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2916 DidFinishNavigation(navigation_handle));
2917}
2918
[email protected]52913802013-12-10 05:52:182919void WebContentsImpl::DidStartProvisionalLoad(
2920 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182921 const GURL& validated_url,
2922 bool is_error_page,
2923 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102924 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482925 FOR_EACH_OBSERVER(
2926 WebContentsObserver,
2927 observers_,
2928 DidStartProvisionalLoadForFrame(
2929 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082930
2931 // Notify accessibility if this is a reload.
2932 NavigationEntry* entry = controller_.GetVisibleEntry();
2933 if (entry && ui::PageTransitionCoreTypeIs(
2934 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2935 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2936 BrowserAccessibilityManager* manager =
2937 ftn->current_frame_host()->browser_accessibility_manager();
2938 if (manager)
2939 manager->UserIsReloading();
2940 }
[email protected]400992b2012-06-14 00:03:542941}
2942
[email protected]3109fbb72014-01-06 23:57:152943void WebContentsImpl::DidFailProvisionalLoadWithError(
2944 RenderFrameHostImpl* render_frame_host,
2945 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2946 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312947 FOR_EACH_OBSERVER(WebContentsObserver,
2948 observers_,
2949 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312950 validated_url,
2951 params.error_code,
gsennton6fbb38692015-06-24 19:23:552952 params.error_description,
2953 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:082954
2955 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2956 BrowserAccessibilityManager* manager =
2957 ftn->current_frame_host()->browser_accessibility_manager();
2958 if (manager)
2959 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152960}
2961
[email protected]b80624c2014-02-09 02:46:552962void WebContentsImpl::DidFailLoadWithError(
2963 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552964 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552965 int error_code,
gsennton6fbb38692015-06-24 19:23:552966 const base::string16& error_description,
2967 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:142968 FOR_EACH_OBSERVER(
2969 WebContentsObserver,
2970 observers_,
gsennton6fbb38692015-06-24 19:23:552971 DidFailLoad(render_frame_host, url, error_code, error_description,
2972 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:552973}
2974
[email protected]52913802013-12-10 05:52:182975void WebContentsImpl::NotifyChangedNavigationState(
2976 InvalidateTypes changed_flags) {
2977 NotifyNavigationStateChanged(changed_flags);
2978}
2979
[email protected]3691e5cf2014-01-22 10:16:202980void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:202981 const GURL& url,
2982 NavigationController::ReloadType reload_type) {
2983 // Notify observers about navigation.
2984 FOR_EACH_OBSERVER(
2985 WebContentsObserver,
2986 observers_,
2987 DidStartNavigationToPendingEntry(url, reload_type));
2988}
2989
[email protected]8cb834e2014-03-06 14:23:232990void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2991 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502992 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2993 // weak pointer of sorts.
2994 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2995 const int32_t frame_id = render_frame_host->GetRoutingID();
2996
[email protected]65920f332014-03-04 21:14:182997 WebContents* new_contents = OpenURL(params);
2998
dchengb907f7332015-01-07 20:35:502999 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183000 // Notify observers.
3001 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3002 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463003 render_frame_host,
[email protected]65920f332014-03-04 21:14:183004 params.url,
3005 params.referrer,
3006 params.disposition,
creis114ca1b2014-11-13 23:51:463007 params.transition));
[email protected]65920f332014-03-04 21:14:183008 }
3009}
3010
creis29460272015-12-16 04:38:223011bool WebContentsImpl::ShouldTransferNavigation() {
3012 if (!delegate_)
3013 return true;
3014 return delegate_->ShouldTransferNavigation();
3015}
3016
[email protected]aa62afd2014-04-22 19:22:463017bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3018 if (!delegate_)
3019 return false;
3020 return delegate_->ShouldPreserveAbortedURLs(this);
3021}
3022
[email protected]37567b432014-02-12 01:12:223023void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433024 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223025 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353026 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223027 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483028 FOR_EACH_OBSERVER(WebContentsObserver,
3029 observers_,
3030 DidCommitProvisionalLoadForFrame(
3031 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083032
3033 BrowserAccessibilityManager* manager =
3034 render_frame_host->browser_accessibility_manager();
3035 if (manager)
3036 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223037}
3038
[email protected]0d0f4c492014-04-02 06:42:573039void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233040 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573041 // Ensure fullscreen mode is exited before committing the navigation to a
3042 // different page. The next page will not start out assuming it is in
3043 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233044 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193045 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573046 return;
3047 }
avibf58fa0c2015-11-11 01:45:523048 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
mlamouri7a78d6fd2015-01-17 13:23:533049 ExitFullscreen();
avibf58fa0c2015-11-11 01:45:523050 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573051}
3052
[email protected]37567b432014-02-12 01:12:223053void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283054 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223055 const LoadCommittedDetails& details,
3056 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3057 if (details.is_navigation_to_different_page()) {
3058 // Clear the status bubble. This is a workaround for a bug where WebKit
3059 // doesn't let us know that the cursor left an element during a
3060 // transition (this is also why the mouse cursor remains as a hand after
3061 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3062 // clear the bubble when a user navigates to a named anchor in the same
3063 // page.
sky8b00392d2015-01-10 00:30:283064 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003065
3066 RenderWidgetHostViewBase* rwhvb =
3067 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3068 if (rwhvb)
3069 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283070
peter90afaba2015-06-01 12:05:293071 did_first_visually_non_empty_paint_ = false;
3072
yusufod41c5f92015-03-06 00:14:283073 // Reset theme color on navigation to new page.
3074 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223075 }
3076
3077 if (!details.is_in_page) {
3078 // Once the main frame is navigated, we're no longer considered to have
3079 // displayed insecure content.
3080 displayed_insecure_content_ = false;
3081 SSLManager::NotifySSLInternalStateChanged(
3082 GetController().GetBrowserContext());
3083 }
3084
3085 // Notify observers about navigation.
3086 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3087 DidNavigateMainFrame(details, params));
3088
[email protected]e85165c642014-06-10 14:34:313089 if (delegate_)
[email protected]37567b432014-02-12 01:12:223090 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313091 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223092}
3093
3094void WebContentsImpl::DidNavigateAnyFramePostCommit(
3095 RenderFrameHostImpl* render_frame_host,
3096 const LoadCommittedDetails& details,
3097 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103098 // Now that something has committed, we don't need to track whether the
3099 // initial page has been accessed.
3100 has_accessed_initial_document_ = false;
3101
[email protected]37567b432014-02-12 01:12:223102 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173103 if (!details.is_in_page)
3104 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223105
3106 // Notify observers about navigation.
3107 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093108 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223109}
3110
3111void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3112 contents_mime_type_ = mime_type;
3113}
3114
[email protected]277857a2014-06-03 10:38:013115bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313116 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053117 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313118 return false;
3119
[email protected]37567b432014-02-12 01:12:223120 if (delegate_)
3121 return delegate_->CanOverscrollContent();
3122
3123 return false;
3124}
3125
[email protected]37b64c52014-07-11 21:14:053126void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293127 // Update the theme color. This is to be published to observers after the
3128 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283129 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293130
3131 if (did_first_visually_non_empty_paint_ &&
3132 last_sent_theme_color_ != theme_color_) {
3133 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3134 DidChangeThemeColor(theme_color_));
3135 last_sent_theme_color_ = theme_color_;
3136 }
[email protected]e7104762014-06-20 19:17:253137}
3138
[email protected]b172aee2012-04-10 17:05:263139void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183140 const GURL& url,
[email protected]70435962011-08-02 20:13:283141 const std::string& security_info,
3142 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183143 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403144 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533145 SSLStatus status;
3146 if (!DeserializeSecurityInfo(security_info, &status)) {
3147 bad_message::ReceivedBadMessage(
3148 GetRenderProcessHost(),
3149 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3150 return;
3151 }
[email protected]724159a2010-12-30 01:11:183152
3153 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593154 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213155 LoadFromMemoryCacheDetails details(
avie0d90182015-07-08 19:33:593156 url, GetRenderProcessHost()->GetID(), status.cert_id, status.cert_status,
3157 http_method, mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:183158
[email protected]b0f724c2013-09-05 04:21:133159 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3160
3161 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3162 DidLoadResourceFromMemoryCache(details));
3163
[email protected]8bfc8272013-09-09 20:10:533164 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3165 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403166 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533167 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3168 GetRenderProcessHost()->GetID()) :
3169 GetBrowserContext()->GetRequestContextForRenderProcess(
3170 GetRenderProcessHost()->GetID()));
3171 BrowserThread::PostTask(
3172 BrowserThread::IO,
3173 FROM_HERE,
3174 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3175 }
[email protected]724159a2010-12-30 01:11:183176}
3177
[email protected]b172aee2012-04-10 17:05:263178void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393179 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183180 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193181 SSLManager::NotifySSLInternalStateChanged(
3182 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183183}
3184
estark910b4572015-12-09 20:55:413185void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3186 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583187 LOG(WARNING) << security_origin << " ran insecure content from "
3188 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393189 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413190 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293191 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393192 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183193 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193194 SSLManager::NotifySSLInternalStateChanged(
3195 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183196}
3197
estark910b4572015-12-09 20:55:413198void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3199 const GURL& url,
3200 const std::string& security_info) {
3201 SSLStatus ssl;
3202 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3203 bad_message::ReceivedBadMessage(
3204 GetRenderProcessHost(),
3205 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3206 return;
3207 }
3208
3209 displayed_insecure_content_ = true;
3210 SSLManager::NotifySSLInternalStateChanged(
3211 GetController().GetBrowserContext());
3212}
3213
3214void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3215 const GURL& security_origin,
3216 const GURL& url,
3217 const std::string& security_info) {
3218 SSLStatus ssl;
3219 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3220 bad_message::ReceivedBadMessage(
3221 GetRenderProcessHost(),
3222 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3223 return;
3224 }
3225
3226 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3227 SSLManager::NotifySSLInternalStateChanged(
3228 GetController().GetBrowserContext());
3229}
3230
[email protected]501052ff2014-02-21 22:19:073231void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113232 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473233 return;
naskofbd033392015-01-27 02:34:473234
[email protected]1d62cf72014-02-07 21:31:573235 RenderFrameHostImpl* rfh =
3236 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143237 FOR_EACH_OBSERVER(
3238 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183239}
3240
naskofbd033392015-01-27 02:34:473241void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113242 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123243 return;
[email protected]a1b99262013-12-27 21:56:223244
[email protected]8b3af1e2014-01-24 13:29:123245 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443246 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373247 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423248 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373249
[email protected]61ac9e242014-03-21 20:55:263250 RenderFrameHostImpl* rfh =
3251 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143252 FOR_EACH_OBSERVER(
3253 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313254}
3255
[email protected]b172aee2012-04-10 17:05:263256void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573257 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3258 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263259}
3260
[email protected]b172aee2012-04-10 17:05:263261void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303262 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263263 minimum_zoom_percent_ = minimum_percent;
3264 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263265}
3266
mcnee432e47d2015-11-09 19:37:463267void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3268 bool is_one = page_scale_factor == 1.f;
3269 if (is_one != page_scale_factor_is_one_) {
3270 page_scale_factor_is_one_ = is_one;
3271
3272 HostZoomMapImpl* host_zoom_map =
3273 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3274
3275 if (host_zoom_map && GetRenderProcessHost()) {
3276 host_zoom_map->SetPageScaleFactorIsOneForView(
3277 GetRenderProcessHost()->GetID(), GetRoutingID(),
3278 page_scale_factor_is_one_);
3279 }
3280 }
3281
3282 FOR_EACH_OBSERVER(WebContentsObserver,
3283 observers_,
3284 OnPageScaleFactorChanged(page_scale_factor));
3285}
3286
[email protected]b172aee2012-04-10 17:05:263287void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343288 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433289 if (!delegate_)
3290 return;
3291
[email protected]b9535422012-02-09 01:47:593292 ChildProcessSecurityPolicyImpl* policy =
3293 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223294 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593295 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213296}
3297
[email protected]b172aee2012-04-10 17:05:263298void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3299 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263300 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363301 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433302 if (!delegate_)
3303 return;
3304
[email protected]b9535422012-02-09 01:47:593305 ChildProcessSecurityPolicyImpl* policy =
3306 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323307 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593308 return;
[email protected]8f810632013-06-06 22:33:323309
[email protected]c125e532014-05-10 20:39:063310 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203311}
3312
[email protected]f5273e52014-07-14 16:30:203313void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3314 const GURL& url,
3315 bool user_gesture) {
3316 if (!delegate_)
3317 return;
3318
3319 ChildProcessSecurityPolicyImpl* policy =
3320 ChildProcessSecurityPolicyImpl::GetInstance();
3321 if (policy->IsPseudoScheme(protocol))
3322 return;
3323
3324 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3325}
3326
kouhei40f03cb2015-09-24 07:47:013327void WebContentsImpl::OnUpdatePageImportanceSignals(
3328 const PageImportanceSignals& signals) {
3329 page_importance_signals_ = signals;
3330}
3331
[email protected]b172aee2012-04-10 17:05:263332void WebContentsImpl::OnFindReply(int request_id,
3333 int number_of_matches,
3334 const gfx::Rect& selection_rect,
3335 int active_match_ordinal,
3336 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433337 if (delegate_) {
3338 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3339 active_match_ordinal, final_update);
3340 }
[email protected]b888919c2011-09-02 00:32:163341}
3342
mfomitchev841f8182015-11-07 02:03:193343#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]59363fc92012-09-05 03:46:313344void WebContentsImpl::OnFindMatchRectsReply(
3345 int version,
3346 const std::vector<gfx::RectF>& rects,
3347 const gfx::RectF& active_rect) {
3348 if (delegate_)
3349 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3350}
[email protected]583418cc2013-01-17 14:01:103351
[email protected]1ff427972013-02-07 21:14:073352void WebContentsImpl::OnOpenDateTimeDialog(
3353 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173354 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093355 GetRenderViewHost(),
3356 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133357 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093358 value.minimum,
3359 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173360 value.step,
3361 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103362}
[email protected]59363fc92012-09-05 03:46:313363#endif
3364
avi60bd4902015-09-23 20:39:243365void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3366 std::string json = json_string;
3367 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3368 Source<WebContents>(this),
3369 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403370}
3371
[email protected]b172aee2012-04-10 17:05:263372void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3373 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103374 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253375 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103376 AppCacheAccessed(manifest_url, blocked_by_policy));
3377}
3378
[email protected]8bc5ff02013-11-29 06:34:033379void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483380 int color_chooser_id,
3381 SkColor color,
3382 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113383 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003384 return;
nasko907fcb62015-01-28 04:24:113385
[email protected]aa62afd2014-04-22 19:22:463386 ColorChooser* new_color_chooser = delegate_ ?
3387 delegate_->OpenColorChooser(this, color, suggestions) :
3388 NULL;
[email protected]820957a2014-01-14 14:56:303389 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213390 return;
[email protected]8ed16472014-04-11 19:02:483391 if (color_chooser_info_.get())
3392 color_chooser_info_->chooser->End();
3393
3394 color_chooser_info_.reset(new ColorChooserInfo(
3395 render_frame_message_source_->GetProcess()->GetID(),
3396 render_frame_message_source_->GetRoutingID(),
3397 new_color_chooser,
3398 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203399}
3400
[email protected]b172aee2012-04-10 17:05:263401void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483402 if (color_chooser_info_ &&
3403 color_chooser_id == color_chooser_info_->identifier)
3404 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203405}
3406
[email protected]b172aee2012-04-10 17:05:263407void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323408 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483409 if (color_chooser_info_ &&
3410 color_chooser_id == color_chooser_info_->identifier)
3411 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203412}
3413
[email protected]d0759f492012-04-19 22:50:503414// This exists for render views that don't have a WebUI, but do have WebUI
3415// bindings enabled.
3416void WebContentsImpl::OnWebUISend(const GURL& source_url,
3417 const std::string& name,
3418 const base::ListValue& args) {
3419 if (delegate_)
3420 delegate_->WebUISend(this, source_url, name, args);
3421}
3422
thestigc4cac8f2014-09-04 21:17:503423#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003424void WebContentsImpl::OnPepperInstanceCreated() {
3425 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3426}
3427
3428void WebContentsImpl::OnPepperInstanceDeleted() {
3429 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3430}
3431
tommyclie6633ca72014-10-31 00:40:423432void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3433 const base::FilePath& path,
3434 bool is_hung) {
3435 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3436
3437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3438 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3439}
3440
3441void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3442 base::ProcessId plugin_pid) {
3443 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3444 PluginCrashed(plugin_path, plugin_pid));
3445}
3446
[email protected]d8415ad92012-08-23 14:40:503447void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443448 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503449 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343450 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163451 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443452 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163453 return;
[email protected]d8415ad92012-08-23 14:40:503454 }
3455
[email protected]8c8fc292012-11-23 18:57:163456 if (!delegate_->RequestPpapiBrokerPermission(
3457 this, url, plugin_path,
3458 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443459 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163460 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443461 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163462 }
[email protected]d8415ad92012-08-23 14:40:503463}
3464
[email protected]ea0309c2013-08-06 19:35:443465void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503466 bool result) {
[email protected]ea0309c2013-08-06 19:35:443467 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503468}
3469
fsamuel833ee7c2015-02-13 23:40:403470void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3471 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393472 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143473 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403474 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373475}
tommyclie6633ca72014-10-31 00:40:423476#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373477
[email protected]795c28972012-12-06 06:13:393478void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393479 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063480 // We get updated favicon URLs after the page stops loading. If a cross-site
3481 // navigation occurs while a page is still loading, the initial page
3482 // may stop loading and send us updated favicon URLs after the navigation
3483 // for the new page has committed.
3484 RenderViewHostImpl* rvhi =
3485 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3486 if (!rvhi->is_active())
3487 return;
3488
[email protected]795c28972012-12-06 06:13:393489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293490 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393491}
3492
avayvod41634b12015-07-08 17:07:053493#if defined(OS_ANDROID)
3494
3495void WebContentsImpl::OnMediaSessionStateChanged() {
3496 MediaSession* session = MediaSession::Get(this);
3497 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3498 MediaSessionStateChanged(session->IsControllable(),
3499 session->IsSuspended()));
3500}
3501
3502void WebContentsImpl::ResumeMediaSession() {
3503 MediaSession::Get(this)->Resume();
3504}
3505
3506void WebContentsImpl::SuspendMediaSession() {
3507 MediaSession::Get(this)->Suspend();
3508}
3509
mlamouri4c4fbed2015-08-17 15:51:013510void WebContentsImpl::StopMediaSession() {
3511 MediaSession::Get(this)->Stop();
3512}
3513
avayvod41634b12015-07-08 17:07:053514#endif // defined(OS_ANDROID)
3515
[email protected]50279492014-05-05 23:24:293516void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153517 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293518 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283519
peter90afaba2015-06-01 12:05:293520 did_first_visually_non_empty_paint_ = true;
3521
yusufod41c5f92015-03-06 00:14:283522 if (theme_color_ != last_sent_theme_color_) {
3523 // Theme color should have updated by now if there was one.
3524 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3525 DidChangeThemeColor(theme_color_));
3526 last_sent_theme_color_ = theme_color_;
3527 }
[email protected]9f268072013-11-07 00:02:153528}
[email protected]d9030b82013-07-19 08:26:063529
[email protected]e67ebf32013-02-13 11:07:193530void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013531 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073532 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013533
estark5ea80e52015-06-19 18:43:123534 SecurityStyleExplanations security_style_explanations;
3535 SecurityStyle security_style =
3536 delegate_->GetSecurityStyle(this, &security_style_explanations);
3537 FOR_EACH_OBSERVER(
3538 WebContentsObserver, observers_,
3539 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013540 }
[email protected]e67ebf32013-02-13 11:07:193541}
3542
[email protected]17e286e2013-03-01 23:29:393543void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3544 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3545 BeforeFormRepostWarningShow());
3546}
3547
[email protected]ec6c05f2013-10-23 18:41:573548void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3549 Activate();
3550 if (delegate_)
3551 delegate_->ShowRepostFormWarningDialog(this);
3552}
3553
[email protected]b4c84012014-04-28 19:51:103554bool WebContentsImpl::HasAccessedInitialDocument() {
3555 return has_accessed_initial_document_;
3556}
3557
[email protected]96d185d2009-04-24 03:28:543558// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593559// loading, or done loading.
fdegans6ce28f52015-03-19 12:52:223560void WebContentsImpl::SetIsLoading(bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093561 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263562 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543563 if (is_loading == is_loading_)
3564 return;
3565
3566 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263567 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3568 base::string16());
[email protected]96d185d2009-04-24 03:28:543569 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563570 upload_size_ = 0;
3571 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543572 }
3573
[email protected]fa944cb82013-11-15 17:51:213574 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543575
3576 is_loading_ = is_loading;
3577 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033578 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543579
[email protected]6ebdc9b2010-09-27 16:55:573580 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093581 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213582 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543583
[email protected]eab61442013-11-14 18:35:483584 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593585 if (is_loading) {
naskob8744d22014-08-28 17:07:433586 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3587 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223588 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593589 } else {
naskob8744d22014-08-28 17:07:433590 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3591 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223592 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593593 }
[email protected]66798902013-10-01 18:40:163594
3595 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213596 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3597 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543598 if (details)
[email protected]8ff00d72012-10-23 19:12:213599 det = Details<LoadNotificationDetails>(details);
3600 NotificationService::current()->Notify(
3601 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543602}
3603
[email protected]b172aee2012-04-10 17:05:263604void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463605 // If we are creating a RVH for a restored controller, then we need to make
3606 // sure the RenderView starts with a next_page_id_ larger than the number
3607 // of restored entries. This must be called before the RenderView starts
3608 // navigating (to avoid a race between the browser updating max_page_id and
3609 // the renderer updating next_page_id_). Because of this, we only call this
3610 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563611 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583612 if (max_restored_page_id >
3613 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3614 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3615 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323616}
3617
[email protected]b172aee2012-04-10 17:05:263618bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263619 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323620 // For file URLs without a title, use the pathname instead. In the case of a
3621 // synthesized title, we don't want the update to count toward the "one set
3622 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263623 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323624 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513625 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243626 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323627 explicit_set = false; // Don't count synthetic titles toward the set limit.
3628 } else {
[email protected]8af69c6c2014-03-03 19:05:313629 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323630 explicit_set = true;
3631 }
3632
[email protected]987fc3a2011-05-26 14:18:093633 // If a page is created via window.open and never navigated,
3634 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553635 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093636 if (entry) {
[email protected]36fc0392011-12-25 03:59:513637 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093638 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323639
[email protected]36fc0392011-12-25 03:59:513640 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093641 } else {
3642 if (page_title_when_no_navigation_entry_ == final_title)
3643 return false; // Nothing changed, don't bother.
3644
3645 page_title_when_no_navigation_entry_ = final_title;
3646 }
[email protected]420ae012009-04-24 05:16:323647
[email protected]420ae012009-04-24 05:16:323648 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233649 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323650
[email protected]66798902013-10-01 18:40:163651 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533652 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163653
[email protected]420ae012009-04-24 05:16:323654 return true;
3655}
3656
fdegansa696e5112015-04-17 01:57:593657void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003658 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003659 if (delegate_)
fdegansa696e5112015-04-17 01:57:593660 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003661}
3662
3663void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343664 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003665 loading_weak_factory_.InvalidateWeakPtrs();
3666 loading_last_progress_update_ = base::TimeTicks();
3667}
3668
[email protected]02d7b6e2014-06-24 21:01:503669void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3670 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323671 // After sending out a swap notification, we need to send a disconnect
3672 // notification so that clients that pick up a pointer to |this| can NULL the
3673 // pointer. See Bug 1230284.
3674 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113675 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283676 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113677
[email protected]7a846df2012-09-20 19:17:393678 // Ensure that the associated embedder gets cleared after a RenderViewHost
3679 // gets swapped, so we don't reuse the same embedder next time a
3680 // RenderViewHost is attached to this WebContents.
3681 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323682}
3683
[email protected]02d7b6e2014-06-24 21:01:503684void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3685 RenderFrameHost* new_host) {
3686 FOR_EACH_OBSERVER(WebContentsObserver,
3687 observers_,
3688 RenderFrameHostChanged(old_host, new_host));
3689}
3690
[email protected]da7a7182013-09-06 08:11:113691// TODO(avi): Remove this entire function because this notification is already
3692// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263693void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323694 if (!notify_disconnection_)
3695 return;
3696
3697 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213698 NotificationService::current()->Notify(
3699 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3700 Source<WebContents>(this),
3701 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323702}
3703
[email protected]cbb1ef592013-06-05 19:49:463704void WebContentsImpl::NotifyNavigationEntryCommitted(
3705 const LoadCommittedDetails& load_details) {
3706 FOR_EACH_OBSERVER(
3707 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3708}
3709
[email protected]f114fa42013-12-06 17:06:443710bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3711 const IPC::Message& message) {
3712 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313713}
3714
[email protected]c31a84802014-04-03 15:55:493715const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3716 return GetLastCommittedURL();
3717}
3718
[email protected]b849847b2013-12-10 21:57:583719void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583720 FOR_EACH_OBSERVER(WebContentsObserver,
3721 observers_,
3722 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303723 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583724}
3725
3726void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3727 FOR_EACH_OBSERVER(WebContentsObserver,
3728 observers_,
3729 RenderFrameDeleted(render_frame_host));
3730}
3731
[email protected]a09d53ce2014-01-31 00:46:423732void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3733 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103734 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423735 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103736 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423737 return;
3738
[email protected]077e704b2014-05-23 19:24:103739 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3740 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423741}
3742
[email protected]87de04b02014-04-08 22:14:493743void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013744 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493745 const base::string16& message,
3746 const base::string16& default_prompt,
3747 const GURL& frame_url,
3748 JavaScriptMessageType javascript_message_type,
3749 IPC::Message* reply_msg) {
3750 // Suppress JavaScript dialogs when requested. Also suppress messages when
3751 // showing an interstitial as it's shown over the previous page and we don't
3752 // want the hidden page's dialogs to interfere with the interstitial.
3753 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223754 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503755 ShowingInterstitialPage() || !delegate_ ||
3756 delegate_->ShouldSuppressDialogs(this) ||
3757 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493758
3759 if (!suppress_this_message) {
3760 std::string accept_lang = GetContentClient()->browser()->
3761 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503762 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493763 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413764 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493765 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413766 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013767 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413768 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493769 &suppress_this_message);
3770 }
3771
3772 if (suppress_this_message) {
3773 // If we are suppressing messages, just reply as if the user immediately
3774 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013775 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3776 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283777 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493778 }
3779
3780 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3781 // http://crbug.com/288961 ). The only safe thing to do here is return.
3782}
3783
3784void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013785 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493786 const base::string16& message,
3787 bool is_reload,
3788 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013789 RenderFrameHostImpl* rfhi =
3790 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493791 if (delegate_)
3792 delegate_->WillRunBeforeUnloadConfirm();
3793
3794 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023795 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3796 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503797 delegate_->ShouldSuppressDialogs(this) ||
3798 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493799 if (suppress_this_message) {
3800 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3801 return;
3802 }
3803
3804 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503805 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493806 dialog_manager_->RunBeforeUnloadDialog(
3807 this, message, is_reload,
3808 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013809 render_frame_host->GetProcess()->GetID(),
3810 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283811 false));
[email protected]87de04b02014-04-08 22:14:493812}
3813
[email protected]a86c0e962013-12-17 17:10:393814WebContents* WebContentsImpl::GetAsWebContents() {
3815 return this;
3816}
3817
[email protected]7912e822014-04-16 02:37:033818bool WebContentsImpl::IsNeverVisible() {
3819 if (!delegate_)
3820 return false;
3821 return delegate_->IsNeverVisible(this);
3822}
3823
[email protected]95640212014-07-26 18:14:303824#if defined(OS_WIN)
3825gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3826 return accessible_parent_;
3827}
3828#endif
3829
[email protected]5a3bdf52012-05-24 15:12:573830RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3831 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323832}
3833
[email protected]8ff00d72012-10-23 19:12:213834RendererPreferences WebContentsImpl::GetRendererPrefs(
3835 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463836 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513837}
3838
avic3aa8422015-11-09 20:57:223839gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3840 RenderWidgetHostImpl* render_widget_host) const {
3841 if (!RenderViewHostImpl::From(render_widget_host))
3842 return gfx::Rect();
3843
[email protected]b7a756d42012-01-23 18:08:173844 if (delegate_)
3845 return delegate_->GetRootWindowResizerRect();
3846 return gfx::Rect();
3847}
3848
[email protected]7a846df2012-09-20 19:17:393849void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273850 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393851 browser_plugin_embedder_.reset();
3852}
3853
[email protected]b172aee2012-04-10 17:05:263854void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443855 // Don't send notifications if we are just creating a swapped-out RVH for
3856 // the opener chain. These won't be used for view-source or WebUI, so it's
3857 // ok to return early.
creiscce56cd2014-09-29 22:45:223858 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443859 return;
3860
[email protected]86f98a22013-03-20 14:35:003861 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313862 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083863
[email protected]8ff00d72012-10-23 19:12:213864 NotificationService::current()->Notify(
3865 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3866 Source<WebContents>(this),
3867 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323868
[email protected]6286a372013-10-09 04:03:273869 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333870 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323871 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183872 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583873 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323874 }
[email protected]0666aef2009-05-13 19:48:083875
[email protected]60780f412013-02-25 16:34:103876 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263877
3878 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253879 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323880}
3881
[email protected]b172aee2012-04-10 17:05:263882void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523883 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323884 // Don't notify the world, since this came from a renderer in the
3885 // background.
3886 return;
3887 }
3888
[email protected]da7a7182013-09-06 08:11:113889 notify_disconnection_ = true;
3890 // TODO(avi): Remove. http://crbug.com/170921
3891 NotificationService::current()->Notify(
3892 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3893 Source<WebContents>(this),
3894 NotificationService::NoDetails());
3895
[email protected]be1f56ab2011-12-22 06:55:313896 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233897 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303898
3899 // Restore the focus to the tab (otherwise the focus will be on the top
3900 // window).
[email protected]484ae5912010-09-29 19:16:143901 if (was_crashed && !FocusLocationBarByDefault() &&
3902 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063903 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143904 }
[email protected]32ded2212011-11-10 18:51:433905
[email protected]d8c660432011-12-22 20:51:253906 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323907}
3908
[email protected]ec6a7eb2013-04-22 17:34:223909void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3910 base::TerminationStatus status,
3911 int error_code) {
[email protected]151a63d2011-12-20 22:32:523912 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323913 // The pending page's RenderViewHost is gone.
3914 return;
3915 }
3916
[email protected]2fcdcc32014-03-05 02:14:073917 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3918 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:523919 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
mlamouri7a78d6fd2015-01-17 13:23:533920 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073921
[email protected]698191dc2014-02-25 01:06:133922 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173923 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133924
[email protected]f738bdcb2014-07-11 20:40:443925 if (delegate_)
3926 delegate_->HideValidationMessage(this);
3927
fdegans6ce28f52015-03-19 12:52:223928 SetIsLoading(false, true, nullptr);
[email protected]420ae012009-04-24 05:16:323929 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233930 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453931
[email protected]960b0372014-05-19 18:01:003932 // Reset the loading progress. TODO(avi): What does it mean to have a
3933 // "renderer crash" when there is more than one renderer process serving a
3934 // webpage? Once this function is called at a more granular frame level, we
3935 // probably will need to more granularly reset the state here.
3936 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003937
[email protected]d8c660432011-12-22 20:51:253938 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273939 observers_,
[email protected]58d5cfe2013-07-10 02:40:523940 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323941}
3942
[email protected]b172aee2012-04-10 17:05:263943void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253944 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063945}
3946
[email protected]b172aee2012-04-10 17:05:263947void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:103948 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:043949 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:383950 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
3951
creise1d3e5b2014-12-01 18:21:573952 // Ensure that this state update comes from a RenderViewHost that belongs to
3953 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413954 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:573955 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413956 return;
[email protected]420ae012009-04-24 05:16:323957
avi286019ce2015-07-29 01:26:583958 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:323959 // when the user is scrolling and entering form data, as well as when we're
3960 // leaving a page, in which case our state may have already been moved to
3961 // the next page. The navigation controller will look up the appropriate
3962 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:583963 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:113964 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:583965 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:113966 if (!entry)
[email protected]420ae012009-04-24 05:16:323967 return;
[email protected]420ae012009-04-24 05:16:323968
nasko346969912015-12-16 22:36:473969 // Sanity check that ensures nav_entry_id and page_id point to the same
3970 // navigation entry.
3971 if (rvhi->GetMainFrame()) {
3972 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
3973 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
3974 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:533975
nasko346969912015-12-16 22:36:473976 DCHECK_EQ(entry, new_entry);
3977 }
creisd63f6c4a2015-11-06 19:05:533978
[email protected]691aa2f2013-05-28 22:52:043979 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323980 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043981 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:113982 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:323983}
3984
sky8b00392d2015-01-10 00:30:283985void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3986 const GURL& url) {
3987 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3988 // If we're fullscreen only update the url if it's from the fullscreen
3989 // renderer.
3990 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:443991 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:283992 return;
3993 }
[email protected]6934a702011-12-20 00:04:513994 if (delegate_)
avi450ce00e2014-09-24 01:58:523995 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323996}
3997
[email protected]b172aee2012-04-10 17:05:263998void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103999#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294000 // The UI may be in an event-tracking loop, such as between the
4001 // mouse-down and mouse-up in text selection or a button click.
4002 // Defer the close until after tracking is complete, so that we
4003 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294004 // TODO(shess): This could get more fine-grained. For instance,
4005 // closing a tab in another window while selecting text in the
4006 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104007 if (view_->IsEventTracking()) {
4008 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294009 return;
4010 }
[email protected]60780f412013-02-25 16:34:104011#endif
[email protected]07707302009-11-06 00:50:294012
[email protected]420ae012009-04-24 05:16:324013 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524014 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514015 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324016}
4017
[email protected]66bbadaf2014-03-28 16:25:544018void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574019 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4020 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574021}
4022
[email protected]b172aee2012-04-10 17:05:264023void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514024 if (delegate_ && delegate_->IsPopupOrPanel(this))
4025 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324026}
4027
fdegansa696e5112015-04-17 01:57:594028void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094029 bool to_different_document) {
fdegans6ce28f52015-03-19 12:52:224030 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:084031
4032 // Notify accessibility that the user is navigating away from the
4033 // current document.
4034 //
4035 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084036 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594037 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084038 if (manager)
4039 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324040}
4041
fdegansc73eec22015-03-19 14:47:544042void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:324043 scoped_ptr<LoadNotificationDetails> details;
4044
[email protected]9595fd82013-04-19 21:28:494045 // Use the last committed entry rather than the active one, in case a
4046 // pending entry has been created.
4047 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204048 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494049
[email protected]420ae012009-04-24 05:16:324050 // An entry may not exist for a stop when loading an initial blank page or
4051 // if an iframe injected by script into a blank page finishes loading.
4052 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204053 base::TimeDelta elapsed =
4054 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324055
4056 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514057 entry->GetVirtualURL(),
4058 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324059 elapsed,
4060 &controller_,
4061 controller_.GetCurrentEntryIndex()));
4062 }
4063
fdegans6ce28f52015-03-19 12:52:224064 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:324065}
4066
fdegansa696e5112015-04-17 01:57:594067void WebContentsImpl::DidChangeLoadProgress() {
4068 double load_progress = frame_tree_.load_progress();
4069
4070 // The delegate is notified immediately for the first and last updates. Also,
4071 // since the message loop may be pretty busy when a page is loaded, it might
4072 // not execute a posted task in a timely manner so the progress report is sent
4073 // immediately if enough time has passed.
4074 base::TimeDelta min_delay =
4075 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4076 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4077 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4078
4079 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4080 // If there is a pending task to send progress, it is now obsolete.
4081 loading_weak_factory_.InvalidateWeakPtrs();
4082
4083 // Notify the load progress change.
4084 SendChangeLoadProgress();
4085
4086 // Clean-up the states if needed.
4087 if (load_progress == 1.0)
4088 ResetLoadProgressState();
4089 return;
4090 }
4091
4092 if (loading_weak_factory_.HasWeakPtrs())
4093 return;
4094
skyostil95082a62015-06-05 19:53:074095 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4096 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4097 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594098 min_delay);
4099}
4100
[email protected]b172aee2012-04-10 17:05:264101void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164102 controller_.DiscardNonCommittedEntries();
4103
4104 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214105 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164106}
4107
[email protected]59167c22013-06-03 18:07:324108void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104109 has_accessed_initial_document_ = true;
4110
[email protected]d1371bf8e2014-04-19 03:26:244111 // We may have left a failed browser-initiated navigation in the address bar
4112 // to let the user edit it and try again. Clear it now that content might
4113 // show up underneath it.
4114 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454115 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244116
[email protected]59167c22013-06-03 18:07:324117 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504118 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324119}
4120
alexmosbe2f4c32015-03-10 02:30:234121void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4122 const std::string& name) {
4123 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4124 FrameNameChanged(render_frame_host, name));
4125}
4126
[email protected]39f2f9252014-05-03 00:54:014127void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294128 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094129 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294130 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094131
4132 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214133 NotificationService::current()->Notify(
4134 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4135 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294136 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084137}
4138
creis8eb8ef22015-11-04 22:51:384139void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4140 const PageState& page_state) {
4141 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4142
4143 // The state update affects the last NavigationEntry associated with the given
4144 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4145 // in the case of an UpdateState from a frame being swapped out). We track
4146 // which entry this is in the RenderFrameHost's nav_entry_id.
4147 RenderFrameHostImpl* rfhi =
4148 static_cast<RenderFrameHostImpl*>(render_frame_host);
4149 NavigationEntryImpl* entry =
4150 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4151 if (!entry)
4152 return;
4153
4154 FrameNavigationEntry* frame_entry =
4155 entry->GetFrameEntry(rfhi->frame_tree_node());
4156 if (!frame_entry)
4157 return;
4158
creisd06a9422015-11-11 03:08:454159 // The SiteInstance might not match if we do a cross-process navigation with
4160 // replacement (e.g., auto-subframe), in which case the swap out of the old
4161 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4162 // has already been replaced and destroyed.
4163 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4164 return;
4165
creis8eb8ef22015-11-04 22:51:384166 if (page_state == frame_entry->page_state())
4167 return; // Nothing to update.
4168
4169 frame_entry->set_page_state(page_state);
4170 controller_.NotifyEntryChanged(entry);
4171}
4172
[email protected]ef3adfc2014-05-11 00:04:544173void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104174 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544175 const base::string16& title,
4176 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544177 // If we have a title, that's a pretty good indication that we've started
4178 // getting useful data.
4179 SetNotWaitingForResponse();
4180
4181 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584182 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544183 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584184 render_frame_host->GetSiteInstance(), page_id);
4185
creisd63f6c4a2015-11-06 19:05:534186 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4187 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
4188 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544189
4190 // We can handle title updates when we don't have an entry in
4191 // UpdateTitleForEntry, but only if the update is from the current RVH.
4192 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584193 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544194 return;
4195
4196 // TODO(evan): make use of title_direction.
4197 // http://code.google.com/p/chromium/issues/detail?id=27094
4198 if (!UpdateTitleForEntry(entry, title))
4199 return;
4200
4201 // Broadcast notifications when the UI should be updated.
4202 if (entry == controller_.GetEntryAtOffset(0))
4203 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4204}
4205
4206void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4207 const std::string& encoding) {
4208 SetEncoding(encoding);
4209}
4210
[email protected]39f2f9252014-05-03 00:54:014211void WebContentsImpl::DocumentAvailableInMainFrame(
4212 RenderViewHost* render_view_host) {
4213 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4214 DocumentAvailableInMainFrame());
4215}
naskoc0fceff2015-04-30 15:53:524216
[email protected]e1c3a552012-05-04 20:51:324217void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4218 // Tell the active RenderViewHost to run unload handlers and close, as long
4219 // as the request came from a RenderViewHost in the same BrowsingInstance.
4220 // In most cases, we receive this from a swapped out RenderViewHost.
4221 // It is possible to receive it from one that has just been swapped in,
4222 // in which case we might as well deliver the message anyway.
4223 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524224 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324225}
4226
alexmose7da5a12015-04-09 02:22:164227bool WebContentsImpl::ShouldRouteMessageEvent(
4228 RenderFrameHost* target_rfh,
4229 SiteInstance* source_site_instance) const {
4230 // Allow the message if this WebContents is dedicated to a browser plugin
4231 // guest.
[email protected]0eba810b2012-10-18 03:19:364232 // Note: This check means that an embedder could theoretically receive a
4233 // postMessage from anyone (not just its own guests). However, this is
4234 // probably not a risk for apps since other pages won't have references
4235 // to App windows.
alexmose7da5a12015-04-09 02:22:164236 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4237}
[email protected]f546640b2012-05-15 00:03:494238
alexmos58729042015-06-18 23:20:004239void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164240 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4241 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494242
alexmose7da5a12015-04-09 02:22:164243 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144244 // If this message is going to outer WebContents from inner WebContents,
4245 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4246 // already created a RenderFrameProxyHost for that purpose.
4247 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084248 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144249 return;
4250 }
4251
alexmose7da5a12015-04-09 02:22:164252 if (GetBrowserPluginGuest()) {
nasko5fb985b2015-08-20 17:28:164253 // We create a swapped out RenderView or RenderFrameProxyHost for the
4254 // embedder in the guest's render process but we intentionally do not
4255 // expose the embedder's opener chain to it.
4256 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
4257 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4258 GetSiteInstance());
4259 } else {
4260 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4261 }
[email protected]f546640b2012-05-15 00:03:494262 } else {
alexmos58729042015-06-18 23:20:004263 RenderFrameHostImpl* source_rfhi =
4264 static_cast<RenderFrameHostImpl*>(source_rfh);
4265 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394266 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494267 }
4268 }
[email protected]f546640b2012-05-15 00:03:494269}
4270
avib7348942015-12-25 20:57:104271bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264272 const base::string16& message,
avib7348942015-12-25 20:57:104273 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264274 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254275 if (!delegate_)
4276 return false;
4277 return delegate_->AddMessageToConsole(this, level, message, line_no,
4278 source_id);
4279}
4280
[email protected]0eba810b2012-10-18 03:19:364281int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214282 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294283 int render_view_routing_id = MSG_ROUTING_NONE;
nickac60e75472015-07-31 00:44:354284 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064285 GetRenderManager()->CreateRenderFrameProxy(instance);
4286 } else {
4287 GetRenderManager()->CreateRenderFrame(
carlosk35f35af2015-12-01 10:55:404288 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN,
nasko4c0feb62015-06-05 18:37:064289 &render_view_routing_id);
4290 }
carlosk37f793792014-11-27 15:08:294291 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364292}
4293
avic3aa8422015-11-09 20:57:224294void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) {
4295 if (render_widget_host != GetRenderViewHost()->GetWidget())
4296 return;
4297
[email protected]ddb85052011-05-18 14:40:274298 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254299 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224300
[email protected]ea114722012-03-12 01:11:254301 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174302 if (rdh) // NULL in unittests.
4303 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254304}
4305
dominickn2dd142dd2015-10-29 05:30:504306void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
4307 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4308 DidGetUserInteraction(type));
4309}
4310
[email protected]b172aee2012-04-10 17:05:264311void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444312 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254313 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444314}
4315
avic3aa8422015-11-09 20:57:224316void WebContentsImpl::RendererUnresponsive(
4317 RenderWidgetHostImpl* render_widget_host) {
[email protected]992db4c2011-05-12 15:37:154318 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224319 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154320 return;
4321
creiscce56cd2014-09-29 22:45:224322 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224323 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584324
[email protected]e5fc1632011-08-08 07:51:534325 // Ignore renderer unresponsive event if debugger is attached to the tab
4326 // since the event may be a result of the renderer sitting on a breakpoint.
4327 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364328 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534329 return;
4330
clamy226727e2015-06-29 10:28:474331 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224332 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324333 // Hang occurred while firing the beforeunload/unload handler.
4334 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224335 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324336
[email protected]fa944cb82013-11-15 17:51:214337 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324338 return;
4339
4340 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564341 // nothing we can do to recover. If the hang is in the beforeunload handler,
4342 // pretend the beforeunload listeners have all fired and allow the delegate
4343 // to continue closing; the user will not have the option of cancelling the
4344 // close. Otherwise, pretend the unload listeners have all fired and close
4345 // the tab.
4346 bool close = true;
clamy226727e2015-06-29 10:28:474347 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564348 delegate_->BeforeUnloadFired(this, true, &close);
4349 }
4350 if (close)
avic3aa8422015-11-09 20:57:224351 Close();
[email protected]420ae012009-04-24 05:16:324352 return;
4353 }
4354
creisc014b402015-04-23 16:41:454355 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474356 return;
4357
[email protected]6934a702011-12-20 00:04:514358 if (delegate_)
4359 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324360}
4361
avic3aa8422015-11-09 20:57:224362void WebContentsImpl::RendererResponsive(
4363 RenderWidgetHostImpl* render_widget_host) {
4364 if (render_widget_host != GetRenderViewHost()->GetWidget())
4365 return;
4366
[email protected]6934a702011-12-20 00:04:514367 if (delegate_)
4368 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324369}
4370
[email protected]b172aee2012-04-10 17:05:264371void WebContentsImpl::LoadStateChanged(
4372 const GURL& url,
4373 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104374 uint64_t upload_position,
4375 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544376 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4377 // is fixed.
4378 tracked_objects::ScopedTracker tracking_profile1(
4379 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4380 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324381 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564382 upload_position_ = upload_position;
4383 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214384 load_state_host_ = url_formatter::IDNToUnicode(
4385 url.host(),
4386 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214387 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324388 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464389 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224390 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4391 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464392 }
[email protected]420ae012009-04-24 05:16:324393}
4394
[email protected]b172aee2012-04-10 17:05:264395void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554396 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324397 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124398 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4399 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514400 if (delegate_)
4401 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094402 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324403}
4404
[email protected]58d5cfe2013-07-10 02:40:524405void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544406 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234407 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224408 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544409}
4410
[email protected]b172aee2012-04-10 17:05:264411void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104412 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214413 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264414 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4415 // here during container initialization and normal window size will be set
4416 // later. In case of tab duplication this resizing to 0x0 prevents setting
4417 // normal size later so just ignore it.
4418 if (!size.IsEmpty())
4419 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324420}
4421
[email protected]af905902013-10-01 21:38:514422void WebContentsImpl::CancelModalDialogsForRenderManager() {
4423 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544424 // deferrer would prevent us from swapping out. We also clear the state
4425 // because this is a cross-process navigation, which means that it's a new
4426 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174427 //
4428 // Note that we don't bother telling browser_plugin_embedder_ because the
4429 // cross-process navigation will either destroy the browser plugins or not
4430 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514431 if (dialog_manager_)
avi2460c762015-04-17 15:21:544432 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514433}
4434
[email protected]02d7b6e2014-06-24 21:01:504435void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4436 RenderFrameHost* new_host,
4437 bool is_main_frame) {
4438 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054439 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504440 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084441
[email protected]02d7b6e2014-06-24 21:01:504442 // Make sure the visible RVH reflects the new delegate's preferences.
4443 if (delegate_)
4444 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394445
[email protected]02d7b6e2014-06-24 21:01:504446 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4447 }
4448
4449 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544450}
4451
naskof5940b9f2015-03-02 23:04:054452void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4453 RenderViewHost* old_host,
4454 RenderViewHost* new_host) {
4455 NotifyViewSwapped(old_host, new_host);
4456}
4457
[email protected]b172aee2012-04-10 17:05:264458NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194459 return GetController();
[email protected]3a3d47472010-07-15 21:03:544460}
4461
carlosk35f35af2015-12-01 10:55:404462scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294463 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514464 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4465 url, std::string())));
[email protected]420ae012009-04-24 05:16:324466}
4467
[email protected]10f417c52011-12-28 21:04:234468NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264469 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324470 return controller_.GetLastCommittedEntry();
4471}
4472
lfgbede6392015-09-11 21:54:064473void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4474 RenderViewHost* render_view_host) {
4475 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144476 bool is_guest_in_site_per_process =
4477 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084478 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064479 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164480 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444481 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164482 rwh_view = rwh_view_child;
4483 } else {
avif9ab5d942015-10-15 14:05:444484 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164485 }
[email protected]1a98a932009-11-17 00:12:524486
[email protected]420ae012009-04-24 05:16:324487 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444488 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214489 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064490}
4491
4492bool WebContentsImpl::CreateRenderViewForRenderManager(
4493 RenderViewHost* render_view_host,
4494 int opener_frame_routing_id,
4495 int proxy_routing_id,
4496 const FrameReplicationState& replicated_frame_state) {
4497 TRACE_EVENT0("browser,navigation",
4498 "WebContentsImpl::CreateRenderViewForRenderManager");
4499
4500 if (proxy_routing_id == MSG_ROUTING_NONE)
4501 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324502
[email protected]74ce1ad2011-12-16 21:51:464503 // Make sure we use the correct starting page_id in the new RenderView.
4504 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104505 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584506 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464507
alexmos5ac402d2015-07-09 07:51:104508 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4509 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4510 max_page_id, replicated_frame_state,
4511 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524512 return false;
[email protected]14392a52012-05-02 20:28:444513 }
[email protected]a4127722011-04-27 23:13:524514
avi2b177592014-12-10 02:08:024515 SetHistoryOffsetAndLengthForView(render_view_host,
4516 controller_.GetLastCommittedEntryIndex(),
4517 controller_.GetEntryCount());
4518
[email protected]a220b5932013-09-21 03:47:444519#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504520 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4521 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444522 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444523 if (rwh_view) {
4524 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4525 render_widget_host->WasResized();
4526 }
[email protected]f8233cc2011-05-31 20:24:504527#endif
4528
[email protected]420ae012009-04-24 05:16:324529 return true;
4530}
4531
[email protected]82307f6b2014-08-07 03:30:124532bool WebContentsImpl::CreateRenderFrameForRenderManager(
4533 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044534 int proxy_routing_id,
4535 int opener_routing_id,
japhete6adf142014-10-31 00:01:494536 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044537 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434538 TRACE_EVENT0("browser,navigation",
4539 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124540
4541 RenderFrameHostImpl* rfh =
4542 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044543 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4544 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124545 return false;
4546
4547 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4548 // RenderFrameHost will have to be associated with the appropriate
4549 // RenderWidgetHostView or a new one should be created here.
4550
4551 return true;
4552}
4553
mfomitchev841f8182015-11-07 02:03:194554#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]fc2b46b2014-05-03 16:33:454555
[email protected]155c7f22013-12-09 17:07:184556base::android::ScopedJavaLocalRef<jobject>
4557WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404558 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564559 return GetWebContentsAndroid()->GetJavaObject();
4560}
[email protected]155c7f22013-12-09 17:07:184561
[email protected]0e813a52014-08-13 10:34:564562WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184563 WebContentsAndroid* web_contents_android =
4564 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4565 if (!web_contents_android) {
4566 web_contents_android = new WebContentsAndroid(this);
4567 SetUserData(kWebContentsAndroidKey, web_contents_android);
4568 }
[email protected]0e813a52014-08-13 10:34:564569 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184570}
4571
[email protected]7d244f12013-08-22 21:41:514572bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064573 return CreateRenderViewForRenderManager(
4574 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064575 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514576}
[email protected]fc2b46b2014-05-03 16:33:454577
4578#elif defined(OS_MACOSX)
4579
[email protected]75f4df72014-07-16 22:39:424580void WebContentsImpl::SetAllowOtherViews(bool allow) {
4581 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454582}
4583
[email protected]75f4df72014-07-16 22:39:424584bool WebContentsImpl::GetAllowOtherViews() {
4585 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454586}
4587
[email protected]7d244f12013-08-22 21:41:514588#endif
4589
[email protected]6fba26d2014-04-29 09:38:284590void WebContentsImpl::OnDialogClosed(int render_process_id,
4591 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264592 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494593 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264594 bool success,
[email protected]fcf75d42013-12-03 20:11:264595 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284596 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4597 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494598 last_dialog_suppressed_ = dialog_was_suppressed;
4599
[email protected]beb440c2009-11-06 04:08:544600 if (is_showing_before_unload_dialog_ && !success) {
4601 // If a beforeunload dialog is canceled, we need to stop the throbber from
4602 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284603 if (rfh)
fdegansc73eec22015-03-19 14:47:544604 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354605 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104606
[email protected]6d65a462013-06-21 21:29:124607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4608 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544609 }
[email protected]87de04b02014-04-08 22:14:494610
[email protected]beb440c2009-11-06 04:08:544611 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284612 if (rfh) {
4613 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4614 dialog_was_suppressed);
4615 } else {
4616 // Don't leak the sync IPC reply if the RFH or process is gone.
4617 delete reply_msg;
4618 }
[email protected]beb440c2009-11-06 04:08:544619}
4620
[email protected]b172aee2012-04-10 17:05:264621void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544622 if (encoding == last_reported_encoding_)
4623 return;
4624 last_reported_encoding_ = encoding;
4625
4626 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124627 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104628}
[email protected]f45d2a72010-03-08 23:28:354629
[email protected]1ac10dca2013-08-20 20:47:044630bool WebContentsImpl::IsHidden() {
4631 return capturer_count_ == 0 && !should_normally_be_visible_;
4632}
4633
rob97250742015-12-10 17:45:154634int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144635 if (node_ && node_->outer_web_contents())
4636 return node_->outer_contents_frame_tree_node_id();
4637
nick2482a2d2015-12-18 01:39:374638 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144639}
4640
[email protected]b0936d22013-11-28 06:47:364641RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214642 return frame_tree_.root()->render_manager();
4643}
4644
lazyboy8e16ddfd2015-09-28 03:41:564645WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4646 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4647 if (node_)
4648 return node_->outer_web_contents();
4649 } else {
4650 if (GetBrowserPluginGuest())
4651 return GetBrowserPluginGuest()->embedder_web_contents();
4652 }
4653 return nullptr;
4654}
4655
[email protected]f8497342013-02-05 22:15:024656BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394657 return browser_plugin_guest_.get();
4658}
4659
[email protected]738f57a2013-06-29 21:06:544660void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4661 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144662 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544663 browser_plugin_guest_.reset(guest);
4664}
4665
[email protected]f8497342013-02-05 22:15:024666BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394667 return browser_plugin_embedder_.get();
4668}
[email protected]8ff00d72012-10-23 19:12:214669
fsamuel60b42282015-03-10 03:29:144670void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4671 if (browser_plugin_embedder_)
4672 return;
4673 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4674}
4675
[email protected]fc2b46b2014-05-03 16:33:454676gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214677 gfx::Size size;
4678 if (delegate_)
4679 size = delegate_->GetSizeForNewRenderView(this);
4680 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454681 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214682 return size;
4683}
4684
[email protected]ae7eeda2014-07-04 01:53:264685void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4686 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024687 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554688}
4689
[email protected]222f5822014-02-05 23:40:494690void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4691 if (!delegate_)
4692 return;
4693 const gfx::Size new_size = GetPreferredSize();
4694 if (new_size != old_size)
4695 delegate_->UpdatePreferredSize(this, new_size);
4696}
4697
dbeama1b926a2015-08-31 23:17:514698WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4699 const std::string& frame_name) {
4700 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4701 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4702 CreateWebUIControllerForURL(web_ui, url);
4703 if (controller) {
4704 web_ui->AddMessageHandler(new GenericHandler());
4705 web_ui->SetController(controller);
4706 return web_ui;
4707 }
4708
4709 delete web_ui;
4710 return NULL;
4711}
4712
[email protected]34ff1cfc2014-08-20 06:16:054713void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4714 force_disable_overscroll_content_ = force_disable;
4715 if (view_)
4716 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4717}
4718
dalecurtis88c240072015-12-09 02:11:184719void WebContentsImpl::MediaStartedPlaying(
4720 const WebContentsObserver::MediaPlayerId& id) {
4721 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4722}
4723
4724void WebContentsImpl::MediaStoppedPlaying(
4725 const WebContentsObserver::MediaPlayerId& id) {
4726 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4727}
4728
[email protected]8ff00d72012-10-23 19:12:214729} // namespace content