blob: b6ff8109294e6b8da9454c4cee3f9241cf83a6e8 [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]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.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"
[email protected]7a846df2012-09-20 19:17:3923#include "content/browser/browser_plugin/browser_plugin_embedder.h"
24#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5925#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4326#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4127#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0428#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4629#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1230#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1631#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1632#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4033#include "content/browser/frame_host/interstitial_page_impl.h"
34#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0135#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1836#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1637#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]f28ef9a32014-05-12 16:36:1038#include "content/browser/geolocation/geolocation_dispatcher_host.h"
[email protected]5c9250872012-01-30 17:24:0539#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4440#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4041#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3042#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5243#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]29998f92014-06-15 03:12:1444#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5345#include "content/browser/message_port_message_filter.h"
46#include "content/browser/message_port_service.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
[email protected]583418cc2013-01-17 14:01:10106#if defined(OS_ANDROID)
[email protected]23f41fd2014-06-21 05:29:17107#include "content/browser/android/content_view_core_impl.h"
[email protected]583418cc2013-01-17 14:01:10108#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45109#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18110#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00111#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10112#endif
113
[email protected]f66df822012-05-18 16:52:17114#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50115#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57116#endif
[email protected]3e45ba92009-02-20 21:09:00117
[email protected]420ae012009-04-24 05:16:32118// Cross-Site Navigations
119//
[email protected]b172aee2012-04-10 17:05:26120// If a WebContentsImpl is told to navigate to a different web site (as
121// determined by SiteInstance), it will replace its current RenderViewHost with
122// a new RenderViewHost dedicated to the new SiteInstance. This works as
123// follows:
[email protected]420ae012009-04-24 05:16:32124//
[email protected]fc6c1872013-10-03 01:22:35125// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46126// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32127// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35128// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32129// run in the current RVH.
130// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35131// that it has a pending cross-site request. We will check this on the IO
132// thread when deciding how to handle the response.
133// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46134// cancel all the pending logic. Otherwise we allow the pending RVH to send
135// the navigation request to its renderer.
136// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35137// main resource load on the pending RVH. It creates a
138// CrossSiteResourceHandler to check whether a process swap is needed when
139// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46140// - When RDH receives a response, the BufferedResourceHandler determines
141// whether it is a download. If so, it sends a message to the new renderer
142// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26143// pending RVH remains until the next DidNavigate event for this
144// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32145// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35146// download, the CrossSiteResourceHandler checks whether a process swap is
147// needed (either because CrossSiteRequestManager has state for it or because
148// a transfer was needed for a redirect).
149// - If so, CrossSiteResourceHandler pauses the response to first run the old
150// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36151// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
152// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35153// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
154// to a new process is needed, based on the stored pending_nav_params_. (This
155// is independent of whether we started out with a cross-process navigation.)
156// - If not, it just tells the ResourceDispatcherHost to resume the response
157// to its current RenderViewHost.
158// - If so, it cancels the current pending RenderViewHost and sets up a new
159// navigation using RequestTransferURL. When the transferred request
160// arrives in the ResourceDispatcherHost, we transfer the response and
161// resume it.
[email protected]420ae012009-04-24 05:16:32162// - The pending renderer sends a FrameNavigate message that invokes the
163// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46164// pending RVH.
[email protected]b0936d22013-11-28 06:47:36165// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15166// the user goes back. The process only stays live if another tab is using
167// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32168
[email protected]8ff00d72012-10-23 19:12:21169namespace content {
[email protected]420ae012009-04-24 05:16:32170namespace {
171
[email protected]960b0372014-05-19 18:01:00172const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
173
174// This matches what Blink's ProgressTracker has traditionally used for a
175// minimum progress value.
176const double kMinimumLoadingProgress = 0.1;
177
[email protected]82114f52012-03-20 22:53:41178const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05179
[email protected]155c7f22013-12-09 17:07:18180#if defined(OS_ANDROID)
181const char kWebContentsAndroidKey[] = "web_contents_android";
182#endif // OS_ANDROID
183
[email protected]e4abd3b42013-11-12 18:28:47184base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46185g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
186
thestigc4cac8f2014-09-04 21:17:50187static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39188 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29189 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30190 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02191 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58192 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02193 ++g_next_image_download_id,
194 url,
195 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30196 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02197 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39198}
199
[email protected]8bfc8272013-09-09 20:10:53200void NotifyCacheOnIO(
201 scoped_refptr<net::URLRequestContextGetter> request_context,
202 const GURL& url,
203 const std::string& http_method) {
204 request_context->GetURLRequestContext()->http_transaction_factory()->
205 GetCache()->OnExternalCacheHit(url, http_method);
206}
207
[email protected]9b159a52013-10-03 17:24:55208// Helper function for retrieving all the sites in a frame tree.
209bool CollectSites(BrowserContext* context,
210 std::set<GURL>* sites,
211 FrameTreeNode* node) {
212 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
213 return true;
214}
215
[email protected]a86c0e962013-12-17 17:10:39216bool ForEachFrameInternal(
217 const base::Callback<void(RenderFrameHost*)>& on_frame,
218 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41219 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39220 return true;
221}
222
[email protected]95640212014-07-26 18:14:30223bool ForEachPendingFrameInternal(
224 const base::Callback<void(RenderFrameHost*)>& on_frame,
225 FrameTreeNode* node) {
226 RenderFrameHost* pending_frame_host =
227 node->render_manager()->pending_frame_host();
228 if (pending_frame_host)
229 on_frame.Run(pending_frame_host);
230 return true;
231}
232
[email protected]a86c0e962013-12-17 17:10:39233void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
234 IPC::Message* message_copy = new IPC::Message(*message);
235 message_copy->set_routing_id(rfh->GetRoutingID());
236 rfh->Send(message_copy);
237}
238
[email protected]948481d2014-06-11 18:32:22239void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
240 RenderFrameHost* rfh) {
241 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
242 ->frame_tree_node()
243 ->render_manager()
244 ->GetRenderWidgetHostView();
245 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59246}
247
[email protected]95640212014-07-26 18:14:30248void SetAccessibilityModeOnFrame(AccessibilityMode mode,
249 RenderFrameHost* frame_host) {
250 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
251}
252
[email protected]420ae012009-04-24 05:16:32253} // namespace
254
[email protected]54944cde2012-12-09 09:24:59255WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15256 return WebContentsImpl::CreateWithOpener(
257 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19258}
259
260WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59261 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30262 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59263 WebContentsImpl* new_contents = new WebContentsImpl(
264 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30265
266 for (SessionStorageNamespaceMap::const_iterator it =
267 session_storage_namespace_map.begin();
268 it != session_storage_namespace_map.end();
269 ++it) {
270 new_contents->GetController()
271 .SetSessionStorageNamespace(it->first, it->second.get());
272 }
273
[email protected]54944cde2012-12-09 09:24:59274 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19275 return new_contents;
[email protected]a81343d232011-12-27 07:39:20276}
[email protected]746d3052012-05-22 15:15:47277
[email protected]e4abd3b42013-11-12 18:28:47278void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46279 g_created_callbacks.Get().push_back(callback);
280}
281
[email protected]e4abd3b42013-11-12 18:28:47282void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46283 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
284 if (g_created_callbacks.Get().at(i).Equals(callback)) {
285 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
286 return;
287 }
288 }
289}
290
[email protected]299d7f12012-05-23 05:31:15291WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47292 return rvh->GetDelegate()->GetAsWebContents();
293}
294
[email protected]a86c0e962013-12-17 17:10:39295WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
296 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
297 if (!rfh_impl)
298 return NULL;
299 return rfh_impl->delegate()->GetAsWebContents();
300}
301
[email protected]7fff43e2013-05-21 20:21:10302// WebContentsImpl::DestructionObserver ----------------------------------------
303
304class WebContentsImpl::DestructionObserver : public WebContentsObserver {
305 public:
306 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
307 : WebContentsObserver(watched_contents),
308 owner_(owner) {
309 }
310
311 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58312 virtual void WebContentsDestroyed() OVERRIDE {
313 owner_->OnWebContentsDestroyed(
314 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10315 }
316
317 private:
318 WebContentsImpl* owner_;
319
320 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
321};
322
[email protected]8ed16472014-04-11 19:02:48323WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
324 int render_frame_id,
325 ColorChooser* chooser,
326 int identifier)
327 : render_process_id(render_process_id),
328 render_frame_id(render_frame_id),
329 chooser(chooser),
330 identifier(identifier) {
331}
332
333WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
334}
335
[email protected]b172aee2012-04-10 17:05:26336// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32337
[email protected]b172aee2012-04-10 17:05:26338WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21339 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19340 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42341 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22342 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57343 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44344 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49345 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08346#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41347 accessible_parent_(NULL),
348#endif
[email protected]6ea6bdf2013-12-06 13:35:01349 frame_tree_(new NavigatorImpl(&controller_, this),
350 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34351 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03352 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23353 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
354 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34355 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26356 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00357 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00358 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56359 upload_size_(0),
360 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47361 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10362 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55363 capturer_count_(0),
364 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57365 is_being_destroyed_(false),
366 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15367 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01368 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02369 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38370 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21371 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
372 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29373 totalPinchGestureAmount_(0),
374 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44375 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42376 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03377 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49378 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05379 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30380 last_dialog_suppressed_(false),
381 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30382 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46383 audio_stream_monitor_(this),
384 loading_weak_factory_(this) {
[email protected]cbb1ef592013-06-05 19:49:46385 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
386 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55387 frame_tree_.SetFrameRemoveListener(
388 base::Bind(&WebContentsImpl::OnFrameRemoved,
389 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35390}
initial.commit09911bf2008-07-26 23:55:29391
[email protected]b172aee2012-04-10 17:05:26392WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32393 is_being_destroyed_ = true;
394
[email protected]21b41c7e892014-02-28 01:52:24395 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
396 // shutdown and be deleted as well.
397 frame_tree_.ForEach(
398 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
399
[email protected]d9030b82013-07-19 08:26:06400 ClearAllPowerSaveBlockers();
401
[email protected]b24b68a2012-09-24 21:57:26402 for (std::set<RenderWidgetHostImpl*>::iterator iter =
403 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
404 (*iter)->DetachDelegate();
405 }
406 created_widgets_.clear();
407
[email protected]3ab9cb82011-06-03 18:02:07408 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15409 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11410 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07411
[email protected]8ed16472014-04-11 19:02:48412 if (color_chooser_info_.get())
413 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20414
[email protected]420ae012009-04-24 05:16:32415 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32416
[email protected]ca13a442012-04-17 14:00:12417 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21418 NotificationService::current()->Notify(
419 NOTIFICATION_WEB_CONTENTS_DESTROYED,
420 Source<WebContents>(this),
421 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32422
[email protected]df0c843f2014-05-23 20:37:23423 // Destroy all frame tree nodes except for the root; this notifies observers.
424 frame_tree_.ResetForMainFrameSwap();
425 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59426
[email protected]df0c843f2014-05-23 20:37:23427 // Manually call the observer methods for the root frame tree node.
428 RenderFrameHostManager* root = GetRenderManager();
429 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27430 FOR_EACH_OBSERVER(WebContentsObserver,
431 observers_,
[email protected]df0c843f2014-05-23 20:37:23432 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27433 }
[email protected]df0c843f2014-05-23 20:37:23434 FOR_EACH_OBSERVER(WebContentsObserver,
435 observers_,
436 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27437
[email protected]df0c843f2014-05-23 20:37:23438 if (root->pending_render_view_host()) {
439 FOR_EACH_OBSERVER(WebContentsObserver,
440 observers_,
441 RenderViewDeleted(root->pending_render_view_host()));
442 }
[email protected]c06c58c2014-03-12 20:31:59443
[email protected]f273ee52013-10-18 16:05:27444 FOR_EACH_OBSERVER(WebContentsObserver,
445 observers_,
[email protected]df0c843f2014-05-23 20:37:23446 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27447
[email protected]2db9bd72012-04-13 20:20:56448 FOR_EACH_OBSERVER(WebContentsObserver,
449 observers_,
[email protected]12a46832014-05-09 13:35:58450 WebContentsDestroyed());
451
452 FOR_EACH_OBSERVER(WebContentsObserver,
453 observers_,
454 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08455
[email protected]6934a702011-12-20 00:04:51456 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10457
458 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
459 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42460}
461
[email protected]d1198fd2012-08-13 22:50:19462WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59463 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19464 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03465 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59466 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06467 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19468
[email protected]4858e432014-06-23 18:14:17469 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06470 // This makes |new_contents| act as a guest.
471 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16472 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06473 // We are instantiating a WebContents for browser plugin. Set its subframe
474 // bit to true.
475 new_contents->is_subframe_ = true;
476 }
[email protected]54944cde2012-12-09 09:24:59477 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19478 return new_contents;
479}
480
[email protected]95640212014-07-26 18:14:30481// static
482std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
483 std::vector<WebContentsImpl*> result;
484 scoped_ptr<RenderWidgetHostIterator> widgets(
485 RenderWidgetHostImpl::GetRenderWidgetHosts());
486 std::set<WebContentsImpl*> web_contents_set;
487 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
488 if (!rwh->IsRenderView())
489 continue;
490 RenderViewHost* rvh = RenderViewHost::From(rwh);
491 if (!rvh)
492 continue;
493 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
494 if (!web_contents)
495 continue;
496 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
497 if (web_contents_set.find(wci) == web_contents_set.end()) {
498 web_contents_set.insert(wci);
499 result.push_back(wci);
500 }
501 }
502 return result;
503}
504
[email protected]b0936d22013-11-28 06:47:36505RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21506 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28507}
508
[email protected]7bb761892012-07-20 09:32:47509bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
510 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44511 return OnMessageReceived(render_view_host, NULL, message);
512}
513
514bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
515 RenderFrameHost* render_frame_host,
516 const IPC::Message& message) {
517 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56518 if (GetWebUI() &&
519 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17520 return true;
[email protected]d2353452012-01-19 19:53:56521 }
[email protected]f82d57b52011-04-27 19:13:17522
[email protected]d8c660432011-12-22 20:51:25523 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
524 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33525 if (render_frame_host) {
526 while ((observer = it.GetNext()) != NULL)
527 if (observer->OnMessageReceived(message, render_frame_host))
528 return true;
529 } else {
530 while ((observer = it.GetNext()) != NULL)
531 if (observer->OnMessageReceived(message))
532 return true;
533 }
[email protected]403415a2011-01-10 18:57:53534
[email protected]1d62cf72014-02-07 21:31:57535 // Message handlers should be aware of which
536 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
537 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02538 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57539 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02540 else
[email protected]1d62cf72014-02-07 21:31:57541 render_view_message_source_ = render_view_host;
542
[email protected]724159a2010-12-30 01:11:18543 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33544 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44545 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
546 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40547 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
548 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05549 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
550 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48551 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
552 OnDocumentLoadedInFrame)
553 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00554 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
555 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
556 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
557 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48558 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
559 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
560 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
561 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19562 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
563 OnMediaPlayingNotification)
564 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
565 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11566 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
567 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18568 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
569 OnDidLoadResourceFromMemoryCache)
570 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
571 OnDidDisplayInsecureContent)
572 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
573 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25574 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26575 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21576 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20577 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
578 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20579 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
580 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16581 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10582 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50583 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50584#if defined(ENABLE_PLUGINS)
[email protected]d8415ad92012-08-23 14:40:50585 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
586 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55587 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
588 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50589#endif
[email protected]41225fe2013-03-29 05:32:02590 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
591 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07592 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
593 OnShowValidationMessage)
594 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
595 OnHideValidationMessage)
596 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
597 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48598#if defined(OS_ANDROID)
599 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
600 OnFindMatchRectsReply)
601 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
602 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48603#endif
[email protected]724159a2010-12-30 01:11:18604 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33605 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44606 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57607 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18608
[email protected]724159a2010-12-30 01:11:18609 return handled;
610}
611
[email protected]b172aee2012-04-10 17:05:26612void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18613 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21614 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43615 if (delegate_)
616 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18617}
618
[email protected]d1198fd2012-08-13 22:50:19619NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56620 return controller_;
621}
622
[email protected]d1198fd2012-08-13 22:50:19623const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56624 return controller_;
625}
626
[email protected]8ff00d72012-10-23 19:12:21627BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55628 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30629}
630
[email protected]b172aee2012-04-10 17:05:26631const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24632 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32633 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51634 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31635}
636
[email protected]a093ce02013-07-22 20:53:14637const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24638 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32639 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24640 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
641}
642
643const GURL& WebContentsImpl::GetLastCommittedURL() const {
644 // We may not have a navigation entry yet.
645 NavigationEntry* entry = controller_.GetLastCommittedEntry();
646 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
647}
648
[email protected]8ff00d72012-10-23 19:12:21649WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31650 return delegate_;
651}
652
[email protected]8ff00d72012-10-23 19:12:21653void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31654 // TODO(cbentzel): remove this debugging code?
655 if (delegate == delegate_)
656 return;
657 if (delegate_)
658 delegate_->Detach(this);
659 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08660 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31661 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08662 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00663 if (view_)
[email protected]e85165c642014-06-10 14:34:31664 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08665 }
[email protected]be1f56ab2011-12-22 06:55:31666}
667
[email protected]8ff00d72012-10-23 19:12:21668RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21669 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41670 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16671}
672
[email protected]60eca4eb2013-12-06 00:02:16673RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41674 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16675}
676
[email protected]9c9343b2014-03-08 02:56:07677RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
678 if (!frame_tree_.GetFocusedFrame())
679 return NULL;
680 return frame_tree_.GetFocusedFrame()->current_frame_host();
681}
682
[email protected]a86c0e962013-12-17 17:10:39683void WebContentsImpl::ForEachFrame(
684 const base::Callback<void(RenderFrameHost*)>& on_frame) {
685 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
686}
687
688void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
689 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
690 delete message;
691}
692
[email protected]b172aee2012-04-10 17:05:26693RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21694 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31695}
696
[email protected]6b618e62012-08-16 12:59:18697int WebContentsImpl::GetRoutingID() const {
698 if (!GetRenderViewHost())
699 return MSG_ROUTING_NONE;
700
701 return GetRenderViewHost()->GetRoutingID();
702}
703
[email protected]44470a22013-01-24 01:21:54704int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
705 return fullscreen_widget_routing_id_;
706}
707
[email protected]b172aee2012-04-10 17:05:26708RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21709 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31710}
711
[email protected]4aebbca2013-09-17 22:26:49712RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
713 const {
714 RenderWidgetHost* const widget_host =
715 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
716 GetFullscreenWidgetRoutingID());
717 return widget_host ? widget_host->GetView() : NULL;
718}
719
[email protected]8ff00d72012-10-23 19:12:21720WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31721 return view_.get();
722}
723
[email protected]95640212014-07-26 18:14:30724void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
725 if (mode == accessibility_mode_)
726 return;
727
728 accessibility_mode_ = mode;
729 frame_tree_.ForEach(
730 base::Bind(&ForEachFrameInternal,
731 base::Bind(&SetAccessibilityModeOnFrame, mode)));
732 frame_tree_.ForEach(
733 base::Bind(&ForEachPendingFrameInternal,
734 base::Bind(&SetAccessibilityModeOnFrame, mode)));
735}
736
737void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50738 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30739}
740
741void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50742 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30743}
744
[email protected]8ff00d72012-10-23 19:12:21745WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56746 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03747 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
748 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22749 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58750 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22751 web_ui->SetController(controller);
752 return web_ui;
753 }
754
755 delete web_ui;
756 return NULL;
757}
758
[email protected]8ff00d72012-10-23 19:12:21759WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21760 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
761 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31762}
763
[email protected]8ff00d72012-10-23 19:12:21764WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21765 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34766}
767
[email protected]86ef6a392012-05-11 22:03:11768void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22769 if (GetUserAgentOverride() == override)
770 return;
771
772 renderer_preferences_.user_agent_override = override;
773
774 // Send the new override string to the renderer.
775 RenderViewHost* host = GetRenderViewHost();
776 if (host)
777 host->SyncRendererPrefs();
778
779 // Reload the page if a load is currently in progress to avoid having
780 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27781 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22782 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
783 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53784
785 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
786 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11787}
788
789const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22790 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11791}
792
[email protected]95640212014-07-26 18:14:30793void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
794 AddAccessibilityMode(AccessibilityModeTreeOnly);
795}
796
797bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
798 return accessibility_mode_ == AccessibilityModeTreeOnly;
799}
800
801bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
802 return accessibility_mode_ == AccessibilityModeComplete;
803}
804
[email protected]2ceee8f2014-01-14 18:02:08805#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41806void WebContentsImpl::SetParentNativeViewAccessible(
807gfx::NativeViewAccessible accessible_parent) {
808 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30809 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
810 if (rfh)
811 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41812}
813#endif
814
[email protected]fcf75d42013-12-03 20:11:26815const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55816 // Transient entries take precedence. They are used for interstitial pages
817 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23818 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08819 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21820 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30821 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23822 if (entry) {
[email protected]b5cca982011-05-26 04:42:08823 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23824 }
[email protected]fa944cb82013-11-15 17:51:21825 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
826 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58827 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54828 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32829 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54830 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35831 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26832 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54833 if (!title.empty())
834 return title;
835 }
836 }
837
838 // We use the title for the last committed entry rather than a pending
839 // navigation entry. For example, when the user types in a URL, we want to
840 // keep the old page's title until the new load has committed and we get a new
841 // title.
[email protected]96d185d2009-04-24 03:28:54842 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32843
[email protected]9eeafc012013-11-25 23:49:47844 // We make an exception for initial navigations.
845 if (controller_.IsInitialNavigation()) {
846 // We only want to use the title from the visible entry in one of two cases:
847 // 1. There's already a committed entry for an initial navigation, in which
848 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
849 // 2. The pending entry has been explicitly assigned a title to display.
850 //
851 // If there's no last committed entry and no assigned title, we should fall
852 // back to |page_title_when_no_navigation_entry_| rather than showing the
853 // URL.
854 if (entry ||
855 (controller_.GetVisibleEntry() &&
856 !controller_.GetVisibleEntry()->GetTitle().empty())) {
857 entry = controller_.GetVisibleEntry();
858 }
859 }
[email protected]59167c22013-06-03 18:07:32860
[email protected]45d0ef7f2011-01-05 13:46:23861 if (entry) {
[email protected]b5cca982011-05-26 04:42:08862 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23863 }
[email protected]987fc3a2011-05-26 14:18:09864
865 // |page_title_when_no_navigation_entry_| is finally used
866 // if no title cannot be retrieved.
867 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54868}
869
[email protected]b172aee2012-04-10 17:05:26870int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46871 return GetMaxPageIDForSiteInstance(GetSiteInstance());
872}
873
[email protected]b172aee2012-04-10 17:05:26874int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
875 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33876 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
877 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46878
[email protected]b6583592012-01-25 19:52:33879 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34880}
881
[email protected]b172aee2012-04-10 17:05:26882void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46883 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
884}
885
[email protected]b172aee2012-04-10 17:05:26886void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33887 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46888 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33889 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34890}
891
[email protected]ec6c05f2013-10-23 18:41:57892void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
893 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
894 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57895}
896
[email protected]b172aee2012-04-10 17:05:26897SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21898 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54899}
900
[email protected]b172aee2012-04-10 17:05:26901SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21902 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
903 GetRenderManager()->pending_render_view_host() :
904 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58905 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38906}
907
[email protected]b172aee2012-04-10 17:05:26908bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31909 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49910}
911
[email protected]6dfed692014-05-22 04:18:03912bool WebContentsImpl::IsLoadingToDifferentDocument() const {
913 return is_loading_ && is_load_to_different_document_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03917 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31918}
919
[email protected]b172aee2012-04-10 17:05:26920const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31921 return load_state_;
922}
923
[email protected]fcf75d42013-12-03 20:11:26924const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31925 return load_state_host_;
926}
927
[email protected]b172aee2012-04-10 17:05:26928uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31929 return upload_size_;
930}
931
[email protected]b172aee2012-04-10 17:05:26932uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return upload_position_;
934}
935
[email protected]1ae93fb2013-06-14 03:38:56936std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56937 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39938 frame_tree_.ForEach(base::Bind(&CollectSites,
939 base::Unretained(GetBrowserContext()),
940 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56941 return sites;
942}
943
[email protected]b172aee2012-04-10 17:05:26944const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54945 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31946}
947
[email protected]b172aee2012-04-10 17:05:26948bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31949 return displayed_insecure_content_;
950}
951
[email protected]222f5822014-02-05 23:40:49952void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25953 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55954 ++capturer_count_;
955 DVLOG(1) << "There are now " << capturer_count_
956 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49957
958 // Note: This provides a hint to upstream code to size the views optimally
959 // for quality (e.g., to avoid scaling).
960 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
961 preferred_size_for_capture_ = capture_size;
962 OnPreferredSizeChanged(preferred_size_);
963 }
[email protected]54597982013-02-06 01:59:55964}
965
966void WebContentsImpl::DecrementCapturerCount() {
967 --capturer_count_;
968 DVLOG(1) << "There are now " << capturer_count_
969 << " capturing(s) of WebContentsImpl@" << this;
970 DCHECK_LE(0, capturer_count_);
971
[email protected]5a652232013-02-12 06:15:25972 if (is_being_destroyed_)
973 return;
974
[email protected]222f5822014-02-05 23:40:49975 if (capturer_count_ == 0) {
976 const gfx::Size old_size = preferred_size_for_capture_;
977 preferred_size_for_capture_ = gfx::Size();
978 OnPreferredSizeChanged(old_size);
979 }
980
[email protected]1ac10dca2013-08-20 20:47:04981 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55982 DVLOG(1) << "Executing delayed WasHidden().";
983 WasHidden();
984 }
[email protected]be1f56ab2011-12-22 06:55:31985}
986
[email protected]f2bd40812013-07-20 04:30:44987int WebContentsImpl::GetCapturerCount() const {
988 return capturer_count_;
989}
990
miu50f97892014-09-22 22:49:52991bool WebContentsImpl::IsAudioMuted() const {
992 return audio_muter_.get() && audio_muter_->is_muting();
993}
994
995void WebContentsImpl::SetAudioMuted(bool mute) {
996 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
997 << " for WebContentsImpl@" << this;
998
999 if (mute == IsAudioMuted())
1000 return;
1001
1002 if (mute) {
1003 if (!audio_muter_)
1004 audio_muter_.reset(new WebContentsAudioMuter(this));
1005 audio_muter_->StartMuting();
1006 } else {
1007 DCHECK(audio_muter_);
1008 audio_muter_->StopMuting();
1009 }
1010
1011 // Notification for UI updates in response to the changed muting state.
1012 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1013}
1014
[email protected]b172aee2012-04-10 17:05:261015bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311016 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1017 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1018 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491019}
1020
[email protected]b172aee2012-04-10 17:05:261021void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1022 int error_code) {
[email protected]443b80e2010-12-14 00:42:231023 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341024 return;
1025
[email protected]443b80e2010-12-14 00:42:231026 crashed_status_ = status;
1027 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211028 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341029}
1030
[email protected]b172aee2012-04-10 17:05:261031base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311032 return crashed_status_;
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311036 return is_being_destroyed_;
1037}
1038
[email protected]7f924832014-08-09 05:57:221039void WebContentsImpl::NotifyNavigationStateChanged(
1040 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301041 // Create and release the audio power save blocker depending on whether the
1042 // tab is actively producing audio or not.
1043 if (changed_flags == INVALIDATE_TYPE_TAB &&
1044 AudioStreamMonitor::monitoring_available()) {
1045 if (WasRecentlyAudible()) {
1046 if (!audio_power_save_blocker_)
1047 CreateAudioPowerSaveBlocker();
1048 } else {
1049 audio_power_save_blocker_.reset();
1050 }
1051 }
1052
[email protected]d5f942ba2008-09-26 19:30:341053 if (delegate_)
1054 delegate_->NavigationStateChanged(this, changed_flags);
1055}
1056
[email protected]9a890452014-02-13 22:21:021057base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1058 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331059}
1060
[email protected]9e2e4632012-07-27 16:38:411061void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541062 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591063
[email protected]948481d2014-06-11 18:32:221064 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1065 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591066 iter != widgets.end();
1067 iter++) {
[email protected]948481d2014-06-11 18:32:221068 if (*iter) {
1069 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431070#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221071 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431072#endif
[email protected]de3c5d82014-05-28 22:12:591073 }
[email protected]789e9152009-08-04 21:59:431074 }
[email protected]96d185d2009-04-24 03:28:541075
[email protected]9a890452014-02-13 22:21:021076 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381077
[email protected]b9769d82012-02-10 00:23:591078 // The resize rect might have changed while this was inactive -- send the new
1079 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581080 RenderViewHostImpl* rvh =
1081 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591082 if (rvh) {
1083 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1084 }
[email protected]96d185d2009-04-24 03:28:541085
dalecurtisbc6572e12014-09-12 19:22:301086 // Restore power save blocker if there are active video players running.
1087 if (!active_video_players_.empty() && !video_power_save_blocker_)
1088 CreateVideoPowerSaveBlocker();
1089
[email protected]c0d9d5672013-10-09 07:38:031090 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1091
[email protected]54597982013-02-06 01:59:551092 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311093}
1094
[email protected]b172aee2012-04-10 17:05:261095void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551096 // If there are entities capturing screenshots or video (e.g., mirroring),
1097 // don't activate the "disable rendering" optimization.
1098 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521099 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551100 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261101 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521102 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331103 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521104 // calls us).
[email protected]948481d2014-06-11 18:32:221105 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1106 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591107 iter != widgets.end();
1108 iter++) {
[email protected]948481d2014-06-11 18:32:221109 if (*iter)
1110 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591111 }
dalecurtisbc6572e12014-09-12 19:22:301112
1113 // Release any video power save blockers held as video is not visible.
1114 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541115 }
1116
[email protected]c0d9d5672013-10-09 07:38:031117 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1118
[email protected]54597982013-02-06 01:59:551119 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371120}
1121
[email protected]b172aee2012-04-10 17:05:261122bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311123 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271124 return WillNotifyDisconnection() &&
1125 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581126 !static_cast<RenderViewHostImpl*>(
1127 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311128}
1129
[email protected]1c3f80bd2014-04-08 23:02:061130void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1131 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1132 for_cross_site_transition);
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211136 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401137 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271138}
1139
[email protected]b172aee2012-04-10 17:05:261140WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441141 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451142 // We pass our own opener so that the cloned page can access it if it was
1143 // before.
[email protected]54944cde2012-12-09 09:24:591144 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451145 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591146 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191147 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221148 FOR_EACH_OBSERVER(WebContentsObserver,
1149 observers_,
1150 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271151 return tc;
1152}
1153
[email protected]14392a52012-05-02 20:28:441154void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211155 const NotificationSource& source,
1156 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441157 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211158 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1159 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031160 RenderWidgetHostView* view = host->GetView();
1161 if (view == GetFullscreenRenderWidgetHostView()) {
1162 // We cannot just call view_->RestoreFocus() here. On some platforms,
1163 // attempting to focus the currently-invisible WebContentsView will be
1164 // flat-out ignored. Therefore, this boolean is used to track whether
1165 // we will request focus after the fullscreen widget has been
1166 // destroyed.
1167 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1168 } else {
1169 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1170 i != pending_widget_views_.end(); ++i) {
1171 if (host->GetView() == i->second) {
1172 pending_widget_views_.erase(i);
1173 break;
1174 }
[email protected]bafe6cd2012-05-23 23:09:501175 }
1176 }
1177 break;
1178 }
[email protected]14392a52012-05-02 20:28:441179 default:
1180 NOTREACHED();
1181 }
1182}
1183
[email protected]ec6c05f2013-10-23 18:41:571184WebContents* WebContentsImpl::GetWebContents() {
1185 return this;
1186}
1187
[email protected]54944cde2012-12-09 09:24:591188void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211189 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361190 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211191 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431192 should_normally_be_visible_ = !params.initially_hidden;
1193
[email protected]fa944cb82013-11-15 17:51:211194 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041195 params.browser_context, params.site_instance, params.routing_id,
1196 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191197
[email protected]fc2b46b2014-05-03 16:33:451198 WebContentsViewDelegate* delegate =
1199 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1200
1201 if (browser_plugin_guest_) {
1202 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1203 this, delegate, &render_view_host_delegate_view_));
1204
1205 WebContentsViewGuest* rv = new WebContentsViewGuest(
1206 this, browser_plugin_guest_.get(), platform_view.Pass(),
1207 render_view_host_delegate_view_);
1208 render_view_host_delegate_view_ = rv;
1209 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191210 } else {
[email protected]fc2b46b2014-05-03 16:33:451211 // Regular WebContentsView.
1212 view_.reset(CreateWebContentsView(
1213 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191214 }
[email protected]fc2b46b2014-05-03 16:33:451215 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191216 CHECK(view_.get());
1217
[email protected]ed245db2012-12-18 08:00:451218 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591219 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191220
1221 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101222 if (opener_)
1223 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191224
1225 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211226 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1227 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101228
1229 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
[email protected]29998f92014-06-15 03:12:141230 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101231
[email protected]01f83f92014-06-17 14:41:541232 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091233 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541234
mlamouriefdca9d2014-09-16 16:55:401235 manifest_manager_host_.reset(new ManifestManagerHost(this));
1236
[email protected]c7654a232013-06-12 21:04:441237#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101238 date_time_chooser_.reset(new DateTimeChooserAndroid());
1239#endif
[email protected]d1198fd2012-08-13 22:50:191240}
1241
[email protected]7fff43e2013-05-21 20:21:101242void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1243 RemoveDestructionObserver(web_contents);
1244
[email protected]14392a52012-05-02 20:28:441245 // Clear the opener if it has been closed.
1246 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441247 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511248 return;
[email protected]14392a52012-05-02 20:28:441249 }
[email protected]ceee8cd2013-03-08 04:59:511250 // Clear a pending contents that has been closed before being shown.
1251 for (PendingContents::iterator iter = pending_contents_.begin();
1252 iter != pending_contents_.end();
1253 ++iter) {
1254 if (iter->second != web_contents)
1255 continue;
1256 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511257 return;
1258 }
1259 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441260}
1261
[email protected]7fff43e2013-05-21 20:21:101262void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1263 if (!ContainsKey(destruction_observers_, web_contents)) {
1264 destruction_observers_[web_contents] =
1265 new DestructionObserver(this, web_contents);
1266 }
1267}
1268
1269void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1270 DestructionObservers::iterator iter =
1271 destruction_observers_.find(web_contents);
1272 if (iter != destruction_observers_.end()) {
1273 delete destruction_observers_[web_contents];
1274 destruction_observers_.erase(iter);
1275 }
1276}
1277
[email protected]b172aee2012-04-10 17:05:261278void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311279 observers_.AddObserver(observer);
1280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311283 observers_.RemoveObserver(observer);
1284}
1285
[email protected]948481d2014-06-11 18:32:221286std::set<RenderWidgetHostView*>
1287WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1288 std::set<RenderWidgetHostView*> set;
1289 if (ShowingInterstitialPage()) {
1290 set.insert(GetRenderWidgetHostView());
1291 } else {
1292 ForEachFrame(
1293 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1294 }
[email protected]de3c5d82014-05-28 22:12:591295 return set;
1296}
1297
[email protected]b172aee2012-04-10 17:05:261298void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341299 if (delegate_)
1300 delegate_->ActivateContents(this);
1301}
1302
[email protected]b172aee2012-04-10 17:05:261303void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121304 if (delegate_)
1305 delegate_->DeactivateContents(this);
1306}
1307
[email protected]b172aee2012-04-10 17:05:261308void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481309 if (delegate_)
1310 delegate_->LostCapture();
1311}
1312
[email protected]b24b68a2012-09-24 21:57:261313void WebContentsImpl::RenderWidgetDeleted(
1314 RenderWidgetHostImpl* render_widget_host) {
1315 if (is_being_destroyed_) {
1316 // |created_widgets_| might have been destroyed.
1317 return;
1318 }
1319
1320 std::set<RenderWidgetHostImpl*>::iterator iter =
1321 created_widgets_.find(render_widget_host);
1322 if (iter != created_widgets_.end())
1323 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541324
1325 if (render_widget_host &&
1326 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491327 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1328 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541329 FOR_EACH_OBSERVER(WebContentsObserver,
1330 observers_,
1331 DidDestroyFullscreenWidget(
1332 fullscreen_widget_routing_id_));
1333 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031334 if (fullscreen_widget_had_focus_at_shutdown_)
1335 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541336 }
[email protected]b24b68a2012-09-24 21:57:261337}
1338
[email protected]b172aee2012-04-10 17:05:261339bool WebContentsImpl::PreHandleKeyboardEvent(
1340 const NativeWebKeyboardEvent& event,
1341 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481342 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131343 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481344}
1345
[email protected]b172aee2012-04-10 17:05:261346void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101347 if (browser_plugin_embedder_ &&
1348 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1349 return;
1350 }
[email protected]63954792011-07-11 04:17:481351 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131352 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481353}
1354
[email protected]d92026ef2014-03-03 21:04:131355bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461356 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191357#if !defined(OS_MACOSX)
1358 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1359 // isn't done for two reasons:
1360 // -the OS already has a gesture to do this through pinch-zoom
1361 // -if a user starts an inertial scroll, let's go, and presses control
1362 // (i.e. control+tab) then the OS's buffered scroll events will come in
1363 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521364 if (delegate_ &&
1365 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551366 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1367 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1368 // gestures, which are regrettably easy to trigger accidentally.
1369 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521370 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1371 return true;
1372 }
[email protected]bccc4472013-04-18 16:37:191373#endif
[email protected]fb3f066e2013-02-12 19:12:521374 return false;
1375}
1376
[email protected]04bce562014-01-30 05:34:541377bool WebContentsImpl::PreHandleGestureEvent(
1378 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031379 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541380}
1381
[email protected]bab38af2014-03-30 17:37:291382bool WebContentsImpl::HandleGestureEvent(
1383 const blink::WebGestureEvent& event) {
1384 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1385 // Use them to implement browser zoom, as for HandleWheelEvent above.
1386 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331387 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291388 // The scale difference necessary to trigger a zoom action. Derived from
1389 // experimentation to find a value that feels reasonable.
1390 const float kZoomStepValue = 0.6f;
1391
1392 // Find the (absolute) thresholds on either side of the current zoom factor,
1393 // then convert those to actual numbers to trigger a zoom in or out.
1394 // This logic deliberately makes the range around the starting zoom value
1395 // for the gesture twice as large as the other ranges (i.e., the notches are
1396 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1397 // so that it's easier to get back to your starting point than it is to
1398 // overshoot.
1399 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1400 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1401 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1402 : -backStep;
1403 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1404 : backStep;
1405
[email protected]fb546cb2014-04-28 14:09:371406 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291407 if (totalPinchGestureAmount_ > zoomInThreshold) {
1408 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461409 if (delegate_)
1410 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291411 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1412 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461413 if (delegate_)
1414 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291415 }
1416 return true;
1417 }
1418
1419 return false;
1420}
1421
[email protected]b172aee2012-04-10 17:05:261422void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431423 if (delegate_)
1424 delegate_->HandleMouseDown();
1425}
1426
[email protected]b172aee2012-04-10 17:05:261427void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481428 if (delegate_)
1429 delegate_->HandleMouseUp();
1430}
1431
[email protected]590a634e2012-07-19 16:38:231432void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481433 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231434 delegate_->HandlePointerActivate();
1435}
1436
1437void WebContentsImpl::HandleGestureBegin() {
1438 if (delegate_)
1439 delegate_->HandleGestureBegin();
1440}
1441
1442void WebContentsImpl::HandleGestureEnd() {
1443 if (delegate_)
1444 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481445}
1446
[email protected]b172aee2012-04-10 17:05:261447void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491448 // This method is being called to enter or leave renderer-initiated fullscreen
1449 // mode. Either way, make sure any existing fullscreen widget is shut down
1450 // first.
1451 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1452 if (widget_view)
1453 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1454
[email protected]8a5e0ca2011-08-25 06:30:471455 if (delegate_)
1456 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371457
1458 FOR_EACH_OBSERVER(WebContentsObserver,
1459 observers_,
1460 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471461}
1462
[email protected]b172aee2012-04-10 17:05:261463bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381464 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121465}
1466
[email protected]a9c81f02012-06-01 00:15:441467void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1468 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371469 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441470 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371471 } else {
1472 GotResponseToLockMouseRequest(false);
1473 }
1474}
1475
[email protected]b172aee2012-04-10 17:05:261476void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371477 if (delegate_)
1478 delegate_->LostMouseLock();
1479}
1480
[email protected]bafe6cd2012-05-23 23:09:501481void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201482 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501483 int route_id,
[email protected]227692c52013-05-31 22:43:041484 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131485 const ViewHostMsg_CreateWindow_Params& params,
1486 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501487 // We usually create the new window in the same BrowsingInstance (group of
1488 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551489 // if the opener is being suppressed (in a non-guest), we create a new
1490 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251491 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551492
[email protected]04cbd3d2013-12-04 04:58:201493 // If the opener is to be suppressed, the new window can be in any process.
1494 // Since routing ids are process specific, we must not have one passed in
1495 // as argument here.
1496 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1497
[email protected]bafe6cd2012-05-23 23:09:501498 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551499 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571500 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501501 GetSiteInstance();
1502
[email protected]04cbd3d2013-12-04 04:58:201503 // A message to create a new window can only come from the active process for
1504 // this WebContentsImpl instance. If any other process sends the request,
1505 // it is invalid and the process must be terminated.
1506 if (GetRenderProcessHost()->GetID() != render_process_id) {
1507 base::ProcessHandle process_handle =
1508 RenderProcessHost::FromID(render_process_id)->GetHandle();
1509 if (process_handle != base::kNullProcessHandle) {
1510 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391511 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
thestigc4cac8f2014-09-04 21:17:501512 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201513 }
1514 return;
1515 }
1516
[email protected]d1198fd2012-08-13 22:50:191517 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341518 //
1519 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301520 const std::string& partition_id =
1521 GetContentClient()->browser()->
1522 GetStoragePartitionIdForSite(GetBrowserContext(),
1523 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461524 StoragePartition* partition = BrowserContext::GetStoragePartition(
1525 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411526 DOMStorageContextWrapper* dom_storage_context =
1527 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191528 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1529 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1530 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371531
1532 if (delegate_ &&
1533 !delegate_->ShouldCreateWebContents(this,
1534 route_id,
1535 params.window_container_type,
1536 params.frame_name,
1537 params.target_url,
1538 partition_id,
1539 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011540 if (route_id != MSG_ROUTING_NONE &&
1541 !RenderViewHost::FromID(render_process_id, route_id)) {
1542 // If the embedder didn't create a WebContents for this route, we need to
1543 // delete the RenderView that had already been created.
1544 Send(new ViewMsg_Close(route_id));
1545 }
[email protected]dd6730412013-08-14 15:03:371546 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1547 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1548 main_frame_route_id);
1549 return;
1550 }
1551
1552 // Create the new web contents. This will automatically create the new
1553 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461554 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591555 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041556 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061557 create_params.opener = this;
1558 create_params.opener_suppressed = params.opener_suppressed;
1559 if (params.disposition == NEW_BACKGROUND_TAB)
1560 create_params.initially_hidden = true;
1561
[email protected]4858e432014-06-23 18:14:171562 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551563 if (!is_guest) {
1564 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451565 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171566 new_contents = static_cast<WebContentsImpl*>(
1567 WebContents::Create(create_params));
1568 } else {
1569 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551570 }
[email protected]50d326e2014-05-20 17:59:061571 new_contents->GetController().SetSessionStorageNamespace(
1572 partition_id,
1573 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261574 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191575
[email protected]c4538072013-03-18 02:17:551576 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341577 // will be shown immediately).
1578 if (!params.opener_suppressed) {
1579 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451580 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501581
[email protected]d70bea92013-04-05 04:23:341582 // TODO(brettw): It seems bogus that we have to call this function on the
1583 // newly created object and give it one of its own member variables.
1584 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1585 }
[email protected]bafe6cd2012-05-23 23:09:501586 // Save the created window associated with the route so we can show it
1587 // later.
1588 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1589 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101590 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501591 }
1592
1593 if (delegate_) {
1594 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071595 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131596 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501597 }
1598
1599 if (params.opener_suppressed) {
1600 // When the opener is suppressed, the original renderer cannot access the
1601 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001602 bool was_blocked = false;
1603 if (delegate_) {
1604 gfx::Rect initial_pos;
1605 delegate_->AddNewContents(
1606 this, new_contents, params.disposition, initial_pos,
1607 params.user_gesture, &was_blocked);
1608 }
1609 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211610 OpenURLParams open_params(params.target_url,
1611 Referrer(),
1612 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351613 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211614 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301615 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001616 new_contents->OpenURL(open_params);
1617 }
[email protected]bafe6cd2012-05-23 23:09:501618 }
1619}
1620
[email protected]a8504022013-12-04 20:23:511621void WebContentsImpl::CreateNewWidget(int render_process_id,
1622 int route_id,
[email protected]180ef242013-11-07 06:50:461623 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511624 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501625}
1626
[email protected]a8504022013-12-04 20:23:511627void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1628 int route_id) {
1629 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501630}
1631
[email protected]a8504022013-12-04 20:23:511632void WebContentsImpl::CreateNewWidget(int render_process_id,
1633 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501634 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461635 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211636 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511637 // A message to create a new widget can only come from the active process for
1638 // this WebContentsImpl instance. If any other process sends the request,
1639 // it is invalid and the process must be terminated.
1640 if (process->GetID() != render_process_id) {
1641 base::ProcessHandle process_handle =
1642 RenderProcessHost::FromID(render_process_id)->GetHandle();
1643 if (process_handle != base::kNullProcessHandle) {
1644 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391645 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
thestigc4cac8f2014-09-04 21:17:501646 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511647 }
1648 return;
1649 }
1650
[email protected]bafe6cd2012-05-23 23:09:501651 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041652 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261653 created_widgets_.insert(widget_host);
1654
[email protected]cfd80b02014-05-01 17:46:481655 RenderWidgetHostViewBase* widget_view =
1656 static_cast<RenderWidgetHostViewBase*>(
1657 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191658 if (!widget_view)
1659 return;
[email protected]bafe6cd2012-05-23 23:09:501660 if (!is_fullscreen) {
1661 // Popups should not get activated.
1662 widget_view->SetPopupType(popup_type);
1663 }
1664 // Save the created widget associated with the route so we can show it later.
1665 pending_widget_views_[route_id] = widget_view;
1666
1667#if defined(OS_MACOSX)
1668 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1669 // to allow it to survive the trip without being hosted.
1670 base::mac::NSObjectRetain(widget_view->GetNativeView());
1671#endif
1672}
1673
1674void WebContentsImpl::ShowCreatedWindow(int route_id,
1675 WindowOpenDisposition disposition,
1676 const gfx::Rect& initial_pos,
1677 bool user_gesture) {
1678 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001679 if (contents) {
1680 WebContentsDelegate* delegate = GetDelegate();
1681 if (delegate) {
1682 delegate->AddNewContents(
1683 this, contents, disposition, initial_pos, user_gesture, NULL);
1684 }
1685 }
[email protected]bafe6cd2012-05-23 23:09:501686}
1687
1688void WebContentsImpl::ShowCreatedWidget(int route_id,
1689 const gfx::Rect& initial_pos) {
1690 ShowCreatedWidget(route_id, false, initial_pos);
1691}
1692
1693void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1694 ShowCreatedWidget(route_id, true, gfx::Rect());
1695}
1696
1697void WebContentsImpl::ShowCreatedWidget(int route_id,
1698 bool is_fullscreen,
1699 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481700 RenderWidgetHostViewBase* widget_host_view =
1701 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501702 if (!widget_host_view)
1703 return;
[email protected]cfd80b02014-05-01 17:46:481704
1705 RenderWidgetHostView* view = NULL;
1706 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1707 if (guest && guest->embedder_web_contents()) {
1708 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1709 } else {
1710 view = GetRenderWidgetHostView();
1711 }
1712
[email protected]4aebbca2013-09-17 22:26:491713 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311714 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031715 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311716 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491717 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1718 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1719 delegate_->ToggleFullscreenModeForTab(this, true);
1720 } else {
[email protected]cfd80b02014-05-01 17:46:481721 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491722 }
[email protected]4aebbca2013-09-17 22:26:491723 FOR_EACH_OBSERVER(WebContentsObserver,
1724 observers_,
1725 DidShowFullscreenWidget(route_id));
1726 if (!widget_host_view->HasFocus())
1727 widget_host_view->Focus();
1728 } else {
[email protected]cfd80b02014-05-01 17:46:481729 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491730 }
[email protected]89054502012-06-03 10:29:241731
1732 RenderWidgetHostImpl* render_widget_host_impl =
1733 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1734 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311735 // Only allow privileged mouse lock for fullscreen render widget, which is
1736 // used to implement Pepper Flash fullscreen.
1737 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501738
1739#if defined(OS_MACOSX)
1740 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1741 // properly embedded (or purposefully ignored) we can release the retain we
1742 // took in CreateNewWidget().
1743 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1744#endif
1745}
1746
1747WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1748 PendingContents::iterator iter = pending_contents_.find(route_id);
1749
1750 // Certain systems can block the creation of new windows. If we didn't succeed
1751 // in creating one, just return NULL.
1752 if (iter == pending_contents_.end()) {
1753 return NULL;
1754 }
1755
1756 WebContentsImpl* new_contents = iter->second;
1757 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101758 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501759
[email protected]d70bea92013-04-05 04:23:341760 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251761 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341762 return new_contents;
1763
[email protected]bafe6cd2012-05-23 23:09:501764 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1765 !new_contents->GetRenderViewHost()->GetView())
1766 return NULL;
1767
creis82dd6af2014-09-17 16:30:451768 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501769 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1770 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451771 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1772
[email protected]bafe6cd2012-05-23 23:09:501773 return new_contents;
1774}
1775
1776RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1777 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1778 if (iter == pending_widget_views_.end()) {
1779 DCHECK(false);
1780 return NULL;
1781 }
1782
1783 RenderWidgetHostView* widget_host_view = iter->second;
1784 pending_widget_views_.erase(route_id);
1785
1786 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1787 if (!widget_host->GetProcess()->HasConnection()) {
1788 // The view has gone away or the renderer crashed. Nothing to do.
1789 return NULL;
1790 }
1791
1792 return widget_host_view;
1793}
1794
[email protected]f13b4202012-06-12 23:53:231795void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091796 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211797 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371798 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231799 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371800 } else {
1801 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041802 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371803 scoped_ptr<MediaStreamUI>());
1804 }
[email protected]f13b4202012-06-12 23:53:231805}
1806
grunell657d4d82014-09-18 00:09:431807bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1808 MediaStreamType type) {
1809 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1810 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1811 return delegate_ &&
1812 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1813}
1814
[email protected]cc9200432013-07-23 23:02:401815SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1816 SiteInstance* instance) {
1817 return controller_.GetSessionStorageNamespace(instance);
1818}
1819
[email protected]6de7fc482014-06-06 10:46:441820SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1821 return controller_.GetSessionStorageNamespaceMap();
1822}
1823
[email protected]9b159a52013-10-03 17:24:551824FrameTree* WebContentsImpl::GetFrameTree() {
1825 return &frame_tree_;
1826}
1827
[email protected]95640212014-07-26 18:14:301828AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1829 return accessibility_mode_;
1830}
1831
[email protected]31a71eaf2014-03-13 01:47:361832void WebContentsImpl::AccessibilityEventReceived(
1833 const std::vector<AXEventNotificationDetails>& details) {
1834 FOR_EACH_OBSERVER(
1835 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1836}
1837
dmazzonia656928e2014-09-15 20:28:541838RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1839 int browser_plugin_instance_id) {
1840 BrowserPluginGuestManager* guest_manager =
1841 GetBrowserContext()->GetGuestManager();
1842 WebContents* guest = guest_manager->GetGuestByInstanceID(
1843 this, browser_plugin_instance_id);
1844 if (!guest)
1845 return NULL;
1846 return guest->GetMainFrame();
1847}
1848
[email protected]edc3af82013-12-12 21:24:071849void WebContentsImpl::OnShowValidationMessage(
1850 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291851 const base::string16& main_text,
1852 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071853 if (delegate_)
1854 delegate_->ShowValidationMessage(
1855 this, anchor_in_root_view, main_text, sub_text);
1856}
1857
1858void WebContentsImpl::OnHideValidationMessage() {
1859 if (delegate_)
1860 delegate_->HideValidationMessage(this);
1861}
1862
1863void WebContentsImpl::OnMoveValidationMessage(
1864 const gfx::Rect& anchor_in_root_view) {
1865 if (delegate_)
1866 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1867}
1868
[email protected]32deec62013-05-15 23:55:041869void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1870 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441871 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041872}
1873
[email protected]95640212014-07-26 18:14:301874BrowserAccessibilityManager*
1875 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1876 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1877 return rfh ? rfh->browser_accessibility_manager() : NULL;
1878}
1879
1880BrowserAccessibilityManager*
1881 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1882 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1883 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1884}
1885
[email protected]b172aee2012-04-10 17:05:261886void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491887 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231888 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491889 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331890}
1891
[email protected]b172aee2012-04-10 17:05:261892void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341893 if (delegate_)
1894 delegate_->ResizeDueToAutoResize(this, new_size);
1895}
1896
[email protected]b172aee2012-04-10 17:05:261897WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201898 if (!delegate_)
1899 return NULL;
[email protected]00c37fc2011-08-02 00:22:501900
[email protected]e5d549d2011-12-28 01:29:201901 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201902 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341903}
1904
[email protected]6b618e62012-08-16 12:59:181905bool WebContentsImpl::Send(IPC::Message* message) {
1906 if (!GetRenderViewHost()) {
1907 delete message;
1908 return false;
1909 }
1910
1911 return GetRenderViewHost()->Send(message);
1912}
1913
[email protected]b172aee2012-04-10 17:05:261914bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501915 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261916 FrameTreeNode* node = frame_tree_.root();
1917
creise42f2a52014-09-18 18:14:571918 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1919 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261920 NavigationEntryImpl* pending_entry =
1921 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571922 if (pending_entry->frame_tree_node_id() != -1) {
1923 FrameTreeNode* subframe =
1924 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1925 DCHECK(subframe);
1926 if (subframe)
1927 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261928 }
1929
1930 return node->navigator()->NavigateToPendingEntry(
1931 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541932}
[email protected]96d185d2009-04-24 03:28:541933
[email protected]a86c0e962013-12-17 17:10:391934void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1935 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441936 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391937 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441938}
1939
[email protected]20ca0382013-02-28 19:50:071940void WebContentsImpl::AttachInterstitialPage(
1941 InterstitialPageImpl* interstitial_page) {
1942 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211943 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291944
1945 // Cancel any visible dialogs so that they don't interfere with the
1946 // interstitial.
1947 if (dialog_manager_)
1948 dialog_manager_->CancelActiveAndPendingDialogs(this);
1949
[email protected]20ca0382013-02-28 19:50:071950 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1951 DidAttachInterstitialPage());
1952}
1953
1954void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571955 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211956 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071957 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1958 DidDetachInterstitialPage());
1959}
1960
[email protected]b172aee2012-04-10 17:05:261961void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331962 const SiteInstance* site_instance,
1963 int history_length,
1964 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411965 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1966 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211967 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191968 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141969 return;
[email protected]9e1ad4b2011-08-14 16:49:191970 }
[email protected]9f76c1e2012-03-05 15:15:581971 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191972 if (!rvh) {
1973 NOTREACHED();
1974 return;
1975 }
[email protected]9f76c1e2012-03-05 15:15:581976 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191977 NOTREACHED();
1978 return;
1979 }
[email protected]6b618e62012-08-16 12:59:181980 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1981 history_length,
1982 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141983}
1984
[email protected]4fed3702014-04-01 09:08:001985void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171986 RenderFrameHost* focused_frame = GetFocusedFrame();
1987 if (!focused_frame)
1988 return;
1989
[email protected]959be4c2014-04-08 15:01:331990 focused_frame->Send(new FrameMsg_Reload(
1991 focused_frame->GetRoutingID(), ignore_cache));
1992}
1993
1994void WebContentsImpl::Undo() {
1995 RenderFrameHost* focused_frame = GetFocusedFrame();
1996 if (!focused_frame)
1997 return;
1998
1999 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2000 RecordAction(base::UserMetricsAction("Undo"));
2001}
2002
2003void WebContentsImpl::Redo() {
2004 RenderFrameHost* focused_frame = GetFocusedFrame();
2005 if (!focused_frame)
2006 return;
2007 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2008 RecordAction(base::UserMetricsAction("Redo"));
2009}
2010
2011void WebContentsImpl::Cut() {
2012 RenderFrameHost* focused_frame = GetFocusedFrame();
2013 if (!focused_frame)
2014 return;
2015
2016 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2017 RecordAction(base::UserMetricsAction("Cut"));
2018}
2019
2020void WebContentsImpl::Copy() {
2021 RenderFrameHost* focused_frame = GetFocusedFrame();
2022 if (!focused_frame)
2023 return;
2024
2025 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2026 RecordAction(base::UserMetricsAction("Copy"));
2027}
2028
2029void WebContentsImpl::CopyToFindPboard() {
2030#if defined(OS_MACOSX)
2031 RenderFrameHost* focused_frame = GetFocusedFrame();
2032 if (!focused_frame)
2033 return;
2034
2035 // Windows/Linux don't have the concept of a find pasteboard.
2036 focused_frame->Send(
2037 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2038 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2039#endif
2040}
2041
2042void WebContentsImpl::Paste() {
2043 RenderFrameHost* focused_frame = GetFocusedFrame();
2044 if (!focused_frame)
2045 return;
2046
2047 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2048 RecordAction(base::UserMetricsAction("Paste"));
2049}
2050
2051void WebContentsImpl::PasteAndMatchStyle() {
2052 RenderFrameHost* focused_frame = GetFocusedFrame();
2053 if (!focused_frame)
2054 return;
2055
2056 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2057 focused_frame->GetRoutingID()));
2058 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2059}
2060
2061void WebContentsImpl::Delete() {
2062 RenderFrameHost* focused_frame = GetFocusedFrame();
2063 if (!focused_frame)
2064 return;
2065
2066 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2067 RecordAction(base::UserMetricsAction("DeleteSelection"));
2068}
2069
2070void WebContentsImpl::SelectAll() {
2071 RenderFrameHost* focused_frame = GetFocusedFrame();
2072 if (!focused_frame)
2073 return;
2074
2075 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2076 RecordAction(base::UserMetricsAction("SelectAll"));
2077}
2078
2079void WebContentsImpl::Unselect() {
2080 RenderFrameHost* focused_frame = GetFocusedFrame();
2081 if (!focused_frame)
2082 return;
2083
2084 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2085 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172086}
2087
2088void WebContentsImpl::Replace(const base::string16& word) {
2089 RenderFrameHost* focused_frame = GetFocusedFrame();
2090 if (!focused_frame)
2091 return;
2092
[email protected]959be4c2014-04-08 15:01:332093 focused_frame->Send(new InputMsg_Replace(
2094 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172095}
2096
2097void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2098 RenderFrameHost* focused_frame = GetFocusedFrame();
2099 if (!focused_frame)
2100 return;
2101
[email protected]959be4c2014-04-08 15:01:332102 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2103 focused_frame->GetRoutingID(), word));
2104}
2105
2106void WebContentsImpl::NotifyContextMenuClosed(
2107 const CustomContextMenuContext& context) {
2108 RenderFrameHost* focused_frame = GetFocusedFrame();
2109 if (!focused_frame)
2110 return;
2111
2112 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2113 focused_frame->GetRoutingID(), context));
2114}
2115
2116void WebContentsImpl::ExecuteCustomContextMenuCommand(
2117 int action, const CustomContextMenuContext& context) {
2118 RenderFrameHost* focused_frame = GetFocusedFrame();
2119 if (!focused_frame)
2120 return;
2121
2122 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2123 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002124}
2125
[email protected]fc2b46b2014-05-03 16:33:452126gfx::NativeView WebContentsImpl::GetNativeView() {
2127 return view_->GetNativeView();
2128}
2129
2130gfx::NativeView WebContentsImpl::GetContentNativeView() {
2131 return view_->GetContentNativeView();
2132}
2133
2134gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2135 return view_->GetTopLevelNativeWindow();
2136}
2137
2138gfx::Rect WebContentsImpl::GetViewBounds() {
2139 return view_->GetViewBounds();
2140}
2141
2142gfx::Rect WebContentsImpl::GetContainerBounds() {
2143 gfx::Rect rv;
2144 view_->GetContainerBounds(&rv);
2145 return rv;
2146}
2147
2148DropData* WebContentsImpl::GetDropData() {
2149 return view_->GetDropData();
2150}
2151
2152void WebContentsImpl::Focus() {
[email protected]0b431992014-06-24 00:08:032153 RenderWidgetHostView* const fullscreen_view =
2154 GetFullscreenRenderWidgetHostView();
2155 if (fullscreen_view)
2156 fullscreen_view->Focus();
2157 else
2158 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452159}
2160
2161void WebContentsImpl::SetInitialFocus() {
[email protected]0b431992014-06-24 00:08:032162 RenderWidgetHostView* const fullscreen_view =
2163 GetFullscreenRenderWidgetHostView();
2164 if (fullscreen_view)
2165 fullscreen_view->Focus();
2166 else
2167 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452168}
2169
2170void WebContentsImpl::StoreFocus() {
[email protected]0b431992014-06-24 00:08:032171 if (!GetFullscreenRenderWidgetHostView())
2172 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452173}
2174
2175void WebContentsImpl::RestoreFocus() {
[email protected]0b431992014-06-24 00:08:032176 RenderWidgetHostView* const fullscreen_view =
2177 GetFullscreenRenderWidgetHostView();
2178 if (fullscreen_view)
2179 fullscreen_view->Focus();
2180 else
2181 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452182}
2183
[email protected]b172aee2012-04-10 17:05:262184void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272185 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212186 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542187 return;
2188 }
[email protected]0b431992014-06-24 00:08:032189 RenderWidgetHostView* const fullscreen_view =
2190 GetFullscreenRenderWidgetHostView();
2191 if (fullscreen_view) {
2192 fullscreen_view->Focus();
2193 return;
2194 }
[email protected]9f76c1e2012-03-05 15:15:582195 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542196}
2197
[email protected]b172aee2012-04-10 17:05:262198bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212199 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542200}
2201
[email protected]b172aee2012-04-10 17:05:262202InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212203 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222204}
2205
[email protected]b172aee2012-04-10 17:05:262206bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162207 // WebKit creates Document object when MIME type is application/xhtml+xml,
2208 // so we also support this MIME type.
2209 return contents_mime_type_ == "text/html" ||
2210 contents_mime_type_ == "text/xml" ||
2211 contents_mime_type_ == "application/xhtml+xml" ||
2212 contents_mime_type_ == "text/plain" ||
2213 contents_mime_type_ == "text/css" ||
2214 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592218 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162219 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552220 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012221 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142222 return;
[email protected]c7dd2f62011-07-18 15:57:592223 }
2224
2225 Stop();
2226
2227 // Create the save package and possibly prompt the user for the name to save
2228 // the page as. The user prompt is an asynchronous operation that runs on
2229 // another thread.
2230 save_package_ = new SavePackage(this);
2231 save_package_->GetSaveInfo();
2232}
2233
2234// Used in automated testing to bypass prompting the user for file names.
2235// Instead, the names and paths are hard coded rather than running them through
2236// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342237bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2238 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212239 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592240 // Stop the page from navigating.
2241 Stop();
2242
2243 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212244 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592245}
2246
[email protected]3c71576ce2013-07-23 02:00:012247void WebContentsImpl::SaveFrame(const GURL& url,
2248 const Referrer& referrer) {
2249 if (!GetURL().is_valid())
2250 return;
2251 bool is_main_frame = (url == GetURL());
2252
2253 DownloadManager* dlm =
2254 BrowserContext::GetDownloadManager(GetBrowserContext());
2255 if (!dlm)
2256 return;
2257 int64 post_id = -1;
2258 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272259 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012260 if (entry)
2261 post_id = entry->GetPostID();
2262 }
2263 scoped_ptr<DownloadUrlParameters> params(
2264 DownloadUrlParameters::FromWebContents(this, url));
2265 params->set_referrer(referrer);
2266 params->set_post_id(post_id);
2267 params->set_prefer_cache(true);
2268 if (post_id >= 0)
2269 params->set_method("POST");
2270 params->set_prompt(true);
2271 dlm->DownloadUrl(params.Pass());
2272}
2273
[email protected]b172aee2012-04-10 17:05:262274void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342275 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482276 const base::Callback<void(int64)>& callback) {
2277 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122278}
2279
[email protected]b172aee2012-04-10 17:05:262280const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272281 return contents_mime_type_;
2282}
2283
[email protected]b172aee2012-04-10 17:05:262284bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272285 return notify_disconnection_;
2286}
2287
[email protected]b172aee2012-04-10 17:05:262288void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312289 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182290 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162291}
2292
[email protected]b172aee2012-04-10 17:05:262293void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542294 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182295 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162296}
2297
[email protected]8ff00d72012-10-23 19:12:212298RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272299 return &renderer_preferences_;
2300}
2301
[email protected]e35ccd52012-05-23 16:22:472302void WebContentsImpl::Close() {
2303 Close(GetRenderViewHost());
2304}
2305
[email protected]cf200a562013-05-03 16:24:292306void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462307 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292308 if (browser_plugin_embedder_.get())
2309 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2310 screen_x, screen_y, operation);
2311 if (GetRenderViewHost())
2312 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2313 screen_x, screen_y, operation);
2314}
2315
[email protected]d60f3702013-12-26 16:30:242316void WebContentsImpl::DidGetResourceResponseStart(
2317 const ResourceRequestDetails& details) {
2318 controller_.ssl_manager()->DidStartResourceResponse(details);
2319
2320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2321 DidGetResourceResponseStart(details));
2322
2323 // TODO(avi): Remove. http://crbug.com/170921
2324 NotificationService::current()->Notify(
2325 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2326 Source<WebContents>(this),
2327 Details<const ResourceRequestDetails>(&details));
2328}
2329
2330void WebContentsImpl::DidGetRedirectForResourceRequest(
2331 RenderViewHost* render_view_host,
2332 const ResourceRedirectDetails& details) {
2333 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2334
2335 FOR_EACH_OBSERVER(
2336 WebContentsObserver,
2337 observers_,
2338 DidGetRedirectForResourceRequest(render_view_host, details));
2339
2340 // TODO(avi): Remove. http://crbug.com/170921
2341 NotificationService::current()->Notify(
2342 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2343 Source<WebContents>(this),
2344 Details<const ResourceRedirectDetails>(&details));
2345}
2346
[email protected]b172aee2012-04-10 17:05:262347void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522348 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582349 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512350 if (delegate_)
2351 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292352 if (browser_plugin_embedder_.get())
2353 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342354}
2355
[email protected]e35ccd52012-05-23 16:22:472356void WebContentsImpl::UserGestureDone() {
2357 OnUserGesture();
2358}
2359
[email protected]b172aee2012-04-10 17:05:262360void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272361 closed_by_user_gesture_ = value;
2362}
2363
[email protected]b172aee2012-04-10 17:05:262364bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272365 return closed_by_user_gesture_;
2366}
2367
[email protected]b172aee2012-04-10 17:05:262368void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502369 if (!delegate_)
2370 return;
2371
[email protected]6286a372013-10-09 04:03:272372 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2373 if (!entry)
[email protected]1788e772010-12-15 16:40:502374 return;
2375
[email protected]6286a372013-10-09 04:03:272376 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042380 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272381 if (!delegate_)
2382 return;
2383
[email protected]691aa2f2013-05-28 22:52:042384 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272385}
2386
[email protected]b172aee2012-04-10 17:05:262387int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272388 return minimum_zoom_percent_;
2389}
2390
[email protected]b172aee2012-04-10 17:05:262391int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272392 return maximum_zoom_percent_;
2393}
2394
[email protected]b172aee2012-04-10 17:05:262395gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492396 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232397}
2398
[email protected]b172aee2012-04-10 17:05:262399bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052400 if (GetBrowserPluginGuest())
2401 return GetBrowserPluginGuest()->LockMouse(allowed);
2402
[email protected]0bfbf882011-12-22 18:19:272403 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582404 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272405}
2406
[email protected]b172aee2012-04-10 17:05:262407bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442408 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502409}
2410
[email protected]cb805452013-05-22 15:16:212411void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482412 if (!color_chooser_info_.get())
2413 return;
2414 RenderFrameHost* rfh = RenderFrameHost::FromID(
2415 color_chooser_info_->render_process_id,
2416 color_chooser_info_->render_frame_id);
2417 if (!rfh)
2418 return;
2419
2420 rfh->Send(new FrameMsg_DidChooseColorResponse(
2421 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202422}
2423
[email protected]cb805452013-05-22 15:16:212424void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482425 if (!color_chooser_info_.get())
2426 return;
2427 RenderFrameHost* rfh = RenderFrameHost::FromID(
2428 color_chooser_info_->render_process_id,
2429 color_chooser_info_->render_frame_id);
2430 if (!rfh)
2431 return;
2432
2433 rfh->Send(new FrameMsg_DidEndColorChooser(
2434 rfh->GetRoutingID(), color_chooser_info_->identifier));
2435 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202436}
2437
[email protected]41225fe2013-03-29 05:32:022438int WebContentsImpl::DownloadImage(const GURL& url,
2439 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302440 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022441 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582442 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022443 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392444 return id;
2445}
2446
[email protected]5dcaf8e2013-12-28 01:31:422447bool WebContentsImpl::IsSubframe() const {
2448 return is_subframe_;
2449}
2450
[email protected]36ec24f2014-01-09 00:32:082451void WebContentsImpl::Find(int request_id,
2452 const base::string16& search_text,
2453 const blink::WebFindOptions& options) {
2454 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2455}
2456
2457void WebContentsImpl::StopFinding(StopFindAction action) {
2458 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2459}
2460
[email protected]4fe53add2014-04-08 19:53:362461void WebContentsImpl::InsertCSS(const std::string& css) {
2462 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2463 GetMainFrame()->GetRoutingID(), css));
2464}
2465
dalecurtisbc6572e12014-09-12 19:22:302466bool WebContentsImpl::WasRecentlyAudible() {
2467 return audio_stream_monitor_.WasRecentlyAudible();
2468}
2469
mlamouriefdca9d2014-09-16 16:55:402470void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2471 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2472}
2473
[email protected]b172aee2012-04-10 17:05:262474bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272475 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172476 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332477 return true;
2478 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272479}
2480
[email protected]b172aee2012-04-10 17:05:262481void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272482 if (delegate_)
2483 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212484}
2485
[email protected]52913802013-12-10 05:52:182486void WebContentsImpl::DidStartProvisionalLoad(
2487 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182488 const GURL& validated_url,
2489 bool is_error_page,
2490 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102491 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482492 FOR_EACH_OBSERVER(
2493 WebContentsObserver,
2494 observers_,
2495 DidStartProvisionalLoadForFrame(
2496 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542497}
2498
[email protected]0c3c54f2014-07-31 01:29:002499void WebContentsImpl::DidStartNavigationTransition(
2500 RenderFrameHostImpl* render_frame_host) {
2501#if defined(OS_ANDROID)
2502 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562503 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
2504 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002505#endif
2506}
2507
[email protected]3109fbb72014-01-06 23:57:152508void WebContentsImpl::DidFailProvisionalLoadWithError(
2509 RenderFrameHostImpl* render_frame_host,
2510 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2511 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312512 FOR_EACH_OBSERVER(WebContentsObserver,
2513 observers_,
2514 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312515 validated_url,
2516 params.error_code,
2517 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152518}
2519
[email protected]b80624c2014-02-09 02:46:552520void WebContentsImpl::DidFailLoadWithError(
2521 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552522 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552523 int error_code,
2524 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142525 FOR_EACH_OBSERVER(
2526 WebContentsObserver,
2527 observers_,
2528 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552529}
2530
[email protected]52913802013-12-10 05:52:182531void WebContentsImpl::NotifyChangedNavigationState(
2532 InvalidateTypes changed_flags) {
2533 NotifyNavigationStateChanged(changed_flags);
2534}
2535
[email protected]3691e5cf2014-01-22 10:16:202536void WebContentsImpl::AboutToNavigateRenderFrame(
2537 RenderFrameHostImpl* render_frame_host) {
2538 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272539 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202540 FOR_EACH_OBSERVER(
2541 WebContentsObserver,
2542 observers_,
[email protected]161eabd2014-03-19 19:47:272543 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202544}
2545
2546void WebContentsImpl::DidStartNavigationToPendingEntry(
2547 RenderFrameHostImpl* render_frame_host,
2548 const GURL& url,
2549 NavigationController::ReloadType reload_type) {
2550 // Notify observers about navigation.
2551 FOR_EACH_OBSERVER(
2552 WebContentsObserver,
2553 observers_,
2554 DidStartNavigationToPendingEntry(url, reload_type));
2555}
2556
[email protected]8cb834e2014-03-06 14:23:232557void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2558 const OpenURLParams& params) {
2559 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182560 WebContents* new_contents = OpenURL(params);
2561
2562 if (new_contents) {
2563 // Notify observers.
2564 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2565 DidOpenRequestedURL(new_contents,
2566 params.url,
2567 params.referrer,
2568 params.disposition,
2569 params.transition,
[email protected]8cb834e2014-03-06 14:23:232570 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182571 }
2572}
2573
[email protected]aa62afd2014-04-22 19:22:462574bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2575 if (!delegate_)
2576 return false;
2577 return delegate_->ShouldPreserveAbortedURLs(this);
2578}
2579
[email protected]37567b432014-02-12 01:12:222580void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432581 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222582 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352583 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222584 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482585 FOR_EACH_OBSERVER(WebContentsObserver,
2586 observers_,
2587 DidCommitProvisionalLoadForFrame(
2588 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222589}
2590
[email protected]0d0f4c492014-04-02 06:42:572591void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232592 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572593 // Ensure fullscreen mode is exited before committing the navigation to a
2594 // different page. The next page will not start out assuming it is in
2595 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232596 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192597 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572598 return;
2599 }
2600 if (IsFullscreenForCurrentTab())
2601 GetRenderViewHost()->ExitFullscreen();
2602 DCHECK(!IsFullscreenForCurrentTab());
2603}
2604
[email protected]37567b432014-02-12 01:12:222605void WebContentsImpl::DidNavigateMainFramePostCommit(
2606 const LoadCommittedDetails& details,
2607 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2608 if (details.is_navigation_to_different_page()) {
2609 // Clear the status bubble. This is a workaround for a bug where WebKit
2610 // doesn't let us know that the cursor left an element during a
2611 // transition (this is also why the mouse cursor remains as a hand after
2612 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2613 // clear the bubble when a user navigates to a named anchor in the same
2614 // page.
avi450ce00e2014-09-24 01:58:522615 UpdateTargetURL(GURL());
[email protected]37567b432014-02-12 01:12:222616 }
2617
2618 if (!details.is_in_page) {
2619 // Once the main frame is navigated, we're no longer considered to have
2620 // displayed insecure content.
2621 displayed_insecure_content_ = false;
2622 SSLManager::NotifySSLInternalStateChanged(
2623 GetController().GetBrowserContext());
2624 }
2625
2626 // Notify observers about navigation.
2627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2628 DidNavigateMainFrame(details, params));
2629
[email protected]e85165c642014-06-10 14:34:312630 if (delegate_)
[email protected]37567b432014-02-12 01:12:222631 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312632 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222633}
2634
2635void WebContentsImpl::DidNavigateAnyFramePostCommit(
2636 RenderFrameHostImpl* render_frame_host,
2637 const LoadCommittedDetails& details,
2638 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102639 // Now that something has committed, we don't need to track whether the
2640 // initial page has been accessed.
2641 has_accessed_initial_document_ = false;
2642
[email protected]37567b432014-02-12 01:12:222643 // If we navigate off the page, close all JavaScript dialogs.
2644 if (dialog_manager_ && !details.is_in_page)
2645 dialog_manager_->CancelActiveAndPendingDialogs(this);
2646
2647 // Notify observers about navigation.
2648 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2649 DidNavigateAnyFrame(details, params));
2650}
2651
2652void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2653 contents_mime_type_ = mime_type;
2654}
2655
[email protected]277857a2014-06-03 10:38:012656bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312657 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052658 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312659 return false;
2660
[email protected]37567b432014-02-12 01:12:222661 if (delegate_)
2662 return delegate_->CanOverscrollContent();
2663
2664 return false;
2665}
2666
[email protected]37b64c52014-07-11 21:14:052667void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252668 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052669 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252670}
2671
[email protected]b172aee2012-04-10 17:05:262672void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182673 const GURL& url,
[email protected]70435962011-08-02 20:13:282674 const std::string& security_info,
2675 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182676 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402677 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192678 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182679 cache.Increment();
2680
2681 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082682 int cert_id = 0;
2683 net::CertStatus cert_status = 0;
2684 int security_bits = -1;
2685 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122686 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212687 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122688 &security_bits, &connection_status,
2689 &signed_certificate_timestamp_ids);
2690 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212691 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002692 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2693 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182694
[email protected]b0f724c2013-09-05 04:21:132695 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2696
2697 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2698 DidLoadResourceFromMemoryCache(details));
2699
[email protected]8bfc8272013-09-09 20:10:532700 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2701 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402702 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532703 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2704 GetRenderProcessHost()->GetID()) :
2705 GetBrowserContext()->GetRequestContextForRenderProcess(
2706 GetRenderProcessHost()->GetID()));
2707 BrowserThread::PostTask(
2708 BrowserThread::IO,
2709 FROM_HERE,
2710 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2711 }
[email protected]724159a2010-12-30 01:11:182712}
2713
[email protected]b172aee2012-04-10 17:05:262714void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392715 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182716 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192717 SSLManager::NotifySSLInternalStateChanged(
2718 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182719}
2720
[email protected]b172aee2012-04-10 17:05:262721void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022722 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582723 LOG(WARNING) << security_origin << " ran insecure content from "
2724 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392725 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412726 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392727 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182728 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412729 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192730 SSLManager::NotifySSLInternalStateChanged(
2731 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182732}
2733
[email protected]501052ff2014-02-21 22:19:072734void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572735 CHECK(render_frame_message_source_);
2736 CHECK(!render_view_message_source_);
2737 RenderFrameHostImpl* rfh =
2738 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142739 FOR_EACH_OBSERVER(
2740 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182741}
2742
[email protected]b172aee2012-04-10 17:05:262743void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262744 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372745 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122746 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2747 GetRenderProcessHost()->ReceivedBadMessage();
2748 return;
2749 }
[email protected]a1b99262013-12-27 21:56:222750
[email protected]8b3af1e2014-01-24 13:29:122751 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442752 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372753 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422754 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372755
[email protected]61ac9e242014-03-21 20:55:262756 RenderFrameHostImpl* rfh =
2757 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142758 FOR_EACH_OBSERVER(
2759 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312760}
2761
[email protected]960b0372014-05-19 18:01:002762void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2763 RenderFrameHostImpl* rfh =
2764 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2765 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2766
2767 // It is possible to get multiple calls to OnDidStartLoading that don't have
2768 // corresponding calls to OnDidStopLoading:
2769 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2770 // out for a cross-process navigation, and it turns into a placeholder for
2771 // one being rendered in a different process.
2772 // - Also, there might be more than one RenderFrameHost sharing the same
2773 // FrameTreeNode (and thus sharing its ID) each sending a start.
2774 // - But in the future, once clamy@ moves navigation network requests to the
2775 // browser process, there's a good chance that callbacks about starting and
2776 // stopping will all be handled by the browser. When that happens, there
2777 // should no longer be a start/stop call imbalance. TODO(avi): When this
2778 // future arrives, update this code to not allow this case.
2779 DCHECK_GE(loading_frames_in_progress_, 0);
2780 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2781 if (loading_frames_in_progress_ == 0)
2782 DidStartLoading(rfh, to_different_document);
2783 ++loading_frames_in_progress_;
2784 }
2785
2786 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2787 SendLoadProgressChanged();
2788}
2789
2790void WebContentsImpl::OnDidStopLoading() {
2791 RenderFrameHostImpl* rfh =
2792 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2793 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2794
2795 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2796 // Load stopped while we were still tracking load. Make sure we update
2797 // progress based on this frame's completion.
2798 loading_progresses_[render_frame_id] = 1.0;
2799 SendLoadProgressChanged();
2800 // Then we clean-up our states.
2801 if (loading_total_progress_ == 1.0)
2802 ResetLoadProgressState();
2803 }
2804
2805 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2806 // calls DidStopLoading() without a matching DidStartLoading().
2807 if (loading_frames_in_progress_ == 0)
2808 return;
2809 --loading_frames_in_progress_;
2810 if (loading_frames_in_progress_ == 0)
2811 DidStopLoading(rfh);
2812}
2813
2814void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2815 RenderFrameHostImpl* rfh =
2816 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2817 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2818
2819 loading_progresses_[render_frame_id] = load_progress;
2820
2821 // We notify progress change immediately for the first and last updates.
2822 // Also, since the message loop may be pretty busy when a page is loaded, it
2823 // might not execute a posted task in a timely manner so we make sure to
2824 // immediately send progress report if enough time has passed.
2825 base::TimeDelta min_delay =
2826 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2827 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2828 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2829 // If there is a pending task to send progress, it is now obsolete.
2830 loading_weak_factory_.InvalidateWeakPtrs();
2831 SendLoadProgressChanged();
2832 if (loading_total_progress_ == 1.0)
2833 ResetLoadProgressState();
2834 return;
2835 }
2836
2837 if (loading_weak_factory_.HasWeakPtrs())
2838 return;
2839
2840 base::MessageLoop::current()->PostDelayedTask(
2841 FROM_HERE,
2842 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2843 loading_weak_factory_.GetWeakPtr()),
2844 min_delay);
2845}
2846
[email protected]b172aee2012-04-10 17:05:262847void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222848 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2849 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262850}
2851
[email protected]b172aee2012-04-10 17:05:262852void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302853 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262854 minimum_zoom_percent_ = minimum_percent;
2855 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262856}
2857
[email protected]b172aee2012-04-10 17:05:262858void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342859 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432860 if (!delegate_)
2861 return;
2862
[email protected]b9535422012-02-09 01:47:592863 ChildProcessSecurityPolicyImpl* policy =
2864 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222865 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592866 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212867}
2868
[email protected]b172aee2012-04-10 17:05:262869void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2870 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262871 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362872 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432873 if (!delegate_)
2874 return;
2875
[email protected]b9535422012-02-09 01:47:592876 ChildProcessSecurityPolicyImpl* policy =
2877 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322878 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592879 return;
[email protected]8f810632013-06-06 22:33:322880
[email protected]c125e532014-05-10 20:39:062881 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202882}
2883
[email protected]f5273e52014-07-14 16:30:202884void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2885 const GURL& url,
2886 bool user_gesture) {
2887 if (!delegate_)
2888 return;
2889
2890 ChildProcessSecurityPolicyImpl* policy =
2891 ChildProcessSecurityPolicyImpl::GetInstance();
2892 if (policy->IsPseudoScheme(protocol))
2893 return;
2894
2895 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2896}
2897
[email protected]b172aee2012-04-10 17:05:262898void WebContentsImpl::OnFindReply(int request_id,
2899 int number_of_matches,
2900 const gfx::Rect& selection_rect,
2901 int active_match_ordinal,
2902 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432903 if (delegate_) {
2904 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2905 active_match_ordinal, final_update);
2906 }
[email protected]b888919c2011-09-02 00:32:162907}
2908
[email protected]59363fc92012-09-05 03:46:312909#if defined(OS_ANDROID)
2910void WebContentsImpl::OnFindMatchRectsReply(
2911 int version,
2912 const std::vector<gfx::RectF>& rects,
2913 const gfx::RectF& active_rect) {
2914 if (delegate_)
2915 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2916}
[email protected]583418cc2013-01-17 14:01:102917
[email protected]1ff427972013-02-07 21:14:072918void WebContentsImpl::OnOpenDateTimeDialog(
2919 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092920 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2921 GetRenderViewHost(),
2922 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132923 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092924 value.minimum,
2925 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172926 value.step,
2927 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102928}
2929
[email protected]59363fc92012-09-05 03:46:312930#endif
2931
[email protected]f114fa42013-12-06 17:06:442932void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2933 const base::FilePath& path,
2934 bool is_hung) {
2935 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2936
2937 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2938 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2939}
2940
2941void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422942 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442943 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422944 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452945}
2946
[email protected]cfa856d62014-02-22 07:58:402947void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2948 int automation_id) {
2949 DomOperationNotificationDetails details(json_string, automation_id);
2950 NotificationService::current()->Notify(
2951 NOTIFICATION_DOM_OPERATION_RESPONSE,
2952 Source<WebContents>(this),
2953 Details<DomOperationNotificationDetails>(&details));
2954}
2955
[email protected]b172aee2012-04-10 17:05:262956void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2957 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102958 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252959 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102960 AppCacheAccessed(manifest_url, blocked_by_policy));
2961}
2962
[email protected]8bc5ff02013-11-29 06:34:032963void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482964 int color_chooser_id,
2965 SkColor color,
2966 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462967 ColorChooser* new_color_chooser = delegate_ ?
2968 delegate_->OpenColorChooser(this, color, suggestions) :
2969 NULL;
[email protected]820957a2014-01-14 14:56:302970 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212971 return;
[email protected]8ed16472014-04-11 19:02:482972 if (color_chooser_info_.get())
2973 color_chooser_info_->chooser->End();
2974
2975 color_chooser_info_.reset(new ColorChooserInfo(
2976 render_frame_message_source_->GetProcess()->GetID(),
2977 render_frame_message_source_->GetRoutingID(),
2978 new_color_chooser,
2979 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202980}
2981
[email protected]b172aee2012-04-10 17:05:262982void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482983 if (color_chooser_info_ &&
2984 color_chooser_id == color_chooser_info_->identifier)
2985 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202986}
2987
[email protected]b172aee2012-04-10 17:05:262988void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322989 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482990 if (color_chooser_info_ &&
2991 color_chooser_id == color_chooser_info_->identifier)
2992 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202993}
2994
[email protected]d0759f492012-04-19 22:50:502995// This exists for render views that don't have a WebUI, but do have WebUI
2996// bindings enabled.
2997void WebContentsImpl::OnWebUISend(const GURL& source_url,
2998 const std::string& name,
2999 const base::ListValue& args) {
3000 if (delegate_)
3001 delegate_->WebUISend(this, source_url, name, args);
3002}
3003
thestigc4cac8f2014-09-04 21:17:503004#if defined(ENABLE_PLUGINS)
[email protected]d8415ad92012-08-23 14:40:503005void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443006 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503007 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343008 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163009 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443010 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163011 return;
[email protected]d8415ad92012-08-23 14:40:503012 }
3013
[email protected]8c8fc292012-11-23 18:57:163014 if (!delegate_->RequestPpapiBrokerPermission(
3015 this, url, plugin_path,
3016 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443017 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163018 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443019 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163020 }
[email protected]d8415ad92012-08-23 14:40:503021}
3022
[email protected]ea0309c2013-08-06 19:35:443023void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503024 bool result) {
[email protected]ea0309c2013-08-06 19:35:443025 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503026}
3027
[email protected]c4538072013-03-18 02:17:553028void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373029 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083030 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553031 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393032 // For more info, see comment above classes BrowserPluginEmbedder and
3033 // BrowserPluginGuest.
3034 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143035 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083036 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373037}
thestigc4cac8f2014-09-04 21:17:503038#endif
[email protected]19be7a62012-10-01 23:03:373039
[email protected]41225fe2013-03-29 05:32:023040void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393041 int id,
[email protected]749fadd2013-05-15 08:37:483042 int http_status_code,
[email protected]795c28972012-12-06 06:13:393043 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303044 const std::vector<SkBitmap>& bitmaps,
3045 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133046 if (bitmaps.size() != original_bitmap_sizes.size())
3047 return;
3048
[email protected]41225fe2013-03-29 05:32:023049 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3050 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393051 // Currently WebContents notifies us of ANY downloads so that it is
3052 // possible to get here.
3053 return;
3054 }
3055 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303056 iter->second.Run(
3057 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393058 }
[email protected]41225fe2013-03-29 05:32:023059 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393060}
3061
3062void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393063 const std::vector<FaviconURL>& candidates) {
3064 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293065 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393066}
3067
dalecurtisbc6572e12014-09-12 19:22:303068void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3069 // ChromeOS has its own way of handling power save blocks for media.
3070#if !defined(OS_CHROMEOS)
3071 DCHECK(!audio_power_save_blocker_);
3072 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3073 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3074#endif
3075}
3076
3077void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3078 // ChromeOS has its own way of handling power save blocks for media.
3079#if !defined(OS_CHROMEOS)
3080 DCHECK(!video_power_save_blocker_);
3081 DCHECK(!active_video_players_.empty());
3082 video_power_save_blocker_ = PowerSaveBlocker::Create(
3083 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3084#if defined(OS_ANDROID)
3085 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3086 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3087#endif
3088#endif
3089}
3090
3091void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3092 // If there are no more audio players and we don't have audio stream
3093 // monitoring, release the audio power save blocker here instead of during
3094 // NotifyNavigationStateChanged().
3095 if (active_audio_players_.empty() &&
3096 !AudioStreamMonitor::monitoring_available()) {
3097 audio_power_save_blocker_.reset();
3098 }
3099
3100 // If there are no more video players, clear the video power save blocker.
3101 if (active_video_players_.empty())
3102 video_power_save_blocker_.reset();
3103}
3104
[email protected]1dd0bb752014-02-01 01:16:263105void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3106 bool has_video,
3107 bool has_audio) {
dalecurtisbc6572e12014-09-12 19:22:303108 if (has_audio) {
3109 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3110
3111 // If we don't have audio stream monitoring, allocate the audio power save
3112 // blocker here instead of during NotifyNavigationStateChanged().
3113 if (!audio_power_save_blocker_ &&
3114 !AudioStreamMonitor::monitoring_available()) {
3115 CreateAudioPowerSaveBlocker();
3116 }
[email protected]1dd0bb752014-02-01 01:16:263117 }
loislo0381a742014-09-11 10:58:113118
dalecurtisbc6572e12014-09-12 19:22:303119 if (has_video) {
3120 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3121
3122 // If we're not hidden and have just created a player, create a blocker.
3123 if (!video_power_save_blocker_ && !IsHidden())
3124 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113125 }
[email protected]1dd0bb752014-02-01 01:16:263126}
3127
3128void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303129 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3130 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3131 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063132}
3133
[email protected]50279492014-05-05 23:24:293134void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153135 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293136 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153137}
[email protected]d9030b82013-07-19 08:26:063138
[email protected]e67ebf32013-02-13 11:07:193139void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073140 if (delegate_)
3141 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193142}
3143
[email protected]17e286e2013-03-01 23:29:393144void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3145 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3146 BeforeFormRepostWarningShow());
3147}
3148
[email protected]ec6c05f2013-10-23 18:41:573149void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3150 Activate();
3151 if (delegate_)
3152 delegate_->ShowRepostFormWarningDialog(this);
3153}
3154
[email protected]b4c84012014-04-28 19:51:103155bool WebContentsImpl::HasAccessedInitialDocument() {
3156 return has_accessed_initial_document_;
3157}
3158
[email protected]96d185d2009-04-24 03:28:543159// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593160// loading, or done loading.
3161void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3162 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093163 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263164 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543165 if (is_loading == is_loading_)
3166 return;
3167
3168 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263169 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3170 base::string16());
[email protected]96d185d2009-04-24 03:28:543171 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563172 upload_size_ = 0;
3173 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543174 }
3175
[email protected]fa944cb82013-11-15 17:51:213176 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543177
3178 is_loading_ = is_loading;
3179 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033180 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543181
[email protected]6ebdc9b2010-09-27 16:55:573182 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093183 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213184 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543185
[email protected]eab61442013-11-14 18:35:483186 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593187 if (is_loading) {
naskob8744d22014-08-28 17:07:433188 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3189 this, "URL", url);
[email protected]91621872013-10-08 04:04:593190 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3191 DidStartLoading(render_view_host));
3192 } else {
naskob8744d22014-08-28 17:07:433193 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3194 this, "URL", url);
[email protected]91621872013-10-08 04:04:593195 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3196 DidStopLoading(render_view_host));
3197 }
[email protected]66798902013-10-01 18:40:163198
3199 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213200 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3201 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543202 if (details)
[email protected]8ff00d72012-10-23 19:12:213203 det = Details<LoadNotificationDetails>(details);
3204 NotificationService::current()->Notify(
3205 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543206}
3207
[email protected]959be4c2014-04-08 15:01:333208void WebContentsImpl::SelectRange(const gfx::Point& start,
3209 const gfx::Point& end) {
3210 RenderFrameHost* focused_frame = GetFocusedFrame();
3211 if (!focused_frame)
3212 return;
3213
3214 focused_frame->Send(
3215 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3216}
3217
[email protected]b172aee2012-04-10 17:05:263218void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463219 // If we are creating a RVH for a restored controller, then we need to make
3220 // sure the RenderView starts with a next_page_id_ larger than the number
3221 // of restored entries. This must be called before the RenderView starts
3222 // navigating (to avoid a race between the browser updating max_page_id and
3223 // the renderer updating next_page_id_). Because of this, we only call this
3224 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563225 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583226 if (max_restored_page_id >
3227 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3228 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3229 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323230}
3231
[email protected]b172aee2012-04-10 17:05:263232bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263233 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323234 // For file URLs without a title, use the pathname instead. In the case of a
3235 // synthesized title, we don't want the update to count toward the "one set
3236 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263237 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323238 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513239 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243240 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323241 explicit_set = false; // Don't count synthetic titles toward the set limit.
3242 } else {
[email protected]8af69c6c2014-03-03 19:05:313243 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323244 explicit_set = true;
3245 }
3246
[email protected]987fc3a2011-05-26 14:18:093247 // If a page is created via window.open and never navigated,
3248 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553249 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093250 if (entry) {
[email protected]36fc0392011-12-25 03:59:513251 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093252 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323253
[email protected]36fc0392011-12-25 03:59:513254 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093255 } else {
3256 if (page_title_when_no_navigation_entry_ == final_title)
3257 return false; // Nothing changed, don't bother.
3258
3259 page_title_when_no_navigation_entry_ = final_title;
3260 }
[email protected]420ae012009-04-24 05:16:323261
[email protected]420ae012009-04-24 05:16:323262 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233263 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323264
[email protected]66798902013-10-01 18:40:163265 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533266 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163267
3268 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213269 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463270 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213271 NotificationService::current()->Notify(
3272 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3273 Source<WebContents>(this),
3274 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043275
[email protected]420ae012009-04-24 05:16:323276 return true;
3277}
3278
[email protected]960b0372014-05-19 18:01:003279void WebContentsImpl::SendLoadProgressChanged() {
3280 loading_last_progress_update_ = base::TimeTicks::Now();
3281 double progress = 0.0;
3282 int frame_count = 0;
3283
3284 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3285 it != loading_progresses_.end();
3286 ++it) {
3287 progress += it->second;
3288 ++frame_count;
3289 }
3290 if (frame_count == 0)
3291 return;
3292 progress /= frame_count;
3293 DCHECK(progress <= 1.0);
3294
3295 if (progress <= loading_total_progress_)
3296 return;
3297 loading_total_progress_ = progress;
3298
3299 if (delegate_)
3300 delegate_->LoadProgressChanged(this, progress);
3301}
3302
3303void WebContentsImpl::ResetLoadProgressState() {
3304 loading_progresses_.clear();
3305 loading_total_progress_ = 0.0;
3306 loading_weak_factory_.InvalidateWeakPtrs();
3307 loading_last_progress_update_ = base::TimeTicks();
3308}
3309
[email protected]02d7b6e2014-06-24 21:01:503310void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3311 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323312 // After sending out a swap notification, we need to send a disconnect
3313 // notification so that clients that pick up a pointer to |this| can NULL the
3314 // pointer. See Bug 1230284.
3315 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283317 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113318
3319 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283320 std::pair<RenderViewHost*, RenderViewHost*> details =
3321 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213322 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283323 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213324 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283325 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393326
3327 // Ensure that the associated embedder gets cleared after a RenderViewHost
3328 // gets swapped, so we don't reuse the same embedder next time a
3329 // RenderViewHost is attached to this WebContents.
3330 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323331}
3332
[email protected]02d7b6e2014-06-24 21:01:503333void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3334 RenderFrameHost* new_host) {
3335 FOR_EACH_OBSERVER(WebContentsObserver,
3336 observers_,
3337 RenderFrameHostChanged(old_host, new_host));
3338}
3339
[email protected]da7a7182013-09-06 08:11:113340// TODO(avi): Remove this entire function because this notification is already
3341// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263342void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323343 if (!notify_disconnection_)
3344 return;
3345
3346 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213347 NotificationService::current()->Notify(
3348 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3349 Source<WebContents>(this),
3350 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323351}
3352
[email protected]cbb1ef592013-06-05 19:49:463353void WebContentsImpl::NotifyNavigationEntryCommitted(
3354 const LoadCommittedDetails& load_details) {
3355 FOR_EACH_OBSERVER(
3356 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3357}
3358
[email protected]f114fa42013-12-06 17:06:443359bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3360 const IPC::Message& message) {
3361 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313362}
3363
[email protected]c31a84802014-04-03 15:55:493364const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3365 return GetLastCommittedURL();
3366}
3367
[email protected]b849847b2013-12-10 21:57:583368void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3369 // Note this is only for subframes, the notification for the main frame
3370 // happens in RenderViewCreated.
3371 FOR_EACH_OBSERVER(WebContentsObserver,
3372 observers_,
3373 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303374 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583375}
3376
3377void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193378 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583379 FOR_EACH_OBSERVER(WebContentsObserver,
3380 observers_,
3381 RenderFrameDeleted(render_frame_host));
3382}
3383
[email protected]a09d53ce2014-01-31 00:46:423384void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303385 if (delegate_)
3386 delegate_->WorkerCrashed(this);
3387}
3388
[email protected]a09d53ce2014-01-31 00:46:423389void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3390 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103391 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423392 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103393 if (GetBrowserPluginGuest()) {
3394 WebContentsViewGuest* view_guest =
3395 static_cast<WebContentsViewGuest*>(GetView());
3396 context_menu_params = view_guest->ConvertContextMenuParams(params);
3397 }
3398 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423399 return;
3400
[email protected]077e704b2014-05-23 19:24:103401 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3402 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423403}
3404
[email protected]87de04b02014-04-08 22:14:493405void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013406 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493407 const base::string16& message,
3408 const base::string16& default_prompt,
3409 const GURL& frame_url,
3410 JavaScriptMessageType javascript_message_type,
3411 IPC::Message* reply_msg) {
3412 // Suppress JavaScript dialogs when requested. Also suppress messages when
3413 // showing an interstitial as it's shown over the previous page and we don't
3414 // want the hidden page's dialogs to interfere with the interstitial.
3415 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013416 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493417 IsSwappedOut() ||
3418 ShowingInterstitialPage() ||
3419 !delegate_ ||
3420 delegate_->ShouldSuppressDialogs() ||
3421 !delegate_->GetJavaScriptDialogManager();
3422
3423 if (!suppress_this_message) {
3424 std::string accept_lang = GetContentClient()->browser()->
3425 GetAcceptLangs(GetBrowserContext());
3426 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3427 dialog_manager_->RunJavaScriptDialog(
3428 this,
3429 frame_url.GetOrigin(),
3430 accept_lang,
3431 javascript_message_type,
3432 message,
3433 default_prompt,
3434 base::Bind(&WebContentsImpl::OnDialogClosed,
3435 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013436 render_frame_host->GetProcess()->GetID(),
3437 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493438 reply_msg,
3439 false),
3440 &suppress_this_message);
3441 }
3442
3443 if (suppress_this_message) {
3444 // If we are suppressing messages, just reply as if the user immediately
3445 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013446 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3447 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283448 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493449 }
3450
3451 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3452 // http://crbug.com/288961 ). The only safe thing to do here is return.
3453}
3454
3455void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013456 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493457 const base::string16& message,
3458 bool is_reload,
3459 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013460 RenderFrameHostImpl* rfhi =
3461 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493462 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013463 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493464 if (delegate_)
3465 delegate_->WillRunBeforeUnloadConfirm();
3466
3467 bool suppress_this_message =
3468 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3469 !delegate_ ||
3470 delegate_->ShouldSuppressDialogs() ||
3471 !delegate_->GetJavaScriptDialogManager();
3472 if (suppress_this_message) {
3473 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3474 return;
3475 }
3476
3477 is_showing_before_unload_dialog_ = true;
3478 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3479 dialog_manager_->RunBeforeUnloadDialog(
3480 this, message, is_reload,
3481 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013482 render_frame_host->GetProcess()->GetID(),
3483 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283484 false));
[email protected]87de04b02014-04-08 22:14:493485}
3486
[email protected]a86c0e962013-12-17 17:10:393487WebContents* WebContentsImpl::GetAsWebContents() {
3488 return this;
3489}
3490
[email protected]7912e822014-04-16 02:37:033491bool WebContentsImpl::IsNeverVisible() {
3492 if (!delegate_)
3493 return false;
3494 return delegate_->IsNeverVisible(this);
3495}
3496
[email protected]95640212014-07-26 18:14:303497#if defined(OS_WIN)
3498gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3499 return accessible_parent_;
3500}
3501#endif
3502
[email protected]5a3bdf52012-05-24 15:12:573503RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3504 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323505}
3506
[email protected]8ff00d72012-10-23 19:12:213507RendererPreferences WebContentsImpl::GetRendererPrefs(
3508 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463509 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513510}
3511
[email protected]b172aee2012-04-10 17:05:263512gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173513 if (delegate_)
3514 return delegate_->GetRootWindowResizerRect();
3515 return gfx::Rect();
3516}
3517
[email protected]7a846df2012-09-20 19:17:393518void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273519 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393520 browser_plugin_embedder_.reset();
3521}
3522
[email protected]b172aee2012-04-10 17:05:263523void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443524 // Don't send notifications if we are just creating a swapped-out RVH for
3525 // the opener chain. These won't be used for view-source or WebUI, so it's
3526 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243527 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443528 return;
3529
[email protected]86f98a22013-03-20 14:35:003530 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313531 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083532
[email protected]8ff00d72012-10-23 19:12:213533 NotificationService::current()->Notify(
3534 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3535 Source<WebContents>(this),
3536 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323537
3538 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353539 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213540 if (GetRenderManager()->pending_web_ui())
3541 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323542
[email protected]6286a372013-10-09 04:03:273543 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333544 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323545 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183546 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583547 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323548 }
[email protected]0666aef2009-05-13 19:48:083549
[email protected]60780f412013-02-25 16:34:103550 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263551
3552 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253553 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583554
3555 // We tell the observers now instead of when the main RenderFrameHostImpl is
3556 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3557 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363558 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583559 FOR_EACH_OBSERVER(
3560 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303561 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
[email protected]420ae012009-04-24 05:16:323562}
3563
[email protected]b172aee2012-04-10 17:05:263564void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523565 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323566 // Don't notify the world, since this came from a renderer in the
3567 // background.
3568 return;
3569 }
3570
[email protected]da7a7182013-09-06 08:11:113571 notify_disconnection_ = true;
3572 // TODO(avi): Remove. http://crbug.com/170921
3573 NotificationService::current()->Notify(
3574 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3575 Source<WebContents>(this),
3576 NotificationService::NoDetails());
3577
[email protected]be1f56ab2011-12-22 06:55:313578 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233579 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303580
3581 // Restore the focus to the tab (otherwise the focus will be on the top
3582 // window).
[email protected]484ae5912010-09-29 19:16:143583 if (was_crashed && !FocusLocationBarByDefault() &&
3584 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063585 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143586 }
[email protected]32ded2212011-11-10 18:51:433587
[email protected]d8c660432011-12-22 20:51:253588 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323589}
3590
[email protected]ec6a7eb2013-04-22 17:34:223591void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3592 base::TerminationStatus status,
3593 int error_code) {
[email protected]151a63d2011-12-20 22:32:523594 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323595 // The pending page's RenderViewHost is gone.
3596 return;
3597 }
3598
[email protected]2fcdcc32014-03-05 02:14:073599 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3600 // renderer may not have made a clean exit.
3601 if (IsFullscreenForCurrentTab())
3602 ToggleFullscreenMode(false);
3603
[email protected]698191dc2014-02-25 01:06:133604 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3605 if (dialog_manager_)
3606 dialog_manager_->CancelActiveAndPendingDialogs(this);
3607
[email protected]f738bdcb2014-07-11 20:40:443608 if (delegate_)
3609 delegate_->HideValidationMessage(this);
3610
[email protected]e3b10d12014-03-28 16:06:093611 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323612 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233613 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453614
[email protected]960b0372014-05-19 18:01:003615 // Reset the loading progress. TODO(avi): What does it mean to have a
3616 // "renderer crash" when there is more than one renderer process serving a
3617 // webpage? Once this function is called at a more granular frame level, we
3618 // probably will need to more granularly reset the state here.
3619 ResetLoadProgressState();
3620 loading_frames_in_progress_ = 0;
3621
[email protected]d8c660432011-12-22 20:51:253622 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273623 observers_,
[email protected]58d5cfe2013-07-10 02:40:523624 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323625}
3626
[email protected]b172aee2012-04-10 17:05:263627void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253628 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063629}
3630
[email protected]b172aee2012-04-10 17:05:263631void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3632 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043633 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153634 // Ensure that this state update comes from either the active RVH or one of
3635 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413636 // TODO(nasko): This should go through RenderFrameHost.
3637 // TODO(creis): We can't update state for cross-process subframes until we
3638 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3639 if (rvh != GetRenderViewHost() &&
3640 !GetRenderManager()->IsRVHOnSwappedOutList(
3641 static_cast<RenderViewHostImpl*>(rvh)))
3642 return;
[email protected]420ae012009-04-24 05:16:323643
3644 // We must be prepared to handle state updates for any page, these occur
3645 // when the user is scrolling and entering form data, as well as when we're
3646 // leaving a page, in which case our state may have already been moved to
3647 // the next page. The navigation controller will look up the appropriate
3648 // NavigationEntry and update it when it is notified via the delegate.
3649
3650 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583651 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323652 if (entry_index < 0)
3653 return;
[email protected]10f417c52011-12-28 21:04:233654 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323655
[email protected]691aa2f2013-05-28 22:52:043656 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323657 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043658 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323659 controller_.NotifyEntryChanged(entry, entry_index);
3660}
3661
avi450ce00e2014-09-24 01:58:523662void WebContentsImpl::UpdateTargetURL(const GURL& url) {
[email protected]6934a702011-12-20 00:04:513663 if (delegate_)
avi450ce00e2014-09-24 01:58:523664 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323665}
3666
[email protected]b172aee2012-04-10 17:05:263667void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103668#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293669 // The UI may be in an event-tracking loop, such as between the
3670 // mouse-down and mouse-up in text selection or a button click.
3671 // Defer the close until after tracking is complete, so that we
3672 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293673 // TODO(shess): This could get more fine-grained. For instance,
3674 // closing a tab in another window while selecting text in the
3675 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103676 if (view_->IsEventTracking()) {
3677 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293678 return;
3679 }
[email protected]60780f412013-02-25 16:34:103680#endif
[email protected]07707302009-11-06 00:50:293681
[email protected]420ae012009-04-24 05:16:323682 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523683 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513684 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323685}
3686
[email protected]66bbadaf2014-03-28 16:25:543687void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573688 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3689 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573690}
3691
[email protected]6f2ac772014-07-24 22:22:083692void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253693 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173694#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563695 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173696#endif
3697}
3698
3699bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3700#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563701 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173702#else
3703 return false;
3704#endif
3705}
3706
[email protected]b172aee2012-04-10 17:05:263707void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513708 if (delegate_ && delegate_->IsPopupOrPanel(this))
3709 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323710}
3711
[email protected]e3b10d12014-03-28 16:06:093712void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3713 bool to_different_document) {
3714 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3715 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323716}
3717
[email protected]723971b2014-02-12 11:08:253718void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323719 scoped_ptr<LoadNotificationDetails> details;
3720
[email protected]9595fd82013-04-19 21:28:493721 // Use the last committed entry rather than the active one, in case a
3722 // pending entry has been created.
3723 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203724 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493725
[email protected]420ae012009-04-24 05:16:323726 // An entry may not exist for a stop when loading an initial blank page or
3727 // if an iframe injected by script into a blank page finishes loading.
3728 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203729 base::TimeDelta elapsed =
3730 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323731
3732 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513733 entry->GetVirtualURL(),
3734 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323735 elapsed,
3736 &controller_,
3737 controller_.GetCurrentEntryIndex()));
3738 }
3739
[email protected]e3b10d12014-03-28 16:06:093740 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3741 details.get());
[email protected]420ae012009-04-24 05:16:323742}
3743
[email protected]b172aee2012-04-10 17:05:263744void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163745 controller_.DiscardNonCommittedEntries();
3746
3747 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213748 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163749}
3750
[email protected]59167c22013-06-03 18:07:323751void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103752 has_accessed_initial_document_ = true;
3753
[email protected]d1371bf8e2014-04-19 03:26:243754 // We may have left a failed browser-initiated navigation in the address bar
3755 // to let the user edit it and try again. Clear it now that content might
3756 // show up underneath it.
3757 if (!IsLoading() && controller_.GetPendingEntry())
3758 controller_.DiscardPendingEntry();
3759
[email protected]59167c22013-06-03 18:07:323760 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503761 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323762}
3763
[email protected]3f19f1a2014-05-02 05:23:273764void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473765 // No action is necessary if the opener has already been cleared.
3766 if (!opener_)
3767 return;
3768
3769 // Clear our opener so that future cross-process navigations don't have an
3770 // opener assigned.
3771 RemoveDestructionObserver(opener_);
3772 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273773
3774 // Notify all swapped out RenderViewHosts for this tab. This is important
3775 // in case we go back to them, or if another window in those processes tries
3776 // to access window.opener.
creisbbbeb062014-08-25 18:20:313777 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273778}
3779
[email protected]39f2f9252014-05-03 00:54:013780void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293781 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293783 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093784
3785 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213786 NotificationService::current()->Notify(
3787 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3788 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293789 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083790}
3791
[email protected]ef3adfc2014-05-11 00:04:543792void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3793 int32 page_id,
3794 const base::string16& title,
3795 base::i18n::TextDirection title_direction) {
3796 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3797
3798 // If we have a title, that's a pretty good indication that we've started
3799 // getting useful data.
3800 SetNotWaitingForResponse();
3801
3802 // Try to find the navigation entry, which might not be the current one.
3803 // For example, it might be from a pending RVH for the pending entry.
3804 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3805 rvh->GetSiteInstance(), page_id);
3806
3807 // We can handle title updates when we don't have an entry in
3808 // UpdateTitleForEntry, but only if the update is from the current RVH.
3809 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3810 if (!entry && rvh != GetRenderViewHost())
3811 return;
3812
3813 // TODO(evan): make use of title_direction.
3814 // http://code.google.com/p/chromium/issues/detail?id=27094
3815 if (!UpdateTitleForEntry(entry, title))
3816 return;
3817
3818 // Broadcast notifications when the UI should be updated.
3819 if (entry == controller_.GetEntryAtOffset(0))
3820 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3821}
3822
3823void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3824 const std::string& encoding) {
3825 SetEncoding(encoding);
3826}
3827
[email protected]39f2f9252014-05-03 00:54:013828void WebContentsImpl::DocumentAvailableInMainFrame(
3829 RenderViewHost* render_view_host) {
3830 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3831 DocumentAvailableInMainFrame());
3832}
[email protected]e1c3a552012-05-04 20:51:323833void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3834 // Tell the active RenderViewHost to run unload handlers and close, as long
3835 // as the request came from a RenderViewHost in the same BrowsingInstance.
3836 // In most cases, we receive this from a swapped out RenderViewHost.
3837 // It is possible to receive it from one that has just been swapped in,
3838 // in which case we might as well deliver the message anyway.
3839 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3840 GetRenderViewHost()->ClosePage();
3841}
3842
[email protected]f546640b2012-05-15 00:03:493843void WebContentsImpl::RouteMessageEvent(
3844 RenderViewHost* rvh,
3845 const ViewMsg_PostMessage_Params& params) {
3846 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363847 // came from a RenderViewHost in the same BrowsingInstance or if this
3848 // WebContents is dedicated to a browser plugin guest.
3849 // Note: This check means that an embedder could theoretically receive a
3850 // postMessage from anyone (not just its own guests). However, this is
3851 // probably not a risk for apps since other pages won't have references
3852 // to App windows.
3853 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3854 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493855 return;
3856
3857 ViewMsg_PostMessage_Params new_params(params);
3858
[email protected]0bc7f3542013-10-21 15:05:533859 if (!params.message_port_ids.empty()) {
3860 MessagePortMessageFilter* message_port_message_filter =
3861 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3862 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093863 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3864 params.message_port_ids,
3865 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533866 }
3867
[email protected]f546640b2012-05-15 00:03:493868 // If there is a source_routing_id, translate it to the routing ID for
3869 // the equivalent swapped out RVH in the target process. If we need
3870 // to create a swapped out RVH for the source tab, we create its opener
3871 // chain as well, since those will also be accessible to the target page.
3872 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3873 // Try to look up the WebContents for the source page.
3874 WebContentsImpl* source_contents = NULL;
3875 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3876 rvh->GetProcess()->GetID(), params.source_routing_id);
3877 if (source_rvh) {
3878 source_contents = static_cast<WebContentsImpl*>(
3879 source_rvh->GetDelegate()->GetAsWebContents());
3880 }
3881
3882 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363883 if (GetBrowserPluginGuest()) {
3884 // We create a swapped out RenderView for the embedder in the guest's
3885 // render process but we intentionally do not expose the embedder's
3886 // opener chain to it.
3887 new_params.source_routing_id =
3888 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3889 } else {
3890 new_params.source_routing_id =
3891 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3892 }
[email protected]f546640b2012-05-15 00:03:493893 } else {
3894 // We couldn't find it, so don't pass a source frame.
3895 new_params.source_routing_id = MSG_ROUTING_NONE;
3896 }
3897 }
3898
3899 // In most cases, we receive this from a swapped out RenderViewHost.
3900 // It is possible to receive it from one that has just been swapped in,
3901 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183902 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493903}
3904
[email protected]a796f202012-05-30 14:14:253905bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263906 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253907 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263908 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253909 if (!delegate_)
3910 return false;
3911 return delegate_->AddMessageToConsole(this, level, message, line_no,
3912 source_id);
3913}
3914
[email protected]9e797d22014-08-08 21:31:303915WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273916 // We want to base the page config off of the actual URL, rather than the
3917 // virtual URL.
3918 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3919 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003920 GURL url = controller_.GetActiveEntry()
3921 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153922
[email protected]9e797d22014-08-08 21:31:303923 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323924}
3925
[email protected]0eba810b2012-10-18 03:19:363926int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213927 SiteInstance* instance) {
[email protected]82307f6b2014-08-07 03:30:123928 return GetRenderManager()->CreateRenderFrame(
3929 instance, MSG_ROUTING_NONE, true, true, true);
[email protected]0eba810b2012-10-18 03:19:363930}
3931
[email protected]b172aee2012-04-10 17:05:263932void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273933 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253934 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223935
[email protected]ea114722012-03-12 01:11:253936 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173937 if (rdh) // NULL in unittests.
3938 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253939}
3940
[email protected]b172aee2012-04-10 17:05:263941void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443942 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253943 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443944}
3945
[email protected]b172aee2012-04-10 17:05:263946void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563947 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263948 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153949 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523950 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153951 return;
3952
[email protected]9f76c1e2012-03-05 15:15:583953 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3954
[email protected]e5fc1632011-08-08 07:51:533955 // Ignore renderer unresponsive event if debugger is attached to the tab
3956 // since the event may be a result of the renderer sitting on a breakpoint.
3957 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363958 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533959 return;
3960
[email protected]2e9d79f2013-08-16 05:45:563961 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323962 // Hang occurred while firing the beforeunload/unload handler.
3963 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583964 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323965
[email protected]fa944cb82013-11-15 17:51:213966 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323967 return;
3968
3969 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563970 // nothing we can do to recover. If the hang is in the beforeunload handler,
3971 // pretend the beforeunload listeners have all fired and allow the delegate
3972 // to continue closing; the user will not have the option of cancelling the
3973 // close. Otherwise, pretend the unload listeners have all fired and close
3974 // the tab.
3975 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463976 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563977 delegate_->BeforeUnloadFired(this, true, &close);
3978 }
3979 if (close)
3980 Close(rvh);
[email protected]420ae012009-04-24 05:16:323981 return;
3982 }
3983
[email protected]9f76c1e2012-03-05 15:15:583984 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473985 return;
3986
[email protected]6934a702011-12-20 00:04:513987 if (delegate_)
3988 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323989}
3990
[email protected]b172aee2012-04-10 17:05:263991void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513992 if (delegate_)
3993 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323994}
3995
[email protected]b172aee2012-04-10 17:05:263996void WebContentsImpl::LoadStateChanged(
3997 const GURL& url,
3998 const net::LoadStateWithParam& load_state,
3999 uint64 upload_position,
4000 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324001 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564002 upload_position_ = upload_position;
4003 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504004 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214005 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304006 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214007 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324008 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464009 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224010 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4011 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464012 }
[email protected]420ae012009-04-24 05:16:324013}
4014
[email protected]b172aee2012-04-10 17:05:264015void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554016 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324017 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124018 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4019 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514020 if (delegate_)
4021 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094022 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324023}
4024
[email protected]58d5cfe2013-07-10 02:40:524025void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544026 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234027 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224028 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544029}
4030
[email protected]b172aee2012-04-10 17:05:264031void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104032 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214033 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264034 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4035 // here during container initialization and normal window size will be set
4036 // later. In case of tab duplication this resizing to 0x0 prevents setting
4037 // normal size later so just ignore it.
4038 if (!size.IsEmpty())
4039 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324040}
4041
[email protected]af905902013-10-01 21:38:514042void WebContentsImpl::CancelModalDialogsForRenderManager() {
4043 // We need to cancel modal dialogs when doing a process swap, since the load
4044 // deferrer would prevent us from swapping out.
4045 if (dialog_manager_)
4046 dialog_manager_->CancelActiveAndPendingDialogs(this);
4047}
4048
[email protected]02d7b6e2014-06-24 21:01:504049void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4050 RenderFrameHost* new_host,
4051 bool is_main_frame) {
4052 if (is_main_frame) {
4053 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4054 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084055
[email protected]02d7b6e2014-06-24 21:01:504056 // Make sure the visible RVH reflects the new delegate's preferences.
4057 if (delegate_)
4058 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394059
[email protected]02d7b6e2014-06-24 21:01:504060 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4061 }
4062
4063 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544064}
4065
[email protected]14392a52012-05-02 20:28:444066int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4067 SiteInstance* instance) {
4068 if (!opener_)
4069 return MSG_ROUTING_NONE;
4070
4071 // Recursively create RenderViews for anything else in the opener chain.
4072 return opener_->CreateOpenerRenderViews(instance);
4073}
4074
4075int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4076 int opener_route_id = MSG_ROUTING_NONE;
4077
4078 // If this tab has an opener, ensure it has a RenderView in the given
4079 // SiteInstance as well.
4080 if (opener_)
4081 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4082
[email protected]45a22ad2013-02-21 03:25:004083 // If any of the renderers (current, pending, or swapped out) for this
4084 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214085 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4086 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374087
[email protected]fa944cb82013-11-15 17:51:214088 if (GetRenderManager()->pending_render_view_host() &&
4089 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4090 instance)
4091 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004092
[email protected]fa944cb82013-11-15 17:51:214093 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374094 instance);
4095 if (rvh)
4096 return rvh->GetRoutingID();
4097
[email protected]14392a52012-05-02 20:28:444098 // Create a swapped out RenderView in the given SiteInstance if none exists,
4099 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]82307f6b2014-08-07 03:30:124100 return GetRenderManager()->CreateRenderFrame(
4101 instance, opener_route_id, true, true, true);
[email protected]14392a52012-05-02 20:28:444102}
4103
[email protected]b172aee2012-04-10 17:05:264104NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194105 return GetController();
[email protected]3a3d47472010-07-15 21:03:544106}
4107
[email protected]b172aee2012-04-10 17:05:264108WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:564109 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:324110}
4111
[email protected]10f417c52011-12-28 21:04:234112NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264113 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324114 return controller_.GetLastCommittedEntry();
4115}
4116
[email protected]b172aee2012-04-10 17:05:264117bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164118 RenderViewHost* render_view_host,
4119 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044120 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124121 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434122 TRACE_EVENT0("browser,navigation",
4123 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444124 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484125 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164126 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4127 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4128 // case this because RWH is still a base class of RenderViewHost, and child
4129 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124130 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164131 RenderWidgetHostViewChildFrame* rwh_view_child =
4132 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164133 rwh_view = rwh_view_child;
4134 } else {
4135 rwh_view = view_->CreateViewForWidget(render_view_host);
4136 }
[email protected]1a98a932009-11-17 00:12:524137
[email protected]420ae012009-04-24 05:16:324138 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444139 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214140 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324141
[email protected]74ce1ad2011-12-16 21:51:464142 // Make sure we use the correct starting page_id in the new RenderView.
4143 UpdateMaxPageIDIfNecessary(render_view_host);
4144 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584145 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464146
[email protected]9f76c1e2012-03-05 15:15:584147 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264148 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494149 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044150 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494151 max_page_id,
4152 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524153 return false;
[email protected]14392a52012-05-02 20:28:444154 }
[email protected]a4127722011-04-27 23:13:524155
[email protected]a220b5932013-09-21 03:47:444156#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504157 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4158 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444159 if (rwh_view) {
4160 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4161 render_widget_host->WasResized();
4162 }
[email protected]f8233cc2011-05-31 20:24:504163#endif
4164
[email protected]420ae012009-04-24 05:16:324165 return true;
4166}
4167
[email protected]82307f6b2014-08-07 03:30:124168bool WebContentsImpl::CreateRenderFrameForRenderManager(
4169 RenderFrameHost* render_frame_host,
4170 int parent_routing_id) {
naskob8744d22014-08-28 17:07:434171 TRACE_EVENT0("browser,navigation",
4172 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124173
4174 RenderFrameHostImpl* rfh =
4175 static_cast<RenderFrameHostImpl*>(render_frame_host);
4176 if (!rfh->CreateRenderFrame(parent_routing_id))
4177 return false;
4178
4179 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4180 // RenderFrameHost will have to be associated with the appropriate
4181 // RenderWidgetHostView or a new one should be created here.
4182
4183 return true;
4184}
4185
[email protected]7d244f12013-08-22 21:41:514186#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454187
[email protected]155c7f22013-12-09 17:07:184188base::android::ScopedJavaLocalRef<jobject>
4189WebContentsImpl::GetJavaWebContents() {
4190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564191 return GetWebContentsAndroid()->GetJavaObject();
4192}
[email protected]155c7f22013-12-09 17:07:184193
[email protected]0e813a52014-08-13 10:34:564194WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184195 WebContentsAndroid* web_contents_android =
4196 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4197 if (!web_contents_android) {
4198 web_contents_android = new WebContentsAndroid(this);
4199 SetUserData(kWebContentsAndroidKey, web_contents_android);
4200 }
[email protected]0e813a52014-08-13 10:34:564201 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184202}
4203
[email protected]7d244f12013-08-22 21:41:514204bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4205 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164206 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044207 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594208 true);
[email protected]7d244f12013-08-22 21:41:514209}
[email protected]fc2b46b2014-05-03 16:33:454210
4211#elif defined(OS_MACOSX)
4212
[email protected]75f4df72014-07-16 22:39:424213void WebContentsImpl::SetAllowOtherViews(bool allow) {
4214 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454215}
4216
[email protected]75f4df72014-07-16 22:39:424217bool WebContentsImpl::GetAllowOtherViews() {
4218 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454219}
4220
[email protected]7d244f12013-08-22 21:41:514221#endif
4222
[email protected]6fba26d2014-04-29 09:38:284223void WebContentsImpl::OnDialogClosed(int render_process_id,
4224 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264225 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494226 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264227 bool success,
[email protected]fcf75d42013-12-03 20:11:264228 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284229 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4230 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494231 last_dialog_suppressed_ = dialog_was_suppressed;
4232
[email protected]beb440c2009-11-06 04:08:544233 if (is_showing_before_unload_dialog_ && !success) {
4234 // If a beforeunload dialog is canceled, we need to stop the throbber from
4235 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284236 if (rfh)
4237 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354238 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104239
[email protected]6d65a462013-06-21 21:29:124240 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4241 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544242 }
[email protected]87de04b02014-04-08 22:14:494243
[email protected]beb440c2009-11-06 04:08:544244 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284245 if (rfh) {
4246 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4247 dialog_was_suppressed);
4248 } else {
4249 // Don't leak the sync IPC reply if the RFH or process is gone.
4250 delete reply_msg;
4251 }
[email protected]beb440c2009-11-06 04:08:544252}
4253
[email protected]b172aee2012-04-10 17:05:264254void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544255 if (encoding == last_reported_encoding_)
4256 return;
4257 last_reported_encoding_ = encoding;
4258
4259 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124260 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104261}
[email protected]f45d2a72010-03-08 23:28:354262
[email protected]b172aee2012-04-10 17:05:264263void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484264 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444265 // Can be NULL during tests.
4266 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454267 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364268}
[email protected]9f76c1e2012-03-05 15:15:584269
[email protected]1ac10dca2013-08-20 20:47:044270bool WebContentsImpl::IsHidden() {
4271 return capturer_count_ == 0 && !should_normally_be_visible_;
4272}
4273
[email protected]b0936d22013-11-28 06:47:364274RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214275 return frame_tree_.root()->render_manager();
4276}
4277
[email protected]b172aee2012-04-10 17:05:264278RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584279 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4280}
[email protected]7900bfdb2012-05-24 19:31:244281
[email protected]f8497342013-02-05 22:15:024282BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394283 return browser_plugin_guest_.get();
4284}
4285
[email protected]738f57a2013-06-29 21:06:544286void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4287 CHECK(!browser_plugin_guest_);
4288 browser_plugin_guest_.reset(guest);
4289}
4290
[email protected]f8497342013-02-05 22:15:024291BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394292 return browser_plugin_embedder_.get();
4293}
[email protected]8ff00d72012-10-23 19:12:214294
[email protected]d9030b82013-07-19 08:26:064295void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194296 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304297 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4298 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4299 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064300}
4301
4302void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304303 active_audio_players_.clear();
4304 active_video_players_.clear();
4305 audio_power_save_blocker_.reset();
4306 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064307}
4308
[email protected]fc2b46b2014-05-03 16:33:454309gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214310 gfx::Size size;
4311 if (delegate_)
4312 size = delegate_->GetSizeForNewRenderView(this);
4313 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454314 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214315 return size;
4316}
4317
[email protected]ae7eeda2014-07-04 01:53:264318void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4319 FOR_EACH_OBSERVER(
4320 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554321}
4322
[email protected]222f5822014-02-05 23:40:494323void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4324 if (!delegate_)
4325 return;
4326 const gfx::Size new_size = GetPreferredSize();
4327 if (new_size != old_size)
4328 delegate_->UpdatePreferredSize(this, new_size);
4329}
4330
dalecurtisbc6572e12014-09-12 19:22:304331void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4332 ActiveMediaPlayerMap* player_map) {
4333 const uintptr_t key =
4334 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4335 DCHECK(std::find((*player_map)[key].begin(),
4336 (*player_map)[key].end(),
4337 player_cookie) == (*player_map)[key].end());
4338 (*player_map)[key].push_back(player_cookie);
4339}
4340
4341void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4342 ActiveMediaPlayerMap* player_map) {
4343 const uintptr_t key =
4344 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4345 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4346 if (it == player_map->end())
4347 return;
4348
4349 // Remove the player.
4350 PlayerList::iterator player_it =
4351 std::find(it->second.begin(), it->second.end(), player_cookie);
4352 if (player_it != it->second.end())
4353 it->second.erase(player_it);
4354
4355 // If there are no players left, remove the map entry.
4356 if (it->second.empty())
4357 player_map->erase(it);
4358}
4359
4360void WebContentsImpl::RemoveAllMediaPlayerEntries(
4361 RenderFrameHost* render_frame_host,
4362 ActiveMediaPlayerMap* player_map) {
4363 ActiveMediaPlayerMap::iterator it =
4364 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4365 if (it == player_map->end())
4366 return;
4367 player_map->erase(it);
4368}
4369
[email protected]23f41fd2014-06-21 05:29:174370void WebContentsImpl::ResumeResponseDeferredAtStart() {
4371 FrameTreeNode* node = frame_tree_.root();
4372 node->render_manager()->ResumeResponseDeferredAtStart();
4373}
4374
[email protected]34ff1cfc2014-08-20 06:16:054375void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4376 force_disable_overscroll_content_ = force_disable;
4377 if (view_)
4378 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4379}
4380
[email protected]8ff00d72012-10-23 19:12:214381} // namespace content