blob: eee0310328aeb465cbe8a1ada81a11d5dc10ec82 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
[email protected]b75b8292010-10-01 07:28:2511
[email protected]36fb2c7c2011-04-04 15:49:0812#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4613#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0714#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5615#include "base/logging.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2018#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2219#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0720#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5121#include "base/strings/string16.h"
22#include "base/strings/string_number_conversions.h"
23#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0024#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0725#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3726#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4227#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1028#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2529#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2130#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3031#include "content/browser/accessibility/accessibility_mode_helper.h"
32#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1833#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3934#include "content/browser/browser_plugin/browser_plugin_embedder.h"
35#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5936#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4137#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0438#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4639#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1240#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1641#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1642#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4043#include "content/browser/frame_host/interstitial_page_impl.h"
44#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3345#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0146#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1847#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5749#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0550#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4451#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4052#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3053#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5254#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1855#include "content/browser/media/media_web_contents_observer.h"
[email protected]0bc7f3542013-10-21 15:05:5356#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0957#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3058#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5059#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3260#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5061#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5962#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4863#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0964#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3365#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1266#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1167#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5868#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0369#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5670#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1471#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4272#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4473#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1774#include "content/common/input_messages.h"
avi286019ce2015-07-29 01:26:5875#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5176#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0277#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3678#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1179#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2880#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4481#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3682#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1783#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1484#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4685#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1586#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0087#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2788#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0089#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3790#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1491#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3092#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3293#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0994#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1295#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3496#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3897#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4298#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:2199#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08100#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35101#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48102#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54103#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49104#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20105#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01106#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03107#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57108#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05109#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40110#include "mojo/common/url_type_converters.h"
111#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53112#include "net/http/http_cache.h"
113#include "net/http/http_transaction_factory.h"
114#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34115#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40116#include "skia/public/type_converters.h"
117#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56118#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01119#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41120#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52121#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31122
[email protected]583418cc2013-01-17 14:01:10123#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40124#include "content/browser/android/content_video_view.h"
avayvod41634b12015-07-08 17:07:05125#include "content/browser/media/android/media_session.h"
dalecurtisc85ed632016-01-13 00:22:46126#include "content/browser/media/android/media_web_contents_observer_android.h"
mfomitchev841f8182015-11-07 02:03:19127#endif // OS_ANDROID
128
129#if defined(OS_ANDROID) && !defined(USE_AURA)
130#include "content/browser/android/date_time_chooser_android.h"
[email protected]155c7f22013-12-09 17:07:18131#include "content/browser/web_contents/web_contents_android.h"
mfomitchev841f8182015-11-07 02:03:19132#endif // OS_ANDROID && !USE_AURA
[email protected]583418cc2013-01-17 14:01:10133
[email protected]f66df822012-05-18 16:52:17134#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50135#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57136#endif
[email protected]3e45ba92009-02-20 21:09:00137
fsamuel9cf7bdf2015-11-20 02:19:32138#if defined(MOJO_SHELL_CLIENT)
139#include "content/browser/web_contents/web_contents_view_mus.h"
140#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46141#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32142#endif
143
[email protected]8ff00d72012-10-23 19:12:21144namespace content {
[email protected]420ae012009-04-24 05:16:32145namespace {
146
[email protected]960b0372014-05-19 18:01:00147const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41148const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05149
[email protected]155c7f22013-12-09 17:07:18150#if defined(OS_ANDROID)
151const char kWebContentsAndroidKey[] = "web_contents_android";
152#endif // OS_ANDROID
153
[email protected]e4abd3b42013-11-12 18:28:47154base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46155g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
156
halton.huoca2eabd2015-07-06 08:17:40157static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
158 int id,
159 const GURL& image_url,
160 image_downloader::DownloadResultPtr result) {
161 DCHECK(result);
162
163 const std::vector<SkBitmap> images =
164 result->images.To<std::vector<SkBitmap>>();
165 const std::vector<gfx::Size> original_image_sizes =
166 result->original_image_sizes.To<std::vector<gfx::Size>>();
167
168 callback.Run(id, result->http_status_code, image_url, images,
169 original_image_sizes);
[email protected]795c28972012-12-06 06:13:39170}
171
[email protected]8bfc8272013-09-09 20:10:53172void NotifyCacheOnIO(
173 scoped_refptr<net::URLRequestContextGetter> request_context,
174 const GURL& url,
175 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58176 net::HttpCache* cache = request_context->GetURLRequestContext()->
177 http_transaction_factory()->GetCache();
178 if (cache)
179 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53180}
181
alexmos4cf2aa32015-07-15 23:40:43182bool FindMatchingProcess(int render_process_id,
183 bool* did_match_process,
184 FrameTreeNode* node) {
185 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) {
186 *did_match_process = true;
187 return false;
188 }
189 return true;
190}
191
[email protected]a86c0e962013-12-17 17:10:39192bool ForEachFrameInternal(
193 const base::Callback<void(RenderFrameHost*)>& on_frame,
194 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41195 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39196 return true;
197}
198
[email protected]95640212014-07-26 18:14:30199bool ForEachPendingFrameInternal(
200 const base::Callback<void(RenderFrameHost*)>& on_frame,
201 FrameTreeNode* node) {
202 RenderFrameHost* pending_frame_host =
203 node->render_manager()->pending_frame_host();
204 if (pending_frame_host)
205 on_frame.Run(pending_frame_host);
206 return true;
207}
208
[email protected]a86c0e962013-12-17 17:10:39209void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
210 IPC::Message* message_copy = new IPC::Message(*message);
211 message_copy->set_routing_id(rfh->GetRoutingID());
212 rfh->Send(message_copy);
213}
214
[email protected]948481d2014-06-11 18:32:22215void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
216 RenderFrameHost* rfh) {
217 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
218 ->frame_tree_node()
219 ->render_manager()
220 ->GetRenderWidgetHostView();
221 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59222}
223
[email protected]95640212014-07-26 18:14:30224void SetAccessibilityModeOnFrame(AccessibilityMode mode,
225 RenderFrameHost* frame_host) {
226 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
227}
228
dtseng0dd3fa12015-07-22 19:00:52229void ResetAccessibility(RenderFrameHost* rfh) {
230 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
231}
232
[email protected]420ae012009-04-24 05:16:32233} // namespace
234
[email protected]54944cde2012-12-09 09:24:59235WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21236 FrameTreeNode* opener_node = nullptr;
237 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
238 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
239 params.opener_render_process_id, params.opener_render_frame_id);
240 if (opener_rfh)
241 opener_node = opener_rfh->frame_tree_node();
242 }
243 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19244}
245
246WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59247 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30248 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21249 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30250
251 for (SessionStorageNamespaceMap::const_iterator it =
252 session_storage_namespace_map.begin();
253 it != session_storage_namespace_map.end();
254 ++it) {
255 new_contents->GetController()
256 .SetSessionStorageNamespace(it->first, it->second.get());
257 }
258
[email protected]54944cde2012-12-09 09:24:59259 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19260 return new_contents;
[email protected]a81343d232011-12-27 07:39:20261}
[email protected]746d3052012-05-22 15:15:47262
nickf9acfbe2014-12-23 19:12:37263void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
264 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46265 g_created_callbacks.Get().push_back(callback);
266}
267
nickf9acfbe2014-12-23 19:12:37268void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
269 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46270 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
271 if (g_created_callbacks.Get().at(i).Equals(callback)) {
272 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
273 return;
274 }
275 }
276}
277
avidf38c952015-10-27 13:45:13278WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
279 if (!rvh)
280 return nullptr;
[email protected]746d3052012-05-22 15:15:47281 return rvh->GetDelegate()->GetAsWebContents();
282}
283
[email protected]a86c0e962013-12-17 17:10:39284WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13285 if (!rfh)
286 return nullptr;
287 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39288}
289
[email protected]7fff43e2013-05-21 20:21:10290// WebContentsImpl::DestructionObserver ----------------------------------------
291
292class WebContentsImpl::DestructionObserver : public WebContentsObserver {
293 public:
294 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
295 : WebContentsObserver(watched_contents),
296 owner_(owner) {
297 }
298
299 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58300 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58301 owner_->OnWebContentsDestroyed(
302 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10303 }
304
305 private:
306 WebContentsImpl* owner_;
307
308 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
309};
310
[email protected]8ed16472014-04-11 19:02:48311WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
312 int render_frame_id,
313 ColorChooser* chooser,
314 int identifier)
315 : render_process_id(render_process_id),
316 render_frame_id(render_frame_id),
317 chooser(chooser),
318 identifier(identifier) {
319}
320
321WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
322}
323
lazyboy6ec48b2a2015-06-29 15:18:14324// WebContentsImpl::WebContentsTreeNode ----------------------------------------
325WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
326 : outer_web_contents_(nullptr),
327 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37328 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14329}
330
331WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
332 // Remove child pointer from our parent.
333 if (outer_web_contents_) {
334 ChildrenSet& child_ptrs_in_parent =
335 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
336 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
337 DCHECK(iter != child_ptrs_in_parent.end());
338 child_ptrs_in_parent.erase(this);
339 }
340
341 // Remove parent pointers from our children.
342 // TODO(lazyboy): We should destroy the children WebContentses too. If the
343 // children do not manage their own lifetime, then we would leak their
344 // WebContentses.
345 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
346 child->outer_web_contents_ = nullptr;
347}
348
349void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
350 WebContentsImpl* outer_web_contents,
351 RenderFrameHostImpl* outer_contents_frame) {
352 outer_web_contents_ = outer_web_contents;
353 outer_contents_frame_tree_node_id_ =
354 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
355
356 if (!outer_web_contents_->node_)
357 outer_web_contents_->node_.reset(new WebContentsTreeNode());
358
359 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
360}
361
[email protected]b172aee2012-04-10 17:05:26362// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32363
alexmose201c7cd2015-06-10 17:14:21364WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42365 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22366 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57367 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21368 created_with_opener_(false),
[email protected]2ceee8f2014-01-14 18:02:08369#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41370 accessible_parent_(NULL),
371#endif
[email protected]6ea6bdf2013-12-06 13:35:01372 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57373 this,
374 this,
375 this,
376 this),
[email protected]d5f942ba2008-09-26 19:30:34377 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03378 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23379 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
380 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34381 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26382 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56383 upload_size_(0),
384 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16385 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47386 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10387 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28388 theme_color_(SK_ColorTRANSPARENT),
389 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29390 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55391 capturer_count_(0),
392 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57393 is_being_destroyed_(false),
394 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15395 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01396 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39397 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38398 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21399 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
400 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22401 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44402 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55403 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42404 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03405 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49406 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05407 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30408 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57409 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30410 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30411 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15412 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50413 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46414 page_scale_factor_is_one_(true),
mohan.reddy371ad9142014-09-17 08:01:46415 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55416 frame_tree_.SetFrameRemoveListener(
417 base::Bind(&WebContentsImpl::OnFrameRemoved,
418 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46419#if defined(OS_ANDROID)
420 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
421#else
qinmin58567c82015-01-07 21:00:20422 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46423#endif
alogvinovf50445a2015-10-30 13:00:12424 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35425}
initial.commit09911bf2008-07-26 23:55:29426
[email protected]b172aee2012-04-10 17:05:26427WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32428 is_being_destroyed_ = true;
429
kenrb2a565f82015-09-02 20:24:59430 rwh_input_event_router_.reset();
431
[email protected]21b41c7e892014-02-28 01:52:24432 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
433 // shutdown and be deleted as well.
434 frame_tree_.ForEach(
435 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
436
carlosk35f35af2015-12-01 10:55:40437 // Destroy all WebUI instances.
438 frame_tree_.ForEach(base::Bind(&RenderFrameHostManager::ClearWebUIInstances));
439
[email protected]b24b68a2012-09-24 21:57:26440 for (std::set<RenderWidgetHostImpl*>::iterator iter =
441 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
442 (*iter)->DetachDelegate();
443 }
444 created_widgets_.clear();
445
[email protected]3ab9cb82011-06-03 18:02:07446 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15447 if (dialog_manager_)
avi2460c762015-04-17 15:21:54448 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07449
[email protected]8ed16472014-04-11 19:02:48450 if (color_chooser_info_.get())
451 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20452
[email protected]420ae012009-04-24 05:16:32453 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32454
[email protected]ca13a442012-04-17 14:00:12455 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21456 NotificationService::current()->Notify(
457 NOTIFICATION_WEB_CONTENTS_DESTROYED,
458 Source<WebContents>(this),
459 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32460
[email protected]df0c843f2014-05-23 20:37:23461 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14462 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23463 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59464
clamy0e119882015-07-31 16:12:33465 // Manually call the observer methods for the root frame tree node. It is
466 // necessary to manually delete all objects tracking navigations
467 // (NavigationHandle, NavigationRequest) for observers to be properly
468 // notified of these navigations stopping before the WebContents is
469 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23470 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56471
clamy0e119882015-07-31 16:12:33472 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56473 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33474 root->pending_frame_host()->SetNavigationHandle(
475 scoped_ptr<NavigationHandleImpl>());
476 }
naskob21fe4872015-02-24 14:15:56477 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33478 root->current_frame_host()->SetNavigationHandle(
479 scoped_ptr<NavigationHandleImpl>());
480
481 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35482 if (IsBrowserSideNavigationEnabled()) {
clamy0e119882015-07-31 16:12:33483 frame_tree_.root()->ResetNavigationRequest(false);
484 if (root->speculative_frame_host()) {
485 root->speculative_frame_host()->SetRenderFrameCreated(false);
486 root->speculative_frame_host()->SetNavigationHandle(
487 scoped_ptr<NavigationHandleImpl>());
488 }
489 }
[email protected]f273ee52013-10-18 16:05:27490
naskoa83483fb2015-02-27 16:57:10491 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
492 FrameDeleted(root->current_frame_host()));
493
[email protected]df0c843f2014-05-23 20:37:23494 if (root->pending_render_view_host()) {
495 FOR_EACH_OBSERVER(WebContentsObserver,
496 observers_,
497 RenderViewDeleted(root->pending_render_view_host()));
498 }
[email protected]c06c58c2014-03-12 20:31:59499
[email protected]f273ee52013-10-18 16:05:27500 FOR_EACH_OBSERVER(WebContentsObserver,
501 observers_,
[email protected]df0c843f2014-05-23 20:37:23502 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27503
[email protected]2db9bd72012-04-13 20:20:56504 FOR_EACH_OBSERVER(WebContentsObserver,
505 observers_,
[email protected]12a46832014-05-09 13:35:58506 WebContentsDestroyed());
507
508 FOR_EACH_OBSERVER(WebContentsObserver,
509 observers_,
510 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08511
[email protected]6934a702011-12-20 00:04:51512 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10513
514 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
515 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42516}
517
[email protected]d1198fd2012-08-13 22:50:19518WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59519 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21520 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03521 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21522 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19523
alexmose201c7cd2015-06-10 17:14:21524 if (!params.opener_suppressed && opener) {
525 new_contents->GetFrameTree()->root()->SetOpener(opener);
526 new_contents->created_with_opener_ = true;
527 }
528
529 // This may be true even when opener is null, such as when opening blocked
530 // popups.
alexmos090fae8e2015-05-28 17:09:28531 if (params.created_with_opener)
532 new_contents->created_with_opener_ = true;
533
[email protected]4858e432014-06-23 18:14:17534 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06535 // This makes |new_contents| act as a guest.
536 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16537 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06538 // We are instantiating a WebContents for browser plugin. Set its subframe
539 // bit to true.
540 new_contents->is_subframe_ = true;
541 }
[email protected]54944cde2012-12-09 09:24:59542 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19543 return new_contents;
544}
545
[email protected]95640212014-07-26 18:14:30546// static
547std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
548 std::vector<WebContentsImpl*> result;
549 scoped_ptr<RenderWidgetHostIterator> widgets(
550 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30551 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30552 RenderViewHost* rvh = RenderViewHost::From(rwh);
553 if (!rvh)
554 continue;
555 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
556 if (!web_contents)
557 continue;
avidf38c952015-10-27 13:45:13558 if (web_contents->GetRenderViewHost() != rvh)
559 continue;
560 // Because a WebContents can only have one current RVH at a time, there will
561 // be no duplicate WebContents here.
562 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30563 }
564 return result;
565}
566
clamya16aa8172015-05-26 13:07:25567// static
568WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
569 FrameTreeNode* frame_tree_node) {
570 return static_cast<WebContentsImpl*>(
571 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
572}
573
clamy0d32d6d2015-11-24 11:16:26574// static
575WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
576 int render_frame_host_id) {
577 DCHECK_CURRENTLY_ON(BrowserThread::UI);
578 RenderFrameHost* render_frame_host =
579 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
580 if (!render_frame_host)
581 return nullptr;
582
583 return WebContents::FromRenderFrameHost(render_frame_host);
584}
585
[email protected]b0936d22013-11-28 06:47:36586RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21587 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28588}
589
[email protected]7bb761892012-07-20 09:32:47590bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
591 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44592 return OnMessageReceived(render_view_host, NULL, message);
593}
594
595bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
596 RenderFrameHost* render_frame_host,
597 const IPC::Message& message) {
598 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56599 if (GetWebUI() &&
600 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17601 return true;
[email protected]d2353452012-01-19 19:53:56602 }
[email protected]f82d57b52011-04-27 19:13:17603
brettw5a1613dc2015-06-02 05:34:43604 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25605 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33606 if (render_frame_host) {
607 while ((observer = it.GetNext()) != NULL)
608 if (observer->OnMessageReceived(message, render_frame_host))
609 return true;
610 } else {
611 while ((observer = it.GetNext()) != NULL)
612 if (observer->OnMessageReceived(message))
613 return true;
614 }
[email protected]403415a2011-01-10 18:57:53615
[email protected]1d62cf72014-02-07 21:31:57616 // Message handlers should be aware of which
617 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
618 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02619 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57620 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02621 else
[email protected]1d62cf72014-02-07 21:31:57622 render_view_message_source_ = render_view_host;
623
[email protected]724159a2010-12-30 01:11:18624 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33625 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40626 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
627 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05628 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
629 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48630 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
631 OnDocumentLoadedInFrame)
632 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
633 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
634 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
635 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
636 OnSetSelectedColorInColorChooser)
dalecurtis88c240072015-12-09 02:11:18637
dglazkov79c426102015-08-31 21:22:43638 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11639 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25640 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18641 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54642 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18643 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54644 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18645 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41646 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
647 OnDidDisplayContentWithCertificateErrors)
648 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
649 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25650 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26651 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46652 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
653 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21654 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48655 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
656 OnRegisterProtocolHandler)
657 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
658 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01659 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
660 OnUpdatePageImportanceSignals)
[email protected]b888919c2011-09-02 00:32:16661 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10662 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50663 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50664#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00665 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
666 OnPepperInstanceCreated)
667 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
668 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42669 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
670 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50671 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
672 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55673 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40674 OnBrowserPluginMessage(render_frame_host,
675 message))
thestigc4cac8f2014-09-04 21:17:50676#endif
[email protected]41225fe2013-03-29 05:32:02677 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07678 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
679 OnShowValidationMessage)
680 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
681 OnHideValidationMessage)
682 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
683 OnMoveValidationMessage)
mfomitchev841f8182015-11-07 02:03:19684#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]8ed16472014-04-11 19:02:48685 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
686 OnFindMatchRectsReply)
687 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
688 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48689#endif
[email protected]724159a2010-12-30 01:11:18690 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33691 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44692 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57693 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18694
[email protected]724159a2010-12-30 01:11:18695 return handled;
696}
697
nasko907fcb62015-01-28 04:24:11698bool WebContentsImpl::HasValidFrameSource() {
699 if (!render_frame_message_source_) {
700 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18701 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
702 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11703 return false;
704 }
705
706 return true;
707}
708
[email protected]b172aee2012-04-10 17:05:26709void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18710 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21711 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43712 if (delegate_)
713 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18714}
715
[email protected]d1198fd2012-08-13 22:50:19716NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56717 return controller_;
718}
719
[email protected]d1198fd2012-08-13 22:50:19720const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56721 return controller_;
722}
723
[email protected]8ff00d72012-10-23 19:12:21724BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55725 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30726}
727
[email protected]b172aee2012-04-10 17:05:26728const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24729 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32730 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51731 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31732}
733
[email protected]a093ce02013-07-22 20:53:14734const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24735 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32736 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24737 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
738}
739
740const GURL& WebContentsImpl::GetLastCommittedURL() const {
741 // We may not have a navigation entry yet.
742 NavigationEntry* entry = controller_.GetLastCommittedEntry();
743 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
744}
745
[email protected]8ff00d72012-10-23 19:12:21746WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31747 return delegate_;
748}
749
[email protected]8ff00d72012-10-23 19:12:21750void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31751 // TODO(cbentzel): remove this debugging code?
752 if (delegate == delegate_)
753 return;
754 if (delegate_)
755 delegate_->Detach(this);
756 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08757 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31758 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08759 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00760 if (view_)
[email protected]e85165c642014-06-10 14:34:31761 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08762 }
[email protected]be1f56ab2011-12-22 06:55:31763}
764
[email protected]8ff00d72012-10-23 19:12:21765RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21766 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41767 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16768}
769
clamydf1975e2015-02-05 19:12:24770RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41771 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16772}
773
nick53d5cbf2015-04-23 22:50:14774RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
775 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
776 if (!focused_node)
777 return nullptr;
778 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07779}
780
rob3e2a0732016-01-06 21:22:09781RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
782 int frame_tree_node_id) {
783 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
784 return frame ? frame->current_frame_host() : nullptr;
785}
786
[email protected]a86c0e962013-12-17 17:10:39787void WebContentsImpl::ForEachFrame(
788 const base::Callback<void(RenderFrameHost*)>& on_frame) {
789 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
790}
791
792void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
793 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
794 delete message;
795}
796
creisc014b402015-04-23 16:41:45797RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21798 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31799}
800
[email protected]6b618e62012-08-16 12:59:18801int WebContentsImpl::GetRoutingID() const {
802 if (!GetRenderViewHost())
803 return MSG_ROUTING_NONE;
804
805 return GetRenderViewHost()->GetRoutingID();
806}
807
creis89a0f782015-05-27 16:13:17808void WebContentsImpl::CancelActiveAndPendingDialogs() {
809 if (dialog_manager_)
810 dialog_manager_->CancelActiveAndPendingDialogs(this);
811 if (browser_plugin_embedder_)
812 browser_plugin_embedder_->CancelGuestDialogs();
813}
814
[email protected]44470a22013-01-24 01:21:54815int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
816 return fullscreen_widget_routing_id_;
817}
818
naskoc0fceff2015-04-30 15:53:52819void WebContentsImpl::ClosePage() {
820 GetRenderViewHost()->ClosePage();
821}
822
[email protected]b172aee2012-04-10 17:05:26823RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21824 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31825}
826
[email protected]4aebbca2013-09-17 22:26:49827RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
828 const {
829 RenderWidgetHost* const widget_host =
830 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
831 GetFullscreenWidgetRoutingID());
832 return widget_host ? widget_host->GetView() : NULL;
833}
834
[email protected]8ff00d72012-10-23 19:12:21835WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31836 return view_.get();
837}
838
yusufod41c5f92015-03-06 00:14:28839SkColor WebContentsImpl::GetThemeColor() const {
840 return theme_color_;
841}
842
[email protected]95640212014-07-26 18:14:30843void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
844 if (mode == accessibility_mode_)
845 return;
846
847 accessibility_mode_ = mode;
848 frame_tree_.ForEach(
849 base::Bind(&ForEachFrameInternal,
850 base::Bind(&SetAccessibilityModeOnFrame, mode)));
851 frame_tree_.ForEach(
852 base::Bind(&ForEachPendingFrameInternal,
853 base::Bind(&SetAccessibilityModeOnFrame, mode)));
854}
855
856void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50857 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30858}
859
860void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50861 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30862}
863
dmazzoni83ba5c82015-04-14 07:11:51864void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
865 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
866 // accessibility tree from the main frame and everything in the
867 // same site instance.
868 GetMainFrame()->RequestAXTreeSnapshot(callback);
869}
870
dbeama1b926a2015-08-31 23:17:51871WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
872 const std::string& frame_name) {
873 DCHECK(!frame_name.empty());
874 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22875}
876
[email protected]8ff00d72012-10-23 19:12:21877WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40878 WebUI* commited_web_ui = GetCommittedWebUI();
879 return commited_web_ui ? commited_web_ui
880 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31881}
882
[email protected]8ff00d72012-10-23 19:12:21883WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40884 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34885}
886
[email protected]86ef6a392012-05-11 22:03:11887void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22888 if (GetUserAgentOverride() == override)
889 return;
890
891 renderer_preferences_.user_agent_override = override;
892
893 // Send the new override string to the renderer.
894 RenderViewHost* host = GetRenderViewHost();
895 if (host)
896 host->SyncRendererPrefs();
897
898 // Reload the page if a load is currently in progress to avoid having
899 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27900 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22901 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
902 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53903
904 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
905 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11906}
907
908const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22909 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11910}
911
[email protected]95640212014-07-26 18:14:30912void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dtseng01e634a2015-11-19 01:48:24913 if (GetAccessibilityMode() != AccessibilityModeOff)
dtseng0dd3fa12015-07-22 19:00:52914 ForEachFrame(base::Bind(&ResetAccessibility));
915 else
916 AddAccessibilityMode(AccessibilityModeTreeOnly);
[email protected]95640212014-07-26 18:14:30917}
918
919bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
920 return accessibility_mode_ == AccessibilityModeTreeOnly;
921}
922
923bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
924 return accessibility_mode_ == AccessibilityModeComplete;
925}
926
[email protected]2ceee8f2014-01-14 18:02:08927#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41928void WebContentsImpl::SetParentNativeViewAccessible(
929gfx::NativeViewAccessible accessible_parent) {
930 accessible_parent_ = accessible_parent;
creisc014b402015-04-23 16:41:45931 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30932 if (rfh)
933 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41934}
935#endif
936
kouhei40f03cb2015-09-24 07:47:01937const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
938 return page_importance_signals_;
939}
940
[email protected]fcf75d42013-12-03 20:11:26941const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55942 // Transient entries take precedence. They are used for interstitial pages
943 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23944 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08945 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21946 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30947 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23948 if (entry) {
[email protected]b5cca982011-05-26 04:42:08949 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23950 }
carlosk35f35af2015-12-01 10:55:40951
952 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
953 WebUI* our_web_ui = navigating_web_ui
954 ? navigating_web_ui
955 : GetRenderManager()->current_frame_host()->web_ui();
956
[email protected]7ade2732011-02-10 00:13:58957 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54958 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32959 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54960 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35961 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26962 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54963 if (!title.empty())
964 return title;
965 }
966 }
967
968 // We use the title for the last committed entry rather than a pending
969 // navigation entry. For example, when the user types in a URL, we want to
970 // keep the old page's title until the new load has committed and we get a new
971 // title.
[email protected]96d185d2009-04-24 03:28:54972 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32973
creis072b61f2015-09-28 20:52:24974 // We make an exception for initial navigations. We only want to use the title
975 // from the visible entry if:
976 // 1. The pending entry has been explicitly assigned a title to display.
977 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
978 // which case there is a pending entry index other than -1.
979 //
980 // Otherwise, we want to stick with the last committed entry's title during
981 // new navigations, which have pending entries at index -1 with no title.
982 if (controller_.IsInitialNavigation() &&
983 ((controller_.GetVisibleEntry() &&
984 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
985 controller_.GetPendingEntryIndex() != -1)) {
986 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47987 }
[email protected]59167c22013-06-03 18:07:32988
[email protected]45d0ef7f2011-01-05 13:46:23989 if (entry) {
[email protected]b5cca982011-05-26 04:42:08990 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23991 }
[email protected]987fc3a2011-05-26 14:18:09992
993 // |page_title_when_no_navigation_entry_| is finally used
994 // if no title cannot be retrieved.
995 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54996}
997
avib7348942015-12-25 20:57:10998int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46999 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1000}
1001
avib7348942015-12-25 20:57:101002int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261003 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331004 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1005 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461006
[email protected]b6583592012-01-25 19:52:331007 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341008}
1009
avib7348942015-12-25 20:57:101010void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461011 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1012}
1013
[email protected]b172aee2012-04-10 17:05:261014void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101015 SiteInstance* site_instance,
1016 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461017 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331018 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341019}
1020
[email protected]ec6c05f2013-10-23 18:41:571021void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1022 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1023 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571024}
1025
creiscce56cd2014-09-29 22:45:221026SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211027 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541028}
1029
creiscce56cd2014-09-29 22:45:221030SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1031 RenderViewHostImpl* dest_rvh =
1032 GetRenderManager()->pending_render_view_host() ?
1033 GetRenderManager()->pending_render_view_host() :
1034 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581035 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381036}
1037
[email protected]b172aee2012-04-10 17:05:261038bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:311039 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:491040}
1041
[email protected]6dfed692014-05-22 04:18:031042bool WebContentsImpl::IsLoadingToDifferentDocument() const {
1043 return is_loading_ && is_load_to_different_document_;
1044}
1045
[email protected]b172aee2012-04-10 17:05:261046bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031047 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311048}
1049
[email protected]b172aee2012-04-10 17:05:261050const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311051 return load_state_;
1052}
1053
[email protected]fcf75d42013-12-03 20:11:261054const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311055 return load_state_host_;
1056}
1057
avib7348942015-12-25 20:57:101058uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311059 return upload_size_;
1060}
1061
avib7348942015-12-25 20:57:101062uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311063 return upload_position_;
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541067 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311068}
1069
[email protected]b172aee2012-04-10 17:05:261070bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311071 return displayed_insecure_content_;
1072}
1073
[email protected]222f5822014-02-05 23:40:491074void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251075 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551076 ++capturer_count_;
1077 DVLOG(1) << "There are now " << capturer_count_
1078 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491079
1080 // Note: This provides a hint to upstream code to size the views optimally
1081 // for quality (e.g., to avoid scaling).
1082 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1083 preferred_size_for_capture_ = capture_size;
1084 OnPreferredSizeChanged(preferred_size_);
1085 }
ccameron8807c38f2015-01-17 00:29:191086
1087 // Ensure that all views are un-occluded before capture begins.
1088 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551089}
1090
1091void WebContentsImpl::DecrementCapturerCount() {
1092 --capturer_count_;
1093 DVLOG(1) << "There are now " << capturer_count_
1094 << " capturing(s) of WebContentsImpl@" << this;
1095 DCHECK_LE(0, capturer_count_);
1096
[email protected]5a652232013-02-12 06:15:251097 if (is_being_destroyed_)
1098 return;
1099
[email protected]222f5822014-02-05 23:40:491100 if (capturer_count_ == 0) {
1101 const gfx::Size old_size = preferred_size_for_capture_;
1102 preferred_size_for_capture_ = gfx::Size();
1103 OnPreferredSizeChanged(old_size);
1104 }
1105
[email protected]1ac10dca2013-08-20 20:47:041106 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551107 DVLOG(1) << "Executing delayed WasHidden().";
1108 WasHidden();
1109 }
[email protected]be1f56ab2011-12-22 06:55:311110}
1111
[email protected]f2bd40812013-07-20 04:30:441112int WebContentsImpl::GetCapturerCount() const {
1113 return capturer_count_;
1114}
1115
miu50f97892014-09-22 22:49:521116bool WebContentsImpl::IsAudioMuted() const {
1117 return audio_muter_.get() && audio_muter_->is_muting();
1118}
1119
1120void WebContentsImpl::SetAudioMuted(bool mute) {
1121 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1122 << " for WebContentsImpl@" << this;
1123
1124 if (mute == IsAudioMuted())
1125 return;
1126
1127 if (mute) {
1128 if (!audio_muter_)
1129 audio_muter_.reset(new WebContentsAudioMuter(this));
1130 audio_muter_->StartMuting();
1131 } else {
1132 DCHECK(audio_muter_);
1133 audio_muter_->StopMuting();
1134 }
1135
wjmaclean2f797c782016-01-07 14:52:031136 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1137 DidUpdateAudioMutingState(mute));
1138
miu50f97892014-09-22 22:49:521139 // Notification for UI updates in response to the changed muting state.
1140 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311144 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1145 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581146 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271147#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581148 crashed_status_ ==
1149 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271150#endif
wfh0d9532a2015-09-02 23:18:581151 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271152 );
[email protected]3c9e1872010-11-18 16:17:491153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1156 int error_code) {
[email protected]443b80e2010-12-14 00:42:231157 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341158 return;
1159
[email protected]443b80e2010-12-14 00:42:231160 crashed_status_ = status;
1161 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211162 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341163}
1164
[email protected]b172aee2012-04-10 17:05:261165base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311166 return crashed_status_;
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311170 return is_being_destroyed_;
1171}
1172
[email protected]7f924832014-08-09 05:57:221173void WebContentsImpl::NotifyNavigationStateChanged(
1174 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541175 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1176 // is fixed.
1177 tracked_objects::ScopedTracker tracking_profile(
1178 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1179 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181180 // Notify the media observer of potential audibility changes.
1181 if (changed_flags & INVALIDATE_TYPE_TAB) {
1182 media_web_contents_observer_->MaybeUpdateAudibleState(
1183 AudioStreamMonitor::monitoring_available() && WasRecentlyAudible());
dalecurtisbc6572e12014-09-12 19:22:301184 }
1185
[email protected]d5f942ba2008-09-26 19:30:341186 if (delegate_)
1187 delegate_->NavigationStateChanged(this, changed_flags);
1188}
1189
gab0dccfef2015-05-20 18:43:391190base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021191 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331192}
1193
georgesak5582cbe2015-05-22 22:08:071194void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1195 last_active_time_ = last_active_time;
1196}
1197
[email protected]9e2e4632012-07-27 16:38:411198void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541199 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591200
ccameron8807c38f2015-01-17 00:29:191201 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1202 if (view) {
1203 view->Show();
[email protected]789e9152009-08-04 21:59:431204#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191205 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431206#endif
[email protected]de3c5d82014-05-28 22:12:591207 }
[email protected]789e9152009-08-04 21:59:431208 }
[email protected]96d185d2009-04-24 03:28:541209
gab0dccfef2015-05-20 18:43:391210 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381211
[email protected]b9769d82012-02-10 00:23:591212 // The resize rect might have changed while this was inactive -- send the new
1213 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451214 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221215 if (rvh) {
1216 rvh->GetWidget()->ResizeRectChanged(
1217 GetRootWindowResizerRect(rvh->GetWidget()));
1218 }
[email protected]96d185d2009-04-24 03:28:541219
[email protected]c0d9d5672013-10-09 07:38:031220 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1221
[email protected]54597982013-02-06 01:59:551222 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311223}
1224
[email protected]b172aee2012-04-10 17:05:261225void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551226 // If there are entities capturing screenshots or video (e.g., mirroring),
1227 // don't activate the "disable rendering" optimization.
1228 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521229 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551230 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261231 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521232 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331233 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521234 // calls us).
ccameron8807c38f2015-01-17 00:29:191235 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1236 if (view)
1237 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591238 }
[email protected]96d185d2009-04-24 03:28:541239 }
1240
[email protected]c0d9d5672013-10-09 07:38:031241 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1242
[email protected]54597982013-02-06 01:59:551243 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371244}
1245
ccameron8807c38f2015-01-17 00:29:191246void WebContentsImpl::WasOccluded() {
1247 if (capturer_count_ > 0)
1248 return;
1249
1250 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1251 if (view)
1252 view->WasOccluded();
1253 }
1254}
1255
1256void WebContentsImpl::WasUnOccluded() {
1257 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1258 if (view)
1259 view->WasUnOccluded();
1260 }
1261}
1262
[email protected]b172aee2012-04-10 17:05:261263bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311264 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451265 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1266 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311267}
1268
[email protected]1c3f80bd2014-04-08 23:02:061269void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451270 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061271}
1272
lazyboy6ec48b2a2015-06-29 15:18:141273void WebContentsImpl::AttachToOuterWebContentsFrame(
1274 WebContents* outer_web_contents,
1275 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081276 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141277 // Create a link to our outer WebContents.
1278 node_.reset(new WebContentsTreeNode());
1279 node_->ConnectToOuterWebContents(
1280 static_cast<WebContentsImpl*>(outer_web_contents),
1281 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1282
1283 DCHECK(outer_contents_frame);
1284
1285 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1286 // SiteInstance of the outer WebContents. The proxy will be used to send
1287 // postMessage to the inner WebContents.
1288 GetRenderManager()->CreateOuterDelegateProxy(
1289 outer_contents_frame->GetSiteInstance(),
1290 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1291
1292 GetRenderManager()->SetRWHViewForInnerContents(
1293 GetRenderManager()->GetRenderWidgetHostView());
1294}
1295
[email protected]b172aee2012-04-10 17:05:261296void WebContentsImpl::Stop() {
clamyf73862c42015-07-08 12:31:331297 frame_tree_.ForEach(base::Bind(&FrameTreeNode::StopLoading));
[email protected]d16609c2013-08-23 06:01:401298 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271299}
1300
[email protected]b172aee2012-04-10 17:05:261301WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441302 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211303 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451304 // before.
[email protected]54944cde2012-12-09 09:24:591305 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451306 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211307 WebContentsImpl* tc =
1308 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191309 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221310 FOR_EACH_OBSERVER(WebContentsObserver,
1311 observers_,
1312 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271313 return tc;
1314}
1315
[email protected]14392a52012-05-02 20:28:441316void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211317 const NotificationSource& source,
1318 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441319 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211320 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1321 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031322 RenderWidgetHostView* view = host->GetView();
1323 if (view == GetFullscreenRenderWidgetHostView()) {
1324 // We cannot just call view_->RestoreFocus() here. On some platforms,
1325 // attempting to focus the currently-invisible WebContentsView will be
1326 // flat-out ignored. Therefore, this boolean is used to track whether
1327 // we will request focus after the fullscreen widget has been
1328 // destroyed.
1329 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1330 } else {
1331 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1332 i != pending_widget_views_.end(); ++i) {
1333 if (host->GetView() == i->second) {
1334 pending_widget_views_.erase(i);
1335 break;
1336 }
[email protected]bafe6cd2012-05-23 23:09:501337 }
1338 }
1339 break;
1340 }
[email protected]14392a52012-05-02 20:28:441341 default:
1342 NOTREACHED();
1343 }
1344}
1345
[email protected]ec6c05f2013-10-23 18:41:571346WebContents* WebContentsImpl::GetWebContents() {
1347 return this;
1348}
1349
[email protected]54944cde2012-12-09 09:24:591350void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211351 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361352 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211353 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431354 should_normally_be_visible_ = !params.initially_hidden;
1355
dcheng3ce04b62015-10-26 23:30:551356 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541357 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551358 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1359 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541360 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551361 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1362 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1363
1364 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1365 if (!site_instance)
1366 site_instance = SiteInstance::Create(params.browser_context);
1367
1368 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1369 // local root by definition.
1370 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1371 // longer be necessary to eagerly grab a routing ID for the view.
1372 // https://crbug.com/545684
1373 int32_t view_routing_id = params.routing_id;
1374 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1375 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1376 view_routing_id = main_frame_widget_routing_id =
1377 site_instance->GetProcess()->GetNextRoutingID();
1378 }
1379
1380 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1381 params.main_frame_routing_id,
1382 main_frame_widget_routing_id);
naskoc9f51dd2015-05-13 00:39:281383 frame_tree_.root()->SetFrameName(params.main_frame_name);
[email protected]d1198fd2012-08-13 22:50:191384
[email protected]fc2b46b2014-05-03 16:33:451385 WebContentsViewDelegate* delegate =
1386 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1387
fsamueladb0033602015-12-09 19:20:411388#if defined(MOJO_SHELL_CLIENT)
1389 if (MojoShellConnection::Get() &&
1390 base::CommandLine::ForCurrentProcess()->HasSwitch(
1391 switches::kUseMusInRenderer)) {
1392 mus::Window* mus_window = aura::GetMusWindow(params.context);
1393 if (mus_window) {
1394 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1395 &render_view_host_delegate_view_));
1396 }
1397 }
1398#endif
1399
1400 if (!view_) {
1401 view_.reset(CreateWebContentsView(this, delegate,
1402 &render_view_host_delegate_view_));
1403 }
fsamuel9cf7bdf2015-11-20 02:19:321404
lazyboy6ec48b2a2015-06-29 15:18:141405 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081406 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321407 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361408 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321409 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191410 }
[email protected]fc2b46b2014-05-03 16:33:451411 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191412 CHECK(view_.get());
1413
[email protected]ed245db2012-12-18 08:00:451414 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591415 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191416
tommyclieb25b2a2014-11-03 19:45:091417#if defined(ENABLE_PLUGINS)
1418 plugin_content_origin_whitelist_.reset(
1419 new PluginContentOriginWhitelist(this));
1420#endif
1421
[email protected]d1198fd2012-08-13 22:50:191422 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211423 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1424 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101425
[email protected]01f83f92014-06-17 14:41:541426 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091427 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541428
mlamouriefdca9d2014-09-16 16:55:401429 manifest_manager_host_.reset(new ManifestManagerHost(this));
1430
mfomitchev841f8182015-11-07 02:03:191431#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]583418cc2013-01-17 14:01:101432 date_time_chooser_.reset(new DateTimeChooserAndroid());
1433#endif
fsamuel7310a4262014-12-05 05:06:441434
1435 // BrowserPluginGuest::Init needs to be called after this WebContents has
1436 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1437 if (browser_plugin_guest_)
1438 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371439
1440 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1441 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561442
1443 // If the WebContents creation was renderer-initiated, it means that the
1444 // corresponding RenderView and main RenderFrame have already been created.
1445 // Ensure observers are notified about this.
1446 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431447 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561448 RenderViewCreated(GetRenderViewHost());
1449 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1450 }
naskof5940b9f2015-03-02 23:04:051451
1452 // Ensure that observers are notified of the creation of this WebContents's
1453 // main RenderFrameHost. It must be done here for main frames, since the
1454 // NotifySwappedFromRenderManager expects view_ to already be created and that
1455 // happens after RenderFrameHostManager::Init.
1456 NotifySwappedFromRenderManager(
1457 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191458}
1459
[email protected]7fff43e2013-05-21 20:21:101460void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1461 RemoveDestructionObserver(web_contents);
1462
[email protected]ceee8cd2013-03-08 04:59:511463 // Clear a pending contents that has been closed before being shown.
1464 for (PendingContents::iterator iter = pending_contents_.begin();
1465 iter != pending_contents_.end();
1466 ++iter) {
1467 if (iter->second != web_contents)
1468 continue;
1469 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511470 return;
1471 }
1472 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441473}
1474
[email protected]7fff43e2013-05-21 20:21:101475void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1476 if (!ContainsKey(destruction_observers_, web_contents)) {
1477 destruction_observers_[web_contents] =
1478 new DestructionObserver(this, web_contents);
1479 }
1480}
1481
1482void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1483 DestructionObservers::iterator iter =
1484 destruction_observers_.find(web_contents);
1485 if (iter != destruction_observers_.end()) {
1486 delete destruction_observers_[web_contents];
1487 destruction_observers_.erase(iter);
1488 }
1489}
1490
[email protected]b172aee2012-04-10 17:05:261491void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311492 observers_.AddObserver(observer);
1493}
1494
[email protected]b172aee2012-04-10 17:05:261495void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311496 observers_.RemoveObserver(observer);
1497}
1498
[email protected]948481d2014-06-11 18:32:221499std::set<RenderWidgetHostView*>
1500WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1501 std::set<RenderWidgetHostView*> set;
1502 if (ShowingInterstitialPage()) {
1503 set.insert(GetRenderWidgetHostView());
1504 } else {
1505 ForEachFrame(
1506 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1507 }
[email protected]de3c5d82014-05-28 22:12:591508 return set;
1509}
1510
[email protected]b172aee2012-04-10 17:05:261511void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341512 if (delegate_)
1513 delegate_->ActivateContents(this);
1514}
1515
avi3e4b8512015-11-11 01:55:491516void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1517 if (!RenderViewHostImpl::From(render_widget_host))
1518 return;
1519
[email protected]63954792011-07-11 04:17:481520 if (delegate_)
1521 delegate_->LostCapture();
1522}
1523
lazyboy63f5b312015-11-23 20:19:521524void WebContentsImpl::RenderWidgetCreated(
1525 RenderWidgetHostImpl* render_widget_host) {
1526 created_widgets_.insert(render_widget_host);
1527}
1528
[email protected]b24b68a2012-09-24 21:57:261529void WebContentsImpl::RenderWidgetDeleted(
1530 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521531 // Note that |is_being_destroyed_| can be true at this point as
1532 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1533 // us here.
1534 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261535
lazyboy63f5b312015-11-23 20:19:521536 if (is_being_destroyed_)
1537 return;
[email protected]44470a22013-01-24 01:21:541538
1539 if (render_widget_host &&
1540 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491541 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531542 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541543 FOR_EACH_OBSERVER(WebContentsObserver,
1544 observers_,
1545 DidDestroyFullscreenWidget(
1546 fullscreen_widget_routing_id_));
1547 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031548 if (fullscreen_widget_had_focus_at_shutdown_)
1549 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541550 }
[email protected]b24b68a2012-09-24 21:57:261551}
1552
miu9e14e492014-10-25 02:39:041553void WebContentsImpl::RenderWidgetGotFocus(
1554 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371555 // Notify the observers if an embedded fullscreen widget was focused.
1556 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1557 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1558 NotifyWebContentsFocused();
1559 }
miu9e14e492014-10-25 02:39:041560}
1561
estaded0a0c992015-01-21 14:12:061562void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311563 RenderWidgetHostImpl* render_widget_host,
1564 bool width_changed) {
creisc014b402015-04-23 16:41:451565 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291566 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061567 return;
estaded0a0c992015-01-21 14:12:061568
rouslan2f5993f2015-01-29 00:18:311569 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1570 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061571}
1572
paulmeyer9ef6e4462015-02-24 19:15:101573void WebContentsImpl::ScreenInfoChanged() {
1574 if (browser_plugin_embedder_)
1575 browser_plugin_embedder_->ScreenInfoChanged();
1576}
1577
[email protected]b172aee2012-04-10 17:05:261578bool WebContentsImpl::PreHandleKeyboardEvent(
1579 const NativeWebKeyboardEvent& event,
1580 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481581 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131582 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481583}
1584
[email protected]b172aee2012-04-10 17:05:261585void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101586 if (browser_plugin_embedder_ &&
1587 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1588 return;
1589 }
[email protected]63954792011-07-11 04:17:481590 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131591 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481592}
1593
[email protected]d92026ef2014-03-03 21:04:131594bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461595 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191596#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331597 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1598 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191599 // -the OS already has a gesture to do this through pinch-zoom
1600 // -if a user starts an inertial scroll, let's go, and presses control
1601 // (i.e. control+tab) then the OS's buffered scroll events will come in
1602 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331603 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551604 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331605 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221606 // Count only integer cumulative scrolls as zoom events; this handles
1607 // smooth scroll and regular scroll device behavior.
1608 zoom_scroll_remainder_ += event.wheelTicksY;
1609 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1610 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1611 if (whole_zoom_scroll_remainder_ != 0) {
1612 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1613 }
[email protected]fb3f066e2013-02-12 19:12:521614 return true;
1615 }
[email protected]bccc4472013-04-18 16:37:191616#endif
[email protected]fb3f066e2013-02-12 19:12:521617 return false;
1618}
1619
[email protected]04bce562014-01-30 05:34:541620bool WebContentsImpl::PreHandleGestureEvent(
1621 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031622 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541623}
1624
kenrb2a565f82015-09-02 20:24:591625RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451626 if (!is_being_destroyed_ && GetOuterWebContents())
1627 return GetOuterWebContents()->GetInputEventRouter();
1628
1629 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591630 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1631 return rwh_input_event_router_.get();
1632}
1633
alexmos3fcd0ca2015-10-23 18:18:331634void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1635 // Focus loss may occur while this WebContents is being destroyed. Don't
1636 // send the message in this case, as the main frame's RenderFrameHost and
1637 // other state has already been cleared.
1638 if (is_being_destroyed_)
1639 return;
1640
1641 frame_tree_.ReplicatePageFocus(is_focused);
1642}
1643
alexmosc4cbacb2015-11-21 01:29:221644RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1645 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521646 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221647 return receiving_widget;
1648
1649 // Events for widgets other than the main frame (e.g., popup menus) should be
1650 // forwarded directly to the widget they arrived on.
1651 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1652 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521653
1654 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1655 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221656 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521657
alexmos732ca3a2015-12-08 02:01:021658 // The view may be null if a subframe's renderer process has crashed while
1659 // the subframe has focus. Drop the event in that case. Do not give
1660 // it to the main frame, so that the user doesn't unexpectedly type into the
1661 // wrong frame if a focused subframe renderer crashes while they type.
1662 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1663 if (!view)
1664 return nullptr;
1665
1666 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521667}
1668
mlamouri7a78d6fd2015-01-17 13:23:531669void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1670 // This method is being called to enter renderer-initiated fullscreen mode.
1671 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491672 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371673 if (widget_view) {
1674 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1675 ->ShutdownAndDestroyWidget(true);
1676 }
[email protected]4aebbca2013-09-17 22:26:491677
[email protected]8a5e0ca2011-08-25 06:30:471678 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531679 delegate_->EnterFullscreenModeForTab(this, origin);
1680
1681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
avibf58fa0c2015-11-11 01:45:521682 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(
1683 GetRenderViewHost()->GetWidget())));
mlamouri7a78d6fd2015-01-17 13:23:531684}
1685
1686void WebContentsImpl::ExitFullscreenMode() {
1687 // This method is being called to leave renderer-initiated fullscreen mode.
1688 // Make sure any existing fullscreen widget is shut down first.
1689 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371690 if (widget_view) {
1691 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1692 ->ShutdownAndDestroyWidget(true);
1693 }
mlamouri7a78d6fd2015-01-17 13:23:531694
hugo.holgersson61288e6c2015-01-28 17:04:401695#if defined(OS_ANDROID)
1696 ContentVideoView* video_view = ContentVideoView::GetInstance();
1697 if (video_view != NULL)
1698 video_view->OnExitFullscreen();
1699#endif
1700
mlamouri7a78d6fd2015-01-17 13:23:531701 if (delegate_)
1702 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371703
scheib3dcb6c932015-02-23 10:55:581704 // Ensure web contents exit fullscreen state by sending a resize message,
1705 // which includes the fullscreen state. This is required for the situation
1706 // of the browser moving the view into a fullscreen state "browser fullscreen"
1707 // and then the contents entering "tab fullscreen". Exiting the contents
1708 // "tab fullscreen" then won't have the side effect of the view resizing,
1709 // hence the explicit call here is required.
1710 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1711 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1712 render_widget_host->WasResized();
1713 }
1714
avibf58fa0c2015-11-11 01:45:521715 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1716 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(
1717 GetRenderViewHost()->GetWidget())));
[email protected]8a5e0ca2011-08-25 06:30:471718}
1719
avibf58fa0c2015-11-11 01:45:521720bool WebContentsImpl::IsFullscreenForCurrentTab(
1721 RenderWidgetHostImpl* render_widget_host) const {
1722 if (!RenderViewHostImpl::From(render_widget_host))
1723 return false;
1724
[email protected]199bba6e2012-04-04 16:19:381725 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121726}
1727
avibf58fa0c2015-11-11 01:45:521728blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1729 RenderWidgetHostImpl* render_widget_host) const {
1730 if (!RenderViewHostImpl::From(render_widget_host))
1731 return blink::WebDisplayModeBrowser;
1732
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121733 return delegate_ ? delegate_->GetDisplayMode(this)
1734 : blink::WebDisplayModeBrowser;
1735}
1736
avic3aa8422015-11-09 20:57:221737void WebContentsImpl::RequestToLockMouse(
1738 RenderWidgetHostImpl* render_widget_host,
1739 bool user_gesture,
1740 bool last_unlocked_by_target) {
1741 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1742 render_widget_host->GotResponseToLockMouseRequest(false);
1743 return;
[email protected]e9621112011-10-17 05:38:371744 }
avic3aa8422015-11-09 20:57:221745
1746 if (delegate_)
1747 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1748 else
1749 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371750}
1751
avi3e4b8512015-11-11 01:55:491752void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1753 if (!RenderViewHostImpl::From(render_widget_host))
1754 return;
1755
[email protected]e9621112011-10-17 05:38:371756 if (delegate_)
1757 delegate_->LostMouseLock();
1758}
1759
dtrainor5ef644e2015-11-19 00:12:471760void WebContentsImpl::ForwardCompositorProto(
1761 RenderWidgetHostImpl* render_widget_host,
1762 const std::vector<uint8_t>& proto) {
1763 if (render_widget_host != GetRenderViewHost()->GetWidget())
1764 return;
1765
1766 if (delegate_)
1767 delegate_->ForwardCompositorProto(proto);
1768}
1769
[email protected]bafe6cd2012-05-23 23:09:501770void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431771 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551772 int32_t route_id,
1773 int32_t main_frame_route_id,
1774 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131775 const ViewHostMsg_CreateWindow_Params& params,
1776 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501777 // We usually create the new window in the same BrowsingInstance (group of
1778 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551779 // if the opener is being suppressed (in a non-guest), we create a new
1780 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251781 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551782
nickd30fd962015-07-27 21:51:081783 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141784 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1785 // yet.
1786 NOTREACHED();
1787 }
1788
[email protected]04cbd3d2013-12-04 04:58:201789 // If the opener is to be suppressed, the new window can be in any process.
1790 // Since routing ids are process specific, we must not have one passed in
1791 // as argument here.
1792 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1793
[email protected]bafe6cd2012-05-23 23:09:501794 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431795 params.opener_suppressed && !is_guest
1796 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1797 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501798
alexmos4cf2aa32015-07-15 23:40:431799 // A message to create a new window can only come from a process for a frame
1800 // in this WebContents' FrameTree. If any other process sends the request, it
1801 // is invalid and the process must be terminated.
1802 int render_process_id = source_site_instance->GetProcess()->GetID();
1803 bool did_match_process = false;
1804 frame_tree_.ForEach(
1805 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1806 if (!did_match_process) {
1807 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351808 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201809 if (process_handle != base::kNullProcessHandle) {
1810 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391811 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351812 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201813 }
1814 return;
1815 }
1816
[email protected]d1198fd2012-08-13 22:50:191817 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341818 //
1819 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301820 const std::string& partition_id =
1821 GetContentClient()->browser()->
1822 GetStoragePartitionIdForSite(GetBrowserContext(),
1823 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461824 StoragePartition* partition = BrowserContext::GetStoragePartition(
1825 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411826 DOMStorageContextWrapper* dom_storage_context =
1827 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191828 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1829 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1830 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371831
1832 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551833 !delegate_->ShouldCreateWebContents(
1834 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1835 params.window_container_type, params.frame_name, params.target_url,
1836 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011837 if (route_id != MSG_ROUTING_NONE &&
1838 !RenderViewHost::FromID(render_process_id, route_id)) {
1839 // If the embedder didn't create a WebContents for this route, we need to
1840 // delete the RenderView that had already been created.
1841 Send(new ViewMsg_Close(route_id));
1842 }
[email protected]dd6730412013-08-14 15:03:371843 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]dd6730412013-08-14 15:03:371844 return;
1845 }
1846
1847 // Create the new web contents. This will automatically create the new
1848 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461849 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591850 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041851 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551852 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121853 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431854 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211855 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061856 create_params.opener_suppressed = params.opener_suppressed;
1857 if (params.disposition == NEW_BACKGROUND_TAB)
1858 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191859 create_params.renderer_initiated_creation =
1860 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061861
[email protected]4858e432014-06-23 18:14:171862 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551863 if (!is_guest) {
1864 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451865 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171866 new_contents = static_cast<WebContentsImpl*>(
1867 WebContents::Create(create_params));
1868 } else {
1869 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551870 }
[email protected]50d326e2014-05-20 17:59:061871 new_contents->GetController().SetSessionStorageNamespace(
1872 partition_id,
1873 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191874
alexmos646fec02015-07-25 00:11:491875 // If the new frame has a name, make sure any SiteInstances that can find
1876 // this named frame have proxies for it. Must be called after
1877 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1878 // GetSessionStorageNamespace.
1879 if (!params.frame_name.empty())
1880 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1881
[email protected]c4538072013-03-18 02:17:551882 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341883 // will be shown immediately).
1884 if (!params.opener_suppressed) {
1885 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451886 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501887
[email protected]d70bea92013-04-05 04:23:341888 // TODO(brettw): It seems bogus that we have to call this function on the
1889 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431890 new_view->CreateViewForWidget(
1891 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341892 }
[email protected]bafe6cd2012-05-23 23:09:501893 // Save the created window associated with the route so we can show it
1894 // later.
1895 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1896 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101897 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501898 }
1899
1900 if (delegate_) {
1901 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071902 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131903 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501904 }
1905
1906 if (params.opener_suppressed) {
1907 // When the opener is suppressed, the original renderer cannot access the
1908 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001909 bool was_blocked = false;
1910 if (delegate_) {
bokan107a47f2015-02-03 23:23:391911 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001912 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391913 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001914 params.user_gesture, &was_blocked);
1915 }
1916 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211917 OpenURLParams open_params(params.target_url,
1918 Referrer(),
1919 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351920 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211921 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301922 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371923
1924 if (delegate_ && !is_guest &&
1925 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1926 // We are in asynchronous add new contents path, delay opening url
1927 new_contents->delayed_open_url_params_.reset(
1928 new OpenURLParams(open_params));
1929 } else {
1930 new_contents->OpenURL(open_params);
1931 }
[email protected]eda238a12012-09-07 23:44:001932 }
[email protected]bafe6cd2012-05-23 23:09:501933 }
1934}
1935
avib7348942015-12-25 20:57:101936void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1937 int32_t route_id,
[email protected]180ef242013-11-07 06:50:461938 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051939 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501940}
1941
avib7348942015-12-25 20:57:101942void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
1943 int32_t route_id) {
piman5d36dae2015-09-24 22:47:051944 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501945}
1946
avib7348942015-12-25 20:57:101947void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
1948 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:501949 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461950 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211951 RenderProcessHost* process = GetRenderProcessHost();
kenrbb46f86a2015-12-07 07:53:231952 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:511953 // this WebContentsImpl instance. If any other process sends the request,
1954 // it is invalid and the process must be terminated.
kenrbb46f86a2015-12-07 07:53:231955 bool did_match_process = false;
1956 frame_tree_.ForEach(
1957 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1958 if (!did_match_process) {
jaekyun37e572a32014-12-04 23:33:351959 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1960 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511961 if (process_handle != base::kNullProcessHandle) {
1962 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391963 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351964 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511965 }
1966 return;
1967 }
1968
[email protected]bafe6cd2012-05-23 23:09:501969 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051970 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261971
[email protected]cfd80b02014-05-01 17:46:481972 RenderWidgetHostViewBase* widget_view =
1973 static_cast<RenderWidgetHostViewBase*>(
1974 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191975 if (!widget_view)
1976 return;
[email protected]bafe6cd2012-05-23 23:09:501977 if (!is_fullscreen) {
1978 // Popups should not get activated.
1979 widget_view->SetPopupType(popup_type);
1980 }
1981 // Save the created widget associated with the route so we can show it later.
1982 pending_widget_views_[route_id] = widget_view;
1983
1984#if defined(OS_MACOSX)
1985 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1986 // to allow it to survive the trip without being hosted.
1987 base::mac::NSObjectRetain(widget_view->GetNativeView());
1988#endif
1989}
1990
1991void WebContentsImpl::ShowCreatedWindow(int route_id,
1992 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391993 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501994 bool user_gesture) {
1995 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001996 if (contents) {
1997 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:161998 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:381999 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2000 contents->ResumeLoadingCreatedWebContents();
2001
[email protected]eda238a12012-09-07 23:44:002002 if (delegate) {
2003 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392004 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002005 }
2006 }
[email protected]bafe6cd2012-05-23 23:09:502007}
2008
2009void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392010 const gfx::Rect& initial_rect) {
2011 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502012}
2013
2014void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2015 ShowCreatedWidget(route_id, true, gfx::Rect());
2016}
2017
2018void WebContentsImpl::ShowCreatedWidget(int route_id,
2019 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392020 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482021 RenderWidgetHostViewBase* widget_host_view =
2022 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502023 if (!widget_host_view)
2024 return;
[email protected]cfd80b02014-05-01 17:46:482025
2026 RenderWidgetHostView* view = NULL;
2027 BrowserPluginGuest* guest = GetBrowserPluginGuest();
2028 if (guest && guest->embedder_web_contents()) {
2029 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
2030 } else {
2031 view = GetRenderWidgetHostView();
2032 }
2033
[email protected]4aebbca2013-09-17 22:26:492034 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312035 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032036 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312037 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492038 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2039 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532040 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492041 } else {
[email protected]cfd80b02014-05-01 17:46:482042 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492043 }
[email protected]4aebbca2013-09-17 22:26:492044 FOR_EACH_OBSERVER(WebContentsObserver,
2045 observers_,
2046 DidShowFullscreenWidget(route_id));
2047 if (!widget_host_view->HasFocus())
2048 widget_host_view->Focus();
2049 } else {
bokan107a47f2015-02-03 23:23:392050 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492051 }
[email protected]89054502012-06-03 10:29:242052
2053 RenderWidgetHostImpl* render_widget_host_impl =
2054 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2055 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312056 // Only allow privileged mouse lock for fullscreen render widget, which is
2057 // used to implement Pepper Flash fullscreen.
2058 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502059
2060#if defined(OS_MACOSX)
2061 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2062 // properly embedded (or purposefully ignored) we can release the retain we
2063 // took in CreateNewWidget().
2064 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2065#endif
2066}
2067
2068WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2069 PendingContents::iterator iter = pending_contents_.find(route_id);
2070
2071 // Certain systems can block the creation of new windows. If we didn't succeed
2072 // in creating one, just return NULL.
2073 if (iter == pending_contents_.end()) {
2074 return NULL;
2075 }
2076
2077 WebContentsImpl* new_contents = iter->second;
2078 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102079 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502080
[email protected]d70bea92013-04-05 04:23:342081 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252082 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342083 return new_contents;
2084
[email protected]bafe6cd2012-05-23 23:09:502085 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432086 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502087 return NULL;
2088
[email protected]bafe6cd2012-05-23 23:09:502089 return new_contents;
2090}
2091
2092RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2093 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2094 if (iter == pending_widget_views_.end()) {
2095 DCHECK(false);
2096 return NULL;
2097 }
2098
2099 RenderWidgetHostView* widget_host_view = iter->second;
2100 pending_widget_views_.erase(route_id);
2101
2102 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2103 if (!widget_host->GetProcess()->HasConnection()) {
2104 // The view has gone away or the renderer crashed. Nothing to do.
2105 return NULL;
2106 }
2107
2108 return widget_host_view;
2109}
2110
[email protected]f13b4202012-06-12 23:53:232111void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092112 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212113 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372114 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232115 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372116 } else {
2117 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042118 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372119 scoped_ptr<MediaStreamUI>());
2120 }
[email protected]f13b4202012-06-12 23:53:232121}
2122
grunell657d4d82014-09-18 00:09:432123bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2124 MediaStreamType type) {
2125 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2126 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2127 return delegate_ &&
2128 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2129}
2130
[email protected]cc9200432013-07-23 23:02:402131SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2132 SiteInstance* instance) {
2133 return controller_.GetSessionStorageNamespace(instance);
2134}
2135
[email protected]6de7fc482014-06-06 10:46:442136SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2137 return controller_.GetSessionStorageNamespaceMap();
2138}
2139
[email protected]9b159a52013-10-03 17:24:552140FrameTree* WebContentsImpl::GetFrameTree() {
2141 return &frame_tree_;
2142}
2143
lukendc35e7f2014-11-10 19:06:142144void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2145 virtual_keyboard_requested_ = requested;
2146}
2147
2148bool WebContentsImpl::IsVirtualKeyboardRequested() {
2149 return virtual_keyboard_requested_;
2150}
2151
[email protected]95640212014-07-26 18:14:302152AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2153 return accessibility_mode_;
2154}
2155
[email protected]31a71eaf2014-03-13 01:47:362156void WebContentsImpl::AccessibilityEventReceived(
2157 const std::vector<AXEventNotificationDetails>& details) {
2158 FOR_EACH_OBSERVER(
2159 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2160}
2161
dmazzonia656928e2014-09-15 20:28:542162RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402163 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542164 int browser_plugin_instance_id) {
2165 BrowserPluginGuestManager* guest_manager =
2166 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202167 if (!guest_manager)
2168 return nullptr;
2169
dmazzonia656928e2014-09-15 20:28:542170 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442171 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542172 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202173 return nullptr;
2174
dmazzonia656928e2014-09-15 20:28:542175 return guest->GetMainFrame();
2176}
2177
blundellc57b93f2014-10-29 13:19:572178GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2179 return geolocation_service_context_.get();
2180}
2181
alogvinovf50445a2015-10-30 13:00:122182WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2183 return wake_lock_service_context_.get();
2184}
2185
[email protected]edc3af82013-12-12 21:24:072186void WebContentsImpl::OnShowValidationMessage(
2187 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292188 const base::string16& main_text,
2189 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072190 if (delegate_)
2191 delegate_->ShowValidationMessage(
2192 this, anchor_in_root_view, main_text, sub_text);
2193}
2194
2195void WebContentsImpl::OnHideValidationMessage() {
2196 if (delegate_)
2197 delegate_->HideValidationMessage(this);
2198}
2199
2200void WebContentsImpl::OnMoveValidationMessage(
2201 const gfx::Rect& anchor_in_root_view) {
2202 if (delegate_)
2203 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2204}
2205
[email protected]32deec62013-05-15 23:55:042206void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2207 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442208 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042209}
2210
[email protected]95640212014-07-26 18:14:302211BrowserAccessibilityManager*
2212 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452213 RenderFrameHostImpl* rfh = GetMainFrame();
2214 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302215}
2216
2217BrowserAccessibilityManager*
2218 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452219 RenderFrameHostImpl* rfh = GetMainFrame();
2220 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302221}
2222
mohsen7ab1ec16ec2015-07-02 18:26:232223void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2224 RenderFrameHost* focused_frame = GetFocusedFrame();
2225 if (!focused_frame)
2226 return;
2227
2228 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2229 focused_frame->GetRoutingID(), extent));
2230}
2231
2232void WebContentsImpl::SelectRange(const gfx::Point& base,
2233 const gfx::Point& extent) {
2234 RenderFrameHost* focused_frame = GetFocusedFrame();
2235 if (!focused_frame)
2236 return;
2237
2238 focused_frame->Send(
2239 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2240}
2241
aurimasab0319022015-07-10 21:57:382242void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2243 int end_adjust) {
2244 RenderFrameHost* focused_frame = GetFocusedFrame();
2245 if (!focused_frame)
2246 return;
2247
2248 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2249 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492253 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232254 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492255 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332256}
2257
avic3aa8422015-11-09 20:57:222258void WebContentsImpl::ResizeDueToAutoResize(
2259 RenderWidgetHostImpl* render_widget_host,
2260 const gfx::Size& new_size) {
2261 if (render_widget_host != GetRenderViewHost()->GetWidget())
2262 return;
2263
[email protected]61e2b3cc2012-03-02 16:13:342264 if (delegate_)
2265 delegate_->ResizeDueToAutoResize(this, new_size);
2266}
2267
[email protected]b172aee2012-04-10 17:05:262268WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202269 if (!delegate_)
2270 return NULL;
[email protected]00c37fc2011-08-02 00:22:502271
[email protected]e5d549d2011-12-28 01:29:202272 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202273 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342274}
2275
[email protected]6b618e62012-08-16 12:59:182276bool WebContentsImpl::Send(IPC::Message* message) {
2277 if (!GetRenderViewHost()) {
2278 delete message;
2279 return false;
2280 }
2281
2282 return GetRenderViewHost()->Send(message);
2283}
2284
[email protected]a86c0e962013-12-17 17:10:392285void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2286 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442287 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392288 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442289}
2290
[email protected]20ca0382013-02-28 19:50:072291void WebContentsImpl::AttachInterstitialPage(
2292 InterstitialPageImpl* interstitial_page) {
2293 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212294 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292295
2296 // Cancel any visible dialogs so that they don't interfere with the
2297 // interstitial.
creis89a0f782015-05-27 16:13:172298 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292299
[email protected]20ca0382013-02-28 19:50:072300 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2301 DidAttachInterstitialPage());
2302}
2303
2304void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572305 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212306 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072307 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2308 DidDetachInterstitialPage());
2309}
2310
avi2b177592014-12-10 02:08:022311void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2312 int history_length) {
2313 SetHistoryOffsetAndLengthForView(
2314 GetRenderViewHost(), history_offset, history_length);
2315}
2316
2317void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2318 RenderViewHost* render_view_host,
2319 int history_offset,
2320 int history_length) {
2321 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2322 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142323}
2324
[email protected]4fed3702014-04-01 09:08:002325void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172326 RenderFrameHost* focused_frame = GetFocusedFrame();
2327 if (!focused_frame)
2328 return;
2329
[email protected]959be4c2014-04-08 15:01:332330 focused_frame->Send(new FrameMsg_Reload(
2331 focused_frame->GetRoutingID(), ignore_cache));
2332}
2333
2334void WebContentsImpl::Undo() {
2335 RenderFrameHost* focused_frame = GetFocusedFrame();
2336 if (!focused_frame)
2337 return;
2338
2339 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2340 RecordAction(base::UserMetricsAction("Undo"));
2341}
2342
2343void WebContentsImpl::Redo() {
2344 RenderFrameHost* focused_frame = GetFocusedFrame();
2345 if (!focused_frame)
2346 return;
2347 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2348 RecordAction(base::UserMetricsAction("Redo"));
2349}
2350
2351void WebContentsImpl::Cut() {
2352 RenderFrameHost* focused_frame = GetFocusedFrame();
2353 if (!focused_frame)
2354 return;
2355
2356 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2357 RecordAction(base::UserMetricsAction("Cut"));
2358}
2359
2360void WebContentsImpl::Copy() {
2361 RenderFrameHost* focused_frame = GetFocusedFrame();
2362 if (!focused_frame)
2363 return;
2364
2365 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2366 RecordAction(base::UserMetricsAction("Copy"));
2367}
2368
2369void WebContentsImpl::CopyToFindPboard() {
2370#if defined(OS_MACOSX)
2371 RenderFrameHost* focused_frame = GetFocusedFrame();
2372 if (!focused_frame)
2373 return;
2374
2375 // Windows/Linux don't have the concept of a find pasteboard.
2376 focused_frame->Send(
2377 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2378 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2379#endif
2380}
2381
2382void WebContentsImpl::Paste() {
2383 RenderFrameHost* focused_frame = GetFocusedFrame();
2384 if (!focused_frame)
2385 return;
2386
2387 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2388 RecordAction(base::UserMetricsAction("Paste"));
2389}
2390
2391void WebContentsImpl::PasteAndMatchStyle() {
2392 RenderFrameHost* focused_frame = GetFocusedFrame();
2393 if (!focused_frame)
2394 return;
2395
2396 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2397 focused_frame->GetRoutingID()));
2398 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2399}
2400
2401void WebContentsImpl::Delete() {
2402 RenderFrameHost* focused_frame = GetFocusedFrame();
2403 if (!focused_frame)
2404 return;
2405
2406 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2407 RecordAction(base::UserMetricsAction("DeleteSelection"));
2408}
2409
2410void WebContentsImpl::SelectAll() {
2411 RenderFrameHost* focused_frame = GetFocusedFrame();
2412 if (!focused_frame)
2413 return;
2414
2415 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2416 RecordAction(base::UserMetricsAction("SelectAll"));
2417}
2418
2419void WebContentsImpl::Unselect() {
2420 RenderFrameHost* focused_frame = GetFocusedFrame();
2421 if (!focused_frame)
2422 return;
2423
2424 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2425 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172426}
2427
2428void WebContentsImpl::Replace(const base::string16& word) {
2429 RenderFrameHost* focused_frame = GetFocusedFrame();
2430 if (!focused_frame)
2431 return;
2432
[email protected]959be4c2014-04-08 15:01:332433 focused_frame->Send(new InputMsg_Replace(
2434 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172435}
2436
2437void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2438 RenderFrameHost* focused_frame = GetFocusedFrame();
2439 if (!focused_frame)
2440 return;
2441
[email protected]959be4c2014-04-08 15:01:332442 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2443 focused_frame->GetRoutingID(), word));
2444}
2445
2446void WebContentsImpl::NotifyContextMenuClosed(
2447 const CustomContextMenuContext& context) {
2448 RenderFrameHost* focused_frame = GetFocusedFrame();
2449 if (!focused_frame)
2450 return;
2451
2452 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2453 focused_frame->GetRoutingID(), context));
2454}
2455
2456void WebContentsImpl::ExecuteCustomContextMenuCommand(
2457 int action, const CustomContextMenuContext& context) {
2458 RenderFrameHost* focused_frame = GetFocusedFrame();
2459 if (!focused_frame)
2460 return;
2461
2462 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2463 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002464}
2465
[email protected]fc2b46b2014-05-03 16:33:452466gfx::NativeView WebContentsImpl::GetNativeView() {
2467 return view_->GetNativeView();
2468}
2469
2470gfx::NativeView WebContentsImpl::GetContentNativeView() {
2471 return view_->GetContentNativeView();
2472}
2473
2474gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2475 return view_->GetTopLevelNativeWindow();
2476}
2477
2478gfx::Rect WebContentsImpl::GetViewBounds() {
2479 return view_->GetViewBounds();
2480}
2481
2482gfx::Rect WebContentsImpl::GetContainerBounds() {
2483 gfx::Rect rv;
2484 view_->GetContainerBounds(&rv);
2485 return rv;
2486}
2487
2488DropData* WebContentsImpl::GetDropData() {
2489 return view_->GetDropData();
2490}
2491
2492void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042493 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452494}
2495
2496void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042497 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452498}
2499
2500void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042501 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452502}
2503
2504void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042505 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452506}
2507
[email protected]b172aee2012-04-10 17:05:262508void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272509 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212510 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542511 return;
2512 }
[email protected]0b431992014-06-24 00:08:032513 RenderWidgetHostView* const fullscreen_view =
2514 GetFullscreenRenderWidgetHostView();
2515 if (fullscreen_view) {
2516 fullscreen_view->Focus();
2517 return;
2518 }
creisc014b402015-04-23 16:41:452519 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542520}
2521
[email protected]b172aee2012-04-10 17:05:262522bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212523 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542524}
2525
[email protected]b172aee2012-04-10 17:05:262526InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212527 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222528}
2529
[email protected]b172aee2012-04-10 17:05:262530bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162531 // WebKit creates Document object when MIME type is application/xhtml+xml,
2532 // so we also support this MIME type.
2533 return contents_mime_type_ == "text/html" ||
2534 contents_mime_type_ == "text/xml" ||
2535 contents_mime_type_ == "application/xhtml+xml" ||
2536 contents_mime_type_ == "text/plain" ||
2537 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252538 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162539}
2540
[email protected]b172aee2012-04-10 17:05:262541void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592542 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162543 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552544 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192545 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142546 return;
[email protected]c7dd2f62011-07-18 15:57:592547 }
2548
2549 Stop();
2550
2551 // Create the save package and possibly prompt the user for the name to save
2552 // the page as. The user prompt is an asynchronous operation that runs on
2553 // another thread.
2554 save_package_ = new SavePackage(this);
2555 save_package_->GetSaveInfo();
2556}
2557
2558// Used in automated testing to bypass prompting the user for file names.
2559// Instead, the names and paths are hard coded rather than running them through
2560// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342561bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2562 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212563 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592564 // Stop the page from navigating.
2565 Stop();
2566
2567 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212568 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592569}
2570
[email protected]3c71576ce2013-07-23 02:00:012571void WebContentsImpl::SaveFrame(const GURL& url,
2572 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372573 SaveFrameWithHeaders(url, referrer, std::string());
2574}
2575
2576void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2577 const Referrer& referrer,
2578 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192579 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012580 return;
sammc92af61552014-11-19 23:27:402581 if (delegate_ && delegate_->SaveFrame(url, referrer))
2582 return;
2583
nasko89ad7742015-03-05 22:14:192584 // TODO(nasko): This check for main frame is incorrect and should be fixed
2585 // by explicitly passing in which frame this method should target.
2586 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012587
2588 DownloadManager* dlm =
2589 BrowserContext::GetDownloadManager(GetBrowserContext());
2590 if (!dlm)
2591 return;
avib7348942015-12-25 20:57:102592 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012593 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272594 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012595 if (entry)
2596 post_id = entry->GetPostID();
2597 }
2598 scoped_ptr<DownloadUrlParameters> params(
2599 DownloadUrlParameters::FromWebContents(this, url));
2600 params->set_referrer(referrer);
2601 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012602 if (post_id >= 0)
2603 params->set_method("POST");
2604 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372605
2606 if (headers.empty()) {
2607 params->set_prefer_cache(true);
2608 } else {
brettw26dab8f02015-08-08 00:28:472609 for (const base::StringPiece& key_value :
2610 base::SplitStringPiece(
2611 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2612 std::vector<std::string> pair = base::SplitString(
2613 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372614 DCHECK_EQ(2ul, pair.size());
2615 params->add_request_header(pair[0], pair[1]);
2616 }
2617 }
dcheng36b6aec92015-12-26 06:16:362618 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012619}
2620
[email protected]b172aee2012-04-10 17:05:262621void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342622 const base::FilePath& file,
avib7348942015-12-25 20:57:102623 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482624 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122625}
2626
[email protected]b172aee2012-04-10 17:05:262627const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272628 return contents_mime_type_;
2629}
2630
[email protected]b172aee2012-04-10 17:05:262631bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272632 return notify_disconnection_;
2633}
2634
[email protected]b172aee2012-04-10 17:05:262635void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312636 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182637 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162638}
2639
[email protected]b172aee2012-04-10 17:05:262640void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542641 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182642 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162643}
2644
[email protected]8ff00d72012-10-23 19:12:212645RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272646 return &renderer_preferences_;
2647}
2648
[email protected]e35ccd52012-05-23 16:22:472649void WebContentsImpl::Close() {
2650 Close(GetRenderViewHost());
2651}
2652
[email protected]cf200a562013-05-03 16:24:292653void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462654 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292655 if (browser_plugin_embedder_.get())
2656 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2657 screen_x, screen_y, operation);
2658 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452659 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2660 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292661}
2662
[email protected]d60f3702013-12-26 16:30:242663void WebContentsImpl::DidGetResourceResponseStart(
2664 const ResourceRequestDetails& details) {
2665 controller_.ssl_manager()->DidStartResourceResponse(details);
2666
2667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2668 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242669}
2670
2671void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462672 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242673 const ResourceRedirectDetails& details) {
2674 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2675
2676 FOR_EACH_OBSERVER(
2677 WebContentsObserver,
2678 observers_,
creis114ca1b2014-11-13 23:51:462679 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242680
2681 // TODO(avi): Remove. http://crbug.com/170921
2682 NotificationService::current()->Notify(
2683 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2684 Source<WebContents>(this),
2685 Details<const ResourceRedirectDetails>(&details));
clamybd8f0432015-12-17 16:06:232686
2687 if (IsResourceTypeFrame(details.resource_type)) {
2688 NavigationHandleImpl* navigation_handle =
2689 static_cast<RenderFrameHostImpl*>(render_frame_host)
2690 ->navigation_handle();
2691 if (navigation_handle)
2692 navigation_handle->DidRedirectNavigation(details.new_url);
2693 }
[email protected]d60f3702013-12-26 16:30:242694}
2695
calamity7fe55ce2015-04-10 03:59:372696void WebContentsImpl::NotifyWebContentsFocused() {
2697 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2698}
2699
[email protected]b172aee2012-04-10 17:05:262700void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522701 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452702 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292703 if (browser_plugin_embedder_.get())
2704 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342705}
2706
[email protected]e35ccd52012-05-23 16:22:472707void WebContentsImpl::UserGestureDone() {
avic3aa8422015-11-09 20:57:222708 OnUserGesture(GetRenderViewHost()->GetWidget());
[email protected]e35ccd52012-05-23 16:22:472709}
2710
[email protected]b172aee2012-04-10 17:05:262711void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272712 closed_by_user_gesture_ = value;
2713}
2714
[email protected]b172aee2012-04-10 17:05:262715bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272716 return closed_by_user_gesture_;
2717}
2718
[email protected]b172aee2012-04-10 17:05:262719void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502720 if (!delegate_)
2721 return;
2722
[email protected]6286a372013-10-09 04:03:272723 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2724 if (!entry)
[email protected]1788e772010-12-15 16:40:502725 return;
2726
[email protected]6286a372013-10-09 04:03:272727 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122728}
2729
[email protected]b172aee2012-04-10 17:05:262730void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042731 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272732 if (!delegate_)
2733 return;
2734
[email protected]691aa2f2013-05-28 22:52:042735 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272736}
2737
[email protected]b172aee2012-04-10 17:05:262738int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272739 return minimum_zoom_percent_;
2740}
2741
[email protected]b172aee2012-04-10 17:05:262742int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272743 return maximum_zoom_percent_;
2744}
2745
mcnee432e47d2015-11-09 19:37:462746void WebContentsImpl::SetPageScale(float page_scale_factor) {
2747 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242748}
2749
[email protected]b172aee2012-04-10 17:05:262750gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492751 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232752}
2753
[email protected]b172aee2012-04-10 17:05:262754bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052755 if (GetBrowserPluginGuest())
2756 return GetBrowserPluginGuest()->LockMouse(allowed);
2757
creisc014b402015-04-23 16:41:452758 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432759 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2760 allowed)
creisc014b402015-04-23 16:41:452761 : false;
[email protected]0bfbf882011-12-22 18:19:272762}
2763
[email protected]b172aee2012-04-10 17:05:262764bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212765 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502766}
2767
alexmose201c7cd2015-06-10 17:14:212768WebContentsImpl* WebContentsImpl::GetOpener() const {
2769 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2770 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572771}
2772
[email protected]cb805452013-05-22 15:16:212773void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482774 if (!color_chooser_info_.get())
2775 return;
2776 RenderFrameHost* rfh = RenderFrameHost::FromID(
2777 color_chooser_info_->render_process_id,
2778 color_chooser_info_->render_frame_id);
2779 if (!rfh)
2780 return;
2781
2782 rfh->Send(new FrameMsg_DidChooseColorResponse(
2783 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202784}
2785
[email protected]cb805452013-05-22 15:16:212786void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482787 if (!color_chooser_info_.get())
2788 return;
2789 RenderFrameHost* rfh = RenderFrameHost::FromID(
2790 color_chooser_info_->render_process_id,
2791 color_chooser_info_->render_frame_id);
2792 if (!rfh)
2793 return;
2794
2795 rfh->Send(new FrameMsg_DidEndColorChooser(
2796 rfh->GetRoutingID(), color_chooser_info_->identifier));
2797 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202798}
2799
halton.huoca2eabd2015-07-06 08:17:402800int WebContentsImpl::DownloadImage(
2801 const GURL& url,
2802 bool is_favicon,
2803 uint32_t max_bitmap_size,
2804 bool bypass_cache,
2805 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552806 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402807 static int next_image_download_id = 0;
2808 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2809 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552810 const int download_id = ++next_image_download_id;
2811 if (!mojo_image_downloader) {
2812 // If the renderer process is dead (i.e. crash, or memory pressure on
2813 // Android), the downloader service will be invalid. Pre-Mojo, this would
2814 // hang the callback indefinetly since the IPC would be dropped. Now,
2815 // respond with a 400 HTTP error code to indicate that something went wrong.
2816 BrowserThread::PostTask(
2817 BrowserThread::UI, FROM_HERE,
2818 base::Bind(&WebContents::ImageDownloadCallback::Run,
2819 base::Owned(new ImageDownloadCallback(callback)),
2820 download_id, 400, url, std::vector<SkBitmap>(),
2821 std::vector<gfx::Size>()));
2822 return download_id;
2823 }
2824
halton.huoca2eabd2015-07-06 08:17:402825 image_downloader::DownloadRequestPtr req =
2826 image_downloader::DownloadRequest::New();
2827
2828 req->url = mojo::String::From(url);
2829 req->is_favicon = is_favicon;
2830 req->max_bitmap_size = max_bitmap_size;
2831 req->bypass_cache = bypass_cache;
2832
2833 mojo_image_downloader->DownloadImage(
dcheng36b6aec92015-12-26 06:16:362834 std::move(req),
amistry9f01b772015-07-29 01:54:552835 base::Bind(&DidDownloadImage, callback, download_id, url));
2836 return download_id;
[email protected]795c28972012-12-06 06:13:392837}
2838
[email protected]5dcaf8e2013-12-28 01:31:422839bool WebContentsImpl::IsSubframe() const {
2840 return is_subframe_;
2841}
2842
[email protected]36ec24f2014-01-09 00:32:082843void WebContentsImpl::Find(int request_id,
2844 const base::string16& search_text,
2845 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:332846 // Cowardly refuse to search for no text.
2847 if (search_text.empty()) {
2848 NOTREACHED();
2849 return;
2850 }
2851
raymes0fa0be52014-10-13 20:38:092852 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472853 if (browser_plugin_embedder_ &&
2854 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2855 return;
raymes0fa0be52014-10-13 20:38:092856 }
[email protected]36ec24f2014-01-09 00:32:082857 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2858}
2859
2860void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012861 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472862 if (browser_plugin_embedder_ &&
2863 browser_plugin_embedder_->StopFinding(action)) {
2864 return;
raymes2bc64182015-02-06 01:23:012865 }
[email protected]36ec24f2014-01-09 00:32:082866 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2867}
2868
[email protected]4fe53add2014-04-08 19:53:362869void WebContentsImpl::InsertCSS(const std::string& css) {
2870 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2871 GetMainFrame()->GetRoutingID(), css));
2872}
2873
dalecurtisbc6572e12014-09-12 19:22:302874bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152875 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302876}
2877
mlamouriefdca9d2014-09-16 16:55:402878void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2879 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2880}
2881
dominickn6919ce32015-10-15 01:52:282882void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2883 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2884}
2885
mlamouri7a78d6fd2015-01-17 13:23:532886void WebContentsImpl::ExitFullscreen() {
2887 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432888 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
mlamouri7a78d6fd2015-01-17 13:23:532889 ExitFullscreenMode();
2890}
2891
mariakhomenko44bdc4732015-04-29 01:55:382892void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372893 if (delayed_open_url_params_.get()) {
2894 OpenURL(*delayed_open_url_params_.get());
2895 delayed_open_url_params_.reset(nullptr);
2896 return;
2897 }
2898
mariakhomenko44bdc4732015-04-29 01:55:382899 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2900 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162901 if (is_resume_pending_) {
2902 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:132903 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:162904 GetMainFrame()->Init();
2905 }
mariakhomenko44bdc4732015-04-29 01:55:382906}
2907
[email protected]b172aee2012-04-10 17:05:262908bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272909 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172910 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332911 return true;
2912 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272913}
2914
[email protected]b172aee2012-04-10 17:05:262915void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272916 if (delegate_)
2917 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212918}
2919
clamy0e119882015-07-31 16:12:332920void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2922 DidStartNavigation(navigation_handle));
2923}
2924
2925void WebContentsImpl::DidRedirectNavigation(
2926 NavigationHandle* navigation_handle) {
2927 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2928 DidRedirectNavigation(navigation_handle));
2929}
2930
clamyefca29e2015-09-17 00:22:112931void WebContentsImpl::ReadyToCommitNavigation(
2932 NavigationHandle* navigation_handle) {
2933 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2934 ReadyToCommitNavigation(navigation_handle));
2935}
2936
clamy0e119882015-07-31 16:12:332937void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
2938 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2939 DidFinishNavigation(navigation_handle));
2940}
2941
[email protected]52913802013-12-10 05:52:182942void WebContentsImpl::DidStartProvisionalLoad(
2943 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182944 const GURL& validated_url,
2945 bool is_error_page,
2946 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102947 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482948 FOR_EACH_OBSERVER(
2949 WebContentsObserver,
2950 observers_,
2951 DidStartProvisionalLoadForFrame(
2952 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082953
2954 // Notify accessibility if this is a reload.
2955 NavigationEntry* entry = controller_.GetVisibleEntry();
2956 if (entry && ui::PageTransitionCoreTypeIs(
2957 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2958 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2959 BrowserAccessibilityManager* manager =
2960 ftn->current_frame_host()->browser_accessibility_manager();
2961 if (manager)
2962 manager->UserIsReloading();
2963 }
[email protected]400992b2012-06-14 00:03:542964}
2965
[email protected]3109fbb72014-01-06 23:57:152966void WebContentsImpl::DidFailProvisionalLoadWithError(
2967 RenderFrameHostImpl* render_frame_host,
2968 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2969 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312970 FOR_EACH_OBSERVER(WebContentsObserver,
2971 observers_,
2972 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312973 validated_url,
2974 params.error_code,
gsennton6fbb38692015-06-24 19:23:552975 params.error_description,
2976 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:082977
2978 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2979 BrowserAccessibilityManager* manager =
2980 ftn->current_frame_host()->browser_accessibility_manager();
2981 if (manager)
2982 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152983}
2984
[email protected]b80624c2014-02-09 02:46:552985void WebContentsImpl::DidFailLoadWithError(
2986 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552987 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552988 int error_code,
gsennton6fbb38692015-06-24 19:23:552989 const base::string16& error_description,
2990 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:142991 FOR_EACH_OBSERVER(
2992 WebContentsObserver,
2993 observers_,
gsennton6fbb38692015-06-24 19:23:552994 DidFailLoad(render_frame_host, url, error_code, error_description,
2995 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:552996}
2997
[email protected]52913802013-12-10 05:52:182998void WebContentsImpl::NotifyChangedNavigationState(
2999 InvalidateTypes changed_flags) {
3000 NotifyNavigationStateChanged(changed_flags);
3001}
3002
[email protected]3691e5cf2014-01-22 10:16:203003void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203004 const GURL& url,
3005 NavigationController::ReloadType reload_type) {
3006 // Notify observers about navigation.
3007 FOR_EACH_OBSERVER(
3008 WebContentsObserver,
3009 observers_,
3010 DidStartNavigationToPendingEntry(url, reload_type));
3011}
3012
[email protected]8cb834e2014-03-06 14:23:233013void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3014 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503015 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3016 // weak pointer of sorts.
3017 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3018 const int32_t frame_id = render_frame_host->GetRoutingID();
3019
[email protected]65920f332014-03-04 21:14:183020 WebContents* new_contents = OpenURL(params);
3021
dchengb907f7332015-01-07 20:35:503022 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183023 // Notify observers.
3024 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3025 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463026 render_frame_host,
[email protected]65920f332014-03-04 21:14:183027 params.url,
3028 params.referrer,
3029 params.disposition,
creis114ca1b2014-11-13 23:51:463030 params.transition));
[email protected]65920f332014-03-04 21:14:183031 }
3032}
3033
creis29460272015-12-16 04:38:223034bool WebContentsImpl::ShouldTransferNavigation() {
3035 if (!delegate_)
3036 return true;
3037 return delegate_->ShouldTransferNavigation();
3038}
3039
[email protected]aa62afd2014-04-22 19:22:463040bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3041 if (!delegate_)
3042 return false;
3043 return delegate_->ShouldPreserveAbortedURLs(this);
3044}
3045
[email protected]37567b432014-02-12 01:12:223046void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433047 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223048 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353049 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223050 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483051 FOR_EACH_OBSERVER(WebContentsObserver,
3052 observers_,
3053 DidCommitProvisionalLoadForFrame(
3054 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083055
3056 BrowserAccessibilityManager* manager =
3057 render_frame_host->browser_accessibility_manager();
3058 if (manager)
3059 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223060}
3061
[email protected]0d0f4c492014-04-02 06:42:573062void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233063 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573064 // Ensure fullscreen mode is exited before committing the navigation to a
3065 // different page. The next page will not start out assuming it is in
3066 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233067 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193068 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573069 return;
3070 }
avibf58fa0c2015-11-11 01:45:523071 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
mlamouri7a78d6fd2015-01-17 13:23:533072 ExitFullscreen();
avibf58fa0c2015-11-11 01:45:523073 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573074}
3075
[email protected]37567b432014-02-12 01:12:223076void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283077 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223078 const LoadCommittedDetails& details,
3079 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3080 if (details.is_navigation_to_different_page()) {
3081 // Clear the status bubble. This is a workaround for a bug where WebKit
3082 // doesn't let us know that the cursor left an element during a
3083 // transition (this is also why the mouse cursor remains as a hand after
3084 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3085 // clear the bubble when a user navigates to a named anchor in the same
3086 // page.
sky8b00392d2015-01-10 00:30:283087 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003088
3089 RenderWidgetHostViewBase* rwhvb =
3090 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3091 if (rwhvb)
3092 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283093
peter90afaba2015-06-01 12:05:293094 did_first_visually_non_empty_paint_ = false;
3095
yusufod41c5f92015-03-06 00:14:283096 // Reset theme color on navigation to new page.
3097 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223098 }
3099
3100 if (!details.is_in_page) {
3101 // Once the main frame is navigated, we're no longer considered to have
3102 // displayed insecure content.
3103 displayed_insecure_content_ = false;
3104 SSLManager::NotifySSLInternalStateChanged(
3105 GetController().GetBrowserContext());
3106 }
3107
3108 // Notify observers about navigation.
3109 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3110 DidNavigateMainFrame(details, params));
3111
[email protected]e85165c642014-06-10 14:34:313112 if (delegate_)
[email protected]37567b432014-02-12 01:12:223113 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313114 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223115}
3116
3117void WebContentsImpl::DidNavigateAnyFramePostCommit(
3118 RenderFrameHostImpl* render_frame_host,
3119 const LoadCommittedDetails& details,
3120 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103121 // Now that something has committed, we don't need to track whether the
3122 // initial page has been accessed.
3123 has_accessed_initial_document_ = false;
3124
[email protected]37567b432014-02-12 01:12:223125 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173126 if (!details.is_in_page)
3127 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223128
3129 // Notify observers about navigation.
3130 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093131 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223132}
3133
3134void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3135 contents_mime_type_ = mime_type;
3136}
3137
[email protected]277857a2014-06-03 10:38:013138bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313139 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053140 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313141 return false;
3142
[email protected]37567b432014-02-12 01:12:223143 if (delegate_)
3144 return delegate_->CanOverscrollContent();
3145
3146 return false;
3147}
3148
[email protected]37b64c52014-07-11 21:14:053149void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293150 // Update the theme color. This is to be published to observers after the
3151 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283152 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293153
3154 if (did_first_visually_non_empty_paint_ &&
3155 last_sent_theme_color_ != theme_color_) {
3156 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3157 DidChangeThemeColor(theme_color_));
3158 last_sent_theme_color_ = theme_color_;
3159 }
[email protected]e7104762014-06-20 19:17:253160}
3161
[email protected]b172aee2012-04-10 17:05:263162void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183163 const GURL& url,
[email protected]70435962011-08-02 20:13:283164 const std::string& security_info,
3165 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183166 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403167 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533168 SSLStatus status;
3169 if (!DeserializeSecurityInfo(security_info, &status)) {
3170 bad_message::ReceivedBadMessage(
3171 GetRenderProcessHost(),
3172 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3173 return;
3174 }
[email protected]724159a2010-12-30 01:11:183175
3176 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593177 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213178 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263179 url, status.cert_id, status.cert_status, http_method, mime_type,
3180 resource_type);
[email protected]724159a2010-12-30 01:11:183181
[email protected]b0f724c2013-09-05 04:21:133182 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3183
3184 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3185 DidLoadResourceFromMemoryCache(details));
3186
[email protected]8bfc8272013-09-09 20:10:533187 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3188 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403189 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533190 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3191 GetRenderProcessHost()->GetID()) :
3192 GetBrowserContext()->GetRequestContextForRenderProcess(
3193 GetRenderProcessHost()->GetID()));
3194 BrowserThread::PostTask(
3195 BrowserThread::IO,
3196 FROM_HERE,
3197 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3198 }
[email protected]724159a2010-12-30 01:11:183199}
3200
[email protected]b172aee2012-04-10 17:05:263201void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393202 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183203 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193204 SSLManager::NotifySSLInternalStateChanged(
3205 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183206}
3207
estark910b4572015-12-09 20:55:413208void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3209 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583210 LOG(WARNING) << security_origin << " ran insecure content from "
3211 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393212 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413213 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293214 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393215 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183216 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193217 SSLManager::NotifySSLInternalStateChanged(
3218 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183219}
3220
estark910b4572015-12-09 20:55:413221void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3222 const GURL& url,
3223 const std::string& security_info) {
3224 SSLStatus ssl;
3225 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3226 bad_message::ReceivedBadMessage(
3227 GetRenderProcessHost(),
3228 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3229 return;
3230 }
3231
3232 displayed_insecure_content_ = true;
3233 SSLManager::NotifySSLInternalStateChanged(
3234 GetController().GetBrowserContext());
3235}
3236
3237void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3238 const GURL& security_origin,
3239 const GURL& url,
3240 const std::string& security_info) {
3241 SSLStatus ssl;
3242 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3243 bad_message::ReceivedBadMessage(
3244 GetRenderProcessHost(),
3245 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3246 return;
3247 }
3248
3249 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3250 SSLManager::NotifySSLInternalStateChanged(
3251 GetController().GetBrowserContext());
3252}
3253
[email protected]501052ff2014-02-21 22:19:073254void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113255 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473256 return;
naskofbd033392015-01-27 02:34:473257
[email protected]1d62cf72014-02-07 21:31:573258 RenderFrameHostImpl* rfh =
3259 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143260 FOR_EACH_OBSERVER(
3261 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183262}
3263
naskofbd033392015-01-27 02:34:473264void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113265 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123266 return;
[email protected]a1b99262013-12-27 21:56:223267
[email protected]8b3af1e2014-01-24 13:29:123268 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443269 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373270 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423271 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373272
[email protected]61ac9e242014-03-21 20:55:263273 RenderFrameHostImpl* rfh =
3274 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143275 FOR_EACH_OBSERVER(
3276 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313277}
3278
[email protected]b172aee2012-04-10 17:05:263279void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573280 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3281 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263282}
3283
[email protected]b172aee2012-04-10 17:05:263284void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303285 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263286 minimum_zoom_percent_ = minimum_percent;
3287 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263288}
3289
mcnee432e47d2015-11-09 19:37:463290void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3291 bool is_one = page_scale_factor == 1.f;
3292 if (is_one != page_scale_factor_is_one_) {
3293 page_scale_factor_is_one_ = is_one;
3294
3295 HostZoomMapImpl* host_zoom_map =
3296 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3297
3298 if (host_zoom_map && GetRenderProcessHost()) {
3299 host_zoom_map->SetPageScaleFactorIsOneForView(
3300 GetRenderProcessHost()->GetID(), GetRoutingID(),
3301 page_scale_factor_is_one_);
3302 }
3303 }
3304
3305 FOR_EACH_OBSERVER(WebContentsObserver,
3306 observers_,
3307 OnPageScaleFactorChanged(page_scale_factor));
3308}
3309
[email protected]b172aee2012-04-10 17:05:263310void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343311 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433312 if (!delegate_)
3313 return;
3314
[email protected]b9535422012-02-09 01:47:593315 ChildProcessSecurityPolicyImpl* policy =
3316 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223317 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593318 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213319}
3320
[email protected]b172aee2012-04-10 17:05:263321void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3322 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263323 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363324 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433325 if (!delegate_)
3326 return;
3327
[email protected]b9535422012-02-09 01:47:593328 ChildProcessSecurityPolicyImpl* policy =
3329 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323330 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593331 return;
[email protected]8f810632013-06-06 22:33:323332
[email protected]c125e532014-05-10 20:39:063333 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203334}
3335
[email protected]f5273e52014-07-14 16:30:203336void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3337 const GURL& url,
3338 bool user_gesture) {
3339 if (!delegate_)
3340 return;
3341
3342 ChildProcessSecurityPolicyImpl* policy =
3343 ChildProcessSecurityPolicyImpl::GetInstance();
3344 if (policy->IsPseudoScheme(protocol))
3345 return;
3346
3347 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3348}
3349
kouhei40f03cb2015-09-24 07:47:013350void WebContentsImpl::OnUpdatePageImportanceSignals(
3351 const PageImportanceSignals& signals) {
3352 page_importance_signals_ = signals;
3353}
3354
[email protected]b172aee2012-04-10 17:05:263355void WebContentsImpl::OnFindReply(int request_id,
3356 int number_of_matches,
3357 const gfx::Rect& selection_rect,
3358 int active_match_ordinal,
3359 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433360 if (delegate_) {
3361 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3362 active_match_ordinal, final_update);
3363 }
[email protected]b888919c2011-09-02 00:32:163364}
3365
mfomitchev841f8182015-11-07 02:03:193366#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]59363fc92012-09-05 03:46:313367void WebContentsImpl::OnFindMatchRectsReply(
3368 int version,
3369 const std::vector<gfx::RectF>& rects,
3370 const gfx::RectF& active_rect) {
3371 if (delegate_)
3372 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3373}
[email protected]583418cc2013-01-17 14:01:103374
[email protected]1ff427972013-02-07 21:14:073375void WebContentsImpl::OnOpenDateTimeDialog(
3376 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173377 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093378 GetRenderViewHost(),
3379 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133380 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093381 value.minimum,
3382 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173383 value.step,
3384 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103385}
[email protected]59363fc92012-09-05 03:46:313386#endif
3387
avi60bd4902015-09-23 20:39:243388void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3389 std::string json = json_string;
3390 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3391 Source<WebContents>(this),
3392 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403393}
3394
[email protected]b172aee2012-04-10 17:05:263395void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3396 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103397 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253398 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103399 AppCacheAccessed(manifest_url, blocked_by_policy));
3400}
3401
[email protected]8bc5ff02013-11-29 06:34:033402void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483403 int color_chooser_id,
3404 SkColor color,
3405 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113406 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003407 return;
nasko907fcb62015-01-28 04:24:113408
[email protected]aa62afd2014-04-22 19:22:463409 ColorChooser* new_color_chooser = delegate_ ?
3410 delegate_->OpenColorChooser(this, color, suggestions) :
3411 NULL;
[email protected]820957a2014-01-14 14:56:303412 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213413 return;
[email protected]8ed16472014-04-11 19:02:483414 if (color_chooser_info_.get())
3415 color_chooser_info_->chooser->End();
3416
3417 color_chooser_info_.reset(new ColorChooserInfo(
3418 render_frame_message_source_->GetProcess()->GetID(),
3419 render_frame_message_source_->GetRoutingID(),
3420 new_color_chooser,
3421 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203422}
3423
[email protected]b172aee2012-04-10 17:05:263424void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483425 if (color_chooser_info_ &&
3426 color_chooser_id == color_chooser_info_->identifier)
3427 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203428}
3429
[email protected]b172aee2012-04-10 17:05:263430void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323431 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483432 if (color_chooser_info_ &&
3433 color_chooser_id == color_chooser_info_->identifier)
3434 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203435}
3436
[email protected]d0759f492012-04-19 22:50:503437// This exists for render views that don't have a WebUI, but do have WebUI
3438// bindings enabled.
3439void WebContentsImpl::OnWebUISend(const GURL& source_url,
3440 const std::string& name,
3441 const base::ListValue& args) {
3442 if (delegate_)
3443 delegate_->WebUISend(this, source_url, name, args);
3444}
3445
thestigc4cac8f2014-09-04 21:17:503446#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003447void WebContentsImpl::OnPepperInstanceCreated() {
3448 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3449}
3450
3451void WebContentsImpl::OnPepperInstanceDeleted() {
3452 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3453}
3454
tommyclie6633ca72014-10-31 00:40:423455void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3456 const base::FilePath& path,
3457 bool is_hung) {
3458 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3459
3460 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3461 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3462}
3463
3464void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3465 base::ProcessId plugin_pid) {
3466 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3467 PluginCrashed(plugin_path, plugin_pid));
3468}
3469
[email protected]d8415ad92012-08-23 14:40:503470void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443471 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503472 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343473 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163474 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443475 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163476 return;
[email protected]d8415ad92012-08-23 14:40:503477 }
3478
[email protected]8c8fc292012-11-23 18:57:163479 if (!delegate_->RequestPpapiBrokerPermission(
3480 this, url, plugin_path,
3481 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443482 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163483 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443484 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163485 }
[email protected]d8415ad92012-08-23 14:40:503486}
3487
[email protected]ea0309c2013-08-06 19:35:443488void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503489 bool result) {
[email protected]ea0309c2013-08-06 19:35:443490 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503491}
3492
fsamuel833ee7c2015-02-13 23:40:403493void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3494 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393495 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143496 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403497 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373498}
tommyclie6633ca72014-10-31 00:40:423499#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373500
[email protected]795c28972012-12-06 06:13:393501void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393502 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063503 // We get updated favicon URLs after the page stops loading. If a cross-site
3504 // navigation occurs while a page is still loading, the initial page
3505 // may stop loading and send us updated favicon URLs after the navigation
3506 // for the new page has committed.
3507 RenderViewHostImpl* rvhi =
3508 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3509 if (!rvhi->is_active())
3510 return;
3511
[email protected]795c28972012-12-06 06:13:393512 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293513 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393514}
3515
avayvod41634b12015-07-08 17:07:053516#if defined(OS_ANDROID)
3517
3518void WebContentsImpl::OnMediaSessionStateChanged() {
3519 MediaSession* session = MediaSession::Get(this);
3520 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3521 MediaSessionStateChanged(session->IsControllable(),
3522 session->IsSuspended()));
3523}
3524
3525void WebContentsImpl::ResumeMediaSession() {
3526 MediaSession::Get(this)->Resume();
3527}
3528
3529void WebContentsImpl::SuspendMediaSession() {
3530 MediaSession::Get(this)->Suspend();
3531}
3532
mlamouri4c4fbed2015-08-17 15:51:013533void WebContentsImpl::StopMediaSession() {
3534 MediaSession::Get(this)->Stop();
3535}
3536
avayvod41634b12015-07-08 17:07:053537#endif // defined(OS_ANDROID)
3538
[email protected]50279492014-05-05 23:24:293539void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153540 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293541 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283542
peter90afaba2015-06-01 12:05:293543 did_first_visually_non_empty_paint_ = true;
3544
yusufod41c5f92015-03-06 00:14:283545 if (theme_color_ != last_sent_theme_color_) {
3546 // Theme color should have updated by now if there was one.
3547 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3548 DidChangeThemeColor(theme_color_));
3549 last_sent_theme_color_ = theme_color_;
3550 }
[email protected]9f268072013-11-07 00:02:153551}
[email protected]d9030b82013-07-19 08:26:063552
[email protected]e67ebf32013-02-13 11:07:193553void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013554 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073555 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013556
estark5ea80e52015-06-19 18:43:123557 SecurityStyleExplanations security_style_explanations;
3558 SecurityStyle security_style =
3559 delegate_->GetSecurityStyle(this, &security_style_explanations);
3560 FOR_EACH_OBSERVER(
3561 WebContentsObserver, observers_,
3562 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013563 }
[email protected]e67ebf32013-02-13 11:07:193564}
3565
[email protected]17e286e2013-03-01 23:29:393566void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3567 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3568 BeforeFormRepostWarningShow());
3569}
3570
[email protected]ec6c05f2013-10-23 18:41:573571void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3572 Activate();
3573 if (delegate_)
3574 delegate_->ShowRepostFormWarningDialog(this);
3575}
3576
[email protected]b4c84012014-04-28 19:51:103577bool WebContentsImpl::HasAccessedInitialDocument() {
3578 return has_accessed_initial_document_;
3579}
3580
[email protected]96d185d2009-04-24 03:28:543581// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593582// loading, or done loading.
fdegans6ce28f52015-03-19 12:52:223583void WebContentsImpl::SetIsLoading(bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093584 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263585 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543586 if (is_loading == is_loading_)
3587 return;
3588
3589 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263590 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3591 base::string16());
[email protected]96d185d2009-04-24 03:28:543592 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563593 upload_size_ = 0;
3594 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543595 }
3596
[email protected]fa944cb82013-11-15 17:51:213597 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543598
3599 is_loading_ = is_loading;
3600 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033601 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543602
[email protected]6ebdc9b2010-09-27 16:55:573603 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093604 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213605 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543606
[email protected]eab61442013-11-14 18:35:483607 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593608 if (is_loading) {
carloskc13951a2015-12-30 16:51:543609 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3610 this, "URL", url, "Main FrameTreeNode id",
3611 GetFrameTree()->root()->frame_tree_node_id());
fdegans6ce28f52015-03-19 12:52:223612 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593613 } else {
naskob8744d22014-08-28 17:07:433614 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3615 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223616 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593617 }
[email protected]66798902013-10-01 18:40:163618
3619 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213620 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3621 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543622 if (details)
[email protected]8ff00d72012-10-23 19:12:213623 det = Details<LoadNotificationDetails>(details);
3624 NotificationService::current()->Notify(
3625 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543626}
3627
[email protected]b172aee2012-04-10 17:05:263628void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463629 // If we are creating a RVH for a restored controller, then we need to make
3630 // sure the RenderView starts with a next_page_id_ larger than the number
3631 // of restored entries. This must be called before the RenderView starts
3632 // navigating (to avoid a race between the browser updating max_page_id and
3633 // the renderer updating next_page_id_). Because of this, we only call this
3634 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563635 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583636 if (max_restored_page_id >
3637 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3638 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3639 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323640}
3641
[email protected]b172aee2012-04-10 17:05:263642bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263643 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323644 // For file URLs without a title, use the pathname instead. In the case of a
3645 // synthesized title, we don't want the update to count toward the "one set
3646 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263647 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323648 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513649 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243650 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323651 explicit_set = false; // Don't count synthetic titles toward the set limit.
3652 } else {
[email protected]8af69c6c2014-03-03 19:05:313653 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323654 explicit_set = true;
3655 }
3656
[email protected]987fc3a2011-05-26 14:18:093657 // If a page is created via window.open and never navigated,
3658 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553659 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093660 if (entry) {
[email protected]36fc0392011-12-25 03:59:513661 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093662 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323663
[email protected]36fc0392011-12-25 03:59:513664 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093665 } else {
3666 if (page_title_when_no_navigation_entry_ == final_title)
3667 return false; // Nothing changed, don't bother.
3668
3669 page_title_when_no_navigation_entry_ = final_title;
3670 }
[email protected]420ae012009-04-24 05:16:323671
[email protected]420ae012009-04-24 05:16:323672 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233673 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323674
[email protected]66798902013-10-01 18:40:163675 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533676 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163677
[email protected]420ae012009-04-24 05:16:323678 return true;
3679}
3680
fdegansa696e5112015-04-17 01:57:593681void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003682 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003683 if (delegate_)
fdegansa696e5112015-04-17 01:57:593684 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003685}
3686
3687void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343688 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003689 loading_weak_factory_.InvalidateWeakPtrs();
3690 loading_last_progress_update_ = base::TimeTicks();
3691}
3692
[email protected]02d7b6e2014-06-24 21:01:503693void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3694 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323695 // After sending out a swap notification, we need to send a disconnect
3696 // notification so that clients that pick up a pointer to |this| can NULL the
3697 // pointer. See Bug 1230284.
3698 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113699 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283700 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113701
[email protected]7a846df2012-09-20 19:17:393702 // Ensure that the associated embedder gets cleared after a RenderViewHost
3703 // gets swapped, so we don't reuse the same embedder next time a
3704 // RenderViewHost is attached to this WebContents.
3705 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323706}
3707
[email protected]02d7b6e2014-06-24 21:01:503708void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3709 RenderFrameHost* new_host) {
3710 FOR_EACH_OBSERVER(WebContentsObserver,
3711 observers_,
3712 RenderFrameHostChanged(old_host, new_host));
3713}
3714
[email protected]da7a7182013-09-06 08:11:113715// TODO(avi): Remove this entire function because this notification is already
3716// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263717void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323718 if (!notify_disconnection_)
3719 return;
3720
3721 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213722 NotificationService::current()->Notify(
3723 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3724 Source<WebContents>(this),
3725 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323726}
3727
[email protected]cbb1ef592013-06-05 19:49:463728void WebContentsImpl::NotifyNavigationEntryCommitted(
3729 const LoadCommittedDetails& load_details) {
3730 FOR_EACH_OBSERVER(
3731 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3732}
3733
[email protected]f114fa42013-12-06 17:06:443734bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3735 const IPC::Message& message) {
3736 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313737}
3738
[email protected]c31a84802014-04-03 15:55:493739const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3740 return GetLastCommittedURL();
3741}
3742
[email protected]b849847b2013-12-10 21:57:583743void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583744 FOR_EACH_OBSERVER(WebContentsObserver,
3745 observers_,
3746 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303747 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583748}
3749
3750void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3751 FOR_EACH_OBSERVER(WebContentsObserver,
3752 observers_,
3753 RenderFrameDeleted(render_frame_host));
3754}
3755
[email protected]a09d53ce2014-01-31 00:46:423756void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3757 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103758 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423759 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103760 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423761 return;
3762
[email protected]077e704b2014-05-23 19:24:103763 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3764 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423765}
3766
[email protected]87de04b02014-04-08 22:14:493767void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013768 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493769 const base::string16& message,
3770 const base::string16& default_prompt,
3771 const GURL& frame_url,
3772 JavaScriptMessageType javascript_message_type,
3773 IPC::Message* reply_msg) {
3774 // Suppress JavaScript dialogs when requested. Also suppress messages when
3775 // showing an interstitial as it's shown over the previous page and we don't
3776 // want the hidden page's dialogs to interfere with the interstitial.
3777 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223778 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503779 ShowingInterstitialPage() || !delegate_ ||
3780 delegate_->ShouldSuppressDialogs(this) ||
3781 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493782
3783 if (!suppress_this_message) {
3784 std::string accept_lang = GetContentClient()->browser()->
3785 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503786 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493787 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413788 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493789 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413790 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013791 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413792 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493793 &suppress_this_message);
3794 }
3795
3796 if (suppress_this_message) {
3797 // If we are suppressing messages, just reply as if the user immediately
3798 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013799 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3800 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283801 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493802 }
3803
3804 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3805 // http://crbug.com/288961 ). The only safe thing to do here is return.
3806}
3807
3808void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013809 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493810 const base::string16& message,
3811 bool is_reload,
3812 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013813 RenderFrameHostImpl* rfhi =
3814 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493815 if (delegate_)
3816 delegate_->WillRunBeforeUnloadConfirm();
3817
3818 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023819 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3820 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503821 delegate_->ShouldSuppressDialogs(this) ||
3822 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493823 if (suppress_this_message) {
3824 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3825 return;
3826 }
3827
3828 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503829 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493830 dialog_manager_->RunBeforeUnloadDialog(
3831 this, message, is_reload,
3832 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013833 render_frame_host->GetProcess()->GetID(),
3834 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283835 false));
[email protected]87de04b02014-04-08 22:14:493836}
3837
[email protected]a86c0e962013-12-17 17:10:393838WebContents* WebContentsImpl::GetAsWebContents() {
3839 return this;
3840}
3841
[email protected]7912e822014-04-16 02:37:033842bool WebContentsImpl::IsNeverVisible() {
3843 if (!delegate_)
3844 return false;
3845 return delegate_->IsNeverVisible(this);
3846}
3847
[email protected]95640212014-07-26 18:14:303848#if defined(OS_WIN)
3849gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3850 return accessible_parent_;
3851}
3852#endif
3853
[email protected]5a3bdf52012-05-24 15:12:573854RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3855 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323856}
3857
[email protected]8ff00d72012-10-23 19:12:213858RendererPreferences WebContentsImpl::GetRendererPrefs(
3859 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463860 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513861}
3862
avic3aa8422015-11-09 20:57:223863gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
3864 RenderWidgetHostImpl* render_widget_host) const {
3865 if (!RenderViewHostImpl::From(render_widget_host))
3866 return gfx::Rect();
3867
[email protected]b7a756d42012-01-23 18:08:173868 if (delegate_)
3869 return delegate_->GetRootWindowResizerRect();
3870 return gfx::Rect();
3871}
3872
[email protected]7a846df2012-09-20 19:17:393873void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273874 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393875 browser_plugin_embedder_.reset();
3876}
3877
[email protected]b172aee2012-04-10 17:05:263878void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443879 // Don't send notifications if we are just creating a swapped-out RVH for
3880 // the opener chain. These won't be used for view-source or WebUI, so it's
3881 // ok to return early.
creiscce56cd2014-09-29 22:45:223882 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443883 return;
3884
[email protected]86f98a22013-03-20 14:35:003885 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313886 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083887
[email protected]8ff00d72012-10-23 19:12:213888 NotificationService::current()->Notify(
3889 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3890 Source<WebContents>(this),
3891 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323892
[email protected]6286a372013-10-09 04:03:273893 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333894 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323895 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183896 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583897 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323898 }
[email protected]0666aef2009-05-13 19:48:083899
[email protected]60780f412013-02-25 16:34:103900 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263901
3902 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253903 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323904}
3905
[email protected]b172aee2012-04-10 17:05:263906void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523907 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323908 // Don't notify the world, since this came from a renderer in the
3909 // background.
3910 return;
3911 }
3912
[email protected]da7a7182013-09-06 08:11:113913 notify_disconnection_ = true;
3914 // TODO(avi): Remove. http://crbug.com/170921
3915 NotificationService::current()->Notify(
3916 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3917 Source<WebContents>(this),
3918 NotificationService::NoDetails());
3919
[email protected]be1f56ab2011-12-22 06:55:313920 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233921 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303922
3923 // Restore the focus to the tab (otherwise the focus will be on the top
3924 // window).
[email protected]484ae5912010-09-29 19:16:143925 if (was_crashed && !FocusLocationBarByDefault() &&
3926 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063927 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143928 }
[email protected]32ded2212011-11-10 18:51:433929
[email protected]d8c660432011-12-22 20:51:253930 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323931}
3932
[email protected]ec6a7eb2013-04-22 17:34:223933void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3934 base::TerminationStatus status,
3935 int error_code) {
[email protected]151a63d2011-12-20 22:32:523936 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323937 // The pending page's RenderViewHost is gone.
3938 return;
3939 }
3940
[email protected]2fcdcc32014-03-05 02:14:073941 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3942 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:523943 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
mlamouri7a78d6fd2015-01-17 13:23:533944 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073945
[email protected]698191dc2014-02-25 01:06:133946 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173947 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133948
[email protected]f738bdcb2014-07-11 20:40:443949 if (delegate_)
3950 delegate_->HideValidationMessage(this);
3951
fdegans6ce28f52015-03-19 12:52:223952 SetIsLoading(false, true, nullptr);
[email protected]420ae012009-04-24 05:16:323953 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233954 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453955
[email protected]960b0372014-05-19 18:01:003956 // Reset the loading progress. TODO(avi): What does it mean to have a
3957 // "renderer crash" when there is more than one renderer process serving a
3958 // webpage? Once this function is called at a more granular frame level, we
3959 // probably will need to more granularly reset the state here.
3960 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003961
[email protected]d8c660432011-12-22 20:51:253962 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273963 observers_,
[email protected]58d5cfe2013-07-10 02:40:523964 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323965}
3966
[email protected]b172aee2012-04-10 17:05:263967void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253968 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063969}
3970
[email protected]b172aee2012-04-10 17:05:263971void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:103972 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:043973 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:383974 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
3975
creise1d3e5b2014-12-01 18:21:573976 // Ensure that this state update comes from a RenderViewHost that belongs to
3977 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413978 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:573979 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413980 return;
[email protected]420ae012009-04-24 05:16:323981
avi286019ce2015-07-29 01:26:583982 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:323983 // when the user is scrolling and entering form data, as well as when we're
3984 // leaving a page, in which case our state may have already been moved to
3985 // the next page. The navigation controller will look up the appropriate
3986 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:583987 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:113988 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:583989 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:113990 if (!entry)
[email protected]420ae012009-04-24 05:16:323991 return;
[email protected]420ae012009-04-24 05:16:323992
nasko346969912015-12-16 22:36:473993 // Sanity check that ensures nav_entry_id and page_id point to the same
3994 // navigation entry.
3995 if (rvhi->GetMainFrame()) {
3996 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
3997 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
3998 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:533999
nasko346969912015-12-16 22:36:474000 DCHECK_EQ(entry, new_entry);
4001 }
creisd63f6c4a2015-11-06 19:05:534002
[email protected]691aa2f2013-05-28 22:52:044003 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324004 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044005 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114006 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324007}
4008
sky8b00392d2015-01-10 00:30:284009void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4010 const GURL& url) {
4011 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4012 // If we're fullscreen only update the url if it's from the fullscreen
4013 // renderer.
4014 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444015 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284016 return;
4017 }
[email protected]6934a702011-12-20 00:04:514018 if (delegate_)
avi450ce00e2014-09-24 01:58:524019 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324020}
4021
[email protected]b172aee2012-04-10 17:05:264022void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104023#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294024 // The UI may be in an event-tracking loop, such as between the
4025 // mouse-down and mouse-up in text selection or a button click.
4026 // Defer the close until after tracking is complete, so that we
4027 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294028 // TODO(shess): This could get more fine-grained. For instance,
4029 // closing a tab in another window while selecting text in the
4030 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104031 if (view_->IsEventTracking()) {
4032 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294033 return;
4034 }
[email protected]60780f412013-02-25 16:34:104035#endif
[email protected]07707302009-11-06 00:50:294036
[email protected]420ae012009-04-24 05:16:324037 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524038 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514039 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324040}
4041
[email protected]66bbadaf2014-03-28 16:25:544042void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574043 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4044 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574045}
4046
[email protected]b172aee2012-04-10 17:05:264047void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514048 if (delegate_ && delegate_->IsPopupOrPanel(this))
4049 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324050}
4051
fdegansa696e5112015-04-17 01:57:594052void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094053 bool to_different_document) {
fdegans6ce28f52015-03-19 12:52:224054 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:084055
4056 // Notify accessibility that the user is navigating away from the
4057 // current document.
4058 //
4059 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084060 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594061 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084062 if (manager)
4063 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324064}
4065
fdegansc73eec22015-03-19 14:47:544066void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:324067 scoped_ptr<LoadNotificationDetails> details;
4068
[email protected]9595fd82013-04-19 21:28:494069 // Use the last committed entry rather than the active one, in case a
4070 // pending entry has been created.
4071 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204072 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494073
[email protected]420ae012009-04-24 05:16:324074 // An entry may not exist for a stop when loading an initial blank page or
4075 // if an iframe injected by script into a blank page finishes loading.
4076 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204077 base::TimeDelta elapsed =
4078 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324079
4080 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514081 entry->GetVirtualURL(),
4082 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324083 elapsed,
4084 &controller_,
4085 controller_.GetCurrentEntryIndex()));
4086 }
4087
fdegans6ce28f52015-03-19 12:52:224088 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:324089}
4090
fdegansa696e5112015-04-17 01:57:594091void WebContentsImpl::DidChangeLoadProgress() {
4092 double load_progress = frame_tree_.load_progress();
4093
4094 // The delegate is notified immediately for the first and last updates. Also,
4095 // since the message loop may be pretty busy when a page is loaded, it might
4096 // not execute a posted task in a timely manner so the progress report is sent
4097 // immediately if enough time has passed.
4098 base::TimeDelta min_delay =
4099 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4100 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4101 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4102
4103 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4104 // If there is a pending task to send progress, it is now obsolete.
4105 loading_weak_factory_.InvalidateWeakPtrs();
4106
4107 // Notify the load progress change.
4108 SendChangeLoadProgress();
4109
4110 // Clean-up the states if needed.
4111 if (load_progress == 1.0)
4112 ResetLoadProgressState();
4113 return;
4114 }
4115
4116 if (loading_weak_factory_.HasWeakPtrs())
4117 return;
4118
skyostil95082a62015-06-05 19:53:074119 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4120 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4121 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594122 min_delay);
4123}
4124
[email protected]b172aee2012-04-10 17:05:264125void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164126 controller_.DiscardNonCommittedEntries();
4127
4128 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214129 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164130}
4131
[email protected]59167c22013-06-03 18:07:324132void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104133 has_accessed_initial_document_ = true;
4134
[email protected]d1371bf8e2014-04-19 03:26:244135 // We may have left a failed browser-initiated navigation in the address bar
4136 // to let the user edit it and try again. Clear it now that content might
4137 // show up underneath it.
4138 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454139 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244140
[email protected]59167c22013-06-03 18:07:324141 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504142 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324143}
4144
alexmosbe2f4c32015-03-10 02:30:234145void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4146 const std::string& name) {
4147 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4148 FrameNameChanged(render_frame_host, name));
4149}
4150
[email protected]39f2f9252014-05-03 00:54:014151void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294152 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294154 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094155
4156 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214157 NotificationService::current()->Notify(
4158 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4159 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294160 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084161}
4162
creis8eb8ef22015-11-04 22:51:384163void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4164 const PageState& page_state) {
4165 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4166
4167 // The state update affects the last NavigationEntry associated with the given
4168 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4169 // in the case of an UpdateState from a frame being swapped out). We track
4170 // which entry this is in the RenderFrameHost's nav_entry_id.
4171 RenderFrameHostImpl* rfhi =
4172 static_cast<RenderFrameHostImpl*>(render_frame_host);
4173 NavigationEntryImpl* entry =
4174 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4175 if (!entry)
4176 return;
4177
4178 FrameNavigationEntry* frame_entry =
4179 entry->GetFrameEntry(rfhi->frame_tree_node());
4180 if (!frame_entry)
4181 return;
4182
creisd06a9422015-11-11 03:08:454183 // The SiteInstance might not match if we do a cross-process navigation with
4184 // replacement (e.g., auto-subframe), in which case the swap out of the old
4185 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4186 // has already been replaced and destroyed.
4187 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4188 return;
4189
creis8eb8ef22015-11-04 22:51:384190 if (page_state == frame_entry->page_state())
4191 return; // Nothing to update.
4192
4193 frame_entry->set_page_state(page_state);
4194 controller_.NotifyEntryChanged(entry);
4195}
4196
[email protected]ef3adfc2014-05-11 00:04:544197void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104198 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544199 const base::string16& title,
4200 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544201 // If we have a title, that's a pretty good indication that we've started
4202 // getting useful data.
4203 SetNotWaitingForResponse();
4204
4205 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584206 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544207 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584208 render_frame_host->GetSiteInstance(), page_id);
4209
creisd63f6c4a2015-11-06 19:05:534210 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4211 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
4212 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544213
4214 // We can handle title updates when we don't have an entry in
4215 // UpdateTitleForEntry, but only if the update is from the current RVH.
4216 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584217 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544218 return;
4219
4220 // TODO(evan): make use of title_direction.
4221 // http://code.google.com/p/chromium/issues/detail?id=27094
4222 if (!UpdateTitleForEntry(entry, title))
4223 return;
4224
4225 // Broadcast notifications when the UI should be updated.
4226 if (entry == controller_.GetEntryAtOffset(0))
4227 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4228}
4229
4230void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4231 const std::string& encoding) {
4232 SetEncoding(encoding);
4233}
4234
[email protected]39f2f9252014-05-03 00:54:014235void WebContentsImpl::DocumentAvailableInMainFrame(
4236 RenderViewHost* render_view_host) {
4237 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4238 DocumentAvailableInMainFrame());
4239}
naskoc0fceff2015-04-30 15:53:524240
[email protected]e1c3a552012-05-04 20:51:324241void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4242 // Tell the active RenderViewHost to run unload handlers and close, as long
4243 // as the request came from a RenderViewHost in the same BrowsingInstance.
4244 // In most cases, we receive this from a swapped out RenderViewHost.
4245 // It is possible to receive it from one that has just been swapped in,
4246 // in which case we might as well deliver the message anyway.
4247 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524248 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324249}
4250
alexmose7da5a12015-04-09 02:22:164251bool WebContentsImpl::ShouldRouteMessageEvent(
4252 RenderFrameHost* target_rfh,
4253 SiteInstance* source_site_instance) const {
4254 // Allow the message if this WebContents is dedicated to a browser plugin
4255 // guest.
[email protected]0eba810b2012-10-18 03:19:364256 // Note: This check means that an embedder could theoretically receive a
4257 // postMessage from anyone (not just its own guests). However, this is
4258 // probably not a risk for apps since other pages won't have references
4259 // to App windows.
alexmose7da5a12015-04-09 02:22:164260 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4261}
[email protected]f546640b2012-05-15 00:03:494262
alexmos58729042015-06-18 23:20:004263void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164264 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4265 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494266
alexmose7da5a12015-04-09 02:22:164267 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144268 // If this message is going to outer WebContents from inner WebContents,
4269 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4270 // already created a RenderFrameProxyHost for that purpose.
4271 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084272 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144273 return;
4274 }
4275
alexmose7da5a12015-04-09 02:22:164276 if (GetBrowserPluginGuest()) {
nasko5fb985b2015-08-20 17:28:164277 // We create a swapped out RenderView or RenderFrameProxyHost for the
4278 // embedder in the guest's render process but we intentionally do not
4279 // expose the embedder's opener chain to it.
4280 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
4281 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4282 GetSiteInstance());
4283 } else {
4284 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4285 }
[email protected]f546640b2012-05-15 00:03:494286 } else {
alexmos58729042015-06-18 23:20:004287 RenderFrameHostImpl* source_rfhi =
4288 static_cast<RenderFrameHostImpl*>(source_rfh);
4289 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394290 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494291 }
4292 }
[email protected]f546640b2012-05-15 00:03:494293}
4294
avib7348942015-12-25 20:57:104295bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264296 const base::string16& message,
avib7348942015-12-25 20:57:104297 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264298 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254299 if (!delegate_)
4300 return false;
4301 return delegate_->AddMessageToConsole(this, level, message, line_no,
4302 source_id);
4303}
4304
[email protected]0eba810b2012-10-18 03:19:364305int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214306 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294307 int render_view_routing_id = MSG_ROUTING_NONE;
nickac60e75472015-07-31 00:44:354308 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064309 GetRenderManager()->CreateRenderFrameProxy(instance);
4310 } else {
4311 GetRenderManager()->CreateRenderFrame(
carlosk35f35af2015-12-01 10:55:404312 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN,
nasko4c0feb62015-06-05 18:37:064313 &render_view_routing_id);
4314 }
carlosk37f793792014-11-27 15:08:294315 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364316}
4317
avic3aa8422015-11-09 20:57:224318void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) {
4319 if (render_widget_host != GetRenderViewHost()->GetWidget())
4320 return;
4321
[email protected]ddb85052011-05-18 14:40:274322 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254323 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224324
[email protected]ea114722012-03-12 01:11:254325 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174326 if (rdh) // NULL in unittests.
4327 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254328}
4329
dominickn2dd142dd2015-10-29 05:30:504330void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
4331 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4332 DidGetUserInteraction(type));
4333}
4334
[email protected]b172aee2012-04-10 17:05:264335void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444336 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254337 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444338}
4339
avic3aa8422015-11-09 20:57:224340void WebContentsImpl::RendererUnresponsive(
4341 RenderWidgetHostImpl* render_widget_host) {
[email protected]992db4c2011-05-12 15:37:154342 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224343 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154344 return;
4345
creiscce56cd2014-09-29 22:45:224346 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224347 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584348
[email protected]e5fc1632011-08-08 07:51:534349 // Ignore renderer unresponsive event if debugger is attached to the tab
4350 // since the event may be a result of the renderer sitting on a breakpoint.
4351 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364352 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534353 return;
4354
clamy226727e2015-06-29 10:28:474355 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224356 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324357 // Hang occurred while firing the beforeunload/unload handler.
4358 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224359 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324360
[email protected]fa944cb82013-11-15 17:51:214361 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324362 return;
4363
4364 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564365 // nothing we can do to recover. If the hang is in the beforeunload handler,
4366 // pretend the beforeunload listeners have all fired and allow the delegate
4367 // to continue closing; the user will not have the option of cancelling the
4368 // close. Otherwise, pretend the unload listeners have all fired and close
4369 // the tab.
4370 bool close = true;
clamy226727e2015-06-29 10:28:474371 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564372 delegate_->BeforeUnloadFired(this, true, &close);
4373 }
4374 if (close)
avic3aa8422015-11-09 20:57:224375 Close();
[email protected]420ae012009-04-24 05:16:324376 return;
4377 }
4378
creisc014b402015-04-23 16:41:454379 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474380 return;
4381
[email protected]6934a702011-12-20 00:04:514382 if (delegate_)
4383 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324384}
4385
avic3aa8422015-11-09 20:57:224386void WebContentsImpl::RendererResponsive(
4387 RenderWidgetHostImpl* render_widget_host) {
4388 if (render_widget_host != GetRenderViewHost()->GetWidget())
4389 return;
4390
[email protected]6934a702011-12-20 00:04:514391 if (delegate_)
4392 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324393}
4394
[email protected]b172aee2012-04-10 17:05:264395void WebContentsImpl::LoadStateChanged(
4396 const GURL& url,
4397 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104398 uint64_t upload_position,
4399 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544400 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4401 // is fixed.
4402 tracked_objects::ScopedTracker tracking_profile1(
4403 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4404 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324405 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564406 upload_position_ = upload_position;
4407 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214408 load_state_host_ = url_formatter::IDNToUnicode(
4409 url.host(),
4410 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214411 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324412 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464413 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224414 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4415 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464416 }
[email protected]420ae012009-04-24 05:16:324417}
4418
[email protected]b172aee2012-04-10 17:05:264419void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554420 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324421 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124422 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4423 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514424 if (delegate_)
4425 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094426 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324427}
4428
[email protected]58d5cfe2013-07-10 02:40:524429void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544430 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234431 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224432 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544433}
4434
[email protected]b172aee2012-04-10 17:05:264435void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104436 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214437 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264438 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4439 // here during container initialization and normal window size will be set
4440 // later. In case of tab duplication this resizing to 0x0 prevents setting
4441 // normal size later so just ignore it.
4442 if (!size.IsEmpty())
4443 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324444}
4445
[email protected]af905902013-10-01 21:38:514446void WebContentsImpl::CancelModalDialogsForRenderManager() {
4447 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544448 // deferrer would prevent us from swapping out. We also clear the state
4449 // because this is a cross-process navigation, which means that it's a new
4450 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174451 //
4452 // Note that we don't bother telling browser_plugin_embedder_ because the
4453 // cross-process navigation will either destroy the browser plugins or not
4454 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514455 if (dialog_manager_)
avi2460c762015-04-17 15:21:544456 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514457}
4458
[email protected]02d7b6e2014-06-24 21:01:504459void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4460 RenderFrameHost* new_host,
4461 bool is_main_frame) {
4462 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054463 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504464 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084465
[email protected]02d7b6e2014-06-24 21:01:504466 // Make sure the visible RVH reflects the new delegate's preferences.
4467 if (delegate_)
4468 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394469
[email protected]02d7b6e2014-06-24 21:01:504470 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4471 }
4472
4473 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544474}
4475
naskof5940b9f2015-03-02 23:04:054476void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4477 RenderViewHost* old_host,
4478 RenderViewHost* new_host) {
4479 NotifyViewSwapped(old_host, new_host);
4480}
4481
[email protected]b172aee2012-04-10 17:05:264482NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194483 return GetController();
[email protected]3a3d47472010-07-15 21:03:544484}
4485
carlosk35f35af2015-12-01 10:55:404486scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294487 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514488 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4489 url, std::string())));
[email protected]420ae012009-04-24 05:16:324490}
4491
[email protected]10f417c52011-12-28 21:04:234492NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264493 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324494 return controller_.GetLastCommittedEntry();
4495}
4496
lfgbede6392015-09-11 21:54:064497void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4498 RenderViewHost* render_view_host) {
4499 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144500 bool is_guest_in_site_per_process =
4501 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084502 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064503 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164504 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444505 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164506 rwh_view = rwh_view_child;
4507 } else {
avif9ab5d942015-10-15 14:05:444508 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164509 }
[email protected]1a98a932009-11-17 00:12:524510
[email protected]420ae012009-04-24 05:16:324511 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444512 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214513 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064514}
4515
4516bool WebContentsImpl::CreateRenderViewForRenderManager(
4517 RenderViewHost* render_view_host,
4518 int opener_frame_routing_id,
4519 int proxy_routing_id,
4520 const FrameReplicationState& replicated_frame_state) {
4521 TRACE_EVENT0("browser,navigation",
4522 "WebContentsImpl::CreateRenderViewForRenderManager");
4523
4524 if (proxy_routing_id == MSG_ROUTING_NONE)
4525 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324526
[email protected]74ce1ad2011-12-16 21:51:464527 // Make sure we use the correct starting page_id in the new RenderView.
4528 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104529 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584530 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464531
alexmos5ac402d2015-07-09 07:51:104532 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4533 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4534 max_page_id, replicated_frame_state,
4535 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524536 return false;
[email protected]14392a52012-05-02 20:28:444537 }
[email protected]a4127722011-04-27 23:13:524538
avi2b177592014-12-10 02:08:024539 SetHistoryOffsetAndLengthForView(render_view_host,
4540 controller_.GetLastCommittedEntryIndex(),
4541 controller_.GetEntryCount());
4542
[email protected]a220b5932013-09-21 03:47:444543#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504544 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4545 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444546 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444547 if (rwh_view) {
4548 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4549 render_widget_host->WasResized();
4550 }
[email protected]f8233cc2011-05-31 20:24:504551#endif
4552
[email protected]420ae012009-04-24 05:16:324553 return true;
4554}
4555
[email protected]82307f6b2014-08-07 03:30:124556bool WebContentsImpl::CreateRenderFrameForRenderManager(
4557 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044558 int proxy_routing_id,
4559 int opener_routing_id,
japhete6adf142014-10-31 00:01:494560 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044561 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434562 TRACE_EVENT0("browser,navigation",
4563 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124564
4565 RenderFrameHostImpl* rfh =
4566 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044567 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4568 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124569 return false;
4570
4571 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4572 // RenderFrameHost will have to be associated with the appropriate
4573 // RenderWidgetHostView or a new one should be created here.
4574
4575 return true;
4576}
4577
mfomitchev841f8182015-11-07 02:03:194578#if defined(OS_ANDROID) && !defined(USE_AURA)
[email protected]fc2b46b2014-05-03 16:33:454579
[email protected]155c7f22013-12-09 17:07:184580base::android::ScopedJavaLocalRef<jobject>
4581WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404582 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564583 return GetWebContentsAndroid()->GetJavaObject();
4584}
[email protected]155c7f22013-12-09 17:07:184585
[email protected]0e813a52014-08-13 10:34:564586WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184587 WebContentsAndroid* web_contents_android =
4588 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4589 if (!web_contents_android) {
4590 web_contents_android = new WebContentsAndroid(this);
4591 SetUserData(kWebContentsAndroidKey, web_contents_android);
4592 }
[email protected]0e813a52014-08-13 10:34:564593 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184594}
4595
[email protected]7d244f12013-08-22 21:41:514596bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064597 return CreateRenderViewForRenderManager(
4598 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064599 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514600}
[email protected]fc2b46b2014-05-03 16:33:454601
4602#elif defined(OS_MACOSX)
4603
[email protected]75f4df72014-07-16 22:39:424604void WebContentsImpl::SetAllowOtherViews(bool allow) {
4605 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454606}
4607
[email protected]75f4df72014-07-16 22:39:424608bool WebContentsImpl::GetAllowOtherViews() {
4609 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454610}
4611
[email protected]7d244f12013-08-22 21:41:514612#endif
4613
[email protected]6fba26d2014-04-29 09:38:284614void WebContentsImpl::OnDialogClosed(int render_process_id,
4615 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264616 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494617 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264618 bool success,
[email protected]fcf75d42013-12-03 20:11:264619 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284620 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4621 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494622 last_dialog_suppressed_ = dialog_was_suppressed;
4623
[email protected]beb440c2009-11-06 04:08:544624 if (is_showing_before_unload_dialog_ && !success) {
4625 // If a beforeunload dialog is canceled, we need to stop the throbber from
4626 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284627 if (rfh)
fdegansc73eec22015-03-19 14:47:544628 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354629 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104630
[email protected]6d65a462013-06-21 21:29:124631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4632 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544633 }
[email protected]87de04b02014-04-08 22:14:494634
[email protected]beb440c2009-11-06 04:08:544635 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284636 if (rfh) {
4637 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4638 dialog_was_suppressed);
4639 } else {
4640 // Don't leak the sync IPC reply if the RFH or process is gone.
4641 delete reply_msg;
4642 }
[email protected]beb440c2009-11-06 04:08:544643}
4644
[email protected]b172aee2012-04-10 17:05:264645void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544646 if (encoding == last_reported_encoding_)
4647 return;
4648 last_reported_encoding_ = encoding;
4649
4650 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124651 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104652}
[email protected]f45d2a72010-03-08 23:28:354653
[email protected]1ac10dca2013-08-20 20:47:044654bool WebContentsImpl::IsHidden() {
4655 return capturer_count_ == 0 && !should_normally_be_visible_;
4656}
4657
rob97250742015-12-10 17:45:154658int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144659 if (node_ && node_->outer_web_contents())
4660 return node_->outer_contents_frame_tree_node_id();
4661
nick2482a2d2015-12-18 01:39:374662 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144663}
4664
[email protected]b0936d22013-11-28 06:47:364665RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214666 return frame_tree_.root()->render_manager();
4667}
4668
lazyboy8e16ddfd2015-09-28 03:41:564669WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4670 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4671 if (node_)
4672 return node_->outer_web_contents();
4673 } else {
4674 if (GetBrowserPluginGuest())
4675 return GetBrowserPluginGuest()->embedder_web_contents();
4676 }
4677 return nullptr;
4678}
4679
[email protected]f8497342013-02-05 22:15:024680BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394681 return browser_plugin_guest_.get();
4682}
4683
[email protected]738f57a2013-06-29 21:06:544684void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4685 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144686 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544687 browser_plugin_guest_.reset(guest);
4688}
4689
[email protected]f8497342013-02-05 22:15:024690BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394691 return browser_plugin_embedder_.get();
4692}
[email protected]8ff00d72012-10-23 19:12:214693
fsamuel60b42282015-03-10 03:29:144694void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4695 if (browser_plugin_embedder_)
4696 return;
4697 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4698}
4699
[email protected]fc2b46b2014-05-03 16:33:454700gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214701 gfx::Size size;
4702 if (delegate_)
4703 size = delegate_->GetSizeForNewRenderView(this);
4704 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454705 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214706 return size;
4707}
4708
[email protected]ae7eeda2014-07-04 01:53:264709void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4710 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024711 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554712}
4713
[email protected]222f5822014-02-05 23:40:494714void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4715 if (!delegate_)
4716 return;
4717 const gfx::Size new_size = GetPreferredSize();
4718 if (new_size != old_size)
4719 delegate_->UpdatePreferredSize(this, new_size);
4720}
4721
dbeama1b926a2015-08-31 23:17:514722WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4723 const std::string& frame_name) {
4724 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4725 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4726 CreateWebUIControllerForURL(web_ui, url);
4727 if (controller) {
4728 web_ui->AddMessageHandler(new GenericHandler());
4729 web_ui->SetController(controller);
4730 return web_ui;
4731 }
4732
4733 delete web_ui;
4734 return NULL;
4735}
4736
[email protected]34ff1cfc2014-08-20 06:16:054737void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4738 force_disable_overscroll_content_ = force_disable;
4739 if (view_)
4740 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4741}
4742
dalecurtis88c240072015-12-09 02:11:184743void WebContentsImpl::MediaStartedPlaying(
4744 const WebContentsObserver::MediaPlayerId& id) {
4745 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4746}
4747
4748void WebContentsImpl::MediaStoppedPlaying(
4749 const WebContentsObserver::MediaPlayerId& id) {
4750 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4751}
4752
[email protected]8ff00d72012-10-23 19:12:214753} // namespace content