blob: 976c921f867aff24bb7be9226c1786d600a718d1 [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"
[email protected]29998f92014-06-15 03:12:1443#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5344#include "content/browser/message_port_message_filter.h"
45#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0646#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3047#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5048#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3249#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5050#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4851#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0952#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3353#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1154#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5855#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0356#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5657#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1458#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4259#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4460#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0261#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1762#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5163#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0264#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3665#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1166#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2867#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4468#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3669#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1770#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1471#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4672#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1573#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0074#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2775#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0076#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3777#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1478#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3079#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3280#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0981#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3482#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3883#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4284#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2585#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2186#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4887#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5488#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4989#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2090#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0391#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5792#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0593#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1694#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2995#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5396#include "net/http/http_cache.h"
97#include "net/http/http_transaction_factory.h"
98#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3499#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56100#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01101#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41102#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52103#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31104
[email protected]583418cc2013-01-17 14:01:10105#if defined(OS_ANDROID)
[email protected]23f41fd2014-06-21 05:29:17106#include "content/browser/android/content_view_core_impl.h"
[email protected]583418cc2013-01-17 14:01:10107#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45108#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18109#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00110#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10111#endif
112
[email protected]f66df822012-05-18 16:52:17113#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50114#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57115#endif
[email protected]3e45ba92009-02-20 21:09:00116
[email protected]420ae012009-04-24 05:16:32117// Cross-Site Navigations
118//
[email protected]b172aee2012-04-10 17:05:26119// If a WebContentsImpl is told to navigate to a different web site (as
120// determined by SiteInstance), it will replace its current RenderViewHost with
121// a new RenderViewHost dedicated to the new SiteInstance. This works as
122// follows:
[email protected]420ae012009-04-24 05:16:32123//
[email protected]fc6c1872013-10-03 01:22:35124// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46125// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32126// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35127// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32128// run in the current RVH.
129// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35130// that it has a pending cross-site request. We will check this on the IO
131// thread when deciding how to handle the response.
132// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46133// cancel all the pending logic. Otherwise we allow the pending RVH to send
134// the navigation request to its renderer.
135// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35136// main resource load on the pending RVH. It creates a
137// CrossSiteResourceHandler to check whether a process swap is needed when
138// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46139// - When RDH receives a response, the BufferedResourceHandler determines
140// whether it is a download. If so, it sends a message to the new renderer
141// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26142// pending RVH remains until the next DidNavigate event for this
143// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32144// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35145// download, the CrossSiteResourceHandler checks whether a process swap is
146// needed (either because CrossSiteRequestManager has state for it or because
147// a transfer was needed for a redirect).
148// - If so, CrossSiteResourceHandler pauses the response to first run the old
149// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36150// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
151// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35152// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
153// to a new process is needed, based on the stored pending_nav_params_. (This
154// is independent of whether we started out with a cross-process navigation.)
155// - If not, it just tells the ResourceDispatcherHost to resume the response
156// to its current RenderViewHost.
157// - If so, it cancels the current pending RenderViewHost and sets up a new
158// navigation using RequestTransferURL. When the transferred request
159// arrives in the ResourceDispatcherHost, we transfer the response and
160// resume it.
[email protected]420ae012009-04-24 05:16:32161// - The pending renderer sends a FrameNavigate message that invokes the
162// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46163// pending RVH.
[email protected]b0936d22013-11-28 06:47:36164// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15165// the user goes back. The process only stays live if another tab is using
166// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32167
[email protected]8ff00d72012-10-23 19:12:21168namespace content {
[email protected]420ae012009-04-24 05:16:32169namespace {
170
[email protected]960b0372014-05-19 18:01:00171const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
172
173// This matches what Blink's ProgressTracker has traditionally used for a
174// minimum progress value.
175const double kMinimumLoadingProgress = 0.1;
176
[email protected]82114f52012-03-20 22:53:41177const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05178
[email protected]155c7f22013-12-09 17:07:18179#if defined(OS_ANDROID)
180const char kWebContentsAndroidKey[] = "web_contents_android";
181#endif // OS_ANDROID
182
[email protected]e4abd3b42013-11-12 18:28:47183base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46184g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
185
thestigc4cac8f2014-09-04 21:17:50186static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39187 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29188 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30189 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02190 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58191 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02192 ++g_next_image_download_id,
193 url,
194 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30195 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02196 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39197}
198
[email protected]8bfc8272013-09-09 20:10:53199void NotifyCacheOnIO(
200 scoped_refptr<net::URLRequestContextGetter> request_context,
201 const GURL& url,
202 const std::string& http_method) {
203 request_context->GetURLRequestContext()->http_transaction_factory()->
204 GetCache()->OnExternalCacheHit(url, http_method);
205}
206
[email protected]9b159a52013-10-03 17:24:55207// Helper function for retrieving all the sites in a frame tree.
208bool CollectSites(BrowserContext* context,
209 std::set<GURL>* sites,
210 FrameTreeNode* node) {
211 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
212 return true;
213}
214
[email protected]a86c0e962013-12-17 17:10:39215bool ForEachFrameInternal(
216 const base::Callback<void(RenderFrameHost*)>& on_frame,
217 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41218 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39219 return true;
220}
221
[email protected]95640212014-07-26 18:14:30222bool ForEachPendingFrameInternal(
223 const base::Callback<void(RenderFrameHost*)>& on_frame,
224 FrameTreeNode* node) {
225 RenderFrameHost* pending_frame_host =
226 node->render_manager()->pending_frame_host();
227 if (pending_frame_host)
228 on_frame.Run(pending_frame_host);
229 return true;
230}
231
[email protected]a86c0e962013-12-17 17:10:39232void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
233 IPC::Message* message_copy = new IPC::Message(*message);
234 message_copy->set_routing_id(rfh->GetRoutingID());
235 rfh->Send(message_copy);
236}
237
[email protected]948481d2014-06-11 18:32:22238void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
239 RenderFrameHost* rfh) {
240 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
241 ->frame_tree_node()
242 ->render_manager()
243 ->GetRenderWidgetHostView();
244 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59245}
246
[email protected]95640212014-07-26 18:14:30247void SetAccessibilityModeOnFrame(AccessibilityMode mode,
248 RenderFrameHost* frame_host) {
249 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
250}
251
[email protected]420ae012009-04-24 05:16:32252} // namespace
253
[email protected]54944cde2012-12-09 09:24:59254WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15255 return WebContentsImpl::CreateWithOpener(
256 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19257}
258
259WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59260 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30261 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59262 WebContentsImpl* new_contents = new WebContentsImpl(
263 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30264
265 for (SessionStorageNamespaceMap::const_iterator it =
266 session_storage_namespace_map.begin();
267 it != session_storage_namespace_map.end();
268 ++it) {
269 new_contents->GetController()
270 .SetSessionStorageNamespace(it->first, it->second.get());
271 }
272
[email protected]54944cde2012-12-09 09:24:59273 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19274 return new_contents;
[email protected]a81343d232011-12-27 07:39:20275}
[email protected]746d3052012-05-22 15:15:47276
[email protected]e4abd3b42013-11-12 18:28:47277void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46278 g_created_callbacks.Get().push_back(callback);
279}
280
[email protected]e4abd3b42013-11-12 18:28:47281void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46282 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
283 if (g_created_callbacks.Get().at(i).Equals(callback)) {
284 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
285 return;
286 }
287 }
288}
289
[email protected]299d7f12012-05-23 05:31:15290WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47291 return rvh->GetDelegate()->GetAsWebContents();
292}
293
[email protected]a86c0e962013-12-17 17:10:39294WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
295 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
296 if (!rfh_impl)
297 return NULL;
298 return rfh_impl->delegate()->GetAsWebContents();
299}
300
[email protected]7fff43e2013-05-21 20:21:10301// WebContentsImpl::DestructionObserver ----------------------------------------
302
303class WebContentsImpl::DestructionObserver : public WebContentsObserver {
304 public:
305 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
306 : WebContentsObserver(watched_contents),
307 owner_(owner) {
308 }
309
310 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58311 virtual void WebContentsDestroyed() OVERRIDE {
312 owner_->OnWebContentsDestroyed(
313 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10314 }
315
316 private:
317 WebContentsImpl* owner_;
318
319 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
320};
321
[email protected]8ed16472014-04-11 19:02:48322WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
323 int render_frame_id,
324 ColorChooser* chooser,
325 int identifier)
326 : render_process_id(render_process_id),
327 render_frame_id(render_frame_id),
328 chooser(chooser),
329 identifier(identifier) {
330}
331
332WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
333}
334
[email protected]b172aee2012-04-10 17:05:26335// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32336
[email protected]b172aee2012-04-10 17:05:26337WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21338 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19339 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42340 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22341 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57342 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44343 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49344 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08345#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41346 accessible_parent_(NULL),
347#endif
[email protected]6ea6bdf2013-12-06 13:35:01348 frame_tree_(new NavigatorImpl(&controller_, this),
349 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34350 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03351 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23352 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
353 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34354 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26355 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00356 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00357 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56358 upload_size_(0),
359 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47360 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10361 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55362 capturer_count_(0),
363 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57364 is_being_destroyed_(false),
365 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15366 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01367 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02368 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38369 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21370 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
371 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29372 totalPinchGestureAmount_(0),
373 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44374 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42375 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03376 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49377 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05378 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30379 last_dialog_suppressed_(false),
380 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30381 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46382 audio_stream_monitor_(this),
383 loading_weak_factory_(this) {
[email protected]cbb1ef592013-06-05 19:49:46384 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
385 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55386 frame_tree_.SetFrameRemoveListener(
387 base::Bind(&WebContentsImpl::OnFrameRemoved,
388 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35389}
initial.commit09911bf2008-07-26 23:55:29390
[email protected]b172aee2012-04-10 17:05:26391WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32392 is_being_destroyed_ = true;
393
[email protected]21b41c7e892014-02-28 01:52:24394 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
395 // shutdown and be deleted as well.
396 frame_tree_.ForEach(
397 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
398
[email protected]d9030b82013-07-19 08:26:06399 ClearAllPowerSaveBlockers();
400
[email protected]b24b68a2012-09-24 21:57:26401 for (std::set<RenderWidgetHostImpl*>::iterator iter =
402 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
403 (*iter)->DetachDelegate();
404 }
405 created_widgets_.clear();
406
[email protected]3ab9cb82011-06-03 18:02:07407 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15408 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11409 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07410
[email protected]8ed16472014-04-11 19:02:48411 if (color_chooser_info_.get())
412 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20413
[email protected]420ae012009-04-24 05:16:32414 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32415
[email protected]ca13a442012-04-17 14:00:12416 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21417 NotificationService::current()->Notify(
418 NOTIFICATION_WEB_CONTENTS_DESTROYED,
419 Source<WebContents>(this),
420 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32421
[email protected]df0c843f2014-05-23 20:37:23422 // Destroy all frame tree nodes except for the root; this notifies observers.
423 frame_tree_.ResetForMainFrameSwap();
424 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59425
[email protected]df0c843f2014-05-23 20:37:23426 // Manually call the observer methods for the root frame tree node.
427 RenderFrameHostManager* root = GetRenderManager();
428 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27429 FOR_EACH_OBSERVER(WebContentsObserver,
430 observers_,
[email protected]df0c843f2014-05-23 20:37:23431 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27432 }
[email protected]df0c843f2014-05-23 20:37:23433 FOR_EACH_OBSERVER(WebContentsObserver,
434 observers_,
435 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27436
[email protected]df0c843f2014-05-23 20:37:23437 if (root->pending_render_view_host()) {
438 FOR_EACH_OBSERVER(WebContentsObserver,
439 observers_,
440 RenderViewDeleted(root->pending_render_view_host()));
441 }
[email protected]c06c58c2014-03-12 20:31:59442
[email protected]f273ee52013-10-18 16:05:27443 FOR_EACH_OBSERVER(WebContentsObserver,
444 observers_,
[email protected]df0c843f2014-05-23 20:37:23445 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27446
[email protected]2db9bd72012-04-13 20:20:56447 FOR_EACH_OBSERVER(WebContentsObserver,
448 observers_,
[email protected]12a46832014-05-09 13:35:58449 WebContentsDestroyed());
450
451 FOR_EACH_OBSERVER(WebContentsObserver,
452 observers_,
453 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08454
[email protected]6934a702011-12-20 00:04:51455 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10456
457 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
458 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42459}
460
[email protected]d1198fd2012-08-13 22:50:19461WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59462 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19463 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03464 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59465 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06466 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19467
[email protected]4858e432014-06-23 18:14:17468 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06469 // This makes |new_contents| act as a guest.
470 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16471 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06472 // We are instantiating a WebContents for browser plugin. Set its subframe
473 // bit to true.
474 new_contents->is_subframe_ = true;
475 }
[email protected]54944cde2012-12-09 09:24:59476 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19477 return new_contents;
478}
479
[email protected]95640212014-07-26 18:14:30480// static
481std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
482 std::vector<WebContentsImpl*> result;
483 scoped_ptr<RenderWidgetHostIterator> widgets(
484 RenderWidgetHostImpl::GetRenderWidgetHosts());
485 std::set<WebContentsImpl*> web_contents_set;
486 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
487 if (!rwh->IsRenderView())
488 continue;
489 RenderViewHost* rvh = RenderViewHost::From(rwh);
490 if (!rvh)
491 continue;
492 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
493 if (!web_contents)
494 continue;
495 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
496 if (web_contents_set.find(wci) == web_contents_set.end()) {
497 web_contents_set.insert(wci);
498 result.push_back(wci);
499 }
500 }
501 return result;
502}
503
[email protected]b0936d22013-11-28 06:47:36504RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21505 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28506}
507
[email protected]7bb761892012-07-20 09:32:47508bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
509 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44510 return OnMessageReceived(render_view_host, NULL, message);
511}
512
513bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
514 RenderFrameHost* render_frame_host,
515 const IPC::Message& message) {
516 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56517 if (GetWebUI() &&
518 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17519 return true;
[email protected]d2353452012-01-19 19:53:56520 }
[email protected]f82d57b52011-04-27 19:13:17521
[email protected]d8c660432011-12-22 20:51:25522 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
523 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33524 if (render_frame_host) {
525 while ((observer = it.GetNext()) != NULL)
526 if (observer->OnMessageReceived(message, render_frame_host))
527 return true;
528 } else {
529 while ((observer = it.GetNext()) != NULL)
530 if (observer->OnMessageReceived(message))
531 return true;
532 }
[email protected]403415a2011-01-10 18:57:53533
[email protected]1d62cf72014-02-07 21:31:57534 // Message handlers should be aware of which
535 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
536 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02537 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57538 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02539 else
[email protected]1d62cf72014-02-07 21:31:57540 render_view_message_source_ = render_view_host;
541
[email protected]724159a2010-12-30 01:11:18542 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33543 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44544 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
545 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40546 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
547 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05548 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
549 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48550 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
551 OnDocumentLoadedInFrame)
552 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00553 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
554 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
555 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
556 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48557 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
558 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
559 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
560 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19561 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
562 OnMediaPlayingNotification)
563 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
564 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11565 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
566 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18567 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
568 OnDidLoadResourceFromMemoryCache)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
570 OnDidDisplayInsecureContent)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
572 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25573 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26574 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21575 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20576 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
577 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20578 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
579 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16580 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10581 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50582 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50583#if defined(ENABLE_PLUGINS)
[email protected]d8415ad92012-08-23 14:40:50584 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
585 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55586 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
587 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50588#endif
[email protected]41225fe2013-03-29 05:32:02589 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
590 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07591 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
592 OnShowValidationMessage)
593 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
594 OnHideValidationMessage)
595 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
596 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48597#if defined(OS_ANDROID)
598 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
599 OnFindMatchRectsReply)
600 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
601 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48602#endif
[email protected]724159a2010-12-30 01:11:18603 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33604 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44605 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57606 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18607
[email protected]724159a2010-12-30 01:11:18608 return handled;
609}
610
[email protected]b172aee2012-04-10 17:05:26611void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18612 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21613 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43614 if (delegate_)
615 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18616}
617
[email protected]d1198fd2012-08-13 22:50:19618NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56619 return controller_;
620}
621
[email protected]d1198fd2012-08-13 22:50:19622const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56623 return controller_;
624}
625
[email protected]8ff00d72012-10-23 19:12:21626BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55627 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30628}
629
[email protected]b172aee2012-04-10 17:05:26630const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24631 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32632 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51633 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31634}
635
[email protected]a093ce02013-07-22 20:53:14636const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24637 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32638 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24639 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
640}
641
642const GURL& WebContentsImpl::GetLastCommittedURL() const {
643 // We may not have a navigation entry yet.
644 NavigationEntry* entry = controller_.GetLastCommittedEntry();
645 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
646}
647
[email protected]8ff00d72012-10-23 19:12:21648WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31649 return delegate_;
650}
651
[email protected]8ff00d72012-10-23 19:12:21652void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31653 // TODO(cbentzel): remove this debugging code?
654 if (delegate == delegate_)
655 return;
656 if (delegate_)
657 delegate_->Detach(this);
658 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08659 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31660 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08661 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00662 if (view_)
[email protected]e85165c642014-06-10 14:34:31663 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08664 }
[email protected]be1f56ab2011-12-22 06:55:31665}
666
[email protected]8ff00d72012-10-23 19:12:21667RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21668 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41669 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16670}
671
[email protected]60eca4eb2013-12-06 00:02:16672RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41673 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16674}
675
[email protected]9c9343b2014-03-08 02:56:07676RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
677 if (!frame_tree_.GetFocusedFrame())
678 return NULL;
679 return frame_tree_.GetFocusedFrame()->current_frame_host();
680}
681
[email protected]a86c0e962013-12-17 17:10:39682void WebContentsImpl::ForEachFrame(
683 const base::Callback<void(RenderFrameHost*)>& on_frame) {
684 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
685}
686
687void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
688 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
689 delete message;
690}
691
[email protected]b172aee2012-04-10 17:05:26692RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21693 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31694}
695
[email protected]6b618e62012-08-16 12:59:18696int WebContentsImpl::GetRoutingID() const {
697 if (!GetRenderViewHost())
698 return MSG_ROUTING_NONE;
699
700 return GetRenderViewHost()->GetRoutingID();
701}
702
[email protected]44470a22013-01-24 01:21:54703int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
704 return fullscreen_widget_routing_id_;
705}
706
[email protected]b172aee2012-04-10 17:05:26707RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21708 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31709}
710
[email protected]4aebbca2013-09-17 22:26:49711RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
712 const {
713 RenderWidgetHost* const widget_host =
714 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
715 GetFullscreenWidgetRoutingID());
716 return widget_host ? widget_host->GetView() : NULL;
717}
718
[email protected]8ff00d72012-10-23 19:12:21719WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31720 return view_.get();
721}
722
[email protected]95640212014-07-26 18:14:30723void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
724 if (mode == accessibility_mode_)
725 return;
726
727 accessibility_mode_ = mode;
728 frame_tree_.ForEach(
729 base::Bind(&ForEachFrameInternal,
730 base::Bind(&SetAccessibilityModeOnFrame, mode)));
731 frame_tree_.ForEach(
732 base::Bind(&ForEachPendingFrameInternal,
733 base::Bind(&SetAccessibilityModeOnFrame, mode)));
734}
735
736void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50737 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30738}
739
740void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50741 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30742}
743
[email protected]8ff00d72012-10-23 19:12:21744WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56745 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03746 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
747 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22748 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58749 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22750 web_ui->SetController(controller);
751 return web_ui;
752 }
753
754 delete web_ui;
755 return NULL;
756}
757
[email protected]8ff00d72012-10-23 19:12:21758WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21759 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
760 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31761}
762
[email protected]8ff00d72012-10-23 19:12:21763WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21764 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34765}
766
[email protected]86ef6a392012-05-11 22:03:11767void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22768 if (GetUserAgentOverride() == override)
769 return;
770
771 renderer_preferences_.user_agent_override = override;
772
773 // Send the new override string to the renderer.
774 RenderViewHost* host = GetRenderViewHost();
775 if (host)
776 host->SyncRendererPrefs();
777
778 // Reload the page if a load is currently in progress to avoid having
779 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27780 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22781 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
782 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53783
784 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
785 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11786}
787
788const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22789 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11790}
791
[email protected]95640212014-07-26 18:14:30792void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
793 AddAccessibilityMode(AccessibilityModeTreeOnly);
794}
795
796bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
797 return accessibility_mode_ == AccessibilityModeTreeOnly;
798}
799
800bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
801 return accessibility_mode_ == AccessibilityModeComplete;
802}
803
[email protected]2ceee8f2014-01-14 18:02:08804#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41805void WebContentsImpl::SetParentNativeViewAccessible(
806gfx::NativeViewAccessible accessible_parent) {
807 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30808 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
809 if (rfh)
810 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41811}
812#endif
813
[email protected]fcf75d42013-12-03 20:11:26814const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55815 // Transient entries take precedence. They are used for interstitial pages
816 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23817 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08818 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21819 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30820 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23821 if (entry) {
[email protected]b5cca982011-05-26 04:42:08822 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23823 }
[email protected]fa944cb82013-11-15 17:51:21824 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
825 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58826 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54827 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32828 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54829 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35830 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26831 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54832 if (!title.empty())
833 return title;
834 }
835 }
836
837 // We use the title for the last committed entry rather than a pending
838 // navigation entry. For example, when the user types in a URL, we want to
839 // keep the old page's title until the new load has committed and we get a new
840 // title.
[email protected]96d185d2009-04-24 03:28:54841 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32842
[email protected]9eeafc012013-11-25 23:49:47843 // We make an exception for initial navigations.
844 if (controller_.IsInitialNavigation()) {
845 // We only want to use the title from the visible entry in one of two cases:
846 // 1. There's already a committed entry for an initial navigation, in which
847 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
848 // 2. The pending entry has been explicitly assigned a title to display.
849 //
850 // If there's no last committed entry and no assigned title, we should fall
851 // back to |page_title_when_no_navigation_entry_| rather than showing the
852 // URL.
853 if (entry ||
854 (controller_.GetVisibleEntry() &&
855 !controller_.GetVisibleEntry()->GetTitle().empty())) {
856 entry = controller_.GetVisibleEntry();
857 }
858 }
[email protected]59167c22013-06-03 18:07:32859
[email protected]45d0ef7f2011-01-05 13:46:23860 if (entry) {
[email protected]b5cca982011-05-26 04:42:08861 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23862 }
[email protected]987fc3a2011-05-26 14:18:09863
864 // |page_title_when_no_navigation_entry_| is finally used
865 // if no title cannot be retrieved.
866 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54867}
868
[email protected]b172aee2012-04-10 17:05:26869int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46870 return GetMaxPageIDForSiteInstance(GetSiteInstance());
871}
872
[email protected]b172aee2012-04-10 17:05:26873int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
874 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33875 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
876 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46877
[email protected]b6583592012-01-25 19:52:33878 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34879}
880
[email protected]b172aee2012-04-10 17:05:26881void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46882 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
883}
884
[email protected]b172aee2012-04-10 17:05:26885void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33886 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46887 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33888 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34889}
890
[email protected]ec6c05f2013-10-23 18:41:57891void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
892 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
893 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57894}
895
[email protected]b172aee2012-04-10 17:05:26896SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21897 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54898}
899
[email protected]b172aee2012-04-10 17:05:26900SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21901 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
902 GetRenderManager()->pending_render_view_host() :
903 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58904 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38905}
906
[email protected]b172aee2012-04-10 17:05:26907bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49909}
910
[email protected]6dfed692014-05-22 04:18:03911bool WebContentsImpl::IsLoadingToDifferentDocument() const {
912 return is_loading_ && is_load_to_different_document_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03916 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31917}
918
[email protected]b172aee2012-04-10 17:05:26919const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31920 return load_state_;
921}
922
[email protected]fcf75d42013-12-03 20:11:26923const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31924 return load_state_host_;
925}
926
[email protected]b172aee2012-04-10 17:05:26927uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return upload_size_;
929}
930
[email protected]b172aee2012-04-10 17:05:26931uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31932 return upload_position_;
933}
934
[email protected]1ae93fb2013-06-14 03:38:56935std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56936 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39937 frame_tree_.ForEach(base::Bind(&CollectSites,
938 base::Unretained(GetBrowserContext()),
939 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56940 return sites;
941}
942
[email protected]b172aee2012-04-10 17:05:26943const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54944 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31945}
946
[email protected]b172aee2012-04-10 17:05:26947bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31948 return displayed_insecure_content_;
949}
950
[email protected]222f5822014-02-05 23:40:49951void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25952 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55953 ++capturer_count_;
954 DVLOG(1) << "There are now " << capturer_count_
955 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49956
957 // Note: This provides a hint to upstream code to size the views optimally
958 // for quality (e.g., to avoid scaling).
959 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
960 preferred_size_for_capture_ = capture_size;
961 OnPreferredSizeChanged(preferred_size_);
962 }
[email protected]54597982013-02-06 01:59:55963}
964
965void WebContentsImpl::DecrementCapturerCount() {
966 --capturer_count_;
967 DVLOG(1) << "There are now " << capturer_count_
968 << " capturing(s) of WebContentsImpl@" << this;
969 DCHECK_LE(0, capturer_count_);
970
[email protected]5a652232013-02-12 06:15:25971 if (is_being_destroyed_)
972 return;
973
[email protected]222f5822014-02-05 23:40:49974 if (capturer_count_ == 0) {
975 const gfx::Size old_size = preferred_size_for_capture_;
976 preferred_size_for_capture_ = gfx::Size();
977 OnPreferredSizeChanged(old_size);
978 }
979
[email protected]1ac10dca2013-08-20 20:47:04980 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55981 DVLOG(1) << "Executing delayed WasHidden().";
982 WasHidden();
983 }
[email protected]be1f56ab2011-12-22 06:55:31984}
985
[email protected]f2bd40812013-07-20 04:30:44986int WebContentsImpl::GetCapturerCount() const {
987 return capturer_count_;
988}
989
[email protected]b172aee2012-04-10 17:05:26990bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31991 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
992 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
993 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49994}
995
[email protected]b172aee2012-04-10 17:05:26996void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
997 int error_code) {
[email protected]443b80e2010-12-14 00:42:23998 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34999 return;
1000
[email protected]443b80e2010-12-14 00:42:231001 crashed_status_ = status;
1002 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211003 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341004}
1005
[email protected]b172aee2012-04-10 17:05:261006base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311007 return crashed_status_;
1008}
1009
[email protected]b172aee2012-04-10 17:05:261010bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311011 return is_being_destroyed_;
1012}
1013
[email protected]7f924832014-08-09 05:57:221014void WebContentsImpl::NotifyNavigationStateChanged(
1015 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301016 // Create and release the audio power save blocker depending on whether the
1017 // tab is actively producing audio or not.
1018 if (changed_flags == INVALIDATE_TYPE_TAB &&
1019 AudioStreamMonitor::monitoring_available()) {
1020 if (WasRecentlyAudible()) {
1021 if (!audio_power_save_blocker_)
1022 CreateAudioPowerSaveBlocker();
1023 } else {
1024 audio_power_save_blocker_.reset();
1025 }
1026 }
1027
[email protected]d5f942ba2008-09-26 19:30:341028 if (delegate_)
1029 delegate_->NavigationStateChanged(this, changed_flags);
1030}
1031
[email protected]9a890452014-02-13 22:21:021032base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1033 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331034}
1035
[email protected]9e2e4632012-07-27 16:38:411036void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541037 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591038
[email protected]948481d2014-06-11 18:32:221039 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1040 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591041 iter != widgets.end();
1042 iter++) {
[email protected]948481d2014-06-11 18:32:221043 if (*iter) {
1044 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431045#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221046 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431047#endif
[email protected]de3c5d82014-05-28 22:12:591048 }
[email protected]789e9152009-08-04 21:59:431049 }
[email protected]96d185d2009-04-24 03:28:541050
[email protected]9a890452014-02-13 22:21:021051 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381052
[email protected]b9769d82012-02-10 00:23:591053 // The resize rect might have changed while this was inactive -- send the new
1054 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581055 RenderViewHostImpl* rvh =
1056 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591057 if (rvh) {
1058 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1059 }
[email protected]96d185d2009-04-24 03:28:541060
dalecurtisbc6572e12014-09-12 19:22:301061 // Restore power save blocker if there are active video players running.
1062 if (!active_video_players_.empty() && !video_power_save_blocker_)
1063 CreateVideoPowerSaveBlocker();
1064
[email protected]c0d9d5672013-10-09 07:38:031065 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1066
[email protected]54597982013-02-06 01:59:551067 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311068}
1069
[email protected]b172aee2012-04-10 17:05:261070void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551071 // If there are entities capturing screenshots or video (e.g., mirroring),
1072 // don't activate the "disable rendering" optimization.
1073 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521074 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551075 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261076 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521077 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331078 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521079 // calls us).
[email protected]948481d2014-06-11 18:32:221080 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1081 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591082 iter != widgets.end();
1083 iter++) {
[email protected]948481d2014-06-11 18:32:221084 if (*iter)
1085 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591086 }
dalecurtisbc6572e12014-09-12 19:22:301087
1088 // Release any video power save blockers held as video is not visible.
1089 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541090 }
1091
[email protected]c0d9d5672013-10-09 07:38:031092 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1093
[email protected]54597982013-02-06 01:59:551094 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371095}
1096
[email protected]b172aee2012-04-10 17:05:261097bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311098 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271099 return WillNotifyDisconnection() &&
1100 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581101 !static_cast<RenderViewHostImpl*>(
1102 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311103}
1104
[email protected]1c3f80bd2014-04-08 23:02:061105void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1106 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1107 for_cross_site_transition);
1108}
1109
[email protected]b172aee2012-04-10 17:05:261110void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211111 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401112 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271113}
1114
[email protected]b172aee2012-04-10 17:05:261115WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441116 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451117 // We pass our own opener so that the cloned page can access it if it was
1118 // before.
[email protected]54944cde2012-12-09 09:24:591119 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451120 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591121 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191122 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221123 FOR_EACH_OBSERVER(WebContentsObserver,
1124 observers_,
1125 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271126 return tc;
1127}
1128
[email protected]14392a52012-05-02 20:28:441129void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211130 const NotificationSource& source,
1131 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441132 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211133 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1134 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031135 RenderWidgetHostView* view = host->GetView();
1136 if (view == GetFullscreenRenderWidgetHostView()) {
1137 // We cannot just call view_->RestoreFocus() here. On some platforms,
1138 // attempting to focus the currently-invisible WebContentsView will be
1139 // flat-out ignored. Therefore, this boolean is used to track whether
1140 // we will request focus after the fullscreen widget has been
1141 // destroyed.
1142 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1143 } else {
1144 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1145 i != pending_widget_views_.end(); ++i) {
1146 if (host->GetView() == i->second) {
1147 pending_widget_views_.erase(i);
1148 break;
1149 }
[email protected]bafe6cd2012-05-23 23:09:501150 }
1151 }
1152 break;
1153 }
[email protected]14392a52012-05-02 20:28:441154 default:
1155 NOTREACHED();
1156 }
1157}
1158
[email protected]ec6c05f2013-10-23 18:41:571159WebContents* WebContentsImpl::GetWebContents() {
1160 return this;
1161}
1162
[email protected]54944cde2012-12-09 09:24:591163void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211164 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361165 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211166 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431167 should_normally_be_visible_ = !params.initially_hidden;
1168
[email protected]fa944cb82013-11-15 17:51:211169 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041170 params.browser_context, params.site_instance, params.routing_id,
1171 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191172
[email protected]fc2b46b2014-05-03 16:33:451173 WebContentsViewDelegate* delegate =
1174 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1175
1176 if (browser_plugin_guest_) {
1177 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1178 this, delegate, &render_view_host_delegate_view_));
1179
1180 WebContentsViewGuest* rv = new WebContentsViewGuest(
1181 this, browser_plugin_guest_.get(), platform_view.Pass(),
1182 render_view_host_delegate_view_);
1183 render_view_host_delegate_view_ = rv;
1184 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191185 } else {
[email protected]fc2b46b2014-05-03 16:33:451186 // Regular WebContentsView.
1187 view_.reset(CreateWebContentsView(
1188 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191189 }
[email protected]fc2b46b2014-05-03 16:33:451190 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191191 CHECK(view_.get());
1192
[email protected]ed245db2012-12-18 08:00:451193 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591194 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191195
1196 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101197 if (opener_)
1198 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191199
1200 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211201 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1202 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101203
1204 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
[email protected]29998f92014-06-15 03:12:141205 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101206
[email protected]01f83f92014-06-17 14:41:541207 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091208 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541209
mlamouriefdca9d2014-09-16 16:55:401210 manifest_manager_host_.reset(new ManifestManagerHost(this));
1211
[email protected]c7654a232013-06-12 21:04:441212#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101213 date_time_chooser_.reset(new DateTimeChooserAndroid());
1214#endif
[email protected]d1198fd2012-08-13 22:50:191215}
1216
[email protected]7fff43e2013-05-21 20:21:101217void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1218 RemoveDestructionObserver(web_contents);
1219
[email protected]14392a52012-05-02 20:28:441220 // Clear the opener if it has been closed.
1221 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441222 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511223 return;
[email protected]14392a52012-05-02 20:28:441224 }
[email protected]ceee8cd2013-03-08 04:59:511225 // Clear a pending contents that has been closed before being shown.
1226 for (PendingContents::iterator iter = pending_contents_.begin();
1227 iter != pending_contents_.end();
1228 ++iter) {
1229 if (iter->second != web_contents)
1230 continue;
1231 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511232 return;
1233 }
1234 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441235}
1236
[email protected]7fff43e2013-05-21 20:21:101237void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1238 if (!ContainsKey(destruction_observers_, web_contents)) {
1239 destruction_observers_[web_contents] =
1240 new DestructionObserver(this, web_contents);
1241 }
1242}
1243
1244void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1245 DestructionObservers::iterator iter =
1246 destruction_observers_.find(web_contents);
1247 if (iter != destruction_observers_.end()) {
1248 delete destruction_observers_[web_contents];
1249 destruction_observers_.erase(iter);
1250 }
1251}
1252
[email protected]b172aee2012-04-10 17:05:261253void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311254 observers_.AddObserver(observer);
1255}
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311258 observers_.RemoveObserver(observer);
1259}
1260
[email protected]948481d2014-06-11 18:32:221261std::set<RenderWidgetHostView*>
1262WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1263 std::set<RenderWidgetHostView*> set;
1264 if (ShowingInterstitialPage()) {
1265 set.insert(GetRenderWidgetHostView());
1266 } else {
1267 ForEachFrame(
1268 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1269 }
[email protected]de3c5d82014-05-28 22:12:591270 return set;
1271}
1272
[email protected]b172aee2012-04-10 17:05:261273void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341274 if (delegate_)
1275 delegate_->ActivateContents(this);
1276}
1277
[email protected]b172aee2012-04-10 17:05:261278void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121279 if (delegate_)
1280 delegate_->DeactivateContents(this);
1281}
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481284 if (delegate_)
1285 delegate_->LostCapture();
1286}
1287
[email protected]b24b68a2012-09-24 21:57:261288void WebContentsImpl::RenderWidgetDeleted(
1289 RenderWidgetHostImpl* render_widget_host) {
1290 if (is_being_destroyed_) {
1291 // |created_widgets_| might have been destroyed.
1292 return;
1293 }
1294
1295 std::set<RenderWidgetHostImpl*>::iterator iter =
1296 created_widgets_.find(render_widget_host);
1297 if (iter != created_widgets_.end())
1298 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541299
1300 if (render_widget_host &&
1301 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491302 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1303 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541304 FOR_EACH_OBSERVER(WebContentsObserver,
1305 observers_,
1306 DidDestroyFullscreenWidget(
1307 fullscreen_widget_routing_id_));
1308 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031309 if (fullscreen_widget_had_focus_at_shutdown_)
1310 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541311 }
[email protected]b24b68a2012-09-24 21:57:261312}
1313
[email protected]b172aee2012-04-10 17:05:261314bool WebContentsImpl::PreHandleKeyboardEvent(
1315 const NativeWebKeyboardEvent& event,
1316 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481317 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131318 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481319}
1320
[email protected]b172aee2012-04-10 17:05:261321void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101322 if (browser_plugin_embedder_ &&
1323 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1324 return;
1325 }
[email protected]63954792011-07-11 04:17:481326 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131327 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481328}
1329
[email protected]d92026ef2014-03-03 21:04:131330bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461331 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191332#if !defined(OS_MACOSX)
1333 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1334 // isn't done for two reasons:
1335 // -the OS already has a gesture to do this through pinch-zoom
1336 // -if a user starts an inertial scroll, let's go, and presses control
1337 // (i.e. control+tab) then the OS's buffered scroll events will come in
1338 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521339 if (delegate_ &&
1340 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551341 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1342 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1343 // gestures, which are regrettably easy to trigger accidentally.
1344 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521345 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1346 return true;
1347 }
[email protected]bccc4472013-04-18 16:37:191348#endif
[email protected]fb3f066e2013-02-12 19:12:521349 return false;
1350}
1351
[email protected]04bce562014-01-30 05:34:541352bool WebContentsImpl::PreHandleGestureEvent(
1353 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031354 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541355}
1356
[email protected]bab38af2014-03-30 17:37:291357bool WebContentsImpl::HandleGestureEvent(
1358 const blink::WebGestureEvent& event) {
1359 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1360 // Use them to implement browser zoom, as for HandleWheelEvent above.
1361 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331362 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291363 // The scale difference necessary to trigger a zoom action. Derived from
1364 // experimentation to find a value that feels reasonable.
1365 const float kZoomStepValue = 0.6f;
1366
1367 // Find the (absolute) thresholds on either side of the current zoom factor,
1368 // then convert those to actual numbers to trigger a zoom in or out.
1369 // This logic deliberately makes the range around the starting zoom value
1370 // for the gesture twice as large as the other ranges (i.e., the notches are
1371 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1372 // so that it's easier to get back to your starting point than it is to
1373 // overshoot.
1374 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1375 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1376 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1377 : -backStep;
1378 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1379 : backStep;
1380
[email protected]fb546cb2014-04-28 14:09:371381 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291382 if (totalPinchGestureAmount_ > zoomInThreshold) {
1383 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461384 if (delegate_)
1385 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291386 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1387 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461388 if (delegate_)
1389 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291390 }
1391 return true;
1392 }
1393
1394 return false;
1395}
1396
[email protected]b172aee2012-04-10 17:05:261397void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431398 if (delegate_)
1399 delegate_->HandleMouseDown();
1400}
1401
[email protected]b172aee2012-04-10 17:05:261402void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481403 if (delegate_)
1404 delegate_->HandleMouseUp();
1405}
1406
[email protected]590a634e2012-07-19 16:38:231407void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481408 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231409 delegate_->HandlePointerActivate();
1410}
1411
1412void WebContentsImpl::HandleGestureBegin() {
1413 if (delegate_)
1414 delegate_->HandleGestureBegin();
1415}
1416
1417void WebContentsImpl::HandleGestureEnd() {
1418 if (delegate_)
1419 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481420}
1421
[email protected]b172aee2012-04-10 17:05:261422void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491423 // This method is being called to enter or leave renderer-initiated fullscreen
1424 // mode. Either way, make sure any existing fullscreen widget is shut down
1425 // first.
1426 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1427 if (widget_view)
1428 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1429
[email protected]8a5e0ca2011-08-25 06:30:471430 if (delegate_)
1431 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371432
1433 FOR_EACH_OBSERVER(WebContentsObserver,
1434 observers_,
1435 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471436}
1437
[email protected]b172aee2012-04-10 17:05:261438bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381439 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121440}
1441
[email protected]a9c81f02012-06-01 00:15:441442void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1443 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371444 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441445 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371446 } else {
1447 GotResponseToLockMouseRequest(false);
1448 }
1449}
1450
[email protected]b172aee2012-04-10 17:05:261451void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371452 if (delegate_)
1453 delegate_->LostMouseLock();
1454}
1455
[email protected]bafe6cd2012-05-23 23:09:501456void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201457 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501458 int route_id,
[email protected]227692c52013-05-31 22:43:041459 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131460 const ViewHostMsg_CreateWindow_Params& params,
1461 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501462 // We usually create the new window in the same BrowsingInstance (group of
1463 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551464 // if the opener is being suppressed (in a non-guest), we create a new
1465 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251466 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551467
[email protected]04cbd3d2013-12-04 04:58:201468 // If the opener is to be suppressed, the new window can be in any process.
1469 // Since routing ids are process specific, we must not have one passed in
1470 // as argument here.
1471 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1472
[email protected]bafe6cd2012-05-23 23:09:501473 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551474 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571475 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501476 GetSiteInstance();
1477
[email protected]04cbd3d2013-12-04 04:58:201478 // A message to create a new window can only come from the active process for
1479 // this WebContentsImpl instance. If any other process sends the request,
1480 // it is invalid and the process must be terminated.
1481 if (GetRenderProcessHost()->GetID() != render_process_id) {
1482 base::ProcessHandle process_handle =
1483 RenderProcessHost::FromID(render_process_id)->GetHandle();
1484 if (process_handle != base::kNullProcessHandle) {
1485 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391486 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
thestigc4cac8f2014-09-04 21:17:501487 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201488 }
1489 return;
1490 }
1491
[email protected]d1198fd2012-08-13 22:50:191492 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341493 //
1494 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301495 const std::string& partition_id =
1496 GetContentClient()->browser()->
1497 GetStoragePartitionIdForSite(GetBrowserContext(),
1498 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461499 StoragePartition* partition = BrowserContext::GetStoragePartition(
1500 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411501 DOMStorageContextWrapper* dom_storage_context =
1502 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191503 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1504 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1505 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371506
1507 if (delegate_ &&
1508 !delegate_->ShouldCreateWebContents(this,
1509 route_id,
1510 params.window_container_type,
1511 params.frame_name,
1512 params.target_url,
1513 partition_id,
1514 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011515 if (route_id != MSG_ROUTING_NONE &&
1516 !RenderViewHost::FromID(render_process_id, route_id)) {
1517 // If the embedder didn't create a WebContents for this route, we need to
1518 // delete the RenderView that had already been created.
1519 Send(new ViewMsg_Close(route_id));
1520 }
[email protected]dd6730412013-08-14 15:03:371521 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1522 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1523 main_frame_route_id);
1524 return;
1525 }
1526
1527 // Create the new web contents. This will automatically create the new
1528 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461529 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591530 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041531 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061532 create_params.opener = this;
1533 create_params.opener_suppressed = params.opener_suppressed;
1534 if (params.disposition == NEW_BACKGROUND_TAB)
1535 create_params.initially_hidden = true;
1536
[email protected]4858e432014-06-23 18:14:171537 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551538 if (!is_guest) {
1539 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451540 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171541 new_contents = static_cast<WebContentsImpl*>(
1542 WebContents::Create(create_params));
1543 } else {
1544 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551545 }
[email protected]50d326e2014-05-20 17:59:061546 new_contents->GetController().SetSessionStorageNamespace(
1547 partition_id,
1548 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261549 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191550
[email protected]c4538072013-03-18 02:17:551551 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341552 // will be shown immediately).
1553 if (!params.opener_suppressed) {
1554 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451555 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501556
[email protected]d70bea92013-04-05 04:23:341557 // TODO(brettw): It seems bogus that we have to call this function on the
1558 // newly created object and give it one of its own member variables.
1559 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1560 }
[email protected]bafe6cd2012-05-23 23:09:501561 // Save the created window associated with the route so we can show it
1562 // later.
1563 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1564 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101565 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501566 }
1567
1568 if (delegate_) {
1569 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071570 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131571 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501572 }
1573
1574 if (params.opener_suppressed) {
1575 // When the opener is suppressed, the original renderer cannot access the
1576 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001577 bool was_blocked = false;
1578 if (delegate_) {
1579 gfx::Rect initial_pos;
1580 delegate_->AddNewContents(
1581 this, new_contents, params.disposition, initial_pos,
1582 params.user_gesture, &was_blocked);
1583 }
1584 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211585 OpenURLParams open_params(params.target_url,
1586 Referrer(),
1587 CURRENT_TAB,
1588 PAGE_TRANSITION_LINK,
1589 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301590 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001591 new_contents->OpenURL(open_params);
1592 }
[email protected]bafe6cd2012-05-23 23:09:501593 }
1594}
1595
[email protected]a8504022013-12-04 20:23:511596void WebContentsImpl::CreateNewWidget(int render_process_id,
1597 int route_id,
[email protected]180ef242013-11-07 06:50:461598 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511599 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501600}
1601
[email protected]a8504022013-12-04 20:23:511602void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1603 int route_id) {
1604 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501605}
1606
[email protected]a8504022013-12-04 20:23:511607void WebContentsImpl::CreateNewWidget(int render_process_id,
1608 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501609 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461610 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211611 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511612 // A message to create a new widget can only come from the active process for
1613 // this WebContentsImpl instance. If any other process sends the request,
1614 // it is invalid and the process must be terminated.
1615 if (process->GetID() != render_process_id) {
1616 base::ProcessHandle process_handle =
1617 RenderProcessHost::FromID(render_process_id)->GetHandle();
1618 if (process_handle != base::kNullProcessHandle) {
1619 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391620 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
thestigc4cac8f2014-09-04 21:17:501621 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511622 }
1623 return;
1624 }
1625
[email protected]bafe6cd2012-05-23 23:09:501626 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041627 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261628 created_widgets_.insert(widget_host);
1629
[email protected]cfd80b02014-05-01 17:46:481630 RenderWidgetHostViewBase* widget_view =
1631 static_cast<RenderWidgetHostViewBase*>(
1632 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191633 if (!widget_view)
1634 return;
[email protected]bafe6cd2012-05-23 23:09:501635 if (!is_fullscreen) {
1636 // Popups should not get activated.
1637 widget_view->SetPopupType(popup_type);
1638 }
1639 // Save the created widget associated with the route so we can show it later.
1640 pending_widget_views_[route_id] = widget_view;
1641
1642#if defined(OS_MACOSX)
1643 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1644 // to allow it to survive the trip without being hosted.
1645 base::mac::NSObjectRetain(widget_view->GetNativeView());
1646#endif
1647}
1648
1649void WebContentsImpl::ShowCreatedWindow(int route_id,
1650 WindowOpenDisposition disposition,
1651 const gfx::Rect& initial_pos,
1652 bool user_gesture) {
1653 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001654 if (contents) {
1655 WebContentsDelegate* delegate = GetDelegate();
1656 if (delegate) {
1657 delegate->AddNewContents(
1658 this, contents, disposition, initial_pos, user_gesture, NULL);
1659 }
1660 }
[email protected]bafe6cd2012-05-23 23:09:501661}
1662
1663void WebContentsImpl::ShowCreatedWidget(int route_id,
1664 const gfx::Rect& initial_pos) {
1665 ShowCreatedWidget(route_id, false, initial_pos);
1666}
1667
1668void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1669 ShowCreatedWidget(route_id, true, gfx::Rect());
1670}
1671
1672void WebContentsImpl::ShowCreatedWidget(int route_id,
1673 bool is_fullscreen,
1674 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481675 RenderWidgetHostViewBase* widget_host_view =
1676 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501677 if (!widget_host_view)
1678 return;
[email protected]cfd80b02014-05-01 17:46:481679
1680 RenderWidgetHostView* view = NULL;
1681 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1682 if (guest && guest->embedder_web_contents()) {
1683 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1684 } else {
1685 view = GetRenderWidgetHostView();
1686 }
1687
[email protected]4aebbca2013-09-17 22:26:491688 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311689 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031690 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311691 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491692 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1693 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1694 delegate_->ToggleFullscreenModeForTab(this, true);
1695 } else {
[email protected]cfd80b02014-05-01 17:46:481696 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491697 }
[email protected]4aebbca2013-09-17 22:26:491698 FOR_EACH_OBSERVER(WebContentsObserver,
1699 observers_,
1700 DidShowFullscreenWidget(route_id));
1701 if (!widget_host_view->HasFocus())
1702 widget_host_view->Focus();
1703 } else {
[email protected]cfd80b02014-05-01 17:46:481704 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491705 }
[email protected]89054502012-06-03 10:29:241706
1707 RenderWidgetHostImpl* render_widget_host_impl =
1708 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1709 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311710 // Only allow privileged mouse lock for fullscreen render widget, which is
1711 // used to implement Pepper Flash fullscreen.
1712 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501713
1714#if defined(OS_MACOSX)
1715 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1716 // properly embedded (or purposefully ignored) we can release the retain we
1717 // took in CreateNewWidget().
1718 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1719#endif
1720}
1721
1722WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1723 PendingContents::iterator iter = pending_contents_.find(route_id);
1724
1725 // Certain systems can block the creation of new windows. If we didn't succeed
1726 // in creating one, just return NULL.
1727 if (iter == pending_contents_.end()) {
1728 return NULL;
1729 }
1730
1731 WebContentsImpl* new_contents = iter->second;
1732 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101733 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501734
[email protected]d70bea92013-04-05 04:23:341735 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251736 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341737 return new_contents;
1738
[email protected]bafe6cd2012-05-23 23:09:501739 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1740 !new_contents->GetRenderViewHost()->GetView())
1741 return NULL;
1742
creis82dd6af2014-09-17 16:30:451743 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501744 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1745 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451746 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1747
[email protected]bafe6cd2012-05-23 23:09:501748 return new_contents;
1749}
1750
1751RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1752 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1753 if (iter == pending_widget_views_.end()) {
1754 DCHECK(false);
1755 return NULL;
1756 }
1757
1758 RenderWidgetHostView* widget_host_view = iter->second;
1759 pending_widget_views_.erase(route_id);
1760
1761 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1762 if (!widget_host->GetProcess()->HasConnection()) {
1763 // The view has gone away or the renderer crashed. Nothing to do.
1764 return NULL;
1765 }
1766
1767 return widget_host_view;
1768}
1769
[email protected]f13b4202012-06-12 23:53:231770void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091771 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211772 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371773 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231774 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371775 } else {
1776 callback.Run(MediaStreamDevices(),
1777 MEDIA_DEVICE_INVALID_STATE,
1778 scoped_ptr<MediaStreamUI>());
1779 }
[email protected]f13b4202012-06-12 23:53:231780}
1781
grunell657d4d82014-09-18 00:09:431782bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1783 MediaStreamType type) {
1784 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1785 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1786 return delegate_ &&
1787 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1788}
1789
[email protected]cc9200432013-07-23 23:02:401790SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1791 SiteInstance* instance) {
1792 return controller_.GetSessionStorageNamespace(instance);
1793}
1794
[email protected]6de7fc482014-06-06 10:46:441795SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1796 return controller_.GetSessionStorageNamespaceMap();
1797}
1798
[email protected]9b159a52013-10-03 17:24:551799FrameTree* WebContentsImpl::GetFrameTree() {
1800 return &frame_tree_;
1801}
1802
[email protected]95640212014-07-26 18:14:301803AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1804 return accessibility_mode_;
1805}
1806
[email protected]31a71eaf2014-03-13 01:47:361807void WebContentsImpl::AccessibilityEventReceived(
1808 const std::vector<AXEventNotificationDetails>& details) {
1809 FOR_EACH_OBSERVER(
1810 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1811}
1812
dmazzonia656928e2014-09-15 20:28:541813RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1814 int browser_plugin_instance_id) {
1815 BrowserPluginGuestManager* guest_manager =
1816 GetBrowserContext()->GetGuestManager();
1817 WebContents* guest = guest_manager->GetGuestByInstanceID(
1818 this, browser_plugin_instance_id);
1819 if (!guest)
1820 return NULL;
1821 return guest->GetMainFrame();
1822}
1823
[email protected]edc3af82013-12-12 21:24:071824void WebContentsImpl::OnShowValidationMessage(
1825 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291826 const base::string16& main_text,
1827 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071828 if (delegate_)
1829 delegate_->ShowValidationMessage(
1830 this, anchor_in_root_view, main_text, sub_text);
1831}
1832
1833void WebContentsImpl::OnHideValidationMessage() {
1834 if (delegate_)
1835 delegate_->HideValidationMessage(this);
1836}
1837
1838void WebContentsImpl::OnMoveValidationMessage(
1839 const gfx::Rect& anchor_in_root_view) {
1840 if (delegate_)
1841 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1842}
1843
[email protected]32deec62013-05-15 23:55:041844void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1845 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441846 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041847}
1848
[email protected]95640212014-07-26 18:14:301849BrowserAccessibilityManager*
1850 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1851 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1852 return rfh ? rfh->browser_accessibility_manager() : NULL;
1853}
1854
1855BrowserAccessibilityManager*
1856 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1857 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1858 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1859}
1860
[email protected]b172aee2012-04-10 17:05:261861void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491862 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231863 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491864 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331865}
1866
[email protected]b172aee2012-04-10 17:05:261867void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341868 if (delegate_)
1869 delegate_->ResizeDueToAutoResize(this, new_size);
1870}
1871
[email protected]b172aee2012-04-10 17:05:261872WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201873 if (!delegate_)
1874 return NULL;
[email protected]00c37fc2011-08-02 00:22:501875
[email protected]e5d549d2011-12-28 01:29:201876 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201877 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341878}
1879
[email protected]6b618e62012-08-16 12:59:181880bool WebContentsImpl::Send(IPC::Message* message) {
1881 if (!GetRenderViewHost()) {
1882 delete message;
1883 return false;
1884 }
1885
1886 return GetRenderViewHost()->Send(message);
1887}
1888
[email protected]b172aee2012-04-10 17:05:261889bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501890 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261891 FrameTreeNode* node = frame_tree_.root();
1892
1893 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1894 // specified in the pending entry.
1895 NavigationEntryImpl* pending_entry =
1896 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1897 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1898 pending_entry->frame_tree_node_id() != -1) {
1899 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1900 }
1901
1902 return node->navigator()->NavigateToPendingEntry(
1903 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541904}
[email protected]96d185d2009-04-24 03:28:541905
[email protected]a86c0e962013-12-17 17:10:391906void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1907 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441908 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391909 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441910}
1911
[email protected]20ca0382013-02-28 19:50:071912void WebContentsImpl::AttachInterstitialPage(
1913 InterstitialPageImpl* interstitial_page) {
1914 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211915 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291916
1917 // Cancel any visible dialogs so that they don't interfere with the
1918 // interstitial.
1919 if (dialog_manager_)
1920 dialog_manager_->CancelActiveAndPendingDialogs(this);
1921
[email protected]20ca0382013-02-28 19:50:071922 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1923 DidAttachInterstitialPage());
1924}
1925
1926void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571927 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211928 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071929 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1930 DidDetachInterstitialPage());
1931}
1932
[email protected]b172aee2012-04-10 17:05:261933void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331934 const SiteInstance* site_instance,
1935 int history_length,
1936 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411937 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1938 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211939 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191940 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141941 return;
[email protected]9e1ad4b2011-08-14 16:49:191942 }
[email protected]9f76c1e2012-03-05 15:15:581943 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191944 if (!rvh) {
1945 NOTREACHED();
1946 return;
1947 }
[email protected]9f76c1e2012-03-05 15:15:581948 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191949 NOTREACHED();
1950 return;
1951 }
[email protected]6b618e62012-08-16 12:59:181952 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1953 history_length,
1954 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141955}
1956
[email protected]4fed3702014-04-01 09:08:001957void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171958 RenderFrameHost* focused_frame = GetFocusedFrame();
1959 if (!focused_frame)
1960 return;
1961
[email protected]959be4c2014-04-08 15:01:331962 focused_frame->Send(new FrameMsg_Reload(
1963 focused_frame->GetRoutingID(), ignore_cache));
1964}
1965
1966void WebContentsImpl::Undo() {
1967 RenderFrameHost* focused_frame = GetFocusedFrame();
1968 if (!focused_frame)
1969 return;
1970
1971 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1972 RecordAction(base::UserMetricsAction("Undo"));
1973}
1974
1975void WebContentsImpl::Redo() {
1976 RenderFrameHost* focused_frame = GetFocusedFrame();
1977 if (!focused_frame)
1978 return;
1979 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1980 RecordAction(base::UserMetricsAction("Redo"));
1981}
1982
1983void WebContentsImpl::Cut() {
1984 RenderFrameHost* focused_frame = GetFocusedFrame();
1985 if (!focused_frame)
1986 return;
1987
1988 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1989 RecordAction(base::UserMetricsAction("Cut"));
1990}
1991
1992void WebContentsImpl::Copy() {
1993 RenderFrameHost* focused_frame = GetFocusedFrame();
1994 if (!focused_frame)
1995 return;
1996
1997 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1998 RecordAction(base::UserMetricsAction("Copy"));
1999}
2000
2001void WebContentsImpl::CopyToFindPboard() {
2002#if defined(OS_MACOSX)
2003 RenderFrameHost* focused_frame = GetFocusedFrame();
2004 if (!focused_frame)
2005 return;
2006
2007 // Windows/Linux don't have the concept of a find pasteboard.
2008 focused_frame->Send(
2009 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2010 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2011#endif
2012}
2013
2014void WebContentsImpl::Paste() {
2015 RenderFrameHost* focused_frame = GetFocusedFrame();
2016 if (!focused_frame)
2017 return;
2018
2019 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2020 RecordAction(base::UserMetricsAction("Paste"));
2021}
2022
2023void WebContentsImpl::PasteAndMatchStyle() {
2024 RenderFrameHost* focused_frame = GetFocusedFrame();
2025 if (!focused_frame)
2026 return;
2027
2028 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2029 focused_frame->GetRoutingID()));
2030 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2031}
2032
2033void WebContentsImpl::Delete() {
2034 RenderFrameHost* focused_frame = GetFocusedFrame();
2035 if (!focused_frame)
2036 return;
2037
2038 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2039 RecordAction(base::UserMetricsAction("DeleteSelection"));
2040}
2041
2042void WebContentsImpl::SelectAll() {
2043 RenderFrameHost* focused_frame = GetFocusedFrame();
2044 if (!focused_frame)
2045 return;
2046
2047 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2048 RecordAction(base::UserMetricsAction("SelectAll"));
2049}
2050
2051void WebContentsImpl::Unselect() {
2052 RenderFrameHost* focused_frame = GetFocusedFrame();
2053 if (!focused_frame)
2054 return;
2055
2056 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2057 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172058}
2059
2060void WebContentsImpl::Replace(const base::string16& word) {
2061 RenderFrameHost* focused_frame = GetFocusedFrame();
2062 if (!focused_frame)
2063 return;
2064
[email protected]959be4c2014-04-08 15:01:332065 focused_frame->Send(new InputMsg_Replace(
2066 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172067}
2068
2069void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2070 RenderFrameHost* focused_frame = GetFocusedFrame();
2071 if (!focused_frame)
2072 return;
2073
[email protected]959be4c2014-04-08 15:01:332074 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2075 focused_frame->GetRoutingID(), word));
2076}
2077
2078void WebContentsImpl::NotifyContextMenuClosed(
2079 const CustomContextMenuContext& context) {
2080 RenderFrameHost* focused_frame = GetFocusedFrame();
2081 if (!focused_frame)
2082 return;
2083
2084 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2085 focused_frame->GetRoutingID(), context));
2086}
2087
2088void WebContentsImpl::ExecuteCustomContextMenuCommand(
2089 int action, const CustomContextMenuContext& context) {
2090 RenderFrameHost* focused_frame = GetFocusedFrame();
2091 if (!focused_frame)
2092 return;
2093
2094 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2095 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002096}
2097
[email protected]fc2b46b2014-05-03 16:33:452098gfx::NativeView WebContentsImpl::GetNativeView() {
2099 return view_->GetNativeView();
2100}
2101
2102gfx::NativeView WebContentsImpl::GetContentNativeView() {
2103 return view_->GetContentNativeView();
2104}
2105
2106gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2107 return view_->GetTopLevelNativeWindow();
2108}
2109
2110gfx::Rect WebContentsImpl::GetViewBounds() {
2111 return view_->GetViewBounds();
2112}
2113
2114gfx::Rect WebContentsImpl::GetContainerBounds() {
2115 gfx::Rect rv;
2116 view_->GetContainerBounds(&rv);
2117 return rv;
2118}
2119
2120DropData* WebContentsImpl::GetDropData() {
2121 return view_->GetDropData();
2122}
2123
2124void WebContentsImpl::Focus() {
[email protected]0b431992014-06-24 00:08:032125 RenderWidgetHostView* const fullscreen_view =
2126 GetFullscreenRenderWidgetHostView();
2127 if (fullscreen_view)
2128 fullscreen_view->Focus();
2129 else
2130 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452131}
2132
2133void WebContentsImpl::SetInitialFocus() {
[email protected]0b431992014-06-24 00:08:032134 RenderWidgetHostView* const fullscreen_view =
2135 GetFullscreenRenderWidgetHostView();
2136 if (fullscreen_view)
2137 fullscreen_view->Focus();
2138 else
2139 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452140}
2141
2142void WebContentsImpl::StoreFocus() {
[email protected]0b431992014-06-24 00:08:032143 if (!GetFullscreenRenderWidgetHostView())
2144 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452145}
2146
2147void WebContentsImpl::RestoreFocus() {
[email protected]0b431992014-06-24 00:08:032148 RenderWidgetHostView* const fullscreen_view =
2149 GetFullscreenRenderWidgetHostView();
2150 if (fullscreen_view)
2151 fullscreen_view->Focus();
2152 else
2153 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452154}
2155
[email protected]b172aee2012-04-10 17:05:262156void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272157 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212158 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542159 return;
2160 }
[email protected]0b431992014-06-24 00:08:032161 RenderWidgetHostView* const fullscreen_view =
2162 GetFullscreenRenderWidgetHostView();
2163 if (fullscreen_view) {
2164 fullscreen_view->Focus();
2165 return;
2166 }
[email protected]9f76c1e2012-03-05 15:15:582167 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542168}
2169
[email protected]b172aee2012-04-10 17:05:262170bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212171 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542172}
2173
[email protected]b172aee2012-04-10 17:05:262174InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212175 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222176}
2177
[email protected]b172aee2012-04-10 17:05:262178bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162179 // WebKit creates Document object when MIME type is application/xhtml+xml,
2180 // so we also support this MIME type.
2181 return contents_mime_type_ == "text/html" ||
2182 contents_mime_type_ == "text/xml" ||
2183 contents_mime_type_ == "application/xhtml+xml" ||
2184 contents_mime_type_ == "text/plain" ||
2185 contents_mime_type_ == "text/css" ||
2186 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2187}
2188
[email protected]b172aee2012-04-10 17:05:262189void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592190 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162191 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552192 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012193 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142194 return;
[email protected]c7dd2f62011-07-18 15:57:592195 }
2196
2197 Stop();
2198
2199 // Create the save package and possibly prompt the user for the name to save
2200 // the page as. The user prompt is an asynchronous operation that runs on
2201 // another thread.
2202 save_package_ = new SavePackage(this);
2203 save_package_->GetSaveInfo();
2204}
2205
2206// Used in automated testing to bypass prompting the user for file names.
2207// Instead, the names and paths are hard coded rather than running them through
2208// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342209bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2210 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212211 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592212 // Stop the page from navigating.
2213 Stop();
2214
2215 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212216 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592217}
2218
[email protected]3c71576ce2013-07-23 02:00:012219void WebContentsImpl::SaveFrame(const GURL& url,
2220 const Referrer& referrer) {
2221 if (!GetURL().is_valid())
2222 return;
2223 bool is_main_frame = (url == GetURL());
2224
2225 DownloadManager* dlm =
2226 BrowserContext::GetDownloadManager(GetBrowserContext());
2227 if (!dlm)
2228 return;
2229 int64 post_id = -1;
2230 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272231 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012232 if (entry)
2233 post_id = entry->GetPostID();
2234 }
2235 scoped_ptr<DownloadUrlParameters> params(
2236 DownloadUrlParameters::FromWebContents(this, url));
2237 params->set_referrer(referrer);
2238 params->set_post_id(post_id);
2239 params->set_prefer_cache(true);
2240 if (post_id >= 0)
2241 params->set_method("POST");
2242 params->set_prompt(true);
2243 dlm->DownloadUrl(params.Pass());
2244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342247 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482248 const base::Callback<void(int64)>& callback) {
2249 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122250}
2251
[email protected]b172aee2012-04-10 17:05:262252const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272253 return contents_mime_type_;
2254}
2255
[email protected]b172aee2012-04-10 17:05:262256bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272257 return notify_disconnection_;
2258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312261 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182262 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542266 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182267 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162268}
2269
[email protected]8ff00d72012-10-23 19:12:212270RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272271 return &renderer_preferences_;
2272}
2273
[email protected]e35ccd52012-05-23 16:22:472274void WebContentsImpl::Close() {
2275 Close(GetRenderViewHost());
2276}
2277
[email protected]cf200a562013-05-03 16:24:292278void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462279 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292280 if (browser_plugin_embedder_.get())
2281 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2282 screen_x, screen_y, operation);
2283 if (GetRenderViewHost())
2284 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2285 screen_x, screen_y, operation);
2286}
2287
[email protected]d60f3702013-12-26 16:30:242288void WebContentsImpl::DidGetResourceResponseStart(
2289 const ResourceRequestDetails& details) {
2290 controller_.ssl_manager()->DidStartResourceResponse(details);
2291
2292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2293 DidGetResourceResponseStart(details));
2294
2295 // TODO(avi): Remove. http://crbug.com/170921
2296 NotificationService::current()->Notify(
2297 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2298 Source<WebContents>(this),
2299 Details<const ResourceRequestDetails>(&details));
2300}
2301
2302void WebContentsImpl::DidGetRedirectForResourceRequest(
2303 RenderViewHost* render_view_host,
2304 const ResourceRedirectDetails& details) {
2305 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2306
2307 FOR_EACH_OBSERVER(
2308 WebContentsObserver,
2309 observers_,
2310 DidGetRedirectForResourceRequest(render_view_host, details));
2311
2312 // TODO(avi): Remove. http://crbug.com/170921
2313 NotificationService::current()->Notify(
2314 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2315 Source<WebContents>(this),
2316 Details<const ResourceRedirectDetails>(&details));
2317}
2318
[email protected]b172aee2012-04-10 17:05:262319void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522320 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582321 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512322 if (delegate_)
2323 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292324 if (browser_plugin_embedder_.get())
2325 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342326}
2327
[email protected]e35ccd52012-05-23 16:22:472328void WebContentsImpl::UserGestureDone() {
2329 OnUserGesture();
2330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272333 closed_by_user_gesture_ = value;
2334}
2335
[email protected]b172aee2012-04-10 17:05:262336bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272337 return closed_by_user_gesture_;
2338}
2339
[email protected]b172aee2012-04-10 17:05:262340void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502341 if (!delegate_)
2342 return;
2343
[email protected]6286a372013-10-09 04:03:272344 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2345 if (!entry)
[email protected]1788e772010-12-15 16:40:502346 return;
2347
[email protected]6286a372013-10-09 04:03:272348 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122349}
2350
[email protected]b172aee2012-04-10 17:05:262351void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042352 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272353 if (!delegate_)
2354 return;
2355
[email protected]691aa2f2013-05-28 22:52:042356 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272357}
2358
[email protected]b172aee2012-04-10 17:05:262359int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272360 return minimum_zoom_percent_;
2361}
2362
[email protected]b172aee2012-04-10 17:05:262363int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272364 return maximum_zoom_percent_;
2365}
2366
[email protected]b172aee2012-04-10 17:05:262367gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492368 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232369}
2370
[email protected]b172aee2012-04-10 17:05:262371bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052372 if (GetBrowserPluginGuest())
2373 return GetBrowserPluginGuest()->LockMouse(allowed);
2374
[email protected]0bfbf882011-12-22 18:19:272375 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582376 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272377}
2378
[email protected]b172aee2012-04-10 17:05:262379bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442380 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502381}
2382
[email protected]cb805452013-05-22 15:16:212383void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482384 if (!color_chooser_info_.get())
2385 return;
2386 RenderFrameHost* rfh = RenderFrameHost::FromID(
2387 color_chooser_info_->render_process_id,
2388 color_chooser_info_->render_frame_id);
2389 if (!rfh)
2390 return;
2391
2392 rfh->Send(new FrameMsg_DidChooseColorResponse(
2393 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202394}
2395
[email protected]cb805452013-05-22 15:16:212396void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482397 if (!color_chooser_info_.get())
2398 return;
2399 RenderFrameHost* rfh = RenderFrameHost::FromID(
2400 color_chooser_info_->render_process_id,
2401 color_chooser_info_->render_frame_id);
2402 if (!rfh)
2403 return;
2404
2405 rfh->Send(new FrameMsg_DidEndColorChooser(
2406 rfh->GetRoutingID(), color_chooser_info_->identifier));
2407 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202408}
2409
[email protected]41225fe2013-03-29 05:32:022410int WebContentsImpl::DownloadImage(const GURL& url,
2411 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302412 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022413 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582414 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022415 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392416 return id;
2417}
2418
[email protected]5dcaf8e2013-12-28 01:31:422419bool WebContentsImpl::IsSubframe() const {
2420 return is_subframe_;
2421}
2422
[email protected]36ec24f2014-01-09 00:32:082423void WebContentsImpl::Find(int request_id,
2424 const base::string16& search_text,
2425 const blink::WebFindOptions& options) {
2426 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2427}
2428
2429void WebContentsImpl::StopFinding(StopFindAction action) {
2430 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2431}
2432
[email protected]4fe53add2014-04-08 19:53:362433void WebContentsImpl::InsertCSS(const std::string& css) {
2434 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2435 GetMainFrame()->GetRoutingID(), css));
2436}
2437
dalecurtisbc6572e12014-09-12 19:22:302438bool WebContentsImpl::WasRecentlyAudible() {
2439 return audio_stream_monitor_.WasRecentlyAudible();
2440}
2441
mlamouriefdca9d2014-09-16 16:55:402442void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2443 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2444}
2445
[email protected]b172aee2012-04-10 17:05:262446bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272447 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172448 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332449 return true;
2450 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272451}
2452
[email protected]b172aee2012-04-10 17:05:262453void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272454 if (delegate_)
2455 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212456}
2457
[email protected]52913802013-12-10 05:52:182458void WebContentsImpl::DidStartProvisionalLoad(
2459 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182460 const GURL& validated_url,
2461 bool is_error_page,
2462 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102463 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482464 FOR_EACH_OBSERVER(
2465 WebContentsObserver,
2466 observers_,
2467 DidStartProvisionalLoadForFrame(
2468 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542469
[email protected]e2d2d4202014-07-03 12:17:482470 if (!render_frame_host->GetParent()) {
[email protected]52913802013-12-10 05:52:182471 FOR_EACH_OBSERVER(
2472 WebContentsObserver,
2473 observers_,
2474 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582475 render_frame_host));
[email protected]400992b2012-06-14 00:03:542476 }
2477}
2478
[email protected]0c3c54f2014-07-31 01:29:002479void WebContentsImpl::DidStartNavigationTransition(
2480 RenderFrameHostImpl* render_frame_host) {
2481#if defined(OS_ANDROID)
2482 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562483 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
2484 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002485#endif
2486}
2487
[email protected]3109fbb72014-01-06 23:57:152488void WebContentsImpl::DidFailProvisionalLoadWithError(
2489 RenderFrameHostImpl* render_frame_host,
2490 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2491 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312492 FOR_EACH_OBSERVER(WebContentsObserver,
2493 observers_,
2494 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312495 validated_url,
2496 params.error_code,
2497 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152498}
2499
[email protected]b80624c2014-02-09 02:46:552500void WebContentsImpl::DidFailLoadWithError(
2501 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552502 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552503 int error_code,
2504 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142505 FOR_EACH_OBSERVER(
2506 WebContentsObserver,
2507 observers_,
2508 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552509}
2510
[email protected]52913802013-12-10 05:52:182511void WebContentsImpl::NotifyChangedNavigationState(
2512 InvalidateTypes changed_flags) {
2513 NotifyNavigationStateChanged(changed_flags);
2514}
2515
[email protected]3691e5cf2014-01-22 10:16:202516void WebContentsImpl::AboutToNavigateRenderFrame(
2517 RenderFrameHostImpl* render_frame_host) {
2518 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272519 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202520 FOR_EACH_OBSERVER(
2521 WebContentsObserver,
2522 observers_,
[email protected]161eabd2014-03-19 19:47:272523 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202524}
2525
2526void WebContentsImpl::DidStartNavigationToPendingEntry(
2527 RenderFrameHostImpl* render_frame_host,
2528 const GURL& url,
2529 NavigationController::ReloadType reload_type) {
2530 // Notify observers about navigation.
2531 FOR_EACH_OBSERVER(
2532 WebContentsObserver,
2533 observers_,
2534 DidStartNavigationToPendingEntry(url, reload_type));
2535}
2536
[email protected]8cb834e2014-03-06 14:23:232537void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2538 const OpenURLParams& params) {
2539 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182540 WebContents* new_contents = OpenURL(params);
2541
2542 if (new_contents) {
2543 // Notify observers.
2544 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2545 DidOpenRequestedURL(new_contents,
2546 params.url,
2547 params.referrer,
2548 params.disposition,
2549 params.transition,
[email protected]8cb834e2014-03-06 14:23:232550 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182551 }
2552}
2553
[email protected]aa62afd2014-04-22 19:22:462554bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2555 if (!delegate_)
2556 return false;
2557 return delegate_->ShouldPreserveAbortedURLs(this);
2558}
2559
[email protected]400992b2012-06-14 00:03:542560void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582561 RenderFrameHostImpl* render_frame_host,
2562 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542563 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582564 FOR_EACH_OBSERVER(
2565 WebContentsObserver,
2566 observers_,
2567 ProvisionalChangeToMainFrameUrl(validated_target_url,
2568 render_frame_host));
[email protected]724159a2010-12-30 01:11:182569}
2570
[email protected]37567b432014-02-12 01:12:222571void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432572 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222573 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432574 PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222575 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482576 FOR_EACH_OBSERVER(WebContentsObserver,
2577 observers_,
2578 DidCommitProvisionalLoadForFrame(
2579 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222580}
2581
[email protected]0d0f4c492014-04-02 06:42:572582void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232583 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572584 // Ensure fullscreen mode is exited before committing the navigation to a
2585 // different page. The next page will not start out assuming it is in
2586 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232587 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192588 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572589 return;
2590 }
2591 if (IsFullscreenForCurrentTab())
2592 GetRenderViewHost()->ExitFullscreen();
2593 DCHECK(!IsFullscreenForCurrentTab());
2594}
2595
[email protected]37567b432014-02-12 01:12:222596void WebContentsImpl::DidNavigateMainFramePostCommit(
2597 const LoadCommittedDetails& details,
2598 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2599 if (details.is_navigation_to_different_page()) {
2600 // Clear the status bubble. This is a workaround for a bug where WebKit
2601 // doesn't let us know that the cursor left an element during a
2602 // transition (this is also why the mouse cursor remains as a hand after
2603 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2604 // clear the bubble when a user navigates to a named anchor in the same
2605 // page.
2606 UpdateTargetURL(details.entry->GetPageID(), GURL());
2607 }
2608
2609 if (!details.is_in_page) {
2610 // Once the main frame is navigated, we're no longer considered to have
2611 // displayed insecure content.
2612 displayed_insecure_content_ = false;
2613 SSLManager::NotifySSLInternalStateChanged(
2614 GetController().GetBrowserContext());
2615 }
2616
2617 // Notify observers about navigation.
2618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2619 DidNavigateMainFrame(details, params));
2620
[email protected]e85165c642014-06-10 14:34:312621 if (delegate_)
[email protected]37567b432014-02-12 01:12:222622 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312623 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222624}
2625
2626void WebContentsImpl::DidNavigateAnyFramePostCommit(
2627 RenderFrameHostImpl* render_frame_host,
2628 const LoadCommittedDetails& details,
2629 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102630 // Now that something has committed, we don't need to track whether the
2631 // initial page has been accessed.
2632 has_accessed_initial_document_ = false;
2633
[email protected]37567b432014-02-12 01:12:222634 // If we navigate off the page, close all JavaScript dialogs.
2635 if (dialog_manager_ && !details.is_in_page)
2636 dialog_manager_->CancelActiveAndPendingDialogs(this);
2637
2638 // Notify observers about navigation.
2639 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2640 DidNavigateAnyFrame(details, params));
2641}
2642
2643void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2644 contents_mime_type_ = mime_type;
2645}
2646
[email protected]277857a2014-06-03 10:38:012647bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312648 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052649 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312650 return false;
2651
[email protected]37567b432014-02-12 01:12:222652 if (delegate_)
2653 return delegate_->CanOverscrollContent();
2654
2655 return false;
2656}
2657
[email protected]37b64c52014-07-11 21:14:052658void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252659 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052660 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252661}
2662
[email protected]b172aee2012-04-10 17:05:262663void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182664 const GURL& url,
[email protected]70435962011-08-02 20:13:282665 const std::string& security_info,
2666 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182667 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402668 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192669 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182670 cache.Increment();
2671
2672 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082673 int cert_id = 0;
2674 net::CertStatus cert_status = 0;
2675 int security_bits = -1;
2676 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122677 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212678 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122679 &security_bits, &connection_status,
2680 &signed_certificate_timestamp_ids);
2681 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212682 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002683 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2684 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182685
[email protected]b0f724c2013-09-05 04:21:132686 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2687
2688 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2689 DidLoadResourceFromMemoryCache(details));
2690
[email protected]8bfc8272013-09-09 20:10:532691 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2692 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402693 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532694 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2695 GetRenderProcessHost()->GetID()) :
2696 GetBrowserContext()->GetRequestContextForRenderProcess(
2697 GetRenderProcessHost()->GetID()));
2698 BrowserThread::PostTask(
2699 BrowserThread::IO,
2700 FROM_HERE,
2701 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2702 }
[email protected]724159a2010-12-30 01:11:182703}
2704
[email protected]b172aee2012-04-10 17:05:262705void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392706 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182707 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192708 SSLManager::NotifySSLInternalStateChanged(
2709 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182710}
2711
[email protected]b172aee2012-04-10 17:05:262712void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022713 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582714 LOG(WARNING) << security_origin << " ran insecure content from "
2715 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392716 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412717 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392718 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182719 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412720 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192721 SSLManager::NotifySSLInternalStateChanged(
2722 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182723}
2724
[email protected]501052ff2014-02-21 22:19:072725void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572726 CHECK(render_frame_message_source_);
2727 CHECK(!render_view_message_source_);
2728 RenderFrameHostImpl* rfh =
2729 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142730 FOR_EACH_OBSERVER(
2731 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262735 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372736 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122737 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2738 GetRenderProcessHost()->ReceivedBadMessage();
2739 return;
2740 }
[email protected]a1b99262013-12-27 21:56:222741
[email protected]8b3af1e2014-01-24 13:29:122742 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442743 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372744 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422745 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372746
[email protected]61ac9e242014-03-21 20:55:262747 RenderFrameHostImpl* rfh =
2748 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142749 FOR_EACH_OBSERVER(
2750 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312751}
2752
[email protected]960b0372014-05-19 18:01:002753void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2754 RenderFrameHostImpl* rfh =
2755 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2756 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2757
2758 // It is possible to get multiple calls to OnDidStartLoading that don't have
2759 // corresponding calls to OnDidStopLoading:
2760 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2761 // out for a cross-process navigation, and it turns into a placeholder for
2762 // one being rendered in a different process.
2763 // - Also, there might be more than one RenderFrameHost sharing the same
2764 // FrameTreeNode (and thus sharing its ID) each sending a start.
2765 // - But in the future, once clamy@ moves navigation network requests to the
2766 // browser process, there's a good chance that callbacks about starting and
2767 // stopping will all be handled by the browser. When that happens, there
2768 // should no longer be a start/stop call imbalance. TODO(avi): When this
2769 // future arrives, update this code to not allow this case.
2770 DCHECK_GE(loading_frames_in_progress_, 0);
2771 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2772 if (loading_frames_in_progress_ == 0)
2773 DidStartLoading(rfh, to_different_document);
2774 ++loading_frames_in_progress_;
2775 }
2776
2777 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2778 SendLoadProgressChanged();
2779}
2780
2781void WebContentsImpl::OnDidStopLoading() {
2782 RenderFrameHostImpl* rfh =
2783 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2784 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2785
2786 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2787 // Load stopped while we were still tracking load. Make sure we update
2788 // progress based on this frame's completion.
2789 loading_progresses_[render_frame_id] = 1.0;
2790 SendLoadProgressChanged();
2791 // Then we clean-up our states.
2792 if (loading_total_progress_ == 1.0)
2793 ResetLoadProgressState();
2794 }
2795
2796 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2797 // calls DidStopLoading() without a matching DidStartLoading().
2798 if (loading_frames_in_progress_ == 0)
2799 return;
2800 --loading_frames_in_progress_;
2801 if (loading_frames_in_progress_ == 0)
2802 DidStopLoading(rfh);
2803}
2804
2805void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2806 RenderFrameHostImpl* rfh =
2807 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2808 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2809
2810 loading_progresses_[render_frame_id] = load_progress;
2811
2812 // We notify progress change immediately for the first and last updates.
2813 // Also, since the message loop may be pretty busy when a page is loaded, it
2814 // might not execute a posted task in a timely manner so we make sure to
2815 // immediately send progress report if enough time has passed.
2816 base::TimeDelta min_delay =
2817 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2818 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2819 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2820 // If there is a pending task to send progress, it is now obsolete.
2821 loading_weak_factory_.InvalidateWeakPtrs();
2822 SendLoadProgressChanged();
2823 if (loading_total_progress_ == 1.0)
2824 ResetLoadProgressState();
2825 return;
2826 }
2827
2828 if (loading_weak_factory_.HasWeakPtrs())
2829 return;
2830
2831 base::MessageLoop::current()->PostDelayedTask(
2832 FROM_HERE,
2833 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2834 loading_weak_factory_.GetWeakPtr()),
2835 min_delay);
2836}
2837
[email protected]b172aee2012-04-10 17:05:262838void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222839 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2840 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262841}
2842
[email protected]b172aee2012-04-10 17:05:262843void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302844 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262845 minimum_zoom_percent_ = minimum_percent;
2846 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262847}
2848
[email protected]b172aee2012-04-10 17:05:262849void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342850 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432851 if (!delegate_)
2852 return;
2853
[email protected]b9535422012-02-09 01:47:592854 ChildProcessSecurityPolicyImpl* policy =
2855 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222856 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592857 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212858}
2859
[email protected]b172aee2012-04-10 17:05:262860void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2861 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262862 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362863 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432864 if (!delegate_)
2865 return;
2866
[email protected]b9535422012-02-09 01:47:592867 ChildProcessSecurityPolicyImpl* policy =
2868 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322869 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592870 return;
[email protected]8f810632013-06-06 22:33:322871
[email protected]c125e532014-05-10 20:39:062872 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202873}
2874
[email protected]f5273e52014-07-14 16:30:202875void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2876 const GURL& url,
2877 bool user_gesture) {
2878 if (!delegate_)
2879 return;
2880
2881 ChildProcessSecurityPolicyImpl* policy =
2882 ChildProcessSecurityPolicyImpl::GetInstance();
2883 if (policy->IsPseudoScheme(protocol))
2884 return;
2885
2886 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2887}
2888
[email protected]b172aee2012-04-10 17:05:262889void WebContentsImpl::OnFindReply(int request_id,
2890 int number_of_matches,
2891 const gfx::Rect& selection_rect,
2892 int active_match_ordinal,
2893 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432894 if (delegate_) {
2895 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2896 active_match_ordinal, final_update);
2897 }
[email protected]b888919c2011-09-02 00:32:162898}
2899
[email protected]59363fc92012-09-05 03:46:312900#if defined(OS_ANDROID)
2901void WebContentsImpl::OnFindMatchRectsReply(
2902 int version,
2903 const std::vector<gfx::RectF>& rects,
2904 const gfx::RectF& active_rect) {
2905 if (delegate_)
2906 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2907}
[email protected]583418cc2013-01-17 14:01:102908
[email protected]1ff427972013-02-07 21:14:072909void WebContentsImpl::OnOpenDateTimeDialog(
2910 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092911 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2912 GetRenderViewHost(),
2913 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132914 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092915 value.minimum,
2916 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172917 value.step,
2918 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102919}
2920
[email protected]59363fc92012-09-05 03:46:312921#endif
2922
[email protected]f114fa42013-12-06 17:06:442923void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2924 const base::FilePath& path,
2925 bool is_hung) {
2926 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2927
2928 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2929 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2930}
2931
2932void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422933 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442934 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422935 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452936}
2937
[email protected]cfa856d62014-02-22 07:58:402938void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2939 int automation_id) {
2940 DomOperationNotificationDetails details(json_string, automation_id);
2941 NotificationService::current()->Notify(
2942 NOTIFICATION_DOM_OPERATION_RESPONSE,
2943 Source<WebContents>(this),
2944 Details<DomOperationNotificationDetails>(&details));
2945}
2946
[email protected]b172aee2012-04-10 17:05:262947void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2948 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102949 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252950 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102951 AppCacheAccessed(manifest_url, blocked_by_policy));
2952}
2953
[email protected]8bc5ff02013-11-29 06:34:032954void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482955 int color_chooser_id,
2956 SkColor color,
2957 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462958 ColorChooser* new_color_chooser = delegate_ ?
2959 delegate_->OpenColorChooser(this, color, suggestions) :
2960 NULL;
[email protected]820957a2014-01-14 14:56:302961 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212962 return;
[email protected]8ed16472014-04-11 19:02:482963 if (color_chooser_info_.get())
2964 color_chooser_info_->chooser->End();
2965
2966 color_chooser_info_.reset(new ColorChooserInfo(
2967 render_frame_message_source_->GetProcess()->GetID(),
2968 render_frame_message_source_->GetRoutingID(),
2969 new_color_chooser,
2970 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202971}
2972
[email protected]b172aee2012-04-10 17:05:262973void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482974 if (color_chooser_info_ &&
2975 color_chooser_id == color_chooser_info_->identifier)
2976 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202977}
2978
[email protected]b172aee2012-04-10 17:05:262979void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322980 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482981 if (color_chooser_info_ &&
2982 color_chooser_id == color_chooser_info_->identifier)
2983 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202984}
2985
[email protected]d0759f492012-04-19 22:50:502986// This exists for render views that don't have a WebUI, but do have WebUI
2987// bindings enabled.
2988void WebContentsImpl::OnWebUISend(const GURL& source_url,
2989 const std::string& name,
2990 const base::ListValue& args) {
2991 if (delegate_)
2992 delegate_->WebUISend(this, source_url, name, args);
2993}
2994
thestigc4cac8f2014-09-04 21:17:502995#if defined(ENABLE_PLUGINS)
[email protected]d8415ad92012-08-23 14:40:502996void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442997 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502998 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342999 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163000 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443001 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163002 return;
[email protected]d8415ad92012-08-23 14:40:503003 }
3004
[email protected]8c8fc292012-11-23 18:57:163005 if (!delegate_->RequestPpapiBrokerPermission(
3006 this, url, plugin_path,
3007 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443008 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163009 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443010 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163011 }
[email protected]d8415ad92012-08-23 14:40:503012}
3013
[email protected]ea0309c2013-08-06 19:35:443014void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503015 bool result) {
[email protected]ea0309c2013-08-06 19:35:443016 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503017}
3018
[email protected]c4538072013-03-18 02:17:553019void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373020 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083021 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553022 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393023 // For more info, see comment above classes BrowserPluginEmbedder and
3024 // BrowserPluginGuest.
3025 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143026 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083027 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373028}
thestigc4cac8f2014-09-04 21:17:503029#endif
[email protected]19be7a62012-10-01 23:03:373030
[email protected]41225fe2013-03-29 05:32:023031void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393032 int id,
[email protected]749fadd2013-05-15 08:37:483033 int http_status_code,
[email protected]795c28972012-12-06 06:13:393034 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303035 const std::vector<SkBitmap>& bitmaps,
3036 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133037 if (bitmaps.size() != original_bitmap_sizes.size())
3038 return;
3039
[email protected]41225fe2013-03-29 05:32:023040 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3041 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393042 // Currently WebContents notifies us of ANY downloads so that it is
3043 // possible to get here.
3044 return;
3045 }
3046 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303047 iter->second.Run(
3048 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393049 }
[email protected]41225fe2013-03-29 05:32:023050 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393051}
3052
3053void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393054 const std::vector<FaviconURL>& candidates) {
3055 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293056 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393057}
3058
dalecurtisbc6572e12014-09-12 19:22:303059void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3060 // ChromeOS has its own way of handling power save blocks for media.
3061#if !defined(OS_CHROMEOS)
3062 DCHECK(!audio_power_save_blocker_);
3063 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3064 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3065#endif
3066}
3067
3068void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3069 // ChromeOS has its own way of handling power save blocks for media.
3070#if !defined(OS_CHROMEOS)
3071 DCHECK(!video_power_save_blocker_);
3072 DCHECK(!active_video_players_.empty());
3073 video_power_save_blocker_ = PowerSaveBlocker::Create(
3074 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3075#if defined(OS_ANDROID)
3076 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3077 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3078#endif
3079#endif
3080}
3081
3082void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3083 // If there are no more audio players and we don't have audio stream
3084 // monitoring, release the audio power save blocker here instead of during
3085 // NotifyNavigationStateChanged().
3086 if (active_audio_players_.empty() &&
3087 !AudioStreamMonitor::monitoring_available()) {
3088 audio_power_save_blocker_.reset();
3089 }
3090
3091 // If there are no more video players, clear the video power save blocker.
3092 if (active_video_players_.empty())
3093 video_power_save_blocker_.reset();
3094}
3095
[email protected]1dd0bb752014-02-01 01:16:263096void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3097 bool has_video,
3098 bool has_audio) {
dalecurtisbc6572e12014-09-12 19:22:303099 if (has_audio) {
3100 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3101
3102 // If we don't have audio stream monitoring, allocate the audio power save
3103 // blocker here instead of during NotifyNavigationStateChanged().
3104 if (!audio_power_save_blocker_ &&
3105 !AudioStreamMonitor::monitoring_available()) {
3106 CreateAudioPowerSaveBlocker();
3107 }
[email protected]1dd0bb752014-02-01 01:16:263108 }
loislo0381a742014-09-11 10:58:113109
dalecurtisbc6572e12014-09-12 19:22:303110 if (has_video) {
3111 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3112
3113 // If we're not hidden and have just created a player, create a blocker.
3114 if (!video_power_save_blocker_ && !IsHidden())
3115 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113116 }
[email protected]1dd0bb752014-02-01 01:16:263117}
3118
3119void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303120 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3121 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3122 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063123}
3124
[email protected]50279492014-05-05 23:24:293125void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153126 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293127 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153128}
[email protected]d9030b82013-07-19 08:26:063129
[email protected]e67ebf32013-02-13 11:07:193130void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073131 if (delegate_)
3132 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193133}
3134
[email protected]17e286e2013-03-01 23:29:393135void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3136 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3137 BeforeFormRepostWarningShow());
3138}
3139
[email protected]ec6c05f2013-10-23 18:41:573140void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3141 Activate();
3142 if (delegate_)
3143 delegate_->ShowRepostFormWarningDialog(this);
3144}
3145
[email protected]b4c84012014-04-28 19:51:103146bool WebContentsImpl::HasAccessedInitialDocument() {
3147 return has_accessed_initial_document_;
3148}
3149
[email protected]96d185d2009-04-24 03:28:543150// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593151// loading, or done loading.
3152void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3153 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093154 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263155 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543156 if (is_loading == is_loading_)
3157 return;
3158
3159 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263160 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3161 base::string16());
[email protected]96d185d2009-04-24 03:28:543162 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563163 upload_size_ = 0;
3164 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543165 }
3166
[email protected]fa944cb82013-11-15 17:51:213167 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543168
3169 is_loading_ = is_loading;
3170 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033171 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543172
[email protected]6ebdc9b2010-09-27 16:55:573173 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093174 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213175 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543176
[email protected]eab61442013-11-14 18:35:483177 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593178 if (is_loading) {
naskob8744d22014-08-28 17:07:433179 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3180 this, "URL", url);
[email protected]91621872013-10-08 04:04:593181 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3182 DidStartLoading(render_view_host));
3183 } else {
naskob8744d22014-08-28 17:07:433184 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3185 this, "URL", url);
[email protected]91621872013-10-08 04:04:593186 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3187 DidStopLoading(render_view_host));
3188 }
[email protected]66798902013-10-01 18:40:163189
3190 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213191 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3192 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543193 if (details)
[email protected]8ff00d72012-10-23 19:12:213194 det = Details<LoadNotificationDetails>(details);
3195 NotificationService::current()->Notify(
3196 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543197}
3198
[email protected]959be4c2014-04-08 15:01:333199void WebContentsImpl::SelectRange(const gfx::Point& start,
3200 const gfx::Point& end) {
3201 RenderFrameHost* focused_frame = GetFocusedFrame();
3202 if (!focused_frame)
3203 return;
3204
3205 focused_frame->Send(
3206 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3207}
3208
[email protected]b172aee2012-04-10 17:05:263209void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463210 // If we are creating a RVH for a restored controller, then we need to make
3211 // sure the RenderView starts with a next_page_id_ larger than the number
3212 // of restored entries. This must be called before the RenderView starts
3213 // navigating (to avoid a race between the browser updating max_page_id and
3214 // the renderer updating next_page_id_). Because of this, we only call this
3215 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563216 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583217 if (max_restored_page_id >
3218 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3219 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3220 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323221}
3222
[email protected]b172aee2012-04-10 17:05:263223bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263224 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323225 // For file URLs without a title, use the pathname instead. In the case of a
3226 // synthesized title, we don't want the update to count toward the "one set
3227 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263228 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323229 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513230 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243231 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323232 explicit_set = false; // Don't count synthetic titles toward the set limit.
3233 } else {
[email protected]8af69c6c2014-03-03 19:05:313234 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323235 explicit_set = true;
3236 }
3237
[email protected]987fc3a2011-05-26 14:18:093238 // If a page is created via window.open and never navigated,
3239 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553240 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093241 if (entry) {
[email protected]36fc0392011-12-25 03:59:513242 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093243 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323244
[email protected]36fc0392011-12-25 03:59:513245 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093246 } else {
3247 if (page_title_when_no_navigation_entry_ == final_title)
3248 return false; // Nothing changed, don't bother.
3249
3250 page_title_when_no_navigation_entry_ = final_title;
3251 }
[email protected]420ae012009-04-24 05:16:323252
[email protected]420ae012009-04-24 05:16:323253 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233254 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323255
[email protected]66798902013-10-01 18:40:163256 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533257 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163258
3259 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213260 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463261 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213262 NotificationService::current()->Notify(
3263 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3264 Source<WebContents>(this),
3265 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043266
[email protected]420ae012009-04-24 05:16:323267 return true;
3268}
3269
[email protected]960b0372014-05-19 18:01:003270void WebContentsImpl::SendLoadProgressChanged() {
3271 loading_last_progress_update_ = base::TimeTicks::Now();
3272 double progress = 0.0;
3273 int frame_count = 0;
3274
3275 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3276 it != loading_progresses_.end();
3277 ++it) {
3278 progress += it->second;
3279 ++frame_count;
3280 }
3281 if (frame_count == 0)
3282 return;
3283 progress /= frame_count;
3284 DCHECK(progress <= 1.0);
3285
3286 if (progress <= loading_total_progress_)
3287 return;
3288 loading_total_progress_ = progress;
3289
3290 if (delegate_)
3291 delegate_->LoadProgressChanged(this, progress);
3292}
3293
3294void WebContentsImpl::ResetLoadProgressState() {
3295 loading_progresses_.clear();
3296 loading_total_progress_ = 0.0;
3297 loading_weak_factory_.InvalidateWeakPtrs();
3298 loading_last_progress_update_ = base::TimeTicks();
3299}
3300
[email protected]02d7b6e2014-06-24 21:01:503301void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3302 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323303 // After sending out a swap notification, we need to send a disconnect
3304 // notification so that clients that pick up a pointer to |this| can NULL the
3305 // pointer. See Bug 1230284.
3306 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113307 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283308 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113309
3310 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283311 std::pair<RenderViewHost*, RenderViewHost*> details =
3312 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213313 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283314 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213315 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283316 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393317
3318 // Ensure that the associated embedder gets cleared after a RenderViewHost
3319 // gets swapped, so we don't reuse the same embedder next time a
3320 // RenderViewHost is attached to this WebContents.
3321 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323322}
3323
[email protected]02d7b6e2014-06-24 21:01:503324void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3325 RenderFrameHost* new_host) {
3326 FOR_EACH_OBSERVER(WebContentsObserver,
3327 observers_,
3328 RenderFrameHostChanged(old_host, new_host));
3329}
3330
[email protected]da7a7182013-09-06 08:11:113331// TODO(avi): Remove this entire function because this notification is already
3332// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263333void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323334 if (!notify_disconnection_)
3335 return;
3336
3337 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213338 NotificationService::current()->Notify(
3339 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3340 Source<WebContents>(this),
3341 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323342}
3343
[email protected]cbb1ef592013-06-05 19:49:463344void WebContentsImpl::NotifyNavigationEntryCommitted(
3345 const LoadCommittedDetails& load_details) {
3346 FOR_EACH_OBSERVER(
3347 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3348}
3349
[email protected]f114fa42013-12-06 17:06:443350bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3351 const IPC::Message& message) {
3352 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313353}
3354
[email protected]c31a84802014-04-03 15:55:493355const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3356 return GetLastCommittedURL();
3357}
3358
[email protected]b849847b2013-12-10 21:57:583359void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3360 // Note this is only for subframes, the notification for the main frame
3361 // happens in RenderViewCreated.
3362 FOR_EACH_OBSERVER(WebContentsObserver,
3363 observers_,
3364 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303365 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583366}
3367
3368void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193369 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583370 FOR_EACH_OBSERVER(WebContentsObserver,
3371 observers_,
3372 RenderFrameDeleted(render_frame_host));
3373}
3374
[email protected]a09d53ce2014-01-31 00:46:423375void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303376 if (delegate_)
3377 delegate_->WorkerCrashed(this);
3378}
3379
[email protected]a09d53ce2014-01-31 00:46:423380void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3381 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103382 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423383 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103384 if (GetBrowserPluginGuest()) {
3385 WebContentsViewGuest* view_guest =
3386 static_cast<WebContentsViewGuest*>(GetView());
3387 context_menu_params = view_guest->ConvertContextMenuParams(params);
3388 }
3389 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423390 return;
3391
[email protected]077e704b2014-05-23 19:24:103392 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3393 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423394}
3395
[email protected]87de04b02014-04-08 22:14:493396void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013397 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493398 const base::string16& message,
3399 const base::string16& default_prompt,
3400 const GURL& frame_url,
3401 JavaScriptMessageType javascript_message_type,
3402 IPC::Message* reply_msg) {
3403 // Suppress JavaScript dialogs when requested. Also suppress messages when
3404 // showing an interstitial as it's shown over the previous page and we don't
3405 // want the hidden page's dialogs to interfere with the interstitial.
3406 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013407 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493408 IsSwappedOut() ||
3409 ShowingInterstitialPage() ||
3410 !delegate_ ||
3411 delegate_->ShouldSuppressDialogs() ||
3412 !delegate_->GetJavaScriptDialogManager();
3413
3414 if (!suppress_this_message) {
3415 std::string accept_lang = GetContentClient()->browser()->
3416 GetAcceptLangs(GetBrowserContext());
3417 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3418 dialog_manager_->RunJavaScriptDialog(
3419 this,
3420 frame_url.GetOrigin(),
3421 accept_lang,
3422 javascript_message_type,
3423 message,
3424 default_prompt,
3425 base::Bind(&WebContentsImpl::OnDialogClosed,
3426 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013427 render_frame_host->GetProcess()->GetID(),
3428 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493429 reply_msg,
3430 false),
3431 &suppress_this_message);
3432 }
3433
3434 if (suppress_this_message) {
3435 // If we are suppressing messages, just reply as if the user immediately
3436 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013437 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3438 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283439 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493440 }
3441
3442 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3443 // http://crbug.com/288961 ). The only safe thing to do here is return.
3444}
3445
3446void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013447 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493448 const base::string16& message,
3449 bool is_reload,
3450 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013451 RenderFrameHostImpl* rfhi =
3452 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493453 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013454 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493455 if (delegate_)
3456 delegate_->WillRunBeforeUnloadConfirm();
3457
3458 bool suppress_this_message =
3459 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3460 !delegate_ ||
3461 delegate_->ShouldSuppressDialogs() ||
3462 !delegate_->GetJavaScriptDialogManager();
3463 if (suppress_this_message) {
3464 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3465 return;
3466 }
3467
3468 is_showing_before_unload_dialog_ = true;
3469 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3470 dialog_manager_->RunBeforeUnloadDialog(
3471 this, message, is_reload,
3472 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013473 render_frame_host->GetProcess()->GetID(),
3474 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283475 false));
[email protected]87de04b02014-04-08 22:14:493476}
3477
[email protected]a86c0e962013-12-17 17:10:393478WebContents* WebContentsImpl::GetAsWebContents() {
3479 return this;
3480}
3481
[email protected]7912e822014-04-16 02:37:033482bool WebContentsImpl::IsNeverVisible() {
3483 if (!delegate_)
3484 return false;
3485 return delegate_->IsNeverVisible(this);
3486}
3487
[email protected]95640212014-07-26 18:14:303488#if defined(OS_WIN)
3489gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3490 return accessible_parent_;
3491}
3492#endif
3493
[email protected]5a3bdf52012-05-24 15:12:573494RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3495 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323496}
3497
[email protected]8ff00d72012-10-23 19:12:213498RendererPreferences WebContentsImpl::GetRendererPrefs(
3499 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463500 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513501}
3502
[email protected]b172aee2012-04-10 17:05:263503gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173504 if (delegate_)
3505 return delegate_->GetRootWindowResizerRect();
3506 return gfx::Rect();
3507}
3508
[email protected]7a846df2012-09-20 19:17:393509void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273510 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393511 browser_plugin_embedder_.reset();
3512}
3513
[email protected]b172aee2012-04-10 17:05:263514void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443515 // Don't send notifications if we are just creating a swapped-out RVH for
3516 // the opener chain. These won't be used for view-source or WebUI, so it's
3517 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243518 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443519 return;
3520
[email protected]86f98a22013-03-20 14:35:003521 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313522 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083523
[email protected]8ff00d72012-10-23 19:12:213524 NotificationService::current()->Notify(
3525 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3526 Source<WebContents>(this),
3527 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323528
3529 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353530 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213531 if (GetRenderManager()->pending_web_ui())
3532 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323533
[email protected]6286a372013-10-09 04:03:273534 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333535 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323536 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183537 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583538 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323539 }
[email protected]0666aef2009-05-13 19:48:083540
[email protected]60780f412013-02-25 16:34:103541 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263542
3543 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253544 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583545
3546 // We tell the observers now instead of when the main RenderFrameHostImpl is
3547 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3548 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363549 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583550 FOR_EACH_OBSERVER(
3551 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303552 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
[email protected]420ae012009-04-24 05:16:323553}
3554
[email protected]b172aee2012-04-10 17:05:263555void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523556 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323557 // Don't notify the world, since this came from a renderer in the
3558 // background.
3559 return;
3560 }
3561
[email protected]da7a7182013-09-06 08:11:113562 notify_disconnection_ = true;
3563 // TODO(avi): Remove. http://crbug.com/170921
3564 NotificationService::current()->Notify(
3565 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3566 Source<WebContents>(this),
3567 NotificationService::NoDetails());
3568
[email protected]be1f56ab2011-12-22 06:55:313569 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233570 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303571
3572 // Restore the focus to the tab (otherwise the focus will be on the top
3573 // window).
[email protected]484ae5912010-09-29 19:16:143574 if (was_crashed && !FocusLocationBarByDefault() &&
3575 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063576 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143577 }
[email protected]32ded2212011-11-10 18:51:433578
[email protected]d8c660432011-12-22 20:51:253579 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323580}
3581
[email protected]ec6a7eb2013-04-22 17:34:223582void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3583 base::TerminationStatus status,
3584 int error_code) {
[email protected]151a63d2011-12-20 22:32:523585 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323586 // The pending page's RenderViewHost is gone.
3587 return;
3588 }
3589
[email protected]2fcdcc32014-03-05 02:14:073590 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3591 // renderer may not have made a clean exit.
3592 if (IsFullscreenForCurrentTab())
3593 ToggleFullscreenMode(false);
3594
[email protected]698191dc2014-02-25 01:06:133595 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3596 if (dialog_manager_)
3597 dialog_manager_->CancelActiveAndPendingDialogs(this);
3598
[email protected]f738bdcb2014-07-11 20:40:443599 if (delegate_)
3600 delegate_->HideValidationMessage(this);
3601
[email protected]e3b10d12014-03-28 16:06:093602 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323603 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233604 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453605
[email protected]960b0372014-05-19 18:01:003606 // Reset the loading progress. TODO(avi): What does it mean to have a
3607 // "renderer crash" when there is more than one renderer process serving a
3608 // webpage? Once this function is called at a more granular frame level, we
3609 // probably will need to more granularly reset the state here.
3610 ResetLoadProgressState();
3611 loading_frames_in_progress_ = 0;
3612
[email protected]d8c660432011-12-22 20:51:253613 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273614 observers_,
[email protected]58d5cfe2013-07-10 02:40:523615 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323616}
3617
[email protected]b172aee2012-04-10 17:05:263618void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253619 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063620}
3621
[email protected]b172aee2012-04-10 17:05:263622void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3623 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043624 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153625 // Ensure that this state update comes from either the active RVH or one of
3626 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413627 // TODO(nasko): This should go through RenderFrameHost.
3628 // TODO(creis): We can't update state for cross-process subframes until we
3629 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3630 if (rvh != GetRenderViewHost() &&
3631 !GetRenderManager()->IsRVHOnSwappedOutList(
3632 static_cast<RenderViewHostImpl*>(rvh)))
3633 return;
[email protected]420ae012009-04-24 05:16:323634
3635 // We must be prepared to handle state updates for any page, these occur
3636 // when the user is scrolling and entering form data, as well as when we're
3637 // leaving a page, in which case our state may have already been moved to
3638 // the next page. The navigation controller will look up the appropriate
3639 // NavigationEntry and update it when it is notified via the delegate.
3640
3641 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583642 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323643 if (entry_index < 0)
3644 return;
[email protected]10f417c52011-12-28 21:04:233645 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323646
[email protected]691aa2f2013-05-28 22:52:043647 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323648 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043649 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323650 controller_.NotifyEntryChanged(entry, entry_index);
3651}
3652
[email protected]b172aee2012-04-10 17:05:263653void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513654 if (delegate_)
3655 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323656}
3657
[email protected]b172aee2012-04-10 17:05:263658void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103659#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293660 // The UI may be in an event-tracking loop, such as between the
3661 // mouse-down and mouse-up in text selection or a button click.
3662 // Defer the close until after tracking is complete, so that we
3663 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293664 // TODO(shess): This could get more fine-grained. For instance,
3665 // closing a tab in another window while selecting text in the
3666 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103667 if (view_->IsEventTracking()) {
3668 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293669 return;
3670 }
[email protected]60780f412013-02-25 16:34:103671#endif
[email protected]07707302009-11-06 00:50:293672
[email protected]420ae012009-04-24 05:16:323673 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523674 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513675 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323676}
3677
[email protected]66bbadaf2014-03-28 16:25:543678void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573679 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3680 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573681}
3682
[email protected]6f2ac772014-07-24 22:22:083683void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253684 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173685#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563686 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173687#endif
3688}
3689
3690bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3691#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563692 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173693#else
3694 return false;
3695#endif
3696}
3697
[email protected]b172aee2012-04-10 17:05:263698void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513699 if (delegate_ && delegate_->IsPopupOrPanel(this))
3700 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323701}
3702
[email protected]e3b10d12014-03-28 16:06:093703void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3704 bool to_different_document) {
3705 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3706 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323707}
3708
[email protected]723971b2014-02-12 11:08:253709void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323710 scoped_ptr<LoadNotificationDetails> details;
3711
[email protected]9595fd82013-04-19 21:28:493712 // Use the last committed entry rather than the active one, in case a
3713 // pending entry has been created.
3714 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203715 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493716
[email protected]420ae012009-04-24 05:16:323717 // An entry may not exist for a stop when loading an initial blank page or
3718 // if an iframe injected by script into a blank page finishes loading.
3719 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203720 base::TimeDelta elapsed =
3721 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323722
3723 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513724 entry->GetVirtualURL(),
3725 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323726 elapsed,
3727 &controller_,
3728 controller_.GetCurrentEntryIndex()));
3729 }
3730
[email protected]e3b10d12014-03-28 16:06:093731 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3732 details.get());
[email protected]420ae012009-04-24 05:16:323733}
3734
[email protected]b172aee2012-04-10 17:05:263735void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163736 controller_.DiscardNonCommittedEntries();
3737
3738 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213739 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163740}
3741
[email protected]59167c22013-06-03 18:07:323742void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103743 has_accessed_initial_document_ = true;
3744
[email protected]d1371bf8e2014-04-19 03:26:243745 // We may have left a failed browser-initiated navigation in the address bar
3746 // to let the user edit it and try again. Clear it now that content might
3747 // show up underneath it.
3748 if (!IsLoading() && controller_.GetPendingEntry())
3749 controller_.DiscardPendingEntry();
3750
[email protected]59167c22013-06-03 18:07:323751 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503752 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323753}
3754
[email protected]3f19f1a2014-05-02 05:23:273755void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473756 // No action is necessary if the opener has already been cleared.
3757 if (!opener_)
3758 return;
3759
3760 // Clear our opener so that future cross-process navigations don't have an
3761 // opener assigned.
3762 RemoveDestructionObserver(opener_);
3763 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273764
3765 // Notify all swapped out RenderViewHosts for this tab. This is important
3766 // in case we go back to them, or if another window in those processes tries
3767 // to access window.opener.
creisbbbeb062014-08-25 18:20:313768 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273769}
3770
[email protected]39f2f9252014-05-03 00:54:013771void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293772 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093773 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293774 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093775
3776 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213777 NotificationService::current()->Notify(
3778 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3779 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293780 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083781}
3782
[email protected]ef3adfc2014-05-11 00:04:543783void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3784 int32 page_id,
3785 const base::string16& title,
3786 base::i18n::TextDirection title_direction) {
3787 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3788
3789 // If we have a title, that's a pretty good indication that we've started
3790 // getting useful data.
3791 SetNotWaitingForResponse();
3792
3793 // Try to find the navigation entry, which might not be the current one.
3794 // For example, it might be from a pending RVH for the pending entry.
3795 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3796 rvh->GetSiteInstance(), page_id);
3797
3798 // We can handle title updates when we don't have an entry in
3799 // UpdateTitleForEntry, but only if the update is from the current RVH.
3800 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3801 if (!entry && rvh != GetRenderViewHost())
3802 return;
3803
3804 // TODO(evan): make use of title_direction.
3805 // http://code.google.com/p/chromium/issues/detail?id=27094
3806 if (!UpdateTitleForEntry(entry, title))
3807 return;
3808
3809 // Broadcast notifications when the UI should be updated.
3810 if (entry == controller_.GetEntryAtOffset(0))
3811 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3812}
3813
3814void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3815 const std::string& encoding) {
3816 SetEncoding(encoding);
3817}
3818
[email protected]39f2f9252014-05-03 00:54:013819void WebContentsImpl::DocumentAvailableInMainFrame(
3820 RenderViewHost* render_view_host) {
3821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3822 DocumentAvailableInMainFrame());
3823}
[email protected]e1c3a552012-05-04 20:51:323824void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3825 // Tell the active RenderViewHost to run unload handlers and close, as long
3826 // as the request came from a RenderViewHost in the same BrowsingInstance.
3827 // In most cases, we receive this from a swapped out RenderViewHost.
3828 // It is possible to receive it from one that has just been swapped in,
3829 // in which case we might as well deliver the message anyway.
3830 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3831 GetRenderViewHost()->ClosePage();
3832}
3833
[email protected]f546640b2012-05-15 00:03:493834void WebContentsImpl::RouteMessageEvent(
3835 RenderViewHost* rvh,
3836 const ViewMsg_PostMessage_Params& params) {
3837 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363838 // came from a RenderViewHost in the same BrowsingInstance or if this
3839 // WebContents is dedicated to a browser plugin guest.
3840 // Note: This check means that an embedder could theoretically receive a
3841 // postMessage from anyone (not just its own guests). However, this is
3842 // probably not a risk for apps since other pages won't have references
3843 // to App windows.
3844 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3845 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493846 return;
3847
3848 ViewMsg_PostMessage_Params new_params(params);
3849
[email protected]0bc7f3542013-10-21 15:05:533850 if (!params.message_port_ids.empty()) {
3851 MessagePortMessageFilter* message_port_message_filter =
3852 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3853 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093854 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3855 params.message_port_ids,
3856 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533857 }
3858
[email protected]f546640b2012-05-15 00:03:493859 // If there is a source_routing_id, translate it to the routing ID for
3860 // the equivalent swapped out RVH in the target process. If we need
3861 // to create a swapped out RVH for the source tab, we create its opener
3862 // chain as well, since those will also be accessible to the target page.
3863 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3864 // Try to look up the WebContents for the source page.
3865 WebContentsImpl* source_contents = NULL;
3866 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3867 rvh->GetProcess()->GetID(), params.source_routing_id);
3868 if (source_rvh) {
3869 source_contents = static_cast<WebContentsImpl*>(
3870 source_rvh->GetDelegate()->GetAsWebContents());
3871 }
3872
3873 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363874 if (GetBrowserPluginGuest()) {
3875 // We create a swapped out RenderView for the embedder in the guest's
3876 // render process but we intentionally do not expose the embedder's
3877 // opener chain to it.
3878 new_params.source_routing_id =
3879 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3880 } else {
3881 new_params.source_routing_id =
3882 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3883 }
[email protected]f546640b2012-05-15 00:03:493884 } else {
3885 // We couldn't find it, so don't pass a source frame.
3886 new_params.source_routing_id = MSG_ROUTING_NONE;
3887 }
3888 }
3889
3890 // In most cases, we receive this from a swapped out RenderViewHost.
3891 // It is possible to receive it from one that has just been swapped in,
3892 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183893 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493894}
3895
[email protected]a796f202012-05-30 14:14:253896bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263897 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253898 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263899 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253900 if (!delegate_)
3901 return false;
3902 return delegate_->AddMessageToConsole(this, level, message, line_no,
3903 source_id);
3904}
3905
[email protected]9e797d22014-08-08 21:31:303906WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273907 // We want to base the page config off of the actual URL, rather than the
3908 // virtual URL.
3909 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3910 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003911 GURL url = controller_.GetActiveEntry()
3912 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153913
[email protected]9e797d22014-08-08 21:31:303914 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323915}
3916
[email protected]0eba810b2012-10-18 03:19:363917int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213918 SiteInstance* instance) {
[email protected]82307f6b2014-08-07 03:30:123919 return GetRenderManager()->CreateRenderFrame(
3920 instance, MSG_ROUTING_NONE, true, true, true);
[email protected]0eba810b2012-10-18 03:19:363921}
3922
[email protected]b172aee2012-04-10 17:05:263923void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273924 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253925 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223926
[email protected]ea114722012-03-12 01:11:253927 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173928 if (rdh) // NULL in unittests.
3929 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253930}
3931
[email protected]b172aee2012-04-10 17:05:263932void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443933 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253934 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443935}
3936
[email protected]b172aee2012-04-10 17:05:263937void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563938 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263939 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153940 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523941 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153942 return;
3943
[email protected]9f76c1e2012-03-05 15:15:583944 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3945
[email protected]e5fc1632011-08-08 07:51:533946 // Ignore renderer unresponsive event if debugger is attached to the tab
3947 // since the event may be a result of the renderer sitting on a breakpoint.
3948 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363949 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533950 return;
3951
[email protected]2e9d79f2013-08-16 05:45:563952 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323953 // Hang occurred while firing the beforeunload/unload handler.
3954 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583955 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323956
[email protected]fa944cb82013-11-15 17:51:213957 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323958 return;
3959
3960 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563961 // nothing we can do to recover. If the hang is in the beforeunload handler,
3962 // pretend the beforeunload listeners have all fired and allow the delegate
3963 // to continue closing; the user will not have the option of cancelling the
3964 // close. Otherwise, pretend the unload listeners have all fired and close
3965 // the tab.
3966 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463967 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563968 delegate_->BeforeUnloadFired(this, true, &close);
3969 }
3970 if (close)
3971 Close(rvh);
[email protected]420ae012009-04-24 05:16:323972 return;
3973 }
3974
[email protected]9f76c1e2012-03-05 15:15:583975 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473976 return;
3977
[email protected]6934a702011-12-20 00:04:513978 if (delegate_)
3979 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323980}
3981
[email protected]b172aee2012-04-10 17:05:263982void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513983 if (delegate_)
3984 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323985}
3986
[email protected]b172aee2012-04-10 17:05:263987void WebContentsImpl::LoadStateChanged(
3988 const GURL& url,
3989 const net::LoadStateWithParam& load_state,
3990 uint64 upload_position,
3991 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323992 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563993 upload_position_ = upload_position;
3994 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503995 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213996 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303997 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213998 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323999 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464000 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224001 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4002 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464003 }
[email protected]420ae012009-04-24 05:16:324004}
4005
[email protected]b172aee2012-04-10 17:05:264006void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554007 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324008 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4010 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514011 if (delegate_)
4012 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094013 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324014}
4015
[email protected]58d5cfe2013-07-10 02:40:524016void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544017 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234018 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224019 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544020}
4021
[email protected]b172aee2012-04-10 17:05:264022void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104023 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214024 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264025 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4026 // here during container initialization and normal window size will be set
4027 // later. In case of tab duplication this resizing to 0x0 prevents setting
4028 // normal size later so just ignore it.
4029 if (!size.IsEmpty())
4030 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324031}
4032
[email protected]af905902013-10-01 21:38:514033void WebContentsImpl::CancelModalDialogsForRenderManager() {
4034 // We need to cancel modal dialogs when doing a process swap, since the load
4035 // deferrer would prevent us from swapping out.
4036 if (dialog_manager_)
4037 dialog_manager_->CancelActiveAndPendingDialogs(this);
4038}
4039
[email protected]02d7b6e2014-06-24 21:01:504040void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4041 RenderFrameHost* new_host,
4042 bool is_main_frame) {
4043 if (is_main_frame) {
4044 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4045 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084046
[email protected]02d7b6e2014-06-24 21:01:504047 // Make sure the visible RVH reflects the new delegate's preferences.
4048 if (delegate_)
4049 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394050
[email protected]02d7b6e2014-06-24 21:01:504051 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4052 }
4053
4054 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544055}
4056
[email protected]14392a52012-05-02 20:28:444057int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4058 SiteInstance* instance) {
4059 if (!opener_)
4060 return MSG_ROUTING_NONE;
4061
4062 // Recursively create RenderViews for anything else in the opener chain.
4063 return opener_->CreateOpenerRenderViews(instance);
4064}
4065
4066int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4067 int opener_route_id = MSG_ROUTING_NONE;
4068
4069 // If this tab has an opener, ensure it has a RenderView in the given
4070 // SiteInstance as well.
4071 if (opener_)
4072 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4073
[email protected]45a22ad2013-02-21 03:25:004074 // If any of the renderers (current, pending, or swapped out) for this
4075 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214076 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4077 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374078
[email protected]fa944cb82013-11-15 17:51:214079 if (GetRenderManager()->pending_render_view_host() &&
4080 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4081 instance)
4082 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004083
[email protected]fa944cb82013-11-15 17:51:214084 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374085 instance);
4086 if (rvh)
4087 return rvh->GetRoutingID();
4088
[email protected]14392a52012-05-02 20:28:444089 // Create a swapped out RenderView in the given SiteInstance if none exists,
4090 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]82307f6b2014-08-07 03:30:124091 return GetRenderManager()->CreateRenderFrame(
4092 instance, opener_route_id, true, true, true);
[email protected]14392a52012-05-02 20:28:444093}
4094
[email protected]b172aee2012-04-10 17:05:264095NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194096 return GetController();
[email protected]3a3d47472010-07-15 21:03:544097}
4098
[email protected]b172aee2012-04-10 17:05:264099WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:564100 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:324101}
4102
[email protected]10f417c52011-12-28 21:04:234103NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264104 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324105 return controller_.GetLastCommittedEntry();
4106}
4107
[email protected]b172aee2012-04-10 17:05:264108bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164109 RenderViewHost* render_view_host,
4110 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044111 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124112 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434113 TRACE_EVENT0("browser,navigation",
4114 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444115 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484116 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164117 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4118 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4119 // case this because RWH is still a base class of RenderViewHost, and child
4120 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124121 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164122 RenderWidgetHostViewChildFrame* rwh_view_child =
4123 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164124 rwh_view = rwh_view_child;
4125 } else {
4126 rwh_view = view_->CreateViewForWidget(render_view_host);
4127 }
[email protected]1a98a932009-11-17 00:12:524128
[email protected]420ae012009-04-24 05:16:324129 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444130 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214131 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324132
[email protected]74ce1ad2011-12-16 21:51:464133 // Make sure we use the correct starting page_id in the new RenderView.
4134 UpdateMaxPageIDIfNecessary(render_view_host);
4135 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584136 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464137
[email protected]9f76c1e2012-03-05 15:15:584138 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264139 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494140 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044141 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494142 max_page_id,
4143 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524144 return false;
[email protected]14392a52012-05-02 20:28:444145 }
[email protected]a4127722011-04-27 23:13:524146
[email protected]a220b5932013-09-21 03:47:444147#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504148 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4149 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444150 if (rwh_view) {
4151 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4152 render_widget_host->WasResized();
4153 }
[email protected]f8233cc2011-05-31 20:24:504154#endif
4155
[email protected]420ae012009-04-24 05:16:324156 return true;
4157}
4158
[email protected]82307f6b2014-08-07 03:30:124159bool WebContentsImpl::CreateRenderFrameForRenderManager(
4160 RenderFrameHost* render_frame_host,
4161 int parent_routing_id) {
naskob8744d22014-08-28 17:07:434162 TRACE_EVENT0("browser,navigation",
4163 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124164
4165 RenderFrameHostImpl* rfh =
4166 static_cast<RenderFrameHostImpl*>(render_frame_host);
4167 if (!rfh->CreateRenderFrame(parent_routing_id))
4168 return false;
4169
4170 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4171 // RenderFrameHost will have to be associated with the appropriate
4172 // RenderWidgetHostView or a new one should be created here.
4173
4174 return true;
4175}
4176
[email protected]7d244f12013-08-22 21:41:514177#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454178
[email protected]155c7f22013-12-09 17:07:184179base::android::ScopedJavaLocalRef<jobject>
4180WebContentsImpl::GetJavaWebContents() {
4181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564182 return GetWebContentsAndroid()->GetJavaObject();
4183}
[email protected]155c7f22013-12-09 17:07:184184
[email protected]0e813a52014-08-13 10:34:564185WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184186 WebContentsAndroid* web_contents_android =
4187 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4188 if (!web_contents_android) {
4189 web_contents_android = new WebContentsAndroid(this);
4190 SetUserData(kWebContentsAndroidKey, web_contents_android);
4191 }
[email protected]0e813a52014-08-13 10:34:564192 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184193}
4194
[email protected]7d244f12013-08-22 21:41:514195bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4196 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164197 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044198 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594199 true);
[email protected]7d244f12013-08-22 21:41:514200}
[email protected]fc2b46b2014-05-03 16:33:454201
4202#elif defined(OS_MACOSX)
4203
[email protected]75f4df72014-07-16 22:39:424204void WebContentsImpl::SetAllowOtherViews(bool allow) {
4205 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454206}
4207
[email protected]75f4df72014-07-16 22:39:424208bool WebContentsImpl::GetAllowOtherViews() {
4209 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454210}
4211
[email protected]7d244f12013-08-22 21:41:514212#endif
4213
[email protected]6fba26d2014-04-29 09:38:284214void WebContentsImpl::OnDialogClosed(int render_process_id,
4215 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264216 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494217 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264218 bool success,
[email protected]fcf75d42013-12-03 20:11:264219 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284220 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4221 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494222 last_dialog_suppressed_ = dialog_was_suppressed;
4223
[email protected]beb440c2009-11-06 04:08:544224 if (is_showing_before_unload_dialog_ && !success) {
4225 // If a beforeunload dialog is canceled, we need to stop the throbber from
4226 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284227 if (rfh)
4228 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354229 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104230
[email protected]6d65a462013-06-21 21:29:124231 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4232 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544233 }
[email protected]87de04b02014-04-08 22:14:494234
[email protected]beb440c2009-11-06 04:08:544235 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284236 if (rfh) {
4237 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4238 dialog_was_suppressed);
4239 } else {
4240 // Don't leak the sync IPC reply if the RFH or process is gone.
4241 delete reply_msg;
4242 }
[email protected]beb440c2009-11-06 04:08:544243}
4244
[email protected]b172aee2012-04-10 17:05:264245void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544246 if (encoding == last_reported_encoding_)
4247 return;
4248 last_reported_encoding_ = encoding;
4249
4250 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124251 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104252}
[email protected]f45d2a72010-03-08 23:28:354253
[email protected]b172aee2012-04-10 17:05:264254void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484255 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444256 // Can be NULL during tests.
4257 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454258 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364259}
[email protected]9f76c1e2012-03-05 15:15:584260
[email protected]1ac10dca2013-08-20 20:47:044261bool WebContentsImpl::IsHidden() {
4262 return capturer_count_ == 0 && !should_normally_be_visible_;
4263}
4264
[email protected]b0936d22013-11-28 06:47:364265RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214266 return frame_tree_.root()->render_manager();
4267}
4268
[email protected]b172aee2012-04-10 17:05:264269RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584270 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4271}
[email protected]7900bfdb2012-05-24 19:31:244272
[email protected]f8497342013-02-05 22:15:024273BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394274 return browser_plugin_guest_.get();
4275}
4276
[email protected]738f57a2013-06-29 21:06:544277void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4278 CHECK(!browser_plugin_guest_);
4279 browser_plugin_guest_.reset(guest);
4280}
4281
[email protected]f8497342013-02-05 22:15:024282BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394283 return browser_plugin_embedder_.get();
4284}
[email protected]8ff00d72012-10-23 19:12:214285
[email protected]d9030b82013-07-19 08:26:064286void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194287 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304288 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4289 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4290 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064291}
4292
4293void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304294 active_audio_players_.clear();
4295 active_video_players_.clear();
4296 audio_power_save_blocker_.reset();
4297 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064298}
4299
[email protected]fc2b46b2014-05-03 16:33:454300gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214301 gfx::Size size;
4302 if (delegate_)
4303 size = delegate_->GetSizeForNewRenderView(this);
4304 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454305 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214306 return size;
4307}
4308
[email protected]ae7eeda2014-07-04 01:53:264309void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4310 FOR_EACH_OBSERVER(
4311 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554312}
4313
[email protected]222f5822014-02-05 23:40:494314void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4315 if (!delegate_)
4316 return;
4317 const gfx::Size new_size = GetPreferredSize();
4318 if (new_size != old_size)
4319 delegate_->UpdatePreferredSize(this, new_size);
4320}
4321
dalecurtisbc6572e12014-09-12 19:22:304322void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4323 ActiveMediaPlayerMap* player_map) {
4324 const uintptr_t key =
4325 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4326 DCHECK(std::find((*player_map)[key].begin(),
4327 (*player_map)[key].end(),
4328 player_cookie) == (*player_map)[key].end());
4329 (*player_map)[key].push_back(player_cookie);
4330}
4331
4332void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4333 ActiveMediaPlayerMap* player_map) {
4334 const uintptr_t key =
4335 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4336 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4337 if (it == player_map->end())
4338 return;
4339
4340 // Remove the player.
4341 PlayerList::iterator player_it =
4342 std::find(it->second.begin(), it->second.end(), player_cookie);
4343 if (player_it != it->second.end())
4344 it->second.erase(player_it);
4345
4346 // If there are no players left, remove the map entry.
4347 if (it->second.empty())
4348 player_map->erase(it);
4349}
4350
4351void WebContentsImpl::RemoveAllMediaPlayerEntries(
4352 RenderFrameHost* render_frame_host,
4353 ActiveMediaPlayerMap* player_map) {
4354 ActiveMediaPlayerMap::iterator it =
4355 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4356 if (it == player_map->end())
4357 return;
4358 player_map->erase(it);
4359}
4360
[email protected]23f41fd2014-06-21 05:29:174361void WebContentsImpl::ResumeResponseDeferredAtStart() {
4362 FrameTreeNode* node = frame_tree_.root();
4363 node->render_manager()->ResumeResponseDeferredAtStart();
4364}
4365
[email protected]34ff1cfc2014-08-20 06:16:054366void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4367 force_disable_overscroll_content_ = force_disable;
4368 if (view_)
4369 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4370}
4371
[email protected]8ff00d72012-10-23 19:12:214372} // namespace content