blob: 41a60845bbd6dcbd8470f5765012c9bd3bd057c6 [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
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4610#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0711#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2014#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2215#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0716#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5117#include "base/strings/string16.h"
18#include "base/strings/string_number_conversions.h"
19#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0020#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0721#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3722#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4223#include "base/trace_event/trace_event.h"
rsleevic327b48f82015-04-30 02:03:2524#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2125#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3026#include "content/browser/accessibility/accessibility_mode_helper.h"
27#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1828#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3929#include "content/browser/browser_plugin/browser_plugin_embedder.h"
30#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5931#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4132#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0433#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4634#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1235#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1636#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1637#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4038#include "content/browser/frame_host/interstitial_page_impl.h"
39#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3340#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0141#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1842#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1643#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5744#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0545#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4446#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4047#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3048#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5249#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5350#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0951#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0652#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3053#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5054#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3255#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5056#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5957#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4858#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0959#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3360#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1261#include "content/browser/wake_lock/wake_lock_service_context.h"
[email protected]b5a40842012-11-28 15:26:1162#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5863#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0364#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5665#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1466#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4267#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4468#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1769#include "content/common/input_messages.h"
avi286019ce2015-07-29 01:26:5870#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5171#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0272#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3673#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1174#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2875#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4476#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3677#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1778#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1479#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4680#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1581#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0082#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2783#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0084#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3785#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1486#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3087#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3288#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0989#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1290#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3491#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3892#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4293#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2594#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2195#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:0896#include "content/public/common/browser_plugin_guest_mode.h"
[email protected]54087fe2011-10-28 22:02:4897#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5498#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4999#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20100#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01101#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03102#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57103#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05104#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40105#include "mojo/common/url_type_converters.h"
106#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53107#include "net/http/http_cache.h"
108#include "net/http/http_transaction_factory.h"
109#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34110#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40111#include "skia/public/type_converters.h"
112#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56113#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01114#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41115#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52116#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31117
qinmin58567c82015-01-07 21:00:20118#if defined(ENABLE_BROWSER_CDMS)
119#include "content/browser/media/media_web_contents_observer.h"
120#endif
121
[email protected]583418cc2013-01-17 14:01:10122#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40123#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10124#include "content/browser/android/date_time_chooser_android.h"
avayvod41634b12015-07-08 17:07:05125#include "content/browser/media/android/media_session.h"
[email protected]155c7f22013-12-09 17:07:18126#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10127#endif
128
[email protected]f66df822012-05-18 16:52:17129#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50130#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57131#endif
[email protected]3e45ba92009-02-20 21:09:00132
[email protected]8ff00d72012-10-23 19:12:21133namespace content {
[email protected]420ae012009-04-24 05:16:32134namespace {
135
[email protected]960b0372014-05-19 18:01:00136const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41137const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05138
[email protected]155c7f22013-12-09 17:07:18139#if defined(OS_ANDROID)
140const char kWebContentsAndroidKey[] = "web_contents_android";
141#endif // OS_ANDROID
142
[email protected]e4abd3b42013-11-12 18:28:47143base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46144g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
145
halton.huoca2eabd2015-07-06 08:17:40146static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
147 int id,
148 const GURL& image_url,
149 image_downloader::DownloadResultPtr result) {
150 DCHECK(result);
151
152 const std::vector<SkBitmap> images =
153 result->images.To<std::vector<SkBitmap>>();
154 const std::vector<gfx::Size> original_image_sizes =
155 result->original_image_sizes.To<std::vector<gfx::Size>>();
156
157 callback.Run(id, result->http_status_code, image_url, images,
158 original_image_sizes);
[email protected]795c28972012-12-06 06:13:39159}
160
[email protected]8bfc8272013-09-09 20:10:53161void NotifyCacheOnIO(
162 scoped_refptr<net::URLRequestContextGetter> request_context,
163 const GURL& url,
164 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58165 net::HttpCache* cache = request_context->GetURLRequestContext()->
166 http_transaction_factory()->GetCache();
167 if (cache)
168 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53169}
170
alexmos4cf2aa32015-07-15 23:40:43171bool FindMatchingProcess(int render_process_id,
172 bool* did_match_process,
173 FrameTreeNode* node) {
174 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) {
175 *did_match_process = true;
176 return false;
177 }
178 return true;
179}
180
[email protected]a86c0e962013-12-17 17:10:39181bool ForEachFrameInternal(
182 const base::Callback<void(RenderFrameHost*)>& on_frame,
183 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41184 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39185 return true;
186}
187
[email protected]95640212014-07-26 18:14:30188bool ForEachPendingFrameInternal(
189 const base::Callback<void(RenderFrameHost*)>& on_frame,
190 FrameTreeNode* node) {
191 RenderFrameHost* pending_frame_host =
192 node->render_manager()->pending_frame_host();
193 if (pending_frame_host)
194 on_frame.Run(pending_frame_host);
195 return true;
196}
197
[email protected]a86c0e962013-12-17 17:10:39198void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
199 IPC::Message* message_copy = new IPC::Message(*message);
200 message_copy->set_routing_id(rfh->GetRoutingID());
201 rfh->Send(message_copy);
202}
203
[email protected]948481d2014-06-11 18:32:22204void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
205 RenderFrameHost* rfh) {
206 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
207 ->frame_tree_node()
208 ->render_manager()
209 ->GetRenderWidgetHostView();
210 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59211}
212
[email protected]95640212014-07-26 18:14:30213void SetAccessibilityModeOnFrame(AccessibilityMode mode,
214 RenderFrameHost* frame_host) {
215 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
216}
217
dtseng0dd3fa12015-07-22 19:00:52218void ResetAccessibility(RenderFrameHost* rfh) {
219 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
220}
221
[email protected]420ae012009-04-24 05:16:32222} // namespace
223
[email protected]54944cde2012-12-09 09:24:59224WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21225 FrameTreeNode* opener_node = nullptr;
226 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
227 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
228 params.opener_render_process_id, params.opener_render_frame_id);
229 if (opener_rfh)
230 opener_node = opener_rfh->frame_tree_node();
231 }
232 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19233}
234
235WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59236 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30237 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21238 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30239
240 for (SessionStorageNamespaceMap::const_iterator it =
241 session_storage_namespace_map.begin();
242 it != session_storage_namespace_map.end();
243 ++it) {
244 new_contents->GetController()
245 .SetSessionStorageNamespace(it->first, it->second.get());
246 }
247
[email protected]54944cde2012-12-09 09:24:59248 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19249 return new_contents;
[email protected]a81343d232011-12-27 07:39:20250}
[email protected]746d3052012-05-22 15:15:47251
nickf9acfbe2014-12-23 19:12:37252void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
253 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46254 g_created_callbacks.Get().push_back(callback);
255}
256
nickf9acfbe2014-12-23 19:12:37257void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
258 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46259 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
260 if (g_created_callbacks.Get().at(i).Equals(callback)) {
261 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
262 return;
263 }
264 }
265}
266
avidf38c952015-10-27 13:45:13267WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
268 if (!rvh)
269 return nullptr;
[email protected]746d3052012-05-22 15:15:47270 return rvh->GetDelegate()->GetAsWebContents();
271}
272
[email protected]a86c0e962013-12-17 17:10:39273WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13274 if (!rfh)
275 return nullptr;
276 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39277}
278
[email protected]7fff43e2013-05-21 20:21:10279// WebContentsImpl::DestructionObserver ----------------------------------------
280
281class WebContentsImpl::DestructionObserver : public WebContentsObserver {
282 public:
283 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
284 : WebContentsObserver(watched_contents),
285 owner_(owner) {
286 }
287
288 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58289 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58290 owner_->OnWebContentsDestroyed(
291 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10292 }
293
294 private:
295 WebContentsImpl* owner_;
296
297 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
298};
299
[email protected]8ed16472014-04-11 19:02:48300WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
301 int render_frame_id,
302 ColorChooser* chooser,
303 int identifier)
304 : render_process_id(render_process_id),
305 render_frame_id(render_frame_id),
306 chooser(chooser),
307 identifier(identifier) {
308}
309
310WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
311}
312
lazyboy6ec48b2a2015-06-29 15:18:14313// WebContentsImpl::WebContentsTreeNode ----------------------------------------
314WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
315 : outer_web_contents_(nullptr),
316 outer_contents_frame_tree_node_id_(
317 FrameTreeNode::kFrameTreeNodeInvalidID) {
318}
319
320WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
321 // Remove child pointer from our parent.
322 if (outer_web_contents_) {
323 ChildrenSet& child_ptrs_in_parent =
324 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
325 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
326 DCHECK(iter != child_ptrs_in_parent.end());
327 child_ptrs_in_parent.erase(this);
328 }
329
330 // Remove parent pointers from our children.
331 // TODO(lazyboy): We should destroy the children WebContentses too. If the
332 // children do not manage their own lifetime, then we would leak their
333 // WebContentses.
334 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
335 child->outer_web_contents_ = nullptr;
336}
337
338void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
339 WebContentsImpl* outer_web_contents,
340 RenderFrameHostImpl* outer_contents_frame) {
341 outer_web_contents_ = outer_web_contents;
342 outer_contents_frame_tree_node_id_ =
343 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
344
345 if (!outer_web_contents_->node_)
346 outer_web_contents_->node_.reset(new WebContentsTreeNode());
347
348 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
349}
350
[email protected]b172aee2012-04-10 17:05:26351// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32352
alexmose201c7cd2015-06-10 17:14:21353WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42354 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22355 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57356 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21357 created_with_opener_(false),
[email protected]2ceee8f2014-01-14 18:02:08358#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41359 accessible_parent_(NULL),
360#endif
[email protected]6ea6bdf2013-12-06 13:35:01361 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57362 this,
363 this,
364 this,
365 this),
[email protected]d5f942ba2008-09-26 19:30:34366 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03367 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23368 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
369 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34370 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26371 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56372 upload_size_(0),
373 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16374 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47375 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10376 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28377 theme_color_(SK_ColorTRANSPARENT),
378 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29379 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55380 capturer_count_(0),
381 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57382 is_being_destroyed_(false),
383 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15384 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01385 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39386 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38387 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21388 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
389 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44390 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55391 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42392 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03393 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49394 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05395 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30396 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57397 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30398 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30399 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15400 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50401 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46402 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55403 frame_tree_.SetFrameRemoveListener(
404 base::Bind(&WebContentsImpl::OnFrameRemoved,
405 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20406#if defined(ENABLE_BROWSER_CDMS)
407 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
408#endif
alogvinovf50445a2015-10-30 13:00:12409
410 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35411}
initial.commit09911bf2008-07-26 23:55:29412
[email protected]b172aee2012-04-10 17:05:26413WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32414 is_being_destroyed_ = true;
415
kenrb2a565f82015-09-02 20:24:59416 rwh_input_event_router_.reset();
417
[email protected]21b41c7e892014-02-28 01:52:24418 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
419 // shutdown and be deleted as well.
420 frame_tree_.ForEach(
421 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
422
[email protected]d9030b82013-07-19 08:26:06423 ClearAllPowerSaveBlockers();
424
[email protected]b24b68a2012-09-24 21:57:26425 for (std::set<RenderWidgetHostImpl*>::iterator iter =
426 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
427 (*iter)->DetachDelegate();
428 }
429 created_widgets_.clear();
430
[email protected]3ab9cb82011-06-03 18:02:07431 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15432 if (dialog_manager_)
avi2460c762015-04-17 15:21:54433 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07434
[email protected]8ed16472014-04-11 19:02:48435 if (color_chooser_info_.get())
436 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20437
[email protected]420ae012009-04-24 05:16:32438 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32439
[email protected]ca13a442012-04-17 14:00:12440 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21441 NotificationService::current()->Notify(
442 NOTIFICATION_WEB_CONTENTS_DESTROYED,
443 Source<WebContents>(this),
444 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32445
[email protected]df0c843f2014-05-23 20:37:23446 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14447 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23448 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59449
clamy0e119882015-07-31 16:12:33450 // Manually call the observer methods for the root frame tree node. It is
451 // necessary to manually delete all objects tracking navigations
452 // (NavigationHandle, NavigationRequest) for observers to be properly
453 // notified of these navigations stopping before the WebContents is
454 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23455 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56456
clamy0e119882015-07-31 16:12:33457 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56458 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33459 root->pending_frame_host()->SetNavigationHandle(
460 scoped_ptr<NavigationHandleImpl>());
461 }
naskob21fe4872015-02-24 14:15:56462 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33463 root->current_frame_host()->SetNavigationHandle(
464 scoped_ptr<NavigationHandleImpl>());
465
466 // PlzNavigate: clear up state specific to browser-side navigation.
467 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
468 switches::kEnableBrowserSideNavigation)) {
469 frame_tree_.root()->ResetNavigationRequest(false);
470 if (root->speculative_frame_host()) {
471 root->speculative_frame_host()->SetRenderFrameCreated(false);
472 root->speculative_frame_host()->SetNavigationHandle(
473 scoped_ptr<NavigationHandleImpl>());
474 }
475 }
[email protected]f273ee52013-10-18 16:05:27476
naskoa83483fb2015-02-27 16:57:10477 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
478 FrameDeleted(root->current_frame_host()));
479
[email protected]df0c843f2014-05-23 20:37:23480 if (root->pending_render_view_host()) {
481 FOR_EACH_OBSERVER(WebContentsObserver,
482 observers_,
483 RenderViewDeleted(root->pending_render_view_host()));
484 }
[email protected]c06c58c2014-03-12 20:31:59485
[email protected]f273ee52013-10-18 16:05:27486 FOR_EACH_OBSERVER(WebContentsObserver,
487 observers_,
[email protected]df0c843f2014-05-23 20:37:23488 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27489
[email protected]2db9bd72012-04-13 20:20:56490 FOR_EACH_OBSERVER(WebContentsObserver,
491 observers_,
[email protected]12a46832014-05-09 13:35:58492 WebContentsDestroyed());
493
494 FOR_EACH_OBSERVER(WebContentsObserver,
495 observers_,
496 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08497
[email protected]6934a702011-12-20 00:04:51498 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10499
500 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
501 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42502}
503
[email protected]d1198fd2012-08-13 22:50:19504WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59505 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21506 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03507 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21508 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19509
alexmose201c7cd2015-06-10 17:14:21510 if (!params.opener_suppressed && opener) {
511 new_contents->GetFrameTree()->root()->SetOpener(opener);
512 new_contents->created_with_opener_ = true;
513 }
514
515 // This may be true even when opener is null, such as when opening blocked
516 // popups.
alexmos090fae8e2015-05-28 17:09:28517 if (params.created_with_opener)
518 new_contents->created_with_opener_ = true;
519
[email protected]4858e432014-06-23 18:14:17520 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06521 // This makes |new_contents| act as a guest.
522 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16523 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06524 // We are instantiating a WebContents for browser plugin. Set its subframe
525 // bit to true.
526 new_contents->is_subframe_ = true;
527 }
[email protected]54944cde2012-12-09 09:24:59528 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19529 return new_contents;
530}
531
[email protected]95640212014-07-26 18:14:30532// static
533std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
534 std::vector<WebContentsImpl*> result;
535 scoped_ptr<RenderWidgetHostIterator> widgets(
536 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30537 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30538 RenderViewHost* rvh = RenderViewHost::From(rwh);
539 if (!rvh)
540 continue;
541 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
542 if (!web_contents)
543 continue;
avidf38c952015-10-27 13:45:13544 if (web_contents->GetRenderViewHost() != rvh)
545 continue;
546 // Because a WebContents can only have one current RVH at a time, there will
547 // be no duplicate WebContents here.
548 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30549 }
550 return result;
551}
552
clamya16aa8172015-05-26 13:07:25553// static
554WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
555 FrameTreeNode* frame_tree_node) {
556 return static_cast<WebContentsImpl*>(
557 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
558}
559
[email protected]b0936d22013-11-28 06:47:36560RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21561 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28562}
563
[email protected]7bb761892012-07-20 09:32:47564bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
565 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44566 return OnMessageReceived(render_view_host, NULL, message);
567}
568
569bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
570 RenderFrameHost* render_frame_host,
571 const IPC::Message& message) {
572 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56573 if (GetWebUI() &&
574 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17575 return true;
[email protected]d2353452012-01-19 19:53:56576 }
[email protected]f82d57b52011-04-27 19:13:17577
brettw5a1613dc2015-06-02 05:34:43578 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25579 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33580 if (render_frame_host) {
581 while ((observer = it.GetNext()) != NULL)
582 if (observer->OnMessageReceived(message, render_frame_host))
583 return true;
584 } else {
585 while ((observer = it.GetNext()) != NULL)
586 if (observer->OnMessageReceived(message))
587 return true;
588 }
[email protected]403415a2011-01-10 18:57:53589
[email protected]1d62cf72014-02-07 21:31:57590 // Message handlers should be aware of which
591 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
592 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02593 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57594 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02595 else
[email protected]1d62cf72014-02-07 21:31:57596 render_view_message_source_ = render_view_host;
597
[email protected]724159a2010-12-30 01:11:18598 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33599 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40600 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
601 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05602 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
603 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48604 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
605 OnDocumentLoadedInFrame)
606 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
607 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
608 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
609 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
610 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19611 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
612 OnMediaPlayingNotification)
613 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
614 OnMediaPausedNotification)
dglazkov79c426102015-08-31 21:22:43615 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11616 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25617 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18618 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54619 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18620 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54621 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18622 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25623 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26624 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21625 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48626 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
627 OnRegisterProtocolHandler)
628 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
629 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01630 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
631 OnUpdatePageImportanceSignals)
[email protected]b888919c2011-09-02 00:32:16632 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10633 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50634 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50635#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00636 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
637 OnPepperInstanceCreated)
638 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
639 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42640 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
641 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50642 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
643 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55644 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40645 OnBrowserPluginMessage(render_frame_host,
646 message))
thestigc4cac8f2014-09-04 21:17:50647#endif
[email protected]41225fe2013-03-29 05:32:02648 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07649 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
650 OnShowValidationMessage)
651 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
652 OnHideValidationMessage)
653 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
654 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48655#if defined(OS_ANDROID)
656 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
657 OnFindMatchRectsReply)
658 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
659 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48660#endif
[email protected]724159a2010-12-30 01:11:18661 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33662 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44663 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57664 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18665
[email protected]724159a2010-12-30 01:11:18666 return handled;
667}
668
nasko907fcb62015-01-28 04:24:11669bool WebContentsImpl::HasValidFrameSource() {
670 if (!render_frame_message_source_) {
671 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18672 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
673 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11674 return false;
675 }
676
677 return true;
678}
679
[email protected]b172aee2012-04-10 17:05:26680void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18681 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21682 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43683 if (delegate_)
684 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18685}
686
[email protected]d1198fd2012-08-13 22:50:19687NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56688 return controller_;
689}
690
[email protected]d1198fd2012-08-13 22:50:19691const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56692 return controller_;
693}
694
[email protected]8ff00d72012-10-23 19:12:21695BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55696 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30697}
698
[email protected]b172aee2012-04-10 17:05:26699const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24700 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32701 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51702 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31703}
704
[email protected]a093ce02013-07-22 20:53:14705const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24706 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32707 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24708 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
709}
710
711const GURL& WebContentsImpl::GetLastCommittedURL() const {
712 // We may not have a navigation entry yet.
713 NavigationEntry* entry = controller_.GetLastCommittedEntry();
714 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
715}
716
[email protected]8ff00d72012-10-23 19:12:21717WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31718 return delegate_;
719}
720
[email protected]8ff00d72012-10-23 19:12:21721void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31722 // TODO(cbentzel): remove this debugging code?
723 if (delegate == delegate_)
724 return;
725 if (delegate_)
726 delegate_->Detach(this);
727 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08728 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31729 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08730 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00731 if (view_)
[email protected]e85165c642014-06-10 14:34:31732 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08733 }
[email protected]be1f56ab2011-12-22 06:55:31734}
735
[email protected]8ff00d72012-10-23 19:12:21736RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21737 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41738 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16739}
740
clamydf1975e2015-02-05 19:12:24741RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41742 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16743}
744
nick53d5cbf2015-04-23 22:50:14745RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
746 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
747 if (!focused_node)
748 return nullptr;
749 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07750}
751
[email protected]a86c0e962013-12-17 17:10:39752void WebContentsImpl::ForEachFrame(
753 const base::Callback<void(RenderFrameHost*)>& on_frame) {
754 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
755}
756
757void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
758 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
759 delete message;
760}
761
creisc014b402015-04-23 16:41:45762RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21763 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31764}
765
[email protected]6b618e62012-08-16 12:59:18766int WebContentsImpl::GetRoutingID() const {
767 if (!GetRenderViewHost())
768 return MSG_ROUTING_NONE;
769
770 return GetRenderViewHost()->GetRoutingID();
771}
772
creis89a0f782015-05-27 16:13:17773void WebContentsImpl::CancelActiveAndPendingDialogs() {
774 if (dialog_manager_)
775 dialog_manager_->CancelActiveAndPendingDialogs(this);
776 if (browser_plugin_embedder_)
777 browser_plugin_embedder_->CancelGuestDialogs();
778}
779
[email protected]44470a22013-01-24 01:21:54780int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
781 return fullscreen_widget_routing_id_;
782}
783
naskoc0fceff2015-04-30 15:53:52784void WebContentsImpl::ClosePage() {
785 GetRenderViewHost()->ClosePage();
786}
787
[email protected]b172aee2012-04-10 17:05:26788RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21789 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31790}
791
[email protected]4aebbca2013-09-17 22:26:49792RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
793 const {
794 RenderWidgetHost* const widget_host =
795 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
796 GetFullscreenWidgetRoutingID());
797 return widget_host ? widget_host->GetView() : NULL;
798}
799
[email protected]8ff00d72012-10-23 19:12:21800WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31801 return view_.get();
802}
803
yusufod41c5f92015-03-06 00:14:28804SkColor WebContentsImpl::GetThemeColor() const {
805 return theme_color_;
806}
807
[email protected]95640212014-07-26 18:14:30808void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
809 if (mode == accessibility_mode_)
810 return;
811
812 accessibility_mode_ = mode;
813 frame_tree_.ForEach(
814 base::Bind(&ForEachFrameInternal,
815 base::Bind(&SetAccessibilityModeOnFrame, mode)));
816 frame_tree_.ForEach(
817 base::Bind(&ForEachPendingFrameInternal,
818 base::Bind(&SetAccessibilityModeOnFrame, mode)));
819}
820
821void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50822 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30823}
824
825void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50826 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30827}
828
dmazzoni83ba5c82015-04-14 07:11:51829void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
830 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
831 // accessibility tree from the main frame and everything in the
832 // same site instance.
833 GetMainFrame()->RequestAXTreeSnapshot(callback);
834}
835
dbeama1b926a2015-08-31 23:17:51836WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
837 const std::string& frame_name) {
838 DCHECK(!frame_name.empty());
839 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22840}
841
[email protected]8ff00d72012-10-23 19:12:21842WebUI* WebContentsImpl::GetWebUI() const {
carlosk795f1b22015-11-06 10:34:13843 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
844 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31845}
846
[email protected]8ff00d72012-10-23 19:12:21847WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21848 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34849}
850
[email protected]86ef6a392012-05-11 22:03:11851void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22852 if (GetUserAgentOverride() == override)
853 return;
854
855 renderer_preferences_.user_agent_override = override;
856
857 // Send the new override string to the renderer.
858 RenderViewHost* host = GetRenderViewHost();
859 if (host)
860 host->SyncRendererPrefs();
861
862 // Reload the page if a load is currently in progress to avoid having
863 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27864 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22865 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
866 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53867
868 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
869 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11870}
871
872const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22873 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11874}
875
[email protected]95640212014-07-26 18:14:30876void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dtseng0dd3fa12015-07-22 19:00:52877 if (GetAccessibilityMode() == AccessibilityModeTreeOnly)
878 ForEachFrame(base::Bind(&ResetAccessibility));
879 else
880 AddAccessibilityMode(AccessibilityModeTreeOnly);
[email protected]95640212014-07-26 18:14:30881}
882
883bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
884 return accessibility_mode_ == AccessibilityModeTreeOnly;
885}
886
887bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
888 return accessibility_mode_ == AccessibilityModeComplete;
889}
890
[email protected]2ceee8f2014-01-14 18:02:08891#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41892void WebContentsImpl::SetParentNativeViewAccessible(
893gfx::NativeViewAccessible accessible_parent) {
894 accessible_parent_ = accessible_parent;
creisc014b402015-04-23 16:41:45895 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30896 if (rfh)
897 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41898}
899#endif
900
kouhei40f03cb2015-09-24 07:47:01901const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
902 return page_importance_signals_;
903}
904
[email protected]fcf75d42013-12-03 20:11:26905const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55906 // Transient entries take precedence. They are used for interstitial pages
907 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23908 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08909 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21910 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30911 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23912 if (entry) {
[email protected]b5cca982011-05-26 04:42:08913 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23914 }
carlosk795f1b22015-11-06 10:34:13915 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
916 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58917 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54918 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32919 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54920 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35921 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26922 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54923 if (!title.empty())
924 return title;
925 }
926 }
927
928 // We use the title for the last committed entry rather than a pending
929 // navigation entry. For example, when the user types in a URL, we want to
930 // keep the old page's title until the new load has committed and we get a new
931 // title.
[email protected]96d185d2009-04-24 03:28:54932 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32933
creis072b61f2015-09-28 20:52:24934 // We make an exception for initial navigations. We only want to use the title
935 // from the visible entry if:
936 // 1. The pending entry has been explicitly assigned a title to display.
937 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
938 // which case there is a pending entry index other than -1.
939 //
940 // Otherwise, we want to stick with the last committed entry's title during
941 // new navigations, which have pending entries at index -1 with no title.
942 if (controller_.IsInitialNavigation() &&
943 ((controller_.GetVisibleEntry() &&
944 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
945 controller_.GetPendingEntryIndex() != -1)) {
946 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:47947 }
[email protected]59167c22013-06-03 18:07:32948
[email protected]45d0ef7f2011-01-05 13:46:23949 if (entry) {
[email protected]b5cca982011-05-26 04:42:08950 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23951 }
[email protected]987fc3a2011-05-26 14:18:09952
953 // |page_title_when_no_navigation_entry_| is finally used
954 // if no title cannot be retrieved.
955 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54956}
957
[email protected]b172aee2012-04-10 17:05:26958int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46959 return GetMaxPageIDForSiteInstance(GetSiteInstance());
960}
961
[email protected]b172aee2012-04-10 17:05:26962int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
963 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33964 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
965 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46966
[email protected]b6583592012-01-25 19:52:33967 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34968}
969
[email protected]b172aee2012-04-10 17:05:26970void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46971 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
972}
973
[email protected]b172aee2012-04-10 17:05:26974void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33975 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46976 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33977 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34978}
979
[email protected]ec6c05f2013-10-23 18:41:57980void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
981 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
982 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57983}
984
creiscce56cd2014-09-29 22:45:22985SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21986 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54987}
988
creiscce56cd2014-09-29 22:45:22989SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
990 RenderViewHostImpl* dest_rvh =
991 GetRenderManager()->pending_render_view_host() ?
992 GetRenderManager()->pending_render_view_host() :
993 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58994 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38995}
996
[email protected]b172aee2012-04-10 17:05:26997bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31998 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49999}
1000
[email protected]6dfed692014-05-22 04:18:031001bool WebContentsImpl::IsLoadingToDifferentDocument() const {
1002 return is_loading_ && is_load_to_different_document_;
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031006 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311007}
1008
[email protected]b172aee2012-04-10 17:05:261009const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311010 return load_state_;
1011}
1012
[email protected]fcf75d42013-12-03 20:11:261013const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311014 return load_state_host_;
1015}
1016
[email protected]b172aee2012-04-10 17:05:261017uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311018 return upload_size_;
1019}
1020
[email protected]b172aee2012-04-10 17:05:261021uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311022 return upload_position_;
1023}
1024
[email protected]b172aee2012-04-10 17:05:261025const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541026 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311027}
1028
[email protected]b172aee2012-04-10 17:05:261029bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311030 return displayed_insecure_content_;
1031}
1032
[email protected]222f5822014-02-05 23:40:491033void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251034 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551035 ++capturer_count_;
1036 DVLOG(1) << "There are now " << capturer_count_
1037 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491038
1039 // Note: This provides a hint to upstream code to size the views optimally
1040 // for quality (e.g., to avoid scaling).
1041 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1042 preferred_size_for_capture_ = capture_size;
1043 OnPreferredSizeChanged(preferred_size_);
1044 }
ccameron8807c38f2015-01-17 00:29:191045
1046 // Ensure that all views are un-occluded before capture begins.
1047 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551048}
1049
1050void WebContentsImpl::DecrementCapturerCount() {
1051 --capturer_count_;
1052 DVLOG(1) << "There are now " << capturer_count_
1053 << " capturing(s) of WebContentsImpl@" << this;
1054 DCHECK_LE(0, capturer_count_);
1055
[email protected]5a652232013-02-12 06:15:251056 if (is_being_destroyed_)
1057 return;
1058
[email protected]222f5822014-02-05 23:40:491059 if (capturer_count_ == 0) {
1060 const gfx::Size old_size = preferred_size_for_capture_;
1061 preferred_size_for_capture_ = gfx::Size();
1062 OnPreferredSizeChanged(old_size);
1063 }
1064
[email protected]1ac10dca2013-08-20 20:47:041065 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551066 DVLOG(1) << "Executing delayed WasHidden().";
1067 WasHidden();
1068 }
[email protected]be1f56ab2011-12-22 06:55:311069}
1070
[email protected]f2bd40812013-07-20 04:30:441071int WebContentsImpl::GetCapturerCount() const {
1072 return capturer_count_;
1073}
1074
miu50f97892014-09-22 22:49:521075bool WebContentsImpl::IsAudioMuted() const {
1076 return audio_muter_.get() && audio_muter_->is_muting();
1077}
1078
1079void WebContentsImpl::SetAudioMuted(bool mute) {
1080 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1081 << " for WebContentsImpl@" << this;
1082
1083 if (mute == IsAudioMuted())
1084 return;
1085
1086 if (mute) {
1087 if (!audio_muter_)
1088 audio_muter_.reset(new WebContentsAudioMuter(this));
1089 audio_muter_->StartMuting();
1090 } else {
1091 DCHECK(audio_muter_);
1092 audio_muter_->StopMuting();
1093 }
1094
1095 // Notification for UI updates in response to the changed muting state.
1096 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1097}
1098
[email protected]b172aee2012-04-10 17:05:261099bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311100 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1101 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581102 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271103#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581104 crashed_status_ ==
1105 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271106#endif
wfh0d9532a2015-09-02 23:18:581107 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271108 );
[email protected]3c9e1872010-11-18 16:17:491109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1112 int error_code) {
[email protected]443b80e2010-12-14 00:42:231113 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341114 return;
1115
[email protected]443b80e2010-12-14 00:42:231116 crashed_status_ = status;
1117 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211118 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341119}
1120
[email protected]b172aee2012-04-10 17:05:261121base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311122 return crashed_status_;
1123}
1124
[email protected]b172aee2012-04-10 17:05:261125bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311126 return is_being_destroyed_;
1127}
1128
[email protected]7f924832014-08-09 05:57:221129void WebContentsImpl::NotifyNavigationStateChanged(
1130 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541131 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1132 // is fixed.
1133 tracked_objects::ScopedTracker tracking_profile(
1134 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1135 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtisbc6572e12014-09-12 19:22:301136 // Create and release the audio power save blocker depending on whether the
1137 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341138 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
avayvodcc85bbd2015-08-28 19:11:151139 AudioStreamMonitor::monitoring_available()) {
dalecurtisbc6572e12014-09-12 19:22:301140 if (WasRecentlyAudible()) {
1141 if (!audio_power_save_blocker_)
1142 CreateAudioPowerSaveBlocker();
1143 } else {
1144 audio_power_save_blocker_.reset();
1145 }
1146 }
1147
[email protected]d5f942ba2008-09-26 19:30:341148 if (delegate_)
1149 delegate_->NavigationStateChanged(this, changed_flags);
1150}
1151
gab0dccfef2015-05-20 18:43:391152base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021153 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331154}
1155
georgesak5582cbe2015-05-22 22:08:071156void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1157 last_active_time_ = last_active_time;
1158}
1159
[email protected]9e2e4632012-07-27 16:38:411160void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541161 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591162
ccameron8807c38f2015-01-17 00:29:191163 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1164 if (view) {
1165 view->Show();
[email protected]789e9152009-08-04 21:59:431166#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191167 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431168#endif
[email protected]de3c5d82014-05-28 22:12:591169 }
[email protected]789e9152009-08-04 21:59:431170 }
[email protected]96d185d2009-04-24 03:28:541171
gab0dccfef2015-05-20 18:43:391172 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381173
[email protected]b9769d82012-02-10 00:23:591174 // The resize rect might have changed while this was inactive -- send the new
1175 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451176 RenderViewHostImpl* rvh = GetRenderViewHost();
1177 if (rvh)
avi3627ecac2015-10-16 17:40:431178 rvh->GetWidget()->ResizeRectChanged(GetRootWindowResizerRect());
[email protected]96d185d2009-04-24 03:28:541179
dalecurtisbc6572e12014-09-12 19:22:301180 // Restore power save blocker if there are active video players running.
1181 if (!active_video_players_.empty() && !video_power_save_blocker_)
1182 CreateVideoPowerSaveBlocker();
1183
[email protected]c0d9d5672013-10-09 07:38:031184 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1185
[email protected]54597982013-02-06 01:59:551186 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311187}
1188
[email protected]b172aee2012-04-10 17:05:261189void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551190 // If there are entities capturing screenshots or video (e.g., mirroring),
1191 // don't activate the "disable rendering" optimization.
1192 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521193 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551194 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261195 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521196 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331197 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521198 // calls us).
ccameron8807c38f2015-01-17 00:29:191199 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1200 if (view)
1201 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591202 }
dalecurtisbc6572e12014-09-12 19:22:301203
1204 // Release any video power save blockers held as video is not visible.
1205 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541206 }
1207
[email protected]c0d9d5672013-10-09 07:38:031208 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1209
[email protected]54597982013-02-06 01:59:551210 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371211}
1212
ccameron8807c38f2015-01-17 00:29:191213void WebContentsImpl::WasOccluded() {
1214 if (capturer_count_ > 0)
1215 return;
1216
1217 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1218 if (view)
1219 view->WasOccluded();
1220 }
1221}
1222
1223void WebContentsImpl::WasUnOccluded() {
1224 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1225 if (view)
1226 view->WasUnOccluded();
1227 }
1228}
1229
[email protected]b172aee2012-04-10 17:05:261230bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311231 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451232 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1233 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311234}
1235
[email protected]1c3f80bd2014-04-08 23:02:061236void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451237 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061238}
1239
lazyboy6ec48b2a2015-06-29 15:18:141240void WebContentsImpl::AttachToOuterWebContentsFrame(
1241 WebContents* outer_web_contents,
1242 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081243 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141244 // Create a link to our outer WebContents.
1245 node_.reset(new WebContentsTreeNode());
1246 node_->ConnectToOuterWebContents(
1247 static_cast<WebContentsImpl*>(outer_web_contents),
1248 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1249
1250 DCHECK(outer_contents_frame);
1251
1252 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1253 // SiteInstance of the outer WebContents. The proxy will be used to send
1254 // postMessage to the inner WebContents.
1255 GetRenderManager()->CreateOuterDelegateProxy(
1256 outer_contents_frame->GetSiteInstance(),
1257 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1258
1259 GetRenderManager()->SetRWHViewForInnerContents(
1260 GetRenderManager()->GetRenderWidgetHostView());
1261}
1262
[email protected]b172aee2012-04-10 17:05:261263void WebContentsImpl::Stop() {
clamyf73862c42015-07-08 12:31:331264 frame_tree_.ForEach(base::Bind(&FrameTreeNode::StopLoading));
[email protected]d16609c2013-08-23 06:01:401265 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271266}
1267
[email protected]b172aee2012-04-10 17:05:261268WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441269 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211270 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451271 // before.
[email protected]54944cde2012-12-09 09:24:591272 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451273 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211274 WebContentsImpl* tc =
1275 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191276 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221277 FOR_EACH_OBSERVER(WebContentsObserver,
1278 observers_,
1279 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271280 return tc;
1281}
1282
[email protected]14392a52012-05-02 20:28:441283void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211284 const NotificationSource& source,
1285 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441286 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211287 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1288 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031289 RenderWidgetHostView* view = host->GetView();
1290 if (view == GetFullscreenRenderWidgetHostView()) {
1291 // We cannot just call view_->RestoreFocus() here. On some platforms,
1292 // attempting to focus the currently-invisible WebContentsView will be
1293 // flat-out ignored. Therefore, this boolean is used to track whether
1294 // we will request focus after the fullscreen widget has been
1295 // destroyed.
1296 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1297 } else {
1298 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1299 i != pending_widget_views_.end(); ++i) {
1300 if (host->GetView() == i->second) {
1301 pending_widget_views_.erase(i);
1302 break;
1303 }
[email protected]bafe6cd2012-05-23 23:09:501304 }
1305 }
1306 break;
1307 }
[email protected]14392a52012-05-02 20:28:441308 default:
1309 NOTREACHED();
1310 }
1311}
1312
[email protected]ec6c05f2013-10-23 18:41:571313WebContents* WebContentsImpl::GetWebContents() {
1314 return this;
1315}
1316
[email protected]54944cde2012-12-09 09:24:591317void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211318 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361319 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211320 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431321 should_normally_be_visible_ = !params.initially_hidden;
1322
dcheng3ce04b62015-10-26 23:30:551323 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541324 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551325 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1326 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541327 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551328 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1329 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1330
1331 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1332 if (!site_instance)
1333 site_instance = SiteInstance::Create(params.browser_context);
1334
1335 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1336 // local root by definition.
1337 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1338 // longer be necessary to eagerly grab a routing ID for the view.
1339 // https://crbug.com/545684
1340 int32_t view_routing_id = params.routing_id;
1341 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1342 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1343 view_routing_id = main_frame_widget_routing_id =
1344 site_instance->GetProcess()->GetNextRoutingID();
1345 }
1346
1347 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1348 params.main_frame_routing_id,
1349 main_frame_widget_routing_id);
naskoc9f51dd2015-05-13 00:39:281350 frame_tree_.root()->SetFrameName(params.main_frame_name);
[email protected]d1198fd2012-08-13 22:50:191351
[email protected]fc2b46b2014-05-03 16:33:451352 WebContentsViewDelegate* delegate =
1353 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1354
lazyboy6ec48b2a2015-06-29 15:18:141355 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081356 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
[email protected]fc2b46b2014-05-03 16:33:451357 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1358 this, delegate, &render_view_host_delegate_view_));
1359
1360 WebContentsViewGuest* rv = new WebContentsViewGuest(
1361 this, browser_plugin_guest_.get(), platform_view.Pass(),
1362 render_view_host_delegate_view_);
1363 render_view_host_delegate_view_ = rv;
1364 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191365 } else {
[email protected]fc2b46b2014-05-03 16:33:451366 // Regular WebContentsView.
1367 view_.reset(CreateWebContentsView(
1368 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191369 }
[email protected]fc2b46b2014-05-03 16:33:451370 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191371 CHECK(view_.get());
1372
[email protected]ed245db2012-12-18 08:00:451373 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591374 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191375
tommyclieb25b2a2014-11-03 19:45:091376#if defined(ENABLE_PLUGINS)
1377 plugin_content_origin_whitelist_.reset(
1378 new PluginContentOriginWhitelist(this));
1379#endif
1380
[email protected]d1198fd2012-08-13 22:50:191381 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211382 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1383 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101384
[email protected]01f83f92014-06-17 14:41:541385 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091386 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541387
mlamouriefdca9d2014-09-16 16:55:401388 manifest_manager_host_.reset(new ManifestManagerHost(this));
1389
[email protected]c7654a232013-06-12 21:04:441390#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101391 date_time_chooser_.reset(new DateTimeChooserAndroid());
1392#endif
fsamuel7310a4262014-12-05 05:06:441393
1394 // BrowserPluginGuest::Init needs to be called after this WebContents has
1395 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1396 if (browser_plugin_guest_)
1397 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371398
1399 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1400 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561401
1402 // If the WebContents creation was renderer-initiated, it means that the
1403 // corresponding RenderView and main RenderFrame have already been created.
1404 // Ensure observers are notified about this.
1405 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431406 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561407 RenderViewCreated(GetRenderViewHost());
1408 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1409 }
naskof5940b9f2015-03-02 23:04:051410
1411 // Ensure that observers are notified of the creation of this WebContents's
1412 // main RenderFrameHost. It must be done here for main frames, since the
1413 // NotifySwappedFromRenderManager expects view_ to already be created and that
1414 // happens after RenderFrameHostManager::Init.
1415 NotifySwappedFromRenderManager(
1416 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191417}
1418
[email protected]7fff43e2013-05-21 20:21:101419void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1420 RemoveDestructionObserver(web_contents);
1421
[email protected]ceee8cd2013-03-08 04:59:511422 // Clear a pending contents that has been closed before being shown.
1423 for (PendingContents::iterator iter = pending_contents_.begin();
1424 iter != pending_contents_.end();
1425 ++iter) {
1426 if (iter->second != web_contents)
1427 continue;
1428 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511429 return;
1430 }
1431 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441432}
1433
[email protected]7fff43e2013-05-21 20:21:101434void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1435 if (!ContainsKey(destruction_observers_, web_contents)) {
1436 destruction_observers_[web_contents] =
1437 new DestructionObserver(this, web_contents);
1438 }
1439}
1440
1441void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1442 DestructionObservers::iterator iter =
1443 destruction_observers_.find(web_contents);
1444 if (iter != destruction_observers_.end()) {
1445 delete destruction_observers_[web_contents];
1446 destruction_observers_.erase(iter);
1447 }
1448}
1449
[email protected]b172aee2012-04-10 17:05:261450void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311451 observers_.AddObserver(observer);
1452}
1453
[email protected]b172aee2012-04-10 17:05:261454void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311455 observers_.RemoveObserver(observer);
1456}
1457
[email protected]948481d2014-06-11 18:32:221458std::set<RenderWidgetHostView*>
1459WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1460 std::set<RenderWidgetHostView*> set;
1461 if (ShowingInterstitialPage()) {
1462 set.insert(GetRenderWidgetHostView());
1463 } else {
1464 ForEachFrame(
1465 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1466 }
[email protected]de3c5d82014-05-28 22:12:591467 return set;
1468}
1469
[email protected]b172aee2012-04-10 17:05:261470void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341471 if (delegate_)
1472 delegate_->ActivateContents(this);
1473}
1474
[email protected]b172aee2012-04-10 17:05:261475void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481476 if (delegate_)
1477 delegate_->LostCapture();
1478}
1479
[email protected]b24b68a2012-09-24 21:57:261480void WebContentsImpl::RenderWidgetDeleted(
1481 RenderWidgetHostImpl* render_widget_host) {
1482 if (is_being_destroyed_) {
1483 // |created_widgets_| might have been destroyed.
1484 return;
1485 }
1486
1487 std::set<RenderWidgetHostImpl*>::iterator iter =
1488 created_widgets_.find(render_widget_host);
1489 if (iter != created_widgets_.end())
1490 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541491
1492 if (render_widget_host &&
1493 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491494 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531495 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541496 FOR_EACH_OBSERVER(WebContentsObserver,
1497 observers_,
1498 DidDestroyFullscreenWidget(
1499 fullscreen_widget_routing_id_));
1500 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031501 if (fullscreen_widget_had_focus_at_shutdown_)
1502 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541503 }
[email protected]b24b68a2012-09-24 21:57:261504}
1505
miu9e14e492014-10-25 02:39:041506void WebContentsImpl::RenderWidgetGotFocus(
1507 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371508 // Notify the observers if an embedded fullscreen widget was focused.
1509 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1510 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1511 NotifyWebContentsFocused();
1512 }
miu9e14e492014-10-25 02:39:041513}
1514
estaded0a0c992015-01-21 14:12:061515void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311516 RenderWidgetHostImpl* render_widget_host,
1517 bool width_changed) {
creisc014b402015-04-23 16:41:451518 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291519 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061520 return;
estaded0a0c992015-01-21 14:12:061521
rouslan2f5993f2015-01-29 00:18:311522 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1523 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061524}
1525
paulmeyer9ef6e4462015-02-24 19:15:101526void WebContentsImpl::ScreenInfoChanged() {
1527 if (browser_plugin_embedder_)
1528 browser_plugin_embedder_->ScreenInfoChanged();
1529}
1530
[email protected]b172aee2012-04-10 17:05:261531bool WebContentsImpl::PreHandleKeyboardEvent(
1532 const NativeWebKeyboardEvent& event,
1533 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481534 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131535 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481536}
1537
[email protected]b172aee2012-04-10 17:05:261538void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101539 if (browser_plugin_embedder_ &&
1540 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1541 return;
1542 }
[email protected]63954792011-07-11 04:17:481543 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131544 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481545}
1546
[email protected]d92026ef2014-03-03 21:04:131547bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461548 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191549#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331550 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1551 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191552 // -the OS already has a gesture to do this through pinch-zoom
1553 // -if a user starts an inertial scroll, let's go, and presses control
1554 // (i.e. control+tab) then the OS's buffered scroll events will come in
1555 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331556 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551557 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331558 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521559 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1560 return true;
1561 }
[email protected]bccc4472013-04-18 16:37:191562#endif
[email protected]fb3f066e2013-02-12 19:12:521563 return false;
1564}
1565
[email protected]04bce562014-01-30 05:34:541566bool WebContentsImpl::PreHandleGestureEvent(
1567 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031568 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541569}
1570
kenrb2a565f82015-09-02 20:24:591571RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
1572 // Currently only supported in site per process mode (--site-per-process).
1573 if (!rwh_input_event_router_.get() && !is_being_destroyed_ &&
1574 SiteIsolationPolicy::AreCrossProcessFramesPossible())
1575 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1576 return rwh_input_event_router_.get();
1577}
1578
alexmos3fcd0ca2015-10-23 18:18:331579void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1580 // Focus loss may occur while this WebContents is being destroyed. Don't
1581 // send the message in this case, as the main frame's RenderFrameHost and
1582 // other state has already been cleared.
1583 if (is_being_destroyed_)
1584 return;
1585
1586 frame_tree_.ReplicatePageFocus(is_focused);
1587}
1588
alexmosc4d183e2015-11-06 00:46:521589RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost() {
1590 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
1591 return GetMainFrame()->GetRenderWidgetHost();
1592
1593 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1594 if (!focused_frame)
1595 return GetMainFrame()->GetRenderWidgetHost();
1596
1597 return RenderWidgetHostImpl::From(
1598 focused_frame->current_frame_host()->GetView()->GetRenderWidgetHost());
1599}
1600
mlamouri7a78d6fd2015-01-17 13:23:531601void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1602 // This method is being called to enter renderer-initiated fullscreen mode.
1603 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491604 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1605 if (widget_view)
1606 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1607
[email protected]8a5e0ca2011-08-25 06:30:471608 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531609 delegate_->EnterFullscreenModeForTab(this, origin);
1610
1611 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1612 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1613}
1614
1615void WebContentsImpl::ExitFullscreenMode() {
1616 // This method is being called to leave renderer-initiated fullscreen mode.
1617 // Make sure any existing fullscreen widget is shut down first.
1618 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1619 if (widget_view)
1620 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1621
hugo.holgersson61288e6c2015-01-28 17:04:401622#if defined(OS_ANDROID)
1623 ContentVideoView* video_view = ContentVideoView::GetInstance();
1624 if (video_view != NULL)
1625 video_view->OnExitFullscreen();
1626#endif
1627
mlamouri7a78d6fd2015-01-17 13:23:531628 if (delegate_)
1629 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371630
scheib3dcb6c932015-02-23 10:55:581631 // Ensure web contents exit fullscreen state by sending a resize message,
1632 // which includes the fullscreen state. This is required for the situation
1633 // of the browser moving the view into a fullscreen state "browser fullscreen"
1634 // and then the contents entering "tab fullscreen". Exiting the contents
1635 // "tab fullscreen" then won't have the side effect of the view resizing,
1636 // hence the explicit call here is required.
1637 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1638 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1639 render_widget_host->WasResized();
1640 }
1641
[email protected]657c8e02014-03-19 19:18:371642 FOR_EACH_OBSERVER(WebContentsObserver,
1643 observers_,
1644 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471645}
1646
[email protected]b172aee2012-04-10 17:05:261647bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381648 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121649}
1650
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121651blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const {
1652 return delegate_ ? delegate_->GetDisplayMode(this)
1653 : blink::WebDisplayModeBrowser;
1654}
1655
[email protected]a9c81f02012-06-01 00:15:441656void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1657 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371658 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441659 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371660 } else {
1661 GotResponseToLockMouseRequest(false);
1662 }
1663}
1664
[email protected]b172aee2012-04-10 17:05:261665void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371666 if (delegate_)
1667 delegate_->LostMouseLock();
1668}
1669
[email protected]bafe6cd2012-05-23 23:09:501670void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431671 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551672 int32_t route_id,
1673 int32_t main_frame_route_id,
1674 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131675 const ViewHostMsg_CreateWindow_Params& params,
1676 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501677 // We usually create the new window in the same BrowsingInstance (group of
1678 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551679 // if the opener is being suppressed (in a non-guest), we create a new
1680 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251681 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551682
nickd30fd962015-07-27 21:51:081683 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141684 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1685 // yet.
1686 NOTREACHED();
1687 }
1688
[email protected]04cbd3d2013-12-04 04:58:201689 // If the opener is to be suppressed, the new window can be in any process.
1690 // Since routing ids are process specific, we must not have one passed in
1691 // as argument here.
1692 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1693
[email protected]bafe6cd2012-05-23 23:09:501694 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431695 params.opener_suppressed && !is_guest
1696 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1697 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501698
alexmos4cf2aa32015-07-15 23:40:431699 // A message to create a new window can only come from a process for a frame
1700 // in this WebContents' FrameTree. If any other process sends the request, it
1701 // is invalid and the process must be terminated.
1702 int render_process_id = source_site_instance->GetProcess()->GetID();
1703 bool did_match_process = false;
1704 frame_tree_.ForEach(
1705 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1706 if (!did_match_process) {
1707 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351708 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201709 if (process_handle != base::kNullProcessHandle) {
1710 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391711 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351712 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201713 }
1714 return;
1715 }
1716
[email protected]d1198fd2012-08-13 22:50:191717 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341718 //
1719 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301720 const std::string& partition_id =
1721 GetContentClient()->browser()->
1722 GetStoragePartitionIdForSite(GetBrowserContext(),
1723 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461724 StoragePartition* partition = BrowserContext::GetStoragePartition(
1725 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411726 DOMStorageContextWrapper* dom_storage_context =
1727 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191728 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1729 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1730 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371731
1732 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551733 !delegate_->ShouldCreateWebContents(
1734 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1735 params.window_container_type, params.frame_name, params.target_url,
1736 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011737 if (route_id != MSG_ROUTING_NONE &&
1738 !RenderViewHost::FromID(render_process_id, route_id)) {
1739 // If the embedder didn't create a WebContents for this route, we need to
1740 // delete the RenderView that had already been created.
1741 Send(new ViewMsg_Close(route_id));
1742 }
[email protected]dd6730412013-08-14 15:03:371743 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1744 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1745 main_frame_route_id);
dcheng3ce04b62015-10-26 23:30:551746 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1747 main_frame_widget_route_id);
[email protected]dd6730412013-08-14 15:03:371748 return;
1749 }
1750
1751 // Create the new web contents. This will automatically create the new
1752 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461753 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591754 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041755 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551756 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121757 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431758 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211759 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061760 create_params.opener_suppressed = params.opener_suppressed;
1761 if (params.disposition == NEW_BACKGROUND_TAB)
1762 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191763 create_params.renderer_initiated_creation =
1764 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061765
[email protected]4858e432014-06-23 18:14:171766 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551767 if (!is_guest) {
1768 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451769 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171770 new_contents = static_cast<WebContentsImpl*>(
1771 WebContents::Create(create_params));
1772 } else {
1773 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551774 }
[email protected]50d326e2014-05-20 17:59:061775 new_contents->GetController().SetSessionStorageNamespace(
1776 partition_id,
1777 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191778
alexmos646fec02015-07-25 00:11:491779 // If the new frame has a name, make sure any SiteInstances that can find
1780 // this named frame have proxies for it. Must be called after
1781 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1782 // GetSessionStorageNamespace.
1783 if (!params.frame_name.empty())
1784 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1785
[email protected]c4538072013-03-18 02:17:551786 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341787 // will be shown immediately).
1788 if (!params.opener_suppressed) {
1789 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451790 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501791
[email protected]d70bea92013-04-05 04:23:341792 // TODO(brettw): It seems bogus that we have to call this function on the
1793 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431794 new_view->CreateViewForWidget(
1795 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341796 }
[email protected]bafe6cd2012-05-23 23:09:501797 // Save the created window associated with the route so we can show it
1798 // later.
1799 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1800 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101801 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501802 }
1803
1804 if (delegate_) {
1805 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071806 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131807 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501808 }
1809
1810 if (params.opener_suppressed) {
1811 // When the opener is suppressed, the original renderer cannot access the
1812 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001813 bool was_blocked = false;
1814 if (delegate_) {
bokan107a47f2015-02-03 23:23:391815 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001816 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391817 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001818 params.user_gesture, &was_blocked);
1819 }
1820 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211821 OpenURLParams open_params(params.target_url,
1822 Referrer(),
1823 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351824 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211825 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301826 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371827
1828 if (delegate_ && !is_guest &&
1829 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1830 // We are in asynchronous add new contents path, delay opening url
1831 new_contents->delayed_open_url_params_.reset(
1832 new OpenURLParams(open_params));
1833 } else {
1834 new_contents->OpenURL(open_params);
1835 }
[email protected]eda238a12012-09-07 23:44:001836 }
[email protected]bafe6cd2012-05-23 23:09:501837 }
1838}
1839
dcheng29f5a6c2015-08-31 21:43:271840void WebContentsImpl::CreateNewWidget(int32 render_process_id,
1841 int32 route_id,
[email protected]180ef242013-11-07 06:50:461842 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:051843 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501844}
1845
dcheng29f5a6c2015-08-31 21:43:271846void WebContentsImpl::CreateNewFullscreenWidget(int32 render_process_id,
piman5d36dae2015-09-24 22:47:051847 int32 route_id) {
1848 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501849}
1850
dcheng29f5a6c2015-08-31 21:43:271851void WebContentsImpl::CreateNewWidget(int32 render_process_id,
1852 int32 route_id,
[email protected]bafe6cd2012-05-23 23:09:501853 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461854 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211855 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511856 // A message to create a new widget can only come from the active process for
1857 // this WebContentsImpl instance. If any other process sends the request,
1858 // it is invalid and the process must be terminated.
1859 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351860 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1861 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511862 if (process_handle != base::kNullProcessHandle) {
1863 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391864 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351865 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511866 }
1867 return;
1868 }
1869
[email protected]bafe6cd2012-05-23 23:09:501870 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:051871 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261872 created_widgets_.insert(widget_host);
1873
[email protected]cfd80b02014-05-01 17:46:481874 RenderWidgetHostViewBase* widget_view =
1875 static_cast<RenderWidgetHostViewBase*>(
1876 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191877 if (!widget_view)
1878 return;
[email protected]bafe6cd2012-05-23 23:09:501879 if (!is_fullscreen) {
1880 // Popups should not get activated.
1881 widget_view->SetPopupType(popup_type);
1882 }
1883 // Save the created widget associated with the route so we can show it later.
1884 pending_widget_views_[route_id] = widget_view;
1885
1886#if defined(OS_MACOSX)
1887 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1888 // to allow it to survive the trip without being hosted.
1889 base::mac::NSObjectRetain(widget_view->GetNativeView());
1890#endif
1891}
1892
1893void WebContentsImpl::ShowCreatedWindow(int route_id,
1894 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391895 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501896 bool user_gesture) {
1897 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001898 if (contents) {
1899 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:161900 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:381901 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
1902 contents->ResumeLoadingCreatedWebContents();
1903
[email protected]eda238a12012-09-07 23:44:001904 if (delegate) {
1905 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391906 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001907 }
1908 }
[email protected]bafe6cd2012-05-23 23:09:501909}
1910
1911void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391912 const gfx::Rect& initial_rect) {
1913 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501914}
1915
1916void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1917 ShowCreatedWidget(route_id, true, gfx::Rect());
1918}
1919
1920void WebContentsImpl::ShowCreatedWidget(int route_id,
1921 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391922 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481923 RenderWidgetHostViewBase* widget_host_view =
1924 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501925 if (!widget_host_view)
1926 return;
[email protected]cfd80b02014-05-01 17:46:481927
1928 RenderWidgetHostView* view = NULL;
1929 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1930 if (guest && guest->embedder_web_contents()) {
1931 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1932 } else {
1933 view = GetRenderWidgetHostView();
1934 }
1935
[email protected]4aebbca2013-09-17 22:26:491936 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311937 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031938 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311939 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491940 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1941 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531942 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491943 } else {
[email protected]cfd80b02014-05-01 17:46:481944 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491945 }
[email protected]4aebbca2013-09-17 22:26:491946 FOR_EACH_OBSERVER(WebContentsObserver,
1947 observers_,
1948 DidShowFullscreenWidget(route_id));
1949 if (!widget_host_view->HasFocus())
1950 widget_host_view->Focus();
1951 } else {
bokan107a47f2015-02-03 23:23:391952 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491953 }
[email protected]89054502012-06-03 10:29:241954
1955 RenderWidgetHostImpl* render_widget_host_impl =
1956 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1957 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311958 // Only allow privileged mouse lock for fullscreen render widget, which is
1959 // used to implement Pepper Flash fullscreen.
1960 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501961
1962#if defined(OS_MACOSX)
1963 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1964 // properly embedded (or purposefully ignored) we can release the retain we
1965 // took in CreateNewWidget().
1966 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1967#endif
1968}
1969
1970WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1971 PendingContents::iterator iter = pending_contents_.find(route_id);
1972
1973 // Certain systems can block the creation of new windows. If we didn't succeed
1974 // in creating one, just return NULL.
1975 if (iter == pending_contents_.end()) {
1976 return NULL;
1977 }
1978
1979 WebContentsImpl* new_contents = iter->second;
1980 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101981 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501982
[email protected]d70bea92013-04-05 04:23:341983 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251984 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341985 return new_contents;
1986
[email protected]bafe6cd2012-05-23 23:09:501987 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:431988 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:501989 return NULL;
1990
[email protected]bafe6cd2012-05-23 23:09:501991 return new_contents;
1992}
1993
1994RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1995 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1996 if (iter == pending_widget_views_.end()) {
1997 DCHECK(false);
1998 return NULL;
1999 }
2000
2001 RenderWidgetHostView* widget_host_view = iter->second;
2002 pending_widget_views_.erase(route_id);
2003
2004 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2005 if (!widget_host->GetProcess()->HasConnection()) {
2006 // The view has gone away or the renderer crashed. Nothing to do.
2007 return NULL;
2008 }
2009
2010 return widget_host_view;
2011}
2012
[email protected]f13b4202012-06-12 23:53:232013void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092014 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212015 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372016 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232017 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372018 } else {
2019 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:042020 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:372021 scoped_ptr<MediaStreamUI>());
2022 }
[email protected]f13b4202012-06-12 23:53:232023}
2024
grunell657d4d82014-09-18 00:09:432025bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2026 MediaStreamType type) {
2027 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2028 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2029 return delegate_ &&
2030 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2031}
2032
[email protected]cc9200432013-07-23 23:02:402033SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2034 SiteInstance* instance) {
2035 return controller_.GetSessionStorageNamespace(instance);
2036}
2037
[email protected]6de7fc482014-06-06 10:46:442038SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2039 return controller_.GetSessionStorageNamespaceMap();
2040}
2041
[email protected]9b159a52013-10-03 17:24:552042FrameTree* WebContentsImpl::GetFrameTree() {
2043 return &frame_tree_;
2044}
2045
lukendc35e7f2014-11-10 19:06:142046void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2047 virtual_keyboard_requested_ = requested;
2048}
2049
2050bool WebContentsImpl::IsVirtualKeyboardRequested() {
2051 return virtual_keyboard_requested_;
2052}
2053
[email protected]95640212014-07-26 18:14:302054AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2055 return accessibility_mode_;
2056}
2057
[email protected]31a71eaf2014-03-13 01:47:362058void WebContentsImpl::AccessibilityEventReceived(
2059 const std::vector<AXEventNotificationDetails>& details) {
2060 FOR_EACH_OBSERVER(
2061 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2062}
2063
dmazzonia656928e2014-09-15 20:28:542064RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402065 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542066 int browser_plugin_instance_id) {
2067 BrowserPluginGuestManager* guest_manager =
2068 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202069 if (!guest_manager)
2070 return nullptr;
2071
dmazzonia656928e2014-09-15 20:28:542072 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442073 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542074 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202075 return nullptr;
2076
dmazzonia656928e2014-09-15 20:28:542077 return guest->GetMainFrame();
2078}
2079
blundellc57b93f2014-10-29 13:19:572080GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2081 return geolocation_service_context_.get();
2082}
2083
alogvinovf50445a2015-10-30 13:00:122084WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2085 return wake_lock_service_context_.get();
2086}
2087
[email protected]edc3af82013-12-12 21:24:072088void WebContentsImpl::OnShowValidationMessage(
2089 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292090 const base::string16& main_text,
2091 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072092 if (delegate_)
2093 delegate_->ShowValidationMessage(
2094 this, anchor_in_root_view, main_text, sub_text);
2095}
2096
2097void WebContentsImpl::OnHideValidationMessage() {
2098 if (delegate_)
2099 delegate_->HideValidationMessage(this);
2100}
2101
2102void WebContentsImpl::OnMoveValidationMessage(
2103 const gfx::Rect& anchor_in_root_view) {
2104 if (delegate_)
2105 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2106}
2107
[email protected]32deec62013-05-15 23:55:042108void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2109 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442110 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042111}
2112
[email protected]95640212014-07-26 18:14:302113BrowserAccessibilityManager*
2114 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452115 RenderFrameHostImpl* rfh = GetMainFrame();
2116 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302117}
2118
2119BrowserAccessibilityManager*
2120 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452121 RenderFrameHostImpl* rfh = GetMainFrame();
2122 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302123}
2124
mohsen7ab1ec16ec2015-07-02 18:26:232125void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2126 RenderFrameHost* focused_frame = GetFocusedFrame();
2127 if (!focused_frame)
2128 return;
2129
2130 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2131 focused_frame->GetRoutingID(), extent));
2132}
2133
2134void WebContentsImpl::SelectRange(const gfx::Point& base,
2135 const gfx::Point& extent) {
2136 RenderFrameHost* focused_frame = GetFocusedFrame();
2137 if (!focused_frame)
2138 return;
2139
2140 focused_frame->Send(
2141 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2142}
2143
aurimasab0319022015-07-10 21:57:382144void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2145 int end_adjust) {
2146 RenderFrameHost* focused_frame = GetFocusedFrame();
2147 if (!focused_frame)
2148 return;
2149
2150 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2151 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2152}
2153
[email protected]b172aee2012-04-10 17:05:262154void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492155 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232156 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492157 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332158}
2159
[email protected]b172aee2012-04-10 17:05:262160void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:342161 if (delegate_)
2162 delegate_->ResizeDueToAutoResize(this, new_size);
2163}
2164
[email protected]b172aee2012-04-10 17:05:262165WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202166 if (!delegate_)
2167 return NULL;
[email protected]00c37fc2011-08-02 00:22:502168
[email protected]e5d549d2011-12-28 01:29:202169 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202170 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342171}
2172
[email protected]6b618e62012-08-16 12:59:182173bool WebContentsImpl::Send(IPC::Message* message) {
2174 if (!GetRenderViewHost()) {
2175 delete message;
2176 return false;
2177 }
2178
2179 return GetRenderViewHost()->Send(message);
2180}
2181
[email protected]a86c0e962013-12-17 17:10:392182void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2183 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442184 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392185 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442186}
2187
[email protected]20ca0382013-02-28 19:50:072188void WebContentsImpl::AttachInterstitialPage(
2189 InterstitialPageImpl* interstitial_page) {
2190 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212191 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292192
2193 // Cancel any visible dialogs so that they don't interfere with the
2194 // interstitial.
creis89a0f782015-05-27 16:13:172195 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292196
[email protected]20ca0382013-02-28 19:50:072197 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2198 DidAttachInterstitialPage());
2199}
2200
2201void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572202 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212203 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2205 DidDetachInterstitialPage());
2206}
2207
avi2b177592014-12-10 02:08:022208void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2209 int history_length) {
2210 SetHistoryOffsetAndLengthForView(
2211 GetRenderViewHost(), history_offset, history_length);
2212}
2213
2214void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2215 RenderViewHost* render_view_host,
2216 int history_offset,
2217 int history_length) {
2218 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2219 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142220}
2221
[email protected]4fed3702014-04-01 09:08:002222void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172223 RenderFrameHost* focused_frame = GetFocusedFrame();
2224 if (!focused_frame)
2225 return;
2226
[email protected]959be4c2014-04-08 15:01:332227 focused_frame->Send(new FrameMsg_Reload(
2228 focused_frame->GetRoutingID(), ignore_cache));
2229}
2230
2231void WebContentsImpl::Undo() {
2232 RenderFrameHost* focused_frame = GetFocusedFrame();
2233 if (!focused_frame)
2234 return;
2235
2236 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2237 RecordAction(base::UserMetricsAction("Undo"));
2238}
2239
2240void WebContentsImpl::Redo() {
2241 RenderFrameHost* focused_frame = GetFocusedFrame();
2242 if (!focused_frame)
2243 return;
2244 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2245 RecordAction(base::UserMetricsAction("Redo"));
2246}
2247
2248void WebContentsImpl::Cut() {
2249 RenderFrameHost* focused_frame = GetFocusedFrame();
2250 if (!focused_frame)
2251 return;
2252
2253 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2254 RecordAction(base::UserMetricsAction("Cut"));
2255}
2256
2257void WebContentsImpl::Copy() {
2258 RenderFrameHost* focused_frame = GetFocusedFrame();
2259 if (!focused_frame)
2260 return;
2261
2262 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2263 RecordAction(base::UserMetricsAction("Copy"));
2264}
2265
2266void WebContentsImpl::CopyToFindPboard() {
2267#if defined(OS_MACOSX)
2268 RenderFrameHost* focused_frame = GetFocusedFrame();
2269 if (!focused_frame)
2270 return;
2271
2272 // Windows/Linux don't have the concept of a find pasteboard.
2273 focused_frame->Send(
2274 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2275 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2276#endif
2277}
2278
2279void WebContentsImpl::Paste() {
2280 RenderFrameHost* focused_frame = GetFocusedFrame();
2281 if (!focused_frame)
2282 return;
2283
2284 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2285 RecordAction(base::UserMetricsAction("Paste"));
2286}
2287
2288void WebContentsImpl::PasteAndMatchStyle() {
2289 RenderFrameHost* focused_frame = GetFocusedFrame();
2290 if (!focused_frame)
2291 return;
2292
2293 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2294 focused_frame->GetRoutingID()));
2295 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2296}
2297
2298void WebContentsImpl::Delete() {
2299 RenderFrameHost* focused_frame = GetFocusedFrame();
2300 if (!focused_frame)
2301 return;
2302
2303 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2304 RecordAction(base::UserMetricsAction("DeleteSelection"));
2305}
2306
2307void WebContentsImpl::SelectAll() {
2308 RenderFrameHost* focused_frame = GetFocusedFrame();
2309 if (!focused_frame)
2310 return;
2311
2312 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2313 RecordAction(base::UserMetricsAction("SelectAll"));
2314}
2315
2316void WebContentsImpl::Unselect() {
2317 RenderFrameHost* focused_frame = GetFocusedFrame();
2318 if (!focused_frame)
2319 return;
2320
2321 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2322 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172323}
2324
2325void WebContentsImpl::Replace(const base::string16& word) {
2326 RenderFrameHost* focused_frame = GetFocusedFrame();
2327 if (!focused_frame)
2328 return;
2329
[email protected]959be4c2014-04-08 15:01:332330 focused_frame->Send(new InputMsg_Replace(
2331 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172332}
2333
2334void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2335 RenderFrameHost* focused_frame = GetFocusedFrame();
2336 if (!focused_frame)
2337 return;
2338
[email protected]959be4c2014-04-08 15:01:332339 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2340 focused_frame->GetRoutingID(), word));
2341}
2342
2343void WebContentsImpl::NotifyContextMenuClosed(
2344 const CustomContextMenuContext& context) {
2345 RenderFrameHost* focused_frame = GetFocusedFrame();
2346 if (!focused_frame)
2347 return;
2348
2349 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2350 focused_frame->GetRoutingID(), context));
2351}
2352
2353void WebContentsImpl::ExecuteCustomContextMenuCommand(
2354 int action, const CustomContextMenuContext& context) {
2355 RenderFrameHost* focused_frame = GetFocusedFrame();
2356 if (!focused_frame)
2357 return;
2358
2359 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2360 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002361}
2362
[email protected]fc2b46b2014-05-03 16:33:452363gfx::NativeView WebContentsImpl::GetNativeView() {
2364 return view_->GetNativeView();
2365}
2366
2367gfx::NativeView WebContentsImpl::GetContentNativeView() {
2368 return view_->GetContentNativeView();
2369}
2370
2371gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2372 return view_->GetTopLevelNativeWindow();
2373}
2374
2375gfx::Rect WebContentsImpl::GetViewBounds() {
2376 return view_->GetViewBounds();
2377}
2378
2379gfx::Rect WebContentsImpl::GetContainerBounds() {
2380 gfx::Rect rv;
2381 view_->GetContainerBounds(&rv);
2382 return rv;
2383}
2384
2385DropData* WebContentsImpl::GetDropData() {
2386 return view_->GetDropData();
2387}
2388
2389void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042390 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452391}
2392
2393void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042394 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452395}
2396
2397void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042398 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452399}
2400
2401void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042402 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452403}
2404
[email protected]b172aee2012-04-10 17:05:262405void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272406 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212407 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542408 return;
2409 }
[email protected]0b431992014-06-24 00:08:032410 RenderWidgetHostView* const fullscreen_view =
2411 GetFullscreenRenderWidgetHostView();
2412 if (fullscreen_view) {
2413 fullscreen_view->Focus();
2414 return;
2415 }
creisc014b402015-04-23 16:41:452416 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542417}
2418
[email protected]b172aee2012-04-10 17:05:262419bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212420 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542421}
2422
[email protected]b172aee2012-04-10 17:05:262423InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212424 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222425}
2426
[email protected]b172aee2012-04-10 17:05:262427bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162428 // WebKit creates Document object when MIME type is application/xhtml+xml,
2429 // so we also support this MIME type.
2430 return contents_mime_type_ == "text/html" ||
2431 contents_mime_type_ == "text/xml" ||
2432 contents_mime_type_ == "application/xhtml+xml" ||
2433 contents_mime_type_ == "text/plain" ||
2434 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252435 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162436}
2437
[email protected]b172aee2012-04-10 17:05:262438void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592439 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162440 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552441 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192442 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142443 return;
[email protected]c7dd2f62011-07-18 15:57:592444 }
2445
2446 Stop();
2447
2448 // Create the save package and possibly prompt the user for the name to save
2449 // the page as. The user prompt is an asynchronous operation that runs on
2450 // another thread.
2451 save_package_ = new SavePackage(this);
2452 save_package_->GetSaveInfo();
2453}
2454
2455// Used in automated testing to bypass prompting the user for file names.
2456// Instead, the names and paths are hard coded rather than running them through
2457// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342458bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2459 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212460 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592461 // Stop the page from navigating.
2462 Stop();
2463
2464 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212465 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592466}
2467
[email protected]3c71576ce2013-07-23 02:00:012468void WebContentsImpl::SaveFrame(const GURL& url,
2469 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372470 SaveFrameWithHeaders(url, referrer, std::string());
2471}
2472
2473void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2474 const Referrer& referrer,
2475 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192476 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012477 return;
sammc92af61552014-11-19 23:27:402478 if (delegate_ && delegate_->SaveFrame(url, referrer))
2479 return;
2480
nasko89ad7742015-03-05 22:14:192481 // TODO(nasko): This check for main frame is incorrect and should be fixed
2482 // by explicitly passing in which frame this method should target.
2483 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012484
2485 DownloadManager* dlm =
2486 BrowserContext::GetDownloadManager(GetBrowserContext());
2487 if (!dlm)
2488 return;
2489 int64 post_id = -1;
2490 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272491 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012492 if (entry)
2493 post_id = entry->GetPostID();
2494 }
2495 scoped_ptr<DownloadUrlParameters> params(
2496 DownloadUrlParameters::FromWebContents(this, url));
2497 params->set_referrer(referrer);
2498 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012499 if (post_id >= 0)
2500 params->set_method("POST");
2501 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372502
2503 if (headers.empty()) {
2504 params->set_prefer_cache(true);
2505 } else {
brettw26dab8f02015-08-08 00:28:472506 for (const base::StringPiece& key_value :
2507 base::SplitStringPiece(
2508 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2509 std::vector<std::string> pair = base::SplitString(
2510 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372511 DCHECK_EQ(2ul, pair.size());
2512 params->add_request_header(pair[0], pair[1]);
2513 }
2514 }
[email protected]3c71576ce2013-07-23 02:00:012515 dlm->DownloadUrl(params.Pass());
2516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342519 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482520 const base::Callback<void(int64)>& callback) {
2521 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122522}
2523
[email protected]b172aee2012-04-10 17:05:262524const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272525 return contents_mime_type_;
2526}
2527
[email protected]b172aee2012-04-10 17:05:262528bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272529 return notify_disconnection_;
2530}
2531
[email protected]b172aee2012-04-10 17:05:262532void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312533 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182534 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162535}
2536
[email protected]b172aee2012-04-10 17:05:262537void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542538 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182539 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162540}
2541
[email protected]8ff00d72012-10-23 19:12:212542RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272543 return &renderer_preferences_;
2544}
2545
[email protected]e35ccd52012-05-23 16:22:472546void WebContentsImpl::Close() {
2547 Close(GetRenderViewHost());
2548}
2549
[email protected]cf200a562013-05-03 16:24:292550void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462551 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292552 if (browser_plugin_embedder_.get())
2553 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2554 screen_x, screen_y, operation);
2555 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452556 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2557 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292558}
2559
[email protected]d60f3702013-12-26 16:30:242560void WebContentsImpl::DidGetResourceResponseStart(
2561 const ResourceRequestDetails& details) {
2562 controller_.ssl_manager()->DidStartResourceResponse(details);
2563
2564 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2565 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242566}
2567
2568void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462569 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242570 const ResourceRedirectDetails& details) {
2571 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2572
2573 FOR_EACH_OBSERVER(
2574 WebContentsObserver,
2575 observers_,
creis114ca1b2014-11-13 23:51:462576 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242577
2578 // TODO(avi): Remove. http://crbug.com/170921
2579 NotificationService::current()->Notify(
2580 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2581 Source<WebContents>(this),
2582 Details<const ResourceRedirectDetails>(&details));
clamy0e119882015-07-31 16:12:332583
2584 if (IsResourceTypeFrame(details.resource_type)) {
2585 NavigationHandleImpl* navigation_handle =
2586 static_cast<RenderFrameHostImpl*>(render_frame_host)
2587 ->navigation_handle();
2588 if (navigation_handle)
2589 navigation_handle->DidRedirectNavigation(details.new_url);
2590 }
[email protected]d60f3702013-12-26 16:30:242591}
2592
calamity7fe55ce2015-04-10 03:59:372593void WebContentsImpl::NotifyWebContentsFocused() {
2594 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2595}
2596
[email protected]b172aee2012-04-10 17:05:262597void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522598 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452599 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292600 if (browser_plugin_embedder_.get())
2601 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342602}
2603
[email protected]e35ccd52012-05-23 16:22:472604void WebContentsImpl::UserGestureDone() {
2605 OnUserGesture();
2606}
2607
[email protected]b172aee2012-04-10 17:05:262608void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272609 closed_by_user_gesture_ = value;
2610}
2611
[email protected]b172aee2012-04-10 17:05:262612bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272613 return closed_by_user_gesture_;
2614}
2615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502617 if (!delegate_)
2618 return;
2619
[email protected]6286a372013-10-09 04:03:272620 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2621 if (!entry)
[email protected]1788e772010-12-15 16:40:502622 return;
2623
[email protected]6286a372013-10-09 04:03:272624 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122625}
2626
[email protected]b172aee2012-04-10 17:05:262627void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042628 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272629 if (!delegate_)
2630 return;
2631
[email protected]691aa2f2013-05-28 22:52:042632 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272633}
2634
[email protected]b172aee2012-04-10 17:05:262635int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272636 return minimum_zoom_percent_;
2637}
2638
[email protected]b172aee2012-04-10 17:05:262639int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272640 return maximum_zoom_percent_;
2641}
2642
ccameronb7c1d6c2015-03-09 17:08:242643void WebContentsImpl::ResetPageScale() {
2644 Send(new ViewMsg_ResetPageScale(GetRoutingID()));
2645}
2646
[email protected]b172aee2012-04-10 17:05:262647gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492648 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232649}
2650
[email protected]b172aee2012-04-10 17:05:262651bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052652 if (GetBrowserPluginGuest())
2653 return GetBrowserPluginGuest()->LockMouse(allowed);
2654
creisc014b402015-04-23 16:41:452655 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432656 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2657 allowed)
creisc014b402015-04-23 16:41:452658 : false;
[email protected]0bfbf882011-12-22 18:19:272659}
2660
[email protected]b172aee2012-04-10 17:05:262661bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212662 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502663}
2664
alexmose201c7cd2015-06-10 17:14:212665WebContentsImpl* WebContentsImpl::GetOpener() const {
2666 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2667 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572668}
2669
[email protected]cb805452013-05-22 15:16:212670void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482671 if (!color_chooser_info_.get())
2672 return;
2673 RenderFrameHost* rfh = RenderFrameHost::FromID(
2674 color_chooser_info_->render_process_id,
2675 color_chooser_info_->render_frame_id);
2676 if (!rfh)
2677 return;
2678
2679 rfh->Send(new FrameMsg_DidChooseColorResponse(
2680 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202681}
2682
[email protected]cb805452013-05-22 15:16:212683void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482684 if (!color_chooser_info_.get())
2685 return;
2686 RenderFrameHost* rfh = RenderFrameHost::FromID(
2687 color_chooser_info_->render_process_id,
2688 color_chooser_info_->render_frame_id);
2689 if (!rfh)
2690 return;
2691
2692 rfh->Send(new FrameMsg_DidEndColorChooser(
2693 rfh->GetRoutingID(), color_chooser_info_->identifier));
2694 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202695}
2696
halton.huoca2eabd2015-07-06 08:17:402697int WebContentsImpl::DownloadImage(
2698 const GURL& url,
2699 bool is_favicon,
2700 uint32_t max_bitmap_size,
2701 bool bypass_cache,
2702 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552703 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402704 static int next_image_download_id = 0;
2705 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2706 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552707 const int download_id = ++next_image_download_id;
2708 if (!mojo_image_downloader) {
2709 // If the renderer process is dead (i.e. crash, or memory pressure on
2710 // Android), the downloader service will be invalid. Pre-Mojo, this would
2711 // hang the callback indefinetly since the IPC would be dropped. Now,
2712 // respond with a 400 HTTP error code to indicate that something went wrong.
2713 BrowserThread::PostTask(
2714 BrowserThread::UI, FROM_HERE,
2715 base::Bind(&WebContents::ImageDownloadCallback::Run,
2716 base::Owned(new ImageDownloadCallback(callback)),
2717 download_id, 400, url, std::vector<SkBitmap>(),
2718 std::vector<gfx::Size>()));
2719 return download_id;
2720 }
2721
halton.huoca2eabd2015-07-06 08:17:402722 image_downloader::DownloadRequestPtr req =
2723 image_downloader::DownloadRequest::New();
2724
2725 req->url = mojo::String::From(url);
2726 req->is_favicon = is_favicon;
2727 req->max_bitmap_size = max_bitmap_size;
2728 req->bypass_cache = bypass_cache;
2729
2730 mojo_image_downloader->DownloadImage(
2731 req.Pass(),
amistry9f01b772015-07-29 01:54:552732 base::Bind(&DidDownloadImage, callback, download_id, url));
2733 return download_id;
[email protected]795c28972012-12-06 06:13:392734}
2735
[email protected]5dcaf8e2013-12-28 01:31:422736bool WebContentsImpl::IsSubframe() const {
2737 return is_subframe_;
2738}
2739
[email protected]36ec24f2014-01-09 00:32:082740void WebContentsImpl::Find(int request_id,
2741 const base::string16& search_text,
2742 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092743 // See if a top level browser plugin handles the find request first.
paulmeyer95703b92015-08-10 17:38:472744 if (browser_plugin_embedder_ &&
2745 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2746 return;
raymes0fa0be52014-10-13 20:38:092747 }
[email protected]36ec24f2014-01-09 00:32:082748 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2749}
2750
2751void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012752 // See if a top level browser plugin handles the stop finding request first.
paulmeyer95703b92015-08-10 17:38:472753 if (browser_plugin_embedder_ &&
2754 browser_plugin_embedder_->StopFinding(action)) {
2755 return;
raymes2bc64182015-02-06 01:23:012756 }
[email protected]36ec24f2014-01-09 00:32:082757 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2758}
2759
[email protected]4fe53add2014-04-08 19:53:362760void WebContentsImpl::InsertCSS(const std::string& css) {
2761 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2762 GetMainFrame()->GetRoutingID(), css));
2763}
2764
dalecurtisbc6572e12014-09-12 19:22:302765bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:152766 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302767}
2768
mlamouriefdca9d2014-09-16 16:55:402769void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2770 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2771}
2772
dominickn6919ce32015-10-15 01:52:282773void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
2774 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
2775}
2776
mlamouri7a78d6fd2015-01-17 13:23:532777void WebContentsImpl::ExitFullscreen() {
2778 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:432779 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
mlamouri7a78d6fd2015-01-17 13:23:532780 ExitFullscreenMode();
2781}
2782
mariakhomenko44bdc4732015-04-29 01:55:382783void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372784 if (delayed_open_url_params_.get()) {
2785 OpenURL(*delayed_open_url_params_.get());
2786 delayed_open_url_params_.reset(nullptr);
2787 return;
2788 }
2789
mariakhomenko44bdc4732015-04-29 01:55:382790 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2791 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162792 if (is_resume_pending_) {
2793 is_resume_pending_ = false;
2794 GetRenderViewHost()->Init();
2795 GetMainFrame()->Init();
2796 }
mariakhomenko44bdc4732015-04-29 01:55:382797}
2798
[email protected]b172aee2012-04-10 17:05:262799bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272800 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172801 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332802 return true;
2803 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272804}
2805
[email protected]b172aee2012-04-10 17:05:262806void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272807 if (delegate_)
2808 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212809}
2810
clamy0e119882015-07-31 16:12:332811void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
2812 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2813 DidStartNavigation(navigation_handle));
2814}
2815
2816void WebContentsImpl::DidRedirectNavigation(
2817 NavigationHandle* navigation_handle) {
2818 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2819 DidRedirectNavigation(navigation_handle));
2820}
2821
clamyefca29e2015-09-17 00:22:112822void WebContentsImpl::ReadyToCommitNavigation(
2823 NavigationHandle* navigation_handle) {
2824 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2825 ReadyToCommitNavigation(navigation_handle));
2826}
2827
clamy0e119882015-07-31 16:12:332828void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
2829 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2830 DidFinishNavigation(navigation_handle));
2831}
2832
[email protected]52913802013-12-10 05:52:182833void WebContentsImpl::DidStartProvisionalLoad(
2834 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182835 const GURL& validated_url,
2836 bool is_error_page,
2837 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102838 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482839 FOR_EACH_OBSERVER(
2840 WebContentsObserver,
2841 observers_,
2842 DidStartProvisionalLoadForFrame(
2843 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082844
2845 // Notify accessibility if this is a reload.
2846 NavigationEntry* entry = controller_.GetVisibleEntry();
2847 if (entry && ui::PageTransitionCoreTypeIs(
2848 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2849 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2850 BrowserAccessibilityManager* manager =
2851 ftn->current_frame_host()->browser_accessibility_manager();
2852 if (manager)
2853 manager->UserIsReloading();
2854 }
[email protected]400992b2012-06-14 00:03:542855}
2856
[email protected]3109fbb72014-01-06 23:57:152857void WebContentsImpl::DidFailProvisionalLoadWithError(
2858 RenderFrameHostImpl* render_frame_host,
2859 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2860 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312861 FOR_EACH_OBSERVER(WebContentsObserver,
2862 observers_,
2863 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312864 validated_url,
2865 params.error_code,
gsennton6fbb38692015-06-24 19:23:552866 params.error_description,
2867 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:082868
2869 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2870 BrowserAccessibilityManager* manager =
2871 ftn->current_frame_host()->browser_accessibility_manager();
2872 if (manager)
2873 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152874}
2875
[email protected]b80624c2014-02-09 02:46:552876void WebContentsImpl::DidFailLoadWithError(
2877 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552878 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552879 int error_code,
gsennton6fbb38692015-06-24 19:23:552880 const base::string16& error_description,
2881 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:142882 FOR_EACH_OBSERVER(
2883 WebContentsObserver,
2884 observers_,
gsennton6fbb38692015-06-24 19:23:552885 DidFailLoad(render_frame_host, url, error_code, error_description,
2886 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:552887}
2888
[email protected]52913802013-12-10 05:52:182889void WebContentsImpl::NotifyChangedNavigationState(
2890 InvalidateTypes changed_flags) {
2891 NotifyNavigationStateChanged(changed_flags);
2892}
2893
[email protected]3691e5cf2014-01-22 10:16:202894void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:202895 const GURL& url,
2896 NavigationController::ReloadType reload_type) {
2897 // Notify observers about navigation.
2898 FOR_EACH_OBSERVER(
2899 WebContentsObserver,
2900 observers_,
2901 DidStartNavigationToPendingEntry(url, reload_type));
2902}
2903
[email protected]8cb834e2014-03-06 14:23:232904void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2905 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502906 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2907 // weak pointer of sorts.
2908 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2909 const int32_t frame_id = render_frame_host->GetRoutingID();
2910
[email protected]65920f332014-03-04 21:14:182911 WebContents* new_contents = OpenURL(params);
2912
dchengb907f7332015-01-07 20:35:502913 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182914 // Notify observers.
2915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2916 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462917 render_frame_host,
[email protected]65920f332014-03-04 21:14:182918 params.url,
2919 params.referrer,
2920 params.disposition,
creis114ca1b2014-11-13 23:51:462921 params.transition));
[email protected]65920f332014-03-04 21:14:182922 }
2923}
2924
[email protected]aa62afd2014-04-22 19:22:462925bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2926 if (!delegate_)
2927 return false;
2928 return delegate_->ShouldPreserveAbortedURLs(this);
2929}
2930
[email protected]37567b432014-02-12 01:12:222931void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432932 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222933 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352934 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222935 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482936 FOR_EACH_OBSERVER(WebContentsObserver,
2937 observers_,
2938 DidCommitProvisionalLoadForFrame(
2939 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:082940
2941 BrowserAccessibilityManager* manager =
2942 render_frame_host->browser_accessibility_manager();
2943 if (manager)
2944 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:222945}
2946
[email protected]0d0f4c492014-04-02 06:42:572947void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232948 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572949 // Ensure fullscreen mode is exited before committing the navigation to a
2950 // different page. The next page will not start out assuming it is in
2951 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232952 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192953 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572954 return;
2955 }
2956 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532957 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572958 DCHECK(!IsFullscreenForCurrentTab());
2959}
2960
[email protected]37567b432014-02-12 01:12:222961void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282962 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222963 const LoadCommittedDetails& details,
2964 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2965 if (details.is_navigation_to_different_page()) {
2966 // Clear the status bubble. This is a workaround for a bug where WebKit
2967 // doesn't let us know that the cursor left an element during a
2968 // transition (this is also why the mouse cursor remains as a hand after
2969 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2970 // clear the bubble when a user navigates to a named anchor in the same
2971 // page.
sky8b00392d2015-01-10 00:30:282972 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:002973
2974 RenderWidgetHostViewBase* rwhvb =
2975 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2976 if (rwhvb)
2977 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:282978
peter90afaba2015-06-01 12:05:292979 did_first_visually_non_empty_paint_ = false;
2980
yusufod41c5f92015-03-06 00:14:282981 // Reset theme color on navigation to new page.
2982 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:222983 }
2984
2985 if (!details.is_in_page) {
2986 // Once the main frame is navigated, we're no longer considered to have
2987 // displayed insecure content.
2988 displayed_insecure_content_ = false;
2989 SSLManager::NotifySSLInternalStateChanged(
2990 GetController().GetBrowserContext());
2991 }
2992
2993 // Notify observers about navigation.
2994 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2995 DidNavigateMainFrame(details, params));
2996
[email protected]e85165c642014-06-10 14:34:312997 if (delegate_)
[email protected]37567b432014-02-12 01:12:222998 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312999 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223000}
3001
3002void WebContentsImpl::DidNavigateAnyFramePostCommit(
3003 RenderFrameHostImpl* render_frame_host,
3004 const LoadCommittedDetails& details,
3005 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103006 // Now that something has committed, we don't need to track whether the
3007 // initial page has been accessed.
3008 has_accessed_initial_document_ = false;
3009
[email protected]37567b432014-02-12 01:12:223010 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173011 if (!details.is_in_page)
3012 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223013
3014 // Notify observers about navigation.
3015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093016 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223017}
3018
3019void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3020 contents_mime_type_ = mime_type;
3021}
3022
[email protected]277857a2014-06-03 10:38:013023bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313024 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053025 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313026 return false;
3027
[email protected]37567b432014-02-12 01:12:223028 if (delegate_)
3029 return delegate_->CanOverscrollContent();
3030
3031 return false;
3032}
3033
[email protected]37b64c52014-07-11 21:14:053034void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293035 // Update the theme color. This is to be published to observers after the
3036 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283037 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293038
3039 if (did_first_visually_non_empty_paint_ &&
3040 last_sent_theme_color_ != theme_color_) {
3041 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3042 DidChangeThemeColor(theme_color_));
3043 last_sent_theme_color_ = theme_color_;
3044 }
[email protected]e7104762014-06-20 19:17:253045}
3046
[email protected]b172aee2012-04-10 17:05:263047void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183048 const GURL& url,
[email protected]70435962011-08-02 20:13:283049 const std::string& security_info,
3050 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183051 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403052 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533053 SSLStatus status;
3054 if (!DeserializeSecurityInfo(security_info, &status)) {
3055 bad_message::ReceivedBadMessage(
3056 GetRenderProcessHost(),
3057 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3058 return;
3059 }
[email protected]724159a2010-12-30 01:11:183060
3061 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593062 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213063 LoadFromMemoryCacheDetails details(
avie0d90182015-07-08 19:33:593064 url, GetRenderProcessHost()->GetID(), status.cert_id, status.cert_status,
3065 http_method, mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:183066
[email protected]b0f724c2013-09-05 04:21:133067 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3068
3069 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3070 DidLoadResourceFromMemoryCache(details));
3071
[email protected]8bfc8272013-09-09 20:10:533072 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3073 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403074 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533075 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3076 GetRenderProcessHost()->GetID()) :
3077 GetBrowserContext()->GetRequestContextForRenderProcess(
3078 GetRenderProcessHost()->GetID()));
3079 BrowserThread::PostTask(
3080 BrowserThread::IO,
3081 FROM_HERE,
3082 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3083 }
[email protected]724159a2010-12-30 01:11:183084}
3085
[email protected]b172aee2012-04-10 17:05:263086void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393087 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183088 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193089 SSLManager::NotifySSLInternalStateChanged(
3090 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183091}
3092
[email protected]b172aee2012-04-10 17:05:263093void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:023094 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583095 LOG(WARNING) << security_origin << " ran insecure content from "
3096 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393097 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
brettwa7ff1b292015-07-16 17:49:293098 if (base::EndsWith(security_origin, kDotGoogleDotCom,
3099 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393100 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183101 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193102 SSLManager::NotifySSLInternalStateChanged(
3103 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183104}
3105
[email protected]501052ff2014-02-21 22:19:073106void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113107 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473108 return;
naskofbd033392015-01-27 02:34:473109
[email protected]1d62cf72014-02-07 21:31:573110 RenderFrameHostImpl* rfh =
3111 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143112 FOR_EACH_OBSERVER(
3113 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183114}
3115
naskofbd033392015-01-27 02:34:473116void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113117 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123118 return;
[email protected]a1b99262013-12-27 21:56:223119
[email protected]8b3af1e2014-01-24 13:29:123120 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443121 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373122 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423123 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373124
[email protected]61ac9e242014-03-21 20:55:263125 RenderFrameHostImpl* rfh =
3126 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143127 FOR_EACH_OBSERVER(
3128 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313129}
3130
[email protected]b172aee2012-04-10 17:05:263131void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573132 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3133 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263134}
3135
[email protected]b172aee2012-04-10 17:05:263136void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303137 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263138 minimum_zoom_percent_ = minimum_percent;
3139 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263140}
3141
[email protected]b172aee2012-04-10 17:05:263142void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343143 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433144 if (!delegate_)
3145 return;
3146
[email protected]b9535422012-02-09 01:47:593147 ChildProcessSecurityPolicyImpl* policy =
3148 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223149 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593150 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213151}
3152
[email protected]b172aee2012-04-10 17:05:263153void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3154 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263155 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363156 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433157 if (!delegate_)
3158 return;
3159
[email protected]b9535422012-02-09 01:47:593160 ChildProcessSecurityPolicyImpl* policy =
3161 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323162 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593163 return;
[email protected]8f810632013-06-06 22:33:323164
[email protected]c125e532014-05-10 20:39:063165 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203166}
3167
[email protected]f5273e52014-07-14 16:30:203168void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3169 const GURL& url,
3170 bool user_gesture) {
3171 if (!delegate_)
3172 return;
3173
3174 ChildProcessSecurityPolicyImpl* policy =
3175 ChildProcessSecurityPolicyImpl::GetInstance();
3176 if (policy->IsPseudoScheme(protocol))
3177 return;
3178
3179 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3180}
3181
kouhei40f03cb2015-09-24 07:47:013182void WebContentsImpl::OnUpdatePageImportanceSignals(
3183 const PageImportanceSignals& signals) {
3184 page_importance_signals_ = signals;
3185}
3186
[email protected]b172aee2012-04-10 17:05:263187void WebContentsImpl::OnFindReply(int request_id,
3188 int number_of_matches,
3189 const gfx::Rect& selection_rect,
3190 int active_match_ordinal,
3191 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433192 if (delegate_) {
3193 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3194 active_match_ordinal, final_update);
3195 }
[email protected]b888919c2011-09-02 00:32:163196}
3197
[email protected]59363fc92012-09-05 03:46:313198#if defined(OS_ANDROID)
3199void WebContentsImpl::OnFindMatchRectsReply(
3200 int version,
3201 const std::vector<gfx::RectF>& rects,
3202 const gfx::RectF& active_rect) {
3203 if (delegate_)
3204 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3205}
[email protected]583418cc2013-01-17 14:01:103206
[email protected]1ff427972013-02-07 21:14:073207void WebContentsImpl::OnOpenDateTimeDialog(
3208 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173209 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093210 GetRenderViewHost(),
3211 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133212 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093213 value.minimum,
3214 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173215 value.step,
3216 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103217}
[email protected]59363fc92012-09-05 03:46:313218#endif
3219
avi60bd4902015-09-23 20:39:243220void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3221 std::string json = json_string;
3222 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3223 Source<WebContents>(this),
3224 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403225}
3226
[email protected]b172aee2012-04-10 17:05:263227void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3228 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103229 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253230 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103231 AppCacheAccessed(manifest_url, blocked_by_policy));
3232}
3233
[email protected]8bc5ff02013-11-29 06:34:033234void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483235 int color_chooser_id,
3236 SkColor color,
3237 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113238 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003239 return;
nasko907fcb62015-01-28 04:24:113240
[email protected]aa62afd2014-04-22 19:22:463241 ColorChooser* new_color_chooser = delegate_ ?
3242 delegate_->OpenColorChooser(this, color, suggestions) :
3243 NULL;
[email protected]820957a2014-01-14 14:56:303244 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213245 return;
[email protected]8ed16472014-04-11 19:02:483246 if (color_chooser_info_.get())
3247 color_chooser_info_->chooser->End();
3248
3249 color_chooser_info_.reset(new ColorChooserInfo(
3250 render_frame_message_source_->GetProcess()->GetID(),
3251 render_frame_message_source_->GetRoutingID(),
3252 new_color_chooser,
3253 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203254}
3255
[email protected]b172aee2012-04-10 17:05:263256void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483257 if (color_chooser_info_ &&
3258 color_chooser_id == color_chooser_info_->identifier)
3259 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203260}
3261
[email protected]b172aee2012-04-10 17:05:263262void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323263 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483264 if (color_chooser_info_ &&
3265 color_chooser_id == color_chooser_info_->identifier)
3266 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203267}
3268
[email protected]d0759f492012-04-19 22:50:503269// This exists for render views that don't have a WebUI, but do have WebUI
3270// bindings enabled.
3271void WebContentsImpl::OnWebUISend(const GURL& source_url,
3272 const std::string& name,
3273 const base::ListValue& args) {
3274 if (delegate_)
3275 delegate_->WebUISend(this, source_url, name, args);
3276}
3277
thestigc4cac8f2014-09-04 21:17:503278#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003279void WebContentsImpl::OnPepperInstanceCreated() {
3280 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3281}
3282
3283void WebContentsImpl::OnPepperInstanceDeleted() {
3284 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3285}
3286
tommyclie6633ca72014-10-31 00:40:423287void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3288 const base::FilePath& path,
3289 bool is_hung) {
3290 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3291
3292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3293 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3294}
3295
3296void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3297 base::ProcessId plugin_pid) {
3298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3299 PluginCrashed(plugin_path, plugin_pid));
3300}
3301
[email protected]d8415ad92012-08-23 14:40:503302void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443303 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503304 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343305 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163306 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443307 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163308 return;
[email protected]d8415ad92012-08-23 14:40:503309 }
3310
[email protected]8c8fc292012-11-23 18:57:163311 if (!delegate_->RequestPpapiBrokerPermission(
3312 this, url, plugin_path,
3313 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443314 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163315 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443316 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163317 }
[email protected]d8415ad92012-08-23 14:40:503318}
3319
[email protected]ea0309c2013-08-06 19:35:443320void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503321 bool result) {
[email protected]ea0309c2013-08-06 19:35:443322 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503323}
3324
fsamuel833ee7c2015-02-13 23:40:403325void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3326 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393327 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143328 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403329 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373330}
tommyclie6633ca72014-10-31 00:40:423331#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373332
[email protected]795c28972012-12-06 06:13:393333void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393334 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063335 // We get updated favicon URLs after the page stops loading. If a cross-site
3336 // navigation occurs while a page is still loading, the initial page
3337 // may stop loading and send us updated favicon URLs after the navigation
3338 // for the new page has committed.
3339 RenderViewHostImpl* rvhi =
3340 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3341 if (!rvhi->is_active())
3342 return;
3343
[email protected]795c28972012-12-06 06:13:393344 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293345 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393346}
3347
dalecurtisbc6572e12014-09-12 19:22:303348void WebContentsImpl::CreateAudioPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303349 DCHECK(!audio_power_save_blocker_);
3350 audio_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033351 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
3352 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio");
dalecurtisbc6572e12014-09-12 19:22:303353}
3354
3355void WebContentsImpl::CreateVideoPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303356 DCHECK(!video_power_save_blocker_);
3357 DCHECK(!active_video_players_.empty());
3358 video_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033359 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
3360 PowerSaveBlocker::kReasonVideoPlayback, "Playing video");
dalecurtisbc6572e12014-09-12 19:22:303361#if defined(OS_ANDROID)
3362 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
boliu65a9d1d2015-04-09 03:58:523363 ->InitDisplaySleepBlocker(this);
dalecurtisbc6572e12014-09-12 19:22:303364#endif
dalecurtisbc6572e12014-09-12 19:22:303365}
3366
3367void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3368 // If there are no more audio players and we don't have audio stream
3369 // monitoring, release the audio power save blocker here instead of during
3370 // NotifyNavigationStateChanged().
3371 if (active_audio_players_.empty() &&
avayvodcc85bbd2015-08-28 19:11:153372 !AudioStreamMonitor::monitoring_available()) {
dalecurtisbc6572e12014-09-12 19:22:303373 audio_power_save_blocker_.reset();
3374 }
3375
3376 // If there are no more video players, clear the video power save blocker.
3377 if (active_video_players_.empty())
3378 video_power_save_blocker_.reset();
3379}
3380
[email protected]1dd0bb752014-02-01 01:16:263381void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3382 bool has_video,
avayvod68017be2014-10-10 18:02:433383 bool has_audio,
3384 bool is_remote) {
3385 // Ignore the videos playing remotely and don't hold the wake lock for the
3386 // screen.
3387 if (is_remote) return;
3388
dalecurtisbc6572e12014-09-12 19:22:303389 if (has_audio) {
3390 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3391
3392 // If we don't have audio stream monitoring, allocate the audio power save
3393 // blocker here instead of during NotifyNavigationStateChanged().
3394 if (!audio_power_save_blocker_ &&
avayvodcc85bbd2015-08-28 19:11:153395 !AudioStreamMonitor::monitoring_available()) {
dalecurtisbc6572e12014-09-12 19:22:303396 CreateAudioPowerSaveBlocker();
3397 }
[email protected]1dd0bb752014-02-01 01:16:263398 }
loislo0381a742014-09-11 10:58:113399
dalecurtisbc6572e12014-09-12 19:22:303400 if (has_video) {
3401 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3402
3403 // If we're not hidden and have just created a player, create a blocker.
3404 if (!video_power_save_blocker_ && !IsHidden())
3405 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113406 }
prashantv0c9b968d22015-03-26 00:58:543407
3408 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying());
[email protected]1dd0bb752014-02-01 01:16:263409}
3410
3411void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303412 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3413 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3414 MaybeReleasePowerSaveBlockers();
prashantv0c9b968d22015-03-26 00:58:543415
3416 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused());
[email protected]d9030b82013-07-19 08:26:063417}
3418
avayvod41634b12015-07-08 17:07:053419#if defined(OS_ANDROID)
3420
3421void WebContentsImpl::OnMediaSessionStateChanged() {
3422 MediaSession* session = MediaSession::Get(this);
3423 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3424 MediaSessionStateChanged(session->IsControllable(),
3425 session->IsSuspended()));
3426}
3427
3428void WebContentsImpl::ResumeMediaSession() {
3429 MediaSession::Get(this)->Resume();
3430}
3431
3432void WebContentsImpl::SuspendMediaSession() {
3433 MediaSession::Get(this)->Suspend();
3434}
3435
mlamouri4c4fbed2015-08-17 15:51:013436void WebContentsImpl::StopMediaSession() {
3437 MediaSession::Get(this)->Stop();
3438}
3439
avayvod41634b12015-07-08 17:07:053440#endif // defined(OS_ANDROID)
3441
[email protected]50279492014-05-05 23:24:293442void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153443 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293444 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283445
peter90afaba2015-06-01 12:05:293446 did_first_visually_non_empty_paint_ = true;
3447
yusufod41c5f92015-03-06 00:14:283448 if (theme_color_ != last_sent_theme_color_) {
3449 // Theme color should have updated by now if there was one.
3450 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3451 DidChangeThemeColor(theme_color_));
3452 last_sent_theme_color_ = theme_color_;
3453 }
[email protected]9f268072013-11-07 00:02:153454}
[email protected]d9030b82013-07-19 08:26:063455
[email protected]e67ebf32013-02-13 11:07:193456void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013457 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073458 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013459
estark5ea80e52015-06-19 18:43:123460 SecurityStyleExplanations security_style_explanations;
3461 SecurityStyle security_style =
3462 delegate_->GetSecurityStyle(this, &security_style_explanations);
3463 FOR_EACH_OBSERVER(
3464 WebContentsObserver, observers_,
3465 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013466 }
[email protected]e67ebf32013-02-13 11:07:193467}
3468
[email protected]17e286e2013-03-01 23:29:393469void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3470 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3471 BeforeFormRepostWarningShow());
3472}
3473
[email protected]ec6c05f2013-10-23 18:41:573474void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3475 Activate();
3476 if (delegate_)
3477 delegate_->ShowRepostFormWarningDialog(this);
3478}
3479
[email protected]b4c84012014-04-28 19:51:103480bool WebContentsImpl::HasAccessedInitialDocument() {
3481 return has_accessed_initial_document_;
3482}
3483
[email protected]96d185d2009-04-24 03:28:543484// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593485// loading, or done loading.
fdegans6ce28f52015-03-19 12:52:223486void WebContentsImpl::SetIsLoading(bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093487 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263488 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543489 if (is_loading == is_loading_)
3490 return;
3491
3492 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263493 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3494 base::string16());
[email protected]96d185d2009-04-24 03:28:543495 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563496 upload_size_ = 0;
3497 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543498 }
3499
[email protected]fa944cb82013-11-15 17:51:213500 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543501
3502 is_loading_ = is_loading;
3503 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033504 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543505
[email protected]6ebdc9b2010-09-27 16:55:573506 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093507 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213508 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543509
[email protected]eab61442013-11-14 18:35:483510 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593511 if (is_loading) {
naskob8744d22014-08-28 17:07:433512 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3513 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223514 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593515 } else {
naskob8744d22014-08-28 17:07:433516 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3517 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223518 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593519 }
[email protected]66798902013-10-01 18:40:163520
3521 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213522 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3523 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543524 if (details)
[email protected]8ff00d72012-10-23 19:12:213525 det = Details<LoadNotificationDetails>(details);
3526 NotificationService::current()->Notify(
3527 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543528}
3529
[email protected]b172aee2012-04-10 17:05:263530void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463531 // If we are creating a RVH for a restored controller, then we need to make
3532 // sure the RenderView starts with a next_page_id_ larger than the number
3533 // of restored entries. This must be called before the RenderView starts
3534 // navigating (to avoid a race between the browser updating max_page_id and
3535 // the renderer updating next_page_id_). Because of this, we only call this
3536 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563537 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583538 if (max_restored_page_id >
3539 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3540 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3541 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323542}
3543
[email protected]b172aee2012-04-10 17:05:263544bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263545 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323546 // For file URLs without a title, use the pathname instead. In the case of a
3547 // synthesized title, we don't want the update to count toward the "one set
3548 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263549 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323550 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513551 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243552 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323553 explicit_set = false; // Don't count synthetic titles toward the set limit.
3554 } else {
[email protected]8af69c6c2014-03-03 19:05:313555 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323556 explicit_set = true;
3557 }
3558
[email protected]987fc3a2011-05-26 14:18:093559 // If a page is created via window.open and never navigated,
3560 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553561 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093562 if (entry) {
[email protected]36fc0392011-12-25 03:59:513563 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093564 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323565
[email protected]36fc0392011-12-25 03:59:513566 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093567 } else {
3568 if (page_title_when_no_navigation_entry_ == final_title)
3569 return false; // Nothing changed, don't bother.
3570
3571 page_title_when_no_navigation_entry_ = final_title;
3572 }
[email protected]420ae012009-04-24 05:16:323573
[email protected]420ae012009-04-24 05:16:323574 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233575 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323576
[email protected]66798902013-10-01 18:40:163577 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533578 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163579
[email protected]420ae012009-04-24 05:16:323580 return true;
3581}
3582
fdegansa696e5112015-04-17 01:57:593583void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003584 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003585 if (delegate_)
fdegansa696e5112015-04-17 01:57:593586 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003587}
3588
3589void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343590 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003591 loading_weak_factory_.InvalidateWeakPtrs();
3592 loading_last_progress_update_ = base::TimeTicks();
3593}
3594
[email protected]02d7b6e2014-06-24 21:01:503595void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3596 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323597 // After sending out a swap notification, we need to send a disconnect
3598 // notification so that clients that pick up a pointer to |this| can NULL the
3599 // pointer. See Bug 1230284.
3600 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113601 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283602 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113603
[email protected]7a846df2012-09-20 19:17:393604 // Ensure that the associated embedder gets cleared after a RenderViewHost
3605 // gets swapped, so we don't reuse the same embedder next time a
3606 // RenderViewHost is attached to this WebContents.
3607 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323608}
3609
[email protected]02d7b6e2014-06-24 21:01:503610void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3611 RenderFrameHost* new_host) {
3612 FOR_EACH_OBSERVER(WebContentsObserver,
3613 observers_,
3614 RenderFrameHostChanged(old_host, new_host));
3615}
3616
[email protected]da7a7182013-09-06 08:11:113617// TODO(avi): Remove this entire function because this notification is already
3618// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263619void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323620 if (!notify_disconnection_)
3621 return;
3622
3623 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213624 NotificationService::current()->Notify(
3625 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3626 Source<WebContents>(this),
3627 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323628}
3629
[email protected]cbb1ef592013-06-05 19:49:463630void WebContentsImpl::NotifyNavigationEntryCommitted(
3631 const LoadCommittedDetails& load_details) {
3632 FOR_EACH_OBSERVER(
3633 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3634}
3635
[email protected]f114fa42013-12-06 17:06:443636bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3637 const IPC::Message& message) {
3638 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313639}
3640
[email protected]c31a84802014-04-03 15:55:493641const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3642 return GetLastCommittedURL();
3643}
3644
[email protected]b849847b2013-12-10 21:57:583645void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583646 FOR_EACH_OBSERVER(WebContentsObserver,
3647 observers_,
3648 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303649 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583650}
3651
3652void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193653 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583654 FOR_EACH_OBSERVER(WebContentsObserver,
3655 observers_,
3656 RenderFrameDeleted(render_frame_host));
3657}
3658
[email protected]a09d53ce2014-01-31 00:46:423659void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3660 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103661 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423662 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103663 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423664 return;
3665
[email protected]077e704b2014-05-23 19:24:103666 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3667 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423668}
3669
[email protected]87de04b02014-04-08 22:14:493670void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013671 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493672 const base::string16& message,
3673 const base::string16& default_prompt,
3674 const GURL& frame_url,
3675 JavaScriptMessageType javascript_message_type,
3676 IPC::Message* reply_msg) {
3677 // Suppress JavaScript dialogs when requested. Also suppress messages when
3678 // showing an interstitial as it's shown over the previous page and we don't
3679 // want the hidden page's dialogs to interfere with the interstitial.
3680 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223681 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503682 ShowingInterstitialPage() || !delegate_ ||
3683 delegate_->ShouldSuppressDialogs(this) ||
3684 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493685
3686 if (!suppress_this_message) {
3687 std::string accept_lang = GetContentClient()->browser()->
3688 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503689 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493690 dialog_manager_->RunJavaScriptDialog(
palmer4e0ae10d2015-09-03 23:38:413691 this, frame_url, accept_lang, javascript_message_type, message,
[email protected]87de04b02014-04-08 22:14:493692 default_prompt,
palmer4e0ae10d2015-09-03 23:38:413693 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013694 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413695 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493696 &suppress_this_message);
3697 }
3698
3699 if (suppress_this_message) {
3700 // If we are suppressing messages, just reply as if the user immediately
3701 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013702 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3703 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283704 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493705 }
3706
3707 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3708 // http://crbug.com/288961 ). The only safe thing to do here is return.
3709}
3710
3711void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013712 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493713 const base::string16& message,
3714 bool is_reload,
3715 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013716 RenderFrameHostImpl* rfhi =
3717 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493718 if (delegate_)
3719 delegate_->WillRunBeforeUnloadConfirm();
3720
3721 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023722 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3723 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503724 delegate_->ShouldSuppressDialogs(this) ||
3725 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493726 if (suppress_this_message) {
3727 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3728 return;
3729 }
3730
3731 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503732 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493733 dialog_manager_->RunBeforeUnloadDialog(
3734 this, message, is_reload,
3735 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013736 render_frame_host->GetProcess()->GetID(),
3737 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283738 false));
[email protected]87de04b02014-04-08 22:14:493739}
3740
[email protected]a86c0e962013-12-17 17:10:393741WebContents* WebContentsImpl::GetAsWebContents() {
3742 return this;
3743}
3744
[email protected]7912e822014-04-16 02:37:033745bool WebContentsImpl::IsNeverVisible() {
3746 if (!delegate_)
3747 return false;
3748 return delegate_->IsNeverVisible(this);
3749}
3750
[email protected]95640212014-07-26 18:14:303751#if defined(OS_WIN)
3752gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3753 return accessible_parent_;
3754}
3755#endif
3756
[email protected]5a3bdf52012-05-24 15:12:573757RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3758 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323759}
3760
[email protected]8ff00d72012-10-23 19:12:213761RendererPreferences WebContentsImpl::GetRendererPrefs(
3762 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463763 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513764}
3765
[email protected]b172aee2012-04-10 17:05:263766gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173767 if (delegate_)
3768 return delegate_->GetRootWindowResizerRect();
3769 return gfx::Rect();
3770}
3771
[email protected]7a846df2012-09-20 19:17:393772void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273773 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393774 browser_plugin_embedder_.reset();
3775}
3776
[email protected]b172aee2012-04-10 17:05:263777void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443778 // Don't send notifications if we are just creating a swapped-out RVH for
3779 // the opener chain. These won't be used for view-source or WebUI, so it's
3780 // ok to return early.
creiscce56cd2014-09-29 22:45:223781 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443782 return;
3783
[email protected]86f98a22013-03-20 14:35:003784 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313785 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083786
[email protected]8ff00d72012-10-23 19:12:213787 NotificationService::current()->Notify(
3788 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3789 Source<WebContents>(this),
3790 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323791
carlosk795f1b22015-11-06 10:34:133792 // When we're creating views, we're still doing initial setup, so we always
3793 // use the pending Web UI rather than any possibly existing committed one.
3794 if (GetRenderManager()->pending_web_ui())
3795 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
3796
3797 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3798 switches::kEnableBrowserSideNavigation) &&
3799 GetRenderManager()->speculative_web_ui()) {
3800 GetRenderManager()->speculative_web_ui()->RenderViewCreated(
3801 render_view_host);
3802 }
3803
[email protected]6286a372013-10-09 04:03:273804 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333805 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323806 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183807 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583808 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323809 }
[email protected]0666aef2009-05-13 19:48:083810
[email protected]60780f412013-02-25 16:34:103811 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263812
3813 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253814 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323815}
3816
[email protected]b172aee2012-04-10 17:05:263817void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523818 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323819 // Don't notify the world, since this came from a renderer in the
3820 // background.
3821 return;
3822 }
3823
[email protected]da7a7182013-09-06 08:11:113824 notify_disconnection_ = true;
3825 // TODO(avi): Remove. http://crbug.com/170921
3826 NotificationService::current()->Notify(
3827 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3828 Source<WebContents>(this),
3829 NotificationService::NoDetails());
3830
[email protected]be1f56ab2011-12-22 06:55:313831 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233832 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303833
3834 // Restore the focus to the tab (otherwise the focus will be on the top
3835 // window).
[email protected]484ae5912010-09-29 19:16:143836 if (was_crashed && !FocusLocationBarByDefault() &&
3837 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063838 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143839 }
[email protected]32ded2212011-11-10 18:51:433840
[email protected]d8c660432011-12-22 20:51:253841 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323842}
3843
[email protected]ec6a7eb2013-04-22 17:34:223844void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3845 base::TerminationStatus status,
3846 int error_code) {
[email protected]151a63d2011-12-20 22:32:523847 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323848 // The pending page's RenderViewHost is gone.
3849 return;
3850 }
3851
[email protected]2fcdcc32014-03-05 02:14:073852 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3853 // renderer may not have made a clean exit.
3854 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533855 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073856
[email protected]698191dc2014-02-25 01:06:133857 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173858 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133859
[email protected]f738bdcb2014-07-11 20:40:443860 if (delegate_)
3861 delegate_->HideValidationMessage(this);
3862
fdegans6ce28f52015-03-19 12:52:223863 SetIsLoading(false, true, nullptr);
[email protected]420ae012009-04-24 05:16:323864 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233865 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453866
[email protected]960b0372014-05-19 18:01:003867 // Reset the loading progress. TODO(avi): What does it mean to have a
3868 // "renderer crash" when there is more than one renderer process serving a
3869 // webpage? Once this function is called at a more granular frame level, we
3870 // probably will need to more granularly reset the state here.
3871 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003872
[email protected]d8c660432011-12-22 20:51:253873 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273874 observers_,
[email protected]58d5cfe2013-07-10 02:40:523875 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323876}
3877
[email protected]b172aee2012-04-10 17:05:263878void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253879 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063880}
3881
[email protected]b172aee2012-04-10 17:05:263882void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3883 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043884 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:383885 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
3886
creise1d3e5b2014-12-01 18:21:573887 // Ensure that this state update comes from a RenderViewHost that belongs to
3888 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413889 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:573890 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413891 return;
[email protected]420ae012009-04-24 05:16:323892
avi286019ce2015-07-29 01:26:583893 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:323894 // when the user is scrolling and entering form data, as well as when we're
3895 // leaving a page, in which case our state may have already been moved to
3896 // the next page. The navigation controller will look up the appropriate
3897 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:583898 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:113899 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:583900 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:113901 if (!entry)
[email protected]420ae012009-04-24 05:16:323902 return;
[email protected]420ae012009-04-24 05:16:323903
creisd63f6c4a2015-11-06 19:05:533904 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
3905 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())->nav_entry_id());
3906
3907 DCHECK_EQ(entry, new_entry);
3908
[email protected]691aa2f2013-05-28 22:52:043909 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323910 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043911 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:113912 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:323913}
3914
sky8b00392d2015-01-10 00:30:283915void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3916 const GURL& url) {
3917 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3918 // If we're fullscreen only update the url if it's from the fullscreen
3919 // renderer.
3920 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:443921 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:283922 return;
3923 }
[email protected]6934a702011-12-20 00:04:513924 if (delegate_)
avi450ce00e2014-09-24 01:58:523925 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323926}
3927
[email protected]b172aee2012-04-10 17:05:263928void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103929#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293930 // The UI may be in an event-tracking loop, such as between the
3931 // mouse-down and mouse-up in text selection or a button click.
3932 // Defer the close until after tracking is complete, so that we
3933 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293934 // TODO(shess): This could get more fine-grained. For instance,
3935 // closing a tab in another window while selecting text in the
3936 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103937 if (view_->IsEventTracking()) {
3938 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293939 return;
3940 }
[email protected]60780f412013-02-25 16:34:103941#endif
[email protected]07707302009-11-06 00:50:293942
[email protected]420ae012009-04-24 05:16:323943 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523944 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513945 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323946}
3947
[email protected]66bbadaf2014-03-28 16:25:543948void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573949 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3950 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573951}
3952
[email protected]b172aee2012-04-10 17:05:263953void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513954 if (delegate_ && delegate_->IsPopupOrPanel(this))
3955 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323956}
3957
fdegansa696e5112015-04-17 01:57:593958void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:093959 bool to_different_document) {
fdegans6ce28f52015-03-19 12:52:223960 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:083961
3962 // Notify accessibility that the user is navigating away from the
3963 // current document.
3964 //
3965 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:083966 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:593967 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:083968 if (manager)
3969 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:323970}
3971
fdegansc73eec22015-03-19 14:47:543972void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:323973 scoped_ptr<LoadNotificationDetails> details;
3974
[email protected]9595fd82013-04-19 21:28:493975 // Use the last committed entry rather than the active one, in case a
3976 // pending entry has been created.
3977 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203978 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493979
[email protected]420ae012009-04-24 05:16:323980 // An entry may not exist for a stop when loading an initial blank page or
3981 // if an iframe injected by script into a blank page finishes loading.
3982 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203983 base::TimeDelta elapsed =
3984 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323985
3986 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513987 entry->GetVirtualURL(),
3988 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323989 elapsed,
3990 &controller_,
3991 controller_.GetCurrentEntryIndex()));
3992 }
3993
fdegans6ce28f52015-03-19 12:52:223994 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:323995}
3996
fdegansa696e5112015-04-17 01:57:593997void WebContentsImpl::DidChangeLoadProgress() {
3998 double load_progress = frame_tree_.load_progress();
3999
4000 // The delegate is notified immediately for the first and last updates. Also,
4001 // since the message loop may be pretty busy when a page is loaded, it might
4002 // not execute a posted task in a timely manner so the progress report is sent
4003 // immediately if enough time has passed.
4004 base::TimeDelta min_delay =
4005 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4006 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4007 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4008
4009 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4010 // If there is a pending task to send progress, it is now obsolete.
4011 loading_weak_factory_.InvalidateWeakPtrs();
4012
4013 // Notify the load progress change.
4014 SendChangeLoadProgress();
4015
4016 // Clean-up the states if needed.
4017 if (load_progress == 1.0)
4018 ResetLoadProgressState();
4019 return;
4020 }
4021
4022 if (loading_weak_factory_.HasWeakPtrs())
4023 return;
4024
skyostil95082a62015-06-05 19:53:074025 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4026 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4027 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594028 min_delay);
4029}
4030
[email protected]b172aee2012-04-10 17:05:264031void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164032 controller_.DiscardNonCommittedEntries();
4033
4034 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214035 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164036}
4037
[email protected]59167c22013-06-03 18:07:324038void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104039 has_accessed_initial_document_ = true;
4040
[email protected]d1371bf8e2014-04-19 03:26:244041 // We may have left a failed browser-initiated navigation in the address bar
4042 // to let the user edit it and try again. Clear it now that content might
4043 // show up underneath it.
4044 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454045 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244046
[email protected]59167c22013-06-03 18:07:324047 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504048 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324049}
4050
alexmosbe2f4c32015-03-10 02:30:234051void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4052 const std::string& name) {
4053 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4054 FrameNameChanged(render_frame_host, name));
4055}
4056
[email protected]39f2f9252014-05-03 00:54:014057void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294058 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094059 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294060 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094061
4062 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214063 NotificationService::current()->Notify(
4064 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4065 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294066 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084067}
4068
creis8eb8ef22015-11-04 22:51:384069void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4070 const PageState& page_state) {
4071 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4072
4073 // The state update affects the last NavigationEntry associated with the given
4074 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4075 // in the case of an UpdateState from a frame being swapped out). We track
4076 // which entry this is in the RenderFrameHost's nav_entry_id.
4077 RenderFrameHostImpl* rfhi =
4078 static_cast<RenderFrameHostImpl*>(render_frame_host);
4079 NavigationEntryImpl* entry =
4080 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4081 if (!entry)
4082 return;
4083
4084 FrameNavigationEntry* frame_entry =
4085 entry->GetFrameEntry(rfhi->frame_tree_node());
4086 if (!frame_entry)
4087 return;
4088
4089 CHECK_EQ(frame_entry->site_instance(), rfhi->GetSiteInstance());
4090 if (page_state == frame_entry->page_state())
4091 return; // Nothing to update.
4092
4093 frame_entry->set_page_state(page_state);
4094 controller_.NotifyEntryChanged(entry);
4095}
4096
[email protected]ef3adfc2014-05-11 00:04:544097void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
4098 int32 page_id,
4099 const base::string16& title,
4100 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544101 // If we have a title, that's a pretty good indication that we've started
4102 // getting useful data.
4103 SetNotWaitingForResponse();
4104
4105 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584106 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544107 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584108 render_frame_host->GetSiteInstance(), page_id);
4109
creisd63f6c4a2015-11-06 19:05:534110 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4111 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
4112 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544113
4114 // We can handle title updates when we don't have an entry in
4115 // UpdateTitleForEntry, but only if the update is from the current RVH.
4116 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584117 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544118 return;
4119
4120 // TODO(evan): make use of title_direction.
4121 // http://code.google.com/p/chromium/issues/detail?id=27094
4122 if (!UpdateTitleForEntry(entry, title))
4123 return;
4124
4125 // Broadcast notifications when the UI should be updated.
4126 if (entry == controller_.GetEntryAtOffset(0))
4127 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4128}
4129
4130void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4131 const std::string& encoding) {
4132 SetEncoding(encoding);
4133}
4134
[email protected]39f2f9252014-05-03 00:54:014135void WebContentsImpl::DocumentAvailableInMainFrame(
4136 RenderViewHost* render_view_host) {
4137 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4138 DocumentAvailableInMainFrame());
4139}
naskoc0fceff2015-04-30 15:53:524140
[email protected]e1c3a552012-05-04 20:51:324141void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4142 // Tell the active RenderViewHost to run unload handlers and close, as long
4143 // as the request came from a RenderViewHost in the same BrowsingInstance.
4144 // In most cases, we receive this from a swapped out RenderViewHost.
4145 // It is possible to receive it from one that has just been swapped in,
4146 // in which case we might as well deliver the message anyway.
4147 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524148 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324149}
4150
alexmose7da5a12015-04-09 02:22:164151bool WebContentsImpl::ShouldRouteMessageEvent(
4152 RenderFrameHost* target_rfh,
4153 SiteInstance* source_site_instance) const {
4154 // Allow the message if this WebContents is dedicated to a browser plugin
4155 // guest.
[email protected]0eba810b2012-10-18 03:19:364156 // Note: This check means that an embedder could theoretically receive a
4157 // postMessage from anyone (not just its own guests). However, this is
4158 // probably not a risk for apps since other pages won't have references
4159 // to App windows.
alexmose7da5a12015-04-09 02:22:164160 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4161}
[email protected]f546640b2012-05-15 00:03:494162
alexmos58729042015-06-18 23:20:004163void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164164 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4165 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494166
alexmose7da5a12015-04-09 02:22:164167 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144168 // If this message is going to outer WebContents from inner WebContents,
4169 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4170 // already created a RenderFrameProxyHost for that purpose.
4171 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084172 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144173 return;
4174 }
4175
alexmose7da5a12015-04-09 02:22:164176 if (GetBrowserPluginGuest()) {
nasko5fb985b2015-08-20 17:28:164177 // We create a swapped out RenderView or RenderFrameProxyHost for the
4178 // embedder in the guest's render process but we intentionally do not
4179 // expose the embedder's opener chain to it.
4180 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
4181 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4182 GetSiteInstance());
4183 } else {
4184 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
4185 }
[email protected]f546640b2012-05-15 00:03:494186 } else {
alexmos58729042015-06-18 23:20:004187 RenderFrameHostImpl* source_rfhi =
4188 static_cast<RenderFrameHostImpl*>(source_rfh);
4189 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394190 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494191 }
4192 }
[email protected]f546640b2012-05-15 00:03:494193}
4194
[email protected]a796f202012-05-30 14:14:254195bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264196 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254197 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264198 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254199 if (!delegate_)
4200 return false;
4201 return delegate_->AddMessageToConsole(this, level, message, line_no,
4202 source_id);
4203}
4204
[email protected]0eba810b2012-10-18 03:19:364205int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214206 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294207 int render_view_routing_id = MSG_ROUTING_NONE;
nickac60e75472015-07-31 00:44:354208 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064209 GetRenderManager()->CreateRenderFrameProxy(instance);
4210 } else {
4211 GetRenderManager()->CreateRenderFrame(
carlosk795f1b22015-11-06 10:34:134212 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN,
nasko4c0feb62015-06-05 18:37:064213 &render_view_routing_id);
4214 }
carlosk37f793792014-11-27 15:08:294215 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364216}
4217
[email protected]b172aee2012-04-10 17:05:264218void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274219 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254220 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224221
[email protected]ea114722012-03-12 01:11:254222 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174223 if (rdh) // NULL in unittests.
4224 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254225}
4226
dominickn2dd142dd2015-10-29 05:30:504227void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) {
4228 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4229 DidGetUserInteraction(type));
4230}
4231
[email protected]b172aee2012-04-10 17:05:264232void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444233 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254234 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444235}
4236
creiscce56cd2014-09-29 22:45:224237void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154238 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224239 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154240 return;
4241
creiscce56cd2014-09-29 22:45:224242 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4243 RenderFrameHostImpl* rfhi =
4244 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584245
[email protected]e5fc1632011-08-08 07:51:534246 // Ignore renderer unresponsive event if debugger is attached to the tab
4247 // since the event may be a result of the renderer sitting on a breakpoint.
4248 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364249 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534250 return;
4251
clamy226727e2015-06-29 10:28:474252 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224253 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324254 // Hang occurred while firing the beforeunload/unload handler.
4255 // Pretend the handler fired so tab closing continues as if it had.
clamyc0a278672015-03-24 17:08:554256 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324257
[email protected]fa944cb82013-11-15 17:51:214258 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324259 return;
4260
4261 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564262 // nothing we can do to recover. If the hang is in the beforeunload handler,
4263 // pretend the beforeunload listeners have all fired and allow the delegate
4264 // to continue closing; the user will not have the option of cancelling the
4265 // close. Otherwise, pretend the unload listeners have all fired and close
4266 // the tab.
4267 bool close = true;
clamy226727e2015-06-29 10:28:474268 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564269 delegate_->BeforeUnloadFired(this, true, &close);
4270 }
4271 if (close)
creiscce56cd2014-09-29 22:45:224272 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324273 return;
4274 }
4275
creisc014b402015-04-23 16:41:454276 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474277 return;
4278
[email protected]6934a702011-12-20 00:04:514279 if (delegate_)
4280 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324281}
4282
[email protected]b172aee2012-04-10 17:05:264283void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514284 if (delegate_)
4285 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324286}
4287
[email protected]b172aee2012-04-10 17:05:264288void WebContentsImpl::LoadStateChanged(
4289 const GURL& url,
4290 const net::LoadStateWithParam& load_state,
4291 uint64 upload_position,
4292 uint64 upload_size) {
erikchen174b78c62015-03-11 22:02:544293 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4294 // is fixed.
4295 tracked_objects::ScopedTracker tracking_profile1(
4296 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4297 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324298 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564299 upload_position_ = upload_position;
4300 upload_size_ = upload_size;
rsleevi24f64dc22015-08-07 21:39:214301 load_state_host_ = url_formatter::IDNToUnicode(
4302 url.host(),
4303 GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214304 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324305 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464306 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224307 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4308 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464309 }
[email protected]420ae012009-04-24 05:16:324310}
4311
[email protected]b172aee2012-04-10 17:05:264312void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554313 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324314 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124315 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4316 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514317 if (delegate_)
4318 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094319 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324320}
4321
[email protected]58d5cfe2013-07-10 02:40:524322void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544323 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234324 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224325 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544326}
4327
[email protected]b172aee2012-04-10 17:05:264328void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104329 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214330 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264331 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4332 // here during container initialization and normal window size will be set
4333 // later. In case of tab duplication this resizing to 0x0 prevents setting
4334 // normal size later so just ignore it.
4335 if (!size.IsEmpty())
4336 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324337}
4338
[email protected]af905902013-10-01 21:38:514339void WebContentsImpl::CancelModalDialogsForRenderManager() {
4340 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544341 // deferrer would prevent us from swapping out. We also clear the state
4342 // because this is a cross-process navigation, which means that it's a new
4343 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174344 //
4345 // Note that we don't bother telling browser_plugin_embedder_ because the
4346 // cross-process navigation will either destroy the browser plugins or not
4347 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514348 if (dialog_manager_)
avi2460c762015-04-17 15:21:544349 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514350}
4351
[email protected]02d7b6e2014-06-24 21:01:504352void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4353 RenderFrameHost* new_host,
4354 bool is_main_frame) {
4355 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054356 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504357 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084358
[email protected]02d7b6e2014-06-24 21:01:504359 // Make sure the visible RVH reflects the new delegate's preferences.
4360 if (delegate_)
4361 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394362
[email protected]02d7b6e2014-06-24 21:01:504363 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4364 }
4365
4366 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544367}
4368
naskof5940b9f2015-03-02 23:04:054369void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4370 RenderViewHost* old_host,
4371 RenderViewHost* new_host) {
4372 NotifyViewSwapped(old_host, new_host);
4373}
4374
[email protected]b172aee2012-04-10 17:05:264375NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194376 return GetController();
[email protected]3a3d47472010-07-15 21:03:544377}
4378
carlosk795f1b22015-11-06 10:34:134379scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
carlosk37f793792014-11-27 15:08:294380 const GURL& url) {
dbeama1b926a2015-08-31 23:17:514381 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(
4382 url, std::string())));
[email protected]420ae012009-04-24 05:16:324383}
4384
[email protected]10f417c52011-12-28 21:04:234385NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264386 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324387 return controller_.GetLastCommittedEntry();
4388}
4389
lfgbede6392015-09-11 21:54:064390void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4391 RenderViewHost* render_view_host) {
4392 RenderWidgetHostViewBase* rwh_view = nullptr;
lazyboy6ec48b2a2015-06-29 15:18:144393 bool is_guest_in_site_per_process =
4394 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084395 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lfgbede6392015-09-11 21:54:064396 if (is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164397 RenderWidgetHostViewChildFrame* rwh_view_child =
avif9ab5d942015-10-15 14:05:444398 new RenderWidgetHostViewChildFrame(render_view_host->GetWidget());
[email protected]bffc8302014-01-23 20:52:164399 rwh_view = rwh_view_child;
4400 } else {
avif9ab5d942015-10-15 14:05:444401 rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]bffc8302014-01-23 20:52:164402 }
[email protected]1a98a932009-11-17 00:12:524403
[email protected]420ae012009-04-24 05:16:324404 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444405 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214406 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064407}
4408
4409bool WebContentsImpl::CreateRenderViewForRenderManager(
4410 RenderViewHost* render_view_host,
4411 int opener_frame_routing_id,
4412 int proxy_routing_id,
4413 const FrameReplicationState& replicated_frame_state) {
4414 TRACE_EVENT0("browser,navigation",
4415 "WebContentsImpl::CreateRenderViewForRenderManager");
4416
4417 if (proxy_routing_id == MSG_ROUTING_NONE)
4418 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324419
[email protected]74ce1ad2011-12-16 21:51:464420 // Make sure we use the correct starting page_id in the new RenderView.
4421 UpdateMaxPageIDIfNecessary(render_view_host);
4422 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584423 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464424
alexmos5ac402d2015-07-09 07:51:104425 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4426 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4427 max_page_id, replicated_frame_state,
4428 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524429 return false;
[email protected]14392a52012-05-02 20:28:444430 }
[email protected]a4127722011-04-27 23:13:524431
avi2b177592014-12-10 02:08:024432 SetHistoryOffsetAndLengthForView(render_view_host,
4433 controller_.GetLastCommittedEntryIndex(),
4434 controller_.GetEntryCount());
4435
[email protected]a220b5932013-09-21 03:47:444436#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504437 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4438 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444439 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444440 if (rwh_view) {
4441 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4442 render_widget_host->WasResized();
4443 }
[email protected]f8233cc2011-05-31 20:24:504444#endif
4445
[email protected]420ae012009-04-24 05:16:324446 return true;
4447}
4448
[email protected]82307f6b2014-08-07 03:30:124449bool WebContentsImpl::CreateRenderFrameForRenderManager(
4450 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044451 int proxy_routing_id,
4452 int opener_routing_id,
japhete6adf142014-10-31 00:01:494453 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044454 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434455 TRACE_EVENT0("browser,navigation",
4456 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124457
4458 RenderFrameHostImpl* rfh =
4459 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044460 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4461 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124462 return false;
4463
4464 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4465 // RenderFrameHost will have to be associated with the appropriate
4466 // RenderWidgetHostView or a new one should be created here.
4467
4468 return true;
4469}
4470
[email protected]7d244f12013-08-22 21:41:514471#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454472
[email protected]155c7f22013-12-09 17:07:184473base::android::ScopedJavaLocalRef<jobject>
4474WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564476 return GetWebContentsAndroid()->GetJavaObject();
4477}
[email protected]155c7f22013-12-09 17:07:184478
[email protected]0e813a52014-08-13 10:34:564479WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184480 WebContentsAndroid* web_contents_android =
4481 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4482 if (!web_contents_android) {
4483 web_contents_android = new WebContentsAndroid(this);
4484 SetUserData(kWebContentsAndroidKey, web_contents_android);
4485 }
[email protected]0e813a52014-08-13 10:34:564486 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184487}
4488
[email protected]7d244f12013-08-22 21:41:514489bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064490 return CreateRenderViewForRenderManager(
4491 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064492 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514493}
[email protected]fc2b46b2014-05-03 16:33:454494
4495#elif defined(OS_MACOSX)
4496
[email protected]75f4df72014-07-16 22:39:424497void WebContentsImpl::SetAllowOtherViews(bool allow) {
4498 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454499}
4500
[email protected]75f4df72014-07-16 22:39:424501bool WebContentsImpl::GetAllowOtherViews() {
4502 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454503}
4504
[email protected]7d244f12013-08-22 21:41:514505#endif
4506
[email protected]6fba26d2014-04-29 09:38:284507void WebContentsImpl::OnDialogClosed(int render_process_id,
4508 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264509 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494510 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264511 bool success,
[email protected]fcf75d42013-12-03 20:11:264512 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284513 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4514 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494515 last_dialog_suppressed_ = dialog_was_suppressed;
4516
[email protected]beb440c2009-11-06 04:08:544517 if (is_showing_before_unload_dialog_ && !success) {
4518 // If a beforeunload dialog is canceled, we need to stop the throbber from
4519 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284520 if (rfh)
fdegansc73eec22015-03-19 14:47:544521 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354522 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104523
[email protected]6d65a462013-06-21 21:29:124524 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4525 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544526 }
[email protected]87de04b02014-04-08 22:14:494527
[email protected]beb440c2009-11-06 04:08:544528 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284529 if (rfh) {
4530 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4531 dialog_was_suppressed);
4532 } else {
4533 // Don't leak the sync IPC reply if the RFH or process is gone.
4534 delete reply_msg;
4535 }
[email protected]beb440c2009-11-06 04:08:544536}
4537
[email protected]b172aee2012-04-10 17:05:264538void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544539 if (encoding == last_reported_encoding_)
4540 return;
4541 last_reported_encoding_ = encoding;
4542
4543 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124544 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104545}
[email protected]f45d2a72010-03-08 23:28:354546
[email protected]1ac10dca2013-08-20 20:47:044547bool WebContentsImpl::IsHidden() {
4548 return capturer_count_ == 0 && !should_normally_be_visible_;
4549}
4550
lazyboy6ec48b2a2015-06-29 15:18:144551int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4552 if (node_ && node_->outer_web_contents())
4553 return node_->outer_contents_frame_tree_node_id();
4554
4555 return FrameTreeNode::kFrameTreeNodeInvalidID;
4556}
4557
[email protected]b0936d22013-11-28 06:47:364558RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214559 return frame_tree_.root()->render_manager();
4560}
4561
lazyboy8e16ddfd2015-09-28 03:41:564562WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4563 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4564 if (node_)
4565 return node_->outer_web_contents();
4566 } else {
4567 if (GetBrowserPluginGuest())
4568 return GetBrowserPluginGuest()->embedder_web_contents();
4569 }
4570 return nullptr;
4571}
4572
[email protected]f8497342013-02-05 22:15:024573BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394574 return browser_plugin_guest_.get();
4575}
4576
[email protected]738f57a2013-06-29 21:06:544577void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4578 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144579 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544580 browser_plugin_guest_.reset(guest);
4581}
4582
[email protected]f8497342013-02-05 22:15:024583BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394584 return browser_plugin_embedder_.get();
4585}
[email protected]8ff00d72012-10-23 19:12:214586
fsamuel60b42282015-03-10 03:29:144587void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4588 if (browser_plugin_embedder_)
4589 return;
4590 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4591}
4592
[email protected]d9030b82013-07-19 08:26:064593void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194594 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304595 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4596 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4597 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064598}
4599
4600void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304601 active_audio_players_.clear();
4602 active_video_players_.clear();
4603 audio_power_save_blocker_.reset();
4604 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064605}
4606
[email protected]fc2b46b2014-05-03 16:33:454607gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214608 gfx::Size size;
4609 if (delegate_)
4610 size = delegate_->GetSizeForNewRenderView(this);
4611 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454612 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214613 return size;
4614}
4615
[email protected]ae7eeda2014-07-04 01:53:264616void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4617 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024618 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554619}
4620
[email protected]222f5822014-02-05 23:40:494621void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4622 if (!delegate_)
4623 return;
4624 const gfx::Size new_size = GetPreferredSize();
4625 if (new_size != old_size)
4626 delegate_->UpdatePreferredSize(this, new_size);
4627}
4628
dalecurtisbc6572e12014-09-12 19:22:304629void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4630 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114631 if (!HasValidFrameSource())
4632 return;
4633
dalecurtisbc6572e12014-09-12 19:22:304634 const uintptr_t key =
4635 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4636 DCHECK(std::find((*player_map)[key].begin(),
4637 (*player_map)[key].end(),
4638 player_cookie) == (*player_map)[key].end());
4639 (*player_map)[key].push_back(player_cookie);
4640}
4641
4642void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4643 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114644 if (!HasValidFrameSource())
4645 return;
4646
dalecurtisbc6572e12014-09-12 19:22:304647 const uintptr_t key =
4648 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4649 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4650 if (it == player_map->end())
4651 return;
4652
4653 // Remove the player.
4654 PlayerList::iterator player_it =
4655 std::find(it->second.begin(), it->second.end(), player_cookie);
4656 if (player_it != it->second.end())
4657 it->second.erase(player_it);
4658
4659 // If there are no players left, remove the map entry.
4660 if (it->second.empty())
4661 player_map->erase(it);
4662}
4663
4664void WebContentsImpl::RemoveAllMediaPlayerEntries(
4665 RenderFrameHost* render_frame_host,
4666 ActiveMediaPlayerMap* player_map) {
4667 ActiveMediaPlayerMap::iterator it =
4668 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4669 if (it == player_map->end())
4670 return;
4671 player_map->erase(it);
4672}
4673
dbeama1b926a2015-08-31 23:17:514674WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4675 const std::string& frame_name) {
4676 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4677 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4678 CreateWebUIControllerForURL(web_ui, url);
4679 if (controller) {
4680 web_ui->AddMessageHandler(new GenericHandler());
4681 web_ui->SetController(controller);
4682 return web_ui;
4683 }
4684
4685 delete web_ui;
4686 return NULL;
4687}
4688
[email protected]34ff1cfc2014-08-20 06:16:054689void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4690 force_disable_overscroll_content_ = force_disable;
4691 if (view_)
4692 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4693}
4694
[email protected]8ff00d72012-10-23 19:12:214695} // namespace content