blob: bb8b483f998a08f058569c40aa5276dc8760600f [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]87f3c082011-10-19 18:07:4450#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3651#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1752#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1453#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4654#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1555#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0056#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2757#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0058#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3759#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1460#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3261#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3462#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3863#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4264#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2565#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1066#include "content/public/browser/web_contents_view.h"
[email protected]3c788372013-01-10 08:34:2867#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2168#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4869#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1870#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5471#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0372#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1673#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2974#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5475#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3476#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3777#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5678#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1679#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0181#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5283#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2484#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3685#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3186#include "webkit/glue/webpreferences.h"
87
[email protected]583418cc2013-01-17 14:01:1088#if defined(OS_ANDROID)
89#include "content/browser/android/date_time_chooser_android.h"
90#endif
91
[email protected]f66df822012-05-18 16:52:1792#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5093#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4194#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5795#endif
[email protected]3e45ba92009-02-20 21:09:0096
[email protected]c71fe6402012-08-15 15:22:5597#if defined(USE_AURA) && defined(USE_X11)
[email protected]54944cde2012-12-09 09:24:5998#include "ui/aura/window.h"
[email protected]c71fe6402012-08-15 15:22:5599#include "ui/base/touch/touch_factory.h"
100#endif // defined (USE_AURA) && defined(USE_X11)
101
[email protected]420ae012009-04-24 05:16:32102// Cross-Site Navigations
103//
[email protected]b172aee2012-04-10 17:05:26104// If a WebContentsImpl is told to navigate to a different web site (as
105// determined by SiteInstance), it will replace its current RenderViewHost with
106// a new RenderViewHost dedicated to the new SiteInstance. This works as
107// follows:
[email protected]420ae012009-04-24 05:16:32108//
109// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46110// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32111// - The pending RVH is "suspended," so that no navigation messages are sent to
112// its renderer until the onbeforeunload JavaScript handler has a chance to
113// run in the current RVH.
114// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
115// that it has a pending cross-site request. ResourceDispatcherHost will
116// check for this when the response arrives.
117// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46118// cancel all the pending logic. Otherwise we allow the pending RVH to send
119// the navigation request to its renderer.
120// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
121// main resource load on the pending RVH. It checks CrossSiteRequestManager
122// to see that it is a cross-site request, and installs a
123// CrossSiteResourceHandler.
124// - When RDH receives a response, the BufferedResourceHandler determines
125// whether it is a download. If so, it sends a message to the new renderer
126// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26127// pending RVH remains until the next DidNavigate event for this
128// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32129// - After RDH receives a response and determines that it is safe and not a
130// download, it pauses the response to first run the old page's onunload
131// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26132// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32133// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15134// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32135// the ResourceDispatcherHost, who unpauses the response. Data is then sent
136// to the pending RVH.
137// - The pending renderer sends a FrameNavigate message that invokes the
138// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46139// pending RVH.
[email protected]992db4c2011-05-12 15:37:15140// - The previous renderer is kept swapped out in RenderViewHostManager in case
141// the user goes back. The process only stays live if another tab is using
142// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32143
[email protected]6717bf272012-05-11 23:31:25144using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44145
[email protected]8ff00d72012-10-23 19:12:21146namespace content {
[email protected]420ae012009-04-24 05:16:32147namespace {
148
149// Amount of time we wait between when a key event is received and the renderer
150// is queried for its state and pushed to the NavigationEntry.
151const int kQueryStateDelay = 5000;
152
[email protected]6ebdc9b2010-09-27 16:55:57153const int kSyncWaitDelay = 40;
154
[email protected]82114f52012-03-20 22:53:41155const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05156
[email protected]795c28972012-12-06 06:13:39157static int StartDownload(content::RenderViewHost* rvh,
158 const GURL& url,
159 int image_size) {
160 static int g_next_favicon_download_id = 0;
161 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
162 ++g_next_favicon_download_id,
163 url,
164 image_size));
165 return g_next_favicon_download_id;
166}
167
[email protected]2c5569662011-03-22 20:45:02168ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21169 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50170 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16171 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47172 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02173 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47174 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02175 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23176 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
177 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16179 break; // Fall through to rest of function.
180 }
[email protected]5e369672009-11-03 23:48:30181
[email protected]59246c572012-02-10 13:32:13182 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
183 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36184 if (entry.restore_type() ==
185 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13186 if (entry.GetHasPostData())
187 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13189 }
[email protected]5e369672009-11-03 23:48:30190
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30192}
193
[email protected]10f417c52011-12-28 21:04:23194void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47195 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21196 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50197 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16198 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51199 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54200 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55201 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
202 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36203 if (!entry.GetBaseURLForDataURL().is_empty()) {
204 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
205 params->history_url_for_data_url = entry.GetVirtualURL();
206 }
[email protected]36fc0392011-12-25 03:59:51207 params->referrer = entry.GetReferrer();
208 params->transition = entry.GetTransitionType();
209 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00210 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55211 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34212 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47213 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48214 params->transferred_request_child_id =
215 entry.transferred_global_request_id().child_id;
216 params->transferred_request_request_id =
217 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22218 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00219 // Avoid downloading when in view-source mode.
220 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44221 params->is_post = entry.GetHasPostData();
222 if(entry.GetBrowserInitiatedPostData()) {
223 params->browser_initiated_post_data.assign(
224 entry.GetBrowserInitiatedPostData()->front(),
225 entry.GetBrowserInitiatedPostData()->front() +
226 entry.GetBrowserInitiatedPostData()->size());
227
228 }
[email protected]6c6b02d2011-09-02 03:36:47229
[email protected]7c16976c2012-08-04 02:38:23230 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
231 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
232 // We may have been redirected when navigating to the current URL.
233 // Use the URL the user originally intended to visit, if it's valid and if a
234 // POST wasn't involved; the latter case avoids issues with sending data to
235 // the wrong page.
236 params->url = entry.GetOriginalRequestURL();
237 } else {
238 params->url = entry.GetURL();
239 }
240
[email protected]951a64832012-10-11 16:26:37241 params->can_load_local_resources = entry.GetCanLoadLocalResources();
242
[email protected]6c6b02d2011-09-02 03:36:47243 if (delegate)
244 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34245}
246
[email protected]f98f5092012-05-19 00:08:14247int GetSwitchValueAsInt(
248 const CommandLine& command_line,
249 const std::string& switch_string,
250 int min_value) {
251 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
252 int int_value;
253 if (base::StringToInt(string_value, &int_value))
254 return std::max(min_value, int_value);
255 else
256 return min_value;
257}
258
[email protected]420ae012009-04-24 05:16:32259} // namespace
260
[email protected]54944cde2012-12-09 09:24:59261WebContents* WebContents::Create(const WebContents::CreateParams& params) {
262 return WebContentsImpl::CreateWithOpener(params, NULL);
[email protected]d1198fd2012-08-13 22:50:19263}
264
265WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59266 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19267 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59268 WebContentsImpl* new_contents = new WebContentsImpl(
269 params.browser_context, NULL);
[email protected]d1198fd2012-08-13 22:50:19270
271 for (SessionStorageNamespaceMap::const_iterator it =
272 session_storage_namespace_map.begin();
273 it != session_storage_namespace_map.end();
274 ++it) {
275 new_contents->GetController().SetSessionStorageNamespace(it->first,
276 it->second);
277 }
278
[email protected]54944cde2012-12-09 09:24:59279 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19280 return new_contents;
[email protected]a81343d232011-12-27 07:39:20281}
[email protected]746d3052012-05-22 15:15:47282
[email protected]299d7f12012-05-23 05:31:15283WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47284 return rvh->GetDelegate()->GetAsWebContents();
285}
286
[email protected]b172aee2012-04-10 17:05:26287// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32288
[email protected]b172aee2012-04-10 17:05:26289WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21290 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19291 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42292 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19293 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57294 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44295 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05296 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34297 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23298 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
299 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34300 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21301 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56302 upload_size_(0),
303 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47304 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57305 capturing_contents_(false),
306 is_being_destroyed_(false),
307 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55308 dialog_creator_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01309 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56310 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38311 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21312 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
313 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00314 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43315 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20316 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35317}
initial.commit09911bf2008-07-26 23:55:29318
[email protected]b172aee2012-04-10 17:05:26319WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32320 is_being_destroyed_ = true;
321
[email protected]b24b68a2012-09-24 21:57:26322 for (std::set<RenderWidgetHostImpl*>::iterator iter =
323 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
324 (*iter)->DetachDelegate();
325 }
326 created_widgets_.clear();
327
[email protected]3ab9cb82011-06-03 18:02:07328 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55329 if (dialog_creator_)
330 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07331
[email protected]da8543762012-03-20 08:52:20332 if (color_chooser_)
333 color_chooser_->End();
334
[email protected]420ae012009-04-24 05:16:32335 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32336
[email protected]ca13a442012-04-17 14:00:12337 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21338 NotificationService::current()->Notify(
339 NOTIFICATION_WEB_CONTENTS_DESTROYED,
340 Source<WebContents>(this),
341 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32342
343 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07344#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32345 // If we still have a window handle, destroy it. GetNativeView can return
346 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42347 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52348 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58349 if (host && host->GetView())
350 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42351 }
[email protected]420ae012009-04-24 05:16:32352#endif
[email protected]7ab1e7d62009-10-14 23:32:01353
354 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15355 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55356 base::TimeTicks now = base::TimeTicks::Now();
357 base::TimeTicks unload_start_time = close_start_time_;
358 if (!before_unload_end_time_.is_null())
359 unload_start_time = before_unload_end_time_;
360 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
361 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01362 }
[email protected]b5a1d11c2011-02-17 03:09:42363
[email protected]2db9bd72012-04-13 20:20:56364 FOR_EACH_OBSERVER(WebContentsObserver,
365 observers_,
366 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08367
[email protected]6934a702011-12-20 00:04:51368 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42369}
370
[email protected]d1198fd2012-08-13 22:50:19371WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59372 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19373 WebContentsImpl* opener) {
[email protected]54944cde2012-12-09 09:24:59374 WebContentsImpl* new_contents = new WebContentsImpl(
375 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19376
[email protected]54944cde2012-12-09 09:24:59377 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19378 return new_contents;
379}
380
[email protected]dd8c8232012-11-03 00:49:36381WebContentsImpl* WebContentsImpl::CreateGuest(
382 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53383 SiteInstance* site_instance,
[email protected]3de10bb32013-01-08 21:57:33384 int routing_id,
385 WebContentsImpl* opener_web_contents,
[email protected]dd8c8232012-11-03 00:49:36386 int guest_instance_id,
387 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]b5a40842012-11-28 15:26:11388
[email protected]3de10bb32013-01-08 21:57:33389 WebContentsImpl* new_contents = new WebContentsImpl(browser_context,
390 opener_web_contents);
[email protected]7a846df2012-09-20 19:17:39391
392 // This makes |new_contents| act as a guest.
393 // For more info, see comment above class BrowserPluginGuest.
[email protected]b5a40842012-11-28 15:26:11394 new_contents->browser_plugin_guest_.reset(
395 BrowserPluginGuest::Create(
396 guest_instance_id,
397 new_contents,
398 params));
399
[email protected]3de10bb32013-01-08 21:57:33400 WebContents::CreateParams create_params(browser_context, site_instance);
401 create_params.routing_id = routing_id;
402 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11403
[email protected]7a846df2012-09-20 19:17:39404 return new_contents;
405}
406
[email protected]b172aee2012-04-10 17:05:26407WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
408 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54409 WebPreferences prefs;
410
411 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
412
413 prefs.developer_extras_enabled = true;
414 prefs.javascript_enabled =
415 !command_line.HasSwitch(switches::kDisableJavaScript);
416 prefs.web_security_enabled =
417 !command_line.HasSwitch(switches::kDisableWebSecurity);
418 prefs.plugins_enabled =
419 !command_line.HasSwitch(switches::kDisablePlugins);
420 prefs.java_enabled =
421 !command_line.HasSwitch(switches::kDisableJava);
422
423 prefs.uses_page_cache =
424 command_line.HasSwitch(switches::kEnableFastback);
425 prefs.remote_fonts_enabled =
426 !command_line.HasSwitch(switches::kDisableRemoteFonts);
427 prefs.xss_auditor_enabled =
428 !command_line.HasSwitch(switches::kDisableXSSAuditor);
429 prefs.application_cache_enabled =
430 !command_line.HasSwitch(switches::kDisableApplicationCache);
431
432 prefs.local_storage_enabled =
433 !command_line.HasSwitch(switches::kDisableLocalStorage);
434 prefs.databases_enabled =
435 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01436#if defined(OS_ANDROID)
437 prefs.webaudio_enabled =
438 command_line.HasSwitch(switches::kEnableWebAudio);
439#else
[email protected]64d69de42012-02-06 00:19:54440 prefs.webaudio_enabled =
441 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01442#endif
[email protected]64d69de42012-02-06 00:19:54443
444 prefs.experimental_webgl_enabled =
445 GpuProcessHost::gpu_enabled() &&
446 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07447#if defined(OS_ANDROID)
448 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
449#else
[email protected]64d69de42012-02-06 00:19:54450 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07451#endif
[email protected]64d69de42012-02-06 00:19:54452
[email protected]5a073092012-06-08 00:42:51453 prefs.flash_3d_enabled =
454 GpuProcessHost::gpu_enabled() &&
455 !command_line.HasSwitch(switches::kDisableFlash3d);
456 prefs.flash_stage3d_enabled =
457 GpuProcessHost::gpu_enabled() &&
458 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19459
[email protected]64d69de42012-02-06 00:19:54460 prefs.gl_multisampling_enabled =
461 !command_line.HasSwitch(switches::kDisableGLMultisampling);
462 prefs.privileged_webgl_extensions_enabled =
463 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
464 prefs.site_specific_quirks_enabled =
465 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
466 prefs.allow_file_access_from_file_urls =
467 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
468 prefs.show_composited_layer_borders =
469 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
470 prefs.show_composited_layer_tree =
471 command_line.HasSwitch(switches::kShowCompositedLayerTree);
472 prefs.show_fps_counter =
473 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08474 prefs.accelerated_compositing_for_overflow_scroll_enabled =
[email protected]1315fdf2012-12-12 19:45:16475 command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll);
476 prefs.accelerated_compositing_for_scrollable_frames_enabled =
477 command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames);
[email protected]ab3dd632013-01-09 23:19:08478 prefs.composited_scrolling_for_frames_enabled =
479 command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames);
[email protected]8611a852012-05-23 22:11:19480 prefs.show_paint_rects =
481 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52482 prefs.render_vsync_enabled =
483 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54484 prefs.accelerated_compositing_enabled =
485 GpuProcessHost::gpu_enabled() &&
486 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54487 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23488 command_line.HasSwitch(switches::kForceCompositingMode) &&
489 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54490 prefs.fixed_position_compositing_enabled =
491 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
492 prefs.accelerated_2d_canvas_enabled =
493 GpuProcessHost::gpu_enabled() &&
494 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58495 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27496 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]a7f899e2013-01-09 12:15:44497 prefs.antialiased_2d_canvas_disabled =
498 command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
[email protected]64d69de42012-02-06 00:19:54499 prefs.accelerated_painting_enabled =
500 GpuProcessHost::gpu_enabled() &&
501 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
502 prefs.accelerated_filters_enabled =
503 GpuProcessHost::gpu_enabled() &&
504 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
[email protected]9bdcfd642012-11-14 21:24:26505 prefs.accelerated_compositing_for_3d_transforms_enabled =
506 prefs.accelerated_compositing_for_animation_enabled =
[email protected]64d69de42012-02-06 00:19:54507 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]9bdcfd642012-11-14 21:24:26508 prefs.accelerated_compositing_for_plugins_enabled =
[email protected]64d69de42012-02-06 00:19:54509 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
[email protected]9bdcfd642012-11-14 21:24:26510 prefs.accelerated_compositing_for_video_enabled =
[email protected]64d69de42012-02-06 00:19:54511 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54512 prefs.fullscreen_enabled =
513 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43514 prefs.css_sticky_position_enabled =
515 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29516 prefs.css_shaders_enabled =
517 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01518 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03519 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]8eb51382012-11-20 00:42:33520 prefs.css_grid_layout_enabled =
521 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]d7932532012-11-21 21:10:31522
523 bool touch_device_present = false;
[email protected]c71fe6402012-08-15 15:22:55524#if defined(USE_AURA) && defined(USE_X11)
[email protected]d7932532012-11-21 21:10:31525 touch_device_present =
[email protected]c71fe6402012-08-15 15:22:55526 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
527#endif
[email protected]25ee94f2012-09-11 19:16:16528#if defined(OS_WIN)
[email protected]d7932532012-11-21 21:10:31529 touch_device_present = ui::IsTouchDevicePresent();
[email protected]25ee94f2012-09-11 19:16:16530#endif
[email protected]d849b122012-07-18 07:35:26531#if defined(OS_ANDROID)
[email protected]d7932532012-11-21 21:10:31532 touch_device_present = true;
533#endif
534 const std::string touch_enabled_switch =
535 command_line.HasSwitch(switches::kTouchEvents) ?
536 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
537 switches::kTouchEventsAuto;
538
539 if (touch_enabled_switch.empty() ||
540 touch_enabled_switch == switches::kTouchEventsEnabled) {
541 prefs.touch_enabled = true;
542 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
543 prefs.touch_enabled = touch_device_present;
544 } else if (touch_enabled_switch != switches::kTouchEventsDisabled) {
545 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
546 }
547
548 prefs.device_supports_touch = prefs.touch_enabled && touch_device_present;
549#if defined(OS_ANDROID)
[email protected]d849b122012-07-18 07:35:26550 prefs.device_supports_mouse = false;
551#endif
[email protected]64d69de42012-02-06 00:19:54552
[email protected]b9c96ff2012-11-26 22:24:40553 prefs.touch_adjustment_enabled =
554 !command_line.HasSwitch(switches::kDisableTouchAdjustment);
555
[email protected]64d69de42012-02-06 00:19:54556#if defined(OS_MACOSX)
557 bool default_enable_scroll_animator = true;
558#else
559 // On CrOS, the launcher always passes in the --enable flag.
560 bool default_enable_scroll_animator = false;
561#endif
562 prefs.enable_scroll_animator = default_enable_scroll_animator;
563 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
564 prefs.enable_scroll_animator = true;
565 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
566 prefs.enable_scroll_animator = false;
567
568 prefs.visual_word_movement_enabled =
569 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54570
571 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32572 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54573 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39574 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21575 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54576 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21577 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54578 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21579 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19580 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21581 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19582 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21583 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54584 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21585 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54586 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21587 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]9bdcfd642012-11-14 21:24:26588 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
589 prefs.accelerated_compositing_for_animation_enabled = false;
[email protected]c521d7462012-10-03 22:28:20590 }
[email protected]8ff00d72012-10-23 19:12:21591 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]9bdcfd642012-11-14 21:24:26592 prefs.accelerated_compositing_for_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54593
594 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45595 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32596 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]9bdcfd642012-11-14 21:24:26597 prefs.accelerated_compositing_for_video_enabled = false;
598 prefs.accelerated_compositing_for_animation_enabled = false;
599 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
600 prefs.accelerated_compositing_for_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54601 }
602 }
603
[email protected]b9535422012-02-09 01:47:59604 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58605 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54606 prefs.loads_images_automatically = true;
607 prefs.javascript_enabled = true;
608 }
609
610 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
611
[email protected]2ee33532013-01-17 12:27:03612 // Force accelerated compositing and 2d canvas off for chrome: and about:
613 // pages (unless it's specifically allowed).
614 if ((url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]64d69de42012-02-06 00:19:54615 (url.SchemeIs(chrome::kAboutScheme) &&
616 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25617 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54618 prefs.accelerated_compositing_enabled = false;
619 prefs.accelerated_2d_canvas_enabled = false;
620 }
[email protected]43d9d782012-03-01 15:40:09621
[email protected]2ee33532013-01-17 12:27:03622 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
623 prefs.show_fps_counter = false;
624
[email protected]f98f5092012-05-19 00:08:14625 if (command_line.HasSwitch(switches::kDefaultTileWidth))
626 prefs.default_tile_width =
627 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
628 if (command_line.HasSwitch(switches::kDefaultTileHeight))
629 prefs.default_tile_height =
630 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
631 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
632 prefs.max_untiled_layer_width =
633 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
634 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
635 prefs.max_untiled_layer_height =
636 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
637
[email protected]ffabb1e2012-10-12 19:51:17638 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
639 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19640 // Only apply when using DIP coordinate system as this setting interferes
641 // with fixed layout mode.
[email protected]9bdcfd642012-11-14 21:24:26642 // TODO(danakj): Fixed layout mode is going away, so turn this on always.
[email protected]2486dce2012-05-23 17:18:19643 prefs.apply_default_device_scale_factor_in_compositor = true;
644 }
645
[email protected]9bdcfd642012-11-14 21:24:26646 prefs.apply_page_scale_factor_in_compositor =
[email protected]16ad47f82012-12-05 21:06:06647 command_line.HasSwitch(switches::kEnablePinch);
[email protected]f49dece2013-01-12 19:04:28648
649 if (command_line.HasSwitch(switches::kEnableCssTransformPinch)) {
650 prefs.apply_default_device_scale_factor_in_compositor = false;
651 prefs.apply_page_scale_factor_in_compositor = false;
652 }
653
[email protected]9bdcfd642012-11-14 21:24:26654 prefs.per_tile_painting_enabled =
655 command_line.HasSwitch(cc::switches::kEnablePerTilePainting);
[email protected]cf6cb622012-11-16 02:00:19656 prefs.accelerated_animation_enabled =
[email protected]9bdcfd642012-11-14 21:24:26657 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
658
[email protected]de023762012-07-26 17:10:17659 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
660 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10661
[email protected]e755a382012-09-13 17:16:35662 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
663 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12664
[email protected]6b4dcb072012-06-18 22:26:51665 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
666
[email protected]5c90d03d2013-01-10 17:16:02667 prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport);
668
[email protected]76f7d4882012-10-26 21:09:22669 prefs.deferred_image_decoding_enabled =
670 command_line.HasSwitch(switches::kEnableDeferredImageDecoding);
671
[email protected]8ff00d72012-10-23 19:12:21672 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54673
[email protected]97456602012-10-03 18:44:25674 // Disable compositing in guests until we have compositing path implemented
675 // for guests.
[email protected]747c30652012-12-18 20:35:53676 bool guest_compositing_enabled = command_line.HasSwitch(
677 switches::kEnableBrowserPluginCompositing);
678 if (rvh->GetProcess()->IsGuest() && !guest_compositing_enabled) {
[email protected]97456602012-10-03 18:44:25679 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06680 prefs.accelerated_compositing_enabled = false;
681 }
[email protected]97456602012-10-03 18:44:25682
[email protected]64d69de42012-02-06 00:19:54683 return prefs;
684}
685
[email protected]b172aee2012-04-10 17:05:26686RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28687 return &render_manager_;
688}
689
[email protected]7bb761892012-07-20 09:32:47690bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
691 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56692 if (GetWebUI() &&
693 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17694 return true;
[email protected]d2353452012-01-19 19:53:56695 }
[email protected]f82d57b52011-04-27 19:13:17696
[email protected]d8c660432011-12-22 20:51:25697 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
698 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10699 while ((observer = it.GetNext()) != NULL)
700 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53701 return true;
[email protected]403415a2011-01-10 18:57:53702
[email protected]7bb761892012-07-20 09:32:47703 // Message handlers should be aware of which RenderViewHost sent the
704 // message, which is temporarily stored in message_source_.
705 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18706 bool handled = true;
707 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26708 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58709 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
710 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24711 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
712 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18713 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
714 OnDidLoadResourceFromMemoryCache)
715 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
716 OnDidDisplayInsecureContent)
717 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
718 OnDidRunInsecureContent)
719 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
720 OnDocumentLoadedInFrame)
721 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26722 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
723 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17724 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
725 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25726 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26727 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59728 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21729 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20730 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
731 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
732 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16733 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45734 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10735 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20736 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
737 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
738 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
739 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29740 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50741 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50742 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
743 OnRequestPpapiBrokerPermission)
[email protected]19be7a62012-10-01 23:03:37744 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
745 OnBrowserPluginCreateGuest)
[email protected]795c28972012-12-06 06:13:39746 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
747 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10748#if defined(OS_ANDROID)
749 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
750 OnFindMatchRectsReply)
751 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
752 OnOpenDateTimeDialog)
753#endif
[email protected]8607c832013-01-18 14:11:57754 IPC_MESSAGE_HANDLER(ViewHostMsg_FrameDetached, OnFrameDetached)
[email protected]724159a2010-12-30 01:11:18755 IPC_MESSAGE_UNHANDLED(handled = false)
756 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47757 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18758
759 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21760 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18761 GetRenderProcessHost()->ReceivedBadMessage();
762 }
763
764 return handled;
765}
766
[email protected]b172aee2012-04-10 17:05:26767void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18768 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21769 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43770 if (delegate_)
771 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18772}
773
[email protected]d1198fd2012-08-13 22:50:19774NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56775 return controller_;
776}
777
[email protected]d1198fd2012-08-13 22:50:19778const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56779 return controller_;
780}
781
[email protected]8ff00d72012-10-23 19:12:21782BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55783 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30784}
785
[email protected]b172aee2012-04-10 17:05:26786const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31787 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23788 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51789 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31790}
791
[email protected]8ff00d72012-10-23 19:12:21792WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31793 return delegate_;
794}
795
[email protected]8ff00d72012-10-23 19:12:21796void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31797 // TODO(cbentzel): remove this debugging code?
798 if (delegate == delegate_)
799 return;
800 if (delegate_)
801 delegate_->Detach(this);
802 delegate_ = delegate;
803 if (delegate_)
804 delegate_->Attach(this);
805}
806
[email protected]8ff00d72012-10-23 19:12:21807RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41808 RenderViewHostImpl* host = render_manager_.current_host();
809 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16810}
811
[email protected]b172aee2012-04-10 17:05:26812RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31813 return render_manager_.current_host();
814}
815
[email protected]a04c9d02012-11-14 21:04:34816void WebContentsImpl::GetRenderViewHostAtPosition(
817 int x,
818 int y,
819 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
820 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
821 if (embedder)
822 embedder->GetRenderViewHostAtPosition(x, y, callback);
823 else
824 callback.Run(GetRenderViewHost(), x, y);
825}
826
[email protected]6b618e62012-08-16 12:59:18827int WebContentsImpl::GetRoutingID() const {
828 if (!GetRenderViewHost())
829 return MSG_ROUTING_NONE;
830
831 return GetRenderViewHost()->GetRoutingID();
832}
833
[email protected]b172aee2012-04-10 17:05:26834RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return render_manager_.GetRenderWidgetHostView();
836}
837
[email protected]8ff00d72012-10-23 19:12:21838WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return view_.get();
840}
841
[email protected]8ff00d72012-10-23 19:12:21842WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]3c788372013-01-10 08:34:28843 WebUIControllerFactory* factory =
844 GetContentClient()->browser()->GetWebUIControllerFactory();
845 if (!factory)
846 return NULL;
[email protected]d2353452012-01-19 19:53:56847 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]3c788372013-01-10 08:34:28848 WebUIController* controller =
849 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22850 if (controller) {
851 web_ui->SetController(controller);
852 return web_ui;
853 }
854
855 delete web_ui;
856 return NULL;
857}
858
[email protected]8ff00d72012-10-23 19:12:21859WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31860 return render_manager_.web_ui() ? render_manager_.web_ui()
861 : render_manager_.pending_web_ui();
862}
863
[email protected]8ff00d72012-10-23 19:12:21864WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34866}
867
[email protected]86ef6a392012-05-11 22:03:11868void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22869 if (GetUserAgentOverride() == override)
870 return;
871
872 renderer_preferences_.user_agent_override = override;
873
874 // Send the new override string to the renderer.
875 RenderViewHost* host = GetRenderViewHost();
876 if (host)
877 host->SyncRendererPrefs();
878
879 // Reload the page if a load is currently in progress to avoid having
880 // different parts of the page loaded using different user agents.
881 NavigationEntry* entry = controller_.GetActiveEntry();
882 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
883 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53884
885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
886 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11887}
888
889const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22890 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11891}
892
[email protected]b172aee2012-04-10 17:05:26893const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55894 // Transient entries take precedence. They are used for interstitial pages
895 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23896 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08897 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21898 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30899 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23900 if (entry) {
[email protected]b5cca982011-05-26 04:42:08901 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23902 }
[email protected]7ade2732011-02-10 00:13:58903 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
904 render_manager_.pending_web_ui() : render_manager_.web_ui();
905 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54906 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55907 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54908 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35909 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22910 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54911 if (!title.empty())
912 return title;
913 }
914 }
915
916 // We use the title for the last committed entry rather than a pending
917 // navigation entry. For example, when the user types in a URL, we want to
918 // keep the old page's title until the new load has committed and we get a new
919 // title.
[email protected]96d185d2009-04-24 03:28:54920 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23921 if (entry) {
[email protected]b5cca982011-05-26 04:42:08922 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23923 }
[email protected]987fc3a2011-05-26 14:18:09924
925 // |page_title_when_no_navigation_entry_| is finally used
926 // if no title cannot be retrieved.
927 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54928}
929
[email protected]b172aee2012-04-10 17:05:26930int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46931 return GetMaxPageIDForSiteInstance(GetSiteInstance());
932}
933
[email protected]b172aee2012-04-10 17:05:26934int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
935 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33936 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
937 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46938
[email protected]b6583592012-01-25 19:52:33939 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34940}
941
[email protected]b172aee2012-04-10 17:05:26942void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46943 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
944}
945
[email protected]b172aee2012-04-10 17:05:26946void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33947 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46948 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33949 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34950}
951
[email protected]b172aee2012-04-10 17:05:26952void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
953 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57954}
955
[email protected]b172aee2012-04-10 17:05:26956SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58957 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54958}
959
[email protected]b172aee2012-04-10 17:05:26960SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38961 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
962 render_manager_.pending_render_view_host() :
963 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58964 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38965}
966
[email protected]b172aee2012-04-10 17:05:26967bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31968 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49969}
970
[email protected]b172aee2012-04-10 17:05:26971bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31972 return waiting_for_response_;
973}
974
[email protected]b172aee2012-04-10 17:05:26975const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31976 return load_state_;
977}
978
[email protected]b172aee2012-04-10 17:05:26979const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31980 return load_state_host_;
981}
982
[email protected]b172aee2012-04-10 17:05:26983uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31984 return upload_size_;
985}
986
[email protected]b172aee2012-04-10 17:05:26987uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31988 return upload_position_;
989}
990
[email protected]b172aee2012-04-10 17:05:26991const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31992 return encoding_;
993}
994
[email protected]b172aee2012-04-10 17:05:26995bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31996 return displayed_insecure_content_;
997}
998
[email protected]b172aee2012-04-10 17:05:26999void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:311000 capturing_contents_ = cap;
1001}
1002
[email protected]b172aee2012-04-10 17:05:261003bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311004 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1005 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1006 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1010 int error_code) {
[email protected]443b80e2010-12-14 00:42:231011 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341012 return;
1013
[email protected]443b80e2010-12-14 00:42:231014 crashed_status_ = status;
1015 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211016 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341017}
1018
[email protected]b172aee2012-04-10 17:05:261019base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311020 return crashed_status_;
1021}
1022
[email protected]b172aee2012-04-10 17:05:261023bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311024 return is_being_destroyed_;
1025}
1026
[email protected]b172aee2012-04-10 17:05:261027void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341028 if (delegate_)
1029 delegate_->NavigationStateChanged(this, changed_flags);
1030}
1031
[email protected]3e324142012-06-25 18:26:331032base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1033 return last_selected_time_;
1034}
1035
[email protected]9e2e4632012-07-27 16:38:411036void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541037 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041038 RenderWidgetHostViewPort* rwhv =
1039 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161040 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411041 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431042#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161043 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431044#endif
1045 }
[email protected]96d185d2009-04-24 03:28:541046
[email protected]5ac20162010-11-24 23:33:111047 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381048
[email protected]9e2e4632012-07-27 16:38:411049 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591050
1051 // The resize rect might have changed while this was inactive -- send the new
1052 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581053 RenderViewHostImpl* rvh =
1054 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591055 if (rvh) {
1056 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1057 }
[email protected]96d185d2009-04-24 03:28:541058
[email protected]3e324142012-06-25 18:26:331059 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211060 NotificationService::current()->Notify(
1061 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1062 Source<WebContents>(this),
1063 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311064}
1065
[email protected]b172aee2012-04-10 17:05:261066void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311067 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521068 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1069 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261070 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521071 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331072 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521073 // calls us).
[email protected]c30585c2012-02-16 15:02:041074 RenderWidgetHostViewPort* rwhv =
1075 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161076 if (rwhv)
1077 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541078 }
1079
[email protected]375fa1b2012-05-22 22:05:371080 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211081 NotificationService::current()->Notify(
1082 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1083 Source<WebContents>(this),
1084 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371085}
1086
[email protected]b172aee2012-04-10 17:05:261087bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311088 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271089 return WillNotifyDisconnection() &&
1090 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581091 !static_cast<RenderViewHostImpl*>(
1092 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311093}
1094
[email protected]b172aee2012-04-10 17:05:261095void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271096 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251097 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271098}
1099
[email protected]b172aee2012-04-10 17:05:261100WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441101 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451102 // We pass our own opener so that the cloned page can access it if it was
1103 // before.
[email protected]54944cde2012-12-09 09:24:591104 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451105 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591106 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191107 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221108 FOR_EACH_OBSERVER(WebContentsObserver,
1109 observers_,
1110 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271111 return tc;
1112}
1113
[email protected]b172aee2012-04-10 17:05:261114gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271115 return view_->GetContentNativeView();
1116}
1117
[email protected]b172aee2012-04-10 17:05:261118gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271119 return view_->GetNativeView();
1120}
1121
[email protected]b172aee2012-04-10 17:05:261122void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271123 view_->GetContainerBounds(out);
1124}
1125
[email protected]b172aee2012-04-10 17:05:261126void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271127 view_->Focus();
1128}
1129
[email protected]14392a52012-05-02 20:28:441130void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211131 const NotificationSource& source,
1132 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441133 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211134 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1135 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441136 break;
[email protected]8ff00d72012-10-23 19:12:211137 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1138 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501139 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1140 i != pending_widget_views_.end(); ++i) {
1141 if (host->GetView() == i->second) {
1142 pending_widget_views_.erase(i);
1143 break;
1144 }
1145 }
1146 break;
1147 }
[email protected]14392a52012-05-02 20:28:441148 default:
1149 NOTREACHED();
1150 }
1151}
1152
[email protected]54944cde2012-12-09 09:24:591153void WebContentsImpl::Init(const WebContents::CreateParams& params) {
1154 render_manager_.Init(
1155 params.browser_context, params.site_instance, params.routing_id);
[email protected]d1198fd2012-08-13 22:50:191156
[email protected]8ff00d72012-10-23 19:12:211157 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191158 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1159 if (view_.get()) {
1160 CHECK(render_view_host_delegate_view_);
1161 } else {
[email protected]b5a40842012-11-28 15:26:111162 if (browser_plugin_guest_.get() &&
1163 CommandLine::ForCurrentProcess()->HasSwitch(
1164 switches::kEnableBrowserPluginCompositing)) {
1165 WebContentsViewGuest* rv = new WebContentsViewGuest(
1166 this,
1167 browser_plugin_guest_.get());
1168 render_view_host_delegate_view_ = rv;
1169 view_.reset(rv);
1170 } else {
1171 WebContentsViewDelegate* delegate =
1172 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1173 view_.reset(CreateWebContentsView(
1174 this, delegate, &render_view_host_delegate_view_));
1175 }
[email protected]d1198fd2012-08-13 22:50:191176 CHECK(render_view_host_delegate_view_);
1177 }
1178 CHECK(view_.get());
1179
[email protected]ed245db2012-12-18 08:00:451180 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591181 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191182
1183 // Listen for whether our opener gets destroyed.
1184 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211185 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1186 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191187 }
1188
1189 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211190 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1191 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191192#if defined(ENABLE_JAVA_BRIDGE)
1193 java_bridge_dispatcher_host_manager_.reset(
1194 new JavaBridgeDispatcherHostManager(this));
1195#endif
[email protected]583418cc2013-01-17 14:01:101196
1197#if defined(OS_ANDROID)
1198 date_time_chooser_.reset(new DateTimeChooserAndroid());
1199#endif
[email protected]d1198fd2012-08-13 22:50:191200}
1201
[email protected]14392a52012-05-02 20:28:441202void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1203 // Clear the opener if it has been closed.
1204 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211205 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1206 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441207 opener_ = NULL;
1208 }
1209}
1210
[email protected]b172aee2012-04-10 17:05:261211void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311212 observers_.AddObserver(observer);
1213}
1214
[email protected]b172aee2012-04-10 17:05:261215void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311216 observers_.RemoveObserver(observer);
1217}
1218
[email protected]b172aee2012-04-10 17:05:261219void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341220 if (delegate_)
1221 delegate_->ActivateContents(this);
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121225 if (delegate_)
1226 delegate_->DeactivateContents(this);
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481230 if (delegate_)
1231 delegate_->LostCapture();
1232}
1233
[email protected]b24b68a2012-09-24 21:57:261234void WebContentsImpl::RenderWidgetDeleted(
1235 RenderWidgetHostImpl* render_widget_host) {
1236 if (is_being_destroyed_) {
1237 // |created_widgets_| might have been destroyed.
1238 return;
1239 }
1240
1241 std::set<RenderWidgetHostImpl*>::iterator iter =
1242 created_widgets_.find(render_widget_host);
1243 if (iter != created_widgets_.end())
1244 created_widgets_.erase(iter);
1245}
1246
[email protected]b172aee2012-04-10 17:05:261247bool WebContentsImpl::PreHandleKeyboardEvent(
1248 const NativeWebKeyboardEvent& event,
1249 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481250 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131251 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481252}
1253
[email protected]b172aee2012-04-10 17:05:261254void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481255 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131256 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481257}
1258
[email protected]b172aee2012-04-10 17:05:261259void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431260 if (delegate_)
1261 delegate_->HandleMouseDown();
1262}
1263
[email protected]b172aee2012-04-10 17:05:261264void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481265 if (delegate_)
1266 delegate_->HandleMouseUp();
1267}
1268
[email protected]590a634e2012-07-19 16:38:231269void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481270 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231271 delegate_->HandlePointerActivate();
1272}
1273
1274void WebContentsImpl::HandleGestureBegin() {
1275 if (delegate_)
1276 delegate_->HandleGestureBegin();
1277}
1278
1279void WebContentsImpl::HandleGestureEnd() {
1280 if (delegate_)
1281 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481282}
1283
[email protected]b172aee2012-04-10 17:05:261284void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471285 if (delegate_)
1286 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1287}
1288
[email protected]b172aee2012-04-10 17:05:261289bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381290 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121291}
1292
[email protected]a9c81f02012-06-01 00:15:441293void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1294 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371295 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441296 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371297 } else {
1298 GotResponseToLockMouseRequest(false);
1299 }
1300}
1301
[email protected]b172aee2012-04-10 17:05:261302void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371303 if (delegate_)
1304 delegate_->LostMouseLock();
1305}
1306
[email protected]bafe6cd2012-05-23 23:09:501307void WebContentsImpl::CreateNewWindow(
1308 int route_id,
[email protected]97714c82012-06-06 10:15:131309 const ViewHostMsg_CreateWindow_Params& params,
1310 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501311 if (delegate_ && !delegate_->ShouldCreateWebContents(
1312 this, route_id, params.window_container_type, params.frame_name,
1313 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091314 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501315 return;
1316 }
1317
1318 // We usually create the new window in the same BrowsingInstance (group of
1319 // script-related windows), by passing in the current SiteInstance. However,
1320 // if the opener is being suppressed, we create a new SiteInstance in its own
1321 // BrowsingInstance.
1322 scoped_refptr<SiteInstance> site_instance =
1323 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571324 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501325 GetSiteInstance();
1326
1327 // Create the new web contents. This will automatically create the new
1328 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191329 WebContentsImpl* new_contents =
1330 new WebContentsImpl(GetBrowserContext(),
1331 params.opener_suppressed ? NULL : this);
1332
1333 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341334 //
1335 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191336 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211337 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571338 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591339 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211340 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341341 BrowserContext::GetStoragePartition(GetBrowserContext(),
1342 site_instance);
[email protected]d1198fd2012-08-13 22:50:191343 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341344 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191345 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1346 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1347 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1348 new_contents->GetController().SetSessionStorageNamespace(
1349 partition_id,
1350 session_storage_namespace);
[email protected]54944cde2012-12-09 09:24:591351 CreateParams create_params(GetBrowserContext(), site_instance);
1352 create_params.routing_id = route_id;
[email protected]ed245db2012-12-18 08:00:451353 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591354 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191355
[email protected]bafe6cd2012-05-23 23:09:501356 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1357
1358 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211359 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501360
1361 // TODO(brettw): It seems bogus that we have to call this function on the
1362 // newly created object and give it one of its own member variables.
1363 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1364
1365 // Save the created window associated with the route so we can show it
1366 // later.
1367 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1368 pending_contents_[route_id] = new_contents;
1369 }
1370
1371 if (delegate_) {
1372 delegate_->WebContentsCreated(
1373 this, params.opener_frame_id, params.target_url, new_contents);
1374 }
1375
1376 if (params.opener_suppressed) {
1377 // When the opener is suppressed, the original renderer cannot access the
1378 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001379 bool was_blocked = false;
1380 if (delegate_) {
1381 gfx::Rect initial_pos;
1382 delegate_->AddNewContents(
1383 this, new_contents, params.disposition, initial_pos,
1384 params.user_gesture, &was_blocked);
1385 }
1386 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211387 OpenURLParams open_params(params.target_url,
1388 Referrer(),
1389 CURRENT_TAB,
1390 PAGE_TRANSITION_LINK,
1391 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001392 new_contents->OpenURL(open_params);
1393 }
[email protected]bafe6cd2012-05-23 23:09:501394 }
1395}
1396
1397void WebContentsImpl::CreateNewWidget(int route_id,
1398 WebKit::WebPopupType popup_type) {
1399 CreateNewWidget(route_id, false, popup_type);
1400}
1401
1402void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1403 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1404}
1405
1406void WebContentsImpl::CreateNewWidget(int route_id,
1407 bool is_fullscreen,
1408 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211409 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501410 RenderWidgetHostImpl* widget_host =
1411 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261412 created_widgets_.insert(widget_host);
1413
[email protected]83918ec2013-01-10 15:37:191414 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1415 view_->CreateViewForPopupWidget(widget_host));
1416 if (!widget_view)
1417 return;
[email protected]bafe6cd2012-05-23 23:09:501418 if (!is_fullscreen) {
1419 // Popups should not get activated.
1420 widget_view->SetPopupType(popup_type);
1421 }
1422 // Save the created widget associated with the route so we can show it later.
1423 pending_widget_views_[route_id] = widget_view;
1424
1425#if defined(OS_MACOSX)
1426 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1427 // to allow it to survive the trip without being hosted.
1428 base::mac::NSObjectRetain(widget_view->GetNativeView());
1429#endif
1430}
1431
1432void WebContentsImpl::ShowCreatedWindow(int route_id,
1433 WindowOpenDisposition disposition,
1434 const gfx::Rect& initial_pos,
1435 bool user_gesture) {
1436 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001437 if (contents) {
1438 WebContentsDelegate* delegate = GetDelegate();
1439 if (delegate) {
1440 delegate->AddNewContents(
1441 this, contents, disposition, initial_pos, user_gesture, NULL);
1442 }
1443 }
[email protected]bafe6cd2012-05-23 23:09:501444}
1445
1446void WebContentsImpl::ShowCreatedWidget(int route_id,
1447 const gfx::Rect& initial_pos) {
1448 ShowCreatedWidget(route_id, false, initial_pos);
1449}
1450
1451void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1452 ShowCreatedWidget(route_id, true, gfx::Rect());
1453}
1454
1455void WebContentsImpl::ShowCreatedWidget(int route_id,
1456 bool is_fullscreen,
1457 const gfx::Rect& initial_pos) {
1458 if (delegate_)
1459 delegate_->RenderWidgetShowing();
1460
1461 RenderWidgetHostViewPort* widget_host_view =
1462 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1463 if (!widget_host_view)
1464 return;
1465 if (is_fullscreen) {
1466 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1467 } else {
1468 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1469 }
[email protected]89054502012-06-03 10:29:241470
1471 RenderWidgetHostImpl* render_widget_host_impl =
1472 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1473 render_widget_host_impl->Init();
1474 // Only allow privileged mouse lock for fullscreen render widget, which is
1475 // used to implement Pepper Flash fullscreen.
1476 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501477
1478#if defined(OS_MACOSX)
1479 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1480 // properly embedded (or purposefully ignored) we can release the retain we
1481 // took in CreateNewWidget().
1482 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1483#endif
1484}
1485
1486WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1487 PendingContents::iterator iter = pending_contents_.find(route_id);
1488
1489 // Certain systems can block the creation of new windows. If we didn't succeed
1490 // in creating one, just return NULL.
1491 if (iter == pending_contents_.end()) {
1492 return NULL;
1493 }
1494
1495 WebContentsImpl* new_contents = iter->second;
1496 pending_contents_.erase(route_id);
1497
1498 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1499 !new_contents->GetRenderViewHost()->GetView())
1500 return NULL;
1501
1502 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1503 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1504 return new_contents;
1505}
1506
1507RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1508 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1509 if (iter == pending_widget_views_.end()) {
1510 DCHECK(false);
1511 return NULL;
1512 }
1513
1514 RenderWidgetHostView* widget_host_view = iter->second;
1515 pending_widget_views_.erase(route_id);
1516
1517 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1518 if (!widget_host->GetProcess()->HasConnection()) {
1519 // The view has gone away or the renderer crashed. Nothing to do.
1520 return NULL;
1521 }
1522
1523 return widget_host_view;
1524}
1525
1526void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211527 const ContextMenuParams& params,
1528 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501529 // Allow WebContentsDelegates to handle the context menu operation first.
1530 if (delegate_ && delegate_->HandleContextMenu(params))
1531 return;
1532
[email protected]ba16e3a2012-09-07 04:14:521533 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501534}
1535
[email protected]f13b4202012-06-12 23:53:231536void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091537 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211538 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231539 if (delegate_)
1540 delegate_->RequestMediaAccessPermission(this, request, callback);
1541 else
[email protected]8ff00d72012-10-23 19:12:211542 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231543}
1544
[email protected]b172aee2012-04-10 17:05:261545void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231546 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331547 if (delegate_)
1548 delegate_->UpdatePreferredSize(this, pref_size);
1549}
1550
[email protected]b172aee2012-04-10 17:05:261551void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341552 if (delegate_)
1553 delegate_->ResizeDueToAutoResize(this, new_size);
1554}
1555
[email protected]b172aee2012-04-10 17:05:261556WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201557 if (!delegate_)
1558 return NULL;
[email protected]00c37fc2011-08-02 00:22:501559
[email protected]e5d549d2011-12-28 01:29:201560 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201561 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341562}
1563
[email protected]6b618e62012-08-16 12:59:181564bool WebContentsImpl::Send(IPC::Message* message) {
1565 if (!GetRenderViewHost()) {
1566 delete message;
1567 return false;
1568 }
1569
1570 return GetRenderViewHost()->Send(message);
1571}
1572
[email protected]b172aee2012-04-10 17:05:261573bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501574 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251575 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231576 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251577 reload_type);
[email protected]876bc832010-09-07 16:29:541578}
[email protected]96d185d2009-04-24 03:28:541579
[email protected]ba45bfd2012-05-22 21:51:441580void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211581 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441582 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1583 RenderViewForInterstitialPageCreated(render_view_host));
1584}
1585
[email protected]b172aee2012-04-10 17:05:261586bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231587 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501588 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401589 // The renderer will reject IPC messages with URLs longer than
1590 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211591 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401592 return false;
1593
[email protected]9f76c1e2012-03-05 15:15:581594 RenderViewHostImpl* dest_render_view_host =
1595 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401596 if (!dest_render_view_host)
1597 return false; // Unable to create the desired render view host.
1598
[email protected]80a8fad2011-01-29 04:02:381599 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071600 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581601 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]3c788372013-01-10 08:34:281602 WebUIControllerFactory* factory =
1603 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271604 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501605 bool is_allowed_in_web_ui_renderer =
[email protected]3c788372013-01-10 08:34:281606 factory &&
1607 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1608 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211609 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231610 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271611 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211612 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231613 CHECK(0);
1614 }
[email protected]54ec6472010-04-09 19:39:581615
[email protected]7bb761892012-07-20 09:32:471616 // Notify observers that we will navigate in this RV.
1617 FOR_EACH_OBSERVER(WebContentsObserver,
1618 observers_,
1619 AboutToNavigateRenderView(dest_render_view_host));
1620
[email protected]96d185d2009-04-24 03:28:541621 // Used for page load time metrics.
1622 current_load_start_ = base::TimeTicks::Now();
1623
1624 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341625 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271626 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471627 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341628 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541629
[email protected]36fc0392011-12-25 03:59:511630 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541631 // HACK!! This code suppresses javascript: URLs from being added to
1632 // session history, which is what we want to do for javascript: URLs that
1633 // do not generate content. What we really need is a message from the
1634 // renderer telling us that a new page was not created. The same message
1635 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511636 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541637 return false;
1638 }
1639
[email protected]3c9e1872010-11-18 16:17:491640 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251641 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041642 observers_,
[email protected]36fc0392011-12-25 03:59:511643 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541644
[email protected]09b29342011-06-24 19:18:481645 if (delegate_)
1646 delegate_->DidNavigateToPendingEntry(this);
1647
[email protected]d5f942ba2008-09-26 19:30:341648 return true;
1649}
1650
[email protected]b172aee2012-04-10 17:05:261651void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331652 const SiteInstance* site_instance,
1653 int history_length,
1654 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411655 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1656 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191657 if (render_manager_.pending_render_view_host()) {
1658 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141659 return;
[email protected]9e1ad4b2011-08-14 16:49:191660 }
[email protected]9f76c1e2012-03-05 15:15:581661 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191662 if (!rvh) {
1663 NOTREACHED();
1664 return;
1665 }
[email protected]9f76c1e2012-03-05 15:15:581666 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191667 NOTREACHED();
1668 return;
1669 }
[email protected]6b618e62012-08-16 12:59:181670 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1671 history_length,
1672 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141673}
1674
[email protected]b172aee2012-04-10 17:05:261675void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271676 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541677 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1678 return;
1679 }
[email protected]9f76c1e2012-03-05 15:15:581680 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541681}
1682
[email protected]b172aee2012-04-10 17:05:261683bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271684 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541685}
1686
[email protected]b172aee2012-04-10 17:05:261687InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271688 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221689}
1690
[email protected]b172aee2012-04-10 17:05:261691bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161692 // WebKit creates Document object when MIME type is application/xhtml+xml,
1693 // so we also support this MIME type.
1694 return contents_mime_type_ == "text/html" ||
1695 contents_mime_type_ == "text/xml" ||
1696 contents_mime_type_ == "application/xhtml+xml" ||
1697 contents_mime_type_ == "text/plain" ||
1698 contents_mime_type_ == "text/css" ||
1699 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1700}
1701
[email protected]b172aee2012-04-10 17:05:261702void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591703 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161704 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551705 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211706 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141707 return;
[email protected]c7dd2f62011-07-18 15:57:591708 }
1709
1710 Stop();
1711
1712 // Create the save package and possibly prompt the user for the name to save
1713 // the page as. The user prompt is an asynchronous operation that runs on
1714 // another thread.
1715 save_package_ = new SavePackage(this);
1716 save_package_->GetSaveInfo();
1717}
1718
1719// Used in automated testing to bypass prompting the user for file names.
1720// Instead, the names and paths are hard coded rather than running them through
1721// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261722bool WebContentsImpl::SavePage(const FilePath& main_file,
1723 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211724 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591725 // Stop the page from navigating.
1726 Stop();
1727
1728 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211729 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591730}
1731
[email protected]b172aee2012-04-10 17:05:261732void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121733 const FilePath& file,
1734 const base::Callback<void(const FilePath&, int64)>& callback) {
1735 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1736}
1737
[email protected]b172aee2012-04-10 17:05:261738bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231739 NavigationEntryImpl* active_entry =
1740 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321741 return (active_entry != NULL &&
1742 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511743 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321744}
1745
[email protected]b172aee2012-04-10 17:05:261746const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271747 return contents_mime_type_;
1748}
1749
[email protected]b172aee2012-04-10 17:05:261750bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271751 return notify_disconnection_;
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311755 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181756 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161757}
1758
[email protected]b172aee2012-04-10 17:05:261759void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311760 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181761 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161762}
1763
[email protected]8ff00d72012-10-23 19:12:211764RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271765 return &renderer_preferences_;
1766}
1767
[email protected]b172aee2012-04-10 17:05:261768void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271769 new_tab_start_time_ = time;
1770}
1771
[email protected]b172aee2012-04-10 17:05:261772base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271773 return new_tab_start_time_;
1774}
1775
[email protected]e35ccd52012-05-23 16:22:471776void WebContentsImpl::Close() {
1777 Close(GetRenderViewHost());
1778}
1779
[email protected]b172aee2012-04-10 17:05:261780void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151781 if (close_start_time_.is_null())
1782 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011783}
1784
[email protected]b172aee2012-04-10 17:05:261785bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191786#if defined(OS_CHROMEOS)
1787 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1788 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511789 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201790 return false;
1791 return true;
[email protected]46624bf2010-06-09 16:04:191792#else
1793 return true;
1794#endif
1795}
1796
[email protected]b172aee2012-04-10 17:05:261797void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521798 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581799 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511800 if (delegate_)
1801 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341802}
1803
[email protected]e35ccd52012-05-23 16:22:471804void WebContentsImpl::UserGestureDone() {
1805 OnUserGesture();
1806}
1807
[email protected]b172aee2012-04-10 17:05:261808void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271809 closed_by_user_gesture_ = value;
1810}
1811
[email protected]b172aee2012-04-10 17:05:261812bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271813 return closed_by_user_gesture_;
1814}
1815
[email protected]b172aee2012-04-10 17:05:261816double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051817 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561818 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251819 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171820 return 0;
[email protected]b75b8292010-10-01 07:28:251821
1822 double zoom_level;
1823 if (temporary_zoom_settings_) {
1824 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581825 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251826 } else {
[email protected]2ae88d12011-10-14 09:11:191827 GURL url;
[email protected]10f417c52011-12-28 21:04:231828 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191829 // Since zoom map is updated using rewritten URL, use rewritten URL
1830 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511831 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191832 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251833 }
[email protected]d0b8d092010-10-25 04:05:171834 return zoom_level;
1835}
[email protected]b75b8292010-10-01 07:28:251836
[email protected]b172aee2012-04-10 17:05:261837int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591838 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171839 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011840 // Calculate the zoom percent from the factor. Round up to the nearest whole
1841 // number.
[email protected]b75b8292010-10-01 07:28:251842 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011843 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251844 *enable_decrement = percent > minimum_zoom_percent_;
1845 *enable_increment = percent < maximum_zoom_percent_;
1846 return percent;
1847}
1848
[email protected]b172aee2012-04-10 17:05:261849void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501850 if (!delegate_)
1851 return;
1852
[email protected]10f417c52011-12-28 21:04:231853 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501854 if (!active_entry)
1855 return;
1856
[email protected]36fc0392011-12-25 03:59:511857 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121858}
1859
[email protected]b172aee2012-04-10 17:05:261860void WebContentsImpl::ViewFrameSource(const GURL& url,
1861 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271862 if (!delegate_)
1863 return;
1864
1865 delegate_->ViewSourceForFrame(this, url, content_state);
1866}
1867
[email protected]b172aee2012-04-10 17:05:261868int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271869 return minimum_zoom_percent_;
1870}
1871
[email protected]b172aee2012-04-10 17:05:261872int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271873 return maximum_zoom_percent_;
1874}
1875
[email protected]b172aee2012-04-10 17:05:261876gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231877 return preferred_size_;
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271881 return content_restrictions_;
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]3c788372013-01-10 08:34:281885 WebUIControllerFactory* factory =
1886 GetContentClient()->browser()->GetWebUIControllerFactory();
1887 if (!factory)
1888 return WebUI::kNoWebUI;
1889 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271890}
1891
[email protected]8ff00d72012-10-23 19:12:211892WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271893 // When there is a pending navigation entry, we want to use the pending WebUI
1894 // that goes along with it to control the basic flags. For example, we want to
1895 // show the pending URL in the URL bar, so we want the display_url flag to
1896 // be from the pending entry.
1897 //
1898 // The confusion comes because there are multiple possibilities for the
1899 // initial load in a tab as a side effect of the way the RenderViewHostManager
1900 // works.
1901 //
1902 // - For the very first tab the load looks "normal". The new tab Web UI is
1903 // the pending one, and we want it to apply here.
1904 //
1905 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1906 // get switched to the one previously associated with the new tab pages.
1907 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1908 // have a committed Web UI in this case.
1909 //
1910 // This condition handles all of these cases:
1911 //
1912 // - First load in first tab: no committed nav entry + pending nav entry +
1913 // pending dom ui:
1914 // -> Use pending Web UI if any.
1915 //
1916 // - First load in second tab: no committed nav entry + pending nav entry +
1917 // no pending Web UI:
1918 // -> Use the committed Web UI if any.
1919 //
1920 // - Second navigation in any tab: committed nav entry + pending nav entry:
1921 // -> Use pending Web UI if any.
1922 //
1923 // - Normal state with no load: committed nav entry + no pending nav entry:
1924 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251925 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271926 (controller_.GetLastCommittedEntry() ||
1927 render_manager_.pending_web_ui()))
1928 return render_manager_.pending_web_ui();
1929 return render_manager_.web_ui();
1930}
1931
[email protected]b172aee2012-04-10 17:05:261932bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271933 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581934 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271935}
1936
[email protected]b172aee2012-04-10 17:05:261937bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441938 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501939}
1940
[email protected]b172aee2012-04-10 17:05:261941void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321942 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181943 Send(new ViewMsg_DidChooseColorResponse(
1944 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201945}
1946
[email protected]b172aee2012-04-10 17:05:261947void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181948 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201949 if (delegate_)
1950 delegate_->DidEndColorChooser();
1951 color_chooser_ = NULL;
1952}
1953
[email protected]795c28972012-12-06 06:13:391954int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
1955 const FaviconDownloadCallback& callback) {
1956 RenderViewHost* host = GetRenderViewHost();
1957 int id = StartDownload(host, url, image_size);
1958 favicon_download_map_[id] = callback;
1959 return id;
1960}
1961
[email protected]b172aee2012-04-10 17:05:261962bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211963 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271964 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221965 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231966 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411967 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271968}
1969
[email protected]b172aee2012-04-10 17:05:261970void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271971 if (delegate_)
1972 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211973}
1974
[email protected]3a3b75a2012-06-01 08:38:361975void WebContentsImpl::OnRegisterIntentService(
1976 const webkit_glue::WebIntentServiceData& data,
1977 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431978 if (delegate_)
1979 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301980}
1981
[email protected]b172aee2012-04-10 17:05:261982void WebContentsImpl::OnWebIntentDispatch(
1983 const webkit_glue::WebIntentData& intent,
1984 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431985 if (!delegate_)
1986 return;
1987
[email protected]0d9989d2011-12-21 20:26:001988 WebIntentsDispatcherImpl* intents_dispatcher =
1989 new WebIntentsDispatcherImpl(this, intent, intent_id);
1990 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301991}
1992
[email protected]54047eb52012-05-08 21:45:571993void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211994 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571995 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131996 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571997 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:571998 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211999 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]ead9009e2013-01-07 22:06:322000 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182001 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212002 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572003 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082004 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182005
[email protected]d974a0a2013-01-10 01:43:572006 if (is_main_frame)
2007 DidChangeLoadProgress(0);
2008
[email protected]0d60f0192011-04-14 12:40:102009 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252010 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132011 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2012 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322013 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542014
2015 if (is_main_frame) {
2016 // Notify observers about the provisional change in the main frame URL.
2017 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2018 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542019 render_view_host));
2020 }
2021}
2022
2023void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212024 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542025 int32 page_id,
[email protected]400992b2012-06-14 00:03:542026 const GURL& source_url,
2027 const GURL& target_url) {
2028 // TODO(creis): Remove this method and have the pre-rendering code listen to
2029 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2030 // instead. See http://crbug.com/78512.
2031 GURL validated_source_url(source_url);
2032 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212033 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542034 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082035 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2036 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542037 NavigationEntry* entry;
2038 if (page_id == -1) {
2039 entry = controller_.GetPendingEntry();
2040 } else {
2041 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2042 page_id);
2043 }
2044 if (!entry || entry->GetURL() != validated_source_url)
2045 return;
2046
2047 // Notify observers about the provisional change in the main frame URL.
2048 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2049 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542050 render_view_host));
[email protected]724159a2010-12-30 01:11:182051}
2052
[email protected]54047eb52012-05-08 21:45:572053void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212054 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582055 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2056 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2057 << ", error_code: " << params.error_code
2058 << ", error_description: " << params.error_description
2059 << ", is_main_frame: " << params.is_main_frame
2060 << ", showing_repost_interstitial: " <<
2061 params.showing_repost_interstitial
2062 << ", frame_id: " << params.frame_id;
2063 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212064 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572065 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082066 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182067
[email protected]d7b175e2011-10-11 15:31:582068 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182069 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2070 // This means that the interstitial won't be torn down properly, which is
2071 // bad. But if we have an interstitial, go back to another tab type, and
2072 // then load the same interstitial again, we could end up getting the first
2073 // interstitial's "failed" message (as a result of the cancel) when we're on
2074 // the second one.
2075 //
2076 // We can't tell this apart, so we think we're tearing down the current page
2077 // which will cause a crash later one. There is also some code in
2078 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2079 // out because of this problem.
2080 //
2081 // http://code.google.com/p/chromium/issues/detail?id=2855
2082 // Because this will not tear down the interstitial properly, if "back" is
2083 // back to another tab type, the interstitial will still be somewhat alive
2084 // in the previous tab type. If you navigate somewhere that activates the
2085 // tab with the interstitial again, you'll see a flash before the new load
2086 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272087 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182088 LOG(WARNING) << "Discarding message during interstitial.";
2089 return;
2090 }
2091
[email protected]a16690732012-07-13 19:22:172092 // Do not clear the pending entry if one exists, so that the user's typed
2093 // URL is not lost when a navigation fails or is aborted. We'll allow
2094 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182095
[email protected]54047eb52012-05-08 21:45:572096 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182097 }
2098
[email protected]d8c660432011-12-22 20:51:252099 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582100 observers_,
2101 DidFailProvisionalLoad(params.frame_id,
2102 params.is_main_frame,
2103 validated_url,
2104 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462105 params.error_description,
2106 render_view_host));
[email protected]724159a2010-12-30 01:11:182107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182110 const GURL& url,
[email protected]70435962011-08-02 20:13:282111 const std::string& security_info,
2112 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182113 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282114 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192115 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182116 cache.Increment();
2117
2118 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082119 int cert_id = 0;
2120 net::CertStatus cert_status = 0;
2121 int security_bits = -1;
2122 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212123 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2124 &security_bits, &connection_status);
2125 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002126 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2127 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182128
[email protected]8ff00d72012-10-23 19:12:212129 NotificationService::current()->Notify(
2130 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2131 Source<NavigationController>(&controller_),
2132 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212136 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182137 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192138 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182139}
2140
[email protected]b172aee2012-04-10 17:05:262141void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022142 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232143 LOG(INFO) << security_origin << " ran insecure content from "
2144 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212145 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412146 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212147 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182148 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412149 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192150 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182151}
2152
[email protected]b172aee2012-04-10 17:05:262153void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182154 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472156 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312160 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062161 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312162 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062163 GURL validated_url(url);
2164 RenderProcessHost* render_process_host = message_source_->GetProcess();
2165 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252166 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472167 DidFinishLoad(frame_id, validated_url, is_main_frame,
2168 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312169}
2170
[email protected]b172aee2012-04-10 17:05:262171void WebContentsImpl::OnDidFailLoadWithError(
2172 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062173 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262174 bool is_main_frame,
2175 int error_code,
2176 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062177 GURL validated_url(url);
2178 RenderProcessHost* render_process_host = message_source_->GetProcess();
2179 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252180 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312181 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472182 error_code, error_description,
2183 message_source_));
[email protected]724159a2010-12-30 01:11:182184}
2185
[email protected]b172aee2012-04-10 17:05:262186void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272187 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432188 if (delegate_)
2189 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172190}
2191
[email protected]b172aee2012-04-10 17:05:262192void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262193 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232194 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252195 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262196 if (!entry)
2197 return;
2198 // Note that we don't call NavigationController::GotToOffset() as we don't
2199 // want to create a pending navigation entry (it might end up lingering
2200 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252201 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212202 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512203 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212204 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472205 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572206
2207 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2208 // it in now that we know. This allows us to find the entry when it commits.
2209 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232210 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332211 entry->set_site_instance(
2212 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572213 }
[email protected]216813952011-05-19 22:21:262214 }
2215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2218 int maximum_percent,
2219 bool remember) {
[email protected]216813952011-05-19 22:21:262220 minimum_zoom_percent_ = minimum_percent;
2221 maximum_zoom_percent_ = maximum_percent;
2222 temporary_zoom_settings_ = !remember;
2223}
2224
[email protected]20b433a2012-05-15 21:23:462225void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212226 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552227 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262228 // Check if the URL to save matches the URL of the main frame. Since this
2229 // message originates from Pepper plugins, it may not be the case if the
2230 // plugin is an embedded element.
2231 GURL main_frame_url = GetURL();
2232 if (!main_frame_url.is_valid())
2233 return;
2234 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462235 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::OnEnumerateDirectory(int request_id,
2239 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432240 if (!delegate_)
2241 return;
2242
[email protected]b9535422012-02-09 01:47:592243 ChildProcessSecurityPolicyImpl* policy =
2244 ChildProcessSecurityPolicyImpl::GetInstance();
2245 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2246 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212247}
2248
[email protected]b172aee2012-04-10 17:05:262249void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432250 if (delegate_)
2251 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202252}
2253
[email protected]b172aee2012-04-10 17:05:262254void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2255 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362256 const string16& title,
2257 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432258 if (!delegate_)
2259 return;
2260
[email protected]b9535422012-02-09 01:47:592261 ChildProcessSecurityPolicyImpl* policy =
2262 ChildProcessSecurityPolicyImpl::GetInstance();
2263 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2264 return;
[email protected]3a3b75a2012-06-01 08:38:362265 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202266}
2267
[email protected]b172aee2012-04-10 17:05:262268void WebContentsImpl::OnFindReply(int request_id,
2269 int number_of_matches,
2270 const gfx::Rect& selection_rect,
2271 int active_match_ordinal,
2272 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432273 if (delegate_) {
2274 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2275 active_match_ordinal, final_update);
2276 }
[email protected]b888919c2011-09-02 00:32:162277}
2278
[email protected]59363fc92012-09-05 03:46:312279#if defined(OS_ANDROID)
2280void WebContentsImpl::OnFindMatchRectsReply(
2281 int version,
2282 const std::vector<gfx::RectF>& rects,
2283 const gfx::RectF& active_rect) {
2284 if (delegate_)
2285 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2286}
[email protected]583418cc2013-01-17 14:01:102287
2288void WebContentsImpl::OnOpenDateTimeDialog(int type, const std::string& value) {
2289 date_time_chooser_->ShowDialog(
2290 GetContentNativeView(), GetRenderViewHost(), type, value);
2291}
2292
[email protected]59363fc92012-09-05 03:46:312293#endif
2294
[email protected]cf4d6e742013-01-10 14:06:422295void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path,
2296 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442297 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422298 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452299}
2300
[email protected]b172aee2012-04-10 17:05:262301void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2302 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102303 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252304 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102305 AppCacheAccessed(manifest_url, blocked_by_policy));
2306}
2307
[email protected]b172aee2012-04-10 17:05:262308void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322309 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432310 color_chooser_ = delegate_ ?
2311 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202312}
2313
[email protected]b172aee2012-04-10 17:05:262314void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202315 if (color_chooser_ &&
2316 color_chooser_id == color_chooser_->identifier())
2317 color_chooser_->End();
2318}
2319
[email protected]b172aee2012-04-10 17:05:262320void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322321 SkColor color) {
[email protected]da8543762012-03-20 08:52:202322 if (color_chooser_ &&
2323 color_chooser_id == color_chooser_->identifier())
2324 color_chooser_->SetSelectedColor(color);
2325}
2326
[email protected]9f2a9d72012-04-16 16:02:222327void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2328 const FilePath& path,
2329 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552330 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2331
[email protected]3fc07c52012-04-20 00:27:442332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2333 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292334}
2335
[email protected]d0759f492012-04-19 22:50:502336// This exists for render views that don't have a WebUI, but do have WebUI
2337// bindings enabled.
2338void WebContentsImpl::OnWebUISend(const GURL& source_url,
2339 const std::string& name,
2340 const base::ListValue& args) {
2341 if (delegate_)
2342 delegate_->WebUISend(this, source_url, name, args);
2343}
2344
[email protected]d8415ad92012-08-23 14:40:502345void WebContentsImpl::OnRequestPpapiBrokerPermission(
2346 int request_id,
2347 const GURL& url,
2348 const FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162349 if (!delegate_) {
2350 OnPpapiBrokerPermissionResult(request_id, false);
2351 return;
[email protected]d8415ad92012-08-23 14:40:502352 }
2353
[email protected]8c8fc292012-11-23 18:57:162354 if (!delegate_->RequestPpapiBrokerPermission(
2355 this, url, plugin_path,
2356 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2357 base::Unretained(this), request_id))) {
2358 NOTIMPLEMENTED();
2359 OnPpapiBrokerPermissionResult(request_id, false);
2360 }
[email protected]d8415ad92012-08-23 14:40:502361}
2362
2363void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2364 bool result) {
2365 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2366 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2367 request_id,
2368 result));
2369}
2370
[email protected]19be7a62012-10-01 23:03:372371void WebContentsImpl::OnBrowserPluginCreateGuest(
[email protected]92a01cc2012-09-29 14:13:592372 int instance_id,
[email protected]dd8c8232012-11-03 00:49:362373 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]19be7a62012-10-01 23:03:372374 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
2375 // specific messages for this WebContents (through its
2376 // BrowserPluginEmbedderHelper). This means that any message from browser
2377 // plugin renderer prior to CreateGuest will be ignored.
[email protected]7a846df2012-09-20 19:17:392378 // For more info, see comment above classes BrowserPluginEmbedder and
2379 // BrowserPluginGuest.
[email protected]b6bcd8c2012-10-03 06:03:582380 // The first BrowserPluginHostMsg_CreateGuest message from this WebContents'
2381 // embedder render process is handled here. Once BrowserPluginEmbedder is
2382 // created, all subsequent BrowserPluginHostMsg_CreateGuest messages are
2383 // intercepted by the BrowserPluginEmbedderHelper and handled by the
2384 // BrowserPluginEmbedder. Thus, this code will not be executed if a
2385 // BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392386 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392387 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212388 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]3997b1b22012-12-20 01:02:542389 BrowserPluginHostMsg_CreateGuest create_guest_msg(
2390 GetRenderViewHost()->GetRoutingID(), instance_id, params);
2391 browser_plugin_embedder_->OnMessageReceived(create_guest_msg);
[email protected]19be7a62012-10-01 23:03:372392}
2393
[email protected]795c28972012-12-06 06:13:392394void WebContentsImpl::OnDidDownloadFavicon(
2395 int id,
2396 const GURL& image_url,
[email protected]795c28972012-12-06 06:13:392397 int requested_size,
2398 const std::vector<SkBitmap>& bitmaps) {
2399 FaviconDownloadMap::iterator iter = favicon_download_map_.find(id);
2400 if (iter == favicon_download_map_.end()) {
2401 // Currently WebContents notifies us of ANY downloads so that it is
2402 // possible to get here.
2403 return;
2404 }
2405 if (!iter->second.is_null()) {
[email protected]8383aa962013-01-10 05:48:532406 iter->second.Run(id, image_url, requested_size, bitmaps);
[email protected]795c28972012-12-06 06:13:392407 }
2408 favicon_download_map_.erase(id);
2409}
2410
2411void WebContentsImpl::OnUpdateFaviconURL(
2412 int32 page_id,
2413 const std::vector<FaviconURL>& candidates) {
2414 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2415 DidUpdateFaviconURL(page_id, candidates));
2416}
2417
[email protected]8607c832013-01-18 14:11:572418void WebContentsImpl::OnFrameDetached(int64 frame_id) {
2419 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2420 FrameDetached(message_source_, frame_id));
2421}
2422
[email protected]818915cd2012-11-20 13:14:112423void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
2424 ThreeDAPIType requester) {
2425 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2426 DidBlock3DAPIs(url, requester));
2427}
2428
[email protected]96d185d2009-04-24 03:28:542429// Notifies the RenderWidgetHost instance about the fact that the page is
2430// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262431void WebContentsImpl::SetIsLoading(bool is_loading,
2432 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542433 if (is_loading == is_loading_)
2434 return;
2435
2436 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212437 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542438 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562439 upload_size_ = 0;
2440 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542441 }
2442
2443 render_manager_.SetIsLoading(is_loading);
2444
2445 is_loading_ = is_loading;
2446 waiting_for_response_ = is_loading;
2447
[email protected]6ebdc9b2010-09-27 16:55:572448 if (delegate_)
2449 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212450 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542451
[email protected]8ff00d72012-10-23 19:12:212452 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2453 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542454 if (details)
[email protected]8ff00d72012-10-23 19:12:212455 det = Details<LoadNotificationDetails>(details);
2456 NotificationService::current()->Notify(
2457 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542458}
2459
[email protected]b172aee2012-04-10 17:05:262460void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212461 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322462 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562463 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382464 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442465 // that opened the window, as long as both renderers have the same
2466 // privileges.
[email protected]1fd1a502011-03-30 16:55:562467 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562468 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582469 // web_ui might be NULL if the URL refers to a non-existent extension.
2470 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402471 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522472 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442473 }
2474 }
[email protected]1fd1a502011-03-30 16:55:562475 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442476 }
2477
[email protected]4e697b042011-07-08 06:44:562478 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322479 // Clear the status bubble. This is a workaround for a bug where WebKit
2480 // doesn't let us know that the cursor left an element during a
2481 // transition (this is also why the mouse cursor remains as a hand after
2482 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2483 // clear the bubble when a user navigates to a named anchor in the same
2484 // page.
[email protected]36fc0392011-12-25 03:59:512485 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322486 }
2487
[email protected]a6e82fc2010-02-24 22:28:142488 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472489 // Once the main frame is navigated, we're no longer considered to have
2490 // displayed insecure content.
2491 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172492 }
[email protected]ce5c4502009-05-06 16:46:112493
[email protected]3c9e1872010-11-18 16:17:492494 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252495 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042496 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322497}
2498
[email protected]b172aee2012-04-10 17:05:262499void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322500 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212501 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322502 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062503 // If we navigate off the page, reset JavaScript state. This does nothing
2504 // to prevent a malicious script from spamming messages, since the script
2505 // could just reload the page to stop blocking.
2506 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552507 dialog_creator_->ResetJavaScriptState(this);
2508 dialog_creator_ = NULL;
2509 }
[email protected]420ae012009-04-24 05:16:322510
[email protected]3c9e1872010-11-18 16:17:492511 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252512 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042513 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322514}
2515
[email protected]b172aee2012-04-10 17:05:262516void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462517 // If we are creating a RVH for a restored controller, then we need to make
2518 // sure the RenderView starts with a next_page_id_ larger than the number
2519 // of restored entries. This must be called before the RenderView starts
2520 // navigating (to avoid a race between the browser updating max_page_id and
2521 // the renderer updating next_page_id_). Because of this, we only call this
2522 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562523 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582524 if (max_restored_page_id >
2525 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2526 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2527 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322528}
2529
[email protected]b172aee2012-04-10 17:05:262530bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2531 const string16& title) {
[email protected]420ae012009-04-24 05:16:322532 // For file URLs without a title, use the pathname instead. In the case of a
2533 // synthesized title, we don't want the update to count toward the "one set
2534 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512535 string16 final_title;
[email protected]420ae012009-04-24 05:16:322536 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512537 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2538 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322539 explicit_set = false; // Don't count synthetic titles toward the set limit.
2540 } else {
[email protected]acafd272011-07-26 17:35:572541 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322542 explicit_set = true;
2543 }
2544
[email protected]987fc3a2011-05-26 14:18:092545 // If a page is created via window.open and never navigated,
2546 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552547 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092548 if (entry) {
[email protected]36fc0392011-12-25 03:59:512549 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092550 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322551
[email protected]36fc0392011-12-25 03:59:512552 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092553 } else {
2554 if (page_title_when_no_navigation_entry_ == final_title)
2555 return false; // Nothing changed, don't bother.
2556
2557 page_title_when_no_navigation_entry_ = final_title;
2558 }
[email protected]420ae012009-04-24 05:16:322559
[email protected]420ae012009-04-24 05:16:322560 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232561 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322562
[email protected]8ff00d72012-10-23 19:12:212563 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462564 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142565
[email protected]8ff00d72012-10-23 19:12:212566 NotificationService::current()->Notify(
2567 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2568 Source<WebContents>(this),
2569 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042570
[email protected]420ae012009-04-24 05:16:322571 return true;
2572}
2573
[email protected]35e0e0792012-11-30 02:35:482574void WebContentsImpl::NotifySwapped(RenderViewHost* old_render_view_host) {
[email protected]420ae012009-04-24 05:16:322575 // After sending out a swap notification, we need to send a disconnect
2576 // notification so that clients that pick up a pointer to |this| can NULL the
2577 // pointer. See Bug 1230284.
2578 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212579 NotificationService::current()->Notify(
2580 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2581 Source<WebContents>(this),
[email protected]35e0e0792012-11-30 02:35:482582 Details<RenderViewHost>(old_render_view_host));
[email protected]7a846df2012-09-20 19:17:392583
2584 // Ensure that the associated embedder gets cleared after a RenderViewHost
2585 // gets swapped, so we don't reuse the same embedder next time a
2586 // RenderViewHost is attached to this WebContents.
2587 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322588}
2589
[email protected]b172aee2012-04-10 17:05:262590void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322591 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212592 NotificationService::current()->Notify(
2593 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2594 Source<WebContents>(this),
2595 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322596}
2597
[email protected]b172aee2012-04-10 17:05:262598void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322599 if (!notify_disconnection_)
2600 return;
2601
2602 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212603 NotificationService::current()->Notify(
2604 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2605 Source<WebContents>(this),
2606 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322607}
2608
[email protected]5a3bdf52012-05-24 15:12:572609RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2610 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322611}
2612
[email protected]8d3347f2009-07-09 22:00:212613RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262614WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212615 return &render_manager_;
2616}
2617
[email protected]8ff00d72012-10-23 19:12:212618RendererPreferences WebContentsImpl::GetRendererPrefs(
2619 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462620 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512621}
2622
[email protected]b172aee2012-04-10 17:05:262623WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172624 return this;
2625}
2626
[email protected]b172aee2012-04-10 17:05:262627gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172628 if (delegate_)
2629 return delegate_->GetRootWindowResizerRect();
2630 return gfx::Rect();
2631}
2632
[email protected]7a846df2012-09-20 19:17:392633void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2634 if (browser_plugin_embedder_.get())
2635 browser_plugin_embedder_.reset();
2636}
2637
[email protected]b172aee2012-04-10 17:05:262638void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442639 // Don't send notifications if we are just creating a swapped-out RVH for
2640 // the opener chain. These won't be used for view-source or WebUI, so it's
2641 // ok to return early.
2642 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2643 return;
2644
[email protected]8ff00d72012-10-23 19:12:212645 NotificationService::current()->Notify(
2646 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2647 Source<WebContents>(this),
2648 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232649 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322650 if (!entry)
2651 return;
2652
2653 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352654 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562655 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582656 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322657
2658 if (entry->IsViewSourceMode()) {
2659 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182660 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582661 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322662 }
[email protected]0666aef2009-05-13 19:48:082663
[email protected]d487beefe2011-12-21 05:41:212664 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262665
2666 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252667 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322668}
2669
[email protected]b172aee2012-04-10 17:05:262670void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522671 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322672 // Don't notify the world, since this came from a renderer in the
2673 // background.
2674 return;
2675 }
2676
2677 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312678 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232679 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302680
2681 // Restore the focus to the tab (otherwise the focus will be on the top
2682 // window).
[email protected]484ae5912010-09-29 19:16:142683 if (was_crashed && !FocusLocationBarByDefault() &&
2684 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302685 Focus();
[email protected]484ae5912010-09-29 19:16:142686 }
[email protected]32ded2212011-11-10 18:51:432687
[email protected]d8c660432011-12-22 20:51:252688 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322689}
2690
[email protected]b172aee2012-04-10 17:05:262691void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2692 base::TerminationStatus status,
2693 int error_code) {
[email protected]151a63d2011-12-20 22:32:522694 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322695 // The pending page's RenderViewHost is gone.
2696 return;
2697 }
2698
2699 SetIsLoading(false, NULL);
2700 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232701 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312702 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322703
[email protected]d8c660432011-12-22 20:51:252704 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272705 observers_,
[email protected]be1f56ab2011-12-22 06:55:312706 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322707}
2708
[email protected]b172aee2012-04-10 17:05:262709void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482710 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252711 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062712}
2713
[email protected]b172aee2012-04-10 17:05:262714void WebContentsImpl::DidNavigate(
2715 RenderViewHost* rvh,
2716 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e3d92a7f2013-01-10 02:35:052717 if (PageTransitionIsMainFrame(params.transition)) {
2718 // When overscroll navigation gesture is enabled, a screenshot of the page
2719 // in its current state is taken so that it can be used during the
2720 // nav-gesture. It is necessary to take the screenshot here, before calling
2721 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2722 // WebContents::GetRenderViewHost to return the new host, instead of the one
2723 // that may have just been swapped out.
2724 controller_.TakeScreenshot();
2725
[email protected]420ae012009-04-24 05:16:322726 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052727 }
[email protected]8030f012009-09-25 18:09:372728
[email protected]434f69f2012-02-06 21:56:522729 // Update the site of the SiteInstance if it doesn't have one yet, unless
2730 // this is for about:blank. In that case, the SiteInstance can still be
2731 // considered unused until a navigation to a real page.
2732 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2733 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332734 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522735 }
[email protected]420ae012009-04-24 05:16:322736
2737 // Need to update MIME type here because it's referred to in
2738 // UpdateNavigationCommands() called by RendererDidNavigate() to
2739 // determine whether or not to enable the encoding menu.
2740 // It's updated only for the main frame. For a subframe,
2741 // RenderView::UpdateURL does not set params.contents_mime_type.
2742 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2743 // TODO(jungshik): Add a test for the encoding menu to avoid
2744 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212745 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322746 contents_mime_type_ = params.contents_mime_type;
2747
[email protected]8ff00d72012-10-23 19:12:212748 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002749 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392750
[email protected]a9c0bfe2010-09-17 08:35:222751 // Send notification about committed provisional loads. This notification is
2752 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2753 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212754 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072755 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2756 // that is not recorded in the navigation history. For the purpose of
2757 // tracking navigation events, we treat this event as a sub frame navigation
2758 // event.
2759 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212760 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222761 // Whether or not a page transition was triggered by going backward or
2762 // forward in the history is only stored in the navigation controller's
2763 // entry list.
2764 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512765 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212766 PAGE_TRANSITION_FORWARD_BACK)) {
2767 transition_type = PageTransitionFromInt(
2768 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222769 }
[email protected]0d60f0192011-04-14 12:40:102770 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102772 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462773 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222774 }
2775
[email protected]76543b92009-08-31 17:27:452776 if (!did_navigate)
2777 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322778
2779 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2780 // for the appropriate notification (best) or you can add it to
2781 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2782 // necessary, please).
2783
2784 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002785 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322786 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512787 if (delegate_)
2788 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002789 }
[email protected]420ae012009-04-24 05:16:322790 DidNavigateAnyFramePostCommit(rvh, details, params);
2791}
2792
[email protected]b172aee2012-04-10 17:05:262793void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2794 int32 page_id,
2795 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152796 // Ensure that this state update comes from either the active RVH or one of
2797 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522798 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322799
2800 // We must be prepared to handle state updates for any page, these occur
2801 // when the user is scrolling and entering form data, as well as when we're
2802 // leaving a page, in which case our state may have already been moved to
2803 // the next page. The navigation controller will look up the appropriate
2804 // NavigationEntry and update it when it is notified via the delegate.
2805
2806 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582807 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322808 if (entry_index < 0)
2809 return;
[email protected]10f417c52011-12-28 21:04:232810 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322811
[email protected]36fc0392011-12-25 03:59:512812 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322813 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512814 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322815 controller_.NotifyEntryChanged(entry, entry_index);
2816}
2817
[email protected]b172aee2012-04-10 17:05:262818void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2819 int32 page_id,
2820 const string16& title,
2821 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322822 // If we have a title, that's a pretty good indication that we've started
2823 // getting useful data.
2824 SetNotWaitingForResponse();
2825
[email protected]73eb2602012-02-09 19:50:552826 // Try to find the navigation entry, which might not be the current one.
2827 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232828 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582829 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092830
[email protected]73eb2602012-02-09 19:50:552831 // We can handle title updates when we don't have an entry in
2832 // UpdateTitleForEntry, but only if the update is from the current RVH.
2833 if (!entry && rvh != GetRenderViewHost())
2834 return;
2835
[email protected]a49e10b2011-08-01 23:57:462836 // TODO(evan): make use of title_direction.
2837 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092838 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322839 return;
2840
2841 // Broadcast notifications when the UI should be updated.
2842 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212843 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322844}
2845
[email protected]b172aee2012-04-10 17:05:262846void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2847 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312848 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322849}
2850
[email protected]b172aee2012-04-10 17:05:262851void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512852 if (delegate_)
2853 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322854}
2855
[email protected]b172aee2012-04-10 17:05:262856void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292857 // The UI may be in an event-tracking loop, such as between the
2858 // mouse-down and mouse-up in text selection or a button click.
2859 // Defer the close until after tracking is complete, so that we
2860 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292861 // TODO(shess): This could get more fine-grained. For instance,
2862 // closing a tab in another window while selecting text in the
2863 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212864 if (GetView()->IsEventTracking()) {
2865 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292866 return;
2867 }
2868
[email protected]420ae012009-04-24 05:16:322869 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522870 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512871 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322872}
2873
[email protected]b172aee2012-04-10 17:05:262874void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522875 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512876 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572877}
2878
[email protected]b172aee2012-04-10 17:05:262879void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512880 if (delegate_ && delegate_->IsPopupOrPanel(this))
2881 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322882}
2883
[email protected]8ff00d72012-10-23 19:12:212884void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322885 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492886
[email protected]82114f52012-03-20 22:53:412887 if (delegate_ && content_restrictions_)
2888 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492889
2890 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292891 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2892 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322893}
2894
[email protected]8ff00d72012-10-23 19:12:212895void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322896 scoped_ptr<LoadNotificationDetails> details;
2897
[email protected]10f417c52011-12-28 21:04:232898 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322899 // An entry may not exist for a stop when loading an initial blank page or
2900 // if an iframe injected by script into a blank page finishes loading.
2901 if (entry) {
[email protected]420ae012009-04-24 05:16:322902 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2903
2904 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512905 entry->GetVirtualURL(),
2906 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322907 elapsed,
2908 &controller_,
2909 controller_.GetCurrentEntryIndex()));
2910 }
2911
[email protected]420ae012009-04-24 05:16:322912 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492913
2914 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2916 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322917}
2918
[email protected]b172aee2012-04-10 17:05:262919void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162920 controller_.DiscardNonCommittedEntries();
2921
2922 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212923 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162924}
2925
[email protected]b172aee2012-04-10 17:05:262926void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262927#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512928 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132929 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262930#endif
[email protected]1a3c3cb2010-12-16 21:03:402931}
2932
[email protected]7cc78902012-12-06 02:32:262933void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2934 // Clear our opener so that future cross-process navigations don't have an
2935 // opener assigned.
2936 opener_ = NULL;
2937
2938 // Notify all swapped out RenderViewHosts for this tab. This is important
2939 // in case we go back to them, or if another window in those processes tries
2940 // to access window.opener.
2941 render_manager_.DidDisownOpener(rvh);
2942}
2943
[email protected]0720b532012-08-28 19:23:372944void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2945 render_manager_.DidUpdateFrameTree(rvh);
2946}
2947
[email protected]87717d0e2012-04-26 02:58:432948void WebContentsImpl::DocumentAvailableInMainFrame(
2949 RenderViewHost* render_view_host) {
2950 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2951 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102952}
2953
[email protected]b172aee2012-04-10 17:05:262954void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082955 RenderViewHost* render_view_host,
2956 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212957 NotificationService::current()->Notify(
2958 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2959 Source<WebContents>(this),
2960 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082961}
2962
[email protected]196159d2012-05-04 17:26:542963void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2964 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212965 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262966 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:182967 int64 source_frame_id,
2968 bool is_cross_site_redirect) {
[email protected]196159d2012-05-04 17:26:542969 // If this came from a swapped out RenderViewHost, we only allow the request
2970 // if we are still in the same BrowsingInstance.
2971 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2972 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2973 return;
2974 }
2975
[email protected]4ad5d77d2011-12-03 02:00:482976 // Delegate to RequestTransferURL because this is just the generic
2977 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582978 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]e2caa032012-11-15 23:29:182979 GlobalRequestID(), is_cross_site_redirect);
[email protected]4ad5d77d2011-12-03 02:00:482980}
2981
[email protected]b172aee2012-04-10 17:05:262982void WebContentsImpl::RequestTransferURL(
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,
2986 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:182987 const GlobalRequestID& old_request_id,
2988 bool is_cross_site_redirect) {
[email protected]e5d549d2011-12-28 01:29:202989 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212990 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582991 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352992 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322993 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2994 // generated suggestions).
2995 //
[email protected]e0112912011-02-02 22:54:352996 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162997 // want web sites to see a referrer of "chrome://blah" (and some
2998 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322999 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:213000 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:223001 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:483002 false /* is_renderer_initiated */);
3003 params.transferred_global_request_id = old_request_id;
3004 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:223005 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:323006 } else {
[email protected]6bf6a6b52012-02-03 15:41:433007 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:213008 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:483009 params.transferred_global_request_id = old_request_id;
[email protected]e2caa032012-11-15 23:29:183010 params.is_cross_site_redirect = is_cross_site_redirect;
[email protected]4ad5d77d2011-12-03 02:00:483011 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:583012 }
3013 if (new_contents) {
3014 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583016 DidOpenRequestedURL(new_contents,
3017 url,
3018 referrer,
3019 disposition,
3020 transition_type,
3021 source_frame_id));
[email protected]420ae012009-04-24 05:16:323022 }
3023}
3024
[email protected]e1c3a552012-05-04 20:51:323025void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3026 // Tell the active RenderViewHost to run unload handlers and close, as long
3027 // as the request came from a RenderViewHost in the same BrowsingInstance.
3028 // In most cases, we receive this from a swapped out RenderViewHost.
3029 // It is possible to receive it from one that has just been swapped in,
3030 // in which case we might as well deliver the message anyway.
3031 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3032 GetRenderViewHost()->ClosePage();
3033}
3034
[email protected]f546640b2012-05-15 00:03:493035void WebContentsImpl::RouteMessageEvent(
3036 RenderViewHost* rvh,
3037 const ViewMsg_PostMessage_Params& params) {
3038 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363039 // came from a RenderViewHost in the same BrowsingInstance or if this
3040 // WebContents is dedicated to a browser plugin guest.
3041 // Note: This check means that an embedder could theoretically receive a
3042 // postMessage from anyone (not just its own guests). However, this is
3043 // probably not a risk for apps since other pages won't have references
3044 // to App windows.
3045 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3046 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493047 return;
3048
3049 ViewMsg_PostMessage_Params new_params(params);
3050
[email protected]0720b532012-08-28 19:23:373051 // If the renderer has changed while the post message is being routed,
3052 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:193053 // TODO(nasko): Check for process ID and target frame id mismatch, once
3054 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:373055
[email protected]f546640b2012-05-15 00:03:493056 // If there is a source_routing_id, translate it to the routing ID for
3057 // the equivalent swapped out RVH in the target process. If we need
3058 // to create a swapped out RVH for the source tab, we create its opener
3059 // chain as well, since those will also be accessible to the target page.
3060 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3061 // Try to look up the WebContents for the source page.
3062 WebContentsImpl* source_contents = NULL;
3063 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3064 rvh->GetProcess()->GetID(), params.source_routing_id);
3065 if (source_rvh) {
3066 source_contents = static_cast<WebContentsImpl*>(
3067 source_rvh->GetDelegate()->GetAsWebContents());
3068 }
3069
3070 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363071 if (GetBrowserPluginGuest()) {
3072 // We create a swapped out RenderView for the embedder in the guest's
3073 // render process but we intentionally do not expose the embedder's
3074 // opener chain to it.
3075 new_params.source_routing_id =
3076 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3077 } else {
3078 new_params.source_routing_id =
3079 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3080 }
[email protected]f546640b2012-05-15 00:03:493081 } else {
3082 // We couldn't find it, so don't pass a source frame.
3083 new_params.source_routing_id = MSG_ROUTING_NONE;
3084 }
3085 }
3086
3087 // In most cases, we receive this from a swapped out RenderViewHost.
3088 // It is possible to receive it from one that has just been swapped in,
3089 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183090 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493091}
3092
[email protected]b172aee2012-04-10 17:05:263093void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343094 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413095 const string16& message,
3096 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323097 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213098 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323099 IPC::Message* reply_msg,
3100 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073101 // Suppress JavaScript dialogs when requested. Also suppress messages when
3102 // showing an interstitial as it's shown over the previous page and we don't
3103 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503104 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583105 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273106 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073107 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523108 delegate_->ShouldSuppressDialogs() ||
3109 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323110
3111 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213112 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433113 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553114 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523115 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433116 this,
3117 frame_url.GetOrigin(),
3118 accept_lang,
3119 javascript_message_type,
3120 message,
[email protected]51da7e32012-01-30 19:24:523121 default_prompt,
[email protected]b172aee2012-04-10 17:05:263122 base::Bind(&WebContentsImpl::OnDialogClosed,
3123 base::Unretained(this),
3124 rvh,
3125 reply_msg),
[email protected]51da7e32012-01-30 19:24:523126 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323127 }
[email protected]3ab9cb82011-06-03 18:02:073128
3129 if (suppress_this_message) {
3130 // If we are suppressing messages, just reply as if the user immediately
3131 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343132 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073133 }
3134
3135 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323136}
3137
[email protected]b172aee2012-04-10 17:05:263138void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3139 const string16& message,
3140 bool is_reload,
3141 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583142 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513143 if (delegate_)
3144 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073145
3146 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583147 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073148 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523149 delegate_->ShouldSuppressDialogs() ||
3150 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153151 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343152 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583153 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503154 return;
3155 }
[email protected]3ab9cb82011-06-03 18:02:073156
[email protected]7ab1e7d62009-10-14 23:32:013157 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553158 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523159 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323160 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263161 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523162 reply_msg));
[email protected]420ae012009-04-24 05:16:323163}
3164
[email protected]a796f202012-05-30 14:14:253165bool WebContentsImpl::AddMessageToConsole(int32 level,
3166 const string16& message,
3167 int32 line_no,
3168 const string16& source_id) {
3169 if (!delegate_)
3170 return false;
3171 return delegate_->AddMessageToConsole(this, level, message, line_no,
3172 source_id);
3173}
3174
[email protected]b172aee2012-04-10 17:05:263175WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333176 // We want to base the page config off of the real URL, rather than the
3177 // display URL.
3178 GURL url = controller_.GetActiveEntry()
3179 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3180 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323181}
3182
[email protected]0eba810b2012-10-18 03:19:363183int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213184 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363185 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3186}
3187
[email protected]b172aee2012-04-10 17:05:263188void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273189 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253190 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223191
[email protected]ea114722012-03-12 01:11:253192 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173193 if (rdh) // NULL in unittests.
3194 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253195}
3196
[email protected]b172aee2012-04-10 17:05:263197void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443198 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253199 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443200}
3201
[email protected]b172aee2012-04-10 17:05:263202void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3203 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153204 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523205 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153206 return;
3207
[email protected]9f76c1e2012-03-05 15:15:583208 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3209
[email protected]e5fc1632011-08-08 07:51:533210 // Ignore renderer unresponsive event if debugger is attached to the tab
3211 // since the event may be a result of the renderer sitting on a breakpoint.
3212 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363213 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533214 return;
3215
[email protected]420ae012009-04-24 05:16:323216 if (is_during_unload) {
3217 // Hang occurred while firing the beforeunload/unload handler.
3218 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583219 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323220
3221 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3222 return;
3223
3224 // If the tab hangs in the beforeunload/unload handler there's really
3225 // nothing we can do to recover. Pretend the unload listeners have
3226 // all fired and close the tab. If the hang is in the beforeunload handler
3227 // then the user will not have the option of cancelling the close.
3228 Close(rvh);
3229 return;
3230 }
3231
[email protected]9f76c1e2012-03-05 15:15:583232 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473233 return;
3234
[email protected]6934a702011-12-20 00:04:513235 if (delegate_)
3236 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323237}
3238
[email protected]b172aee2012-04-10 17:05:263239void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513240 if (delegate_)
3241 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323242}
3243
[email protected]b172aee2012-04-10 17:05:263244void WebContentsImpl::LoadStateChanged(
3245 const GURL& url,
3246 const net::LoadStateWithParam& load_state,
3247 uint64 upload_position,
3248 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323249 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563250 upload_position_ = upload_position;
3251 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503252 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213253 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303254 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213255 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323256 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463257 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213258 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463259 }
[email protected]420ae012009-04-24 05:16:323260}
3261
[email protected]b172aee2012-04-10 17:05:263262void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513263 if (delegate_)
3264 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253265}
3266
[email protected]b172aee2012-04-10 17:05:263267void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553268 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323269 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553270 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513271 if (delegate_)
3272 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323273}
3274
[email protected]b172aee2012-04-10 17:05:263275void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543276 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233277 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3278 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543279}
3280
[email protected]b172aee2012-04-10 17:05:263281void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103282 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263283 gfx::Size size = view_->GetContainerSize();
3284 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3285 // here during container initialization and normal window size will be set
3286 // later. In case of tab duplication this resizing to 0x0 prevents setting
3287 // normal size later so just ignore it.
3288 if (!size.IsEmpty())
3289 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323290}
3291
[email protected]35e0e0792012-11-30 02:35:483292void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) {
3293 NotifySwapped(rvh);
[email protected]3a3d47472010-07-15 21:03:543294}
3295
[email protected]14392a52012-05-02 20:28:443296int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3297 SiteInstance* instance) {
3298 if (!opener_)
3299 return MSG_ROUTING_NONE;
3300
3301 // Recursively create RenderViews for anything else in the opener chain.
3302 return opener_->CreateOpenerRenderViews(instance);
3303}
3304
3305int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3306 int opener_route_id = MSG_ROUTING_NONE;
3307
3308 // If this tab has an opener, ensure it has a RenderView in the given
3309 // SiteInstance as well.
3310 if (opener_)
3311 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3312
[email protected]0720b532012-08-28 19:23:373313 // If any of the renderers for this WebContents has the same SiteInstance,
3314 // use it.
3315 if (render_manager_.current_host()->GetSiteInstance() == instance)
3316 return render_manager_.current_host()->GetRoutingID();
3317
3318 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3319 instance);
3320 if (rvh)
3321 return rvh->GetRoutingID();
3322
[email protected]14392a52012-05-02 20:28:443323 // Create a swapped out RenderView in the given SiteInstance if none exists,
3324 // setting its opener to the given route_id. Return the new view's route_id.
3325 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3326}
3327
[email protected]b172aee2012-04-10 17:05:263328NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193329 return GetController();
[email protected]3a3d47472010-07-15 21:03:543330}
3331
[email protected]b172aee2012-04-10 17:05:263332WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563333 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323334}
3335
[email protected]10f417c52011-12-28 21:04:233336NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263337 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323338 return controller_.GetLastCommittedEntry();
3339}
3340
[email protected]b172aee2012-04-10 17:05:263341bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443342 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443343 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323344 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523345
[email protected]420ae012009-04-24 05:16:323346 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443347 if (rwh_view)
3348 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323349
[email protected]74ce1ad2011-12-16 21:51:463350 // Make sure we use the correct starting page_id in the new RenderView.
3351 UpdateMaxPageIDIfNecessary(render_view_host);
3352 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583353 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463354
[email protected]9f76c1e2012-03-05 15:15:583355 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493356 render_view_host)->CreateRenderView(string16(),
3357 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133358 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523359 return false;
[email protected]14392a52012-05-02 20:28:443360 }
[email protected]a4127722011-04-27 23:13:523361
[email protected]e60c0232011-11-11 19:56:353362#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503363 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3364 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443365 if (rwh_view) {
3366 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3367 render_widget_host->WasResized();
3368 }
[email protected]f8233cc2011-05-31 20:24:503369#endif
3370
[email protected]420ae012009-04-24 05:16:323371 return true;
3372}
3373
[email protected]b172aee2012-04-10 17:05:263374void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3375 IPC::Message* reply_msg,
3376 bool success,
3377 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543378 if (is_showing_before_unload_dialog_ && !success) {
3379 // If a beforeunload dialog is canceled, we need to stop the throbber from
3380 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293381 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353382 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543383
[email protected]3bbacc5b2012-04-17 17:46:153384 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553385 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543386 }
3387 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583388 static_cast<RenderViewHostImpl*>(
3389 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543390}
3391
[email protected]b172aee2012-04-10 17:05:263392void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213393 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123394 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103395}
[email protected]f45d2a72010-03-08 23:28:353396
[email protected]b172aee2012-04-10 17:05:263397void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213398 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263399 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573400 DownloadManager* dlm =
3401 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143402 if (!dlm)
3403 return;
3404 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263405 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143406 const NavigationEntry* entry = controller_.GetActiveEntry();
3407 if (entry)
3408 post_id = entry->GetPostID();
3409 }
[email protected]c5a5c0842012-05-04 20:05:143410 scoped_ptr<DownloadUrlParameters> params(
[email protected]49d812e2012-11-06 21:18:123411 DownloadUrlParameters::FromWebContents(this, url));
[email protected]f859eba2012-05-30 17:22:493412 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143413 params->set_post_id(post_id);
3414 params->set_prefer_cache(true);
3415 if (post_id >= 0)
3416 params->set_method("POST");
[email protected]49d812e2012-11-06 21:18:123417 params->set_prompt(true);
[email protected]c5a5c0842012-05-04 20:05:143418 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143419}
3420
[email protected]b172aee2012-04-10 17:05:263421void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213422 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443423 // Can be NULL during tests.
3424 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213425 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363426}
[email protected]9f76c1e2012-03-05 15:15:583427
[email protected]b172aee2012-04-10 17:05:263428RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583429 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3430}
[email protected]7900bfdb2012-05-24 19:31:243431
[email protected]8ff00d72012-10-23 19:12:213432BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393433 return browser_plugin_guest_.get();
3434}
3435
[email protected]8ff00d72012-10-23 19:12:213436BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393437 return browser_plugin_embedder_.get();
3438}
[email protected]8ff00d72012-10-23 19:12:213439
3440} // namespace content