blob: bf77e42fb435bffe5b36ef9f76801feb5499fcd0 [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"
[email protected]6d636e62013-07-31 03:15:5611#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2013#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2214#include "base/profiler/scoped_tracker.h"
[email protected]348fbaac2013-06-11 06:31:5115#include "base/strings/string16.h"
16#include "base/strings/string_number_conversions.h"
17#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3719#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4220#include "base/trace_event/trace_event.h"
[email protected]95640212014-07-26 18:14:3021#include "content/browser/accessibility/accessibility_mode_helper.h"
22#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1823#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3924#include "content/browser/browser_plugin/browser_plugin_embedder.h"
25#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5926#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1827#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4128#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0429#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4630#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1231#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1632#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1633#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4034#include "content/browser/frame_host/interstitial_page_impl.h"
35#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0136#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1837#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1638#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5739#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0540#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4441#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4042#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3043#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5244#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5345#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0946#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0647#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3048#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5049#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3250#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5051#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4852#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0953#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3354#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1155#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5856#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0357#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5658#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1459#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4260#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4461#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0262#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1763#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5164#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0265#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3666#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1167#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2868#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4469#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3670#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1771#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1472#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4673#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1574#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0075#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2776#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0077#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3778#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1479#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3080#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3281#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0982#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3483#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3884#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4285#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2586#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2187#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4888#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5489#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4990#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2091#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0392#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5793#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0594#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1695#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2996#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5397#include "net/http/http_cache.h"
98#include "net/http/http_transaction_factory.h"
99#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34100#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56101#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01102#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41103#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52104#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31105
qinmin58567c82015-01-07 21:00:20106#if defined(ENABLE_BROWSER_CDMS)
107#include "content/browser/media/media_web_contents_observer.h"
108#endif
109
[email protected]583418cc2013-01-17 14:01:10110#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40111#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10112#include "content/browser/android/date_time_chooser_android.h"
timavf6f6f692015-03-04 02:19:37113#include "content/browser/android/media_players_observer.h"
[email protected]fc2b46b2014-05-03 16:33:45114#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18115#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10116#endif
117
[email protected]f66df822012-05-18 16:52:17118#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50119#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57120#endif
[email protected]3e45ba92009-02-20 21:09:00121
[email protected]8ff00d72012-10-23 19:12:21122namespace content {
[email protected]420ae012009-04-24 05:16:32123namespace {
124
[email protected]960b0372014-05-19 18:01:00125const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41126const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05127
[email protected]155c7f22013-12-09 17:07:18128#if defined(OS_ANDROID)
129const char kWebContentsAndroidKey[] = "web_contents_android";
130#endif // OS_ANDROID
131
[email protected]e4abd3b42013-11-12 18:28:47132base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46133g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
134
thestigc4cac8f2014-09-04 21:17:50135static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39136 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29137 bool is_favicon,
pkotwiczfd773552015-03-16 00:29:14138 uint32_t max_bitmap_size,
139 bool bypass_cache) {
[email protected]41225fe2013-03-29 05:32:02140 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58141 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02142 ++g_next_image_download_id,
143 url,
144 is_favicon,
pkotwiczfd773552015-03-16 00:29:14145 max_bitmap_size,
146 bypass_cache));
[email protected]41225fe2013-03-29 05:32:02147 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39148}
149
[email protected]8bfc8272013-09-09 20:10:53150void NotifyCacheOnIO(
151 scoped_refptr<net::URLRequestContextGetter> request_context,
152 const GURL& url,
153 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58154 net::HttpCache* cache = request_context->GetURLRequestContext()->
155 http_transaction_factory()->GetCache();
156 if (cache)
157 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53158}
159
[email protected]9b159a52013-10-03 17:24:55160// Helper function for retrieving all the sites in a frame tree.
161bool CollectSites(BrowserContext* context,
162 std::set<GURL>* sites,
163 FrameTreeNode* node) {
164 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
165 return true;
166}
167
fdegans4a49ce932015-03-12 17:11:37168// Helper function used with FrameTree::ForEach() for retrieving the total
169// loading progress and number of frames in a frame tree.
170bool CollectLoadProgress(double* progress,
171 int* frame_count,
172 FrameTreeNode* node) {
173 // Ignore the current frame if it has not started loading.
174 double frame_progress = node->GetLoadingProgress();
175 if (frame_progress == RenderFrameHostImpl::kLoadingProgressNotStarted)
176 return true;
177
178 // Collect progress.
179 *progress += node->GetLoadingProgress();
180 (*frame_count)++;
181 return true;
182}
183
184// Helper function used with FrameTree::ForEach() to check if at least one of
185// the nodes is loading.
186bool IsNodeLoading(bool* is_loading, FrameTreeNode* node) {
187 if (node->IsLoading()) {
188 // There is at least one node loading, so abort traversal.
189 *is_loading = true;
190 return false;
191 }
192 return true;
193}
194
195// Helper function used with FrameTree::ForEach() to reset the load progress.
196bool ResetLoadProgress(FrameTreeNode* node) {
197 node->current_frame_host()->set_loading_progress(
198 RenderFrameHostImpl::kLoadingProgressNotStarted);
199 return true;
200}
201
[email protected]a86c0e962013-12-17 17:10:39202bool ForEachFrameInternal(
203 const base::Callback<void(RenderFrameHost*)>& on_frame,
204 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41205 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39206 return true;
207}
208
[email protected]95640212014-07-26 18:14:30209bool ForEachPendingFrameInternal(
210 const base::Callback<void(RenderFrameHost*)>& on_frame,
211 FrameTreeNode* node) {
212 RenderFrameHost* pending_frame_host =
213 node->render_manager()->pending_frame_host();
214 if (pending_frame_host)
215 on_frame.Run(pending_frame_host);
216 return true;
217}
218
[email protected]a86c0e962013-12-17 17:10:39219void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
220 IPC::Message* message_copy = new IPC::Message(*message);
221 message_copy->set_routing_id(rfh->GetRoutingID());
222 rfh->Send(message_copy);
223}
224
[email protected]948481d2014-06-11 18:32:22225void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
226 RenderFrameHost* rfh) {
227 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
228 ->frame_tree_node()
229 ->render_manager()
230 ->GetRenderWidgetHostView();
231 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59232}
233
[email protected]95640212014-07-26 18:14:30234void SetAccessibilityModeOnFrame(AccessibilityMode mode,
235 RenderFrameHost* frame_host) {
236 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
237}
238
fdegans4a49ce932015-03-12 17:11:37239// Returns true if at least one of the nodes in the |frame_tree| is loading.
240bool IsFrameTreeLoading(FrameTree& frame_tree) {
241 bool is_loading = false;
242 frame_tree.ForEach(base::Bind(&IsNodeLoading, &is_loading));
243 return is_loading;
244}
245
[email protected]420ae012009-04-24 05:16:32246} // namespace
247
[email protected]54944cde2012-12-09 09:24:59248WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15249 return WebContentsImpl::CreateWithOpener(
250 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19251}
252
253WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59254 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30255 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59256 WebContentsImpl* new_contents = new WebContentsImpl(
257 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30258
259 for (SessionStorageNamespaceMap::const_iterator it =
260 session_storage_namespace_map.begin();
261 it != session_storage_namespace_map.end();
262 ++it) {
263 new_contents->GetController()
264 .SetSessionStorageNamespace(it->first, it->second.get());
265 }
266
[email protected]54944cde2012-12-09 09:24:59267 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19268 return new_contents;
[email protected]a81343d232011-12-27 07:39:20269}
[email protected]746d3052012-05-22 15:15:47270
nickf9acfbe2014-12-23 19:12:37271void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
272 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46273 g_created_callbacks.Get().push_back(callback);
274}
275
nickf9acfbe2014-12-23 19:12:37276void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
277 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46278 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
279 if (g_created_callbacks.Get().at(i).Equals(callback)) {
280 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
281 return;
282 }
283 }
284}
285
[email protected]299d7f12012-05-23 05:31:15286WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47287 return rvh->GetDelegate()->GetAsWebContents();
288}
289
[email protected]a86c0e962013-12-17 17:10:39290WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
291 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
292 if (!rfh_impl)
293 return NULL;
294 return rfh_impl->delegate()->GetAsWebContents();
295}
296
[email protected]7fff43e2013-05-21 20:21:10297// WebContentsImpl::DestructionObserver ----------------------------------------
298
299class WebContentsImpl::DestructionObserver : public WebContentsObserver {
300 public:
301 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
302 : WebContentsObserver(watched_contents),
303 owner_(owner) {
304 }
305
306 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58307 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58308 owner_->OnWebContentsDestroyed(
309 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10310 }
311
312 private:
313 WebContentsImpl* owner_;
314
315 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
316};
317
[email protected]8ed16472014-04-11 19:02:48318WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
319 int render_frame_id,
320 ColorChooser* chooser,
321 int identifier)
322 : render_process_id(render_process_id),
323 render_frame_id(render_frame_id),
324 chooser(chooser),
325 identifier(identifier) {
326}
327
328WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
329}
330
[email protected]b172aee2012-04-10 17:05:26331// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32332
blundellc57b93f2014-10-29 13:19:57333WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
334 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42335 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22336 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57337 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44338 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49339 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08340#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41341 accessible_parent_(NULL),
342#endif
[email protected]6ea6bdf2013-12-06 13:35:01343 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57344 this,
345 this,
346 this,
347 this),
[email protected]d5f942ba2008-09-26 19:30:34348 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03349 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23350 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
351 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34352 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26353 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00354 loading_total_progress_(0.0),
[email protected]094e5b22009-09-25 04:23:56355 upload_size_(0),
356 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47357 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10358 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28359 theme_color_(SK_ColorTRANSPARENT),
360 last_sent_theme_color_(SK_ColorTRANSPARENT),
[email protected]54597982013-02-06 01:59:55361 capturer_count_(0),
362 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57363 is_being_destroyed_(false),
364 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15365 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01366 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02367 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38368 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21369 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
370 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44371 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55372 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42373 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03374 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49375 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05376 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30377 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57378 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30379 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30380 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddyaae039a2014-11-21 17:39:50381 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46382 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55383 frame_tree_.SetFrameRemoveListener(
384 base::Bind(&WebContentsImpl::OnFrameRemoved,
385 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20386#if defined(ENABLE_BROWSER_CDMS)
387 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
388#endif
timavf6f6f692015-03-04 02:19:37389
390#if defined(OS_ANDROID)
391 audio_state_provider_.reset(new MediaPlayersObserver(this));
392#else
393 audio_state_provider_.reset(new AudioStreamMonitor(this));
394#endif
[email protected]332af7732009-03-11 13:21:35395}
initial.commit09911bf2008-07-26 23:55:29396
[email protected]b172aee2012-04-10 17:05:26397WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32398 is_being_destroyed_ = true;
399
[email protected]21b41c7e892014-02-28 01:52:24400 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
401 // shutdown and be deleted as well.
402 frame_tree_.ForEach(
403 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
404
[email protected]d9030b82013-07-19 08:26:06405 ClearAllPowerSaveBlockers();
406
[email protected]b24b68a2012-09-24 21:57:26407 for (std::set<RenderWidgetHostImpl*>::iterator iter =
408 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
409 (*iter)->DetachDelegate();
410 }
411 created_widgets_.clear();
412
[email protected]3ab9cb82011-06-03 18:02:07413 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15414 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11415 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07416
[email protected]8ed16472014-04-11 19:02:48417 if (color_chooser_info_.get())
418 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20419
[email protected]420ae012009-04-24 05:16:32420 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32421
[email protected]ca13a442012-04-17 14:00:12422 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21423 NotificationService::current()->Notify(
424 NOTIFICATION_WEB_CONTENTS_DESTROYED,
425 Source<WebContents>(this),
426 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32427
[email protected]df0c843f2014-05-23 20:37:23428 // Destroy all frame tree nodes except for the root; this notifies observers.
429 frame_tree_.ResetForMainFrameSwap();
430 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59431
[email protected]df0c843f2014-05-23 20:37:23432 // Manually call the observer methods for the root frame tree node.
433 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56434
435 if (root->pending_frame_host())
436 root->pending_frame_host()->SetRenderFrameCreated(false);
437 root->current_frame_host()->SetRenderFrameCreated(false);
[email protected]f273ee52013-10-18 16:05:27438
naskoa83483fb2015-02-27 16:57:10439 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
440 FrameDeleted(root->current_frame_host()));
441
[email protected]df0c843f2014-05-23 20:37:23442 if (root->pending_render_view_host()) {
443 FOR_EACH_OBSERVER(WebContentsObserver,
444 observers_,
445 RenderViewDeleted(root->pending_render_view_host()));
446 }
[email protected]c06c58c2014-03-12 20:31:59447
[email protected]f273ee52013-10-18 16:05:27448 FOR_EACH_OBSERVER(WebContentsObserver,
449 observers_,
[email protected]df0c843f2014-05-23 20:37:23450 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27451
[email protected]2db9bd72012-04-13 20:20:56452 FOR_EACH_OBSERVER(WebContentsObserver,
453 observers_,
[email protected]12a46832014-05-09 13:35:58454 WebContentsDestroyed());
455
456 FOR_EACH_OBSERVER(WebContentsObserver,
457 observers_,
458 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08459
[email protected]6934a702011-12-20 00:04:51460 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10461
462 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
463 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42464}
465
[email protected]d1198fd2012-08-13 22:50:19466WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59467 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19468 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03469 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59470 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06471 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19472
[email protected]4858e432014-06-23 18:14:17473 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06474 // This makes |new_contents| act as a guest.
475 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16476 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06477 // We are instantiating a WebContents for browser plugin. Set its subframe
478 // bit to true.
479 new_contents->is_subframe_ = true;
480 }
[email protected]54944cde2012-12-09 09:24:59481 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19482 return new_contents;
483}
484
[email protected]95640212014-07-26 18:14:30485// static
486std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
487 std::vector<WebContentsImpl*> result;
488 scoped_ptr<RenderWidgetHostIterator> widgets(
489 RenderWidgetHostImpl::GetRenderWidgetHosts());
490 std::set<WebContentsImpl*> web_contents_set;
491 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
492 if (!rwh->IsRenderView())
493 continue;
494 RenderViewHost* rvh = RenderViewHost::From(rwh);
495 if (!rvh)
496 continue;
497 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
498 if (!web_contents)
499 continue;
500 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
501 if (web_contents_set.find(wci) == web_contents_set.end()) {
502 web_contents_set.insert(wci);
503 result.push_back(wci);
504 }
505 }
506 return result;
507}
508
[email protected]b0936d22013-11-28 06:47:36509RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21510 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28511}
512
[email protected]7bb761892012-07-20 09:32:47513bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
514 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44515 return OnMessageReceived(render_view_host, NULL, message);
516}
517
518bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
519 RenderFrameHost* render_frame_host,
520 const IPC::Message& message) {
521 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56522 if (GetWebUI() &&
523 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17524 return true;
[email protected]d2353452012-01-19 19:53:56525 }
[email protected]f82d57b52011-04-27 19:13:17526
danakj4ef352d2015-03-09 17:45:39527 ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25528 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33529 if (render_frame_host) {
530 while ((observer = it.GetNext()) != NULL)
531 if (observer->OnMessageReceived(message, render_frame_host))
532 return true;
533 } else {
534 while ((observer = it.GetNext()) != NULL)
535 if (observer->OnMessageReceived(message))
536 return true;
537 }
[email protected]403415a2011-01-10 18:57:53538
[email protected]1d62cf72014-02-07 21:31:57539 // Message handlers should be aware of which
540 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
541 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02542 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57543 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02544 else
[email protected]1d62cf72014-02-07 21:31:57545 render_view_message_source_ = render_view_host;
546
[email protected]724159a2010-12-30 01:11:18547 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33548 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40549 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
550 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05551 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
552 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48553 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
554 OnDocumentLoadedInFrame)
555 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00556 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
557 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
558 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
559 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48560 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
561 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
562 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
563 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19564 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
565 OnMediaPlayingNotification)
566 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
567 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11568 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
569 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18570 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
571 OnDidLoadResourceFromMemoryCache)
572 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
573 OnDidDisplayInsecureContent)
574 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
575 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25576 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26577 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21578 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20579 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
580 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20581 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
582 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16583 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10584 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50585 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50586#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42587 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
588 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50589 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
590 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55591 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40592 OnBrowserPluginMessage(render_frame_host,
593 message))
thestigc4cac8f2014-09-04 21:17:50594#endif
[email protected]41225fe2013-03-29 05:32:02595 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
596 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07597 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
598 OnShowValidationMessage)
599 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
600 OnHideValidationMessage)
601 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
602 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48603#if defined(OS_ANDROID)
604 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
605 OnFindMatchRectsReply)
606 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
607 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48608#endif
[email protected]724159a2010-12-30 01:11:18609 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33610 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44611 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57612 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18613
[email protected]724159a2010-12-30 01:11:18614 return handled;
615}
616
nasko907fcb62015-01-28 04:24:11617bool WebContentsImpl::HasValidFrameSource() {
618 if (!render_frame_message_source_) {
619 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18620 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
621 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11622 return false;
623 }
624
625 return true;
626}
627
[email protected]b172aee2012-04-10 17:05:26628void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18629 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21630 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43631 if (delegate_)
632 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18633}
634
[email protected]d1198fd2012-08-13 22:50:19635NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56636 return controller_;
637}
638
[email protected]d1198fd2012-08-13 22:50:19639const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56640 return controller_;
641}
642
[email protected]8ff00d72012-10-23 19:12:21643BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55644 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30645}
646
[email protected]b172aee2012-04-10 17:05:26647const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24648 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32649 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51650 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31651}
652
[email protected]a093ce02013-07-22 20:53:14653const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24654 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32655 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24656 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
657}
658
659const GURL& WebContentsImpl::GetLastCommittedURL() const {
660 // We may not have a navigation entry yet.
661 NavigationEntry* entry = controller_.GetLastCommittedEntry();
662 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
663}
664
[email protected]8ff00d72012-10-23 19:12:21665WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31666 return delegate_;
667}
668
[email protected]8ff00d72012-10-23 19:12:21669void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31670 // TODO(cbentzel): remove this debugging code?
671 if (delegate == delegate_)
672 return;
673 if (delegate_)
674 delegate_->Detach(this);
675 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08676 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31677 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08678 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00679 if (view_)
[email protected]e85165c642014-06-10 14:34:31680 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08681 }
[email protected]be1f56ab2011-12-22 06:55:31682}
683
[email protected]8ff00d72012-10-23 19:12:21684RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21685 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41686 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16687}
688
clamydf1975e2015-02-05 19:12:24689RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41690 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16691}
692
[email protected]9c9343b2014-03-08 02:56:07693RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
694 if (!frame_tree_.GetFocusedFrame())
695 return NULL;
696 return frame_tree_.GetFocusedFrame()->current_frame_host();
697}
698
[email protected]a86c0e962013-12-17 17:10:39699void WebContentsImpl::ForEachFrame(
700 const base::Callback<void(RenderFrameHost*)>& on_frame) {
701 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
702}
703
704void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
705 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
706 delete message;
707}
708
[email protected]b172aee2012-04-10 17:05:26709RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21710 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31711}
712
[email protected]6b618e62012-08-16 12:59:18713int WebContentsImpl::GetRoutingID() const {
714 if (!GetRenderViewHost())
715 return MSG_ROUTING_NONE;
716
717 return GetRenderViewHost()->GetRoutingID();
718}
719
[email protected]44470a22013-01-24 01:21:54720int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
721 return fullscreen_widget_routing_id_;
722}
723
[email protected]b172aee2012-04-10 17:05:26724RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21725 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31726}
727
[email protected]4aebbca2013-09-17 22:26:49728RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
729 const {
730 RenderWidgetHost* const widget_host =
731 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
732 GetFullscreenWidgetRoutingID());
733 return widget_host ? widget_host->GetView() : NULL;
734}
735
[email protected]8ff00d72012-10-23 19:12:21736WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31737 return view_.get();
738}
739
yusufod41c5f92015-03-06 00:14:28740SkColor WebContentsImpl::GetThemeColor() const {
741 return theme_color_;
742}
743
[email protected]95640212014-07-26 18:14:30744void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
745 if (mode == accessibility_mode_)
746 return;
747
748 accessibility_mode_ = mode;
749 frame_tree_.ForEach(
750 base::Bind(&ForEachFrameInternal,
751 base::Bind(&SetAccessibilityModeOnFrame, mode)));
752 frame_tree_.ForEach(
753 base::Bind(&ForEachPendingFrameInternal,
754 base::Bind(&SetAccessibilityModeOnFrame, mode)));
755}
756
757void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50758 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30759}
760
761void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50762 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30763}
764
zhenw1f790352014-10-30 00:06:04765void WebContentsImpl::ClearNavigationTransitionData() {
766 FrameTreeNode* node = frame_tree_.root();
767 node->render_manager()->ClearNavigationTransitionData();
768}
769
[email protected]8ff00d72012-10-23 19:12:21770WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56771 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03772 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
773 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22774 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58775 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22776 web_ui->SetController(controller);
777 return web_ui;
778 }
779
780 delete web_ui;
781 return NULL;
782}
783
[email protected]8ff00d72012-10-23 19:12:21784WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21785 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
786 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31787}
788
[email protected]8ff00d72012-10-23 19:12:21789WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21790 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34791}
792
[email protected]86ef6a392012-05-11 22:03:11793void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22794 if (GetUserAgentOverride() == override)
795 return;
796
797 renderer_preferences_.user_agent_override = override;
798
799 // Send the new override string to the renderer.
800 RenderViewHost* host = GetRenderViewHost();
801 if (host)
802 host->SyncRendererPrefs();
803
804 // Reload the page if a load is currently in progress to avoid having
805 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27806 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22807 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
808 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53809
810 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
811 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11812}
813
814const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22815 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11816}
817
[email protected]95640212014-07-26 18:14:30818void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
819 AddAccessibilityMode(AccessibilityModeTreeOnly);
820}
821
822bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
823 return accessibility_mode_ == AccessibilityModeTreeOnly;
824}
825
826bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
827 return accessibility_mode_ == AccessibilityModeComplete;
828}
829
[email protected]2ceee8f2014-01-14 18:02:08830#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41831void WebContentsImpl::SetParentNativeViewAccessible(
832gfx::NativeViewAccessible accessible_parent) {
833 accessible_parent_ = accessible_parent;
clamyc0a278672015-03-24 17:08:55834 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
[email protected]95640212014-07-26 18:14:30835 if (rfh)
836 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41837}
838#endif
839
[email protected]fcf75d42013-12-03 20:11:26840const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55841 // Transient entries take precedence. They are used for interstitial pages
842 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23843 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08844 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21845 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30846 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23847 if (entry) {
[email protected]b5cca982011-05-26 04:42:08848 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23849 }
[email protected]fa944cb82013-11-15 17:51:21850 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
851 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58852 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54853 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32854 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54855 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35856 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26857 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54858 if (!title.empty())
859 return title;
860 }
861 }
862
863 // We use the title for the last committed entry rather than a pending
864 // navigation entry. For example, when the user types in a URL, we want to
865 // keep the old page's title until the new load has committed and we get a new
866 // title.
[email protected]96d185d2009-04-24 03:28:54867 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32868
[email protected]9eeafc012013-11-25 23:49:47869 // We make an exception for initial navigations.
870 if (controller_.IsInitialNavigation()) {
871 // We only want to use the title from the visible entry in one of two cases:
872 // 1. There's already a committed entry for an initial navigation, in which
873 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
874 // 2. The pending entry has been explicitly assigned a title to display.
875 //
876 // If there's no last committed entry and no assigned title, we should fall
877 // back to |page_title_when_no_navigation_entry_| rather than showing the
878 // URL.
879 if (entry ||
880 (controller_.GetVisibleEntry() &&
881 !controller_.GetVisibleEntry()->GetTitle().empty())) {
882 entry = controller_.GetVisibleEntry();
883 }
884 }
[email protected]59167c22013-06-03 18:07:32885
[email protected]45d0ef7f2011-01-05 13:46:23886 if (entry) {
[email protected]b5cca982011-05-26 04:42:08887 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23888 }
[email protected]987fc3a2011-05-26 14:18:09889
890 // |page_title_when_no_navigation_entry_| is finally used
891 // if no title cannot be retrieved.
892 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54893}
894
[email protected]b172aee2012-04-10 17:05:26895int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46896 return GetMaxPageIDForSiteInstance(GetSiteInstance());
897}
898
[email protected]b172aee2012-04-10 17:05:26899int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
900 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33901 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
902 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46903
[email protected]b6583592012-01-25 19:52:33904 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34905}
906
[email protected]b172aee2012-04-10 17:05:26907void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46908 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
909}
910
[email protected]b172aee2012-04-10 17:05:26911void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33912 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46913 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33914 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34915}
916
[email protected]ec6c05f2013-10-23 18:41:57917void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
918 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
919 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57920}
921
creiscce56cd2014-09-29 22:45:22922SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21923 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54924}
925
creiscce56cd2014-09-29 22:45:22926SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
927 RenderViewHostImpl* dest_rvh =
928 GetRenderManager()->pending_render_view_host() ?
929 GetRenderManager()->pending_render_view_host() :
930 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58931 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38932}
933
[email protected]b172aee2012-04-10 17:05:26934bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31935 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49936}
937
[email protected]6dfed692014-05-22 04:18:03938bool WebContentsImpl::IsLoadingToDifferentDocument() const {
939 return is_loading_ && is_load_to_different_document_;
940}
941
[email protected]b172aee2012-04-10 17:05:26942bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03943 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31944}
945
[email protected]b172aee2012-04-10 17:05:26946const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31947 return load_state_;
948}
949
[email protected]fcf75d42013-12-03 20:11:26950const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31951 return load_state_host_;
952}
953
[email protected]b172aee2012-04-10 17:05:26954uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31955 return upload_size_;
956}
957
[email protected]b172aee2012-04-10 17:05:26958uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31959 return upload_position_;
960}
961
[email protected]1ae93fb2013-06-14 03:38:56962std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56963 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39964 frame_tree_.ForEach(base::Bind(&CollectSites,
965 base::Unretained(GetBrowserContext()),
966 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56967 return sites;
968}
969
[email protected]b172aee2012-04-10 17:05:26970const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54971 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31972}
973
[email protected]b172aee2012-04-10 17:05:26974bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31975 return displayed_insecure_content_;
976}
977
[email protected]222f5822014-02-05 23:40:49978void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25979 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55980 ++capturer_count_;
981 DVLOG(1) << "There are now " << capturer_count_
982 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49983
984 // Note: This provides a hint to upstream code to size the views optimally
985 // for quality (e.g., to avoid scaling).
986 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
987 preferred_size_for_capture_ = capture_size;
988 OnPreferredSizeChanged(preferred_size_);
989 }
ccameron8807c38f2015-01-17 00:29:19990
991 // Ensure that all views are un-occluded before capture begins.
992 WasUnOccluded();
[email protected]54597982013-02-06 01:59:55993}
994
995void WebContentsImpl::DecrementCapturerCount() {
996 --capturer_count_;
997 DVLOG(1) << "There are now " << capturer_count_
998 << " capturing(s) of WebContentsImpl@" << this;
999 DCHECK_LE(0, capturer_count_);
1000
[email protected]5a652232013-02-12 06:15:251001 if (is_being_destroyed_)
1002 return;
1003
[email protected]222f5822014-02-05 23:40:491004 if (capturer_count_ == 0) {
1005 const gfx::Size old_size = preferred_size_for_capture_;
1006 preferred_size_for_capture_ = gfx::Size();
1007 OnPreferredSizeChanged(old_size);
1008 }
1009
[email protected]1ac10dca2013-08-20 20:47:041010 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551011 DVLOG(1) << "Executing delayed WasHidden().";
1012 WasHidden();
1013 }
[email protected]be1f56ab2011-12-22 06:55:311014}
1015
[email protected]f2bd40812013-07-20 04:30:441016int WebContentsImpl::GetCapturerCount() const {
1017 return capturer_count_;
1018}
1019
miu50f97892014-09-22 22:49:521020bool WebContentsImpl::IsAudioMuted() const {
1021 return audio_muter_.get() && audio_muter_->is_muting();
1022}
1023
1024void WebContentsImpl::SetAudioMuted(bool mute) {
1025 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1026 << " for WebContentsImpl@" << this;
1027
1028 if (mute == IsAudioMuted())
1029 return;
1030
1031 if (mute) {
1032 if (!audio_muter_)
1033 audio_muter_.reset(new WebContentsAudioMuter(this));
1034 audio_muter_->StartMuting();
1035 } else {
1036 DCHECK(audio_muter_);
1037 audio_muter_->StopMuting();
1038 }
1039
1040 // Notification for UI updates in response to the changed muting state.
1041 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1042}
1043
[email protected]b172aee2012-04-10 17:05:261044bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311045 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1046 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1047 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491048}
1049
[email protected]b172aee2012-04-10 17:05:261050void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1051 int error_code) {
[email protected]443b80e2010-12-14 00:42:231052 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341053 return;
1054
[email protected]443b80e2010-12-14 00:42:231055 crashed_status_ = status;
1056 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211057 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341058}
1059
[email protected]b172aee2012-04-10 17:05:261060base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311061 return crashed_status_;
1062}
1063
[email protected]b172aee2012-04-10 17:05:261064bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311065 return is_being_destroyed_;
1066}
1067
[email protected]7f924832014-08-09 05:57:221068void WebContentsImpl::NotifyNavigationStateChanged(
1069 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541070 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1071 // is fixed.
1072 tracked_objects::ScopedTracker tracking_profile(
1073 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1074 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtisbc6572e12014-09-12 19:22:301075 // Create and release the audio power save blocker depending on whether the
1076 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341077 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
timavf6f6f692015-03-04 02:19:371078 audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:301079 if (WasRecentlyAudible()) {
1080 if (!audio_power_save_blocker_)
1081 CreateAudioPowerSaveBlocker();
1082 } else {
1083 audio_power_save_blocker_.reset();
1084 }
1085 }
1086
[email protected]d5f942ba2008-09-26 19:30:341087 if (delegate_)
1088 delegate_->NavigationStateChanged(this, changed_flags);
1089}
1090
[email protected]9a890452014-02-13 22:21:021091base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1092 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331093}
1094
[email protected]9e2e4632012-07-27 16:38:411095void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541096 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591097
ccameron8807c38f2015-01-17 00:29:191098 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1099 if (view) {
1100 view->Show();
[email protected]789e9152009-08-04 21:59:431101#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191102 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431103#endif
[email protected]de3c5d82014-05-28 22:12:591104 }
[email protected]789e9152009-08-04 21:59:431105 }
[email protected]96d185d2009-04-24 03:28:541106
[email protected]9a890452014-02-13 22:21:021107 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381108
[email protected]b9769d82012-02-10 00:23:591109 // The resize rect might have changed while this was inactive -- send the new
1110 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581111 RenderViewHostImpl* rvh =
1112 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591113 if (rvh) {
1114 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1115 }
[email protected]96d185d2009-04-24 03:28:541116
dalecurtisbc6572e12014-09-12 19:22:301117 // Restore power save blocker if there are active video players running.
1118 if (!active_video_players_.empty() && !video_power_save_blocker_)
1119 CreateVideoPowerSaveBlocker();
1120
[email protected]c0d9d5672013-10-09 07:38:031121 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1122
[email protected]54597982013-02-06 01:59:551123 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311124}
1125
[email protected]b172aee2012-04-10 17:05:261126void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551127 // If there are entities capturing screenshots or video (e.g., mirroring),
1128 // don't activate the "disable rendering" optimization.
1129 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521130 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551131 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261132 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521133 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331134 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521135 // calls us).
ccameron8807c38f2015-01-17 00:29:191136 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1137 if (view)
1138 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591139 }
dalecurtisbc6572e12014-09-12 19:22:301140
1141 // Release any video power save blockers held as video is not visible.
1142 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541143 }
1144
[email protected]c0d9d5672013-10-09 07:38:031145 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1146
[email protected]54597982013-02-06 01:59:551147 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371148}
1149
ccameron8807c38f2015-01-17 00:29:191150void WebContentsImpl::WasOccluded() {
1151 if (capturer_count_ > 0)
1152 return;
1153
1154 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1155 if (view)
1156 view->WasOccluded();
1157 }
1158}
1159
1160void WebContentsImpl::WasUnOccluded() {
1161 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1162 if (view)
1163 view->WasUnOccluded();
1164 }
1165}
1166
[email protected]b172aee2012-04-10 17:05:261167bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311168 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271169 return WillNotifyDisconnection() &&
1170 !ShowingInterstitialPage() &&
clamyc0a278672015-03-24 17:08:551171 !static_cast<RenderViewHostImpl*>(
1172 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311173}
1174
[email protected]1c3f80bd2014-04-08 23:02:061175void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
clamyc0a278672015-03-24 17:08:551176 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1177 for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061178}
1179
[email protected]b172aee2012-04-10 17:05:261180void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211181 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401182 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271183}
1184
[email protected]b172aee2012-04-10 17:05:261185WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441186 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451187 // We pass our own opener so that the cloned page can access it if it was
1188 // before.
[email protected]54944cde2012-12-09 09:24:591189 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451190 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591191 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191192 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221193 FOR_EACH_OBSERVER(WebContentsObserver,
1194 observers_,
1195 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271196 return tc;
1197}
1198
[email protected]14392a52012-05-02 20:28:441199void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211200 const NotificationSource& source,
1201 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441202 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211203 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1204 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031205 RenderWidgetHostView* view = host->GetView();
1206 if (view == GetFullscreenRenderWidgetHostView()) {
1207 // We cannot just call view_->RestoreFocus() here. On some platforms,
1208 // attempting to focus the currently-invisible WebContentsView will be
1209 // flat-out ignored. Therefore, this boolean is used to track whether
1210 // we will request focus after the fullscreen widget has been
1211 // destroyed.
1212 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1213 } else {
1214 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1215 i != pending_widget_views_.end(); ++i) {
1216 if (host->GetView() == i->second) {
1217 pending_widget_views_.erase(i);
1218 break;
1219 }
[email protected]bafe6cd2012-05-23 23:09:501220 }
1221 }
1222 break;
1223 }
[email protected]14392a52012-05-02 20:28:441224 default:
1225 NOTREACHED();
1226 }
1227}
1228
[email protected]ec6c05f2013-10-23 18:41:571229WebContents* WebContentsImpl::GetWebContents() {
1230 return this;
1231}
1232
[email protected]54944cde2012-12-09 09:24:591233void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211234 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361235 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211236 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431237 should_normally_be_visible_ = !params.initially_hidden;
1238
avic2c29d782014-12-12 00:23:541239 // Either both routing ids can be given, or neither can be.
1240 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1241 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1242 (params.routing_id != MSG_ROUTING_NONE &&
1243 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211244 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041245 params.browser_context, params.site_instance, params.routing_id,
1246 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191247
[email protected]fc2b46b2014-05-03 16:33:451248 WebContentsViewDelegate* delegate =
1249 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1250
1251 if (browser_plugin_guest_) {
1252 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1253 this, delegate, &render_view_host_delegate_view_));
1254
1255 WebContentsViewGuest* rv = new WebContentsViewGuest(
1256 this, browser_plugin_guest_.get(), platform_view.Pass(),
1257 render_view_host_delegate_view_);
1258 render_view_host_delegate_view_ = rv;
1259 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191260 } else {
[email protected]fc2b46b2014-05-03 16:33:451261 // Regular WebContentsView.
1262 view_.reset(CreateWebContentsView(
1263 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191264 }
[email protected]fc2b46b2014-05-03 16:33:451265 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191266 CHECK(view_.get());
1267
[email protected]ed245db2012-12-18 08:00:451268 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591269 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191270
1271 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101272 if (opener_)
1273 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191274
tommyclieb25b2a2014-11-03 19:45:091275#if defined(ENABLE_PLUGINS)
1276 plugin_content_origin_whitelist_.reset(
1277 new PluginContentOriginWhitelist(this));
1278#endif
1279
[email protected]d1198fd2012-08-13 22:50:191280 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211281 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1282 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101283
[email protected]01f83f92014-06-17 14:41:541284 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091285 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541286
mlamouriefdca9d2014-09-16 16:55:401287 manifest_manager_host_.reset(new ManifestManagerHost(this));
1288
[email protected]c7654a232013-06-12 21:04:441289#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101290 date_time_chooser_.reset(new DateTimeChooserAndroid());
1291#endif
fsamuel7310a4262014-12-05 05:06:441292
1293 // BrowserPluginGuest::Init needs to be called after this WebContents has
1294 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1295 if (browser_plugin_guest_)
1296 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371297
1298 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1299 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561300
1301 // If the WebContents creation was renderer-initiated, it means that the
1302 // corresponding RenderView and main RenderFrame have already been created.
1303 // Ensure observers are notified about this.
1304 if (params.renderer_initiated_creation) {
1305 RenderViewCreated(GetRenderViewHost());
1306 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1307 }
naskof5940b9f2015-03-02 23:04:051308
1309 // Ensure that observers are notified of the creation of this WebContents's
1310 // main RenderFrameHost. It must be done here for main frames, since the
1311 // NotifySwappedFromRenderManager expects view_ to already be created and that
1312 // happens after RenderFrameHostManager::Init.
1313 NotifySwappedFromRenderManager(
1314 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191315}
1316
[email protected]7fff43e2013-05-21 20:21:101317void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1318 RemoveDestructionObserver(web_contents);
1319
[email protected]14392a52012-05-02 20:28:441320 // Clear the opener if it has been closed.
1321 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441322 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511323 return;
[email protected]14392a52012-05-02 20:28:441324 }
[email protected]ceee8cd2013-03-08 04:59:511325 // Clear a pending contents that has been closed before being shown.
1326 for (PendingContents::iterator iter = pending_contents_.begin();
1327 iter != pending_contents_.end();
1328 ++iter) {
1329 if (iter->second != web_contents)
1330 continue;
1331 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511332 return;
1333 }
1334 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441335}
1336
[email protected]7fff43e2013-05-21 20:21:101337void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1338 if (!ContainsKey(destruction_observers_, web_contents)) {
1339 destruction_observers_[web_contents] =
1340 new DestructionObserver(this, web_contents);
1341 }
1342}
1343
1344void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1345 DestructionObservers::iterator iter =
1346 destruction_observers_.find(web_contents);
1347 if (iter != destruction_observers_.end()) {
1348 delete destruction_observers_[web_contents];
1349 destruction_observers_.erase(iter);
1350 }
1351}
1352
[email protected]b172aee2012-04-10 17:05:261353void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311354 observers_.AddObserver(observer);
1355}
1356
[email protected]b172aee2012-04-10 17:05:261357void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311358 observers_.RemoveObserver(observer);
1359}
1360
[email protected]948481d2014-06-11 18:32:221361std::set<RenderWidgetHostView*>
1362WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1363 std::set<RenderWidgetHostView*> set;
1364 if (ShowingInterstitialPage()) {
1365 set.insert(GetRenderWidgetHostView());
1366 } else {
1367 ForEachFrame(
1368 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1369 }
[email protected]de3c5d82014-05-28 22:12:591370 return set;
1371}
1372
[email protected]b172aee2012-04-10 17:05:261373void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341374 if (delegate_)
1375 delegate_->ActivateContents(this);
1376}
1377
[email protected]b172aee2012-04-10 17:05:261378void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121379 if (delegate_)
1380 delegate_->DeactivateContents(this);
1381}
1382
[email protected]b172aee2012-04-10 17:05:261383void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481384 if (delegate_)
1385 delegate_->LostCapture();
1386}
1387
[email protected]b24b68a2012-09-24 21:57:261388void WebContentsImpl::RenderWidgetDeleted(
1389 RenderWidgetHostImpl* render_widget_host) {
1390 if (is_being_destroyed_) {
1391 // |created_widgets_| might have been destroyed.
1392 return;
1393 }
1394
1395 std::set<RenderWidgetHostImpl*>::iterator iter =
1396 created_widgets_.find(render_widget_host);
1397 if (iter != created_widgets_.end())
1398 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541399
1400 if (render_widget_host &&
1401 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491402 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531403 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541404 FOR_EACH_OBSERVER(WebContentsObserver,
1405 observers_,
1406 DidDestroyFullscreenWidget(
1407 fullscreen_widget_routing_id_));
1408 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031409 if (fullscreen_widget_had_focus_at_shutdown_)
1410 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541411 }
[email protected]b24b68a2012-09-24 21:57:261412}
1413
miu9e14e492014-10-25 02:39:041414void WebContentsImpl::RenderWidgetGotFocus(
1415 RenderWidgetHostImpl* render_widget_host) {
1416 // Notify the delegate if an embedded fullscreen widget was focused.
1417 if (delegate_ && render_widget_host &&
1418 delegate_->EmbedsFullscreenWidget() &&
1419 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1420 delegate_->WebContentsFocused(this);
1421}
1422
estaded0a0c992015-01-21 14:12:061423void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311424 RenderWidgetHostImpl* render_widget_host,
1425 bool width_changed) {
clamyc0a278672015-03-24 17:08:551426 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
estadece344ec2015-01-23 00:12:291427 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061428 return;
estaded0a0c992015-01-21 14:12:061429
rouslan2f5993f2015-01-29 00:18:311430 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1431 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061432}
1433
paulmeyer9ef6e4462015-02-24 19:15:101434void WebContentsImpl::ScreenInfoChanged() {
1435 if (browser_plugin_embedder_)
1436 browser_plugin_embedder_->ScreenInfoChanged();
1437}
1438
[email protected]b172aee2012-04-10 17:05:261439bool WebContentsImpl::PreHandleKeyboardEvent(
1440 const NativeWebKeyboardEvent& event,
1441 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481442 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131443 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481444}
1445
[email protected]b172aee2012-04-10 17:05:261446void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101447 if (browser_plugin_embedder_ &&
1448 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1449 return;
1450 }
[email protected]63954792011-07-11 04:17:481451 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131452 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481453}
1454
[email protected]d92026ef2014-03-03 21:04:131455bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461456 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191457#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331458 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1459 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191460 // -the OS already has a gesture to do this through pinch-zoom
1461 // -if a user starts an inertial scroll, let's go, and presses control
1462 // (i.e. control+tab) then the OS's buffered scroll events will come in
1463 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331464 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551465 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331466 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521467 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1468 return true;
1469 }
[email protected]bccc4472013-04-18 16:37:191470#endif
[email protected]fb3f066e2013-02-12 19:12:521471 return false;
1472}
1473
[email protected]04bce562014-01-30 05:34:541474bool WebContentsImpl::PreHandleGestureEvent(
1475 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031476 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541477}
1478
[email protected]b172aee2012-04-10 17:05:261479void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431480 if (delegate_)
1481 delegate_->HandleMouseDown();
1482}
1483
[email protected]b172aee2012-04-10 17:05:261484void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481485 if (delegate_)
1486 delegate_->HandleMouseUp();
1487}
1488
[email protected]590a634e2012-07-19 16:38:231489void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481490 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231491 delegate_->HandlePointerActivate();
1492}
1493
1494void WebContentsImpl::HandleGestureBegin() {
1495 if (delegate_)
1496 delegate_->HandleGestureBegin();
1497}
1498
1499void WebContentsImpl::HandleGestureEnd() {
1500 if (delegate_)
1501 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481502}
1503
mlamouri7a78d6fd2015-01-17 13:23:531504void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1505 // This method is being called to enter renderer-initiated fullscreen mode.
1506 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491507 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1508 if (widget_view)
1509 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1510
[email protected]8a5e0ca2011-08-25 06:30:471511 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531512 delegate_->EnterFullscreenModeForTab(this, origin);
1513
1514 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1515 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1516}
1517
1518void WebContentsImpl::ExitFullscreenMode() {
1519 // This method is being called to leave renderer-initiated fullscreen mode.
1520 // Make sure any existing fullscreen widget is shut down first.
1521 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1522 if (widget_view)
1523 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1524
hugo.holgersson61288e6c2015-01-28 17:04:401525#if defined(OS_ANDROID)
1526 ContentVideoView* video_view = ContentVideoView::GetInstance();
1527 if (video_view != NULL)
1528 video_view->OnExitFullscreen();
1529#endif
1530
mlamouri7a78d6fd2015-01-17 13:23:531531 if (delegate_)
1532 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371533
scheib3dcb6c932015-02-23 10:55:581534 // Ensure web contents exit fullscreen state by sending a resize message,
1535 // which includes the fullscreen state. This is required for the situation
1536 // of the browser moving the view into a fullscreen state "browser fullscreen"
1537 // and then the contents entering "tab fullscreen". Exiting the contents
1538 // "tab fullscreen" then won't have the side effect of the view resizing,
1539 // hence the explicit call here is required.
1540 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1541 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1542 render_widget_host->WasResized();
1543 }
1544
[email protected]657c8e02014-03-19 19:18:371545 FOR_EACH_OBSERVER(WebContentsObserver,
1546 observers_,
1547 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471548}
1549
[email protected]b172aee2012-04-10 17:05:261550bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381551 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121552}
1553
[email protected]a9c81f02012-06-01 00:15:441554void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1555 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371556 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441557 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371558 } else {
1559 GotResponseToLockMouseRequest(false);
1560 }
1561}
1562
[email protected]b172aee2012-04-10 17:05:261563void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371564 if (delegate_)
1565 delegate_->LostMouseLock();
1566}
1567
[email protected]bafe6cd2012-05-23 23:09:501568void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201569 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501570 int route_id,
[email protected]227692c52013-05-31 22:43:041571 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131572 const ViewHostMsg_CreateWindow_Params& params,
1573 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501574 // We usually create the new window in the same BrowsingInstance (group of
1575 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551576 // if the opener is being suppressed (in a non-guest), we create a new
1577 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251578 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551579
[email protected]04cbd3d2013-12-04 04:58:201580 // If the opener is to be suppressed, the new window can be in any process.
1581 // Since routing ids are process specific, we must not have one passed in
1582 // as argument here.
1583 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1584
[email protected]bafe6cd2012-05-23 23:09:501585 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551586 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571587 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501588 GetSiteInstance();
1589
[email protected]04cbd3d2013-12-04 04:58:201590 // A message to create a new window can only come from the active process for
1591 // this WebContentsImpl instance. If any other process sends the request,
1592 // it is invalid and the process must be terminated.
1593 if (GetRenderProcessHost()->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351594 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1595 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201596 if (process_handle != base::kNullProcessHandle) {
1597 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391598 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351599 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201600 }
1601 return;
1602 }
1603
[email protected]d1198fd2012-08-13 22:50:191604 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341605 //
1606 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301607 const std::string& partition_id =
1608 GetContentClient()->browser()->
1609 GetStoragePartitionIdForSite(GetBrowserContext(),
1610 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461611 StoragePartition* partition = BrowserContext::GetStoragePartition(
1612 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411613 DOMStorageContextWrapper* dom_storage_context =
1614 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191615 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1616 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1617 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371618
1619 if (delegate_ &&
1620 !delegate_->ShouldCreateWebContents(this,
1621 route_id,
avic2c29d782014-12-12 00:23:541622 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371623 params.window_container_type,
1624 params.frame_name,
1625 params.target_url,
1626 partition_id,
1627 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011628 if (route_id != MSG_ROUTING_NONE &&
1629 !RenderViewHost::FromID(render_process_id, route_id)) {
1630 // If the embedder didn't create a WebContents for this route, we need to
1631 // delete the RenderView that had already been created.
1632 Send(new ViewMsg_Close(route_id));
1633 }
[email protected]dd6730412013-08-14 15:03:371634 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1635 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1636 main_frame_route_id);
1637 return;
1638 }
1639
1640 // Create the new web contents. This will automatically create the new
1641 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461642 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591643 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041644 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061645 create_params.opener = this;
1646 create_params.opener_suppressed = params.opener_suppressed;
1647 if (params.disposition == NEW_BACKGROUND_TAB)
1648 create_params.initially_hidden = true;
naskob21fe4872015-02-24 14:15:561649 create_params.renderer_initiated_creation = true;
[email protected]50d326e2014-05-20 17:59:061650
[email protected]4858e432014-06-23 18:14:171651 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551652 if (!is_guest) {
1653 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451654 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171655 new_contents = static_cast<WebContentsImpl*>(
1656 WebContents::Create(create_params));
1657 } else {
1658 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551659 }
[email protected]50d326e2014-05-20 17:59:061660 new_contents->GetController().SetSessionStorageNamespace(
1661 partition_id,
1662 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191663
[email protected]c4538072013-03-18 02:17:551664 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341665 // will be shown immediately).
1666 if (!params.opener_suppressed) {
1667 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451668 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501669
[email protected]d70bea92013-04-05 04:23:341670 // TODO(brettw): It seems bogus that we have to call this function on the
1671 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041672 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341673 }
[email protected]bafe6cd2012-05-23 23:09:501674 // Save the created window associated with the route so we can show it
1675 // later.
1676 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1677 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101678 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501679 }
1680
1681 if (delegate_) {
1682 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071683 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131684 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501685 }
1686
1687 if (params.opener_suppressed) {
1688 // When the opener is suppressed, the original renderer cannot access the
1689 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001690 bool was_blocked = false;
1691 if (delegate_) {
bokan107a47f2015-02-03 23:23:391692 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001693 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391694 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001695 params.user_gesture, &was_blocked);
1696 }
1697 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211698 OpenURLParams open_params(params.target_url,
1699 Referrer(),
1700 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351701 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211702 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301703 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001704 new_contents->OpenURL(open_params);
1705 }
[email protected]bafe6cd2012-05-23 23:09:501706 }
1707}
1708
[email protected]a8504022013-12-04 20:23:511709void WebContentsImpl::CreateNewWidget(int render_process_id,
1710 int route_id,
[email protected]180ef242013-11-07 06:50:461711 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511712 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501713}
1714
[email protected]a8504022013-12-04 20:23:511715void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1716 int route_id) {
1717 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501718}
1719
[email protected]a8504022013-12-04 20:23:511720void WebContentsImpl::CreateNewWidget(int render_process_id,
1721 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501722 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461723 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211724 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511725 // A message to create a new widget can only come from the active process for
1726 // this WebContentsImpl instance. If any other process sends the request,
1727 // it is invalid and the process must be terminated.
1728 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351729 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1730 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511731 if (process_handle != base::kNullProcessHandle) {
1732 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391733 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351734 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511735 }
1736 return;
1737 }
1738
[email protected]bafe6cd2012-05-23 23:09:501739 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041740 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261741 created_widgets_.insert(widget_host);
1742
[email protected]cfd80b02014-05-01 17:46:481743 RenderWidgetHostViewBase* widget_view =
1744 static_cast<RenderWidgetHostViewBase*>(
1745 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191746 if (!widget_view)
1747 return;
[email protected]bafe6cd2012-05-23 23:09:501748 if (!is_fullscreen) {
1749 // Popups should not get activated.
1750 widget_view->SetPopupType(popup_type);
1751 }
1752 // Save the created widget associated with the route so we can show it later.
1753 pending_widget_views_[route_id] = widget_view;
1754
1755#if defined(OS_MACOSX)
1756 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1757 // to allow it to survive the trip without being hosted.
1758 base::mac::NSObjectRetain(widget_view->GetNativeView());
1759#endif
1760}
1761
1762void WebContentsImpl::ShowCreatedWindow(int route_id,
1763 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391764 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501765 bool user_gesture) {
1766 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001767 if (contents) {
1768 WebContentsDelegate* delegate = GetDelegate();
1769 if (delegate) {
1770 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391771 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001772 }
1773 }
[email protected]bafe6cd2012-05-23 23:09:501774}
1775
1776void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391777 const gfx::Rect& initial_rect) {
1778 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501779}
1780
1781void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1782 ShowCreatedWidget(route_id, true, gfx::Rect());
1783}
1784
1785void WebContentsImpl::ShowCreatedWidget(int route_id,
1786 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391787 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481788 RenderWidgetHostViewBase* widget_host_view =
1789 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501790 if (!widget_host_view)
1791 return;
[email protected]cfd80b02014-05-01 17:46:481792
1793 RenderWidgetHostView* view = NULL;
1794 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1795 if (guest && guest->embedder_web_contents()) {
1796 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1797 } else {
1798 view = GetRenderWidgetHostView();
1799 }
1800
[email protected]4aebbca2013-09-17 22:26:491801 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311802 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031803 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311804 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491805 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1806 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531807 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491808 } else {
[email protected]cfd80b02014-05-01 17:46:481809 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491810 }
[email protected]4aebbca2013-09-17 22:26:491811 FOR_EACH_OBSERVER(WebContentsObserver,
1812 observers_,
1813 DidShowFullscreenWidget(route_id));
1814 if (!widget_host_view->HasFocus())
1815 widget_host_view->Focus();
1816 } else {
bokan107a47f2015-02-03 23:23:391817 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491818 }
[email protected]89054502012-06-03 10:29:241819
1820 RenderWidgetHostImpl* render_widget_host_impl =
1821 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1822 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311823 // Only allow privileged mouse lock for fullscreen render widget, which is
1824 // used to implement Pepper Flash fullscreen.
1825 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501826
1827#if defined(OS_MACOSX)
1828 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1829 // properly embedded (or purposefully ignored) we can release the retain we
1830 // took in CreateNewWidget().
1831 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1832#endif
1833}
1834
1835WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1836 PendingContents::iterator iter = pending_contents_.find(route_id);
1837
1838 // Certain systems can block the creation of new windows. If we didn't succeed
1839 // in creating one, just return NULL.
1840 if (iter == pending_contents_.end()) {
1841 return NULL;
1842 }
1843
1844 WebContentsImpl* new_contents = iter->second;
1845 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101846 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501847
[email protected]d70bea92013-04-05 04:23:341848 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251849 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341850 return new_contents;
1851
[email protected]bafe6cd2012-05-23 23:09:501852 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1853 !new_contents->GetRenderViewHost()->GetView())
1854 return NULL;
1855
creis82dd6af2014-09-17 16:30:451856 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501857 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1858 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
clamyc0a278672015-03-24 17:08:551859 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
creis82dd6af2014-09-17 16:30:451860
[email protected]bafe6cd2012-05-23 23:09:501861 return new_contents;
1862}
1863
1864RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1865 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1866 if (iter == pending_widget_views_.end()) {
1867 DCHECK(false);
1868 return NULL;
1869 }
1870
1871 RenderWidgetHostView* widget_host_view = iter->second;
1872 pending_widget_views_.erase(route_id);
1873
1874 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1875 if (!widget_host->GetProcess()->HasConnection()) {
1876 // The view has gone away or the renderer crashed. Nothing to do.
1877 return NULL;
1878 }
1879
1880 return widget_host_view;
1881}
1882
[email protected]f13b4202012-06-12 23:53:231883void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091884 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211885 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371886 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231887 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371888 } else {
1889 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041890 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371891 scoped_ptr<MediaStreamUI>());
1892 }
[email protected]f13b4202012-06-12 23:53:231893}
1894
grunell657d4d82014-09-18 00:09:431895bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1896 MediaStreamType type) {
1897 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1898 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1899 return delegate_ &&
1900 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1901}
1902
[email protected]cc9200432013-07-23 23:02:401903SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1904 SiteInstance* instance) {
1905 return controller_.GetSessionStorageNamespace(instance);
1906}
1907
[email protected]6de7fc482014-06-06 10:46:441908SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1909 return controller_.GetSessionStorageNamespaceMap();
1910}
1911
[email protected]9b159a52013-10-03 17:24:551912FrameTree* WebContentsImpl::GetFrameTree() {
1913 return &frame_tree_;
1914}
1915
lukendc35e7f2014-11-10 19:06:141916void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1917 virtual_keyboard_requested_ = requested;
1918}
1919
1920bool WebContentsImpl::IsVirtualKeyboardRequested() {
1921 return virtual_keyboard_requested_;
1922}
1923
[email protected]95640212014-07-26 18:14:301924AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1925 return accessibility_mode_;
1926}
1927
[email protected]31a71eaf2014-03-13 01:47:361928void WebContentsImpl::AccessibilityEventReceived(
1929 const std::vector<AXEventNotificationDetails>& details) {
1930 FOR_EACH_OBSERVER(
1931 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1932}
1933
dmazzonia656928e2014-09-15 20:28:541934RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:401935 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:541936 int browser_plugin_instance_id) {
1937 BrowserPluginGuestManager* guest_manager =
1938 GetBrowserContext()->GetGuestManager();
1939 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:441940 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:541941 if (!guest)
1942 return NULL;
1943 return guest->GetMainFrame();
1944}
1945
blundellc57b93f2014-10-29 13:19:571946GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1947 return geolocation_service_context_.get();
1948}
1949
[email protected]edc3af82013-12-12 21:24:071950void WebContentsImpl::OnShowValidationMessage(
1951 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291952 const base::string16& main_text,
1953 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071954 if (delegate_)
1955 delegate_->ShowValidationMessage(
1956 this, anchor_in_root_view, main_text, sub_text);
1957}
1958
1959void WebContentsImpl::OnHideValidationMessage() {
1960 if (delegate_)
1961 delegate_->HideValidationMessage(this);
1962}
1963
1964void WebContentsImpl::OnMoveValidationMessage(
1965 const gfx::Rect& anchor_in_root_view) {
1966 if (delegate_)
1967 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1968}
1969
[email protected]32deec62013-05-15 23:55:041970void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1971 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441972 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041973}
1974
[email protected]95640212014-07-26 18:14:301975BrowserAccessibilityManager*
1976 WebContentsImpl::GetRootBrowserAccessibilityManager() {
clamyc0a278672015-03-24 17:08:551977 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
[email protected]95640212014-07-26 18:14:301978 return rfh ? rfh->browser_accessibility_manager() : NULL;
1979}
1980
1981BrowserAccessibilityManager*
1982 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
clamyc0a278672015-03-24 17:08:551983 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
[email protected]95640212014-07-26 18:14:301984 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1985}
1986
[email protected]b172aee2012-04-10 17:05:261987void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491988 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231989 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491990 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331991}
1992
[email protected]b172aee2012-04-10 17:05:261993void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341994 if (delegate_)
1995 delegate_->ResizeDueToAutoResize(this, new_size);
1996}
1997
[email protected]b172aee2012-04-10 17:05:261998WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201999 if (!delegate_)
2000 return NULL;
[email protected]00c37fc2011-08-02 00:22:502001
[email protected]e5d549d2011-12-28 01:29:202002 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202003 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342004}
2005
[email protected]6b618e62012-08-16 12:59:182006bool WebContentsImpl::Send(IPC::Message* message) {
2007 if (!GetRenderViewHost()) {
2008 delete message;
2009 return false;
2010 }
2011
2012 return GetRenderViewHost()->Send(message);
2013}
2014
[email protected]b172aee2012-04-10 17:05:262015bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:502016 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:262017 FrameTreeNode* node = frame_tree_.root();
2018
creise42f2a52014-09-18 18:14:572019 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
2020 // is currently only used in --site-per-process and tests.
creis2b4cc93952015-02-20 02:04:052021 // TODO(creis): Remove this method and NavigationEntryImpl::frame_tree_node_id
2022 // by using FrameNavigationEntries instead. See https://crbug.com/236848.
creis3da03872015-02-20 21:12:322023 NavigationEntryImpl* pending_entry = controller_.GetPendingEntry();
creise42f2a52014-09-18 18:14:572024 if (pending_entry->frame_tree_node_id() != -1) {
2025 FrameTreeNode* subframe =
2026 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
2027 DCHECK(subframe);
2028 if (subframe)
2029 node = subframe;
[email protected]61ac9e242014-03-21 20:55:262030 }
2031
creis2b4cc93952015-02-20 02:04:052032 return node->navigator()->NavigateToPendingEntry(node, reload_type);
[email protected]876bc832010-09-07 16:29:542033}
[email protected]96d185d2009-04-24 03:28:542034
[email protected]a86c0e962013-12-17 17:10:392035void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2036 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442037 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392038 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442039}
2040
[email protected]20ca0382013-02-28 19:50:072041void WebContentsImpl::AttachInterstitialPage(
2042 InterstitialPageImpl* interstitial_page) {
2043 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212044 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292045
2046 // Cancel any visible dialogs so that they don't interfere with the
2047 // interstitial.
2048 if (dialog_manager_)
2049 dialog_manager_->CancelActiveAndPendingDialogs(this);
2050
[email protected]20ca0382013-02-28 19:50:072051 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2052 DidAttachInterstitialPage());
2053}
2054
2055void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572056 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212057 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072058 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2059 DidDetachInterstitialPage());
2060}
2061
avi2b177592014-12-10 02:08:022062void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2063 int history_length) {
2064 SetHistoryOffsetAndLengthForView(
2065 GetRenderViewHost(), history_offset, history_length);
2066}
2067
2068void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2069 RenderViewHost* render_view_host,
2070 int history_offset,
2071 int history_length) {
2072 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2073 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142074}
2075
[email protected]4fed3702014-04-01 09:08:002076void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172077 RenderFrameHost* focused_frame = GetFocusedFrame();
2078 if (!focused_frame)
2079 return;
2080
[email protected]959be4c2014-04-08 15:01:332081 focused_frame->Send(new FrameMsg_Reload(
2082 focused_frame->GetRoutingID(), ignore_cache));
2083}
2084
2085void WebContentsImpl::Undo() {
2086 RenderFrameHost* focused_frame = GetFocusedFrame();
2087 if (!focused_frame)
2088 return;
2089
2090 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2091 RecordAction(base::UserMetricsAction("Undo"));
2092}
2093
2094void WebContentsImpl::Redo() {
2095 RenderFrameHost* focused_frame = GetFocusedFrame();
2096 if (!focused_frame)
2097 return;
2098 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2099 RecordAction(base::UserMetricsAction("Redo"));
2100}
2101
2102void WebContentsImpl::Cut() {
2103 RenderFrameHost* focused_frame = GetFocusedFrame();
2104 if (!focused_frame)
2105 return;
2106
2107 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2108 RecordAction(base::UserMetricsAction("Cut"));
2109}
2110
2111void WebContentsImpl::Copy() {
2112 RenderFrameHost* focused_frame = GetFocusedFrame();
2113 if (!focused_frame)
2114 return;
2115
2116 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2117 RecordAction(base::UserMetricsAction("Copy"));
2118}
2119
2120void WebContentsImpl::CopyToFindPboard() {
2121#if defined(OS_MACOSX)
2122 RenderFrameHost* focused_frame = GetFocusedFrame();
2123 if (!focused_frame)
2124 return;
2125
2126 // Windows/Linux don't have the concept of a find pasteboard.
2127 focused_frame->Send(
2128 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2129 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2130#endif
2131}
2132
2133void WebContentsImpl::Paste() {
2134 RenderFrameHost* focused_frame = GetFocusedFrame();
2135 if (!focused_frame)
2136 return;
2137
2138 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2139 RecordAction(base::UserMetricsAction("Paste"));
2140}
2141
2142void WebContentsImpl::PasteAndMatchStyle() {
2143 RenderFrameHost* focused_frame = GetFocusedFrame();
2144 if (!focused_frame)
2145 return;
2146
2147 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2148 focused_frame->GetRoutingID()));
2149 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2150}
2151
2152void WebContentsImpl::Delete() {
2153 RenderFrameHost* focused_frame = GetFocusedFrame();
2154 if (!focused_frame)
2155 return;
2156
2157 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2158 RecordAction(base::UserMetricsAction("DeleteSelection"));
2159}
2160
2161void WebContentsImpl::SelectAll() {
2162 RenderFrameHost* focused_frame = GetFocusedFrame();
2163 if (!focused_frame)
2164 return;
2165
2166 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2167 RecordAction(base::UserMetricsAction("SelectAll"));
2168}
2169
2170void WebContentsImpl::Unselect() {
2171 RenderFrameHost* focused_frame = GetFocusedFrame();
2172 if (!focused_frame)
2173 return;
2174
2175 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2176 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172177}
2178
2179void WebContentsImpl::Replace(const base::string16& word) {
2180 RenderFrameHost* focused_frame = GetFocusedFrame();
2181 if (!focused_frame)
2182 return;
2183
[email protected]959be4c2014-04-08 15:01:332184 focused_frame->Send(new InputMsg_Replace(
2185 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172186}
2187
2188void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2189 RenderFrameHost* focused_frame = GetFocusedFrame();
2190 if (!focused_frame)
2191 return;
2192
[email protected]959be4c2014-04-08 15:01:332193 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2194 focused_frame->GetRoutingID(), word));
2195}
2196
2197void WebContentsImpl::NotifyContextMenuClosed(
2198 const CustomContextMenuContext& context) {
2199 RenderFrameHost* focused_frame = GetFocusedFrame();
2200 if (!focused_frame)
2201 return;
2202
2203 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2204 focused_frame->GetRoutingID(), context));
2205}
2206
2207void WebContentsImpl::ExecuteCustomContextMenuCommand(
2208 int action, const CustomContextMenuContext& context) {
2209 RenderFrameHost* focused_frame = GetFocusedFrame();
2210 if (!focused_frame)
2211 return;
2212
2213 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2214 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002215}
2216
[email protected]fc2b46b2014-05-03 16:33:452217gfx::NativeView WebContentsImpl::GetNativeView() {
2218 return view_->GetNativeView();
2219}
2220
2221gfx::NativeView WebContentsImpl::GetContentNativeView() {
2222 return view_->GetContentNativeView();
2223}
2224
2225gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2226 return view_->GetTopLevelNativeWindow();
2227}
2228
2229gfx::Rect WebContentsImpl::GetViewBounds() {
2230 return view_->GetViewBounds();
2231}
2232
2233gfx::Rect WebContentsImpl::GetContainerBounds() {
2234 gfx::Rect rv;
2235 view_->GetContainerBounds(&rv);
2236 return rv;
2237}
2238
2239DropData* WebContentsImpl::GetDropData() {
2240 return view_->GetDropData();
2241}
2242
2243void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042244 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452245}
2246
2247void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042248 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452249}
2250
2251void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042252 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452253}
2254
2255void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042256 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452257}
2258
[email protected]b172aee2012-04-10 17:05:262259void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272260 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212261 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542262 return;
2263 }
[email protected]0b431992014-06-24 00:08:032264 RenderWidgetHostView* const fullscreen_view =
2265 GetFullscreenRenderWidgetHostView();
2266 if (fullscreen_view) {
2267 fullscreen_view->Focus();
2268 return;
2269 }
[email protected]9f76c1e2012-03-05 15:15:582270 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542271}
2272
[email protected]b172aee2012-04-10 17:05:262273bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212274 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542275}
2276
[email protected]b172aee2012-04-10 17:05:262277InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212278 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222279}
2280
[email protected]b172aee2012-04-10 17:05:262281bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162282 // WebKit creates Document object when MIME type is application/xhtml+xml,
2283 // so we also support this MIME type.
2284 return contents_mime_type_ == "text/html" ||
2285 contents_mime_type_ == "text/xml" ||
2286 contents_mime_type_ == "application/xhtml+xml" ||
2287 contents_mime_type_ == "text/plain" ||
2288 contents_mime_type_ == "text/css" ||
2289 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2290}
2291
[email protected]b172aee2012-04-10 17:05:262292void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592293 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162294 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552295 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192296 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142297 return;
[email protected]c7dd2f62011-07-18 15:57:592298 }
2299
2300 Stop();
2301
2302 // Create the save package and possibly prompt the user for the name to save
2303 // the page as. The user prompt is an asynchronous operation that runs on
2304 // another thread.
2305 save_package_ = new SavePackage(this);
2306 save_package_->GetSaveInfo();
2307}
2308
2309// Used in automated testing to bypass prompting the user for file names.
2310// Instead, the names and paths are hard coded rather than running them through
2311// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342312bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2313 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212314 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592315 // Stop the page from navigating.
2316 Stop();
2317
2318 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212319 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592320}
2321
[email protected]3c71576ce2013-07-23 02:00:012322void WebContentsImpl::SaveFrame(const GURL& url,
2323 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372324 SaveFrameWithHeaders(url, referrer, std::string());
2325}
2326
2327void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2328 const Referrer& referrer,
2329 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192330 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012331 return;
sammc92af61552014-11-19 23:27:402332 if (delegate_ && delegate_->SaveFrame(url, referrer))
2333 return;
2334
nasko89ad7742015-03-05 22:14:192335 // TODO(nasko): This check for main frame is incorrect and should be fixed
2336 // by explicitly passing in which frame this method should target.
2337 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012338
2339 DownloadManager* dlm =
2340 BrowserContext::GetDownloadManager(GetBrowserContext());
2341 if (!dlm)
2342 return;
2343 int64 post_id = -1;
2344 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272345 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012346 if (entry)
2347 post_id = entry->GetPostID();
2348 }
2349 scoped_ptr<DownloadUrlParameters> params(
2350 DownloadUrlParameters::FromWebContents(this, url));
2351 params->set_referrer(referrer);
2352 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012353 if (post_id >= 0)
2354 params->set_method("POST");
2355 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372356
2357 if (headers.empty()) {
2358 params->set_prefer_cache(true);
2359 } else {
2360 std::vector<std::string> key_value_list;
2361 base::SplitString(headers, '\n', &key_value_list);
2362 for (const auto& key_value : key_value_list) {
2363 std::vector<std::string> pair;
2364 base::SplitString(key_value, ':', &pair);
2365 DCHECK_EQ(2ul, pair.size());
2366 params->add_request_header(pair[0], pair[1]);
2367 }
2368 }
[email protected]3c71576ce2013-07-23 02:00:012369 dlm->DownloadUrl(params.Pass());
2370}
2371
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342373 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482374 const base::Callback<void(int64)>& callback) {
2375 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122376}
2377
[email protected]b172aee2012-04-10 17:05:262378const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272379 return contents_mime_type_;
2380}
2381
[email protected]b172aee2012-04-10 17:05:262382bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272383 return notify_disconnection_;
2384}
2385
[email protected]b172aee2012-04-10 17:05:262386void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312387 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182388 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162389}
2390
[email protected]b172aee2012-04-10 17:05:262391void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542392 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182393 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162394}
2395
[email protected]8ff00d72012-10-23 19:12:212396RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272397 return &renderer_preferences_;
2398}
2399
[email protected]e35ccd52012-05-23 16:22:472400void WebContentsImpl::Close() {
2401 Close(GetRenderViewHost());
2402}
2403
[email protected]cf200a562013-05-03 16:24:292404void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462405 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292406 if (browser_plugin_embedder_.get())
2407 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2408 screen_x, screen_y, operation);
2409 if (GetRenderViewHost())
2410 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2411 screen_x, screen_y, operation);
2412}
2413
[email protected]d60f3702013-12-26 16:30:242414void WebContentsImpl::DidGetResourceResponseStart(
2415 const ResourceRequestDetails& details) {
2416 controller_.ssl_manager()->DidStartResourceResponse(details);
2417
2418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2419 DidGetResourceResponseStart(details));
2420
2421 // TODO(avi): Remove. http://crbug.com/170921
2422 NotificationService::current()->Notify(
2423 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2424 Source<WebContents>(this),
2425 Details<const ResourceRequestDetails>(&details));
2426}
2427
2428void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462429 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242430 const ResourceRedirectDetails& details) {
2431 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2432
2433 FOR_EACH_OBSERVER(
2434 WebContentsObserver,
2435 observers_,
creis114ca1b2014-11-13 23:51:462436 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242437
2438 // TODO(avi): Remove. http://crbug.com/170921
2439 NotificationService::current()->Notify(
2440 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2441 Source<WebContents>(this),
2442 Details<const ResourceRedirectDetails>(&details));
2443}
2444
[email protected]b172aee2012-04-10 17:05:262445void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522446 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582447 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512448 if (delegate_)
2449 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292450 if (browser_plugin_embedder_.get())
2451 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342452}
2453
[email protected]e35ccd52012-05-23 16:22:472454void WebContentsImpl::UserGestureDone() {
2455 OnUserGesture();
2456}
2457
[email protected]b172aee2012-04-10 17:05:262458void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272459 closed_by_user_gesture_ = value;
2460}
2461
[email protected]b172aee2012-04-10 17:05:262462bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272463 return closed_by_user_gesture_;
2464}
2465
[email protected]b172aee2012-04-10 17:05:262466void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502467 if (!delegate_)
2468 return;
2469
[email protected]6286a372013-10-09 04:03:272470 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2471 if (!entry)
[email protected]1788e772010-12-15 16:40:502472 return;
2473
[email protected]6286a372013-10-09 04:03:272474 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122475}
2476
[email protected]b172aee2012-04-10 17:05:262477void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042478 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272479 if (!delegate_)
2480 return;
2481
[email protected]691aa2f2013-05-28 22:52:042482 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272483}
2484
[email protected]b172aee2012-04-10 17:05:262485int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272486 return minimum_zoom_percent_;
2487}
2488
[email protected]b172aee2012-04-10 17:05:262489int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272490 return maximum_zoom_percent_;
2491}
2492
ccameronb7c1d6c2015-03-09 17:08:242493void WebContentsImpl::ResetPageScale() {
2494 Send(new ViewMsg_ResetPageScale(GetRoutingID()));
2495}
2496
[email protected]b172aee2012-04-10 17:05:262497gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492498 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232499}
2500
[email protected]b172aee2012-04-10 17:05:262501bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052502 if (GetBrowserPluginGuest())
2503 return GetBrowserPluginGuest()->LockMouse(allowed);
2504
[email protected]0bfbf882011-12-22 18:19:272505 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582506 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272507}
2508
[email protected]b172aee2012-04-10 17:05:262509bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442510 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502511}
2512
jochen55ff3502014-12-18 20:52:572513WebContents* WebContentsImpl::GetOpener() const {
2514 return static_cast<WebContents*>(opener_);
2515}
2516
[email protected]cb805452013-05-22 15:16:212517void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482518 if (!color_chooser_info_.get())
2519 return;
2520 RenderFrameHost* rfh = RenderFrameHost::FromID(
2521 color_chooser_info_->render_process_id,
2522 color_chooser_info_->render_frame_id);
2523 if (!rfh)
2524 return;
2525
2526 rfh->Send(new FrameMsg_DidChooseColorResponse(
2527 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202528}
2529
[email protected]cb805452013-05-22 15:16:212530void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482531 if (!color_chooser_info_.get())
2532 return;
2533 RenderFrameHost* rfh = RenderFrameHost::FromID(
2534 color_chooser_info_->render_process_id,
2535 color_chooser_info_->render_frame_id);
2536 if (!rfh)
2537 return;
2538
2539 rfh->Send(new FrameMsg_DidEndColorChooser(
2540 rfh->GetRoutingID(), color_chooser_info_->identifier));
2541 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202542}
2543
[email protected]41225fe2013-03-29 05:32:022544int WebContentsImpl::DownloadImage(const GURL& url,
2545 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302546 uint32_t max_bitmap_size,
pkotwiczfd773552015-03-16 00:29:142547 bool bypass_cache,
[email protected]41225fe2013-03-29 05:32:022548 const ImageDownloadCallback& callback) {
pkotwiczfd773552015-03-16 00:29:142549 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size,
2550 bypass_cache);
[email protected]41225fe2013-03-29 05:32:022551 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392552 return id;
2553}
2554
[email protected]5dcaf8e2013-12-28 01:31:422555bool WebContentsImpl::IsSubframe() const {
2556 return is_subframe_;
2557}
2558
[email protected]36ec24f2014-01-09 00:32:082559void WebContentsImpl::Find(int request_id,
2560 const base::string16& search_text,
2561 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092562 // See if a top level browser plugin handles the find request first.
2563 if (browser_plugin_embedder_ &&
2564 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2565 return;
2566 }
[email protected]36ec24f2014-01-09 00:32:082567 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2568}
2569
2570void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012571 // See if a top level browser plugin handles the stop finding request first.
2572 if (browser_plugin_embedder_ &&
2573 browser_plugin_embedder_->StopFinding(action)) {
2574 return;
2575 }
[email protected]36ec24f2014-01-09 00:32:082576 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2577}
2578
[email protected]4fe53add2014-04-08 19:53:362579void WebContentsImpl::InsertCSS(const std::string& css) {
2580 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2581 GetMainFrame()->GetRoutingID(), css));
2582}
2583
dalecurtisbc6572e12014-09-12 19:22:302584bool WebContentsImpl::WasRecentlyAudible() {
timavf6f6f692015-03-04 02:19:372585 return audio_state_provider_->WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302586}
2587
mlamouriefdca9d2014-09-16 16:55:402588void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2589 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2590}
2591
mlamouri7a78d6fd2015-01-17 13:23:532592void WebContentsImpl::ExitFullscreen() {
2593 // Clean up related state and initiate the fullscreen exit.
2594 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2595 ExitFullscreenMode();
2596}
2597
[email protected]b172aee2012-04-10 17:05:262598bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272599 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172600 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332601 return true;
2602 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272603}
2604
[email protected]b172aee2012-04-10 17:05:262605void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272606 if (delegate_)
2607 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212608}
2609
[email protected]52913802013-12-10 05:52:182610void WebContentsImpl::DidStartProvisionalLoad(
2611 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182612 const GURL& validated_url,
2613 bool is_error_page,
2614 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102615 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482616 FOR_EACH_OBSERVER(
2617 WebContentsObserver,
2618 observers_,
2619 DidStartProvisionalLoadForFrame(
2620 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082621
2622 // Notify accessibility if this is a reload.
2623 NavigationEntry* entry = controller_.GetVisibleEntry();
2624 if (entry && ui::PageTransitionCoreTypeIs(
2625 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2626 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2627 BrowserAccessibilityManager* manager =
2628 ftn->current_frame_host()->browser_accessibility_manager();
2629 if (manager)
2630 manager->UserIsReloading();
2631 }
[email protected]400992b2012-06-14 00:03:542632}
2633
[email protected]0c3c54f2014-07-31 01:29:002634void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592635 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002636#if defined(OS_ANDROID)
2637 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562638 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592639 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002640#endif
2641}
2642
[email protected]3109fbb72014-01-06 23:57:152643void WebContentsImpl::DidFailProvisionalLoadWithError(
2644 RenderFrameHostImpl* render_frame_host,
2645 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2646 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312647 FOR_EACH_OBSERVER(WebContentsObserver,
2648 observers_,
2649 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312650 validated_url,
2651 params.error_code,
2652 params.error_description));
dmazzonibf8cec42015-02-08 08:28:082653
2654 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2655 BrowserAccessibilityManager* manager =
2656 ftn->current_frame_host()->browser_accessibility_manager();
2657 if (manager)
2658 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152659}
2660
[email protected]b80624c2014-02-09 02:46:552661void WebContentsImpl::DidFailLoadWithError(
2662 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552663 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552664 int error_code,
2665 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142666 FOR_EACH_OBSERVER(
2667 WebContentsObserver,
2668 observers_,
2669 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552670}
2671
[email protected]52913802013-12-10 05:52:182672void WebContentsImpl::NotifyChangedNavigationState(
2673 InvalidateTypes changed_flags) {
2674 NotifyNavigationStateChanged(changed_flags);
2675}
2676
[email protected]3691e5cf2014-01-22 10:16:202677void WebContentsImpl::AboutToNavigateRenderFrame(
pfeldmanf87691a2015-01-23 16:58:172678 RenderFrameHostImpl* old_host,
2679 RenderFrameHostImpl* new_host) {
creis114ca1b2014-11-13 23:51:462680 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202681 FOR_EACH_OBSERVER(
2682 WebContentsObserver,
2683 observers_,
pfeldmanf87691a2015-01-23 16:58:172684 AboutToNavigateRenderFrame(old_host, new_host));
[email protected]3691e5cf2014-01-22 10:16:202685}
2686
2687void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:202688 const GURL& url,
2689 NavigationController::ReloadType reload_type) {
2690 // Notify observers about navigation.
2691 FOR_EACH_OBSERVER(
2692 WebContentsObserver,
2693 observers_,
2694 DidStartNavigationToPendingEntry(url, reload_type));
2695}
2696
[email protected]8cb834e2014-03-06 14:23:232697void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2698 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502699 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2700 // weak pointer of sorts.
2701 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2702 const int32_t frame_id = render_frame_host->GetRoutingID();
2703
[email protected]65920f332014-03-04 21:14:182704 WebContents* new_contents = OpenURL(params);
2705
dchengb907f7332015-01-07 20:35:502706 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182707 // Notify observers.
2708 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2709 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462710 render_frame_host,
[email protected]65920f332014-03-04 21:14:182711 params.url,
2712 params.referrer,
2713 params.disposition,
creis114ca1b2014-11-13 23:51:462714 params.transition));
[email protected]65920f332014-03-04 21:14:182715 }
2716}
2717
[email protected]aa62afd2014-04-22 19:22:462718bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2719 if (!delegate_)
2720 return false;
2721 return delegate_->ShouldPreserveAbortedURLs(this);
2722}
2723
[email protected]37567b432014-02-12 01:12:222724void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432725 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222726 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352727 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222728 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482729 FOR_EACH_OBSERVER(WebContentsObserver,
2730 observers_,
2731 DidCommitProvisionalLoadForFrame(
2732 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:082733
2734 BrowserAccessibilityManager* manager =
2735 render_frame_host->browser_accessibility_manager();
2736 if (manager)
2737 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:222738}
2739
[email protected]0d0f4c492014-04-02 06:42:572740void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232741 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572742 // Ensure fullscreen mode is exited before committing the navigation to a
2743 // different page. The next page will not start out assuming it is in
2744 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232745 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192746 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572747 return;
2748 }
2749 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532750 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572751 DCHECK(!IsFullscreenForCurrentTab());
2752}
2753
[email protected]37567b432014-02-12 01:12:222754void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282755 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222756 const LoadCommittedDetails& details,
2757 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2758 if (details.is_navigation_to_different_page()) {
2759 // Clear the status bubble. This is a workaround for a bug where WebKit
2760 // doesn't let us know that the cursor left an element during a
2761 // transition (this is also why the mouse cursor remains as a hand after
2762 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2763 // clear the bubble when a user navigates to a named anchor in the same
2764 // page.
sky8b00392d2015-01-10 00:30:282765 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:002766
2767 RenderWidgetHostViewBase* rwhvb =
2768 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2769 if (rwhvb)
2770 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:282771
2772 // Reset theme color on navigation to new page.
2773 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:222774 }
2775
2776 if (!details.is_in_page) {
2777 // Once the main frame is navigated, we're no longer considered to have
2778 // displayed insecure content.
2779 displayed_insecure_content_ = false;
2780 SSLManager::NotifySSLInternalStateChanged(
2781 GetController().GetBrowserContext());
2782 }
2783
2784 // Notify observers about navigation.
2785 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2786 DidNavigateMainFrame(details, params));
2787
[email protected]e85165c642014-06-10 14:34:312788 if (delegate_)
[email protected]37567b432014-02-12 01:12:222789 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312790 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222791}
2792
2793void WebContentsImpl::DidNavigateAnyFramePostCommit(
2794 RenderFrameHostImpl* render_frame_host,
2795 const LoadCommittedDetails& details,
2796 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102797 // Now that something has committed, we don't need to track whether the
2798 // initial page has been accessed.
2799 has_accessed_initial_document_ = false;
2800
[email protected]37567b432014-02-12 01:12:222801 // If we navigate off the page, close all JavaScript dialogs.
2802 if (dialog_manager_ && !details.is_in_page)
2803 dialog_manager_->CancelActiveAndPendingDialogs(this);
2804
2805 // Notify observers about navigation.
2806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092807 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222808}
2809
2810void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2811 contents_mime_type_ = mime_type;
2812}
2813
[email protected]277857a2014-06-03 10:38:012814bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312815 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052816 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312817 return false;
2818
[email protected]37567b432014-02-12 01:12:222819 if (delegate_)
2820 return delegate_->CanOverscrollContent();
2821
2822 return false;
2823}
2824
[email protected]37b64c52014-07-11 21:14:052825void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
yusufod41c5f92015-03-06 00:14:282826 // Update the theme color. This is to be published to observers on visually
2827 // non empty paint.
2828 theme_color_ = theme_color;
[email protected]e7104762014-06-20 19:17:252829}
2830
[email protected]b172aee2012-04-10 17:05:262831void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182832 const GURL& url,
[email protected]70435962011-08-02 20:13:282833 const std::string& security_info,
2834 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182835 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402836 ResourceType resource_type) {
[email protected]724159a2010-12-30 01:11:182837
2838 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082839 int cert_id = 0;
2840 net::CertStatus cert_status = 0;
2841 int security_bits = -1;
2842 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122843 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212844 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122845 &security_bits, &connection_status,
2846 &signed_certificate_timestamp_ids);
2847 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212848 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002849 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2850 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182851
[email protected]b0f724c2013-09-05 04:21:132852 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2853
2854 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2855 DidLoadResourceFromMemoryCache(details));
2856
[email protected]8bfc8272013-09-09 20:10:532857 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2858 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402859 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532860 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2861 GetRenderProcessHost()->GetID()) :
2862 GetBrowserContext()->GetRequestContextForRenderProcess(
2863 GetRenderProcessHost()->GetID()));
2864 BrowserThread::PostTask(
2865 BrowserThread::IO,
2866 FROM_HERE,
2867 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2868 }
[email protected]724159a2010-12-30 01:11:182869}
2870
[email protected]b172aee2012-04-10 17:05:262871void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392872 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182873 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192874 SSLManager::NotifySSLInternalStateChanged(
2875 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182876}
2877
[email protected]b172aee2012-04-10 17:05:262878void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022879 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582880 LOG(WARNING) << security_origin << " ran insecure content from "
2881 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392882 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412883 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392884 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182885 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412886 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192887 SSLManager::NotifySSLInternalStateChanged(
2888 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182889}
2890
[email protected]501052ff2014-02-21 22:19:072891void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:112892 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:472893 return;
naskofbd033392015-01-27 02:34:472894
[email protected]1d62cf72014-02-07 21:31:572895 RenderFrameHostImpl* rfh =
2896 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142897 FOR_EACH_OBSERVER(
2898 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182899}
2900
naskofbd033392015-01-27 02:34:472901void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:112902 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:122903 return;
[email protected]a1b99262013-12-27 21:56:222904
[email protected]8b3af1e2014-01-24 13:29:122905 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442906 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372907 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422908 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372909
[email protected]61ac9e242014-03-21 20:55:262910 RenderFrameHostImpl* rfh =
2911 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142912 FOR_EACH_OBSERVER(
2913 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312914}
2915
[email protected]960b0372014-05-19 18:01:002916void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
nasko907fcb62015-01-28 04:24:112917 if (!HasValidFrameSource())
2918 return;
2919
[email protected]960b0372014-05-19 18:01:002920 RenderFrameHostImpl* rfh =
2921 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]960b0372014-05-19 18:01:002922
creis1163acf2014-12-19 21:18:472923 // Any main frame load to a new document should reset the load progress, since
2924 // it will replace the current page and any frames.
2925 if (to_different_document && !rfh->GetParent()) {
2926 ResetLoadProgressState();
fdegans4a49ce932015-03-12 17:11:372927 rfh->set_is_loading(false);
creis1163acf2014-12-19 21:18:472928 }
2929
fdegans4a49ce932015-03-12 17:11:372930 // This method should never be called when the frame is loading.
2931 // Unfortunately, it can happen if a history navigation happens during a
2932 // BeforeUnload or Unload event.
2933 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
2934 // refactored in Blink. See crbug.com/466089
2935 if (rfh->is_loading()) {
2936 LOG(WARNING) << "OnDidStartLoading was called twice.";
tasakde32453d2015-03-06 10:39:492937 return;
fdegans4a49ce932015-03-12 17:11:372938 }
naskoa7064ad6e2015-01-15 18:44:562939
fdegans4a49ce932015-03-12 17:11:372940 if (!IsFrameTreeLoading(frame_tree_))
naskoa7064ad6e2015-01-15 18:44:562941 DidStartLoading(rfh, to_different_document);
2942
fdegans4a49ce932015-03-12 17:11:372943 rfh->set_is_loading(true);
2944 rfh->set_loading_progress(RenderFrameHostImpl::kLoadingProgressMinimum);
[email protected]960b0372014-05-19 18:01:002945
nasko3e8c20e2014-12-18 06:54:562946 // Notify the RenderFrameHostManager of the event.
2947 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2948
[email protected]960b0372014-05-19 18:01:002949 SendLoadProgressChanged();
2950}
2951
2952void WebContentsImpl::OnDidStopLoading() {
erikchen35629cc2015-03-10 20:43:222953 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2954 // fixed.
2955 tracked_objects::ScopedTracker tracking_profile1(
2956 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2957 "465796 WebContentsImpl::OnDidStopLoading::Start"));
2958
nasko907fcb62015-01-28 04:24:112959 if (!HasValidFrameSource())
2960 return;
2961
[email protected]960b0372014-05-19 18:01:002962 RenderFrameHostImpl* rfh =
2963 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]960b0372014-05-19 18:01:002964
fdegans4a49ce932015-03-12 17:11:372965 // This method should never be called when the frame is not loading.
2966 // Unfortunately, it can happen if a history navigation happens during a
2967 // BeforeUnload or Unload event.
2968 // TODO(fdegans): Change this to a DCHECK after LoadEventProgress has been
2969 // refactored in Blink. See crbug.com/466089
2970 if (!rfh->is_loading()) {
2971 LOG(WARNING) << "OnDidStopLoading was called twice.";
2972 return;
tasakde32453d2015-03-06 10:39:492973 }
[email protected]960b0372014-05-19 18:01:002974
fdegans4a49ce932015-03-12 17:11:372975 rfh->set_is_loading(false);
2976 rfh->set_loading_progress(RenderFrameHostImpl::kLoadingProgressDone);
2977
2978 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2979 // fixed.
2980 tracked_objects::ScopedTracker tracking_profile2(
2981 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2982 "465796 "
2983 "WebContentsImpl::OnDidStopLoading::SendLoadProgressChanged"));
2984
2985 // Update progress based on this frame's completion.
2986 SendLoadProgressChanged();
2987
2988 // Then clean-up the states.
2989 if (loading_total_progress_ == 1.0)
2990 ResetLoadProgressState();
2991
erikchen35629cc2015-03-10 20:43:222992 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
2993 // fixed.
2994 tracked_objects::ScopedTracker tracking_profile3(
2995 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2996 "465796 WebContentsImpl::OnDidStopLoading::NotifyRenderManager"));
nasko3e8c20e2014-12-18 06:54:562997 // Notify the RenderFrameHostManager of the event.
2998 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2999
fdegans4a49ce932015-03-12 17:11:373000 if (!IsFrameTreeLoading(frame_tree_)) {
3001 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
3002 // fixed.
3003 tracked_objects::ScopedTracker tracking_profile4(
3004 FROM_HERE_WITH_EXPLICIT_FUNCTION(
3005 "465796 WebContentsImpl::OnDidStopLoading::WCIDidStopLoading"));
fdegansc73eec22015-03-19 14:47:543006 DidStopLoading();
fdegans4a49ce932015-03-12 17:11:373007 }
erikchen35629cc2015-03-10 20:43:223008
3009 // TODO(erikchen): Remove ScopedTracker below once crbug.com/465796 is
3010 // fixed.
3011 tracked_objects::ScopedTracker tracking_profile4(
3012 FROM_HERE_WITH_EXPLICIT_FUNCTION(
fdegans4a49ce932015-03-12 17:11:373013 "465796 WebContentsImpl::OnDidStopLoading::End"));
[email protected]960b0372014-05-19 18:01:003014}
3015
3016void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
nasko907fcb62015-01-28 04:24:113017 if (!HasValidFrameSource())
3018 return;
3019
[email protected]960b0372014-05-19 18:01:003020 RenderFrameHostImpl* rfh =
3021 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]960b0372014-05-19 18:01:003022
fdegans4a49ce932015-03-12 17:11:373023 rfh->set_loading_progress(load_progress);
[email protected]960b0372014-05-19 18:01:003024
3025 // We notify progress change immediately for the first and last updates.
3026 // Also, since the message loop may be pretty busy when a page is loaded, it
3027 // might not execute a posted task in a timely manner so we make sure to
3028 // immediately send progress report if enough time has passed.
3029 base::TimeDelta min_delay =
3030 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
3031 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
3032 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
3033 // If there is a pending task to send progress, it is now obsolete.
3034 loading_weak_factory_.InvalidateWeakPtrs();
3035 SendLoadProgressChanged();
3036 if (loading_total_progress_ == 1.0)
3037 ResetLoadProgressState();
3038 return;
3039 }
3040
3041 if (loading_weak_factory_.HasWeakPtrs())
3042 return;
3043
3044 base::MessageLoop::current()->PostDelayedTask(
3045 FROM_HERE,
3046 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
3047 loading_weak_factory_.GetWeakPtr()),
3048 min_delay);
3049}
3050
[email protected]b172aee2012-04-10 17:05:263051void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:223052 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3053 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263054}
3055
[email protected]b172aee2012-04-10 17:05:263056void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303057 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263058 minimum_zoom_percent_ = minimum_percent;
3059 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263060}
3061
[email protected]b172aee2012-04-10 17:05:263062void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343063 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433064 if (!delegate_)
3065 return;
3066
[email protected]b9535422012-02-09 01:47:593067 ChildProcessSecurityPolicyImpl* policy =
3068 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223069 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593070 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213071}
3072
[email protected]b172aee2012-04-10 17:05:263073void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3074 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263075 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363076 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433077 if (!delegate_)
3078 return;
3079
[email protected]b9535422012-02-09 01:47:593080 ChildProcessSecurityPolicyImpl* policy =
3081 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323082 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593083 return;
[email protected]8f810632013-06-06 22:33:323084
[email protected]c125e532014-05-10 20:39:063085 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203086}
3087
[email protected]f5273e52014-07-14 16:30:203088void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3089 const GURL& url,
3090 bool user_gesture) {
3091 if (!delegate_)
3092 return;
3093
3094 ChildProcessSecurityPolicyImpl* policy =
3095 ChildProcessSecurityPolicyImpl::GetInstance();
3096 if (policy->IsPseudoScheme(protocol))
3097 return;
3098
3099 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3100}
3101
[email protected]b172aee2012-04-10 17:05:263102void WebContentsImpl::OnFindReply(int request_id,
3103 int number_of_matches,
3104 const gfx::Rect& selection_rect,
3105 int active_match_ordinal,
3106 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433107 if (delegate_) {
3108 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3109 active_match_ordinal, final_update);
3110 }
[email protected]b888919c2011-09-02 00:32:163111}
3112
[email protected]59363fc92012-09-05 03:46:313113#if defined(OS_ANDROID)
3114void WebContentsImpl::OnFindMatchRectsReply(
3115 int version,
3116 const std::vector<gfx::RectF>& rects,
3117 const gfx::RectF& active_rect) {
3118 if (delegate_)
3119 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3120}
[email protected]583418cc2013-01-17 14:01:103121
[email protected]1ff427972013-02-07 21:14:073122void WebContentsImpl::OnOpenDateTimeDialog(
3123 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173124 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093125 GetRenderViewHost(),
3126 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133127 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093128 value.minimum,
3129 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173130 value.step,
3131 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103132}
[email protected]59363fc92012-09-05 03:46:313133#endif
3134
[email protected]cfa856d62014-02-22 07:58:403135void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
3136 int automation_id) {
3137 DomOperationNotificationDetails details(json_string, automation_id);
3138 NotificationService::current()->Notify(
3139 NOTIFICATION_DOM_OPERATION_RESPONSE,
3140 Source<WebContents>(this),
3141 Details<DomOperationNotificationDetails>(&details));
3142}
3143
[email protected]b172aee2012-04-10 17:05:263144void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3145 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103146 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253147 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103148 AppCacheAccessed(manifest_url, blocked_by_policy));
3149}
3150
[email protected]8bc5ff02013-11-29 06:34:033151void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483152 int color_chooser_id,
3153 SkColor color,
3154 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113155 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003156 return;
nasko907fcb62015-01-28 04:24:113157
[email protected]aa62afd2014-04-22 19:22:463158 ColorChooser* new_color_chooser = delegate_ ?
3159 delegate_->OpenColorChooser(this, color, suggestions) :
3160 NULL;
[email protected]820957a2014-01-14 14:56:303161 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213162 return;
[email protected]8ed16472014-04-11 19:02:483163 if (color_chooser_info_.get())
3164 color_chooser_info_->chooser->End();
3165
3166 color_chooser_info_.reset(new ColorChooserInfo(
3167 render_frame_message_source_->GetProcess()->GetID(),
3168 render_frame_message_source_->GetRoutingID(),
3169 new_color_chooser,
3170 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203171}
3172
[email protected]b172aee2012-04-10 17:05:263173void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483174 if (color_chooser_info_ &&
3175 color_chooser_id == color_chooser_info_->identifier)
3176 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203177}
3178
[email protected]b172aee2012-04-10 17:05:263179void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323180 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483181 if (color_chooser_info_ &&
3182 color_chooser_id == color_chooser_info_->identifier)
3183 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203184}
3185
[email protected]d0759f492012-04-19 22:50:503186// This exists for render views that don't have a WebUI, but do have WebUI
3187// bindings enabled.
3188void WebContentsImpl::OnWebUISend(const GURL& source_url,
3189 const std::string& name,
3190 const base::ListValue& args) {
3191 if (delegate_)
3192 delegate_->WebUISend(this, source_url, name, args);
3193}
3194
thestigc4cac8f2014-09-04 21:17:503195#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:423196void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3197 const base::FilePath& path,
3198 bool is_hung) {
3199 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3200
3201 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3202 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3203}
3204
3205void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3206 base::ProcessId plugin_pid) {
3207 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3208 PluginCrashed(plugin_path, plugin_pid));
3209}
3210
[email protected]d8415ad92012-08-23 14:40:503211void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443212 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503213 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343214 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163215 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443216 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163217 return;
[email protected]d8415ad92012-08-23 14:40:503218 }
3219
[email protected]8c8fc292012-11-23 18:57:163220 if (!delegate_->RequestPpapiBrokerPermission(
3221 this, url, plugin_path,
3222 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443223 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163224 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443225 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163226 }
[email protected]d8415ad92012-08-23 14:40:503227}
3228
[email protected]ea0309c2013-08-06 19:35:443229void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503230 bool result) {
[email protected]ea0309c2013-08-06 19:35:443231 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503232}
3233
fsamuel833ee7c2015-02-13 23:40:403234void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3235 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393236 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143237 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403238 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373239}
tommyclie6633ca72014-10-31 00:40:423240#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373241
[email protected]41225fe2013-03-29 05:32:023242void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393243 int id,
[email protected]749fadd2013-05-15 08:37:483244 int http_status_code,
[email protected]795c28972012-12-06 06:13:393245 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303246 const std::vector<SkBitmap>& bitmaps,
3247 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133248 if (bitmaps.size() != original_bitmap_sizes.size())
3249 return;
3250
[email protected]41225fe2013-03-29 05:32:023251 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3252 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393253 // Currently WebContents notifies us of ANY downloads so that it is
3254 // possible to get here.
3255 return;
3256 }
3257 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303258 iter->second.Run(
3259 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393260 }
[email protected]41225fe2013-03-29 05:32:023261 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393262}
3263
3264void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393265 const std::vector<FaviconURL>& candidates) {
3266 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293267 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393268}
3269
dalecurtisbc6572e12014-09-12 19:22:303270void WebContentsImpl::CreateAudioPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303271 DCHECK(!audio_power_save_blocker_);
3272 audio_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033273 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
3274 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio");
dalecurtisbc6572e12014-09-12 19:22:303275}
3276
3277void WebContentsImpl::CreateVideoPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303278 DCHECK(!video_power_save_blocker_);
3279 DCHECK(!active_video_players_.empty());
3280 video_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033281 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
3282 PowerSaveBlocker::kReasonVideoPlayback, "Playing video");
dalecurtisbc6572e12014-09-12 19:22:303283#if defined(OS_ANDROID)
3284 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3285 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3286#endif
dalecurtisbc6572e12014-09-12 19:22:303287}
3288
3289void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3290 // If there are no more audio players and we don't have audio stream
3291 // monitoring, release the audio power save blocker here instead of during
3292 // NotifyNavigationStateChanged().
3293 if (active_audio_players_.empty() &&
timavf6f6f692015-03-04 02:19:373294 !audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:303295 audio_power_save_blocker_.reset();
3296 }
3297
3298 // If there are no more video players, clear the video power save blocker.
3299 if (active_video_players_.empty())
3300 video_power_save_blocker_.reset();
3301}
3302
[email protected]1dd0bb752014-02-01 01:16:263303void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3304 bool has_video,
avayvod68017be2014-10-10 18:02:433305 bool has_audio,
3306 bool is_remote) {
3307 // Ignore the videos playing remotely and don't hold the wake lock for the
3308 // screen.
3309 if (is_remote) return;
3310
dalecurtisbc6572e12014-09-12 19:22:303311 if (has_audio) {
3312 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3313
3314 // If we don't have audio stream monitoring, allocate the audio power save
3315 // blocker here instead of during NotifyNavigationStateChanged().
3316 if (!audio_power_save_blocker_ &&
timavf6f6f692015-03-04 02:19:373317 !audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:303318 CreateAudioPowerSaveBlocker();
3319 }
[email protected]1dd0bb752014-02-01 01:16:263320 }
loislo0381a742014-09-11 10:58:113321
dalecurtisbc6572e12014-09-12 19:22:303322 if (has_video) {
3323 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3324
3325 // If we're not hidden and have just created a player, create a blocker.
3326 if (!video_power_save_blocker_ && !IsHidden())
3327 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113328 }
prashantv0c9b968d22015-03-26 00:58:543329
3330 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying());
[email protected]1dd0bb752014-02-01 01:16:263331}
3332
3333void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303334 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3335 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3336 MaybeReleasePowerSaveBlockers();
prashantv0c9b968d22015-03-26 00:58:543337
3338 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused());
[email protected]d9030b82013-07-19 08:26:063339}
3340
[email protected]50279492014-05-05 23:24:293341void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153342 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293343 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283344
3345 if (theme_color_ != last_sent_theme_color_) {
3346 // Theme color should have updated by now if there was one.
3347 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3348 DidChangeThemeColor(theme_color_));
3349 last_sent_theme_color_ = theme_color_;
3350 }
[email protected]9f268072013-11-07 00:02:153351}
[email protected]d9030b82013-07-19 08:26:063352
[email protected]e67ebf32013-02-13 11:07:193353void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073354 if (delegate_)
3355 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193356}
3357
[email protected]17e286e2013-03-01 23:29:393358void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3359 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3360 BeforeFormRepostWarningShow());
3361}
3362
[email protected]ec6c05f2013-10-23 18:41:573363void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3364 Activate();
3365 if (delegate_)
3366 delegate_->ShowRepostFormWarningDialog(this);
3367}
3368
[email protected]b4c84012014-04-28 19:51:103369bool WebContentsImpl::HasAccessedInitialDocument() {
3370 return has_accessed_initial_document_;
3371}
3372
[email protected]96d185d2009-04-24 03:28:543373// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593374// loading, or done loading.
fdegans6ce28f52015-03-19 12:52:223375void WebContentsImpl::SetIsLoading(bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093376 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263377 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543378 if (is_loading == is_loading_)
3379 return;
3380
3381 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263382 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3383 base::string16());
[email protected]96d185d2009-04-24 03:28:543384 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563385 upload_size_ = 0;
3386 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543387 }
3388
[email protected]fa944cb82013-11-15 17:51:213389 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543390
3391 is_loading_ = is_loading;
3392 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033393 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543394
[email protected]6ebdc9b2010-09-27 16:55:573395 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093396 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213397 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543398
[email protected]eab61442013-11-14 18:35:483399 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593400 if (is_loading) {
naskob8744d22014-08-28 17:07:433401 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3402 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223403 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593404 } else {
naskob8744d22014-08-28 17:07:433405 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3406 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223407 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593408 }
[email protected]66798902013-10-01 18:40:163409
3410 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213411 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3412 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543413 if (details)
[email protected]8ff00d72012-10-23 19:12:213414 det = Details<LoadNotificationDetails>(details);
3415 NotificationService::current()->Notify(
3416 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543417}
3418
christiankaeed9862014-11-05 10:49:143419void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3420 RenderFrameHost* focused_frame = GetFocusedFrame();
3421 if (!focused_frame)
3422 return;
3423
3424 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3425 focused_frame->GetRoutingID(), extent));
3426}
3427
3428void WebContentsImpl::SelectRange(const gfx::Point& base,
3429 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333430 RenderFrameHost* focused_frame = GetFocusedFrame();
3431 if (!focused_frame)
3432 return;
3433
3434 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143435 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333436}
3437
[email protected]b172aee2012-04-10 17:05:263438void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463439 // If we are creating a RVH for a restored controller, then we need to make
3440 // sure the RenderView starts with a next_page_id_ larger than the number
3441 // of restored entries. This must be called before the RenderView starts
3442 // navigating (to avoid a race between the browser updating max_page_id and
3443 // the renderer updating next_page_id_). Because of this, we only call this
3444 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563445 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583446 if (max_restored_page_id >
3447 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3448 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3449 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323450}
3451
[email protected]b172aee2012-04-10 17:05:263452bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263453 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323454 // For file URLs without a title, use the pathname instead. In the case of a
3455 // synthesized title, we don't want the update to count toward the "one set
3456 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263457 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323458 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513459 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243460 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323461 explicit_set = false; // Don't count synthetic titles toward the set limit.
3462 } else {
[email protected]8af69c6c2014-03-03 19:05:313463 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323464 explicit_set = true;
3465 }
3466
[email protected]987fc3a2011-05-26 14:18:093467 // If a page is created via window.open and never navigated,
3468 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553469 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093470 if (entry) {
[email protected]36fc0392011-12-25 03:59:513471 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093472 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323473
[email protected]36fc0392011-12-25 03:59:513474 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093475 } else {
3476 if (page_title_when_no_navigation_entry_ == final_title)
3477 return false; // Nothing changed, don't bother.
3478
3479 page_title_when_no_navigation_entry_ = final_title;
3480 }
[email protected]420ae012009-04-24 05:16:323481
[email protected]420ae012009-04-24 05:16:323482 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233483 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323484
[email protected]66798902013-10-01 18:40:163485 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533486 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163487
3488 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213489 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463490 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213491 NotificationService::current()->Notify(
3492 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3493 Source<WebContents>(this),
3494 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043495
[email protected]420ae012009-04-24 05:16:323496 return true;
3497}
3498
[email protected]960b0372014-05-19 18:01:003499void WebContentsImpl::SendLoadProgressChanged() {
3500 loading_last_progress_update_ = base::TimeTicks::Now();
3501 double progress = 0.0;
3502 int frame_count = 0;
3503
fdegans4a49ce932015-03-12 17:11:373504 frame_tree_.ForEach(
3505 base::Bind(&CollectLoadProgress, &progress, &frame_count));
3506 if (frame_count != 0)
3507 progress /= frame_count;
3508 DCHECK_LE(progress, 1.0);
[email protected]960b0372014-05-19 18:01:003509
3510 if (progress <= loading_total_progress_)
3511 return;
3512 loading_total_progress_ = progress;
3513
3514 if (delegate_)
3515 delegate_->LoadProgressChanged(this, progress);
3516}
3517
3518void WebContentsImpl::ResetLoadProgressState() {
fdegans4a49ce932015-03-12 17:11:373519 frame_tree_.ForEach(base::Bind(&ResetLoadProgress));
[email protected]960b0372014-05-19 18:01:003520 loading_total_progress_ = 0.0;
3521 loading_weak_factory_.InvalidateWeakPtrs();
3522 loading_last_progress_update_ = base::TimeTicks();
3523}
3524
[email protected]02d7b6e2014-06-24 21:01:503525void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3526 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323527 // After sending out a swap notification, we need to send a disconnect
3528 // notification so that clients that pick up a pointer to |this| can NULL the
3529 // pointer. See Bug 1230284.
3530 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283532 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113533
3534 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283535 std::pair<RenderViewHost*, RenderViewHost*> details =
3536 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213537 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283538 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213539 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283540 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393541
3542 // Ensure that the associated embedder gets cleared after a RenderViewHost
3543 // gets swapped, so we don't reuse the same embedder next time a
3544 // RenderViewHost is attached to this WebContents.
3545 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323546}
3547
[email protected]02d7b6e2014-06-24 21:01:503548void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3549 RenderFrameHost* new_host) {
3550 FOR_EACH_OBSERVER(WebContentsObserver,
3551 observers_,
3552 RenderFrameHostChanged(old_host, new_host));
3553}
3554
[email protected]da7a7182013-09-06 08:11:113555// TODO(avi): Remove this entire function because this notification is already
3556// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263557void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323558 if (!notify_disconnection_)
3559 return;
3560
3561 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213562 NotificationService::current()->Notify(
3563 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3564 Source<WebContents>(this),
3565 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323566}
3567
[email protected]cbb1ef592013-06-05 19:49:463568void WebContentsImpl::NotifyNavigationEntryCommitted(
3569 const LoadCommittedDetails& load_details) {
3570 FOR_EACH_OBSERVER(
3571 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3572}
3573
[email protected]f114fa42013-12-06 17:06:443574bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3575 const IPC::Message& message) {
3576 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313577}
3578
[email protected]c31a84802014-04-03 15:55:493579const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3580 return GetLastCommittedURL();
3581}
3582
[email protected]b849847b2013-12-10 21:57:583583void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3584 // Note this is only for subframes, the notification for the main frame
3585 // happens in RenderViewCreated.
3586 FOR_EACH_OBSERVER(WebContentsObserver,
3587 observers_,
3588 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303589 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583590}
3591
3592void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193593 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583594 FOR_EACH_OBSERVER(WebContentsObserver,
3595 observers_,
3596 RenderFrameDeleted(render_frame_host));
3597}
3598
[email protected]a09d53ce2014-01-31 00:46:423599void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303600 if (delegate_)
3601 delegate_->WorkerCrashed(this);
3602}
3603
[email protected]a09d53ce2014-01-31 00:46:423604void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3605 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103606 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423607 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103608 if (GetBrowserPluginGuest()) {
3609 WebContentsViewGuest* view_guest =
3610 static_cast<WebContentsViewGuest*>(GetView());
3611 context_menu_params = view_guest->ConvertContextMenuParams(params);
3612 }
3613 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423614 return;
3615
[email protected]077e704b2014-05-23 19:24:103616 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3617 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423618}
3619
[email protected]87de04b02014-04-08 22:14:493620void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013621 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493622 const base::string16& message,
3623 const base::string16& default_prompt,
3624 const GURL& frame_url,
3625 JavaScriptMessageType javascript_message_type,
3626 IPC::Message* reply_msg) {
3627 // Suppress JavaScript dialogs when requested. Also suppress messages when
3628 // showing an interstitial as it's shown over the previous page and we don't
3629 // want the hidden page's dialogs to interfere with the interstitial.
3630 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223631 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503632 ShowingInterstitialPage() || !delegate_ ||
3633 delegate_->ShouldSuppressDialogs(this) ||
3634 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493635
3636 if (!suppress_this_message) {
3637 std::string accept_lang = GetContentClient()->browser()->
3638 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503639 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493640 dialog_manager_->RunJavaScriptDialog(
3641 this,
3642 frame_url.GetOrigin(),
3643 accept_lang,
3644 javascript_message_type,
3645 message,
3646 default_prompt,
3647 base::Bind(&WebContentsImpl::OnDialogClosed,
3648 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013649 render_frame_host->GetProcess()->GetID(),
3650 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493651 reply_msg,
3652 false),
3653 &suppress_this_message);
3654 }
3655
3656 if (suppress_this_message) {
3657 // If we are suppressing messages, just reply as if the user immediately
3658 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013659 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3660 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283661 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493662 }
3663
3664 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3665 // http://crbug.com/288961 ). The only safe thing to do here is return.
3666}
3667
3668void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013669 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493670 const base::string16& message,
3671 bool is_reload,
3672 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013673 RenderFrameHostImpl* rfhi =
3674 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493675 if (delegate_)
3676 delegate_->WillRunBeforeUnloadConfirm();
3677
3678 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503679 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3680 delegate_->ShouldSuppressDialogs(this) ||
3681 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493682 if (suppress_this_message) {
3683 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3684 return;
3685 }
3686
3687 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503688 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493689 dialog_manager_->RunBeforeUnloadDialog(
3690 this, message, is_reload,
3691 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013692 render_frame_host->GetProcess()->GetID(),
3693 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283694 false));
[email protected]87de04b02014-04-08 22:14:493695}
3696
[email protected]a86c0e962013-12-17 17:10:393697WebContents* WebContentsImpl::GetAsWebContents() {
3698 return this;
3699}
3700
[email protected]7912e822014-04-16 02:37:033701bool WebContentsImpl::IsNeverVisible() {
3702 if (!delegate_)
3703 return false;
3704 return delegate_->IsNeverVisible(this);
3705}
3706
[email protected]95640212014-07-26 18:14:303707#if defined(OS_WIN)
3708gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3709 return accessible_parent_;
3710}
3711#endif
3712
[email protected]5a3bdf52012-05-24 15:12:573713RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3714 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323715}
3716
[email protected]8ff00d72012-10-23 19:12:213717RendererPreferences WebContentsImpl::GetRendererPrefs(
3718 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463719 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513720}
3721
[email protected]b172aee2012-04-10 17:05:263722gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173723 if (delegate_)
3724 return delegate_->GetRootWindowResizerRect();
3725 return gfx::Rect();
3726}
3727
[email protected]7a846df2012-09-20 19:17:393728void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273729 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393730 browser_plugin_embedder_.reset();
3731}
3732
[email protected]b172aee2012-04-10 17:05:263733void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443734 // Don't send notifications if we are just creating a swapped-out RVH for
3735 // the opener chain. These won't be used for view-source or WebUI, so it's
3736 // ok to return early.
creiscce56cd2014-09-29 22:45:223737 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443738 return;
3739
[email protected]86f98a22013-03-20 14:35:003740 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313741 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083742
[email protected]8ff00d72012-10-23 19:12:213743 NotificationService::current()->Notify(
3744 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3745 Source<WebContents>(this),
3746 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323747
3748 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353749 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213750 if (GetRenderManager()->pending_web_ui())
3751 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323752
[email protected]6286a372013-10-09 04:03:273753 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333754 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323755 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183756 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583757 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323758 }
[email protected]0666aef2009-05-13 19:48:083759
[email protected]60780f412013-02-25 16:34:103760 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263761
3762 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253763 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583764
dgozman24bfc912014-09-29 11:04:183765 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323766}
3767
[email protected]b172aee2012-04-10 17:05:263768void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523769 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323770 // Don't notify the world, since this came from a renderer in the
3771 // background.
3772 return;
3773 }
3774
[email protected]da7a7182013-09-06 08:11:113775 notify_disconnection_ = true;
3776 // TODO(avi): Remove. http://crbug.com/170921
3777 NotificationService::current()->Notify(
3778 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3779 Source<WebContents>(this),
3780 NotificationService::NoDetails());
3781
[email protected]be1f56ab2011-12-22 06:55:313782 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233783 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303784
3785 // Restore the focus to the tab (otherwise the focus will be on the top
3786 // window).
[email protected]484ae5912010-09-29 19:16:143787 if (was_crashed && !FocusLocationBarByDefault() &&
3788 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063789 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143790 }
[email protected]32ded2212011-11-10 18:51:433791
[email protected]d8c660432011-12-22 20:51:253792 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323793}
3794
[email protected]ec6a7eb2013-04-22 17:34:223795void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3796 base::TerminationStatus status,
3797 int error_code) {
[email protected]151a63d2011-12-20 22:32:523798 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323799 // The pending page's RenderViewHost is gone.
3800 return;
3801 }
3802
[email protected]2fcdcc32014-03-05 02:14:073803 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3804 // renderer may not have made a clean exit.
3805 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533806 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073807
[email protected]698191dc2014-02-25 01:06:133808 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3809 if (dialog_manager_)
3810 dialog_manager_->CancelActiveAndPendingDialogs(this);
3811
[email protected]f738bdcb2014-07-11 20:40:443812 if (delegate_)
3813 delegate_->HideValidationMessage(this);
3814
fdegans6ce28f52015-03-19 12:52:223815 SetIsLoading(false, true, nullptr);
[email protected]420ae012009-04-24 05:16:323816 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233817 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453818
[email protected]960b0372014-05-19 18:01:003819 // Reset the loading progress. TODO(avi): What does it mean to have a
3820 // "renderer crash" when there is more than one renderer process serving a
3821 // webpage? Once this function is called at a more granular frame level, we
3822 // probably will need to more granularly reset the state here.
3823 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003824
[email protected]d8c660432011-12-22 20:51:253825 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273826 observers_,
[email protected]58d5cfe2013-07-10 02:40:523827 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323828}
3829
[email protected]b172aee2012-04-10 17:05:263830void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253831 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063832}
3833
[email protected]b172aee2012-04-10 17:05:263834void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3835 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043836 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573837 // Ensure that this state update comes from a RenderViewHost that belongs to
3838 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413839 // TODO(nasko): This should go through RenderFrameHost.
3840 // TODO(creis): We can't update state for cross-process subframes until we
3841 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573842 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413843 return;
[email protected]420ae012009-04-24 05:16:323844
3845 // We must be prepared to handle state updates for any page, these occur
3846 // when the user is scrolling and entering form data, as well as when we're
3847 // leaving a page, in which case our state may have already been moved to
3848 // the next page. The navigation controller will look up the appropriate
3849 // NavigationEntry and update it when it is notified via the delegate.
3850
3851 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583852 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323853 if (entry_index < 0)
3854 return;
[email protected]10f417c52011-12-28 21:04:233855 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323856
[email protected]691aa2f2013-05-28 22:52:043857 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323858 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043859 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323860 controller_.NotifyEntryChanged(entry, entry_index);
3861}
3862
sky8b00392d2015-01-10 00:30:283863void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3864 const GURL& url) {
3865 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3866 // If we're fullscreen only update the url if it's from the fullscreen
3867 // renderer.
3868 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3869 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3870 return;
3871 }
[email protected]6934a702011-12-20 00:04:513872 if (delegate_)
avi450ce00e2014-09-24 01:58:523873 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323874}
3875
[email protected]b172aee2012-04-10 17:05:263876void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103877#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293878 // The UI may be in an event-tracking loop, such as between the
3879 // mouse-down and mouse-up in text selection or a button click.
3880 // Defer the close until after tracking is complete, so that we
3881 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293882 // TODO(shess): This could get more fine-grained. For instance,
3883 // closing a tab in another window while selecting text in the
3884 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103885 if (view_->IsEventTracking()) {
3886 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293887 return;
3888 }
[email protected]60780f412013-02-25 16:34:103889#endif
[email protected]07707302009-11-06 00:50:293890
[email protected]420ae012009-04-24 05:16:323891 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523892 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513893 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323894}
3895
[email protected]66bbadaf2014-03-28 16:25:543896void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573897 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3898 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573899}
3900
[email protected]6f2ac772014-07-24 22:22:083901void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253902 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173903#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563904 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173905#endif
3906}
3907
3908bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3909#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563910 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173911#else
3912 return false;
3913#endif
3914}
3915
[email protected]b172aee2012-04-10 17:05:263916void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513917 if (delegate_ && delegate_->IsPopupOrPanel(this))
3918 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323919}
3920
[email protected]e3b10d12014-03-28 16:06:093921void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3922 bool to_different_document) {
fdegans6ce28f52015-03-19 12:52:223923 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:083924
3925 // Notify accessibility that the user is navigating away from the
3926 // current document.
3927 //
3928 // TODO(dmazzoni): do this using a WebContentsObserver.
3929 FrameTreeNode* ftn = static_cast<RenderFrameHostImpl*>(render_frame_host)->
3930 frame_tree_node();
3931 BrowserAccessibilityManager* manager =
3932 ftn->current_frame_host()->browser_accessibility_manager();
3933 if (manager)
3934 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:323935}
3936
fdegansc73eec22015-03-19 14:47:543937void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:323938 scoped_ptr<LoadNotificationDetails> details;
3939
[email protected]9595fd82013-04-19 21:28:493940 // Use the last committed entry rather than the active one, in case a
3941 // pending entry has been created.
3942 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203943 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493944
[email protected]420ae012009-04-24 05:16:323945 // An entry may not exist for a stop when loading an initial blank page or
3946 // if an iframe injected by script into a blank page finishes loading.
3947 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203948 base::TimeDelta elapsed =
3949 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323950
3951 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513952 entry->GetVirtualURL(),
3953 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323954 elapsed,
3955 &controller_,
3956 controller_.GetCurrentEntryIndex()));
3957 }
3958
fdegans6ce28f52015-03-19 12:52:223959 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:323960}
3961
[email protected]b172aee2012-04-10 17:05:263962void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163963 controller_.DiscardNonCommittedEntries();
3964
3965 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213966 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163967}
3968
[email protected]59167c22013-06-03 18:07:323969void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103970 has_accessed_initial_document_ = true;
3971
[email protected]d1371bf8e2014-04-19 03:26:243972 // We may have left a failed browser-initiated navigation in the address bar
3973 // to let the user edit it and try again. Clear it now that content might
3974 // show up underneath it.
3975 if (!IsLoading() && controller_.GetPendingEntry())
3976 controller_.DiscardPendingEntry();
3977
[email protected]59167c22013-06-03 18:07:323978 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503979 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323980}
3981
alexmosbe2f4c32015-03-10 02:30:233982void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
3983 const std::string& name) {
3984 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3985 FrameNameChanged(render_frame_host, name));
3986}
3987
[email protected]3f19f1a2014-05-02 05:23:273988void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473989 // No action is necessary if the opener has already been cleared.
3990 if (!opener_)
3991 return;
3992
3993 // Clear our opener so that future cross-process navigations don't have an
3994 // opener assigned.
3995 RemoveDestructionObserver(opener_);
3996 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273997
3998 // Notify all swapped out RenderViewHosts for this tab. This is important
3999 // in case we go back to them, or if another window in those processes tries
4000 // to access window.opener.
creisbbbeb062014-08-25 18:20:314001 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:274002}
4003
[email protected]39f2f9252014-05-03 00:54:014004void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294005 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094006 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294007 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094008
4009 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214010 NotificationService::current()->Notify(
4011 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4012 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294013 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084014}
4015
[email protected]ef3adfc2014-05-11 00:04:544016void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
4017 int32 page_id,
4018 const base::string16& title,
4019 base::i18n::TextDirection title_direction) {
4020 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
4021
4022 // If we have a title, that's a pretty good indication that we've started
4023 // getting useful data.
4024 SetNotWaitingForResponse();
4025
4026 // Try to find the navigation entry, which might not be the current one.
4027 // For example, it might be from a pending RVH for the pending entry.
4028 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
4029 rvh->GetSiteInstance(), page_id);
4030
4031 // We can handle title updates when we don't have an entry in
4032 // UpdateTitleForEntry, but only if the update is from the current RVH.
4033 // TODO(avi): Change to make decisions based on the RenderFrameHost.
4034 if (!entry && rvh != GetRenderViewHost())
4035 return;
4036
4037 // TODO(evan): make use of title_direction.
4038 // http://code.google.com/p/chromium/issues/detail?id=27094
4039 if (!UpdateTitleForEntry(entry, title))
4040 return;
4041
4042 // Broadcast notifications when the UI should be updated.
4043 if (entry == controller_.GetEntryAtOffset(0))
4044 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4045}
4046
4047void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4048 const std::string& encoding) {
4049 SetEncoding(encoding);
4050}
4051
[email protected]39f2f9252014-05-03 00:54:014052void WebContentsImpl::DocumentAvailableInMainFrame(
4053 RenderViewHost* render_view_host) {
4054 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4055 DocumentAvailableInMainFrame());
4056}
[email protected]e1c3a552012-05-04 20:51:324057void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4058 // Tell the active RenderViewHost to run unload handlers and close, as long
4059 // as the request came from a RenderViewHost in the same BrowsingInstance.
4060 // In most cases, we receive this from a swapped out RenderViewHost.
4061 // It is possible to receive it from one that has just been swapped in,
4062 // in which case we might as well deliver the message anyway.
4063 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
4064 GetRenderViewHost()->ClosePage();
4065}
4066
[email protected]f546640b2012-05-15 00:03:494067void WebContentsImpl::RouteMessageEvent(
4068 RenderViewHost* rvh,
4069 const ViewMsg_PostMessage_Params& params) {
4070 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:364071 // came from a RenderViewHost in the same BrowsingInstance or if this
4072 // WebContents is dedicated to a browser plugin guest.
4073 // Note: This check means that an embedder could theoretically receive a
4074 // postMessage from anyone (not just its own guests). However, this is
4075 // probably not a risk for apps since other pages won't have references
4076 // to App windows.
4077 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
4078 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:494079 return;
4080
4081 ViewMsg_PostMessage_Params new_params(params);
4082
4083 // If there is a source_routing_id, translate it to the routing ID for
4084 // the equivalent swapped out RVH in the target process. If we need
4085 // to create a swapped out RVH for the source tab, we create its opener
4086 // chain as well, since those will also be accessible to the target page.
4087 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
4088 // Try to look up the WebContents for the source page.
4089 WebContentsImpl* source_contents = NULL;
4090 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
4091 rvh->GetProcess()->GetID(), params.source_routing_id);
4092 if (source_rvh) {
4093 source_contents = static_cast<WebContentsImpl*>(
4094 source_rvh->GetDelegate()->GetAsWebContents());
4095 }
4096
4097 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:364098 if (GetBrowserPluginGuest()) {
4099 // We create a swapped out RenderView for the embedder in the guest's
4100 // render process but we intentionally do not expose the embedder's
4101 // opener chain to it.
4102 new_params.source_routing_id =
4103 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
4104 } else {
4105 new_params.source_routing_id =
4106 source_contents->CreateOpenerRenderViews(GetSiteInstance());
4107 }
[email protected]f546640b2012-05-15 00:03:494108 } else {
4109 // We couldn't find it, so don't pass a source frame.
4110 new_params.source_routing_id = MSG_ROUTING_NONE;
4111 }
4112 }
4113
4114 // In most cases, we receive this from a swapped out RenderViewHost.
4115 // It is possible to receive it from one that has just been swapped in,
4116 // in which case we might as well deliver the message anyway.
mek5b679c92015-02-28 02:38:064117 if (!params.message_ports.empty()) {
marjab5fe7ad32015-02-18 23:08:464118 // Updating the message port information has to be done in the IO thread;
4119 // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send
4120 // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution
4121 // would've been to post a task on the IO thread to do the IO-thread-bound
4122 // work, and make that post a task back to WebContentsImpl in the UI
4123 // thread. But we cannot do that, since there's nothing to guarantee that
4124 // WebContentsImpl stays alive during the round trip.
4125 scoped_refptr<MessagePortMessageFilter> message_port_message_filter(
4126 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
4127 ->message_port_message_filter());
4128 BrowserThread::PostTask(
4129 BrowserThread::IO, FROM_HERE,
4130 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
4131 message_port_message_filter, GetRoutingID(), new_params));
4132 } else {
4133 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
4134 }
[email protected]f546640b2012-05-15 00:03:494135}
4136
[email protected]a796f202012-05-30 14:14:254137bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264138 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254139 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264140 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254141 if (!delegate_)
4142 return false;
4143 return delegate_->AddMessageToConsole(this, level, message, line_no,
4144 source_id);
4145}
4146
[email protected]0eba810b2012-10-18 03:19:364147int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214148 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294149 int render_view_routing_id = MSG_ROUTING_NONE;
4150 GetRenderManager()->CreateRenderFrame(
4151 instance, nullptr, MSG_ROUTING_NONE,
4152 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4153 CREATE_RF_HIDDEN,
4154 &render_view_routing_id);
4155 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364156}
4157
[email protected]b172aee2012-04-10 17:05:264158void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274159 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254160 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224161
[email protected]ea114722012-03-12 01:11:254162 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174163 if (rdh) // NULL in unittests.
4164 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254165}
4166
[email protected]b172aee2012-04-10 17:05:264167void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444168 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254169 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444170}
4171
creiscce56cd2014-09-29 22:45:224172void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154173 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224174 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154175 return;
4176
creiscce56cd2014-09-29 22:45:224177 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4178 RenderFrameHostImpl* rfhi =
4179 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584180
[email protected]e5fc1632011-08-08 07:51:534181 // Ignore renderer unresponsive event if debugger is attached to the tab
4182 // since the event may be a result of the renderer sitting on a breakpoint.
4183 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364184 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534185 return;
4186
clamyafbf7f02015-01-21 20:38:114187 if (rfhi->IsWaitingForBeforeUnloadACK() ||
creiscce56cd2014-09-29 22:45:224188 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324189 // Hang occurred while firing the beforeunload/unload handler.
4190 // Pretend the handler fired so tab closing continues as if it had.
clamyc0a278672015-03-24 17:08:554191 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324192
[email protected]fa944cb82013-11-15 17:51:214193 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324194 return;
4195
4196 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564197 // nothing we can do to recover. If the hang is in the beforeunload handler,
4198 // pretend the beforeunload listeners have all fired and allow the delegate
4199 // to continue closing; the user will not have the option of cancelling the
4200 // close. Otherwise, pretend the unload listeners have all fired and close
4201 // the tab.
4202 bool close = true;
clamyafbf7f02015-01-21 20:38:114203 if (rfhi->IsWaitingForBeforeUnloadACK() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564204 delegate_->BeforeUnloadFired(this, true, &close);
4205 }
4206 if (close)
creiscce56cd2014-09-29 22:45:224207 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324208 return;
4209 }
4210
[email protected]9f76c1e2012-03-05 15:15:584211 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474212 return;
4213
[email protected]6934a702011-12-20 00:04:514214 if (delegate_)
4215 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324216}
4217
[email protected]b172aee2012-04-10 17:05:264218void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514219 if (delegate_)
4220 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324221}
4222
[email protected]b172aee2012-04-10 17:05:264223void WebContentsImpl::LoadStateChanged(
4224 const GURL& url,
4225 const net::LoadStateWithParam& load_state,
4226 uint64 upload_position,
4227 uint64 upload_size) {
erikchen174b78c62015-03-11 22:02:544228 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4229 // is fixed.
4230 tracked_objects::ScopedTracker tracking_profile1(
4231 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4232 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324233 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564234 upload_position_ = upload_position;
4235 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504236 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214237 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304238 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214239 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324240 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464241 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224242 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4243 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464244 }
[email protected]420ae012009-04-24 05:16:324245}
4246
[email protected]b172aee2012-04-10 17:05:264247void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554248 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324249 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124250 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4251 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514252 if (delegate_)
4253 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094254 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324255}
4256
[email protected]58d5cfe2013-07-10 02:40:524257void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544258 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234259 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224260 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544261}
4262
[email protected]b172aee2012-04-10 17:05:264263void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104264 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214265 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264266 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4267 // here during container initialization and normal window size will be set
4268 // later. In case of tab duplication this resizing to 0x0 prevents setting
4269 // normal size later so just ignore it.
4270 if (!size.IsEmpty())
4271 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324272}
4273
[email protected]af905902013-10-01 21:38:514274void WebContentsImpl::CancelModalDialogsForRenderManager() {
4275 // We need to cancel modal dialogs when doing a process swap, since the load
4276 // deferrer would prevent us from swapping out.
4277 if (dialog_manager_)
4278 dialog_manager_->CancelActiveAndPendingDialogs(this);
4279}
4280
[email protected]02d7b6e2014-06-24 21:01:504281void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4282 RenderFrameHost* new_host,
4283 bool is_main_frame) {
4284 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054285 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504286 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084287
[email protected]02d7b6e2014-06-24 21:01:504288 // Make sure the visible RVH reflects the new delegate's preferences.
4289 if (delegate_)
4290 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394291
[email protected]02d7b6e2014-06-24 21:01:504292 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4293 }
4294
4295 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544296}
4297
naskof5940b9f2015-03-02 23:04:054298void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4299 RenderViewHost* old_host,
4300 RenderViewHost* new_host) {
4301 NotifyViewSwapped(old_host, new_host);
4302}
4303
[email protected]14392a52012-05-02 20:28:444304int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4305 SiteInstance* instance) {
4306 if (!opener_)
4307 return MSG_ROUTING_NONE;
4308
4309 // Recursively create RenderViews for anything else in the opener chain.
4310 return opener_->CreateOpenerRenderViews(instance);
4311}
4312
4313int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4314 int opener_route_id = MSG_ROUTING_NONE;
4315
4316 // If this tab has an opener, ensure it has a RenderView in the given
4317 // SiteInstance as well.
4318 if (opener_)
4319 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4320
[email protected]45a22ad2013-02-21 03:25:004321 // If any of the renderers (current, pending, or swapped out) for this
4322 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214323 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4324 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374325
[email protected]fa944cb82013-11-15 17:51:214326 if (GetRenderManager()->pending_render_view_host() &&
4327 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4328 instance)
4329 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004330
[email protected]fa944cb82013-11-15 17:51:214331 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374332 instance);
4333 if (rvh)
4334 return rvh->GetRoutingID();
4335
[email protected]14392a52012-05-02 20:28:444336 // Create a swapped out RenderView in the given SiteInstance if none exists,
4337 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294338 int render_view_routing_id = MSG_ROUTING_NONE;
4339 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4340 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4341 CREATE_RF_SWAPPED_OUT |
4342 CREATE_RF_HIDDEN,
4343 &render_view_routing_id);
4344 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444345}
4346
[email protected]b172aee2012-04-10 17:05:264347NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194348 return GetController();
[email protected]3a3d47472010-07-15 21:03:544349}
4350
carlosk37f793792014-11-27 15:08:294351scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4352 const GURL& url) {
4353 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324354}
4355
[email protected]10f417c52011-12-28 21:04:234356NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264357 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324358 return controller_.GetLastCommittedEntry();
4359}
4360
[email protected]b172aee2012-04-10 17:05:264361bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164362 RenderViewHost* render_view_host,
4363 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044364 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124365 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434366 TRACE_EVENT0("browser,navigation",
4367 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444368 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484369 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164370 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4371 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4372 // case this because RWH is still a base class of RenderViewHost, and child
4373 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124374 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164375 RenderWidgetHostViewChildFrame* rwh_view_child =
4376 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164377 rwh_view = rwh_view_child;
4378 } else {
lazyboy549b3b42014-10-20 17:16:044379 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164380 }
[email protected]1a98a932009-11-17 00:12:524381
[email protected]420ae012009-04-24 05:16:324382 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444383 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214384 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324385
[email protected]74ce1ad2011-12-16 21:51:464386 // Make sure we use the correct starting page_id in the new RenderView.
4387 UpdateMaxPageIDIfNecessary(render_view_host);
4388 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584389 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464390
[email protected]9f76c1e2012-03-05 15:15:584391 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264392 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494393 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044394 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494395 max_page_id,
4396 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524397 return false;
[email protected]14392a52012-05-02 20:28:444398 }
[email protected]a4127722011-04-27 23:13:524399
avi2b177592014-12-10 02:08:024400 SetHistoryOffsetAndLengthForView(render_view_host,
4401 controller_.GetLastCommittedEntryIndex(),
4402 controller_.GetEntryCount());
4403
[email protected]a220b5932013-09-21 03:47:444404#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504405 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4406 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444407 if (rwh_view) {
4408 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4409 render_widget_host->WasResized();
4410 }
[email protected]f8233cc2011-05-31 20:24:504411#endif
4412
[email protected]420ae012009-04-24 05:16:324413 return true;
4414}
4415
[email protected]82307f6b2014-08-07 03:30:124416bool WebContentsImpl::CreateRenderFrameForRenderManager(
4417 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494418 int parent_routing_id,
4419 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434420 TRACE_EVENT0("browser,navigation",
4421 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124422
4423 RenderFrameHostImpl* rfh =
4424 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494425 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124426 return false;
4427
4428 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4429 // RenderFrameHost will have to be associated with the appropriate
4430 // RenderWidgetHostView or a new one should be created here.
4431
4432 return true;
4433}
4434
[email protected]7d244f12013-08-22 21:41:514435#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454436
[email protected]155c7f22013-12-09 17:07:184437base::android::ScopedJavaLocalRef<jobject>
4438WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404439 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564440 return GetWebContentsAndroid()->GetJavaObject();
4441}
[email protected]155c7f22013-12-09 17:07:184442
[email protected]0e813a52014-08-13 10:34:564443WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184444 WebContentsAndroid* web_contents_android =
4445 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4446 if (!web_contents_android) {
4447 web_contents_android = new WebContentsAndroid(this);
4448 SetUserData(kWebContentsAndroidKey, web_contents_android);
4449 }
[email protected]0e813a52014-08-13 10:34:564450 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184451}
4452
[email protected]7d244f12013-08-22 21:41:514453bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4454 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164455 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044456 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594457 true);
[email protected]7d244f12013-08-22 21:41:514458}
[email protected]fc2b46b2014-05-03 16:33:454459
4460#elif defined(OS_MACOSX)
4461
[email protected]75f4df72014-07-16 22:39:424462void WebContentsImpl::SetAllowOtherViews(bool allow) {
4463 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454464}
4465
[email protected]75f4df72014-07-16 22:39:424466bool WebContentsImpl::GetAllowOtherViews() {
4467 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454468}
4469
[email protected]7d244f12013-08-22 21:41:514470#endif
4471
[email protected]6fba26d2014-04-29 09:38:284472void WebContentsImpl::OnDialogClosed(int render_process_id,
4473 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264474 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494475 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264476 bool success,
[email protected]fcf75d42013-12-03 20:11:264477 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284478 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4479 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494480 last_dialog_suppressed_ = dialog_was_suppressed;
4481
[email protected]beb440c2009-11-06 04:08:544482 if (is_showing_before_unload_dialog_ && !success) {
4483 // If a beforeunload dialog is canceled, we need to stop the throbber from
4484 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284485 if (rfh)
fdegansc73eec22015-03-19 14:47:544486 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354487 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104488
[email protected]6d65a462013-06-21 21:29:124489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4490 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544491 }
[email protected]87de04b02014-04-08 22:14:494492
[email protected]beb440c2009-11-06 04:08:544493 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284494 if (rfh) {
4495 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4496 dialog_was_suppressed);
4497 } else {
4498 // Don't leak the sync IPC reply if the RFH or process is gone.
4499 delete reply_msg;
4500 }
[email protected]beb440c2009-11-06 04:08:544501}
4502
[email protected]b172aee2012-04-10 17:05:264503void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544504 if (encoding == last_reported_encoding_)
4505 return;
4506 last_reported_encoding_ = encoding;
4507
4508 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124509 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104510}
[email protected]f45d2a72010-03-08 23:28:354511
[email protected]1ac10dca2013-08-20 20:47:044512bool WebContentsImpl::IsHidden() {
4513 return capturer_count_ == 0 && !should_normally_be_visible_;
4514}
4515
[email protected]b0936d22013-11-28 06:47:364516RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214517 return frame_tree_.root()->render_manager();
4518}
4519
[email protected]b172aee2012-04-10 17:05:264520RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584521 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4522}
[email protected]7900bfdb2012-05-24 19:31:244523
[email protected]f8497342013-02-05 22:15:024524BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394525 return browser_plugin_guest_.get();
4526}
4527
[email protected]738f57a2013-06-29 21:06:544528void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4529 CHECK(!browser_plugin_guest_);
4530 browser_plugin_guest_.reset(guest);
4531}
4532
[email protected]f8497342013-02-05 22:15:024533BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394534 return browser_plugin_embedder_.get();
4535}
[email protected]8ff00d72012-10-23 19:12:214536
fsamuel60b42282015-03-10 03:29:144537void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4538 if (browser_plugin_embedder_)
4539 return;
4540 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4541}
4542
[email protected]d9030b82013-07-19 08:26:064543void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194544 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304545 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4546 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4547 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064548}
4549
4550void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304551 active_audio_players_.clear();
4552 active_video_players_.clear();
4553 audio_power_save_blocker_.reset();
4554 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064555}
4556
[email protected]fc2b46b2014-05-03 16:33:454557gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214558 gfx::Size size;
4559 if (delegate_)
4560 size = delegate_->GetSizeForNewRenderView(this);
4561 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454562 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214563 return size;
4564}
4565
[email protected]ae7eeda2014-07-04 01:53:264566void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4567 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024568 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554569}
4570
[email protected]222f5822014-02-05 23:40:494571void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4572 if (!delegate_)
4573 return;
4574 const gfx::Size new_size = GetPreferredSize();
4575 if (new_size != old_size)
4576 delegate_->UpdatePreferredSize(this, new_size);
4577}
4578
dalecurtisbc6572e12014-09-12 19:22:304579void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4580 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114581 if (!HasValidFrameSource())
4582 return;
4583
dalecurtisbc6572e12014-09-12 19:22:304584 const uintptr_t key =
4585 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4586 DCHECK(std::find((*player_map)[key].begin(),
4587 (*player_map)[key].end(),
4588 player_cookie) == (*player_map)[key].end());
4589 (*player_map)[key].push_back(player_cookie);
4590}
4591
4592void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4593 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114594 if (!HasValidFrameSource())
4595 return;
4596
dalecurtisbc6572e12014-09-12 19:22:304597 const uintptr_t key =
4598 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4599 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4600 if (it == player_map->end())
4601 return;
4602
4603 // Remove the player.
4604 PlayerList::iterator player_it =
4605 std::find(it->second.begin(), it->second.end(), player_cookie);
4606 if (player_it != it->second.end())
4607 it->second.erase(player_it);
4608
4609 // If there are no players left, remove the map entry.
4610 if (it->second.empty())
4611 player_map->erase(it);
4612}
4613
4614void WebContentsImpl::RemoveAllMediaPlayerEntries(
4615 RenderFrameHost* render_frame_host,
4616 ActiveMediaPlayerMap* player_map) {
4617 ActiveMediaPlayerMap::iterator it =
4618 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4619 if (it == player_map->end())
4620 return;
4621 player_map->erase(it);
4622}
4623
[email protected]23f41fd2014-06-21 05:29:174624void WebContentsImpl::ResumeResponseDeferredAtStart() {
4625 FrameTreeNode* node = frame_tree_.root();
4626 node->render_manager()->ResumeResponseDeferredAtStart();
4627}
4628
[email protected]34ff1cfc2014-08-20 06:16:054629void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4630 force_disable_overscroll_content_ = force_disable;
4631 if (view_)
4632 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4633}
4634
[email protected]8ff00d72012-10-23 19:12:214635} // namespace content