blob: 6039e323ad825f26a4e8392d93d0bc012f19fa48 [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"
[email protected]29998f92014-06-15 03:12:1441#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5342#include "content/browser/message_port_message_filter.h"
43#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0644#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3045#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5046#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3247#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5048#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4849#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]01f83f92014-06-17 14:41:5450#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
[email protected]b6583592012-01-25 19:52:3351#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1152#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5853#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0354#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5655#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1456#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4257#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4458#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0259#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1760#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5161#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0262#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3663#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1164#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2865#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4466#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3667#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1768#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1469#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4670#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1571#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0072#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2773#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0074#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3775#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1476#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3077#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3278#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3479#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3880#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4281#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2582#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2183#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4884#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5485#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4986#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2087#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0388#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5789#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0590#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1691#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2992#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5393#include "net/http/http_cache.h"
94#include "net/http/http_transaction_factory.h"
95#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3496#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5697#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0198#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4199#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52100#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31101
[email protected]583418cc2013-01-17 14:01:10102#if defined(OS_ANDROID)
[email protected]23f41fd2014-06-21 05:29:17103#include "content/browser/android/content_view_core_impl.h"
[email protected]583418cc2013-01-17 14:01:10104#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45105#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18106#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00107#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10108#endif
109
[email protected]f66df822012-05-18 16:52:17110#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50111#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57112#endif
[email protected]3e45ba92009-02-20 21:09:00113
[email protected]420ae012009-04-24 05:16:32114// Cross-Site Navigations
115//
[email protected]b172aee2012-04-10 17:05:26116// If a WebContentsImpl is told to navigate to a different web site (as
117// determined by SiteInstance), it will replace its current RenderViewHost with
118// a new RenderViewHost dedicated to the new SiteInstance. This works as
119// follows:
[email protected]420ae012009-04-24 05:16:32120//
[email protected]fc6c1872013-10-03 01:22:35121// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46122// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32123// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35124// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32125// run in the current RVH.
126// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35127// that it has a pending cross-site request. We will check this on the IO
128// thread when deciding how to handle the response.
129// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46130// cancel all the pending logic. Otherwise we allow the pending RVH to send
131// the navigation request to its renderer.
132// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35133// main resource load on the pending RVH. It creates a
134// CrossSiteResourceHandler to check whether a process swap is needed when
135// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46136// - When RDH receives a response, the BufferedResourceHandler determines
137// whether it is a download. If so, it sends a message to the new renderer
138// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26139// pending RVH remains until the next DidNavigate event for this
140// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32141// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35142// download, the CrossSiteResourceHandler checks whether a process swap is
143// needed (either because CrossSiteRequestManager has state for it or because
144// a transfer was needed for a redirect).
145// - If so, CrossSiteResourceHandler pauses the response to first run the old
146// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36147// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
148// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35149// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
150// to a new process is needed, based on the stored pending_nav_params_. (This
151// is independent of whether we started out with a cross-process navigation.)
152// - If not, it just tells the ResourceDispatcherHost to resume the response
153// to its current RenderViewHost.
154// - If so, it cancels the current pending RenderViewHost and sets up a new
155// navigation using RequestTransferURL. When the transferred request
156// arrives in the ResourceDispatcherHost, we transfer the response and
157// resume it.
[email protected]420ae012009-04-24 05:16:32158// - The pending renderer sends a FrameNavigate message that invokes the
159// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46160// pending RVH.
[email protected]b0936d22013-11-28 06:47:36161// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15162// the user goes back. The process only stays live if another tab is using
163// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32164
[email protected]8ff00d72012-10-23 19:12:21165namespace content {
[email protected]420ae012009-04-24 05:16:32166namespace {
167
[email protected]960b0372014-05-19 18:01:00168const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
169
170// This matches what Blink's ProgressTracker has traditionally used for a
171// minimum progress value.
172const double kMinimumLoadingProgress = 0.1;
173
[email protected]82114f52012-03-20 22:53:41174const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05175
[email protected]155c7f22013-12-09 17:07:18176#if defined(OS_ANDROID)
177const char kWebContentsAndroidKey[] = "web_contents_android";
178#endif // OS_ANDROID
179
[email protected]e4abd3b42013-11-12 18:28:47180base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46181g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
182
[email protected]988ed7132014-03-31 16:25:58183static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39184 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29185 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30186 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02187 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58188 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02189 ++g_next_image_download_id,
190 url,
191 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30192 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02193 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39194}
195
[email protected]8bfc8272013-09-09 20:10:53196void NotifyCacheOnIO(
197 scoped_refptr<net::URLRequestContextGetter> request_context,
198 const GURL& url,
199 const std::string& http_method) {
200 request_context->GetURLRequestContext()->http_transaction_factory()->
201 GetCache()->OnExternalCacheHit(url, http_method);
202}
203
[email protected]9b159a52013-10-03 17:24:55204// Helper function for retrieving all the sites in a frame tree.
205bool CollectSites(BrowserContext* context,
206 std::set<GURL>* sites,
207 FrameTreeNode* node) {
208 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
209 return true;
210}
211
[email protected]a86c0e962013-12-17 17:10:39212bool ForEachFrameInternal(
213 const base::Callback<void(RenderFrameHost*)>& on_frame,
214 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41215 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39216 return true;
217}
218
[email protected]95640212014-07-26 18:14:30219bool ForEachPendingFrameInternal(
220 const base::Callback<void(RenderFrameHost*)>& on_frame,
221 FrameTreeNode* node) {
222 RenderFrameHost* pending_frame_host =
223 node->render_manager()->pending_frame_host();
224 if (pending_frame_host)
225 on_frame.Run(pending_frame_host);
226 return true;
227}
228
[email protected]a86c0e962013-12-17 17:10:39229void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
230 IPC::Message* message_copy = new IPC::Message(*message);
231 message_copy->set_routing_id(rfh->GetRoutingID());
232 rfh->Send(message_copy);
233}
234
[email protected]948481d2014-06-11 18:32:22235void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
236 RenderFrameHost* rfh) {
237 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
238 ->frame_tree_node()
239 ->render_manager()
240 ->GetRenderWidgetHostView();
241 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59242}
243
[email protected]95640212014-07-26 18:14:30244void SetAccessibilityModeOnFrame(AccessibilityMode mode,
245 RenderFrameHost* frame_host) {
246 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
247}
248
[email protected]420ae012009-04-24 05:16:32249} // namespace
250
[email protected]54944cde2012-12-09 09:24:59251WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15252 return WebContentsImpl::CreateWithOpener(
253 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19254}
255
256WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59257 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30258 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59259 WebContentsImpl* new_contents = new WebContentsImpl(
260 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30261
262 for (SessionStorageNamespaceMap::const_iterator it =
263 session_storage_namespace_map.begin();
264 it != session_storage_namespace_map.end();
265 ++it) {
266 new_contents->GetController()
267 .SetSessionStorageNamespace(it->first, it->second.get());
268 }
269
[email protected]54944cde2012-12-09 09:24:59270 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19271 return new_contents;
[email protected]a81343d232011-12-27 07:39:20272}
[email protected]746d3052012-05-22 15:15:47273
[email protected]e4abd3b42013-11-12 18:28:47274void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46275 g_created_callbacks.Get().push_back(callback);
276}
277
[email protected]e4abd3b42013-11-12 18:28:47278void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46279 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
280 if (g_created_callbacks.Get().at(i).Equals(callback)) {
281 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
282 return;
283 }
284 }
285}
286
[email protected]299d7f12012-05-23 05:31:15287WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47288 return rvh->GetDelegate()->GetAsWebContents();
289}
290
[email protected]a86c0e962013-12-17 17:10:39291WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
292 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
293 if (!rfh_impl)
294 return NULL;
295 return rfh_impl->delegate()->GetAsWebContents();
296}
297
[email protected]7fff43e2013-05-21 20:21:10298// WebContentsImpl::DestructionObserver ----------------------------------------
299
300class WebContentsImpl::DestructionObserver : public WebContentsObserver {
301 public:
302 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
303 : WebContentsObserver(watched_contents),
304 owner_(owner) {
305 }
306
307 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58308 virtual void WebContentsDestroyed() OVERRIDE {
309 owner_->OnWebContentsDestroyed(
310 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10311 }
312
313 private:
314 WebContentsImpl* owner_;
315
316 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
317};
318
[email protected]8ed16472014-04-11 19:02:48319WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
320 int render_frame_id,
321 ColorChooser* chooser,
322 int identifier)
323 : render_process_id(render_process_id),
324 render_frame_id(render_frame_id),
325 chooser(chooser),
326 identifier(identifier) {
327}
328
329WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
330}
331
[email protected]b172aee2012-04-10 17:05:26332// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32333
[email protected]b172aee2012-04-10 17:05:26334WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21335 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19336 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42337 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22338 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57339 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44340 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49341 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08342#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41343 accessible_parent_(NULL),
344#endif
[email protected]6ea6bdf2013-12-06 13:35:01345 frame_tree_(new NavigatorImpl(&controller_, this),
346 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34347 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03348 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23349 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
350 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34351 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26352 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00353 loading_total_progress_(0.0),
354 loading_weak_factory_(this),
355 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56356 upload_size_(0),
357 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47358 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10359 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55360 capturer_count_(0),
361 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57362 is_being_destroyed_(false),
363 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15364 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01365 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02366 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38367 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21368 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
369 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29370 totalPinchGestureAmount_(0),
371 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44372 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42373 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03374 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49375 is_subframe_(false),
[email protected]e85165c642014-06-10 14:34:31376 touch_emulation_enabled_(false),
[email protected]95640212014-07-26 18:14:30377 last_dialog_suppressed_(false),
378 accessibility_mode_(
379 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()) {
[email protected]cbb1ef592013-06-05 19:49:46380 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
381 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55382 frame_tree_.SetFrameRemoveListener(
383 base::Bind(&WebContentsImpl::OnFrameRemoved,
384 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35385}
initial.commit09911bf2008-07-26 23:55:29386
[email protected]b172aee2012-04-10 17:05:26387WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32388 is_being_destroyed_ = true;
389
[email protected]21b41c7e892014-02-28 01:52:24390 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
391 // shutdown and be deleted as well.
392 frame_tree_.ForEach(
393 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
394
[email protected]d9030b82013-07-19 08:26:06395 ClearAllPowerSaveBlockers();
396
[email protected]b24b68a2012-09-24 21:57:26397 for (std::set<RenderWidgetHostImpl*>::iterator iter =
398 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
399 (*iter)->DetachDelegate();
400 }
401 created_widgets_.clear();
402
[email protected]3ab9cb82011-06-03 18:02:07403 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15404 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11405 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07406
[email protected]8ed16472014-04-11 19:02:48407 if (color_chooser_info_.get())
408 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20409
[email protected]420ae012009-04-24 05:16:32410 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32411
[email protected]ca13a442012-04-17 14:00:12412 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21413 NotificationService::current()->Notify(
414 NOTIFICATION_WEB_CONTENTS_DESTROYED,
415 Source<WebContents>(this),
416 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32417
[email protected]df0c843f2014-05-23 20:37:23418 // Destroy all frame tree nodes except for the root; this notifies observers.
419 frame_tree_.ResetForMainFrameSwap();
420 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59421
[email protected]df0c843f2014-05-23 20:37:23422 // Manually call the observer methods for the root frame tree node.
423 RenderFrameHostManager* root = GetRenderManager();
424 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27425 FOR_EACH_OBSERVER(WebContentsObserver,
426 observers_,
[email protected]df0c843f2014-05-23 20:37:23427 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27428 }
[email protected]df0c843f2014-05-23 20:37:23429 FOR_EACH_OBSERVER(WebContentsObserver,
430 observers_,
431 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27432
[email protected]df0c843f2014-05-23 20:37:23433 if (root->pending_render_view_host()) {
434 FOR_EACH_OBSERVER(WebContentsObserver,
435 observers_,
436 RenderViewDeleted(root->pending_render_view_host()));
437 }
[email protected]c06c58c2014-03-12 20:31:59438
[email protected]f273ee52013-10-18 16:05:27439 FOR_EACH_OBSERVER(WebContentsObserver,
440 observers_,
[email protected]df0c843f2014-05-23 20:37:23441 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27442
[email protected]2db9bd72012-04-13 20:20:56443 FOR_EACH_OBSERVER(WebContentsObserver,
444 observers_,
[email protected]12a46832014-05-09 13:35:58445 WebContentsDestroyed());
446
447 FOR_EACH_OBSERVER(WebContentsObserver,
448 observers_,
449 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08450
[email protected]6934a702011-12-20 00:04:51451 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10452
453 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
454 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42455}
456
[email protected]d1198fd2012-08-13 22:50:19457WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59458 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19459 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03460 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59461 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06462 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19463
[email protected]4858e432014-06-23 18:14:17464 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06465 // This makes |new_contents| act as a guest.
466 // For more info, see comment above class BrowserPluginGuest.
[email protected]4858e432014-06-23 18:14:17467 BrowserPluginGuest::Create(params.guest_delegate->GetGuestInstanceID(),
[email protected]83100cd2014-05-10 11:50:06468 new_contents,
[email protected]4858e432014-06-23 18:14:17469 params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06470 // We are instantiating a WebContents for browser plugin. Set its subframe
471 // bit to true.
472 new_contents->is_subframe_ = true;
473 }
[email protected]54944cde2012-12-09 09:24:59474 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19475 return new_contents;
476}
477
[email protected]95640212014-07-26 18:14:30478// static
479std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
480 std::vector<WebContentsImpl*> result;
481 scoped_ptr<RenderWidgetHostIterator> widgets(
482 RenderWidgetHostImpl::GetRenderWidgetHosts());
483 std::set<WebContentsImpl*> web_contents_set;
484 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
485 if (!rwh->IsRenderView())
486 continue;
487 RenderViewHost* rvh = RenderViewHost::From(rwh);
488 if (!rvh)
489 continue;
490 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
491 if (!web_contents)
492 continue;
493 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
494 if (web_contents_set.find(wci) == web_contents_set.end()) {
495 web_contents_set.insert(wci);
496 result.push_back(wci);
497 }
498 }
499 return result;
500}
501
[email protected]b0936d22013-11-28 06:47:36502RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21503 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28504}
505
[email protected]7bb761892012-07-20 09:32:47506bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
507 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44508 return OnMessageReceived(render_view_host, NULL, message);
509}
510
511bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
512 RenderFrameHost* render_frame_host,
513 const IPC::Message& message) {
514 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56515 if (GetWebUI() &&
516 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17517 return true;
[email protected]d2353452012-01-19 19:53:56518 }
[email protected]f82d57b52011-04-27 19:13:17519
[email protected]d8c660432011-12-22 20:51:25520 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
521 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33522 if (render_frame_host) {
523 while ((observer = it.GetNext()) != NULL)
524 if (observer->OnMessageReceived(message, render_frame_host))
525 return true;
526 } else {
527 while ((observer = it.GetNext()) != NULL)
528 if (observer->OnMessageReceived(message))
529 return true;
530 }
[email protected]403415a2011-01-10 18:57:53531
[email protected]1d62cf72014-02-07 21:31:57532 // Message handlers should be aware of which
533 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
534 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02535 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57536 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02537 else
[email protected]1d62cf72014-02-07 21:31:57538 render_view_message_source_ = render_view_host;
[email protected]1d62cf72014-02-07 21:31:57539
[email protected]724159a2010-12-30 01:11:18540 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33541 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44542 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
543 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40544 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
545 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05546 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
547 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48548 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
549 OnDocumentLoadedInFrame)
550 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00551 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
552 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
553 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
554 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48555 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
556 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
557 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
558 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19559 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
560 OnMediaPlayingNotification)
561 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
562 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11563 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
564 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18565 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
566 OnDidLoadResourceFromMemoryCache)
567 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
568 OnDidDisplayInsecureContent)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
570 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25571 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26572 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21573 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20574 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
575 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20576 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
577 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16578 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10579 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50580 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50581 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
582 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55583 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
584 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02585 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
586 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07587 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
588 OnShowValidationMessage)
589 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
590 OnHideValidationMessage)
591 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
592 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48593#if defined(OS_ANDROID)
594 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
595 OnFindMatchRectsReply)
596 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
597 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48598#endif
[email protected]724159a2010-12-30 01:11:18599 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33600 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44601 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57602 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18603
[email protected]724159a2010-12-30 01:11:18604 return handled;
605}
606
[email protected]b172aee2012-04-10 17:05:26607void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18608 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21609 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43610 if (delegate_)
611 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18612}
613
[email protected]d1198fd2012-08-13 22:50:19614NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56615 return controller_;
616}
617
[email protected]d1198fd2012-08-13 22:50:19618const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56619 return controller_;
620}
621
[email protected]8ff00d72012-10-23 19:12:21622BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55623 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30624}
625
[email protected]b172aee2012-04-10 17:05:26626const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24627 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32628 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51629 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31630}
631
[email protected]a093ce02013-07-22 20:53:14632const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24633 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32634 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24635 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
636}
637
638const GURL& WebContentsImpl::GetLastCommittedURL() const {
639 // We may not have a navigation entry yet.
640 NavigationEntry* entry = controller_.GetLastCommittedEntry();
641 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
642}
643
[email protected]8ff00d72012-10-23 19:12:21644WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31645 return delegate_;
646}
647
[email protected]8ff00d72012-10-23 19:12:21648void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31649 // TODO(cbentzel): remove this debugging code?
650 if (delegate == delegate_)
651 return;
652 if (delegate_)
653 delegate_->Detach(this);
654 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08655 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31656 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08657 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00658 if (view_)
[email protected]e85165c642014-06-10 14:34:31659 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08660 }
[email protected]be1f56ab2011-12-22 06:55:31661}
662
[email protected]8ff00d72012-10-23 19:12:21663RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21664 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41665 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16666}
667
[email protected]60eca4eb2013-12-06 00:02:16668RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41669 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16670}
671
[email protected]9c9343b2014-03-08 02:56:07672RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
673 if (!frame_tree_.GetFocusedFrame())
674 return NULL;
675 return frame_tree_.GetFocusedFrame()->current_frame_host();
676}
677
[email protected]a86c0e962013-12-17 17:10:39678void WebContentsImpl::ForEachFrame(
679 const base::Callback<void(RenderFrameHost*)>& on_frame) {
680 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
681}
682
683void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
684 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
685 delete message;
686}
687
[email protected]b172aee2012-04-10 17:05:26688RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21689 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31690}
691
[email protected]6b618e62012-08-16 12:59:18692int WebContentsImpl::GetRoutingID() const {
693 if (!GetRenderViewHost())
694 return MSG_ROUTING_NONE;
695
696 return GetRenderViewHost()->GetRoutingID();
697}
698
[email protected]44470a22013-01-24 01:21:54699int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
700 return fullscreen_widget_routing_id_;
701}
702
[email protected]b172aee2012-04-10 17:05:26703RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21704 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31705}
706
[email protected]4aebbca2013-09-17 22:26:49707RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
708 const {
709 RenderWidgetHost* const widget_host =
710 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
711 GetFullscreenWidgetRoutingID());
712 return widget_host ? widget_host->GetView() : NULL;
713}
714
[email protected]8ff00d72012-10-23 19:12:21715WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31716 return view_.get();
717}
718
[email protected]95640212014-07-26 18:14:30719void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
720 if (mode == accessibility_mode_)
721 return;
722
723 accessibility_mode_ = mode;
724 frame_tree_.ForEach(
725 base::Bind(&ForEachFrameInternal,
726 base::Bind(&SetAccessibilityModeOnFrame, mode)));
727 frame_tree_.ForEach(
728 base::Bind(&ForEachPendingFrameInternal,
729 base::Bind(&SetAccessibilityModeOnFrame, mode)));
730}
731
732void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
733 SetAccessibilityMode(
734 content::AddAccessibilityModeTo(accessibility_mode_, mode));
735}
736
737void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
738 SetAccessibilityMode(
739 content::RemoveAccessibilityModeFrom(accessibility_mode_, mode));
740}
741
[email protected]8ff00d72012-10-23 19:12:21742WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56743 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03744 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
745 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22746 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58747 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22748 web_ui->SetController(controller);
749 return web_ui;
750 }
751
752 delete web_ui;
753 return NULL;
754}
755
[email protected]8ff00d72012-10-23 19:12:21756WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21757 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
758 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31759}
760
[email protected]8ff00d72012-10-23 19:12:21761WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21762 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34763}
764
[email protected]86ef6a392012-05-11 22:03:11765void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22766 if (GetUserAgentOverride() == override)
767 return;
768
769 renderer_preferences_.user_agent_override = override;
770
771 // Send the new override string to the renderer.
772 RenderViewHost* host = GetRenderViewHost();
773 if (host)
774 host->SyncRendererPrefs();
775
776 // Reload the page if a load is currently in progress to avoid having
777 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27778 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22779 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
780 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53781
782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
783 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11784}
785
786const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22787 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11788}
789
[email protected]95640212014-07-26 18:14:30790void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
791 AddAccessibilityMode(AccessibilityModeTreeOnly);
792}
793
794bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
795 return accessibility_mode_ == AccessibilityModeTreeOnly;
796}
797
798bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
799 return accessibility_mode_ == AccessibilityModeComplete;
800}
801
[email protected]2ceee8f2014-01-14 18:02:08802#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41803void WebContentsImpl::SetParentNativeViewAccessible(
804gfx::NativeViewAccessible accessible_parent) {
805 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30806 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
807 if (rfh)
808 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41809}
810#endif
811
[email protected]fcf75d42013-12-03 20:11:26812const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55813 // Transient entries take precedence. They are used for interstitial pages
814 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23815 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08816 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21817 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30818 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23819 if (entry) {
[email protected]b5cca982011-05-26 04:42:08820 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23821 }
[email protected]fa944cb82013-11-15 17:51:21822 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
823 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58824 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54825 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32826 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54827 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35828 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26829 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54830 if (!title.empty())
831 return title;
832 }
833 }
834
835 // We use the title for the last committed entry rather than a pending
836 // navigation entry. For example, when the user types in a URL, we want to
837 // keep the old page's title until the new load has committed and we get a new
838 // title.
[email protected]96d185d2009-04-24 03:28:54839 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32840
[email protected]9eeafc012013-11-25 23:49:47841 // We make an exception for initial navigations.
842 if (controller_.IsInitialNavigation()) {
843 // We only want to use the title from the visible entry in one of two cases:
844 // 1. There's already a committed entry for an initial navigation, in which
845 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
846 // 2. The pending entry has been explicitly assigned a title to display.
847 //
848 // If there's no last committed entry and no assigned title, we should fall
849 // back to |page_title_when_no_navigation_entry_| rather than showing the
850 // URL.
851 if (entry ||
852 (controller_.GetVisibleEntry() &&
853 !controller_.GetVisibleEntry()->GetTitle().empty())) {
854 entry = controller_.GetVisibleEntry();
855 }
856 }
[email protected]59167c22013-06-03 18:07:32857
[email protected]45d0ef7f2011-01-05 13:46:23858 if (entry) {
[email protected]b5cca982011-05-26 04:42:08859 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23860 }
[email protected]987fc3a2011-05-26 14:18:09861
862 // |page_title_when_no_navigation_entry_| is finally used
863 // if no title cannot be retrieved.
864 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54865}
866
[email protected]b172aee2012-04-10 17:05:26867int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46868 return GetMaxPageIDForSiteInstance(GetSiteInstance());
869}
870
[email protected]b172aee2012-04-10 17:05:26871int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
872 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33873 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
874 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46875
[email protected]b6583592012-01-25 19:52:33876 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34877}
878
[email protected]b172aee2012-04-10 17:05:26879void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46880 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
881}
882
[email protected]b172aee2012-04-10 17:05:26883void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33884 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46885 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33886 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34887}
888
[email protected]ec6c05f2013-10-23 18:41:57889void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
890 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
891 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57892}
893
[email protected]b172aee2012-04-10 17:05:26894SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21895 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54896}
897
[email protected]b172aee2012-04-10 17:05:26898SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21899 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
900 GetRenderManager()->pending_render_view_host() :
901 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58902 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38903}
904
[email protected]b172aee2012-04-10 17:05:26905bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49907}
908
[email protected]6dfed692014-05-22 04:18:03909bool WebContentsImpl::IsLoadingToDifferentDocument() const {
910 return is_loading_ && is_load_to_different_document_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03914 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31915}
916
[email protected]b172aee2012-04-10 17:05:26917const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return load_state_;
919}
920
[email protected]fcf75d42013-12-03 20:11:26921const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31922 return load_state_host_;
923}
924
[email protected]b172aee2012-04-10 17:05:26925uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31926 return upload_size_;
927}
928
[email protected]b172aee2012-04-10 17:05:26929uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return upload_position_;
931}
932
[email protected]1ae93fb2013-06-14 03:38:56933std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56934 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39935 frame_tree_.ForEach(base::Bind(&CollectSites,
936 base::Unretained(GetBrowserContext()),
937 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56938 return sites;
939}
940
[email protected]b172aee2012-04-10 17:05:26941const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54942 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31943}
944
[email protected]b172aee2012-04-10 17:05:26945bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31946 return displayed_insecure_content_;
947}
948
[email protected]222f5822014-02-05 23:40:49949void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25950 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55951 ++capturer_count_;
952 DVLOG(1) << "There are now " << capturer_count_
953 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49954
955 // Note: This provides a hint to upstream code to size the views optimally
956 // for quality (e.g., to avoid scaling).
957 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
958 preferred_size_for_capture_ = capture_size;
959 OnPreferredSizeChanged(preferred_size_);
960 }
[email protected]54597982013-02-06 01:59:55961}
962
963void WebContentsImpl::DecrementCapturerCount() {
964 --capturer_count_;
965 DVLOG(1) << "There are now " << capturer_count_
966 << " capturing(s) of WebContentsImpl@" << this;
967 DCHECK_LE(0, capturer_count_);
968
[email protected]5a652232013-02-12 06:15:25969 if (is_being_destroyed_)
970 return;
971
[email protected]222f5822014-02-05 23:40:49972 if (capturer_count_ == 0) {
973 const gfx::Size old_size = preferred_size_for_capture_;
974 preferred_size_for_capture_ = gfx::Size();
975 OnPreferredSizeChanged(old_size);
976 }
977
[email protected]1ac10dca2013-08-20 20:47:04978 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55979 DVLOG(1) << "Executing delayed WasHidden().";
980 WasHidden();
981 }
[email protected]be1f56ab2011-12-22 06:55:31982}
983
[email protected]f2bd40812013-07-20 04:30:44984int WebContentsImpl::GetCapturerCount() const {
985 return capturer_count_;
986}
987
[email protected]b172aee2012-04-10 17:05:26988bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31989 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
990 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
991 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49992}
993
[email protected]b172aee2012-04-10 17:05:26994void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
995 int error_code) {
[email protected]443b80e2010-12-14 00:42:23996 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34997 return;
998
[email protected]443b80e2010-12-14 00:42:23999 crashed_status_ = status;
1000 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211001 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341002}
1003
[email protected]b172aee2012-04-10 17:05:261004base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311005 return crashed_status_;
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311009 return is_being_destroyed_;
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341013 if (delegate_)
1014 delegate_->NavigationStateChanged(this, changed_flags);
1015}
1016
[email protected]9a890452014-02-13 22:21:021017base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1018 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331019}
1020
[email protected]9e2e4632012-07-27 16:38:411021void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541022 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591023
[email protected]948481d2014-06-11 18:32:221024 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1025 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591026 iter != widgets.end();
1027 iter++) {
[email protected]948481d2014-06-11 18:32:221028 if (*iter) {
1029 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431030#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221031 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431032#endif
[email protected]de3c5d82014-05-28 22:12:591033 }
[email protected]789e9152009-08-04 21:59:431034 }
[email protected]96d185d2009-04-24 03:28:541035
[email protected]9a890452014-02-13 22:21:021036 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381037
[email protected]b9769d82012-02-10 00:23:591038 // The resize rect might have changed while this was inactive -- send the new
1039 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581040 RenderViewHostImpl* rvh =
1041 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591042 if (rvh) {
1043 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1044 }
[email protected]96d185d2009-04-24 03:28:541045
[email protected]c0d9d5672013-10-09 07:38:031046 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1047
[email protected]54597982013-02-06 01:59:551048 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311049}
1050
[email protected]b172aee2012-04-10 17:05:261051void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551052 // If there are entities capturing screenshots or video (e.g., mirroring),
1053 // don't activate the "disable rendering" optimization.
1054 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521055 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551056 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261057 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521058 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331059 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521060 // calls us).
[email protected]948481d2014-06-11 18:32:221061 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1062 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591063 iter != widgets.end();
1064 iter++) {
[email protected]948481d2014-06-11 18:32:221065 if (*iter)
1066 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591067 }
[email protected]96d185d2009-04-24 03:28:541068 }
1069
[email protected]c0d9d5672013-10-09 07:38:031070 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1071
[email protected]54597982013-02-06 01:59:551072 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371073}
1074
[email protected]b172aee2012-04-10 17:05:261075bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311076 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271077 return WillNotifyDisconnection() &&
1078 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581079 !static_cast<RenderViewHostImpl*>(
1080 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311081}
1082
[email protected]1c3f80bd2014-04-08 23:02:061083void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1084 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1085 for_cross_site_transition);
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211089 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401090 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271091}
1092
[email protected]b172aee2012-04-10 17:05:261093WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441094 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451095 // We pass our own opener so that the cloned page can access it if it was
1096 // before.
[email protected]54944cde2012-12-09 09:24:591097 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451098 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591099 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191100 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221101 FOR_EACH_OBSERVER(WebContentsObserver,
1102 observers_,
1103 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271104 return tc;
1105}
1106
[email protected]14392a52012-05-02 20:28:441107void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211108 const NotificationSource& source,
1109 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441110 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211111 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1112 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031113 RenderWidgetHostView* view = host->GetView();
1114 if (view == GetFullscreenRenderWidgetHostView()) {
1115 // We cannot just call view_->RestoreFocus() here. On some platforms,
1116 // attempting to focus the currently-invisible WebContentsView will be
1117 // flat-out ignored. Therefore, this boolean is used to track whether
1118 // we will request focus after the fullscreen widget has been
1119 // destroyed.
1120 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1121 } else {
1122 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1123 i != pending_widget_views_.end(); ++i) {
1124 if (host->GetView() == i->second) {
1125 pending_widget_views_.erase(i);
1126 break;
1127 }
[email protected]bafe6cd2012-05-23 23:09:501128 }
1129 }
1130 break;
1131 }
[email protected]14392a52012-05-02 20:28:441132 default:
1133 NOTREACHED();
1134 }
1135}
1136
[email protected]ec6c05f2013-10-23 18:41:571137WebContents* WebContentsImpl::GetWebContents() {
1138 return this;
1139}
1140
[email protected]54944cde2012-12-09 09:24:591141void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211142 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361143 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211144 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431145 should_normally_be_visible_ = !params.initially_hidden;
1146
[email protected]fa944cb82013-11-15 17:51:211147 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041148 params.browser_context, params.site_instance, params.routing_id,
1149 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191150
[email protected]fc2b46b2014-05-03 16:33:451151 WebContentsViewDelegate* delegate =
1152 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1153
1154 if (browser_plugin_guest_) {
1155 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1156 this, delegate, &render_view_host_delegate_view_));
1157
1158 WebContentsViewGuest* rv = new WebContentsViewGuest(
1159 this, browser_plugin_guest_.get(), platform_view.Pass(),
1160 render_view_host_delegate_view_);
1161 render_view_host_delegate_view_ = rv;
1162 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191163 } else {
[email protected]fc2b46b2014-05-03 16:33:451164 // Regular WebContentsView.
1165 view_.reset(CreateWebContentsView(
1166 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191167 }
[email protected]fc2b46b2014-05-03 16:33:451168 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191169 CHECK(view_.get());
1170
[email protected]ed245db2012-12-18 08:00:451171 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591172 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191173
1174 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101175 if (opener_)
1176 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191177
1178 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211179 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1180 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101181
1182 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
[email protected]29998f92014-06-15 03:12:141183 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101184
[email protected]01f83f92014-06-17 14:41:541185 screen_orientation_dispatcher_host_.reset(
1186 new ScreenOrientationDispatcherHost(this));
1187
[email protected]c7654a232013-06-12 21:04:441188#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101189 date_time_chooser_.reset(new DateTimeChooserAndroid());
1190#endif
[email protected]d1198fd2012-08-13 22:50:191191}
1192
[email protected]7fff43e2013-05-21 20:21:101193void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1194 RemoveDestructionObserver(web_contents);
1195
[email protected]14392a52012-05-02 20:28:441196 // Clear the opener if it has been closed.
1197 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441198 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511199 return;
[email protected]14392a52012-05-02 20:28:441200 }
[email protected]ceee8cd2013-03-08 04:59:511201 // Clear a pending contents that has been closed before being shown.
1202 for (PendingContents::iterator iter = pending_contents_.begin();
1203 iter != pending_contents_.end();
1204 ++iter) {
1205 if (iter->second != web_contents)
1206 continue;
1207 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511208 return;
1209 }
1210 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441211}
1212
[email protected]7fff43e2013-05-21 20:21:101213void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1214 if (!ContainsKey(destruction_observers_, web_contents)) {
1215 destruction_observers_[web_contents] =
1216 new DestructionObserver(this, web_contents);
1217 }
1218}
1219
1220void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1221 DestructionObservers::iterator iter =
1222 destruction_observers_.find(web_contents);
1223 if (iter != destruction_observers_.end()) {
1224 delete destruction_observers_[web_contents];
1225 destruction_observers_.erase(iter);
1226 }
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311230 observers_.AddObserver(observer);
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311234 observers_.RemoveObserver(observer);
1235}
1236
[email protected]948481d2014-06-11 18:32:221237std::set<RenderWidgetHostView*>
1238WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1239 std::set<RenderWidgetHostView*> set;
1240 if (ShowingInterstitialPage()) {
1241 set.insert(GetRenderWidgetHostView());
1242 } else {
1243 ForEachFrame(
1244 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1245 }
[email protected]de3c5d82014-05-28 22:12:591246 return set;
1247}
1248
[email protected]b172aee2012-04-10 17:05:261249void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341250 if (delegate_)
1251 delegate_->ActivateContents(this);
1252}
1253
[email protected]b172aee2012-04-10 17:05:261254void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121255 if (delegate_)
1256 delegate_->DeactivateContents(this);
1257}
1258
[email protected]b172aee2012-04-10 17:05:261259void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481260 if (delegate_)
1261 delegate_->LostCapture();
1262}
1263
[email protected]b24b68a2012-09-24 21:57:261264void WebContentsImpl::RenderWidgetDeleted(
1265 RenderWidgetHostImpl* render_widget_host) {
1266 if (is_being_destroyed_) {
1267 // |created_widgets_| might have been destroyed.
1268 return;
1269 }
1270
1271 std::set<RenderWidgetHostImpl*>::iterator iter =
1272 created_widgets_.find(render_widget_host);
1273 if (iter != created_widgets_.end())
1274 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541275
1276 if (render_widget_host &&
1277 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491278 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1279 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541280 FOR_EACH_OBSERVER(WebContentsObserver,
1281 observers_,
1282 DidDestroyFullscreenWidget(
1283 fullscreen_widget_routing_id_));
1284 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031285 if (fullscreen_widget_had_focus_at_shutdown_)
1286 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541287 }
[email protected]b24b68a2012-09-24 21:57:261288}
1289
[email protected]b172aee2012-04-10 17:05:261290bool WebContentsImpl::PreHandleKeyboardEvent(
1291 const NativeWebKeyboardEvent& event,
1292 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481293 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131294 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481295}
1296
[email protected]b172aee2012-04-10 17:05:261297void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481298 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131299 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481300}
1301
[email protected]d92026ef2014-03-03 21:04:131302bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461303 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191304#if !defined(OS_MACOSX)
1305 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1306 // isn't done for two reasons:
1307 // -the OS already has a gesture to do this through pinch-zoom
1308 // -if a user starts an inertial scroll, let's go, and presses control
1309 // (i.e. control+tab) then the OS's buffered scroll events will come in
1310 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521311 if (delegate_ &&
1312 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551313 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1314 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1315 // gestures, which are regrettably easy to trigger accidentally.
1316 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521317 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1318 return true;
1319 }
[email protected]bccc4472013-04-18 16:37:191320#endif
[email protected]fb3f066e2013-02-12 19:12:521321 return false;
1322}
1323
[email protected]04bce562014-01-30 05:34:541324bool WebContentsImpl::PreHandleGestureEvent(
1325 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031326 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541327}
1328
[email protected]bab38af2014-03-30 17:37:291329bool WebContentsImpl::HandleGestureEvent(
1330 const blink::WebGestureEvent& event) {
1331 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1332 // Use them to implement browser zoom, as for HandleWheelEvent above.
1333 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331334 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291335 // The scale difference necessary to trigger a zoom action. Derived from
1336 // experimentation to find a value that feels reasonable.
1337 const float kZoomStepValue = 0.6f;
1338
1339 // Find the (absolute) thresholds on either side of the current zoom factor,
1340 // then convert those to actual numbers to trigger a zoom in or out.
1341 // This logic deliberately makes the range around the starting zoom value
1342 // for the gesture twice as large as the other ranges (i.e., the notches are
1343 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1344 // so that it's easier to get back to your starting point than it is to
1345 // overshoot.
1346 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1347 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1348 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1349 : -backStep;
1350 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1351 : backStep;
1352
[email protected]fb546cb2014-04-28 14:09:371353 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291354 if (totalPinchGestureAmount_ > zoomInThreshold) {
1355 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461356 if (delegate_)
1357 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291358 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1359 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461360 if (delegate_)
1361 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291362 }
1363 return true;
1364 }
1365
1366 return false;
1367}
1368
[email protected]b172aee2012-04-10 17:05:261369void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431370 if (delegate_)
1371 delegate_->HandleMouseDown();
1372}
1373
[email protected]b172aee2012-04-10 17:05:261374void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481375 if (delegate_)
1376 delegate_->HandleMouseUp();
1377}
1378
[email protected]590a634e2012-07-19 16:38:231379void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481380 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231381 delegate_->HandlePointerActivate();
1382}
1383
1384void WebContentsImpl::HandleGestureBegin() {
1385 if (delegate_)
1386 delegate_->HandleGestureBegin();
1387}
1388
1389void WebContentsImpl::HandleGestureEnd() {
1390 if (delegate_)
1391 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481392}
1393
[email protected]b172aee2012-04-10 17:05:261394void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491395 // This method is being called to enter or leave renderer-initiated fullscreen
1396 // mode. Either way, make sure any existing fullscreen widget is shut down
1397 // first.
1398 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1399 if (widget_view)
1400 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1401
[email protected]8a5e0ca2011-08-25 06:30:471402 if (delegate_)
1403 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371404
1405 FOR_EACH_OBSERVER(WebContentsObserver,
1406 observers_,
1407 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471408}
1409
[email protected]b172aee2012-04-10 17:05:261410bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381411 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121412}
1413
[email protected]a9c81f02012-06-01 00:15:441414void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1415 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371416 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441417 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371418 } else {
1419 GotResponseToLockMouseRequest(false);
1420 }
1421}
1422
[email protected]b172aee2012-04-10 17:05:261423void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371424 if (delegate_)
1425 delegate_->LostMouseLock();
1426}
1427
[email protected]bafe6cd2012-05-23 23:09:501428void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201429 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501430 int route_id,
[email protected]227692c52013-05-31 22:43:041431 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131432 const ViewHostMsg_CreateWindow_Params& params,
1433 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501434 // We usually create the new window in the same BrowsingInstance (group of
1435 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551436 // if the opener is being suppressed (in a non-guest), we create a new
1437 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251438 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551439
[email protected]04cbd3d2013-12-04 04:58:201440 // If the opener is to be suppressed, the new window can be in any process.
1441 // Since routing ids are process specific, we must not have one passed in
1442 // as argument here.
1443 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1444
[email protected]bafe6cd2012-05-23 23:09:501445 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551446 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571447 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501448 GetSiteInstance();
1449
[email protected]04cbd3d2013-12-04 04:58:201450 // A message to create a new window can only come from the active process for
1451 // this WebContentsImpl instance. If any other process sends the request,
1452 // it is invalid and the process must be terminated.
1453 if (GetRenderProcessHost()->GetID() != render_process_id) {
1454 base::ProcessHandle process_handle =
1455 RenderProcessHost::FromID(render_process_id)->GetHandle();
1456 if (process_handle != base::kNullProcessHandle) {
1457 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391458 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201459 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1460 }
1461 return;
1462 }
1463
[email protected]d1198fd2012-08-13 22:50:191464 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341465 //
1466 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301467 const std::string& partition_id =
1468 GetContentClient()->browser()->
1469 GetStoragePartitionIdForSite(GetBrowserContext(),
1470 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461471 StoragePartition* partition = BrowserContext::GetStoragePartition(
1472 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411473 DOMStorageContextWrapper* dom_storage_context =
1474 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191475 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1476 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1477 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371478
1479 if (delegate_ &&
1480 !delegate_->ShouldCreateWebContents(this,
1481 route_id,
1482 params.window_container_type,
1483 params.frame_name,
1484 params.target_url,
1485 partition_id,
1486 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011487 if (route_id != MSG_ROUTING_NONE &&
1488 !RenderViewHost::FromID(render_process_id, route_id)) {
1489 // If the embedder didn't create a WebContents for this route, we need to
1490 // delete the RenderView that had already been created.
1491 Send(new ViewMsg_Close(route_id));
1492 }
[email protected]dd6730412013-08-14 15:03:371493 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1494 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1495 main_frame_route_id);
1496 return;
1497 }
1498
1499 // Create the new web contents. This will automatically create the new
1500 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461501 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591502 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041503 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061504 create_params.opener = this;
1505 create_params.opener_suppressed = params.opener_suppressed;
1506 if (params.disposition == NEW_BACKGROUND_TAB)
1507 create_params.initially_hidden = true;
1508
[email protected]4858e432014-06-23 18:14:171509 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551510 if (!is_guest) {
1511 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451512 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171513 new_contents = static_cast<WebContentsImpl*>(
1514 WebContents::Create(create_params));
1515 } else {
1516 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551517 }
[email protected]50d326e2014-05-20 17:59:061518 new_contents->GetController().SetSessionStorageNamespace(
1519 partition_id,
1520 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261521 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191522
[email protected]c4538072013-03-18 02:17:551523 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341524 // will be shown immediately).
1525 if (!params.opener_suppressed) {
1526 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451527 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501528
[email protected]d70bea92013-04-05 04:23:341529 // TODO(brettw): It seems bogus that we have to call this function on the
1530 // newly created object and give it one of its own member variables.
1531 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1532 }
[email protected]bafe6cd2012-05-23 23:09:501533 // Save the created window associated with the route so we can show it
1534 // later.
1535 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1536 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101537 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501538 }
1539
1540 if (delegate_) {
1541 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071542 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131543 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501544 }
1545
1546 if (params.opener_suppressed) {
1547 // When the opener is suppressed, the original renderer cannot access the
1548 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001549 bool was_blocked = false;
1550 if (delegate_) {
1551 gfx::Rect initial_pos;
1552 delegate_->AddNewContents(
1553 this, new_contents, params.disposition, initial_pos,
1554 params.user_gesture, &was_blocked);
1555 }
1556 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211557 OpenURLParams open_params(params.target_url,
1558 Referrer(),
1559 CURRENT_TAB,
1560 PAGE_TRANSITION_LINK,
1561 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301562 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001563 new_contents->OpenURL(open_params);
1564 }
[email protected]bafe6cd2012-05-23 23:09:501565 }
1566}
1567
[email protected]a8504022013-12-04 20:23:511568void WebContentsImpl::CreateNewWidget(int render_process_id,
1569 int route_id,
[email protected]180ef242013-11-07 06:50:461570 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511571 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501572}
1573
[email protected]a8504022013-12-04 20:23:511574void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1575 int route_id) {
1576 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501577}
1578
[email protected]a8504022013-12-04 20:23:511579void WebContentsImpl::CreateNewWidget(int render_process_id,
1580 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501581 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461582 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211583 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511584 // A message to create a new widget can only come from the active process for
1585 // this WebContentsImpl instance. If any other process sends the request,
1586 // it is invalid and the process must be terminated.
1587 if (process->GetID() != render_process_id) {
1588 base::ProcessHandle process_handle =
1589 RenderProcessHost::FromID(render_process_id)->GetHandle();
1590 if (process_handle != base::kNullProcessHandle) {
1591 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391592 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511593 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1594 }
1595 return;
1596 }
1597
[email protected]bafe6cd2012-05-23 23:09:501598 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041599 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261600 created_widgets_.insert(widget_host);
1601
[email protected]cfd80b02014-05-01 17:46:481602 RenderWidgetHostViewBase* widget_view =
1603 static_cast<RenderWidgetHostViewBase*>(
1604 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191605 if (!widget_view)
1606 return;
[email protected]bafe6cd2012-05-23 23:09:501607 if (!is_fullscreen) {
1608 // Popups should not get activated.
1609 widget_view->SetPopupType(popup_type);
1610 }
1611 // Save the created widget associated with the route so we can show it later.
1612 pending_widget_views_[route_id] = widget_view;
1613
1614#if defined(OS_MACOSX)
1615 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1616 // to allow it to survive the trip without being hosted.
1617 base::mac::NSObjectRetain(widget_view->GetNativeView());
1618#endif
1619}
1620
1621void WebContentsImpl::ShowCreatedWindow(int route_id,
1622 WindowOpenDisposition disposition,
1623 const gfx::Rect& initial_pos,
1624 bool user_gesture) {
1625 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001626 if (contents) {
1627 WebContentsDelegate* delegate = GetDelegate();
1628 if (delegate) {
1629 delegate->AddNewContents(
1630 this, contents, disposition, initial_pos, user_gesture, NULL);
1631 }
1632 }
[email protected]bafe6cd2012-05-23 23:09:501633}
1634
1635void WebContentsImpl::ShowCreatedWidget(int route_id,
1636 const gfx::Rect& initial_pos) {
1637 ShowCreatedWidget(route_id, false, initial_pos);
1638}
1639
1640void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1641 ShowCreatedWidget(route_id, true, gfx::Rect());
1642}
1643
1644void WebContentsImpl::ShowCreatedWidget(int route_id,
1645 bool is_fullscreen,
1646 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481647 RenderWidgetHostViewBase* widget_host_view =
1648 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501649 if (!widget_host_view)
1650 return;
[email protected]cfd80b02014-05-01 17:46:481651
1652 RenderWidgetHostView* view = NULL;
1653 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1654 if (guest && guest->embedder_web_contents()) {
1655 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1656 } else {
1657 view = GetRenderWidgetHostView();
1658 }
1659
[email protected]4aebbca2013-09-17 22:26:491660 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311661 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031662 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311663 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491664 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1665 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1666 delegate_->ToggleFullscreenModeForTab(this, true);
1667 } else {
[email protected]cfd80b02014-05-01 17:46:481668 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491669 }
[email protected]4aebbca2013-09-17 22:26:491670 FOR_EACH_OBSERVER(WebContentsObserver,
1671 observers_,
1672 DidShowFullscreenWidget(route_id));
1673 if (!widget_host_view->HasFocus())
1674 widget_host_view->Focus();
1675 } else {
[email protected]cfd80b02014-05-01 17:46:481676 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491677 }
[email protected]89054502012-06-03 10:29:241678
1679 RenderWidgetHostImpl* render_widget_host_impl =
1680 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1681 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311682 // Only allow privileged mouse lock for fullscreen render widget, which is
1683 // used to implement Pepper Flash fullscreen.
1684 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501685
1686#if defined(OS_MACOSX)
1687 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1688 // properly embedded (or purposefully ignored) we can release the retain we
1689 // took in CreateNewWidget().
1690 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1691#endif
1692}
1693
1694WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1695 PendingContents::iterator iter = pending_contents_.find(route_id);
1696
1697 // Certain systems can block the creation of new windows. If we didn't succeed
1698 // in creating one, just return NULL.
1699 if (iter == pending_contents_.end()) {
1700 return NULL;
1701 }
1702
1703 WebContentsImpl* new_contents = iter->second;
1704 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101705 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501706
[email protected]d70bea92013-04-05 04:23:341707 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251708 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341709 return new_contents;
1710
[email protected]bafe6cd2012-05-23 23:09:501711 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1712 !new_contents->GetRenderViewHost()->GetView())
1713 return NULL;
1714
1715 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1716 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1717 return new_contents;
1718}
1719
1720RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1721 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1722 if (iter == pending_widget_views_.end()) {
1723 DCHECK(false);
1724 return NULL;
1725 }
1726
1727 RenderWidgetHostView* widget_host_view = iter->second;
1728 pending_widget_views_.erase(route_id);
1729
1730 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1731 if (!widget_host->GetProcess()->HasConnection()) {
1732 // The view has gone away or the renderer crashed. Nothing to do.
1733 return NULL;
1734 }
1735
1736 return widget_host_view;
1737}
1738
[email protected]f13b4202012-06-12 23:53:231739void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091740 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211741 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371742 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231743 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371744 } else {
1745 callback.Run(MediaStreamDevices(),
1746 MEDIA_DEVICE_INVALID_STATE,
1747 scoped_ptr<MediaStreamUI>());
1748 }
[email protected]f13b4202012-06-12 23:53:231749}
1750
[email protected]cc9200432013-07-23 23:02:401751SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1752 SiteInstance* instance) {
1753 return controller_.GetSessionStorageNamespace(instance);
1754}
1755
[email protected]6de7fc482014-06-06 10:46:441756SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1757 return controller_.GetSessionStorageNamespaceMap();
1758}
1759
[email protected]9b159a52013-10-03 17:24:551760FrameTree* WebContentsImpl::GetFrameTree() {
1761 return &frame_tree_;
1762}
1763
[email protected]95640212014-07-26 18:14:301764AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1765 return accessibility_mode_;
1766}
1767
[email protected]31a71eaf2014-03-13 01:47:361768void WebContentsImpl::AccessibilityEventReceived(
1769 const std::vector<AXEventNotificationDetails>& details) {
1770 FOR_EACH_OBSERVER(
1771 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1772}
1773
[email protected]edc3af82013-12-12 21:24:071774void WebContentsImpl::OnShowValidationMessage(
1775 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291776 const base::string16& main_text,
1777 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071778 if (delegate_)
1779 delegate_->ShowValidationMessage(
1780 this, anchor_in_root_view, main_text, sub_text);
1781}
1782
1783void WebContentsImpl::OnHideValidationMessage() {
1784 if (delegate_)
1785 delegate_->HideValidationMessage(this);
1786}
1787
1788void WebContentsImpl::OnMoveValidationMessage(
1789 const gfx::Rect& anchor_in_root_view) {
1790 if (delegate_)
1791 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1792}
1793
[email protected]32deec62013-05-15 23:55:041794void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1795 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441796 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041797}
1798
[email protected]e85165c642014-06-10 14:34:311799void WebContentsImpl::OnTouchEmulationEnabled(bool enabled) {
1800 touch_emulation_enabled_ = enabled;
1801 if (view_)
1802 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
1803}
1804
[email protected]95640212014-07-26 18:14:301805BrowserAccessibilityManager*
1806 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1807 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1808 return rfh ? rfh->browser_accessibility_manager() : NULL;
1809}
1810
1811BrowserAccessibilityManager*
1812 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1813 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1814 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1815}
1816
[email protected]b172aee2012-04-10 17:05:261817void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491818 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231819 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491820 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331821}
1822
[email protected]b172aee2012-04-10 17:05:261823void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341824 if (delegate_)
1825 delegate_->ResizeDueToAutoResize(this, new_size);
1826}
1827
[email protected]b172aee2012-04-10 17:05:261828WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201829 if (!delegate_)
1830 return NULL;
[email protected]00c37fc2011-08-02 00:22:501831
[email protected]e5d549d2011-12-28 01:29:201832 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201833 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341834}
1835
[email protected]6b618e62012-08-16 12:59:181836bool WebContentsImpl::Send(IPC::Message* message) {
1837 if (!GetRenderViewHost()) {
1838 delete message;
1839 return false;
1840 }
1841
1842 return GetRenderViewHost()->Send(message);
1843}
1844
[email protected]b172aee2012-04-10 17:05:261845bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501846 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261847 FrameTreeNode* node = frame_tree_.root();
1848
1849 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1850 // specified in the pending entry.
1851 NavigationEntryImpl* pending_entry =
1852 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1853 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1854 pending_entry->frame_tree_node_id() != -1) {
1855 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1856 }
1857
1858 return node->navigator()->NavigateToPendingEntry(
1859 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541860}
[email protected]96d185d2009-04-24 03:28:541861
[email protected]a86c0e962013-12-17 17:10:391862void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1863 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441864 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391865 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441866}
1867
[email protected]20ca0382013-02-28 19:50:071868void WebContentsImpl::AttachInterstitialPage(
1869 InterstitialPageImpl* interstitial_page) {
1870 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211871 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291872
1873 // Cancel any visible dialogs so that they don't interfere with the
1874 // interstitial.
1875 if (dialog_manager_)
1876 dialog_manager_->CancelActiveAndPendingDialogs(this);
1877
[email protected]20ca0382013-02-28 19:50:071878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1879 DidAttachInterstitialPage());
1880}
1881
1882void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571883 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211884 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1886 DidDetachInterstitialPage());
1887}
1888
[email protected]b172aee2012-04-10 17:05:261889void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331890 const SiteInstance* site_instance,
1891 int history_length,
1892 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411893 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1894 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211895 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191896 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141897 return;
[email protected]9e1ad4b2011-08-14 16:49:191898 }
[email protected]9f76c1e2012-03-05 15:15:581899 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191900 if (!rvh) {
1901 NOTREACHED();
1902 return;
1903 }
[email protected]9f76c1e2012-03-05 15:15:581904 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191905 NOTREACHED();
1906 return;
1907 }
[email protected]6b618e62012-08-16 12:59:181908 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1909 history_length,
1910 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141911}
1912
[email protected]4fed3702014-04-01 09:08:001913void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171914 RenderFrameHost* focused_frame = GetFocusedFrame();
1915 if (!focused_frame)
1916 return;
1917
[email protected]959be4c2014-04-08 15:01:331918 focused_frame->Send(new FrameMsg_Reload(
1919 focused_frame->GetRoutingID(), ignore_cache));
1920}
1921
1922void WebContentsImpl::Undo() {
1923 RenderFrameHost* focused_frame = GetFocusedFrame();
1924 if (!focused_frame)
1925 return;
1926
1927 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1928 RecordAction(base::UserMetricsAction("Undo"));
1929}
1930
1931void WebContentsImpl::Redo() {
1932 RenderFrameHost* focused_frame = GetFocusedFrame();
1933 if (!focused_frame)
1934 return;
1935 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1936 RecordAction(base::UserMetricsAction("Redo"));
1937}
1938
1939void WebContentsImpl::Cut() {
1940 RenderFrameHost* focused_frame = GetFocusedFrame();
1941 if (!focused_frame)
1942 return;
1943
1944 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1945 RecordAction(base::UserMetricsAction("Cut"));
1946}
1947
1948void WebContentsImpl::Copy() {
1949 RenderFrameHost* focused_frame = GetFocusedFrame();
1950 if (!focused_frame)
1951 return;
1952
1953 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1954 RecordAction(base::UserMetricsAction("Copy"));
1955}
1956
1957void WebContentsImpl::CopyToFindPboard() {
1958#if defined(OS_MACOSX)
1959 RenderFrameHost* focused_frame = GetFocusedFrame();
1960 if (!focused_frame)
1961 return;
1962
1963 // Windows/Linux don't have the concept of a find pasteboard.
1964 focused_frame->Send(
1965 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1966 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1967#endif
1968}
1969
1970void WebContentsImpl::Paste() {
1971 RenderFrameHost* focused_frame = GetFocusedFrame();
1972 if (!focused_frame)
1973 return;
1974
1975 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1976 RecordAction(base::UserMetricsAction("Paste"));
1977}
1978
1979void WebContentsImpl::PasteAndMatchStyle() {
1980 RenderFrameHost* focused_frame = GetFocusedFrame();
1981 if (!focused_frame)
1982 return;
1983
1984 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1985 focused_frame->GetRoutingID()));
1986 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1987}
1988
1989void WebContentsImpl::Delete() {
1990 RenderFrameHost* focused_frame = GetFocusedFrame();
1991 if (!focused_frame)
1992 return;
1993
1994 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1995 RecordAction(base::UserMetricsAction("DeleteSelection"));
1996}
1997
1998void WebContentsImpl::SelectAll() {
1999 RenderFrameHost* focused_frame = GetFocusedFrame();
2000 if (!focused_frame)
2001 return;
2002
2003 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2004 RecordAction(base::UserMetricsAction("SelectAll"));
2005}
2006
2007void WebContentsImpl::Unselect() {
2008 RenderFrameHost* focused_frame = GetFocusedFrame();
2009 if (!focused_frame)
2010 return;
2011
2012 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2013 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172014}
2015
2016void WebContentsImpl::Replace(const base::string16& word) {
2017 RenderFrameHost* focused_frame = GetFocusedFrame();
2018 if (!focused_frame)
2019 return;
2020
[email protected]959be4c2014-04-08 15:01:332021 focused_frame->Send(new InputMsg_Replace(
2022 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172023}
2024
2025void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2026 RenderFrameHost* focused_frame = GetFocusedFrame();
2027 if (!focused_frame)
2028 return;
2029
[email protected]959be4c2014-04-08 15:01:332030 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2031 focused_frame->GetRoutingID(), word));
2032}
2033
2034void WebContentsImpl::NotifyContextMenuClosed(
2035 const CustomContextMenuContext& context) {
2036 RenderFrameHost* focused_frame = GetFocusedFrame();
2037 if (!focused_frame)
2038 return;
2039
2040 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2041 focused_frame->GetRoutingID(), context));
2042}
2043
2044void WebContentsImpl::ExecuteCustomContextMenuCommand(
2045 int action, const CustomContextMenuContext& context) {
2046 RenderFrameHost* focused_frame = GetFocusedFrame();
2047 if (!focused_frame)
2048 return;
2049
2050 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2051 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002052}
2053
[email protected]fc2b46b2014-05-03 16:33:452054gfx::NativeView WebContentsImpl::GetNativeView() {
2055 return view_->GetNativeView();
2056}
2057
2058gfx::NativeView WebContentsImpl::GetContentNativeView() {
2059 return view_->GetContentNativeView();
2060}
2061
2062gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2063 return view_->GetTopLevelNativeWindow();
2064}
2065
2066gfx::Rect WebContentsImpl::GetViewBounds() {
2067 return view_->GetViewBounds();
2068}
2069
2070gfx::Rect WebContentsImpl::GetContainerBounds() {
2071 gfx::Rect rv;
2072 view_->GetContainerBounds(&rv);
2073 return rv;
2074}
2075
2076DropData* WebContentsImpl::GetDropData() {
2077 return view_->GetDropData();
2078}
2079
2080void WebContentsImpl::Focus() {
[email protected]0b431992014-06-24 00:08:032081 RenderWidgetHostView* const fullscreen_view =
2082 GetFullscreenRenderWidgetHostView();
2083 if (fullscreen_view)
2084 fullscreen_view->Focus();
2085 else
2086 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452087}
2088
2089void WebContentsImpl::SetInitialFocus() {
[email protected]0b431992014-06-24 00:08:032090 RenderWidgetHostView* const fullscreen_view =
2091 GetFullscreenRenderWidgetHostView();
2092 if (fullscreen_view)
2093 fullscreen_view->Focus();
2094 else
2095 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452096}
2097
2098void WebContentsImpl::StoreFocus() {
[email protected]0b431992014-06-24 00:08:032099 if (!GetFullscreenRenderWidgetHostView())
2100 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452101}
2102
2103void WebContentsImpl::RestoreFocus() {
[email protected]0b431992014-06-24 00:08:032104 RenderWidgetHostView* const fullscreen_view =
2105 GetFullscreenRenderWidgetHostView();
2106 if (fullscreen_view)
2107 fullscreen_view->Focus();
2108 else
2109 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452110}
2111
[email protected]b172aee2012-04-10 17:05:262112void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272113 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212114 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542115 return;
2116 }
[email protected]0b431992014-06-24 00:08:032117 RenderWidgetHostView* const fullscreen_view =
2118 GetFullscreenRenderWidgetHostView();
2119 if (fullscreen_view) {
2120 fullscreen_view->Focus();
2121 return;
2122 }
[email protected]9f76c1e2012-03-05 15:15:582123 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542124}
2125
[email protected]b172aee2012-04-10 17:05:262126bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212127 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542128}
2129
[email protected]b172aee2012-04-10 17:05:262130InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212131 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222132}
2133
[email protected]b172aee2012-04-10 17:05:262134bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162135 // WebKit creates Document object when MIME type is application/xhtml+xml,
2136 // so we also support this MIME type.
2137 return contents_mime_type_ == "text/html" ||
2138 contents_mime_type_ == "text/xml" ||
2139 contents_mime_type_ == "application/xhtml+xml" ||
2140 contents_mime_type_ == "text/plain" ||
2141 contents_mime_type_ == "text/css" ||
2142 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2143}
2144
[email protected]b172aee2012-04-10 17:05:262145void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592146 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162147 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552148 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012149 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142150 return;
[email protected]c7dd2f62011-07-18 15:57:592151 }
2152
2153 Stop();
2154
2155 // Create the save package and possibly prompt the user for the name to save
2156 // the page as. The user prompt is an asynchronous operation that runs on
2157 // another thread.
2158 save_package_ = new SavePackage(this);
2159 save_package_->GetSaveInfo();
2160}
2161
2162// Used in automated testing to bypass prompting the user for file names.
2163// Instead, the names and paths are hard coded rather than running them through
2164// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342165bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2166 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212167 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592168 // Stop the page from navigating.
2169 Stop();
2170
2171 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212172 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592173}
2174
[email protected]3c71576ce2013-07-23 02:00:012175void WebContentsImpl::SaveFrame(const GURL& url,
2176 const Referrer& referrer) {
2177 if (!GetURL().is_valid())
2178 return;
2179 bool is_main_frame = (url == GetURL());
2180
2181 DownloadManager* dlm =
2182 BrowserContext::GetDownloadManager(GetBrowserContext());
2183 if (!dlm)
2184 return;
2185 int64 post_id = -1;
2186 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272187 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012188 if (entry)
2189 post_id = entry->GetPostID();
2190 }
2191 scoped_ptr<DownloadUrlParameters> params(
2192 DownloadUrlParameters::FromWebContents(this, url));
2193 params->set_referrer(referrer);
2194 params->set_post_id(post_id);
2195 params->set_prefer_cache(true);
2196 if (post_id >= 0)
2197 params->set_method("POST");
2198 params->set_prompt(true);
2199 dlm->DownloadUrl(params.Pass());
2200}
2201
[email protected]b172aee2012-04-10 17:05:262202void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342203 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482204 const base::Callback<void(int64)>& callback) {
2205 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122206}
2207
[email protected]b172aee2012-04-10 17:05:262208const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272209 return contents_mime_type_;
2210}
2211
[email protected]b172aee2012-04-10 17:05:262212bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272213 return notify_disconnection_;
2214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312217 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182218 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162219}
2220
[email protected]b172aee2012-04-10 17:05:262221void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542222 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182223 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162224}
2225
[email protected]8ff00d72012-10-23 19:12:212226RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272227 return &renderer_preferences_;
2228}
2229
[email protected]e35ccd52012-05-23 16:22:472230void WebContentsImpl::Close() {
2231 Close(GetRenderViewHost());
2232}
2233
[email protected]cf200a562013-05-03 16:24:292234void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462235 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292236 if (browser_plugin_embedder_.get())
2237 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2238 screen_x, screen_y, operation);
2239 if (GetRenderViewHost())
2240 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2241 screen_x, screen_y, operation);
2242}
2243
[email protected]d60f3702013-12-26 16:30:242244void WebContentsImpl::DidGetResourceResponseStart(
2245 const ResourceRequestDetails& details) {
2246 controller_.ssl_manager()->DidStartResourceResponse(details);
2247
2248 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2249 DidGetResourceResponseStart(details));
2250
2251 // TODO(avi): Remove. http://crbug.com/170921
2252 NotificationService::current()->Notify(
2253 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2254 Source<WebContents>(this),
2255 Details<const ResourceRequestDetails>(&details));
2256}
2257
2258void WebContentsImpl::DidGetRedirectForResourceRequest(
2259 RenderViewHost* render_view_host,
2260 const ResourceRedirectDetails& details) {
2261 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2262
2263 FOR_EACH_OBSERVER(
2264 WebContentsObserver,
2265 observers_,
2266 DidGetRedirectForResourceRequest(render_view_host, details));
2267
2268 // TODO(avi): Remove. http://crbug.com/170921
2269 NotificationService::current()->Notify(
2270 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2271 Source<WebContents>(this),
2272 Details<const ResourceRedirectDetails>(&details));
2273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522276 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582277 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512278 if (delegate_)
2279 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292280 if (browser_plugin_embedder_.get())
2281 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342282}
2283
[email protected]e35ccd52012-05-23 16:22:472284void WebContentsImpl::UserGestureDone() {
2285 OnUserGesture();
2286}
2287
[email protected]b172aee2012-04-10 17:05:262288void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272289 closed_by_user_gesture_ = value;
2290}
2291
[email protected]b172aee2012-04-10 17:05:262292bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272293 return closed_by_user_gesture_;
2294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502297 if (!delegate_)
2298 return;
2299
[email protected]6286a372013-10-09 04:03:272300 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2301 if (!entry)
[email protected]1788e772010-12-15 16:40:502302 return;
2303
[email protected]6286a372013-10-09 04:03:272304 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122305}
2306
[email protected]b172aee2012-04-10 17:05:262307void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042308 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272309 if (!delegate_)
2310 return;
2311
[email protected]691aa2f2013-05-28 22:52:042312 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272313}
2314
[email protected]b172aee2012-04-10 17:05:262315int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272316 return minimum_zoom_percent_;
2317}
2318
[email protected]b172aee2012-04-10 17:05:262319int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272320 return maximum_zoom_percent_;
2321}
2322
[email protected]b172aee2012-04-10 17:05:262323gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492324 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232325}
2326
[email protected]b172aee2012-04-10 17:05:262327bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052328 if (GetBrowserPluginGuest())
2329 return GetBrowserPluginGuest()->LockMouse(allowed);
2330
[email protected]0bfbf882011-12-22 18:19:272331 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582332 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272333}
2334
[email protected]b172aee2012-04-10 17:05:262335bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442336 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502337}
2338
[email protected]cb805452013-05-22 15:16:212339void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482340 if (!color_chooser_info_.get())
2341 return;
2342 RenderFrameHost* rfh = RenderFrameHost::FromID(
2343 color_chooser_info_->render_process_id,
2344 color_chooser_info_->render_frame_id);
2345 if (!rfh)
2346 return;
2347
2348 rfh->Send(new FrameMsg_DidChooseColorResponse(
2349 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202350}
2351
[email protected]cb805452013-05-22 15:16:212352void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482353 if (!color_chooser_info_.get())
2354 return;
2355 RenderFrameHost* rfh = RenderFrameHost::FromID(
2356 color_chooser_info_->render_process_id,
2357 color_chooser_info_->render_frame_id);
2358 if (!rfh)
2359 return;
2360
2361 rfh->Send(new FrameMsg_DidEndColorChooser(
2362 rfh->GetRoutingID(), color_chooser_info_->identifier));
2363 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202364}
2365
[email protected]41225fe2013-03-29 05:32:022366int WebContentsImpl::DownloadImage(const GURL& url,
2367 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302368 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022369 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582370 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022371 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392372 return id;
2373}
2374
[email protected]5dcaf8e2013-12-28 01:31:422375bool WebContentsImpl::IsSubframe() const {
2376 return is_subframe_;
2377}
2378
[email protected]36ec24f2014-01-09 00:32:082379void WebContentsImpl::Find(int request_id,
2380 const base::string16& search_text,
2381 const blink::WebFindOptions& options) {
2382 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2383}
2384
2385void WebContentsImpl::StopFinding(StopFindAction action) {
2386 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2387}
2388
[email protected]4fe53add2014-04-08 19:53:362389void WebContentsImpl::InsertCSS(const std::string& css) {
2390 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2391 GetMainFrame()->GetRoutingID(), css));
2392}
2393
[email protected]b172aee2012-04-10 17:05:262394bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272395 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172396 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332397 return true;
2398 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272399}
2400
[email protected]b172aee2012-04-10 17:05:262401void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272402 if (delegate_)
2403 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212404}
2405
[email protected]52913802013-12-10 05:52:182406void WebContentsImpl::DidStartProvisionalLoad(
2407 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182408 const GURL& validated_url,
2409 bool is_error_page,
2410 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102411 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482412 FOR_EACH_OBSERVER(
2413 WebContentsObserver,
2414 observers_,
2415 DidStartProvisionalLoadForFrame(
2416 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542417
[email protected]e2d2d4202014-07-03 12:17:482418 if (!render_frame_host->GetParent()) {
[email protected]52913802013-12-10 05:52:182419 FOR_EACH_OBSERVER(
2420 WebContentsObserver,
2421 observers_,
2422 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582423 render_frame_host));
[email protected]400992b2012-06-14 00:03:542424 }
2425}
2426
[email protected]0c3c54f2014-07-31 01:29:002427void WebContentsImpl::DidStartNavigationTransition(
2428 RenderFrameHostImpl* render_frame_host) {
2429#if defined(OS_ANDROID)
2430 int render_frame_id = render_frame_host->GetRoutingID();
2431 ContentViewCoreImpl::FromWebContents(this)->
2432 DidStartNavigationTransitionForFrame(render_frame_id);
2433#endif
2434}
2435
[email protected]3109fbb72014-01-06 23:57:152436void WebContentsImpl::DidFailProvisionalLoadWithError(
2437 RenderFrameHostImpl* render_frame_host,
2438 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2439 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312440 FOR_EACH_OBSERVER(WebContentsObserver,
2441 observers_,
2442 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312443 validated_url,
2444 params.error_code,
2445 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152446}
2447
[email protected]b80624c2014-02-09 02:46:552448void WebContentsImpl::DidFailLoadWithError(
2449 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552450 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552451 int error_code,
2452 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142453 FOR_EACH_OBSERVER(
2454 WebContentsObserver,
2455 observers_,
2456 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552457}
2458
[email protected]52913802013-12-10 05:52:182459void WebContentsImpl::NotifyChangedNavigationState(
2460 InvalidateTypes changed_flags) {
2461 NotifyNavigationStateChanged(changed_flags);
2462}
2463
[email protected]3691e5cf2014-01-22 10:16:202464void WebContentsImpl::AboutToNavigateRenderFrame(
2465 RenderFrameHostImpl* render_frame_host) {
2466 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272467 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202468 FOR_EACH_OBSERVER(
2469 WebContentsObserver,
2470 observers_,
[email protected]161eabd2014-03-19 19:47:272471 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202472}
2473
2474void WebContentsImpl::DidStartNavigationToPendingEntry(
2475 RenderFrameHostImpl* render_frame_host,
2476 const GURL& url,
2477 NavigationController::ReloadType reload_type) {
2478 // Notify observers about navigation.
2479 FOR_EACH_OBSERVER(
2480 WebContentsObserver,
2481 observers_,
2482 DidStartNavigationToPendingEntry(url, reload_type));
2483}
2484
[email protected]8cb834e2014-03-06 14:23:232485void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2486 const OpenURLParams& params) {
2487 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182488 WebContents* new_contents = OpenURL(params);
2489
2490 if (new_contents) {
2491 // Notify observers.
2492 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2493 DidOpenRequestedURL(new_contents,
2494 params.url,
2495 params.referrer,
2496 params.disposition,
2497 params.transition,
[email protected]8cb834e2014-03-06 14:23:232498 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182499 }
2500}
2501
[email protected]aa62afd2014-04-22 19:22:462502bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2503 if (!delegate_)
2504 return false;
2505 return delegate_->ShouldPreserveAbortedURLs(this);
2506}
2507
[email protected]400992b2012-06-14 00:03:542508void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582509 RenderFrameHostImpl* render_frame_host,
2510 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542511 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582512 FOR_EACH_OBSERVER(
2513 WebContentsObserver,
2514 observers_,
2515 ProvisionalChangeToMainFrameUrl(validated_target_url,
2516 render_frame_host));
[email protected]724159a2010-12-30 01:11:182517}
2518
[email protected]37567b432014-02-12 01:12:222519void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432520 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222521 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432522 PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222523 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482524 FOR_EACH_OBSERVER(WebContentsObserver,
2525 observers_,
2526 DidCommitProvisionalLoadForFrame(
2527 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222528}
2529
[email protected]0d0f4c492014-04-02 06:42:572530void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232531 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572532 // Ensure fullscreen mode is exited before committing the navigation to a
2533 // different page. The next page will not start out assuming it is in
2534 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232535 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192536 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572537 return;
2538 }
2539 if (IsFullscreenForCurrentTab())
2540 GetRenderViewHost()->ExitFullscreen();
2541 DCHECK(!IsFullscreenForCurrentTab());
2542}
2543
[email protected]37567b432014-02-12 01:12:222544void WebContentsImpl::DidNavigateMainFramePostCommit(
2545 const LoadCommittedDetails& details,
2546 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2547 if (details.is_navigation_to_different_page()) {
2548 // Clear the status bubble. This is a workaround for a bug where WebKit
2549 // doesn't let us know that the cursor left an element during a
2550 // transition (this is also why the mouse cursor remains as a hand after
2551 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2552 // clear the bubble when a user navigates to a named anchor in the same
2553 // page.
2554 UpdateTargetURL(details.entry->GetPageID(), GURL());
2555 }
2556
2557 if (!details.is_in_page) {
2558 // Once the main frame is navigated, we're no longer considered to have
2559 // displayed insecure content.
2560 displayed_insecure_content_ = false;
2561 SSLManager::NotifySSLInternalStateChanged(
2562 GetController().GetBrowserContext());
2563 }
2564
2565 // Notify observers about navigation.
2566 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2567 DidNavigateMainFrame(details, params));
2568
[email protected]e85165c642014-06-10 14:34:312569 if (delegate_)
[email protected]37567b432014-02-12 01:12:222570 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312571 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222572}
2573
2574void WebContentsImpl::DidNavigateAnyFramePostCommit(
2575 RenderFrameHostImpl* render_frame_host,
2576 const LoadCommittedDetails& details,
2577 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102578 // Now that something has committed, we don't need to track whether the
2579 // initial page has been accessed.
2580 has_accessed_initial_document_ = false;
2581
[email protected]37567b432014-02-12 01:12:222582 // If we navigate off the page, close all JavaScript dialogs.
2583 if (dialog_manager_ && !details.is_in_page)
2584 dialog_manager_->CancelActiveAndPendingDialogs(this);
2585
2586 // Notify observers about navigation.
2587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2588 DidNavigateAnyFrame(details, params));
2589}
2590
2591void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2592 contents_mime_type_ = mime_type;
2593}
2594
[email protected]277857a2014-06-03 10:38:012595bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312596 // Disable overscroll when touch emulation is on. See crbug.com/369938.
2597 if (touch_emulation_enabled_)
2598 return false;
2599
[email protected]37567b432014-02-12 01:12:222600 if (delegate_)
2601 return delegate_->CanOverscrollContent();
2602
2603 return false;
2604}
2605
[email protected]37b64c52014-07-11 21:14:052606void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052608 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252609}
2610
[email protected]b172aee2012-04-10 17:05:262611void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182612 const GURL& url,
[email protected]70435962011-08-02 20:13:282613 const std::string& security_info,
2614 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182615 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402616 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192617 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182618 cache.Increment();
2619
2620 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082621 int cert_id = 0;
2622 net::CertStatus cert_status = 0;
2623 int security_bits = -1;
2624 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122625 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212626 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122627 &security_bits, &connection_status,
2628 &signed_certificate_timestamp_ids);
2629 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212630 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002631 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2632 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182633
[email protected]b0f724c2013-09-05 04:21:132634 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2635
2636 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2637 DidLoadResourceFromMemoryCache(details));
2638
[email protected]8bfc8272013-09-09 20:10:532639 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2640 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402641 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532642 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2643 GetRenderProcessHost()->GetID()) :
2644 GetBrowserContext()->GetRequestContextForRenderProcess(
2645 GetRenderProcessHost()->GetID()));
2646 BrowserThread::PostTask(
2647 BrowserThread::IO,
2648 FROM_HERE,
2649 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2650 }
[email protected]724159a2010-12-30 01:11:182651}
2652
[email protected]b172aee2012-04-10 17:05:262653void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392654 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182655 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192656 SSLManager::NotifySSLInternalStateChanged(
2657 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182658}
2659
[email protected]b172aee2012-04-10 17:05:262660void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022661 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582662 LOG(WARNING) << security_origin << " ran insecure content from "
2663 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392664 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412665 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392666 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182667 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412668 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192669 SSLManager::NotifySSLInternalStateChanged(
2670 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182671}
2672
[email protected]501052ff2014-02-21 22:19:072673void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572674 CHECK(render_frame_message_source_);
2675 CHECK(!render_view_message_source_);
2676 RenderFrameHostImpl* rfh =
2677 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142678 FOR_EACH_OBSERVER(
2679 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182680}
2681
[email protected]b172aee2012-04-10 17:05:262682void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262683 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372684 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122685 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2686 GetRenderProcessHost()->ReceivedBadMessage();
2687 return;
2688 }
[email protected]a1b99262013-12-27 21:56:222689
[email protected]8b3af1e2014-01-24 13:29:122690 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442691 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372692 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422693 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372694
[email protected]61ac9e242014-03-21 20:55:262695 RenderFrameHostImpl* rfh =
2696 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142697 FOR_EACH_OBSERVER(
2698 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312699}
2700
[email protected]960b0372014-05-19 18:01:002701void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2702 RenderFrameHostImpl* rfh =
2703 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2704 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2705
2706 // It is possible to get multiple calls to OnDidStartLoading that don't have
2707 // corresponding calls to OnDidStopLoading:
2708 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2709 // out for a cross-process navigation, and it turns into a placeholder for
2710 // one being rendered in a different process.
2711 // - Also, there might be more than one RenderFrameHost sharing the same
2712 // FrameTreeNode (and thus sharing its ID) each sending a start.
2713 // - But in the future, once clamy@ moves navigation network requests to the
2714 // browser process, there's a good chance that callbacks about starting and
2715 // stopping will all be handled by the browser. When that happens, there
2716 // should no longer be a start/stop call imbalance. TODO(avi): When this
2717 // future arrives, update this code to not allow this case.
2718 DCHECK_GE(loading_frames_in_progress_, 0);
2719 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2720 if (loading_frames_in_progress_ == 0)
2721 DidStartLoading(rfh, to_different_document);
2722 ++loading_frames_in_progress_;
2723 }
2724
2725 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2726 SendLoadProgressChanged();
2727}
2728
2729void WebContentsImpl::OnDidStopLoading() {
2730 RenderFrameHostImpl* rfh =
2731 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2732 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2733
2734 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2735 // Load stopped while we were still tracking load. Make sure we update
2736 // progress based on this frame's completion.
2737 loading_progresses_[render_frame_id] = 1.0;
2738 SendLoadProgressChanged();
2739 // Then we clean-up our states.
2740 if (loading_total_progress_ == 1.0)
2741 ResetLoadProgressState();
2742 }
2743
2744 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2745 // calls DidStopLoading() without a matching DidStartLoading().
2746 if (loading_frames_in_progress_ == 0)
2747 return;
2748 --loading_frames_in_progress_;
2749 if (loading_frames_in_progress_ == 0)
2750 DidStopLoading(rfh);
2751}
2752
2753void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
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 loading_progresses_[render_frame_id] = load_progress;
2759
2760 // We notify progress change immediately for the first and last updates.
2761 // Also, since the message loop may be pretty busy when a page is loaded, it
2762 // might not execute a posted task in a timely manner so we make sure to
2763 // immediately send progress report if enough time has passed.
2764 base::TimeDelta min_delay =
2765 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2766 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2767 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2768 // If there is a pending task to send progress, it is now obsolete.
2769 loading_weak_factory_.InvalidateWeakPtrs();
2770 SendLoadProgressChanged();
2771 if (loading_total_progress_ == 1.0)
2772 ResetLoadProgressState();
2773 return;
2774 }
2775
2776 if (loading_weak_factory_.HasWeakPtrs())
2777 return;
2778
2779 base::MessageLoop::current()->PostDelayedTask(
2780 FROM_HERE,
2781 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2782 loading_weak_factory_.GetWeakPtr()),
2783 min_delay);
2784}
2785
[email protected]b172aee2012-04-10 17:05:262786void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222787 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2788 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262789}
2790
[email protected]b172aee2012-04-10 17:05:262791void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302792 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262793 minimum_zoom_percent_ = minimum_percent;
2794 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262795}
2796
[email protected]b172aee2012-04-10 17:05:262797void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342798 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432799 if (!delegate_)
2800 return;
2801
[email protected]b9535422012-02-09 01:47:592802 ChildProcessSecurityPolicyImpl* policy =
2803 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222804 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592805 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212806}
2807
[email protected]b172aee2012-04-10 17:05:262808void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2809 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262810 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362811 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432812 if (!delegate_)
2813 return;
2814
[email protected]b9535422012-02-09 01:47:592815 ChildProcessSecurityPolicyImpl* policy =
2816 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322817 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592818 return;
[email protected]8f810632013-06-06 22:33:322819
[email protected]c125e532014-05-10 20:39:062820 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202821}
2822
[email protected]f5273e52014-07-14 16:30:202823void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2824 const GURL& url,
2825 bool user_gesture) {
2826 if (!delegate_)
2827 return;
2828
2829 ChildProcessSecurityPolicyImpl* policy =
2830 ChildProcessSecurityPolicyImpl::GetInstance();
2831 if (policy->IsPseudoScheme(protocol))
2832 return;
2833
2834 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::OnFindReply(int request_id,
2838 int number_of_matches,
2839 const gfx::Rect& selection_rect,
2840 int active_match_ordinal,
2841 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432842 if (delegate_) {
2843 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2844 active_match_ordinal, final_update);
2845 }
[email protected]b888919c2011-09-02 00:32:162846}
2847
[email protected]59363fc92012-09-05 03:46:312848#if defined(OS_ANDROID)
2849void WebContentsImpl::OnFindMatchRectsReply(
2850 int version,
2851 const std::vector<gfx::RectF>& rects,
2852 const gfx::RectF& active_rect) {
2853 if (delegate_)
2854 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2855}
[email protected]583418cc2013-01-17 14:01:102856
[email protected]1ff427972013-02-07 21:14:072857void WebContentsImpl::OnOpenDateTimeDialog(
2858 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092859 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2860 GetRenderViewHost(),
2861 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132862 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092863 value.minimum,
2864 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172865 value.step,
2866 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102867}
2868
[email protected]59363fc92012-09-05 03:46:312869#endif
2870
[email protected]f114fa42013-12-06 17:06:442871void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2872 const base::FilePath& path,
2873 bool is_hung) {
2874 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2875
2876 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2877 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2878}
2879
2880void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422881 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442882 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422883 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452884}
2885
[email protected]cfa856d62014-02-22 07:58:402886void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2887 int automation_id) {
2888 DomOperationNotificationDetails details(json_string, automation_id);
2889 NotificationService::current()->Notify(
2890 NOTIFICATION_DOM_OPERATION_RESPONSE,
2891 Source<WebContents>(this),
2892 Details<DomOperationNotificationDetails>(&details));
2893}
2894
[email protected]b172aee2012-04-10 17:05:262895void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2896 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102897 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252898 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102899 AppCacheAccessed(manifest_url, blocked_by_policy));
2900}
2901
[email protected]8bc5ff02013-11-29 06:34:032902void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482903 int color_chooser_id,
2904 SkColor color,
2905 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462906 ColorChooser* new_color_chooser = delegate_ ?
2907 delegate_->OpenColorChooser(this, color, suggestions) :
2908 NULL;
[email protected]820957a2014-01-14 14:56:302909 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212910 return;
[email protected]8ed16472014-04-11 19:02:482911 if (color_chooser_info_.get())
2912 color_chooser_info_->chooser->End();
2913
2914 color_chooser_info_.reset(new ColorChooserInfo(
2915 render_frame_message_source_->GetProcess()->GetID(),
2916 render_frame_message_source_->GetRoutingID(),
2917 new_color_chooser,
2918 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202919}
2920
[email protected]b172aee2012-04-10 17:05:262921void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482922 if (color_chooser_info_ &&
2923 color_chooser_id == color_chooser_info_->identifier)
2924 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202925}
2926
[email protected]b172aee2012-04-10 17:05:262927void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322928 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482929 if (color_chooser_info_ &&
2930 color_chooser_id == color_chooser_info_->identifier)
2931 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202932}
2933
[email protected]d0759f492012-04-19 22:50:502934// This exists for render views that don't have a WebUI, but do have WebUI
2935// bindings enabled.
2936void WebContentsImpl::OnWebUISend(const GURL& source_url,
2937 const std::string& name,
2938 const base::ListValue& args) {
2939 if (delegate_)
2940 delegate_->WebUISend(this, source_url, name, args);
2941}
2942
[email protected]d8415ad92012-08-23 14:40:502943void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442944 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502945 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342946 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162947 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442948 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162949 return;
[email protected]d8415ad92012-08-23 14:40:502950 }
2951
[email protected]8c8fc292012-11-23 18:57:162952 if (!delegate_->RequestPpapiBrokerPermission(
2953 this, url, plugin_path,
2954 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442955 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162956 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442957 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162958 }
[email protected]d8415ad92012-08-23 14:40:502959}
2960
[email protected]ea0309c2013-08-06 19:35:442961void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502962 bool result) {
[email protected]ea0309c2013-08-06 19:35:442963 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502964}
2965
[email protected]c4538072013-03-18 02:17:552966void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372967 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082968 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552969 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392970 // For more info, see comment above classes BrowserPluginEmbedder and
2971 // BrowserPluginGuest.
2972 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142973 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082974 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372975}
2976
[email protected]41225fe2013-03-29 05:32:022977void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392978 int id,
[email protected]749fadd2013-05-15 08:37:482979 int http_status_code,
[email protected]795c28972012-12-06 06:13:392980 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302981 const std::vector<SkBitmap>& bitmaps,
2982 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132983 if (bitmaps.size() != original_bitmap_sizes.size())
2984 return;
2985
[email protected]41225fe2013-03-29 05:32:022986 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2987 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392988 // Currently WebContents notifies us of ANY downloads so that it is
2989 // possible to get here.
2990 return;
2991 }
2992 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302993 iter->second.Run(
2994 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392995 }
[email protected]41225fe2013-03-29 05:32:022996 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392997}
2998
2999void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393000 const std::vector<FaviconURL>& candidates) {
3001 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293002 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393003}
3004
[email protected]1dd0bb752014-02-01 01:16:263005void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3006 bool has_video,
3007 bool has_audio) {
[email protected]1dd0bb752014-02-01 01:16:263008#if !defined(OS_CHROMEOS)
3009 scoped_ptr<PowerSaveBlocker> blocker;
3010 if (has_video) {
3011 blocker = PowerSaveBlocker::Create(
3012 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
3013#if defined(OS_ANDROID)
3014 static_cast<PowerSaveBlockerImpl*>(blocker.get())
3015 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3016#endif
3017 } else if (has_audio) {
3018 blocker = PowerSaveBlocker::Create(
3019 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
3020 }
3021
3022 if (blocker) {
[email protected]c9e3b202014-08-08 08:24:423023 uintptr_t key = reinterpret_cast<uintptr_t>(render_frame_message_source_);
3024 if (!power_save_blockers_.contains(key)) {
3025 power_save_blockers_.add(key,
3026 make_scoped_ptr(new PowerSaveBlockerMapEntry));
3027 }
3028 PowerSaveBlockerMapEntry* map_entry =
3029 power_save_blockers_.get(key);
3030 map_entry->set(player_cookie, blocker.Pass());
[email protected]1dd0bb752014-02-01 01:16:263031 }
3032#endif // !defined(OS_CHROMEOS)
3033}
3034
3035void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:063036#if !defined(OS_CHROMEOS)
[email protected]c9e3b202014-08-08 08:24:423037 uintptr_t key = reinterpret_cast<uintptr_t>(render_frame_message_source_);
3038 PowerSaveBlockerMapEntry* map_entry = power_save_blockers_.get(key);
3039 if (map_entry)
3040 map_entry->erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:063041#endif // !defined(OS_CHROMEOS)
3042}
3043
[email protected]50279492014-05-05 23:24:293044void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153045 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293046 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153047}
[email protected]d9030b82013-07-19 08:26:063048
[email protected]e67ebf32013-02-13 11:07:193049void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073050 if (delegate_)
3051 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193052}
3053
[email protected]17e286e2013-03-01 23:29:393054void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3055 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3056 BeforeFormRepostWarningShow());
3057}
3058
[email protected]ec6c05f2013-10-23 18:41:573059
3060void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3061 Activate();
3062 if (delegate_)
3063 delegate_->ShowRepostFormWarningDialog(this);
3064}
3065
[email protected]b4c84012014-04-28 19:51:103066bool WebContentsImpl::HasAccessedInitialDocument() {
3067 return has_accessed_initial_document_;
3068}
3069
[email protected]96d185d2009-04-24 03:28:543070// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593071// loading, or done loading.
3072void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3073 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093074 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263075 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543076 if (is_loading == is_loading_)
3077 return;
3078
3079 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263080 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3081 base::string16());
[email protected]96d185d2009-04-24 03:28:543082 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563083 upload_size_ = 0;
3084 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543085 }
3086
[email protected]fa944cb82013-11-15 17:51:213087 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543088
3089 is_loading_ = is_loading;
3090 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033091 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543092
[email protected]6ebdc9b2010-09-27 16:55:573093 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093094 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213095 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543096
[email protected]eab61442013-11-14 18:35:483097 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593098 if (is_loading) {
[email protected]eab61442013-11-14 18:35:483099 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
3100 "URL", url);
[email protected]91621872013-10-08 04:04:593101 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3102 DidStartLoading(render_view_host));
3103 } else {
[email protected]eab61442013-11-14 18:35:483104 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
3105 "URL", url);
[email protected]91621872013-10-08 04:04:593106 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3107 DidStopLoading(render_view_host));
3108 }
[email protected]66798902013-10-01 18:40:163109
3110 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213111 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3112 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543113 if (details)
[email protected]8ff00d72012-10-23 19:12:213114 det = Details<LoadNotificationDetails>(details);
3115 NotificationService::current()->Notify(
3116 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543117}
3118
[email protected]959be4c2014-04-08 15:01:333119void WebContentsImpl::SelectRange(const gfx::Point& start,
3120 const gfx::Point& end) {
3121 RenderFrameHost* focused_frame = GetFocusedFrame();
3122 if (!focused_frame)
3123 return;
3124
3125 focused_frame->Send(
3126 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3127}
3128
[email protected]b172aee2012-04-10 17:05:263129void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463130 // If we are creating a RVH for a restored controller, then we need to make
3131 // sure the RenderView starts with a next_page_id_ larger than the number
3132 // of restored entries. This must be called before the RenderView starts
3133 // navigating (to avoid a race between the browser updating max_page_id and
3134 // the renderer updating next_page_id_). Because of this, we only call this
3135 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563136 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583137 if (max_restored_page_id >
3138 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3139 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3140 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323141}
3142
[email protected]b172aee2012-04-10 17:05:263143bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263144 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323145 // For file URLs without a title, use the pathname instead. In the case of a
3146 // synthesized title, we don't want the update to count toward the "one set
3147 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263148 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323149 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513150 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243151 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323152 explicit_set = false; // Don't count synthetic titles toward the set limit.
3153 } else {
[email protected]8af69c6c2014-03-03 19:05:313154 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323155 explicit_set = true;
3156 }
3157
[email protected]987fc3a2011-05-26 14:18:093158 // If a page is created via window.open and never navigated,
3159 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553160 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093161 if (entry) {
[email protected]36fc0392011-12-25 03:59:513162 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093163 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323164
[email protected]36fc0392011-12-25 03:59:513165 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093166 } else {
3167 if (page_title_when_no_navigation_entry_ == final_title)
3168 return false; // Nothing changed, don't bother.
3169
3170 page_title_when_no_navigation_entry_ = final_title;
3171 }
[email protected]420ae012009-04-24 05:16:323172
[email protected]420ae012009-04-24 05:16:323173 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233174 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323175
[email protected]66798902013-10-01 18:40:163176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533177 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163178
3179 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213180 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463181 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213182 NotificationService::current()->Notify(
3183 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3184 Source<WebContents>(this),
3185 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043186
[email protected]420ae012009-04-24 05:16:323187 return true;
3188}
3189
[email protected]960b0372014-05-19 18:01:003190void WebContentsImpl::SendLoadProgressChanged() {
3191 loading_last_progress_update_ = base::TimeTicks::Now();
3192 double progress = 0.0;
3193 int frame_count = 0;
3194
3195 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3196 it != loading_progresses_.end();
3197 ++it) {
3198 progress += it->second;
3199 ++frame_count;
3200 }
3201 if (frame_count == 0)
3202 return;
3203 progress /= frame_count;
3204 DCHECK(progress <= 1.0);
3205
3206 if (progress <= loading_total_progress_)
3207 return;
3208 loading_total_progress_ = progress;
3209
3210 if (delegate_)
3211 delegate_->LoadProgressChanged(this, progress);
3212}
3213
3214void WebContentsImpl::ResetLoadProgressState() {
3215 loading_progresses_.clear();
3216 loading_total_progress_ = 0.0;
3217 loading_weak_factory_.InvalidateWeakPtrs();
3218 loading_last_progress_update_ = base::TimeTicks();
3219}
3220
[email protected]02d7b6e2014-06-24 21:01:503221void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3222 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323223 // After sending out a swap notification, we need to send a disconnect
3224 // notification so that clients that pick up a pointer to |this| can NULL the
3225 // pointer. See Bug 1230284.
3226 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113227 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283228 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113229
3230 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283231 std::pair<RenderViewHost*, RenderViewHost*> details =
3232 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213233 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283234 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213235 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283236 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393237
3238 // Ensure that the associated embedder gets cleared after a RenderViewHost
3239 // gets swapped, so we don't reuse the same embedder next time a
3240 // RenderViewHost is attached to this WebContents.
3241 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323242}
3243
[email protected]02d7b6e2014-06-24 21:01:503244void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3245 RenderFrameHost* new_host) {
3246 FOR_EACH_OBSERVER(WebContentsObserver,
3247 observers_,
3248 RenderFrameHostChanged(old_host, new_host));
3249}
3250
[email protected]da7a7182013-09-06 08:11:113251// TODO(avi): Remove this entire function because this notification is already
3252// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263253void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323254 if (!notify_disconnection_)
3255 return;
3256
3257 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213258 NotificationService::current()->Notify(
3259 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3260 Source<WebContents>(this),
3261 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323262}
3263
[email protected]cbb1ef592013-06-05 19:49:463264void WebContentsImpl::NotifyNavigationEntryCommitted(
3265 const LoadCommittedDetails& load_details) {
3266 FOR_EACH_OBSERVER(
3267 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3268}
3269
[email protected]f114fa42013-12-06 17:06:443270bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3271 const IPC::Message& message) {
3272 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313273}
3274
[email protected]c31a84802014-04-03 15:55:493275const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3276 return GetLastCommittedURL();
3277}
3278
[email protected]b849847b2013-12-10 21:57:583279void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3280 // Note this is only for subframes, the notification for the main frame
3281 // happens in RenderViewCreated.
3282 FOR_EACH_OBSERVER(WebContentsObserver,
3283 observers_,
3284 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303285 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583286}
3287
3288void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193289 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583290 FOR_EACH_OBSERVER(WebContentsObserver,
3291 observers_,
3292 RenderFrameDeleted(render_frame_host));
3293}
3294
[email protected]a09d53ce2014-01-31 00:46:423295void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303296 if (delegate_)
3297 delegate_->WorkerCrashed(this);
3298}
3299
[email protected]a09d53ce2014-01-31 00:46:423300void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3301 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103302 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423303 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103304 if (GetBrowserPluginGuest()) {
3305 WebContentsViewGuest* view_guest =
3306 static_cast<WebContentsViewGuest*>(GetView());
3307 context_menu_params = view_guest->ConvertContextMenuParams(params);
3308 }
3309 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423310 return;
3311
[email protected]077e704b2014-05-23 19:24:103312 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3313 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423314}
3315
[email protected]87de04b02014-04-08 22:14:493316void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013317 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493318 const base::string16& message,
3319 const base::string16& default_prompt,
3320 const GURL& frame_url,
3321 JavaScriptMessageType javascript_message_type,
3322 IPC::Message* reply_msg) {
3323 // Suppress JavaScript dialogs when requested. Also suppress messages when
3324 // showing an interstitial as it's shown over the previous page and we don't
3325 // want the hidden page's dialogs to interfere with the interstitial.
3326 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013327 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493328 IsSwappedOut() ||
3329 ShowingInterstitialPage() ||
3330 !delegate_ ||
3331 delegate_->ShouldSuppressDialogs() ||
3332 !delegate_->GetJavaScriptDialogManager();
3333
3334 if (!suppress_this_message) {
3335 std::string accept_lang = GetContentClient()->browser()->
3336 GetAcceptLangs(GetBrowserContext());
3337 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3338 dialog_manager_->RunJavaScriptDialog(
3339 this,
3340 frame_url.GetOrigin(),
3341 accept_lang,
3342 javascript_message_type,
3343 message,
3344 default_prompt,
3345 base::Bind(&WebContentsImpl::OnDialogClosed,
3346 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013347 render_frame_host->GetProcess()->GetID(),
3348 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493349 reply_msg,
3350 false),
3351 &suppress_this_message);
3352 }
3353
3354 if (suppress_this_message) {
3355 // If we are suppressing messages, just reply as if the user immediately
3356 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013357 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3358 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283359 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493360 }
3361
3362 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3363 // http://crbug.com/288961 ). The only safe thing to do here is return.
3364}
3365
3366void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013367 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493368 const base::string16& message,
3369 bool is_reload,
3370 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013371 RenderFrameHostImpl* rfhi =
3372 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493373 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013374 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493375 if (delegate_)
3376 delegate_->WillRunBeforeUnloadConfirm();
3377
3378 bool suppress_this_message =
3379 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3380 !delegate_ ||
3381 delegate_->ShouldSuppressDialogs() ||
3382 !delegate_->GetJavaScriptDialogManager();
3383 if (suppress_this_message) {
3384 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3385 return;
3386 }
3387
3388 is_showing_before_unload_dialog_ = true;
3389 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3390 dialog_manager_->RunBeforeUnloadDialog(
3391 this, message, is_reload,
3392 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013393 render_frame_host->GetProcess()->GetID(),
3394 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283395 false));
[email protected]87de04b02014-04-08 22:14:493396}
3397
[email protected]a86c0e962013-12-17 17:10:393398WebContents* WebContentsImpl::GetAsWebContents() {
3399 return this;
3400}
3401
[email protected]7912e822014-04-16 02:37:033402bool WebContentsImpl::IsNeverVisible() {
3403 if (!delegate_)
3404 return false;
3405 return delegate_->IsNeverVisible(this);
3406}
3407
[email protected]95640212014-07-26 18:14:303408#if defined(OS_WIN)
3409gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3410 return accessible_parent_;
3411}
3412#endif
3413
[email protected]5a3bdf52012-05-24 15:12:573414RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3415 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323416}
3417
[email protected]8ff00d72012-10-23 19:12:213418RendererPreferences WebContentsImpl::GetRendererPrefs(
3419 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463420 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513421}
3422
[email protected]b172aee2012-04-10 17:05:263423gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173424 if (delegate_)
3425 return delegate_->GetRootWindowResizerRect();
3426 return gfx::Rect();
3427}
3428
[email protected]7a846df2012-09-20 19:17:393429void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273430 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393431 browser_plugin_embedder_.reset();
3432}
3433
[email protected]b172aee2012-04-10 17:05:263434void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443435 // Don't send notifications if we are just creating a swapped-out RVH for
3436 // the opener chain. These won't be used for view-source or WebUI, so it's
3437 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243438 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443439 return;
3440
[email protected]86f98a22013-03-20 14:35:003441 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313442 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083443
[email protected]8ff00d72012-10-23 19:12:213444 NotificationService::current()->Notify(
3445 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3446 Source<WebContents>(this),
3447 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323448
3449 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353450 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213451 if (GetRenderManager()->pending_web_ui())
3452 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323453
[email protected]6286a372013-10-09 04:03:273454 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333455 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323456 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183457 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583458 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323459 }
[email protected]0666aef2009-05-13 19:48:083460
[email protected]60780f412013-02-25 16:34:103461 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263462
3463 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253464 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583465
3466 // We tell the observers now instead of when the main RenderFrameHostImpl is
3467 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3468 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363469 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583470 FOR_EACH_OBSERVER(
3471 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303472 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
[email protected]420ae012009-04-24 05:16:323473}
3474
[email protected]b172aee2012-04-10 17:05:263475void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523476 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323477 // Don't notify the world, since this came from a renderer in the
3478 // background.
3479 return;
3480 }
3481
[email protected]da7a7182013-09-06 08:11:113482 notify_disconnection_ = true;
3483 // TODO(avi): Remove. http://crbug.com/170921
3484 NotificationService::current()->Notify(
3485 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3486 Source<WebContents>(this),
3487 NotificationService::NoDetails());
3488
[email protected]be1f56ab2011-12-22 06:55:313489 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233490 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303491
3492 // Restore the focus to the tab (otherwise the focus will be on the top
3493 // window).
[email protected]484ae5912010-09-29 19:16:143494 if (was_crashed && !FocusLocationBarByDefault() &&
3495 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063496 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143497 }
[email protected]32ded2212011-11-10 18:51:433498
[email protected]d8c660432011-12-22 20:51:253499 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323500}
3501
[email protected]ec6a7eb2013-04-22 17:34:223502void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3503 base::TerminationStatus status,
3504 int error_code) {
[email protected]151a63d2011-12-20 22:32:523505 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323506 // The pending page's RenderViewHost is gone.
3507 return;
3508 }
3509
[email protected]2fcdcc32014-03-05 02:14:073510 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3511 // renderer may not have made a clean exit.
3512 if (IsFullscreenForCurrentTab())
3513 ToggleFullscreenMode(false);
3514
[email protected]698191dc2014-02-25 01:06:133515 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3516 if (dialog_manager_)
3517 dialog_manager_->CancelActiveAndPendingDialogs(this);
3518
[email protected]f738bdcb2014-07-11 20:40:443519 if (delegate_)
3520 delegate_->HideValidationMessage(this);
3521
[email protected]e3b10d12014-03-28 16:06:093522 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323523 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233524 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453525
[email protected]960b0372014-05-19 18:01:003526 // Reset the loading progress. TODO(avi): What does it mean to have a
3527 // "renderer crash" when there is more than one renderer process serving a
3528 // webpage? Once this function is called at a more granular frame level, we
3529 // probably will need to more granularly reset the state here.
3530 ResetLoadProgressState();
3531 loading_frames_in_progress_ = 0;
3532
[email protected]d8c660432011-12-22 20:51:253533 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273534 observers_,
[email protected]58d5cfe2013-07-10 02:40:523535 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323536}
3537
[email protected]b172aee2012-04-10 17:05:263538void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253539 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063540}
3541
[email protected]b172aee2012-04-10 17:05:263542void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3543 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043544 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153545 // Ensure that this state update comes from either the active RVH or one of
3546 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413547 // TODO(nasko): This should go through RenderFrameHost.
3548 // TODO(creis): We can't update state for cross-process subframes until we
3549 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3550 if (rvh != GetRenderViewHost() &&
3551 !GetRenderManager()->IsRVHOnSwappedOutList(
3552 static_cast<RenderViewHostImpl*>(rvh)))
3553 return;
[email protected]420ae012009-04-24 05:16:323554
3555 // We must be prepared to handle state updates for any page, these occur
3556 // when the user is scrolling and entering form data, as well as when we're
3557 // leaving a page, in which case our state may have already been moved to
3558 // the next page. The navigation controller will look up the appropriate
3559 // NavigationEntry and update it when it is notified via the delegate.
3560
3561 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583562 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323563 if (entry_index < 0)
3564 return;
[email protected]10f417c52011-12-28 21:04:233565 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323566
[email protected]691aa2f2013-05-28 22:52:043567 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323568 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043569 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323570 controller_.NotifyEntryChanged(entry, entry_index);
3571}
3572
[email protected]b172aee2012-04-10 17:05:263573void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513574 if (delegate_)
3575 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323576}
3577
[email protected]b172aee2012-04-10 17:05:263578void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103579#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293580 // The UI may be in an event-tracking loop, such as between the
3581 // mouse-down and mouse-up in text selection or a button click.
3582 // Defer the close until after tracking is complete, so that we
3583 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293584 // TODO(shess): This could get more fine-grained. For instance,
3585 // closing a tab in another window while selecting text in the
3586 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103587 if (view_->IsEventTracking()) {
3588 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293589 return;
3590 }
[email protected]60780f412013-02-25 16:34:103591#endif
[email protected]07707302009-11-06 00:50:293592
[email protected]420ae012009-04-24 05:16:323593 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523594 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513595 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323596}
3597
[email protected]66bbadaf2014-03-28 16:25:543598void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573599 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3600 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573601}
3602
[email protected]6f2ac772014-07-24 22:22:083603void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253604 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173605#if defined(OS_ANDROID)
[email protected]6f2ac772014-07-24 22:22:083606 ContentViewCoreImpl::FromWebContents(this)->DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253607 transition_data);
[email protected]23f41fd2014-06-21 05:29:173608#endif
3609}
3610
3611bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3612#if defined(OS_ANDROID)
3613 return ContentViewCoreImpl::FromWebContents(this)->
3614 WillHandleDeferAfterResponseStarted();
3615#else
3616 return false;
3617#endif
3618}
3619
[email protected]b172aee2012-04-10 17:05:263620void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513621 if (delegate_ && delegate_->IsPopupOrPanel(this))
3622 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323623}
3624
[email protected]e3b10d12014-03-28 16:06:093625void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3626 bool to_different_document) {
3627 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3628 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323629}
3630
[email protected]723971b2014-02-12 11:08:253631void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323632 scoped_ptr<LoadNotificationDetails> details;
3633
[email protected]9595fd82013-04-19 21:28:493634 // Use the last committed entry rather than the active one, in case a
3635 // pending entry has been created.
3636 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203637 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493638
[email protected]420ae012009-04-24 05:16:323639 // An entry may not exist for a stop when loading an initial blank page or
3640 // if an iframe injected by script into a blank page finishes loading.
3641 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203642 base::TimeDelta elapsed =
3643 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323644
3645 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513646 entry->GetVirtualURL(),
3647 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323648 elapsed,
3649 &controller_,
3650 controller_.GetCurrentEntryIndex()));
3651 }
3652
[email protected]e3b10d12014-03-28 16:06:093653 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3654 details.get());
[email protected]420ae012009-04-24 05:16:323655}
3656
[email protected]b172aee2012-04-10 17:05:263657void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163658 controller_.DiscardNonCommittedEntries();
3659
3660 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213661 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163662}
3663
[email protected]59167c22013-06-03 18:07:323664void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103665 has_accessed_initial_document_ = true;
3666
[email protected]d1371bf8e2014-04-19 03:26:243667 // We may have left a failed browser-initiated navigation in the address bar
3668 // to let the user edit it and try again. Clear it now that content might
3669 // show up underneath it.
3670 if (!IsLoading() && controller_.GetPendingEntry())
3671 controller_.DiscardPendingEntry();
3672
[email protected]59167c22013-06-03 18:07:323673 // Update the URL display.
3674 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3675}
3676
[email protected]3f19f1a2014-05-02 05:23:273677void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3678 if (opener_) {
3679 // Clear our opener so that future cross-process navigations don't have an
3680 // opener assigned.
3681 RemoveDestructionObserver(opener_);
3682 opener_ = NULL;
3683 }
3684
3685 // Notify all swapped out RenderViewHosts for this tab. This is important
3686 // in case we go back to them, or if another window in those processes tries
3687 // to access window.opener.
3688 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3689}
3690
[email protected]39f2f9252014-05-03 00:54:013691void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293692 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093693 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293694 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093695
3696 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213697 NotificationService::current()->Notify(
3698 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3699 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293700 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083701}
3702
[email protected]ef3adfc2014-05-11 00:04:543703void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3704 int32 page_id,
3705 const base::string16& title,
3706 base::i18n::TextDirection title_direction) {
3707 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3708
3709 // If we have a title, that's a pretty good indication that we've started
3710 // getting useful data.
3711 SetNotWaitingForResponse();
3712
3713 // Try to find the navigation entry, which might not be the current one.
3714 // For example, it might be from a pending RVH for the pending entry.
3715 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3716 rvh->GetSiteInstance(), page_id);
3717
3718 // We can handle title updates when we don't have an entry in
3719 // UpdateTitleForEntry, but only if the update is from the current RVH.
3720 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3721 if (!entry && rvh != GetRenderViewHost())
3722 return;
3723
3724 // TODO(evan): make use of title_direction.
3725 // http://code.google.com/p/chromium/issues/detail?id=27094
3726 if (!UpdateTitleForEntry(entry, title))
3727 return;
3728
3729 // Broadcast notifications when the UI should be updated.
3730 if (entry == controller_.GetEntryAtOffset(0))
3731 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3732}
3733
3734void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3735 const std::string& encoding) {
3736 SetEncoding(encoding);
3737}
3738
[email protected]39f2f9252014-05-03 00:54:013739void WebContentsImpl::DocumentAvailableInMainFrame(
3740 RenderViewHost* render_view_host) {
3741 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3742 DocumentAvailableInMainFrame());
3743}
[email protected]e1c3a552012-05-04 20:51:323744void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3745 // Tell the active RenderViewHost to run unload handlers and close, as long
3746 // as the request came from a RenderViewHost in the same BrowsingInstance.
3747 // In most cases, we receive this from a swapped out RenderViewHost.
3748 // It is possible to receive it from one that has just been swapped in,
3749 // in which case we might as well deliver the message anyway.
3750 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3751 GetRenderViewHost()->ClosePage();
3752}
3753
[email protected]f546640b2012-05-15 00:03:493754void WebContentsImpl::RouteMessageEvent(
3755 RenderViewHost* rvh,
3756 const ViewMsg_PostMessage_Params& params) {
3757 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363758 // came from a RenderViewHost in the same BrowsingInstance or if this
3759 // WebContents is dedicated to a browser plugin guest.
3760 // Note: This check means that an embedder could theoretically receive a
3761 // postMessage from anyone (not just its own guests). However, this is
3762 // probably not a risk for apps since other pages won't have references
3763 // to App windows.
3764 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3765 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493766 return;
3767
3768 ViewMsg_PostMessage_Params new_params(params);
3769
[email protected]0bc7f3542013-10-21 15:05:533770 if (!params.message_port_ids.empty()) {
3771 MessagePortMessageFilter* message_port_message_filter =
3772 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3773 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093774 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3775 params.message_port_ids,
3776 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533777 }
3778
[email protected]f546640b2012-05-15 00:03:493779 // If there is a source_routing_id, translate it to the routing ID for
3780 // the equivalent swapped out RVH in the target process. If we need
3781 // to create a swapped out RVH for the source tab, we create its opener
3782 // chain as well, since those will also be accessible to the target page.
3783 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3784 // Try to look up the WebContents for the source page.
3785 WebContentsImpl* source_contents = NULL;
3786 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3787 rvh->GetProcess()->GetID(), params.source_routing_id);
3788 if (source_rvh) {
3789 source_contents = static_cast<WebContentsImpl*>(
3790 source_rvh->GetDelegate()->GetAsWebContents());
3791 }
3792
3793 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363794 if (GetBrowserPluginGuest()) {
3795 // We create a swapped out RenderView for the embedder in the guest's
3796 // render process but we intentionally do not expose the embedder's
3797 // opener chain to it.
3798 new_params.source_routing_id =
3799 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3800 } else {
3801 new_params.source_routing_id =
3802 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3803 }
[email protected]f546640b2012-05-15 00:03:493804 } else {
3805 // We couldn't find it, so don't pass a source frame.
3806 new_params.source_routing_id = MSG_ROUTING_NONE;
3807 }
3808 }
3809
3810 // In most cases, we receive this from a swapped out RenderViewHost.
3811 // It is possible to receive it from one that has just been swapped in,
3812 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183813 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493814}
3815
[email protected]a796f202012-05-30 14:14:253816bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263817 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253818 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263819 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253820 if (!delegate_)
3821 return false;
3822 return delegate_->AddMessageToConsole(this, level, message, line_no,
3823 source_id);
3824}
3825
[email protected]9e797d22014-08-08 21:31:303826WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273827 // We want to base the page config off of the actual URL, rather than the
3828 // virtual URL.
3829 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3830 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003831 GURL url = controller_.GetActiveEntry()
3832 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153833
[email protected]9e797d22014-08-08 21:31:303834 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323835}
3836
[email protected]0eba810b2012-10-18 03:19:363837int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213838 SiteInstance* instance) {
[email protected]82307f6b2014-08-07 03:30:123839 return GetRenderManager()->CreateRenderFrame(
3840 instance, MSG_ROUTING_NONE, true, true, true);
[email protected]0eba810b2012-10-18 03:19:363841}
3842
[email protected]b172aee2012-04-10 17:05:263843void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273844 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253845 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223846
[email protected]ea114722012-03-12 01:11:253847 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173848 if (rdh) // NULL in unittests.
3849 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253850}
3851
[email protected]b172aee2012-04-10 17:05:263852void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443853 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253854 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443855}
3856
[email protected]b172aee2012-04-10 17:05:263857void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563858 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263859 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153860 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523861 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153862 return;
3863
[email protected]9f76c1e2012-03-05 15:15:583864 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3865
[email protected]e5fc1632011-08-08 07:51:533866 // Ignore renderer unresponsive event if debugger is attached to the tab
3867 // since the event may be a result of the renderer sitting on a breakpoint.
3868 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363869 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533870 return;
3871
[email protected]2e9d79f2013-08-16 05:45:563872 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323873 // Hang occurred while firing the beforeunload/unload handler.
3874 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583875 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323876
[email protected]fa944cb82013-11-15 17:51:213877 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323878 return;
3879
3880 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563881 // nothing we can do to recover. If the hang is in the beforeunload handler,
3882 // pretend the beforeunload listeners have all fired and allow the delegate
3883 // to continue closing; the user will not have the option of cancelling the
3884 // close. Otherwise, pretend the unload listeners have all fired and close
3885 // the tab.
3886 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463887 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563888 delegate_->BeforeUnloadFired(this, true, &close);
3889 }
3890 if (close)
3891 Close(rvh);
[email protected]420ae012009-04-24 05:16:323892 return;
3893 }
3894
[email protected]9f76c1e2012-03-05 15:15:583895 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473896 return;
3897
[email protected]6934a702011-12-20 00:04:513898 if (delegate_)
3899 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323900}
3901
[email protected]b172aee2012-04-10 17:05:263902void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513903 if (delegate_)
3904 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323905}
3906
[email protected]b172aee2012-04-10 17:05:263907void WebContentsImpl::LoadStateChanged(
3908 const GURL& url,
3909 const net::LoadStateWithParam& load_state,
3910 uint64 upload_position,
3911 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323912 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563913 upload_position_ = upload_position;
3914 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503915 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213916 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303917 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213918 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323919 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463920 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213921 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463922 }
[email protected]420ae012009-04-24 05:16:323923}
3924
[email protected]b172aee2012-04-10 17:05:263925void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553926 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323927 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123928 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3929 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513930 if (delegate_)
3931 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093932 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323933}
3934
[email protected]58d5cfe2013-07-10 02:40:523935void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543936 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233937 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223938 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543939}
3940
[email protected]b172aee2012-04-10 17:05:263941void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103942 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213943 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263944 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3945 // here during container initialization and normal window size will be set
3946 // later. In case of tab duplication this resizing to 0x0 prevents setting
3947 // normal size later so just ignore it.
3948 if (!size.IsEmpty())
3949 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323950}
3951
[email protected]af905902013-10-01 21:38:513952void WebContentsImpl::CancelModalDialogsForRenderManager() {
3953 // We need to cancel modal dialogs when doing a process swap, since the load
3954 // deferrer would prevent us from swapping out.
3955 if (dialog_manager_)
3956 dialog_manager_->CancelActiveAndPendingDialogs(this);
3957}
3958
[email protected]02d7b6e2014-06-24 21:01:503959void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
3960 RenderFrameHost* new_host,
3961 bool is_main_frame) {
3962 if (is_main_frame) {
3963 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
3964 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:083965
[email protected]02d7b6e2014-06-24 21:01:503966 // Make sure the visible RVH reflects the new delegate's preferences.
3967 if (delegate_)
3968 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393969
[email protected]02d7b6e2014-06-24 21:01:503970 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
3971 }
3972
3973 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:543974}
3975
[email protected]14392a52012-05-02 20:28:443976int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3977 SiteInstance* instance) {
3978 if (!opener_)
3979 return MSG_ROUTING_NONE;
3980
3981 // Recursively create RenderViews for anything else in the opener chain.
3982 return opener_->CreateOpenerRenderViews(instance);
3983}
3984
3985int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3986 int opener_route_id = MSG_ROUTING_NONE;
3987
3988 // If this tab has an opener, ensure it has a RenderView in the given
3989 // SiteInstance as well.
3990 if (opener_)
3991 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3992
[email protected]45a22ad2013-02-21 03:25:003993 // If any of the renderers (current, pending, or swapped out) for this
3994 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213995 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3996 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373997
[email protected]fa944cb82013-11-15 17:51:213998 if (GetRenderManager()->pending_render_view_host() &&
3999 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4000 instance)
4001 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004002
[email protected]fa944cb82013-11-15 17:51:214003 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374004 instance);
4005 if (rvh)
4006 return rvh->GetRoutingID();
4007
[email protected]14392a52012-05-02 20:28:444008 // Create a swapped out RenderView in the given SiteInstance if none exists,
4009 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]82307f6b2014-08-07 03:30:124010 return GetRenderManager()->CreateRenderFrame(
4011 instance, opener_route_id, true, true, true);
[email protected]14392a52012-05-02 20:28:444012}
4013
[email protected]b172aee2012-04-10 17:05:264014NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194015 return GetController();
[email protected]3a3d47472010-07-15 21:03:544016}
4017
[email protected]b172aee2012-04-10 17:05:264018WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:564019 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:324020}
4021
[email protected]10f417c52011-12-28 21:04:234022NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264023 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324024 return controller_.GetLastCommittedEntry();
4025}
4026
[email protected]b172aee2012-04-10 17:05:264027bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164028 RenderViewHost* render_view_host,
4029 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044030 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124031 bool for_main_frame_navigation) {
[email protected]e11f0e92013-06-12 15:12:034032 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444033 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484034 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164035 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4036 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4037 // case this because RWH is still a base class of RenderViewHost, and child
4038 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124039 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164040 RenderWidgetHostViewChildFrame* rwh_view_child =
4041 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164042 rwh_view = rwh_view_child;
4043 } else {
4044 rwh_view = view_->CreateViewForWidget(render_view_host);
4045 }
[email protected]1a98a932009-11-17 00:12:524046
[email protected]420ae012009-04-24 05:16:324047 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444048 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214049 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324050
[email protected]74ce1ad2011-12-16 21:51:464051 // Make sure we use the correct starting page_id in the new RenderView.
4052 UpdateMaxPageIDIfNecessary(render_view_host);
4053 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584054 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464055
[email protected]9f76c1e2012-03-05 15:15:584056 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264057 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494058 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044059 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494060 max_page_id,
4061 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524062 return false;
[email protected]14392a52012-05-02 20:28:444063 }
[email protected]a4127722011-04-27 23:13:524064
[email protected]a220b5932013-09-21 03:47:444065#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504066 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4067 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444068 if (rwh_view) {
4069 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4070 render_widget_host->WasResized();
4071 }
[email protected]f8233cc2011-05-31 20:24:504072#endif
4073
[email protected]420ae012009-04-24 05:16:324074 return true;
4075}
4076
[email protected]82307f6b2014-08-07 03:30:124077bool WebContentsImpl::CreateRenderFrameForRenderManager(
4078 RenderFrameHost* render_frame_host,
4079 int parent_routing_id) {
4080 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderFrameForRenderManager");
4081
4082 RenderFrameHostImpl* rfh =
4083 static_cast<RenderFrameHostImpl*>(render_frame_host);
4084 if (!rfh->CreateRenderFrame(parent_routing_id))
4085 return false;
4086
4087 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4088 // RenderFrameHost will have to be associated with the appropriate
4089 // RenderWidgetHostView or a new one should be created here.
4090
4091 return true;
4092}
4093
[email protected]7d244f12013-08-22 21:41:514094#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454095
[email protected]155c7f22013-12-09 17:07:184096base::android::ScopedJavaLocalRef<jobject>
4097WebContentsImpl::GetJavaWebContents() {
4098 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4099
4100 WebContentsAndroid* web_contents_android =
4101 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4102 if (!web_contents_android) {
4103 web_contents_android = new WebContentsAndroid(this);
4104 SetUserData(kWebContentsAndroidKey, web_contents_android);
4105 }
4106 return web_contents_android->GetJavaObject();
4107}
4108
[email protected]7d244f12013-08-22 21:41:514109bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4110 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164111 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044112 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594113 true);
[email protected]7d244f12013-08-22 21:41:514114}
[email protected]fc2b46b2014-05-03 16:33:454115
4116#elif defined(OS_MACOSX)
4117
4118void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
4119 view_->SetAllowOverlappingViews(overlapping);
4120}
4121
4122bool WebContentsImpl::GetAllowOverlappingViews() {
4123 return view_->GetAllowOverlappingViews();
4124}
4125
[email protected]75f4df72014-07-16 22:39:424126void WebContentsImpl::SetAllowOtherViews(bool allow) {
4127 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454128}
4129
[email protected]75f4df72014-07-16 22:39:424130bool WebContentsImpl::GetAllowOtherViews() {
4131 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454132}
4133
[email protected]7d244f12013-08-22 21:41:514134#endif
4135
[email protected]6fba26d2014-04-29 09:38:284136void WebContentsImpl::OnDialogClosed(int render_process_id,
4137 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264138 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494139 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264140 bool success,
[email protected]fcf75d42013-12-03 20:11:264141 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284142 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4143 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494144 last_dialog_suppressed_ = dialog_was_suppressed;
4145
[email protected]beb440c2009-11-06 04:08:544146 if (is_showing_before_unload_dialog_ && !success) {
4147 // If a beforeunload dialog is canceled, we need to stop the throbber from
4148 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284149 if (rfh)
4150 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354151 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104152
[email protected]6d65a462013-06-21 21:29:124153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4154 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544155 }
[email protected]87de04b02014-04-08 22:14:494156
[email protected]beb440c2009-11-06 04:08:544157 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284158 if (rfh) {
4159 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4160 dialog_was_suppressed);
4161 } else {
4162 // Don't leak the sync IPC reply if the RFH or process is gone.
4163 delete reply_msg;
4164 }
[email protected]beb440c2009-11-06 04:08:544165}
4166
[email protected]b172aee2012-04-10 17:05:264167void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544168 if (encoding == last_reported_encoding_)
4169 return;
4170 last_reported_encoding_ = encoding;
4171
4172 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124173 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104174}
[email protected]f45d2a72010-03-08 23:28:354175
[email protected]b172aee2012-04-10 17:05:264176void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484177 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444178 // Can be NULL during tests.
4179 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454180 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364181}
[email protected]9f76c1e2012-03-05 15:15:584182
[email protected]1ac10dca2013-08-20 20:47:044183bool WebContentsImpl::IsHidden() {
4184 return capturer_count_ == 0 && !should_normally_be_visible_;
4185}
4186
[email protected]b0936d22013-11-28 06:47:364187RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214188 return frame_tree_.root()->render_manager();
4189}
4190
[email protected]b172aee2012-04-10 17:05:264191RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584192 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4193}
[email protected]7900bfdb2012-05-24 19:31:244194
[email protected]f8497342013-02-05 22:15:024195BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394196 return browser_plugin_guest_.get();
4197}
4198
[email protected]738f57a2013-06-29 21:06:544199void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4200 CHECK(!browser_plugin_guest_);
4201 browser_plugin_guest_.reset(guest);
4202}
4203
[email protected]f8497342013-02-05 22:15:024204BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394205 return browser_plugin_embedder_.get();
4206}
[email protected]8ff00d72012-10-23 19:12:214207
[email protected]d9030b82013-07-19 08:26:064208void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194209 RenderFrameHost* render_frame_host) {
[email protected]c9e3b202014-08-08 08:24:424210#if !defined(OS_CHROMEOS)
4211 uintptr_t key = reinterpret_cast<uintptr_t>(render_frame_host);
4212 scoped_ptr<PowerSaveBlockerMapEntry> map_entry =
4213 power_save_blockers_.take_and_erase(key);
4214 if (map_entry)
4215 map_entry->clear();
4216#endif
[email protected]d9030b82013-07-19 08:26:064217}
4218
4219void WebContentsImpl::ClearAllPowerSaveBlockers() {
[email protected]c9e3b202014-08-08 08:24:424220#if !defined(OS_CHROMEOS)
[email protected]d9030b82013-07-19 08:26:064221 power_save_blockers_.clear();
[email protected]c9e3b202014-08-08 08:24:424222#endif
[email protected]d9030b82013-07-19 08:26:064223}
4224
[email protected]fc2b46b2014-05-03 16:33:454225gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214226 gfx::Size size;
4227 if (delegate_)
4228 size = delegate_->GetSizeForNewRenderView(this);
4229 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454230 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214231 return size;
4232}
4233
[email protected]ae7eeda2014-07-04 01:53:264234void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4235 FOR_EACH_OBSERVER(
4236 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554237}
4238
[email protected]222f5822014-02-05 23:40:494239void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4240 if (!delegate_)
4241 return;
4242 const gfx::Size new_size = GetPreferredSize();
4243 if (new_size != old_size)
4244 delegate_->UpdatePreferredSize(this, new_size);
4245}
4246
[email protected]23f41fd2014-06-21 05:29:174247void WebContentsImpl::ResumeResponseDeferredAtStart() {
4248 FrameTreeNode* node = frame_tree_.root();
4249 node->render_manager()->ResumeResponseDeferredAtStart();
4250}
4251
[email protected]8ff00d72012-10-23 19:12:214252} // namespace content