blob: 15032102a75bac471a2c03e8812cd26506206e27 [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]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]65bfd9972012-10-19 03:39:3718#include "cc/switches.h"
[email protected]7a846df2012-09-20 19:17:3919#include "content/browser/browser_plugin/browser_plugin_embedder.h"
20#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5921#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1922#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1923#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0424#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4625#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1226#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1627#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3228#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5429#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0530#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0031#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]678c0362012-12-05 08:02:4432#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]f3b1a082011-11-18 00:34:3033#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3234#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5035#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3336#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3737#include "content/browser/web_contents/interstitial_page_impl.h"
38#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]b5a40842012-11-28 15:26:1139#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]d2353452012-01-19 19:53:5640#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3941#include "content/common/browser_plugin_messages.h"
[email protected]795c28972012-12-06 06:13:3942#include "content/common/icon_messages.h"
[email protected]ce9751942011-09-21 01:57:2443#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5144#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0245#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5746#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5847#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1148#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2049#include "content/public/browser/color_chooser.h"
[email protected]2a5e9d02013-01-20 01:09:2550#include "content/public/browser/compositor_util.h"
[email protected]87f3c082011-10-19 18:07:4451#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3652#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1753#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1454#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4655#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1556#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0057#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2758#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0059#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3760#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1461#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3262#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3463#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3864#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4265#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2566#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1067#include "content/public/browser/web_contents_view.h"
[email protected]3c788372013-01-10 08:34:2868#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2169#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4870#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1871#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5472#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0373#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1674#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2975#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5476#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3477#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3778#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5679#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1680#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0182#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4183#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5284#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2485#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3686#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3187#include "webkit/glue/webpreferences.h"
88
[email protected]583418cc2013-01-17 14:01:1089#if defined(OS_ANDROID)
90#include "content/browser/android/date_time_chooser_android.h"
91#endif
92
[email protected]f66df822012-05-18 16:52:1793#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5094#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4195#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5796#endif
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]c71fe6402012-08-15 15:22:5598#if defined(USE_AURA) && defined(USE_X11)
[email protected]54944cde2012-12-09 09:24:5999#include "ui/aura/window.h"
[email protected]c71fe6402012-08-15 15:22:55100#include "ui/base/touch/touch_factory.h"
101#endif // defined (USE_AURA) && defined(USE_X11)
102
[email protected]4cc1ab52013-01-21 19:24:34103#if defined(ENABLE_JAVA_BRIDGE)
104#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
105#endif
106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
[email protected]b172aee2012-04-10 17:05:26109// If a WebContentsImpl is told to navigate to a different web site (as
110// determined by SiteInstance), it will replace its current RenderViewHost with
111// a new RenderViewHost dedicated to the new SiteInstance. This works as
112// follows:
[email protected]420ae012009-04-24 05:16:32113//
114// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46115// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32116// - The pending RVH is "suspended," so that no navigation messages are sent to
117// its renderer until the onbeforeunload JavaScript handler has a chance to
118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
120// that it has a pending cross-site request. ResourceDispatcherHost will
121// check for this when the response arrives.
122// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46123// cancel all the pending logic. Otherwise we allow the pending RVH to send
124// the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
126// main resource load on the pending RVH. It checks CrossSiteRequestManager
127// to see that it is a cross-site request, and installs a
128// CrossSiteResourceHandler.
129// - When RDH receives a response, the BufferedResourceHandler determines
130// whether it is a download. If so, it sends a message to the new renderer
131// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26132// pending RVH remains until the next DidNavigate event for this
133// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32134// - After RDH receives a response and determines that it is safe and not a
135// download, it pauses the response to first run the old page's onunload
136// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26137// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32138// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15139// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32140// the ResourceDispatcherHost, who unpauses the response. Data is then sent
141// to the pending RVH.
142// - The pending renderer sends a FrameNavigate message that invokes the
143// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46144// pending RVH.
[email protected]992db4c2011-05-12 15:37:15145// - The previous renderer is kept swapped out in RenderViewHostManager in case
146// the user goes back. The process only stays live if another tab is using
147// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32148
[email protected]6717bf272012-05-11 23:31:25149using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44150
[email protected]8ff00d72012-10-23 19:12:21151namespace content {
[email protected]420ae012009-04-24 05:16:32152namespace {
153
154// Amount of time we wait between when a key event is received and the renderer
155// is queried for its state and pushed to the NavigationEntry.
156const int kQueryStateDelay = 5000;
157
[email protected]6ebdc9b2010-09-27 16:55:57158const int kSyncWaitDelay = 40;
159
[email protected]82114f52012-03-20 22:53:41160const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05161
[email protected]795c28972012-12-06 06:13:39162static int StartDownload(content::RenderViewHost* rvh,
163 const GURL& url,
164 int image_size) {
165 static int g_next_favicon_download_id = 0;
166 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
167 ++g_next_favicon_download_id,
168 url,
169 image_size));
170 return g_next_favicon_download_id;
171}
172
[email protected]2c5569662011-03-22 20:45:02173ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21174 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50175 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16176 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23181 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
182 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16184 break; // Fall through to rest of function.
185 }
[email protected]5e369672009-11-03 23:48:30186
[email protected]59246c572012-02-10 13:32:13187 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
188 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36189 if (entry.restore_type() ==
190 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13191 if (entry.GetHasPostData())
192 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13194 }
[email protected]5e369672009-11-03 23:48:30195
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30197}
198
[email protected]10f417c52011-12-28 21:04:23199void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47200 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21201 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50202 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16203 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51204 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54205 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55206 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
207 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36208 if (!entry.GetBaseURLForDataURL().is_empty()) {
209 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
210 params->history_url_for_data_url = entry.GetVirtualURL();
211 }
[email protected]36fc0392011-12-25 03:59:51212 params->referrer = entry.GetReferrer();
213 params->transition = entry.GetTransitionType();
214 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00215 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55216 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34217 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47218 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48219 params->transferred_request_child_id =
220 entry.transferred_global_request_id().child_id;
221 params->transferred_request_request_id =
222 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22223 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00224 // Avoid downloading when in view-source mode.
225 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44226 params->is_post = entry.GetHasPostData();
227 if(entry.GetBrowserInitiatedPostData()) {
228 params->browser_initiated_post_data.assign(
229 entry.GetBrowserInitiatedPostData()->front(),
230 entry.GetBrowserInitiatedPostData()->front() +
231 entry.GetBrowserInitiatedPostData()->size());
232
233 }
[email protected]6c6b02d2011-09-02 03:36:47234
[email protected]7c16976c2012-08-04 02:38:23235 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
236 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
237 // We may have been redirected when navigating to the current URL.
238 // Use the URL the user originally intended to visit, if it's valid and if a
239 // POST wasn't involved; the latter case avoids issues with sending data to
240 // the wrong page.
241 params->url = entry.GetOriginalRequestURL();
242 } else {
243 params->url = entry.GetURL();
244 }
245
[email protected]951a64832012-10-11 16:26:37246 params->can_load_local_resources = entry.GetCanLoadLocalResources();
247
[email protected]6c6b02d2011-09-02 03:36:47248 if (delegate)
249 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34250}
251
[email protected]f98f5092012-05-19 00:08:14252int GetSwitchValueAsInt(
253 const CommandLine& command_line,
254 const std::string& switch_string,
255 int min_value) {
256 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
257 int int_value;
258 if (base::StringToInt(string_value, &int_value))
259 return std::max(min_value, int_value);
260 else
261 return min_value;
262}
263
[email protected]420ae012009-04-24 05:16:32264} // namespace
265
[email protected]54944cde2012-12-09 09:24:59266WebContents* WebContents::Create(const WebContents::CreateParams& params) {
267 return WebContentsImpl::CreateWithOpener(params, NULL);
[email protected]d1198fd2012-08-13 22:50:19268}
269
270WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59271 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19272 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59273 WebContentsImpl* new_contents = new WebContentsImpl(
274 params.browser_context, NULL);
[email protected]d1198fd2012-08-13 22:50:19275
276 for (SessionStorageNamespaceMap::const_iterator it =
277 session_storage_namespace_map.begin();
278 it != session_storage_namespace_map.end();
279 ++it) {
280 new_contents->GetController().SetSessionStorageNamespace(it->first,
281 it->second);
282 }
283
[email protected]54944cde2012-12-09 09:24:59284 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19285 return new_contents;
[email protected]a81343d232011-12-27 07:39:20286}
[email protected]746d3052012-05-22 15:15:47287
[email protected]299d7f12012-05-23 05:31:15288WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47289 return rvh->GetDelegate()->GetAsWebContents();
290}
291
[email protected]b172aee2012-04-10 17:05:26292// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32293
[email protected]b172aee2012-04-10 17:05:26294WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21295 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19296 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42297 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19298 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57299 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44300 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05301 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34302 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23303 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
304 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34305 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21306 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56307 upload_size_(0),
308 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47309 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57310 capturing_contents_(false),
311 is_being_destroyed_(false),
312 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55313 dialog_creator_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01314 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56315 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38316 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21317 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
318 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00319 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43320 content_restrictions_(0),
[email protected]44470a22013-01-24 01:21:54321 color_chooser_(NULL),
322 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]332af7732009-03-11 13:21:35323}
initial.commit09911bf2008-07-26 23:55:29324
[email protected]b172aee2012-04-10 17:05:26325WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32326 is_being_destroyed_ = true;
327
[email protected]b24b68a2012-09-24 21:57:26328 for (std::set<RenderWidgetHostImpl*>::iterator iter =
329 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
330 (*iter)->DetachDelegate();
331 }
332 created_widgets_.clear();
333
[email protected]3ab9cb82011-06-03 18:02:07334 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55335 if (dialog_creator_)
336 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07337
[email protected]da8543762012-03-20 08:52:20338 if (color_chooser_)
339 color_chooser_->End();
340
[email protected]420ae012009-04-24 05:16:32341 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32342
[email protected]ca13a442012-04-17 14:00:12343 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21344 NotificationService::current()->Notify(
345 NOTIFICATION_WEB_CONTENTS_DESTROYED,
346 Source<WebContents>(this),
347 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32348
349 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07350#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32351 // If we still have a window handle, destroy it. GetNativeView can return
352 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42353 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52354 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58355 if (host && host->GetView())
356 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42357 }
[email protected]420ae012009-04-24 05:16:32358#endif
[email protected]7ab1e7d62009-10-14 23:32:01359
360 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15361 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55362 base::TimeTicks now = base::TimeTicks::Now();
363 base::TimeTicks unload_start_time = close_start_time_;
364 if (!before_unload_end_time_.is_null())
365 unload_start_time = before_unload_end_time_;
366 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
367 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01368 }
[email protected]b5a1d11c2011-02-17 03:09:42369
[email protected]2db9bd72012-04-13 20:20:56370 FOR_EACH_OBSERVER(WebContentsObserver,
371 observers_,
372 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08373
[email protected]6934a702011-12-20 00:04:51374 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42375}
376
[email protected]d1198fd2012-08-13 22:50:19377WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59378 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19379 WebContentsImpl* opener) {
[email protected]54944cde2012-12-09 09:24:59380 WebContentsImpl* new_contents = new WebContentsImpl(
381 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19382
[email protected]54944cde2012-12-09 09:24:59383 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19384 return new_contents;
385}
386
[email protected]dd8c8232012-11-03 00:49:36387WebContentsImpl* WebContentsImpl::CreateGuest(
388 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53389 SiteInstance* site_instance,
[email protected]3de10bb32013-01-08 21:57:33390 int routing_id,
391 WebContentsImpl* opener_web_contents,
[email protected]dd8c8232012-11-03 00:49:36392 int guest_instance_id,
393 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]b5a40842012-11-28 15:26:11394
[email protected]3de10bb32013-01-08 21:57:33395 WebContentsImpl* new_contents = new WebContentsImpl(browser_context,
396 opener_web_contents);
[email protected]7a846df2012-09-20 19:17:39397
398 // This makes |new_contents| act as a guest.
399 // For more info, see comment above class BrowserPluginGuest.
[email protected]b5a40842012-11-28 15:26:11400 new_contents->browser_plugin_guest_.reset(
401 BrowserPluginGuest::Create(
402 guest_instance_id,
403 new_contents,
404 params));
405
[email protected]3de10bb32013-01-08 21:57:33406 WebContents::CreateParams create_params(browser_context, site_instance);
407 create_params.routing_id = routing_id;
408 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11409
[email protected]7a846df2012-09-20 19:17:39410 return new_contents;
411}
412
[email protected]b172aee2012-04-10 17:05:26413WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
414 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54415 WebPreferences prefs;
416
417 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
418
419 prefs.developer_extras_enabled = true;
420 prefs.javascript_enabled =
421 !command_line.HasSwitch(switches::kDisableJavaScript);
422 prefs.web_security_enabled =
423 !command_line.HasSwitch(switches::kDisableWebSecurity);
424 prefs.plugins_enabled =
425 !command_line.HasSwitch(switches::kDisablePlugins);
426 prefs.java_enabled =
427 !command_line.HasSwitch(switches::kDisableJava);
428
429 prefs.uses_page_cache =
430 command_line.HasSwitch(switches::kEnableFastback);
431 prefs.remote_fonts_enabled =
432 !command_line.HasSwitch(switches::kDisableRemoteFonts);
433 prefs.xss_auditor_enabled =
434 !command_line.HasSwitch(switches::kDisableXSSAuditor);
435 prefs.application_cache_enabled =
436 !command_line.HasSwitch(switches::kDisableApplicationCache);
437
438 prefs.local_storage_enabled =
439 !command_line.HasSwitch(switches::kDisableLocalStorage);
440 prefs.databases_enabled =
441 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01442#if defined(OS_ANDROID)
443 prefs.webaudio_enabled =
444 command_line.HasSwitch(switches::kEnableWebAudio);
445#else
[email protected]64d69de42012-02-06 00:19:54446 prefs.webaudio_enabled =
447 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01448#endif
[email protected]64d69de42012-02-06 00:19:54449
450 prefs.experimental_webgl_enabled =
451 GpuProcessHost::gpu_enabled() &&
452 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07453#if defined(OS_ANDROID)
454 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
455#else
[email protected]64d69de42012-02-06 00:19:54456 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07457#endif
[email protected]64d69de42012-02-06 00:19:54458
[email protected]5a073092012-06-08 00:42:51459 prefs.flash_3d_enabled =
460 GpuProcessHost::gpu_enabled() &&
461 !command_line.HasSwitch(switches::kDisableFlash3d);
462 prefs.flash_stage3d_enabled =
463 GpuProcessHost::gpu_enabled() &&
464 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19465
[email protected]64d69de42012-02-06 00:19:54466 prefs.gl_multisampling_enabled =
467 !command_line.HasSwitch(switches::kDisableGLMultisampling);
468 prefs.privileged_webgl_extensions_enabled =
469 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
470 prefs.site_specific_quirks_enabled =
471 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
472 prefs.allow_file_access_from_file_urls =
473 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
474 prefs.show_composited_layer_borders =
475 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
476 prefs.show_composited_layer_tree =
477 command_line.HasSwitch(switches::kShowCompositedLayerTree);
478 prefs.show_fps_counter =
479 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08480 prefs.accelerated_compositing_for_overflow_scroll_enabled =
[email protected]1315fdf2012-12-12 19:45:16481 command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll);
482 prefs.accelerated_compositing_for_scrollable_frames_enabled =
483 command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames);
[email protected]ab3dd632013-01-09 23:19:08484 prefs.composited_scrolling_for_frames_enabled =
485 command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames);
[email protected]8611a852012-05-23 22:11:19486 prefs.show_paint_rects =
487 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52488 prefs.render_vsync_enabled =
489 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54490 prefs.accelerated_compositing_enabled =
491 GpuProcessHost::gpu_enabled() &&
492 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54493 prefs.force_compositing_mode =
[email protected]2a5e9d02013-01-20 01:09:25494 content::IsForceCompositingModeEnabled() &&
[email protected]9b19cf82012-06-13 06:23:23495 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54496 prefs.fixed_position_compositing_enabled =
497 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
498 prefs.accelerated_2d_canvas_enabled =
499 GpuProcessHost::gpu_enabled() &&
500 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58501 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27502 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]a7f899e2013-01-09 12:15:44503 prefs.antialiased_2d_canvas_disabled =
504 command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
[email protected]64d69de42012-02-06 00:19:54505 prefs.accelerated_painting_enabled =
506 GpuProcessHost::gpu_enabled() &&
507 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
508 prefs.accelerated_filters_enabled =
509 GpuProcessHost::gpu_enabled() &&
510 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
[email protected]9bdcfd642012-11-14 21:24:26511 prefs.accelerated_compositing_for_3d_transforms_enabled =
512 prefs.accelerated_compositing_for_animation_enabled =
[email protected]64d69de42012-02-06 00:19:54513 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]9bdcfd642012-11-14 21:24:26514 prefs.accelerated_compositing_for_plugins_enabled =
[email protected]64d69de42012-02-06 00:19:54515 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
[email protected]9bdcfd642012-11-14 21:24:26516 prefs.accelerated_compositing_for_video_enabled =
[email protected]64d69de42012-02-06 00:19:54517 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54518 prefs.fullscreen_enabled =
519 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43520 prefs.css_sticky_position_enabled =
521 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29522 prefs.css_shaders_enabled =
523 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01524 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03525 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]8eb51382012-11-20 00:42:33526 prefs.css_grid_layout_enabled =
527 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]d7932532012-11-21 21:10:31528
529 bool touch_device_present = false;
[email protected]c71fe6402012-08-15 15:22:55530#if defined(USE_AURA) && defined(USE_X11)
[email protected]d7932532012-11-21 21:10:31531 touch_device_present =
[email protected]c71fe6402012-08-15 15:22:55532 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
533#endif
[email protected]25ee94f2012-09-11 19:16:16534#if defined(OS_WIN)
[email protected]d7932532012-11-21 21:10:31535 touch_device_present = ui::IsTouchDevicePresent();
[email protected]25ee94f2012-09-11 19:16:16536#endif
[email protected]d849b122012-07-18 07:35:26537#if defined(OS_ANDROID)
[email protected]d7932532012-11-21 21:10:31538 touch_device_present = true;
539#endif
540 const std::string touch_enabled_switch =
541 command_line.HasSwitch(switches::kTouchEvents) ?
542 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
543 switches::kTouchEventsAuto;
544
545 if (touch_enabled_switch.empty() ||
546 touch_enabled_switch == switches::kTouchEventsEnabled) {
547 prefs.touch_enabled = true;
548 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
549 prefs.touch_enabled = touch_device_present;
550 } else if (touch_enabled_switch != switches::kTouchEventsDisabled) {
551 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
552 }
553
554 prefs.device_supports_touch = prefs.touch_enabled && touch_device_present;
555#if defined(OS_ANDROID)
[email protected]d849b122012-07-18 07:35:26556 prefs.device_supports_mouse = false;
557#endif
[email protected]64d69de42012-02-06 00:19:54558
[email protected]b9c96ff2012-11-26 22:24:40559 prefs.touch_adjustment_enabled =
560 !command_line.HasSwitch(switches::kDisableTouchAdjustment);
561
[email protected]2a5e9d02013-01-20 01:09:25562#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
[email protected]64d69de42012-02-06 00:19:54563 bool default_enable_scroll_animator = true;
564#else
[email protected]64d69de42012-02-06 00:19:54565 bool default_enable_scroll_animator = false;
566#endif
567 prefs.enable_scroll_animator = default_enable_scroll_animator;
568 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
569 prefs.enable_scroll_animator = true;
570 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
571 prefs.enable_scroll_animator = false;
572
573 prefs.visual_word_movement_enabled =
574 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54575
576 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32577 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54578 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39579 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21580 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54581 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21582 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54583 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21584 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19585 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21586 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19587 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21588 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54589 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21590 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54591 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21592 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]9bdcfd642012-11-14 21:24:26593 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
594 prefs.accelerated_compositing_for_animation_enabled = false;
[email protected]c521d7462012-10-03 22:28:20595 }
[email protected]8ff00d72012-10-23 19:12:21596 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]9bdcfd642012-11-14 21:24:26597 prefs.accelerated_compositing_for_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54598
599 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45600 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32601 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]9bdcfd642012-11-14 21:24:26602 prefs.accelerated_compositing_for_video_enabled = false;
603 prefs.accelerated_compositing_for_animation_enabled = false;
604 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
605 prefs.accelerated_compositing_for_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54606 }
607 }
608
[email protected]b9535422012-02-09 01:47:59609 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58610 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54611 prefs.loads_images_automatically = true;
612 prefs.javascript_enabled = true;
613 }
614
615 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
616
[email protected]2ee33532013-01-17 12:27:03617 // Force accelerated compositing and 2d canvas off for chrome: and about:
618 // pages (unless it's specifically allowed).
619 if ((url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]64d69de42012-02-06 00:19:54620 (url.SchemeIs(chrome::kAboutScheme) &&
621 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25622 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54623 prefs.accelerated_compositing_enabled = false;
624 prefs.accelerated_2d_canvas_enabled = false;
625 }
[email protected]43d9d782012-03-01 15:40:09626
[email protected]2ee33532013-01-17 12:27:03627 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
628 prefs.show_fps_counter = false;
629
[email protected]f98f5092012-05-19 00:08:14630 if (command_line.HasSwitch(switches::kDefaultTileWidth))
631 prefs.default_tile_width =
632 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
633 if (command_line.HasSwitch(switches::kDefaultTileHeight))
634 prefs.default_tile_height =
635 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
636 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
637 prefs.max_untiled_layer_width =
638 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
639 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
640 prefs.max_untiled_layer_height =
641 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
642
[email protected]ffabb1e2012-10-12 19:51:17643 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
644 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19645 // Only apply when using DIP coordinate system as this setting interferes
646 // with fixed layout mode.
[email protected]9bdcfd642012-11-14 21:24:26647 // TODO(danakj): Fixed layout mode is going away, so turn this on always.
[email protected]2486dce2012-05-23 17:18:19648 prefs.apply_default_device_scale_factor_in_compositor = true;
649 }
650
[email protected]9bdcfd642012-11-14 21:24:26651 prefs.apply_page_scale_factor_in_compositor =
[email protected]16ad47f82012-12-05 21:06:06652 command_line.HasSwitch(switches::kEnablePinch);
[email protected]f49dece2013-01-12 19:04:28653
654 if (command_line.HasSwitch(switches::kEnableCssTransformPinch)) {
655 prefs.apply_default_device_scale_factor_in_compositor = false;
656 prefs.apply_page_scale_factor_in_compositor = false;
657 }
658
[email protected]9bdcfd642012-11-14 21:24:26659 prefs.per_tile_painting_enabled =
660 command_line.HasSwitch(cc::switches::kEnablePerTilePainting);
[email protected]cf6cb622012-11-16 02:00:19661 prefs.accelerated_animation_enabled =
[email protected]9bdcfd642012-11-14 21:24:26662 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
663
[email protected]de023762012-07-26 17:10:17664 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
665 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10666
[email protected]e755a382012-09-13 17:16:35667 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
668 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12669
[email protected]6b4dcb072012-06-18 22:26:51670 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
671
[email protected]5c90d03d2013-01-10 17:16:02672 prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport);
673
[email protected]76f7d4882012-10-26 21:09:22674 prefs.deferred_image_decoding_enabled =
675 command_line.HasSwitch(switches::kEnableDeferredImageDecoding);
676
[email protected]8ff00d72012-10-23 19:12:21677 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54678
[email protected]97456602012-10-03 18:44:25679 // Disable compositing in guests until we have compositing path implemented
680 // for guests.
[email protected]747c30652012-12-18 20:35:53681 bool guest_compositing_enabled = command_line.HasSwitch(
682 switches::kEnableBrowserPluginCompositing);
683 if (rvh->GetProcess()->IsGuest() && !guest_compositing_enabled) {
[email protected]97456602012-10-03 18:44:25684 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06685 prefs.accelerated_compositing_enabled = false;
686 }
[email protected]97456602012-10-03 18:44:25687
[email protected]64d69de42012-02-06 00:19:54688 return prefs;
689}
690
[email protected]b172aee2012-04-10 17:05:26691RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28692 return &render_manager_;
693}
694
[email protected]7bb761892012-07-20 09:32:47695bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
696 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56697 if (GetWebUI() &&
698 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17699 return true;
[email protected]d2353452012-01-19 19:53:56700 }
[email protected]f82d57b52011-04-27 19:13:17701
[email protected]d8c660432011-12-22 20:51:25702 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
703 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10704 while ((observer = it.GetNext()) != NULL)
705 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53706 return true;
[email protected]403415a2011-01-10 18:57:53707
[email protected]7bb761892012-07-20 09:32:47708 // Message handlers should be aware of which RenderViewHost sent the
709 // message, which is temporarily stored in message_source_.
710 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18711 bool handled = true;
712 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26713 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58714 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
715 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24716 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
717 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18718 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
719 OnDidLoadResourceFromMemoryCache)
720 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
721 OnDidDisplayInsecureContent)
722 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
723 OnDidRunInsecureContent)
724 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
725 OnDocumentLoadedInFrame)
726 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26727 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
728 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17729 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
730 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25731 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26732 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59733 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21734 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20735 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
736 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
737 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16738 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45739 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10740 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20741 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
742 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
743 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
744 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29745 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50746 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50747 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
748 OnRequestPpapiBrokerPermission)
[email protected]b479912c2013-01-23 00:07:08749 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID,
750 OnBrowserPluginAllocateInstanceID)
[email protected]795c28972012-12-06 06:13:39751 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
752 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10753#if defined(OS_ANDROID)
754 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
755 OnFindMatchRectsReply)
756 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
757 OnOpenDateTimeDialog)
758#endif
[email protected]8607c832013-01-18 14:11:57759 IPC_MESSAGE_HANDLER(ViewHostMsg_FrameDetached, OnFrameDetached)
[email protected]724159a2010-12-30 01:11:18760 IPC_MESSAGE_UNHANDLED(handled = false)
761 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47762 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18763
764 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21765 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18766 GetRenderProcessHost()->ReceivedBadMessage();
767 }
768
769 return handled;
770}
771
[email protected]b172aee2012-04-10 17:05:26772void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18773 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21774 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43775 if (delegate_)
776 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18777}
778
[email protected]d1198fd2012-08-13 22:50:19779NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56780 return controller_;
781}
782
[email protected]d1198fd2012-08-13 22:50:19783const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56784 return controller_;
785}
786
[email protected]8ff00d72012-10-23 19:12:21787BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55788 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30789}
790
[email protected]b172aee2012-04-10 17:05:26791const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31792 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23793 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51794 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31795}
796
[email protected]8ff00d72012-10-23 19:12:21797WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31798 return delegate_;
799}
800
[email protected]8ff00d72012-10-23 19:12:21801void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31802 // TODO(cbentzel): remove this debugging code?
803 if (delegate == delegate_)
804 return;
805 if (delegate_)
806 delegate_->Detach(this);
807 delegate_ = delegate;
808 if (delegate_)
809 delegate_->Attach(this);
810}
811
[email protected]8ff00d72012-10-23 19:12:21812RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41813 RenderViewHostImpl* host = render_manager_.current_host();
814 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16815}
816
[email protected]b172aee2012-04-10 17:05:26817RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31818 return render_manager_.current_host();
819}
820
[email protected]a04c9d02012-11-14 21:04:34821void WebContentsImpl::GetRenderViewHostAtPosition(
822 int x,
823 int y,
824 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
825 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
826 if (embedder)
827 embedder->GetRenderViewHostAtPosition(x, y, callback);
828 else
829 callback.Run(GetRenderViewHost(), x, y);
830}
831
[email protected]6b618e62012-08-16 12:59:18832int WebContentsImpl::GetRoutingID() const {
833 if (!GetRenderViewHost())
834 return MSG_ROUTING_NONE;
835
836 return GetRenderViewHost()->GetRoutingID();
837}
838
[email protected]44470a22013-01-24 01:21:54839int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
840 return fullscreen_widget_routing_id_;
841}
842
[email protected]b172aee2012-04-10 17:05:26843RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31844 return render_manager_.GetRenderWidgetHostView();
845}
846
[email protected]8ff00d72012-10-23 19:12:21847WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31848 return view_.get();
849}
850
[email protected]8ff00d72012-10-23 19:12:21851WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]3c788372013-01-10 08:34:28852 WebUIControllerFactory* factory =
853 GetContentClient()->browser()->GetWebUIControllerFactory();
854 if (!factory)
855 return NULL;
[email protected]d2353452012-01-19 19:53:56856 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]3c788372013-01-10 08:34:28857 WebUIController* controller =
858 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22859 if (controller) {
860 web_ui->SetController(controller);
861 return web_ui;
862 }
863
864 delete web_ui;
865 return NULL;
866}
867
[email protected]8ff00d72012-10-23 19:12:21868WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31869 return render_manager_.web_ui() ? render_manager_.web_ui()
870 : render_manager_.pending_web_ui();
871}
872
[email protected]8ff00d72012-10-23 19:12:21873WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31874 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34875}
876
[email protected]86ef6a392012-05-11 22:03:11877void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22878 if (GetUserAgentOverride() == override)
879 return;
880
881 renderer_preferences_.user_agent_override = override;
882
883 // Send the new override string to the renderer.
884 RenderViewHost* host = GetRenderViewHost();
885 if (host)
886 host->SyncRendererPrefs();
887
888 // Reload the page if a load is currently in progress to avoid having
889 // different parts of the page loaded using different user agents.
890 NavigationEntry* entry = controller_.GetActiveEntry();
891 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
892 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53893
894 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
895 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11896}
897
898const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22899 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11900}
901
[email protected]b172aee2012-04-10 17:05:26902const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55903 // Transient entries take precedence. They are used for interstitial pages
904 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23905 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08906 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21907 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30908 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23909 if (entry) {
[email protected]b5cca982011-05-26 04:42:08910 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23911 }
[email protected]7ade2732011-02-10 00:13:58912 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
913 render_manager_.pending_web_ui() : render_manager_.web_ui();
914 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54915 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55916 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54917 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35918 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22919 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54920 if (!title.empty())
921 return title;
922 }
923 }
924
925 // We use the title for the last committed entry rather than a pending
926 // navigation entry. For example, when the user types in a URL, we want to
927 // keep the old page's title until the new load has committed and we get a new
928 // title.
[email protected]96d185d2009-04-24 03:28:54929 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23930 if (entry) {
[email protected]b5cca982011-05-26 04:42:08931 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23932 }
[email protected]987fc3a2011-05-26 14:18:09933
934 // |page_title_when_no_navigation_entry_| is finally used
935 // if no title cannot be retrieved.
936 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54937}
938
[email protected]b172aee2012-04-10 17:05:26939int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46940 return GetMaxPageIDForSiteInstance(GetSiteInstance());
941}
942
[email protected]b172aee2012-04-10 17:05:26943int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
944 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33945 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
946 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46947
[email protected]b6583592012-01-25 19:52:33948 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34949}
950
[email protected]b172aee2012-04-10 17:05:26951void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46952 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
953}
954
[email protected]b172aee2012-04-10 17:05:26955void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33956 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46957 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33958 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34959}
960
[email protected]b172aee2012-04-10 17:05:26961void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
962 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57963}
964
[email protected]b172aee2012-04-10 17:05:26965SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58966 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54967}
968
[email protected]b172aee2012-04-10 17:05:26969SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38970 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
971 render_manager_.pending_render_view_host() :
972 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58973 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38974}
975
[email protected]b172aee2012-04-10 17:05:26976bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31977 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49978}
979
[email protected]b172aee2012-04-10 17:05:26980bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31981 return waiting_for_response_;
982}
983
[email protected]b172aee2012-04-10 17:05:26984const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31985 return load_state_;
986}
987
[email protected]b172aee2012-04-10 17:05:26988const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31989 return load_state_host_;
990}
991
[email protected]b172aee2012-04-10 17:05:26992uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31993 return upload_size_;
994}
995
[email protected]b172aee2012-04-10 17:05:26996uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31997 return upload_position_;
998}
999
[email protected]b172aee2012-04-10 17:05:261000const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:311001 return encoding_;
1002}
1003
[email protected]b172aee2012-04-10 17:05:261004bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311005 return displayed_insecure_content_;
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:311009 capturing_contents_ = cap;
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311013 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1014 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1015 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491016}
1017
[email protected]b172aee2012-04-10 17:05:261018void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1019 int error_code) {
[email protected]443b80e2010-12-14 00:42:231020 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341021 return;
1022
[email protected]443b80e2010-12-14 00:42:231023 crashed_status_ = status;
1024 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211025 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341026}
1027
[email protected]b172aee2012-04-10 17:05:261028base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311029 return crashed_status_;
1030}
1031
[email protected]b172aee2012-04-10 17:05:261032bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311033 return is_being_destroyed_;
1034}
1035
[email protected]b172aee2012-04-10 17:05:261036void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341037 if (delegate_)
1038 delegate_->NavigationStateChanged(this, changed_flags);
1039}
1040
[email protected]3e324142012-06-25 18:26:331041base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1042 return last_selected_time_;
1043}
1044
[email protected]9e2e4632012-07-27 16:38:411045void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541046 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041047 RenderWidgetHostViewPort* rwhv =
1048 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161049 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411050 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431051#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161052 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431053#endif
1054 }
[email protected]96d185d2009-04-24 03:28:541055
[email protected]5ac20162010-11-24 23:33:111056 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381057
[email protected]9e2e4632012-07-27 16:38:411058 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591059
1060 // The resize rect might have changed while this was inactive -- send the new
1061 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581062 RenderViewHostImpl* rvh =
1063 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591064 if (rvh) {
1065 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1066 }
[email protected]96d185d2009-04-24 03:28:541067
[email protected]3e324142012-06-25 18:26:331068 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211069 NotificationService::current()->Notify(
1070 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1071 Source<WebContents>(this),
1072 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311073}
1074
[email protected]b172aee2012-04-10 17:05:261075void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311076 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521077 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1078 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261079 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521080 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331081 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521082 // calls us).
[email protected]c30585c2012-02-16 15:02:041083 RenderWidgetHostViewPort* rwhv =
1084 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161085 if (rwhv)
1086 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541087 }
1088
[email protected]375fa1b2012-05-22 22:05:371089 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211090 NotificationService::current()->Notify(
1091 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1092 Source<WebContents>(this),
1093 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371094}
1095
[email protected]b172aee2012-04-10 17:05:261096bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311097 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271098 return WillNotifyDisconnection() &&
1099 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581100 !static_cast<RenderViewHostImpl*>(
1101 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311102}
1103
[email protected]b172aee2012-04-10 17:05:261104void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271105 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251106 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271107}
1108
[email protected]b172aee2012-04-10 17:05:261109WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441110 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451111 // We pass our own opener so that the cloned page can access it if it was
1112 // before.
[email protected]54944cde2012-12-09 09:24:591113 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451114 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591115 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191116 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221117 FOR_EACH_OBSERVER(WebContentsObserver,
1118 observers_,
1119 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271120 return tc;
1121}
1122
[email protected]b172aee2012-04-10 17:05:261123gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271124 return view_->GetContentNativeView();
1125}
1126
[email protected]b172aee2012-04-10 17:05:261127gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271128 return view_->GetNativeView();
1129}
1130
[email protected]b172aee2012-04-10 17:05:261131void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271132 view_->GetContainerBounds(out);
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271136 view_->Focus();
1137}
1138
[email protected]14392a52012-05-02 20:28:441139void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211140 const NotificationSource& source,
1141 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441142 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211143 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1144 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441145 break;
[email protected]8ff00d72012-10-23 19:12:211146 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1147 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501148 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1149 i != pending_widget_views_.end(); ++i) {
1150 if (host->GetView() == i->second) {
1151 pending_widget_views_.erase(i);
1152 break;
1153 }
1154 }
1155 break;
1156 }
[email protected]14392a52012-05-02 20:28:441157 default:
1158 NOTREACHED();
1159 }
1160}
1161
[email protected]54944cde2012-12-09 09:24:591162void WebContentsImpl::Init(const WebContents::CreateParams& params) {
1163 render_manager_.Init(
1164 params.browser_context, params.site_instance, params.routing_id);
[email protected]d1198fd2012-08-13 22:50:191165
[email protected]8ff00d72012-10-23 19:12:211166 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191167 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1168 if (view_.get()) {
1169 CHECK(render_view_host_delegate_view_);
1170 } else {
[email protected]b5a40842012-11-28 15:26:111171 if (browser_plugin_guest_.get() &&
1172 CommandLine::ForCurrentProcess()->HasSwitch(
1173 switches::kEnableBrowserPluginCompositing)) {
1174 WebContentsViewGuest* rv = new WebContentsViewGuest(
1175 this,
1176 browser_plugin_guest_.get());
1177 render_view_host_delegate_view_ = rv;
1178 view_.reset(rv);
1179 } else {
1180 WebContentsViewDelegate* delegate =
1181 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1182 view_.reset(CreateWebContentsView(
1183 this, delegate, &render_view_host_delegate_view_));
1184 }
[email protected]d1198fd2012-08-13 22:50:191185 CHECK(render_view_host_delegate_view_);
1186 }
1187 CHECK(view_.get());
1188
[email protected]ed245db2012-12-18 08:00:451189 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591190 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191191
1192 // Listen for whether our opener gets destroyed.
1193 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211194 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1195 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191196 }
1197
1198 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211199 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1200 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191201#if defined(ENABLE_JAVA_BRIDGE)
1202 java_bridge_dispatcher_host_manager_.reset(
1203 new JavaBridgeDispatcherHostManager(this));
1204#endif
[email protected]583418cc2013-01-17 14:01:101205
1206#if defined(OS_ANDROID)
1207 date_time_chooser_.reset(new DateTimeChooserAndroid());
1208#endif
[email protected]d1198fd2012-08-13 22:50:191209}
1210
[email protected]14392a52012-05-02 20:28:441211void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1212 // Clear the opener if it has been closed.
1213 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211214 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1215 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441216 opener_ = NULL;
1217 }
1218}
1219
[email protected]b172aee2012-04-10 17:05:261220void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311221 observers_.AddObserver(observer);
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311225 observers_.RemoveObserver(observer);
1226}
1227
[email protected]b172aee2012-04-10 17:05:261228void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341229 if (delegate_)
1230 delegate_->ActivateContents(this);
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121234 if (delegate_)
1235 delegate_->DeactivateContents(this);
1236}
1237
[email protected]b172aee2012-04-10 17:05:261238void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481239 if (delegate_)
1240 delegate_->LostCapture();
1241}
1242
[email protected]b24b68a2012-09-24 21:57:261243void WebContentsImpl::RenderWidgetDeleted(
1244 RenderWidgetHostImpl* render_widget_host) {
1245 if (is_being_destroyed_) {
1246 // |created_widgets_| might have been destroyed.
1247 return;
1248 }
1249
1250 std::set<RenderWidgetHostImpl*>::iterator iter =
1251 created_widgets_.find(render_widget_host);
1252 if (iter != created_widgets_.end())
1253 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541254
1255 if (render_widget_host &&
1256 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
1257 FOR_EACH_OBSERVER(WebContentsObserver,
1258 observers_,
1259 DidDestroyFullscreenWidget(
1260 fullscreen_widget_routing_id_));
1261 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1262 }
[email protected]b24b68a2012-09-24 21:57:261263}
1264
[email protected]b172aee2012-04-10 17:05:261265bool WebContentsImpl::PreHandleKeyboardEvent(
1266 const NativeWebKeyboardEvent& event,
1267 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481268 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131269 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481270}
1271
[email protected]b172aee2012-04-10 17:05:261272void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481273 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131274 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481275}
1276
[email protected]b172aee2012-04-10 17:05:261277void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431278 if (delegate_)
1279 delegate_->HandleMouseDown();
1280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481283 if (delegate_)
1284 delegate_->HandleMouseUp();
1285}
1286
[email protected]590a634e2012-07-19 16:38:231287void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481288 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231289 delegate_->HandlePointerActivate();
1290}
1291
1292void WebContentsImpl::HandleGestureBegin() {
1293 if (delegate_)
1294 delegate_->HandleGestureBegin();
1295}
1296
1297void WebContentsImpl::HandleGestureEnd() {
1298 if (delegate_)
1299 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481300}
1301
[email protected]b172aee2012-04-10 17:05:261302void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471303 if (delegate_)
1304 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381308 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121309}
1310
[email protected]a9c81f02012-06-01 00:15:441311void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1312 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371313 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441314 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371315 } else {
1316 GotResponseToLockMouseRequest(false);
1317 }
1318}
1319
[email protected]b172aee2012-04-10 17:05:261320void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371321 if (delegate_)
1322 delegate_->LostMouseLock();
1323}
1324
[email protected]bafe6cd2012-05-23 23:09:501325void WebContentsImpl::CreateNewWindow(
1326 int route_id,
[email protected]97714c82012-06-06 10:15:131327 const ViewHostMsg_CreateWindow_Params& params,
1328 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501329 if (delegate_ && !delegate_->ShouldCreateWebContents(
1330 this, route_id, params.window_container_type, params.frame_name,
1331 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091332 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501333 return;
1334 }
1335
1336 // We usually create the new window in the same BrowsingInstance (group of
1337 // script-related windows), by passing in the current SiteInstance. However,
1338 // if the opener is being suppressed, we create a new SiteInstance in its own
1339 // BrowsingInstance.
1340 scoped_refptr<SiteInstance> site_instance =
1341 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571342 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501343 GetSiteInstance();
1344
1345 // Create the new web contents. This will automatically create the new
1346 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191347 WebContentsImpl* new_contents =
1348 new WebContentsImpl(GetBrowserContext(),
1349 params.opener_suppressed ? NULL : this);
1350
1351 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341352 //
1353 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191354 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211355 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571356 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591357 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211358 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341359 BrowserContext::GetStoragePartition(GetBrowserContext(),
1360 site_instance);
[email protected]d1198fd2012-08-13 22:50:191361 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341362 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191363 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1364 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1365 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1366 new_contents->GetController().SetSessionStorageNamespace(
1367 partition_id,
1368 session_storage_namespace);
[email protected]54944cde2012-12-09 09:24:591369 CreateParams create_params(GetBrowserContext(), site_instance);
1370 create_params.routing_id = route_id;
[email protected]ed245db2012-12-18 08:00:451371 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591372 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191373
[email protected]bafe6cd2012-05-23 23:09:501374 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1375
1376 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211377 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501378
1379 // TODO(brettw): It seems bogus that we have to call this function on the
1380 // newly created object and give it one of its own member variables.
1381 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1382
1383 // Save the created window associated with the route so we can show it
1384 // later.
1385 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1386 pending_contents_[route_id] = new_contents;
1387 }
1388
1389 if (delegate_) {
1390 delegate_->WebContentsCreated(
1391 this, params.opener_frame_id, params.target_url, new_contents);
1392 }
1393
1394 if (params.opener_suppressed) {
1395 // When the opener is suppressed, the original renderer cannot access the
1396 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001397 bool was_blocked = false;
1398 if (delegate_) {
1399 gfx::Rect initial_pos;
1400 delegate_->AddNewContents(
1401 this, new_contents, params.disposition, initial_pos,
1402 params.user_gesture, &was_blocked);
1403 }
1404 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211405 OpenURLParams open_params(params.target_url,
1406 Referrer(),
1407 CURRENT_TAB,
1408 PAGE_TRANSITION_LINK,
1409 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001410 new_contents->OpenURL(open_params);
1411 }
[email protected]bafe6cd2012-05-23 23:09:501412 }
1413}
1414
1415void WebContentsImpl::CreateNewWidget(int route_id,
1416 WebKit::WebPopupType popup_type) {
1417 CreateNewWidget(route_id, false, popup_type);
1418}
1419
1420void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1421 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1422}
1423
1424void WebContentsImpl::CreateNewWidget(int route_id,
1425 bool is_fullscreen,
1426 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211427 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501428 RenderWidgetHostImpl* widget_host =
1429 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261430 created_widgets_.insert(widget_host);
1431
[email protected]83918ec2013-01-10 15:37:191432 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1433 view_->CreateViewForPopupWidget(widget_host));
1434 if (!widget_view)
1435 return;
[email protected]bafe6cd2012-05-23 23:09:501436 if (!is_fullscreen) {
1437 // Popups should not get activated.
1438 widget_view->SetPopupType(popup_type);
1439 }
1440 // Save the created widget associated with the route so we can show it later.
1441 pending_widget_views_[route_id] = widget_view;
1442
1443#if defined(OS_MACOSX)
1444 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1445 // to allow it to survive the trip without being hosted.
1446 base::mac::NSObjectRetain(widget_view->GetNativeView());
1447#endif
1448}
1449
1450void WebContentsImpl::ShowCreatedWindow(int route_id,
1451 WindowOpenDisposition disposition,
1452 const gfx::Rect& initial_pos,
1453 bool user_gesture) {
1454 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001455 if (contents) {
1456 WebContentsDelegate* delegate = GetDelegate();
1457 if (delegate) {
1458 delegate->AddNewContents(
1459 this, contents, disposition, initial_pos, user_gesture, NULL);
1460 }
1461 }
[email protected]bafe6cd2012-05-23 23:09:501462}
1463
1464void WebContentsImpl::ShowCreatedWidget(int route_id,
1465 const gfx::Rect& initial_pos) {
1466 ShowCreatedWidget(route_id, false, initial_pos);
1467}
1468
1469void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1470 ShowCreatedWidget(route_id, true, gfx::Rect());
[email protected]44470a22013-01-24 01:21:541471
1472 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1473 fullscreen_widget_routing_id_ = route_id;
1474 FOR_EACH_OBSERVER(WebContentsObserver,
1475 observers_,
1476 DidShowFullscreenWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501477}
1478
1479void WebContentsImpl::ShowCreatedWidget(int route_id,
1480 bool is_fullscreen,
1481 const gfx::Rect& initial_pos) {
1482 if (delegate_)
1483 delegate_->RenderWidgetShowing();
1484
1485 RenderWidgetHostViewPort* widget_host_view =
1486 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1487 if (!widget_host_view)
1488 return;
1489 if (is_fullscreen) {
1490 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1491 } else {
1492 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1493 }
[email protected]89054502012-06-03 10:29:241494
1495 RenderWidgetHostImpl* render_widget_host_impl =
1496 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1497 render_widget_host_impl->Init();
1498 // Only allow privileged mouse lock for fullscreen render widget, which is
1499 // used to implement Pepper Flash fullscreen.
1500 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501501
1502#if defined(OS_MACOSX)
1503 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1504 // properly embedded (or purposefully ignored) we can release the retain we
1505 // took in CreateNewWidget().
1506 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1507#endif
1508}
1509
1510WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1511 PendingContents::iterator iter = pending_contents_.find(route_id);
1512
1513 // Certain systems can block the creation of new windows. If we didn't succeed
1514 // in creating one, just return NULL.
1515 if (iter == pending_contents_.end()) {
1516 return NULL;
1517 }
1518
1519 WebContentsImpl* new_contents = iter->second;
1520 pending_contents_.erase(route_id);
1521
1522 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1523 !new_contents->GetRenderViewHost()->GetView())
1524 return NULL;
1525
1526 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1527 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1528 return new_contents;
1529}
1530
1531RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1532 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1533 if (iter == pending_widget_views_.end()) {
1534 DCHECK(false);
1535 return NULL;
1536 }
1537
1538 RenderWidgetHostView* widget_host_view = iter->second;
1539 pending_widget_views_.erase(route_id);
1540
1541 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1542 if (!widget_host->GetProcess()->HasConnection()) {
1543 // The view has gone away or the renderer crashed. Nothing to do.
1544 return NULL;
1545 }
1546
1547 return widget_host_view;
1548}
1549
1550void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211551 const ContextMenuParams& params,
1552 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501553 // Allow WebContentsDelegates to handle the context menu operation first.
1554 if (delegate_ && delegate_->HandleContextMenu(params))
1555 return;
1556
[email protected]ba16e3a2012-09-07 04:14:521557 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501558}
1559
[email protected]f13b4202012-06-12 23:53:231560void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091561 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211562 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231563 if (delegate_)
1564 delegate_->RequestMediaAccessPermission(this, request, callback);
1565 else
[email protected]8ff00d72012-10-23 19:12:211566 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231567}
1568
[email protected]b172aee2012-04-10 17:05:261569void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231570 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331571 if (delegate_)
1572 delegate_->UpdatePreferredSize(this, pref_size);
1573}
1574
[email protected]b172aee2012-04-10 17:05:261575void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341576 if (delegate_)
1577 delegate_->ResizeDueToAutoResize(this, new_size);
1578}
1579
[email protected]b172aee2012-04-10 17:05:261580WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201581 if (!delegate_)
1582 return NULL;
[email protected]00c37fc2011-08-02 00:22:501583
[email protected]e5d549d2011-12-28 01:29:201584 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201585 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341586}
1587
[email protected]6b618e62012-08-16 12:59:181588bool WebContentsImpl::Send(IPC::Message* message) {
1589 if (!GetRenderViewHost()) {
1590 delete message;
1591 return false;
1592 }
1593
1594 return GetRenderViewHost()->Send(message);
1595}
1596
[email protected]b172aee2012-04-10 17:05:261597bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501598 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251599 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231600 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251601 reload_type);
[email protected]876bc832010-09-07 16:29:541602}
[email protected]96d185d2009-04-24 03:28:541603
[email protected]ba45bfd2012-05-22 21:51:441604void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211605 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441606 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1607 RenderViewForInterstitialPageCreated(render_view_host));
1608}
1609
[email protected]b172aee2012-04-10 17:05:261610bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231611 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501612 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401613 // The renderer will reject IPC messages with URLs longer than
1614 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211615 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401616 return false;
1617
[email protected]9f76c1e2012-03-05 15:15:581618 RenderViewHostImpl* dest_render_view_host =
1619 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401620 if (!dest_render_view_host)
1621 return false; // Unable to create the desired render view host.
1622
[email protected]80a8fad2011-01-29 04:02:381623 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071624 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581625 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]3c788372013-01-10 08:34:281626 WebUIControllerFactory* factory =
1627 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271628 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501629 bool is_allowed_in_web_ui_renderer =
[email protected]3c788372013-01-10 08:34:281630 factory &&
1631 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1632 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211633 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231634 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271635 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211636 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231637 CHECK(0);
1638 }
[email protected]54ec6472010-04-09 19:39:581639
[email protected]7bb761892012-07-20 09:32:471640 // Notify observers that we will navigate in this RV.
1641 FOR_EACH_OBSERVER(WebContentsObserver,
1642 observers_,
1643 AboutToNavigateRenderView(dest_render_view_host));
1644
[email protected]96d185d2009-04-24 03:28:541645 // Used for page load time metrics.
1646 current_load_start_ = base::TimeTicks::Now();
1647
1648 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341649 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271650 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471651 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341652 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541653
[email protected]36fc0392011-12-25 03:59:511654 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541655 // HACK!! This code suppresses javascript: URLs from being added to
1656 // session history, which is what we want to do for javascript: URLs that
1657 // do not generate content. What we really need is a message from the
1658 // renderer telling us that a new page was not created. The same message
1659 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511660 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541661 return false;
1662 }
1663
[email protected]3c9e1872010-11-18 16:17:491664 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251665 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041666 observers_,
[email protected]36fc0392011-12-25 03:59:511667 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541668
[email protected]09b29342011-06-24 19:18:481669 if (delegate_)
1670 delegate_->DidNavigateToPendingEntry(this);
1671
[email protected]d5f942ba2008-09-26 19:30:341672 return true;
1673}
1674
[email protected]b172aee2012-04-10 17:05:261675void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331676 const SiteInstance* site_instance,
1677 int history_length,
1678 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411679 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1680 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191681 if (render_manager_.pending_render_view_host()) {
1682 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141683 return;
[email protected]9e1ad4b2011-08-14 16:49:191684 }
[email protected]9f76c1e2012-03-05 15:15:581685 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191686 if (!rvh) {
1687 NOTREACHED();
1688 return;
1689 }
[email protected]9f76c1e2012-03-05 15:15:581690 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191691 NOTREACHED();
1692 return;
1693 }
[email protected]6b618e62012-08-16 12:59:181694 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1695 history_length,
1696 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271700 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541701 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1702 return;
1703 }
[email protected]9f76c1e2012-03-05 15:15:581704 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541705}
1706
[email protected]b172aee2012-04-10 17:05:261707bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271708 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541709}
1710
[email protected]b172aee2012-04-10 17:05:261711InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271712 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221713}
1714
[email protected]b172aee2012-04-10 17:05:261715bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161716 // WebKit creates Document object when MIME type is application/xhtml+xml,
1717 // so we also support this MIME type.
1718 return contents_mime_type_ == "text/html" ||
1719 contents_mime_type_ == "text/xml" ||
1720 contents_mime_type_ == "application/xhtml+xml" ||
1721 contents_mime_type_ == "text/plain" ||
1722 contents_mime_type_ == "text/css" ||
1723 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591727 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161728 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551729 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211730 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141731 return;
[email protected]c7dd2f62011-07-18 15:57:591732 }
1733
1734 Stop();
1735
1736 // Create the save package and possibly prompt the user for the name to save
1737 // the page as. The user prompt is an asynchronous operation that runs on
1738 // another thread.
1739 save_package_ = new SavePackage(this);
1740 save_package_->GetSaveInfo();
1741}
1742
1743// Used in automated testing to bypass prompting the user for file names.
1744// Instead, the names and paths are hard coded rather than running them through
1745// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261746bool WebContentsImpl::SavePage(const FilePath& main_file,
1747 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211748 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591749 // Stop the page from navigating.
1750 Stop();
1751
1752 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211753 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591754}
1755
[email protected]b172aee2012-04-10 17:05:261756void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121757 const FilePath& file,
1758 const base::Callback<void(const FilePath&, int64)>& callback) {
1759 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1760}
1761
[email protected]b172aee2012-04-10 17:05:261762bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231763 NavigationEntryImpl* active_entry =
1764 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321765 return (active_entry != NULL &&
1766 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511767 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321768}
1769
[email protected]b172aee2012-04-10 17:05:261770const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271771 return contents_mime_type_;
1772}
1773
[email protected]b172aee2012-04-10 17:05:261774bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271775 return notify_disconnection_;
1776}
1777
[email protected]b172aee2012-04-10 17:05:261778void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311779 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181780 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161781}
1782
[email protected]b172aee2012-04-10 17:05:261783void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311784 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181785 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161786}
1787
[email protected]8ff00d72012-10-23 19:12:211788RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271789 return &renderer_preferences_;
1790}
1791
[email protected]b172aee2012-04-10 17:05:261792void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271793 new_tab_start_time_ = time;
1794}
1795
[email protected]b172aee2012-04-10 17:05:261796base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271797 return new_tab_start_time_;
1798}
1799
[email protected]e35ccd52012-05-23 16:22:471800void WebContentsImpl::Close() {
1801 Close(GetRenderViewHost());
1802}
1803
[email protected]b172aee2012-04-10 17:05:261804void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151805 if (close_start_time_.is_null())
1806 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011807}
1808
[email protected]b172aee2012-04-10 17:05:261809bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191810#if defined(OS_CHROMEOS)
1811 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1812 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511813 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201814 return false;
1815 return true;
[email protected]46624bf2010-06-09 16:04:191816#else
1817 return true;
1818#endif
1819}
1820
[email protected]b172aee2012-04-10 17:05:261821void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521822 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581823 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511824 if (delegate_)
1825 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341826}
1827
[email protected]e35ccd52012-05-23 16:22:471828void WebContentsImpl::UserGestureDone() {
1829 OnUserGesture();
1830}
1831
[email protected]b172aee2012-04-10 17:05:261832void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271833 closed_by_user_gesture_ = value;
1834}
1835
[email protected]b172aee2012-04-10 17:05:261836bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271837 return closed_by_user_gesture_;
1838}
1839
[email protected]b172aee2012-04-10 17:05:261840double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051841 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561842 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251843 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171844 return 0;
[email protected]b75b8292010-10-01 07:28:251845
1846 double zoom_level;
1847 if (temporary_zoom_settings_) {
1848 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581849 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251850 } else {
[email protected]2ae88d12011-10-14 09:11:191851 GURL url;
[email protected]10f417c52011-12-28 21:04:231852 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191853 // Since zoom map is updated using rewritten URL, use rewritten URL
1854 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511855 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191856 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251857 }
[email protected]d0b8d092010-10-25 04:05:171858 return zoom_level;
1859}
[email protected]b75b8292010-10-01 07:28:251860
[email protected]b172aee2012-04-10 17:05:261861int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591862 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171863 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011864 // Calculate the zoom percent from the factor. Round up to the nearest whole
1865 // number.
[email protected]b75b8292010-10-01 07:28:251866 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011867 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251868 *enable_decrement = percent > minimum_zoom_percent_;
1869 *enable_increment = percent < maximum_zoom_percent_;
1870 return percent;
1871}
1872
[email protected]b172aee2012-04-10 17:05:261873void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501874 if (!delegate_)
1875 return;
1876
[email protected]10f417c52011-12-28 21:04:231877 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501878 if (!active_entry)
1879 return;
1880
[email protected]36fc0392011-12-25 03:59:511881 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121882}
1883
[email protected]b172aee2012-04-10 17:05:261884void WebContentsImpl::ViewFrameSource(const GURL& url,
1885 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271886 if (!delegate_)
1887 return;
1888
1889 delegate_->ViewSourceForFrame(this, url, content_state);
1890}
1891
[email protected]b172aee2012-04-10 17:05:261892int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271893 return minimum_zoom_percent_;
1894}
1895
[email protected]b172aee2012-04-10 17:05:261896int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271897 return maximum_zoom_percent_;
1898}
1899
[email protected]b172aee2012-04-10 17:05:261900gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231901 return preferred_size_;
1902}
1903
[email protected]b172aee2012-04-10 17:05:261904int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271905 return content_restrictions_;
1906}
1907
[email protected]b172aee2012-04-10 17:05:261908WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]3c788372013-01-10 08:34:281909 WebUIControllerFactory* factory =
1910 GetContentClient()->browser()->GetWebUIControllerFactory();
1911 if (!factory)
1912 return WebUI::kNoWebUI;
1913 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271914}
1915
[email protected]8ff00d72012-10-23 19:12:211916WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271917 // When there is a pending navigation entry, we want to use the pending WebUI
1918 // that goes along with it to control the basic flags. For example, we want to
1919 // show the pending URL in the URL bar, so we want the display_url flag to
1920 // be from the pending entry.
1921 //
1922 // The confusion comes because there are multiple possibilities for the
1923 // initial load in a tab as a side effect of the way the RenderViewHostManager
1924 // works.
1925 //
1926 // - For the very first tab the load looks "normal". The new tab Web UI is
1927 // the pending one, and we want it to apply here.
1928 //
1929 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1930 // get switched to the one previously associated with the new tab pages.
1931 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1932 // have a committed Web UI in this case.
1933 //
1934 // This condition handles all of these cases:
1935 //
1936 // - First load in first tab: no committed nav entry + pending nav entry +
1937 // pending dom ui:
1938 // -> Use pending Web UI if any.
1939 //
1940 // - First load in second tab: no committed nav entry + pending nav entry +
1941 // no pending Web UI:
1942 // -> Use the committed Web UI if any.
1943 //
1944 // - Second navigation in any tab: committed nav entry + pending nav entry:
1945 // -> Use pending Web UI if any.
1946 //
1947 // - Normal state with no load: committed nav entry + no pending nav entry:
1948 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251949 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271950 (controller_.GetLastCommittedEntry() ||
1951 render_manager_.pending_web_ui()))
1952 return render_manager_.pending_web_ui();
1953 return render_manager_.web_ui();
1954}
1955
[email protected]b172aee2012-04-10 17:05:261956bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271957 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581958 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271959}
1960
[email protected]b172aee2012-04-10 17:05:261961bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441962 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501963}
1964
[email protected]b172aee2012-04-10 17:05:261965void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321966 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181967 Send(new ViewMsg_DidChooseColorResponse(
1968 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201969}
1970
[email protected]b172aee2012-04-10 17:05:261971void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181972 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201973 if (delegate_)
1974 delegate_->DidEndColorChooser();
1975 color_chooser_ = NULL;
1976}
1977
[email protected]795c28972012-12-06 06:13:391978int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
1979 const FaviconDownloadCallback& callback) {
1980 RenderViewHost* host = GetRenderViewHost();
1981 int id = StartDownload(host, url, image_size);
1982 favicon_download_map_[id] = callback;
1983 return id;
1984}
1985
[email protected]b172aee2012-04-10 17:05:261986bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211987 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271988 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221989 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231990 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411991 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271992}
1993
[email protected]b172aee2012-04-10 17:05:261994void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271995 if (delegate_)
1996 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211997}
1998
[email protected]3a3b75a2012-06-01 08:38:361999void WebContentsImpl::OnRegisterIntentService(
2000 const webkit_glue::WebIntentServiceData& data,
2001 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432002 if (delegate_)
2003 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:302004}
2005
[email protected]b172aee2012-04-10 17:05:262006void WebContentsImpl::OnWebIntentDispatch(
2007 const webkit_glue::WebIntentData& intent,
2008 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:432009 if (!delegate_)
2010 return;
2011
[email protected]0d9989d2011-12-21 20:26:002012 WebIntentsDispatcherImpl* intents_dispatcher =
2013 new WebIntentsDispatcherImpl(this, intent, intent_id);
2014 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:302015}
2016
[email protected]54047eb52012-05-08 21:45:572017void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:212018 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:572019 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132020 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572021 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:572022 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:212023 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]ead9009e2013-01-07 22:06:322024 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182025 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212026 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572027 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082028 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182029
[email protected]d974a0a2013-01-10 01:43:572030 if (is_main_frame)
2031 DidChangeLoadProgress(0);
2032
[email protected]0d60f0192011-04-14 12:40:102033 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252034 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132035 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2036 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322037 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542038
2039 if (is_main_frame) {
2040 // Notify observers about the provisional change in the main frame URL.
2041 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2042 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542043 render_view_host));
2044 }
2045}
2046
2047void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212048 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542049 int32 page_id,
[email protected]400992b2012-06-14 00:03:542050 const GURL& source_url,
2051 const GURL& target_url) {
2052 // TODO(creis): Remove this method and have the pre-rendering code listen to
2053 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2054 // instead. See http://crbug.com/78512.
2055 GURL validated_source_url(source_url);
2056 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212057 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542058 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082059 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2060 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542061 NavigationEntry* entry;
2062 if (page_id == -1) {
2063 entry = controller_.GetPendingEntry();
2064 } else {
2065 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2066 page_id);
2067 }
2068 if (!entry || entry->GetURL() != validated_source_url)
2069 return;
2070
2071 // Notify observers about the provisional change in the main frame URL.
2072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2073 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542074 render_view_host));
[email protected]724159a2010-12-30 01:11:182075}
2076
[email protected]54047eb52012-05-08 21:45:572077void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212078 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582079 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2080 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2081 << ", error_code: " << params.error_code
2082 << ", error_description: " << params.error_description
2083 << ", is_main_frame: " << params.is_main_frame
2084 << ", showing_repost_interstitial: " <<
2085 params.showing_repost_interstitial
2086 << ", frame_id: " << params.frame_id;
2087 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212088 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572089 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082090 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182091
[email protected]d7b175e2011-10-11 15:31:582092 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182093 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2094 // This means that the interstitial won't be torn down properly, which is
2095 // bad. But if we have an interstitial, go back to another tab type, and
2096 // then load the same interstitial again, we could end up getting the first
2097 // interstitial's "failed" message (as a result of the cancel) when we're on
2098 // the second one.
2099 //
2100 // We can't tell this apart, so we think we're tearing down the current page
2101 // which will cause a crash later one. There is also some code in
2102 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2103 // out because of this problem.
2104 //
2105 // http://code.google.com/p/chromium/issues/detail?id=2855
2106 // Because this will not tear down the interstitial properly, if "back" is
2107 // back to another tab type, the interstitial will still be somewhat alive
2108 // in the previous tab type. If you navigate somewhere that activates the
2109 // tab with the interstitial again, you'll see a flash before the new load
2110 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272111 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182112 LOG(WARNING) << "Discarding message during interstitial.";
2113 return;
2114 }
2115
[email protected]a16690732012-07-13 19:22:172116 // Do not clear the pending entry if one exists, so that the user's typed
2117 // URL is not lost when a navigation fails or is aborted. We'll allow
2118 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182119
[email protected]54047eb52012-05-08 21:45:572120 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182121 }
2122
[email protected]d8c660432011-12-22 20:51:252123 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582124 observers_,
2125 DidFailProvisionalLoad(params.frame_id,
2126 params.is_main_frame,
2127 validated_url,
2128 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462129 params.error_description,
2130 render_view_host));
[email protected]724159a2010-12-30 01:11:182131}
2132
[email protected]b172aee2012-04-10 17:05:262133void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182134 const GURL& url,
[email protected]70435962011-08-02 20:13:282135 const std::string& security_info,
2136 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182137 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282138 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192139 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182140 cache.Increment();
2141
2142 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082143 int cert_id = 0;
2144 net::CertStatus cert_status = 0;
2145 int security_bits = -1;
2146 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212147 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2148 &security_bits, &connection_status);
2149 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002150 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2151 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182152
[email protected]8ff00d72012-10-23 19:12:212153 NotificationService::current()->Notify(
2154 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2155 Source<NavigationController>(&controller_),
2156 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212160 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182161 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192162 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182163}
2164
[email protected]b172aee2012-04-10 17:05:262165void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022166 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232167 LOG(INFO) << security_origin << " ran insecure content from "
2168 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212169 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412170 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212171 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182172 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412173 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192174 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182175}
2176
[email protected]b172aee2012-04-10 17:05:262177void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182178 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252179 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472180 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182181}
2182
[email protected]b172aee2012-04-10 17:05:262183void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5b2011-11-29 11:36:312184 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062185 const GURL& url,
[email protected]1a55c5b2011-11-29 11:36:312186 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062187 GURL validated_url(url);
2188 RenderProcessHost* render_process_host = message_source_->GetProcess();
2189 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252190 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472191 DidFinishLoad(frame_id, validated_url, is_main_frame,
2192 message_source_));
[email protected]1a55c5b2011-11-29 11:36:312193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::OnDidFailLoadWithError(
2196 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062197 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262198 bool is_main_frame,
2199 int error_code,
2200 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062201 GURL validated_url(url);
2202 RenderProcessHost* render_process_host = message_source_->GetProcess();
2203 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:312205 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472206 error_code, error_description,
2207 message_source_));
[email protected]724159a2010-12-30 01:11:182208}
2209
[email protected]b172aee2012-04-10 17:05:262210void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272211 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432212 if (delegate_)
2213 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262217 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232218 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252219 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262220 if (!entry)
2221 return;
2222 // Note that we don't call NavigationController::GotToOffset() as we don't
2223 // want to create a pending navigation entry (it might end up lingering
2224 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252225 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212226 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512227 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212228 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472229 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572230
2231 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2232 // it in now that we know. This allows us to find the entry when it commits.
2233 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232234 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332235 entry->set_site_instance(
2236 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572237 }
[email protected]216813952011-05-19 22:21:262238 }
2239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2242 int maximum_percent,
2243 bool remember) {
[email protected]216813952011-05-19 22:21:262244 minimum_zoom_percent_ = minimum_percent;
2245 maximum_zoom_percent_ = maximum_percent;
2246 temporary_zoom_settings_ = !remember;
2247}
2248
[email protected]20b433a2012-05-15 21:23:462249void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212250 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552251 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262252 // Check if the URL to save matches the URL of the main frame. Since this
2253 // message originates from Pepper plugins, it may not be the case if the
2254 // plugin is an embedded element.
2255 GURL main_frame_url = GetURL();
2256 if (!main_frame_url.is_valid())
2257 return;
2258 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462259 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272260}
2261
[email protected]b172aee2012-04-10 17:05:262262void WebContentsImpl::OnEnumerateDirectory(int request_id,
2263 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432264 if (!delegate_)
2265 return;
2266
[email protected]b9535422012-02-09 01:47:592267 ChildProcessSecurityPolicyImpl* policy =
2268 ChildProcessSecurityPolicyImpl::GetInstance();
2269 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2270 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212271}
2272
[email protected]b172aee2012-04-10 17:05:262273void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432274 if (delegate_)
2275 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202276}
2277
[email protected]b172aee2012-04-10 17:05:262278void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2279 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362280 const string16& title,
2281 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432282 if (!delegate_)
2283 return;
2284
[email protected]b9535422012-02-09 01:47:592285 ChildProcessSecurityPolicyImpl* policy =
2286 ChildProcessSecurityPolicyImpl::GetInstance();
2287 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2288 return;
[email protected]3a3b75a2012-06-01 08:38:362289 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202290}
2291
[email protected]b172aee2012-04-10 17:05:262292void WebContentsImpl::OnFindReply(int request_id,
2293 int number_of_matches,
2294 const gfx::Rect& selection_rect,
2295 int active_match_ordinal,
2296 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432297 if (delegate_) {
2298 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2299 active_match_ordinal, final_update);
2300 }
[email protected]b888919c2011-09-02 00:32:162301}
2302
[email protected]59363fc92012-09-05 03:46:312303#if defined(OS_ANDROID)
2304void WebContentsImpl::OnFindMatchRectsReply(
2305 int version,
2306 const std::vector<gfx::RectF>& rects,
2307 const gfx::RectF& active_rect) {
2308 if (delegate_)
2309 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2310}
[email protected]583418cc2013-01-17 14:01:102311
2312void WebContentsImpl::OnOpenDateTimeDialog(int type, const std::string& value) {
2313 date_time_chooser_->ShowDialog(
2314 GetContentNativeView(), GetRenderViewHost(), type, value);
2315}
2316
[email protected]59363fc92012-09-05 03:46:312317#endif
2318
[email protected]cf4d6e742013-01-10 14:06:422319void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path,
2320 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442321 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422322 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452323}
2324
[email protected]b172aee2012-04-10 17:05:262325void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2326 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102327 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252328 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102329 AppCacheAccessed(manifest_url, blocked_by_policy));
2330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322333 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432334 color_chooser_ = delegate_ ?
2335 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202336}
2337
[email protected]b172aee2012-04-10 17:05:262338void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202339 if (color_chooser_ &&
2340 color_chooser_id == color_chooser_->identifier())
2341 color_chooser_->End();
2342}
2343
[email protected]b172aee2012-04-10 17:05:262344void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322345 SkColor color) {
[email protected]da8543762012-03-20 08:52:202346 if (color_chooser_ &&
2347 color_chooser_id == color_chooser_->identifier())
2348 color_chooser_->SetSelectedColor(color);
2349}
2350
[email protected]9f2a9d72012-04-16 16:02:222351void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2352 const FilePath& path,
2353 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552354 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2355
[email protected]3fc07c52012-04-20 00:27:442356 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2357 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292358}
2359
[email protected]d0759f492012-04-19 22:50:502360// This exists for render views that don't have a WebUI, but do have WebUI
2361// bindings enabled.
2362void WebContentsImpl::OnWebUISend(const GURL& source_url,
2363 const std::string& name,
2364 const base::ListValue& args) {
2365 if (delegate_)
2366 delegate_->WebUISend(this, source_url, name, args);
2367}
2368
[email protected]d8415ad92012-08-23 14:40:502369void WebContentsImpl::OnRequestPpapiBrokerPermission(
2370 int request_id,
2371 const GURL& url,
2372 const FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162373 if (!delegate_) {
2374 OnPpapiBrokerPermissionResult(request_id, false);
2375 return;
[email protected]d8415ad92012-08-23 14:40:502376 }
2377
[email protected]8c8fc292012-11-23 18:57:162378 if (!delegate_->RequestPpapiBrokerPermission(
2379 this, url, plugin_path,
2380 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2381 base::Unretained(this), request_id))) {
2382 NOTIMPLEMENTED();
2383 OnPpapiBrokerPermissionResult(request_id, false);
2384 }
[email protected]d8415ad92012-08-23 14:40:502385}
2386
2387void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2388 bool result) {
2389 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2390 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2391 request_id,
2392 result));
2393}
2394
[email protected]b479912c2013-01-23 00:07:082395void WebContentsImpl::OnBrowserPluginAllocateInstanceID(
2396 const IPC::Message& message, int request_id) {
[email protected]19be7a62012-10-01 23:03:372397 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082398 // specific messages for this WebContents. This means that any message from
2399 // a BrowserPlugin prior to AllocateInstanceID will be ignored.
[email protected]7a846df2012-09-20 19:17:392400 // For more info, see comment above classes BrowserPluginEmbedder and
2401 // BrowserPluginGuest.
[email protected]b479912c2013-01-23 00:07:082402 // The first BrowserPluginHostMsg_AllocateInstanceID message from this
2403 // WebContents' embedder render process is handled here. Once
2404 // BrowserPluginEmbedder is created, all subsequent BrowserPluginHostMsg_*
2405 // messages are handled in BrowserPluginEmbedder. Thus, this code will not be
2406 // executed if a BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392407 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392408 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212409 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]b479912c2013-01-23 00:07:082410 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372411}
2412
[email protected]795c28972012-12-06 06:13:392413void WebContentsImpl::OnDidDownloadFavicon(
2414 int id,
2415 const GURL& image_url,
[email protected]795c28972012-12-06 06:13:392416 int requested_size,
2417 const std::vector<SkBitmap>& bitmaps) {
2418 FaviconDownloadMap::iterator iter = favicon_download_map_.find(id);
2419 if (iter == favicon_download_map_.end()) {
2420 // Currently WebContents notifies us of ANY downloads so that it is
2421 // possible to get here.
2422 return;
2423 }
2424 if (!iter->second.is_null()) {
[email protected]8383aa962013-01-10 05:48:532425 iter->second.Run(id, image_url, requested_size, bitmaps);
[email protected]795c28972012-12-06 06:13:392426 }
2427 favicon_download_map_.erase(id);
2428}
2429
2430void WebContentsImpl::OnUpdateFaviconURL(
2431 int32 page_id,
2432 const std::vector<FaviconURL>& candidates) {
2433 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2434 DidUpdateFaviconURL(page_id, candidates));
2435}
2436
[email protected]8607c832013-01-18 14:11:572437void WebContentsImpl::OnFrameDetached(int64 frame_id) {
2438 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2439 FrameDetached(message_source_, frame_id));
2440}
2441
[email protected]818915cd2012-11-20 13:14:112442void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
2443 ThreeDAPIType requester) {
2444 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2445 DidBlock3DAPIs(url, requester));
2446}
2447
[email protected]96d185d2009-04-24 03:28:542448// Notifies the RenderWidgetHost instance about the fact that the page is
2449// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262450void WebContentsImpl::SetIsLoading(bool is_loading,
2451 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542452 if (is_loading == is_loading_)
2453 return;
2454
2455 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212456 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542457 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562458 upload_size_ = 0;
2459 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542460 }
2461
2462 render_manager_.SetIsLoading(is_loading);
2463
2464 is_loading_ = is_loading;
2465 waiting_for_response_ = is_loading;
2466
[email protected]6ebdc9b2010-09-27 16:55:572467 if (delegate_)
2468 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212469 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542470
[email protected]8ff00d72012-10-23 19:12:212471 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2472 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542473 if (details)
[email protected]8ff00d72012-10-23 19:12:212474 det = Details<LoadNotificationDetails>(details);
2475 NotificationService::current()->Notify(
2476 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542477}
2478
[email protected]b172aee2012-04-10 17:05:262479void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212480 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322481 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562482 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382483 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442484 // that opened the window, as long as both renderers have the same
2485 // privileges.
[email protected]1fd1a502011-03-30 16:55:562486 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562487 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582488 // web_ui might be NULL if the URL refers to a non-existent extension.
2489 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402490 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522491 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442492 }
2493 }
[email protected]1fd1a502011-03-30 16:55:562494 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442495 }
2496
[email protected]4e697b042011-07-08 06:44:562497 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322498 // Clear the status bubble. This is a workaround for a bug where WebKit
2499 // doesn't let us know that the cursor left an element during a
2500 // transition (this is also why the mouse cursor remains as a hand after
2501 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2502 // clear the bubble when a user navigates to a named anchor in the same
2503 // page.
[email protected]36fc0392011-12-25 03:59:512504 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322505 }
2506
[email protected]a6e82fc2010-02-24 22:28:142507 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472508 // Once the main frame is navigated, we're no longer considered to have
2509 // displayed insecure content.
2510 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172511 }
[email protected]ce5c4502009-05-06 16:46:112512
[email protected]3c9e1872010-11-18 16:17:492513 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252514 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042515 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322519 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212520 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322521 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062522 // If we navigate off the page, reset JavaScript state. This does nothing
2523 // to prevent a malicious script from spamming messages, since the script
2524 // could just reload the page to stop blocking.
2525 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552526 dialog_creator_->ResetJavaScriptState(this);
2527 dialog_creator_ = NULL;
2528 }
[email protected]420ae012009-04-24 05:16:322529
[email protected]3c9e1872010-11-18 16:17:492530 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042532 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322533}
2534
[email protected]b172aee2012-04-10 17:05:262535void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462536 // If we are creating a RVH for a restored controller, then we need to make
2537 // sure the RenderView starts with a next_page_id_ larger than the number
2538 // of restored entries. This must be called before the RenderView starts
2539 // navigating (to avoid a race between the browser updating max_page_id and
2540 // the renderer updating next_page_id_). Because of this, we only call this
2541 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562542 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582543 if (max_restored_page_id >
2544 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2545 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2546 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322547}
2548
[email protected]b172aee2012-04-10 17:05:262549bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2550 const string16& title) {
[email protected]420ae012009-04-24 05:16:322551 // For file URLs without a title, use the pathname instead. In the case of a
2552 // synthesized title, we don't want the update to count toward the "one set
2553 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512554 string16 final_title;
[email protected]420ae012009-04-24 05:16:322555 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512556 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2557 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322558 explicit_set = false; // Don't count synthetic titles toward the set limit.
2559 } else {
[email protected]acafd272011-07-26 17:35:572560 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322561 explicit_set = true;
2562 }
2563
[email protected]987fc3a2011-05-26 14:18:092564 // If a page is created via window.open and never navigated,
2565 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552566 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092567 if (entry) {
[email protected]36fc0392011-12-25 03:59:512568 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092569 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322570
[email protected]36fc0392011-12-25 03:59:512571 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092572 } else {
2573 if (page_title_when_no_navigation_entry_ == final_title)
2574 return false; // Nothing changed, don't bother.
2575
2576 page_title_when_no_navigation_entry_ = final_title;
2577 }
[email protected]420ae012009-04-24 05:16:322578
[email protected]420ae012009-04-24 05:16:322579 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232580 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322581
[email protected]8ff00d72012-10-23 19:12:212582 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462583 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142584
[email protected]8ff00d72012-10-23 19:12:212585 NotificationService::current()->Notify(
2586 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2587 Source<WebContents>(this),
2588 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042589
[email protected]420ae012009-04-24 05:16:322590 return true;
2591}
2592
[email protected]35e0e0792012-11-30 02:35:482593void WebContentsImpl::NotifySwapped(RenderViewHost* old_render_view_host) {
[email protected]420ae012009-04-24 05:16:322594 // After sending out a swap notification, we need to send a disconnect
2595 // notification so that clients that pick up a pointer to |this| can NULL the
2596 // pointer. See Bug 1230284.
2597 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212598 NotificationService::current()->Notify(
2599 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2600 Source<WebContents>(this),
[email protected]35e0e0792012-11-30 02:35:482601 Details<RenderViewHost>(old_render_view_host));
[email protected]7a846df2012-09-20 19:17:392602
2603 // Ensure that the associated embedder gets cleared after a RenderViewHost
2604 // gets swapped, so we don't reuse the same embedder next time a
2605 // RenderViewHost is attached to this WebContents.
2606 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322610 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212611 NotificationService::current()->Notify(
2612 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2613 Source<WebContents>(this),
2614 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322615}
2616
[email protected]b172aee2012-04-10 17:05:262617void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322618 if (!notify_disconnection_)
2619 return;
2620
2621 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212622 NotificationService::current()->Notify(
2623 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2624 Source<WebContents>(this),
2625 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322626}
2627
[email protected]5a3bdf52012-05-24 15:12:572628RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2629 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]8d3347f2009-07-09 22:00:212632RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262633WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212634 return &render_manager_;
2635}
2636
[email protected]8ff00d72012-10-23 19:12:212637RendererPreferences WebContentsImpl::GetRendererPrefs(
2638 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462639 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512640}
2641
[email protected]b172aee2012-04-10 17:05:262642WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172643 return this;
2644}
2645
[email protected]b172aee2012-04-10 17:05:262646gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172647 if (delegate_)
2648 return delegate_->GetRootWindowResizerRect();
2649 return gfx::Rect();
2650}
2651
[email protected]7a846df2012-09-20 19:17:392652void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2653 if (browser_plugin_embedder_.get())
2654 browser_plugin_embedder_.reset();
2655}
2656
[email protected]b172aee2012-04-10 17:05:262657void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442658 // Don't send notifications if we are just creating a swapped-out RVH for
2659 // the opener chain. These won't be used for view-source or WebUI, so it's
2660 // ok to return early.
2661 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2662 return;
2663
[email protected]8ff00d72012-10-23 19:12:212664 NotificationService::current()->Notify(
2665 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2666 Source<WebContents>(this),
2667 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232668 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322669 if (!entry)
2670 return;
2671
2672 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352673 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562674 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582675 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322676
2677 if (entry->IsViewSourceMode()) {
2678 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182679 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582680 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322681 }
[email protected]0666aef2009-05-13 19:48:082682
[email protected]d487beefe2011-12-21 05:41:212683 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262684
2685 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252686 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322687}
2688
[email protected]b172aee2012-04-10 17:05:262689void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522690 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322691 // Don't notify the world, since this came from a renderer in the
2692 // background.
2693 return;
2694 }
2695
2696 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312697 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232698 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302699
2700 // Restore the focus to the tab (otherwise the focus will be on the top
2701 // window).
[email protected]484ae5912010-09-29 19:16:142702 if (was_crashed && !FocusLocationBarByDefault() &&
2703 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302704 Focus();
[email protected]484ae5912010-09-29 19:16:142705 }
[email protected]32ded2212011-11-10 18:51:432706
[email protected]d8c660432011-12-22 20:51:252707 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322708}
2709
[email protected]b172aee2012-04-10 17:05:262710void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2711 base::TerminationStatus status,
2712 int error_code) {
[email protected]151a63d2011-12-20 22:32:522713 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322714 // The pending page's RenderViewHost is gone.
2715 return;
2716 }
2717
2718 SetIsLoading(false, NULL);
2719 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232720 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312721 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322722
[email protected]d8c660432011-12-22 20:51:252723 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272724 observers_,
[email protected]be1f56ab2011-12-22 06:55:312725 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322726}
2727
[email protected]b172aee2012-04-10 17:05:262728void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482729 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252730 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062731}
2732
[email protected]b172aee2012-04-10 17:05:262733void WebContentsImpl::DidNavigate(
2734 RenderViewHost* rvh,
2735 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e3d92a7f2013-01-10 02:35:052736 if (PageTransitionIsMainFrame(params.transition)) {
2737 // When overscroll navigation gesture is enabled, a screenshot of the page
2738 // in its current state is taken so that it can be used during the
2739 // nav-gesture. It is necessary to take the screenshot here, before calling
2740 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2741 // WebContents::GetRenderViewHost to return the new host, instead of the one
2742 // that may have just been swapped out.
2743 controller_.TakeScreenshot();
2744
[email protected]420ae012009-04-24 05:16:322745 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052746 }
[email protected]8030f012009-09-25 18:09:372747
[email protected]434f69f2012-02-06 21:56:522748 // Update the site of the SiteInstance if it doesn't have one yet, unless
2749 // this is for about:blank. In that case, the SiteInstance can still be
2750 // considered unused until a navigation to a real page.
2751 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2752 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332753 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522754 }
[email protected]420ae012009-04-24 05:16:322755
2756 // Need to update MIME type here because it's referred to in
2757 // UpdateNavigationCommands() called by RendererDidNavigate() to
2758 // determine whether or not to enable the encoding menu.
2759 // It's updated only for the main frame. For a subframe,
2760 // RenderView::UpdateURL does not set params.contents_mime_type.
2761 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2762 // TODO(jungshik): Add a test for the encoding menu to avoid
2763 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212764 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322765 contents_mime_type_ = params.contents_mime_type;
2766
[email protected]8ff00d72012-10-23 19:12:212767 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002768 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392769
[email protected]a9c0bfe2010-09-17 08:35:222770 // Send notification about committed provisional loads. This notification is
2771 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2772 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212773 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072774 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2775 // that is not recorded in the navigation history. For the purpose of
2776 // tracking navigation events, we treat this event as a sub frame navigation
2777 // event.
2778 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212779 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222780 // Whether or not a page transition was triggered by going backward or
2781 // forward in the history is only stored in the navigation controller's
2782 // entry list.
2783 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512784 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212785 PAGE_TRANSITION_FORWARD_BACK)) {
2786 transition_type = PageTransitionFromInt(
2787 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222788 }
[email protected]0d60f0192011-04-14 12:40:102789 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102791 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462792 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222793 }
2794
[email protected]76543b92009-08-31 17:27:452795 if (!did_navigate)
2796 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322797
2798 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2799 // for the appropriate notification (best) or you can add it to
2800 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2801 // necessary, please).
2802
2803 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002804 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322805 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512806 if (delegate_)
2807 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002808 }
[email protected]420ae012009-04-24 05:16:322809 DidNavigateAnyFramePostCommit(rvh, details, params);
2810}
2811
[email protected]b172aee2012-04-10 17:05:262812void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2813 int32 page_id,
2814 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152815 // Ensure that this state update comes from either the active RVH or one of
2816 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522817 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322818
2819 // We must be prepared to handle state updates for any page, these occur
2820 // when the user is scrolling and entering form data, as well as when we're
2821 // leaving a page, in which case our state may have already been moved to
2822 // the next page. The navigation controller will look up the appropriate
2823 // NavigationEntry and update it when it is notified via the delegate.
2824
2825 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582826 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322827 if (entry_index < 0)
2828 return;
[email protected]10f417c52011-12-28 21:04:232829 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322830
[email protected]36fc0392011-12-25 03:59:512831 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322832 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512833 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322834 controller_.NotifyEntryChanged(entry, entry_index);
2835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2838 int32 page_id,
2839 const string16& title,
2840 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322841 // If we have a title, that's a pretty good indication that we've started
2842 // getting useful data.
2843 SetNotWaitingForResponse();
2844
[email protected]73eb2602012-02-09 19:50:552845 // Try to find the navigation entry, which might not be the current one.
2846 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232847 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582848 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092849
[email protected]73eb2602012-02-09 19:50:552850 // We can handle title updates when we don't have an entry in
2851 // UpdateTitleForEntry, but only if the update is from the current RVH.
2852 if (!entry && rvh != GetRenderViewHost())
2853 return;
2854
[email protected]a49e10b2011-08-01 23:57:462855 // TODO(evan): make use of title_direction.
2856 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092857 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322858 return;
2859
2860 // Broadcast notifications when the UI should be updated.
2861 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212862 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322863}
2864
[email protected]b172aee2012-04-10 17:05:262865void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2866 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312867 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322868}
2869
[email protected]b172aee2012-04-10 17:05:262870void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512871 if (delegate_)
2872 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322873}
2874
[email protected]b172aee2012-04-10 17:05:262875void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292876 // The UI may be in an event-tracking loop, such as between the
2877 // mouse-down and mouse-up in text selection or a button click.
2878 // Defer the close until after tracking is complete, so that we
2879 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292880 // TODO(shess): This could get more fine-grained. For instance,
2881 // closing a tab in another window while selecting text in the
2882 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212883 if (GetView()->IsEventTracking()) {
2884 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292885 return;
2886 }
2887
[email protected]420ae012009-04-24 05:16:322888 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522889 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512890 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322891}
2892
[email protected]b172aee2012-04-10 17:05:262893void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522894 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512895 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572896}
2897
[email protected]b172aee2012-04-10 17:05:262898void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512899 if (delegate_ && delegate_->IsPopupOrPanel(this))
2900 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322901}
2902
[email protected]8ff00d72012-10-23 19:12:212903void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322904 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492905
[email protected]82114f52012-03-20 22:53:412906 if (delegate_ && content_restrictions_)
2907 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492908
2909 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292910 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2911 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322912}
2913
[email protected]8ff00d72012-10-23 19:12:212914void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322915 scoped_ptr<LoadNotificationDetails> details;
2916
[email protected]10f417c52011-12-28 21:04:232917 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322918 // An entry may not exist for a stop when loading an initial blank page or
2919 // if an iframe injected by script into a blank page finishes loading.
2920 if (entry) {
[email protected]420ae012009-04-24 05:16:322921 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2922
2923 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512924 entry->GetVirtualURL(),
2925 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322926 elapsed,
2927 &controller_,
2928 controller_.GetCurrentEntryIndex()));
2929 }
2930
[email protected]420ae012009-04-24 05:16:322931 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492932
2933 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292934 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2935 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322936}
2937
[email protected]b172aee2012-04-10 17:05:262938void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162939 controller_.DiscardNonCommittedEntries();
2940
2941 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212942 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162943}
2944
[email protected]b172aee2012-04-10 17:05:262945void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262946#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512947 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132948 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262949#endif
[email protected]1a3c3cb2010-12-16 21:03:402950}
2951
[email protected]7cc78902012-12-06 02:32:262952void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2953 // Clear our opener so that future cross-process navigations don't have an
2954 // opener assigned.
2955 opener_ = NULL;
2956
2957 // Notify all swapped out RenderViewHosts for this tab. This is important
2958 // in case we go back to them, or if another window in those processes tries
2959 // to access window.opener.
2960 render_manager_.DidDisownOpener(rvh);
2961}
2962
[email protected]0720b532012-08-28 19:23:372963void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2964 render_manager_.DidUpdateFrameTree(rvh);
2965}
2966
[email protected]87717d0e2012-04-26 02:58:432967void WebContentsImpl::DocumentAvailableInMainFrame(
2968 RenderViewHost* render_view_host) {
2969 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2970 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102971}
2972
[email protected]b172aee2012-04-10 17:05:262973void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082974 RenderViewHost* render_view_host,
2975 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212976 NotificationService::current()->Notify(
2977 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2978 Source<WebContents>(this),
2979 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082980}
2981
[email protected]196159d2012-05-04 17:26:542982void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2983 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212984 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262985 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:182986 int64 source_frame_id,
2987 bool is_cross_site_redirect) {
[email protected]196159d2012-05-04 17:26:542988 // If this came from a swapped out RenderViewHost, we only allow the request
2989 // if we are still in the same BrowsingInstance.
2990 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2991 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2992 return;
2993 }
2994
[email protected]4ad5d77d2011-12-03 02:00:482995 // Delegate to RequestTransferURL because this is just the generic
2996 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582997 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]e2caa032012-11-15 23:29:182998 GlobalRequestID(), is_cross_site_redirect);
[email protected]4ad5d77d2011-12-03 02:00:482999}
3000
[email protected]b172aee2012-04-10 17:05:263001void WebContentsImpl::RequestTransferURL(
3002 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213003 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263004 WindowOpenDisposition disposition,
3005 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183006 const GlobalRequestID& old_request_id,
3007 bool is_cross_site_redirect) {
[email protected]e5d549d2011-12-28 01:29:203008 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:213009 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:583010 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:353011 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:323012 // is so the new tab page can specify AUTO_BOOKMARK for automatically
3013 // generated suggestions).
3014 //
[email protected]e0112912011-02-02 22:54:353015 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163016 // want web sites to see a referrer of "chrome://blah" (and some
3017 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323018 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:213019 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:223020 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:483021 false /* is_renderer_initiated */);
3022 params.transferred_global_request_id = old_request_id;
3023 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:223024 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:323025 } else {
[email protected]6bf6a6b52012-02-03 15:41:433026 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:213027 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:483028 params.transferred_global_request_id = old_request_id;
[email protected]e2caa032012-11-15 23:29:183029 params.is_cross_site_redirect = is_cross_site_redirect;
[email protected]4ad5d77d2011-12-03 02:00:483030 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:583031 }
3032 if (new_contents) {
3033 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253034 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583035 DidOpenRequestedURL(new_contents,
3036 url,
3037 referrer,
3038 disposition,
3039 transition_type,
3040 source_frame_id));
[email protected]420ae012009-04-24 05:16:323041 }
3042}
3043
[email protected]e1c3a552012-05-04 20:51:323044void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3045 // Tell the active RenderViewHost to run unload handlers and close, as long
3046 // as the request came from a RenderViewHost in the same BrowsingInstance.
3047 // In most cases, we receive this from a swapped out RenderViewHost.
3048 // It is possible to receive it from one that has just been swapped in,
3049 // in which case we might as well deliver the message anyway.
3050 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3051 GetRenderViewHost()->ClosePage();
3052}
3053
[email protected]f546640b2012-05-15 00:03:493054void WebContentsImpl::RouteMessageEvent(
3055 RenderViewHost* rvh,
3056 const ViewMsg_PostMessage_Params& params) {
3057 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363058 // came from a RenderViewHost in the same BrowsingInstance or if this
3059 // WebContents is dedicated to a browser plugin guest.
3060 // Note: This check means that an embedder could theoretically receive a
3061 // postMessage from anyone (not just its own guests). However, this is
3062 // probably not a risk for apps since other pages won't have references
3063 // to App windows.
3064 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3065 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493066 return;
3067
3068 ViewMsg_PostMessage_Params new_params(params);
3069
[email protected]0720b532012-08-28 19:23:373070 // If the renderer has changed while the post message is being routed,
3071 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:193072 // TODO(nasko): Check for process ID and target frame id mismatch, once
3073 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:373074
[email protected]f546640b2012-05-15 00:03:493075 // If there is a source_routing_id, translate it to the routing ID for
3076 // the equivalent swapped out RVH in the target process. If we need
3077 // to create a swapped out RVH for the source tab, we create its opener
3078 // chain as well, since those will also be accessible to the target page.
3079 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3080 // Try to look up the WebContents for the source page.
3081 WebContentsImpl* source_contents = NULL;
3082 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3083 rvh->GetProcess()->GetID(), params.source_routing_id);
3084 if (source_rvh) {
3085 source_contents = static_cast<WebContentsImpl*>(
3086 source_rvh->GetDelegate()->GetAsWebContents());
3087 }
3088
3089 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363090 if (GetBrowserPluginGuest()) {
3091 // We create a swapped out RenderView for the embedder in the guest's
3092 // render process but we intentionally do not expose the embedder's
3093 // opener chain to it.
3094 new_params.source_routing_id =
3095 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3096 } else {
3097 new_params.source_routing_id =
3098 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3099 }
[email protected]f546640b2012-05-15 00:03:493100 } else {
3101 // We couldn't find it, so don't pass a source frame.
3102 new_params.source_routing_id = MSG_ROUTING_NONE;
3103 }
3104 }
3105
3106 // In most cases, we receive this from a swapped out RenderViewHost.
3107 // It is possible to receive it from one that has just been swapped in,
3108 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183109 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493110}
3111
[email protected]b172aee2012-04-10 17:05:263112void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343113 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413114 const string16& message,
3115 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323116 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213117 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323118 IPC::Message* reply_msg,
3119 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073120 // Suppress JavaScript dialogs when requested. Also suppress messages when
3121 // showing an interstitial as it's shown over the previous page and we don't
3122 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503123 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583124 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273125 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073126 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523127 delegate_->ShouldSuppressDialogs() ||
3128 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323129
3130 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213131 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433132 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553133 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523134 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433135 this,
3136 frame_url.GetOrigin(),
3137 accept_lang,
3138 javascript_message_type,
3139 message,
[email protected]51da7e32012-01-30 19:24:523140 default_prompt,
[email protected]b172aee2012-04-10 17:05:263141 base::Bind(&WebContentsImpl::OnDialogClosed,
3142 base::Unretained(this),
3143 rvh,
3144 reply_msg),
[email protected]51da7e32012-01-30 19:24:523145 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323146 }
[email protected]3ab9cb82011-06-03 18:02:073147
3148 if (suppress_this_message) {
3149 // If we are suppressing messages, just reply as if the user immediately
3150 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343151 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073152 }
3153
3154 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323155}
3156
[email protected]b172aee2012-04-10 17:05:263157void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3158 const string16& message,
3159 bool is_reload,
3160 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583161 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513162 if (delegate_)
3163 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073164
3165 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583166 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073167 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523168 delegate_->ShouldSuppressDialogs() ||
3169 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153170 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343171 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583172 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503173 return;
3174 }
[email protected]3ab9cb82011-06-03 18:02:073175
[email protected]7ab1e7d62009-10-14 23:32:013176 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553177 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523178 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323179 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263180 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523181 reply_msg));
[email protected]420ae012009-04-24 05:16:323182}
3183
[email protected]a796f202012-05-30 14:14:253184bool WebContentsImpl::AddMessageToConsole(int32 level,
3185 const string16& message,
3186 int32 line_no,
3187 const string16& source_id) {
3188 if (!delegate_)
3189 return false;
3190 return delegate_->AddMessageToConsole(this, level, message, line_no,
3191 source_id);
3192}
3193
[email protected]b172aee2012-04-10 17:05:263194WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333195 // We want to base the page config off of the real URL, rather than the
3196 // display URL.
3197 GURL url = controller_.GetActiveEntry()
3198 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3199 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323200}
3201
[email protected]0eba810b2012-10-18 03:19:363202int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213203 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363204 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3205}
3206
[email protected]b172aee2012-04-10 17:05:263207void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273208 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253209 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223210
[email protected]ea114722012-03-12 01:11:253211 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173212 if (rdh) // NULL in unittests.
3213 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253214}
3215
[email protected]b172aee2012-04-10 17:05:263216void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443217 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253218 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443219}
3220
[email protected]b172aee2012-04-10 17:05:263221void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3222 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153223 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523224 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153225 return;
3226
[email protected]9f76c1e2012-03-05 15:15:583227 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3228
[email protected]e5fc1632011-08-08 07:51:533229 // Ignore renderer unresponsive event if debugger is attached to the tab
3230 // since the event may be a result of the renderer sitting on a breakpoint.
3231 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363232 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533233 return;
3234
[email protected]420ae012009-04-24 05:16:323235 if (is_during_unload) {
3236 // Hang occurred while firing the beforeunload/unload handler.
3237 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583238 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323239
3240 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3241 return;
3242
3243 // If the tab hangs in the beforeunload/unload handler there's really
3244 // nothing we can do to recover. Pretend the unload listeners have
3245 // all fired and close the tab. If the hang is in the beforeunload handler
3246 // then the user will not have the option of cancelling the close.
3247 Close(rvh);
3248 return;
3249 }
3250
[email protected]9f76c1e2012-03-05 15:15:583251 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473252 return;
3253
[email protected]6934a702011-12-20 00:04:513254 if (delegate_)
3255 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323256}
3257
[email protected]b172aee2012-04-10 17:05:263258void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513259 if (delegate_)
3260 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323261}
3262
[email protected]b172aee2012-04-10 17:05:263263void WebContentsImpl::LoadStateChanged(
3264 const GURL& url,
3265 const net::LoadStateWithParam& load_state,
3266 uint64 upload_position,
3267 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323268 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563269 upload_position_ = upload_position;
3270 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503271 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213272 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303273 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213274 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323275 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463276 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213277 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463278 }
[email protected]420ae012009-04-24 05:16:323279}
3280
[email protected]b172aee2012-04-10 17:05:263281void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513282 if (delegate_)
3283 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253284}
3285
[email protected]b172aee2012-04-10 17:05:263286void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553287 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323288 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553289 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513290 if (delegate_)
3291 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323292}
3293
[email protected]b172aee2012-04-10 17:05:263294void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543295 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233296 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3297 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543298}
3299
[email protected]b172aee2012-04-10 17:05:263300void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103301 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263302 gfx::Size size = view_->GetContainerSize();
3303 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3304 // here during container initialization and normal window size will be set
3305 // later. In case of tab duplication this resizing to 0x0 prevents setting
3306 // normal size later so just ignore it.
3307 if (!size.IsEmpty())
3308 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323309}
3310
[email protected]35e0e0792012-11-30 02:35:483311void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) {
3312 NotifySwapped(rvh);
[email protected]3a3d47472010-07-15 21:03:543313}
3314
[email protected]14392a52012-05-02 20:28:443315int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3316 SiteInstance* instance) {
3317 if (!opener_)
3318 return MSG_ROUTING_NONE;
3319
3320 // Recursively create RenderViews for anything else in the opener chain.
3321 return opener_->CreateOpenerRenderViews(instance);
3322}
3323
3324int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3325 int opener_route_id = MSG_ROUTING_NONE;
3326
3327 // If this tab has an opener, ensure it has a RenderView in the given
3328 // SiteInstance as well.
3329 if (opener_)
3330 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3331
[email protected]0720b532012-08-28 19:23:373332 // If any of the renderers for this WebContents has the same SiteInstance,
3333 // use it.
3334 if (render_manager_.current_host()->GetSiteInstance() == instance)
3335 return render_manager_.current_host()->GetRoutingID();
3336
3337 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3338 instance);
3339 if (rvh)
3340 return rvh->GetRoutingID();
3341
[email protected]14392a52012-05-02 20:28:443342 // Create a swapped out RenderView in the given SiteInstance if none exists,
3343 // setting its opener to the given route_id. Return the new view's route_id.
3344 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3345}
3346
[email protected]b172aee2012-04-10 17:05:263347NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193348 return GetController();
[email protected]3a3d47472010-07-15 21:03:543349}
3350
[email protected]b172aee2012-04-10 17:05:263351WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563352 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323353}
3354
[email protected]10f417c52011-12-28 21:04:233355NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263356 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323357 return controller_.GetLastCommittedEntry();
3358}
3359
[email protected]b172aee2012-04-10 17:05:263360bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443361 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443362 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323363 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523364
[email protected]420ae012009-04-24 05:16:323365 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443366 if (rwh_view)
3367 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323368
[email protected]74ce1ad2011-12-16 21:51:463369 // Make sure we use the correct starting page_id in the new RenderView.
3370 UpdateMaxPageIDIfNecessary(render_view_host);
3371 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583372 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463373
[email protected]9f76c1e2012-03-05 15:15:583374 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493375 render_view_host)->CreateRenderView(string16(),
3376 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133377 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523378 return false;
[email protected]14392a52012-05-02 20:28:443379 }
[email protected]a4127722011-04-27 23:13:523380
[email protected]e60c0232011-11-11 19:56:353381#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503382 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3383 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443384 if (rwh_view) {
3385 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3386 render_widget_host->WasResized();
3387 }
[email protected]f8233cc2011-05-31 20:24:503388#endif
3389
[email protected]420ae012009-04-24 05:16:323390 return true;
3391}
3392
[email protected]b172aee2012-04-10 17:05:263393void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3394 IPC::Message* reply_msg,
3395 bool success,
3396 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543397 if (is_showing_before_unload_dialog_ && !success) {
3398 // If a beforeunload dialog is canceled, we need to stop the throbber from
3399 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293400 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353401 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543402
[email protected]3bbacc5b2012-04-17 17:46:153403 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553404 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543405 }
3406 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583407 static_cast<RenderViewHostImpl*>(
3408 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543409}
3410
[email protected]b172aee2012-04-10 17:05:263411void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213412 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123413 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103414}
[email protected]f45d2a72010-03-08 23:28:353415
[email protected]b172aee2012-04-10 17:05:263416void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213417 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263418 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573419 DownloadManager* dlm =
3420 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143421 if (!dlm)
3422 return;
3423 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263424 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143425 const NavigationEntry* entry = controller_.GetActiveEntry();
3426 if (entry)
3427 post_id = entry->GetPostID();
3428 }
[email protected]c5a5c0842012-05-04 20:05:143429 scoped_ptr<DownloadUrlParameters> params(
[email protected]49d812e2012-11-06 21:18:123430 DownloadUrlParameters::FromWebContents(this, url));
[email protected]f859eba2012-05-30 17:22:493431 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143432 params->set_post_id(post_id);
3433 params->set_prefer_cache(true);
3434 if (post_id >= 0)
3435 params->set_method("POST");
[email protected]49d812e2012-11-06 21:18:123436 params->set_prompt(true);
[email protected]c5a5c0842012-05-04 20:05:143437 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143438}
3439
[email protected]b172aee2012-04-10 17:05:263440void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213441 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443442 // Can be NULL during tests.
3443 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213444 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363445}
[email protected]9f76c1e2012-03-05 15:15:583446
[email protected]b172aee2012-04-10 17:05:263447RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583448 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3449}
[email protected]7900bfdb2012-05-24 19:31:243450
[email protected]8ff00d72012-10-23 19:12:213451BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393452 return browser_plugin_guest_.get();
3453}
3454
[email protected]8ff00d72012-10-23 19:12:213455BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393456 return browser_plugin_embedder_.get();
3457}
[email protected]8ff00d72012-10-23 19:12:213458
3459} // namespace content