blob: 8b1f8e985466a3194a7968a1ae47141fa6bdb2d3 [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]eb2ef212013-01-29 04:27:5840#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0341#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5642#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3943#include "content/common/browser_plugin_messages.h"
[email protected]795c28972012-12-06 06:13:3944#include "content/common/icon_messages.h"
[email protected]ce9751942011-09-21 01:57:2445#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5146#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0247#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5748#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5849#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1150#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2051#include "content/public/browser/color_chooser.h"
[email protected]2a5e9d02013-01-20 01:09:2552#include "content/public/browser/compositor_util.h"
[email protected]87f3c082011-10-19 18:07:4453#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3654#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1755#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1456#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4657#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1558#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0059#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2760#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0061#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3762#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1463#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3264#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3465#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3866#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4267#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2568#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1069#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2170#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4871#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1872#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5473#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0374#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1675#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2976#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5477#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3478#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3779#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5680#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1681#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0183#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4184#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5285#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2486#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3687#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3188#include "webkit/glue/webpreferences.h"
89
[email protected]583418cc2013-01-17 14:01:1090#if defined(OS_ANDROID)
91#include "content/browser/android/date_time_chooser_android.h"
92#endif
93
[email protected]f66df822012-05-18 16:52:1794#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5095#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4196#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5797#endif
[email protected]3e45ba92009-02-20 21:09:0098
[email protected]c71fe6402012-08-15 15:22:5599#if defined(USE_AURA) && defined(USE_X11)
[email protected]54944cde2012-12-09 09:24:59100#include "ui/aura/window.h"
[email protected]c71fe6402012-08-15 15:22:55101#include "ui/base/touch/touch_factory.h"
102#endif // defined (USE_AURA) && defined(USE_X11)
103
[email protected]4cc1ab52013-01-21 19:24:34104#if defined(ENABLE_JAVA_BRIDGE)
105#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
106#endif
107
[email protected]420ae012009-04-24 05:16:32108// Cross-Site Navigations
109//
[email protected]b172aee2012-04-10 17:05:26110// If a WebContentsImpl is told to navigate to a different web site (as
111// determined by SiteInstance), it will replace its current RenderViewHost with
112// a new RenderViewHost dedicated to the new SiteInstance. This works as
113// follows:
[email protected]420ae012009-04-24 05:16:32114//
115// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46116// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32117// - The pending RVH is "suspended," so that no navigation messages are sent to
118// its renderer until the onbeforeunload JavaScript handler has a chance to
119// run in the current RVH.
120// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
121// that it has a pending cross-site request. ResourceDispatcherHost will
122// check for this when the response arrives.
123// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46124// cancel all the pending logic. Otherwise we allow the pending RVH to send
125// the navigation request to its renderer.
126// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
127// main resource load on the pending RVH. It checks CrossSiteRequestManager
128// to see that it is a cross-site request, and installs a
129// CrossSiteResourceHandler.
130// - When RDH receives a response, the BufferedResourceHandler determines
131// whether it is a download. If so, it sends a message to the new renderer
132// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26133// pending RVH remains until the next DidNavigate event for this
134// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32135// - After RDH receives a response and determines that it is safe and not a
136// download, it pauses the response to first run the old page's onunload
137// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26138// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32139// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15140// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32141// the ResourceDispatcherHost, who unpauses the response. Data is then sent
142// to the pending RVH.
143// - The pending renderer sends a FrameNavigate message that invokes the
144// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46145// pending RVH.
[email protected]992db4c2011-05-12 15:37:15146// - The previous renderer is kept swapped out in RenderViewHostManager in case
147// the user goes back. The process only stays live if another tab is using
148// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32149
[email protected]6717bf272012-05-11 23:31:25150using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44151
[email protected]8ff00d72012-10-23 19:12:21152namespace content {
[email protected]420ae012009-04-24 05:16:32153namespace {
154
155// Amount of time we wait between when a key event is received and the renderer
156// is queried for its state and pushed to the NavigationEntry.
157const int kQueryStateDelay = 5000;
158
[email protected]6ebdc9b2010-09-27 16:55:57159const int kSyncWaitDelay = 40;
160
[email protected]82114f52012-03-20 22:53:41161const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05162
[email protected]795c28972012-12-06 06:13:39163static int StartDownload(content::RenderViewHost* rvh,
164 const GURL& url,
165 int image_size) {
166 static int g_next_favicon_download_id = 0;
167 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
168 ++g_next_favicon_download_id,
169 url,
170 image_size));
171 return g_next_favicon_download_id;
172}
173
[email protected]2c5569662011-03-22 20:45:02174ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21175 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50176 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16177 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47180 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02181 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23182 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
183 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47184 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16185 break; // Fall through to rest of function.
186 }
[email protected]5e369672009-11-03 23:48:30187
[email protected]59246c572012-02-10 13:32:13188 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
189 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36190 if (entry.restore_type() ==
191 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13192 if (entry.GetHasPostData())
193 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13195 }
[email protected]5e369672009-11-03 23:48:30196
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30198}
199
[email protected]10f417c52011-12-28 21:04:23200void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47201 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21202 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50203 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16204 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51205 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54206 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55207 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
208 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36209 if (!entry.GetBaseURLForDataURL().is_empty()) {
210 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
211 params->history_url_for_data_url = entry.GetVirtualURL();
212 }
[email protected]36fc0392011-12-25 03:59:51213 params->referrer = entry.GetReferrer();
214 params->transition = entry.GetTransitionType();
215 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00216 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55217 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34218 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47219 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48220 params->transferred_request_child_id =
221 entry.transferred_global_request_id().child_id;
222 params->transferred_request_request_id =
223 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22224 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00225 // Avoid downloading when in view-source mode.
226 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44227 params->is_post = entry.GetHasPostData();
228 if(entry.GetBrowserInitiatedPostData()) {
229 params->browser_initiated_post_data.assign(
230 entry.GetBrowserInitiatedPostData()->front(),
231 entry.GetBrowserInitiatedPostData()->front() +
232 entry.GetBrowserInitiatedPostData()->size());
233
234 }
[email protected]6c6b02d2011-09-02 03:36:47235
[email protected]7c16976c2012-08-04 02:38:23236 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
237 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
238 // We may have been redirected when navigating to the current URL.
239 // Use the URL the user originally intended to visit, if it's valid and if a
240 // POST wasn't involved; the latter case avoids issues with sending data to
241 // the wrong page.
242 params->url = entry.GetOriginalRequestURL();
243 } else {
244 params->url = entry.GetURL();
245 }
246
[email protected]951a64832012-10-11 16:26:37247 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58248 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37249
[email protected]6c6b02d2011-09-02 03:36:47250 if (delegate)
251 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34252}
253
[email protected]f98f5092012-05-19 00:08:14254int GetSwitchValueAsInt(
255 const CommandLine& command_line,
256 const std::string& switch_string,
257 int min_value) {
258 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
259 int int_value;
260 if (base::StringToInt(string_value, &int_value))
261 return std::max(min_value, int_value);
262 else
263 return min_value;
264}
265
[email protected]420ae012009-04-24 05:16:32266} // namespace
267
[email protected]54944cde2012-12-09 09:24:59268WebContents* WebContents::Create(const WebContents::CreateParams& params) {
269 return WebContentsImpl::CreateWithOpener(params, NULL);
[email protected]d1198fd2012-08-13 22:50:19270}
271
272WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59273 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19274 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59275 WebContentsImpl* new_contents = new WebContentsImpl(
276 params.browser_context, NULL);
[email protected]d1198fd2012-08-13 22:50:19277
278 for (SessionStorageNamespaceMap::const_iterator it =
279 session_storage_namespace_map.begin();
280 it != session_storage_namespace_map.end();
281 ++it) {
282 new_contents->GetController().SetSessionStorageNamespace(it->first,
283 it->second);
284 }
285
[email protected]54944cde2012-12-09 09:24:59286 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19287 return new_contents;
[email protected]a81343d232011-12-27 07:39:20288}
[email protected]746d3052012-05-22 15:15:47289
[email protected]299d7f12012-05-23 05:31:15290WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47291 return rvh->GetDelegate()->GetAsWebContents();
292}
293
[email protected]b172aee2012-04-10 17:05:26294// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32295
[email protected]b172aee2012-04-10 17:05:26296WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21297 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19298 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42299 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19300 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57301 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44302 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05303 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34304 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23305 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
306 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34307 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21308 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56309 upload_size_(0),
310 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47311 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57312 capturing_contents_(false),
313 is_being_destroyed_(false),
314 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55315 dialog_creator_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01316 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56317 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38318 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21319 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
320 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00321 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43322 content_restrictions_(0),
[email protected]44470a22013-01-24 01:21:54323 color_chooser_(NULL),
324 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]332af7732009-03-11 13:21:35325}
initial.commit09911bf2008-07-26 23:55:29326
[email protected]b172aee2012-04-10 17:05:26327WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32328 is_being_destroyed_ = true;
329
[email protected]b24b68a2012-09-24 21:57:26330 for (std::set<RenderWidgetHostImpl*>::iterator iter =
331 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
332 (*iter)->DetachDelegate();
333 }
334 created_widgets_.clear();
335
[email protected]3ab9cb82011-06-03 18:02:07336 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55337 if (dialog_creator_)
338 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07339
[email protected]da8543762012-03-20 08:52:20340 if (color_chooser_)
341 color_chooser_->End();
342
[email protected]420ae012009-04-24 05:16:32343 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32344
[email protected]ca13a442012-04-17 14:00:12345 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21346 NotificationService::current()->Notify(
347 NOTIFICATION_WEB_CONTENTS_DESTROYED,
348 Source<WebContents>(this),
349 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32350
351 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07352#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32353 // If we still have a window handle, destroy it. GetNativeView can return
354 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42355 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52356 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58357 if (host && host->GetView())
358 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42359 }
[email protected]420ae012009-04-24 05:16:32360#endif
[email protected]7ab1e7d62009-10-14 23:32:01361
362 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15363 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55364 base::TimeTicks now = base::TimeTicks::Now();
365 base::TimeTicks unload_start_time = close_start_time_;
366 if (!before_unload_end_time_.is_null())
367 unload_start_time = before_unload_end_time_;
368 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
369 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01370 }
[email protected]b5a1d11c2011-02-17 03:09:42371
[email protected]2db9bd72012-04-13 20:20:56372 FOR_EACH_OBSERVER(WebContentsObserver,
373 observers_,
374 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08375
[email protected]6934a702011-12-20 00:04:51376 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42377}
378
[email protected]d1198fd2012-08-13 22:50:19379WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59380 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19381 WebContentsImpl* opener) {
[email protected]54944cde2012-12-09 09:24:59382 WebContentsImpl* new_contents = new WebContentsImpl(
383 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19384
[email protected]54944cde2012-12-09 09:24:59385 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19386 return new_contents;
387}
388
[email protected]dd8c8232012-11-03 00:49:36389WebContentsImpl* WebContentsImpl::CreateGuest(
390 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53391 SiteInstance* site_instance,
[email protected]3de10bb32013-01-08 21:57:33392 int routing_id,
393 WebContentsImpl* opener_web_contents,
[email protected]dd8c8232012-11-03 00:49:36394 int guest_instance_id,
395 const BrowserPluginHostMsg_CreateGuest_Params& params) {
[email protected]b5a40842012-11-28 15:26:11396
[email protected]3de10bb32013-01-08 21:57:33397 WebContentsImpl* new_contents = new WebContentsImpl(browser_context,
398 opener_web_contents);
[email protected]7a846df2012-09-20 19:17:39399
400 // This makes |new_contents| act as a guest.
401 // For more info, see comment above class BrowserPluginGuest.
[email protected]b5a40842012-11-28 15:26:11402 new_contents->browser_plugin_guest_.reset(
403 BrowserPluginGuest::Create(
404 guest_instance_id,
405 new_contents,
406 params));
407
[email protected]3de10bb32013-01-08 21:57:33408 WebContents::CreateParams create_params(browser_context, site_instance);
409 create_params.routing_id = routing_id;
410 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11411
[email protected]216be772013-01-25 00:22:27412 // We are instantiating a WebContents for browser plugin. Set its subframe bit
413 // to true.
414 static_cast<RenderViewHostImpl*>(
415 new_contents->GetRenderViewHost())->set_is_subframe(true);
416
[email protected]7a846df2012-09-20 19:17:39417 return new_contents;
418}
419
[email protected]b172aee2012-04-10 17:05:26420WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
421 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54422 WebPreferences prefs;
423
424 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
425
426 prefs.developer_extras_enabled = true;
427 prefs.javascript_enabled =
428 !command_line.HasSwitch(switches::kDisableJavaScript);
429 prefs.web_security_enabled =
430 !command_line.HasSwitch(switches::kDisableWebSecurity);
431 prefs.plugins_enabled =
432 !command_line.HasSwitch(switches::kDisablePlugins);
433 prefs.java_enabled =
434 !command_line.HasSwitch(switches::kDisableJava);
435
436 prefs.uses_page_cache =
437 command_line.HasSwitch(switches::kEnableFastback);
438 prefs.remote_fonts_enabled =
439 !command_line.HasSwitch(switches::kDisableRemoteFonts);
440 prefs.xss_auditor_enabled =
441 !command_line.HasSwitch(switches::kDisableXSSAuditor);
442 prefs.application_cache_enabled =
443 !command_line.HasSwitch(switches::kDisableApplicationCache);
444
445 prefs.local_storage_enabled =
446 !command_line.HasSwitch(switches::kDisableLocalStorage);
447 prefs.databases_enabled =
448 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01449#if defined(OS_ANDROID)
450 prefs.webaudio_enabled =
451 command_line.HasSwitch(switches::kEnableWebAudio);
452#else
[email protected]64d69de42012-02-06 00:19:54453 prefs.webaudio_enabled =
454 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01455#endif
[email protected]64d69de42012-02-06 00:19:54456
457 prefs.experimental_webgl_enabled =
458 GpuProcessHost::gpu_enabled() &&
459 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07460#if defined(OS_ANDROID)
461 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
462#else
[email protected]64d69de42012-02-06 00:19:54463 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07464#endif
[email protected]64d69de42012-02-06 00:19:54465
[email protected]5a073092012-06-08 00:42:51466 prefs.flash_3d_enabled =
467 GpuProcessHost::gpu_enabled() &&
468 !command_line.HasSwitch(switches::kDisableFlash3d);
469 prefs.flash_stage3d_enabled =
470 GpuProcessHost::gpu_enabled() &&
471 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19472
[email protected]64d69de42012-02-06 00:19:54473 prefs.gl_multisampling_enabled =
474 !command_line.HasSwitch(switches::kDisableGLMultisampling);
475 prefs.privileged_webgl_extensions_enabled =
476 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
477 prefs.site_specific_quirks_enabled =
478 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
479 prefs.allow_file_access_from_file_urls =
480 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
481 prefs.show_composited_layer_borders =
482 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
483 prefs.show_composited_layer_tree =
484 command_line.HasSwitch(switches::kShowCompositedLayerTree);
485 prefs.show_fps_counter =
486 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08487 prefs.accelerated_compositing_for_overflow_scroll_enabled =
[email protected]1315fdf2012-12-12 19:45:16488 command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll);
489 prefs.accelerated_compositing_for_scrollable_frames_enabled =
490 command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames);
[email protected]ab3dd632013-01-09 23:19:08491 prefs.composited_scrolling_for_frames_enabled =
492 command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames);
[email protected]8611a852012-05-23 22:11:19493 prefs.show_paint_rects =
494 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52495 prefs.render_vsync_enabled =
496 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54497 prefs.accelerated_compositing_enabled =
498 GpuProcessHost::gpu_enabled() &&
499 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54500 prefs.force_compositing_mode =
[email protected]2a5e9d02013-01-20 01:09:25501 content::IsForceCompositingModeEnabled() &&
[email protected]9b19cf82012-06-13 06:23:23502 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54503 prefs.fixed_position_compositing_enabled =
504 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
505 prefs.accelerated_2d_canvas_enabled =
506 GpuProcessHost::gpu_enabled() &&
507 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58508 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27509 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]a7f899e2013-01-09 12:15:44510 prefs.antialiased_2d_canvas_disabled =
511 command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing);
[email protected]64d69de42012-02-06 00:19:54512 prefs.accelerated_painting_enabled =
513 GpuProcessHost::gpu_enabled() &&
514 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
515 prefs.accelerated_filters_enabled =
516 GpuProcessHost::gpu_enabled() &&
517 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
[email protected]9bdcfd642012-11-14 21:24:26518 prefs.accelerated_compositing_for_3d_transforms_enabled =
519 prefs.accelerated_compositing_for_animation_enabled =
[email protected]64d69de42012-02-06 00:19:54520 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]9bdcfd642012-11-14 21:24:26521 prefs.accelerated_compositing_for_plugins_enabled =
[email protected]64d69de42012-02-06 00:19:54522 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
[email protected]9bdcfd642012-11-14 21:24:26523 prefs.accelerated_compositing_for_video_enabled =
[email protected]64d69de42012-02-06 00:19:54524 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54525 prefs.fullscreen_enabled =
526 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43527 prefs.css_sticky_position_enabled =
528 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29529 prefs.css_shaders_enabled =
530 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01531 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03532 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]8eb51382012-11-20 00:42:33533 prefs.css_grid_layout_enabled =
534 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]d7932532012-11-21 21:10:31535
536 bool touch_device_present = false;
[email protected]c71fe6402012-08-15 15:22:55537#if defined(USE_AURA) && defined(USE_X11)
[email protected]d7932532012-11-21 21:10:31538 touch_device_present =
[email protected]c71fe6402012-08-15 15:22:55539 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
540#endif
[email protected]25ee94f2012-09-11 19:16:16541#if defined(OS_WIN)
[email protected]d7932532012-11-21 21:10:31542 touch_device_present = ui::IsTouchDevicePresent();
[email protected]25ee94f2012-09-11 19:16:16543#endif
[email protected]d849b122012-07-18 07:35:26544#if defined(OS_ANDROID)
[email protected]d7932532012-11-21 21:10:31545 touch_device_present = true;
546#endif
547 const std::string touch_enabled_switch =
548 command_line.HasSwitch(switches::kTouchEvents) ?
549 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
550 switches::kTouchEventsAuto;
551
552 if (touch_enabled_switch.empty() ||
553 touch_enabled_switch == switches::kTouchEventsEnabled) {
554 prefs.touch_enabled = true;
555 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
556 prefs.touch_enabled = touch_device_present;
557 } else if (touch_enabled_switch != switches::kTouchEventsDisabled) {
558 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
559 }
560
561 prefs.device_supports_touch = prefs.touch_enabled && touch_device_present;
562#if defined(OS_ANDROID)
[email protected]d849b122012-07-18 07:35:26563 prefs.device_supports_mouse = false;
564#endif
[email protected]64d69de42012-02-06 00:19:54565
[email protected]b9c96ff2012-11-26 22:24:40566 prefs.touch_adjustment_enabled =
567 !command_line.HasSwitch(switches::kDisableTouchAdjustment);
568
[email protected]2a5e9d02013-01-20 01:09:25569#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
[email protected]64d69de42012-02-06 00:19:54570 bool default_enable_scroll_animator = true;
571#else
[email protected]64d69de42012-02-06 00:19:54572 bool default_enable_scroll_animator = false;
573#endif
574 prefs.enable_scroll_animator = default_enable_scroll_animator;
575 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
576 prefs.enable_scroll_animator = true;
577 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
578 prefs.enable_scroll_animator = false;
579
580 prefs.visual_word_movement_enabled =
581 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54582
583 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32584 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54585 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39586 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21587 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54588 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21589 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54590 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21591 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19592 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21593 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19594 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21595 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54596 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21597 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54598 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21599 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]9bdcfd642012-11-14 21:24:26600 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
601 prefs.accelerated_compositing_for_animation_enabled = false;
[email protected]c521d7462012-10-03 22:28:20602 }
[email protected]8ff00d72012-10-23 19:12:21603 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]9bdcfd642012-11-14 21:24:26604 prefs.accelerated_compositing_for_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54605
606 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45607 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32608 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]9bdcfd642012-11-14 21:24:26609 prefs.accelerated_compositing_for_video_enabled = false;
610 prefs.accelerated_compositing_for_animation_enabled = false;
611 prefs.accelerated_compositing_for_3d_transforms_enabled = false;
612 prefs.accelerated_compositing_for_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54613 }
614 }
615
[email protected]b9535422012-02-09 01:47:59616 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58617 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54618 prefs.loads_images_automatically = true;
619 prefs.javascript_enabled = true;
620 }
621
622 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
623
[email protected]2ee33532013-01-17 12:27:03624 // Force accelerated compositing and 2d canvas off for chrome: and about:
625 // pages (unless it's specifically allowed).
626 if ((url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]64d69de42012-02-06 00:19:54627 (url.SchemeIs(chrome::kAboutScheme) &&
628 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25629 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54630 prefs.accelerated_compositing_enabled = false;
631 prefs.accelerated_2d_canvas_enabled = false;
632 }
[email protected]43d9d782012-03-01 15:40:09633
[email protected]2ee33532013-01-17 12:27:03634 if (url.SchemeIs(chrome::kChromeDevToolsScheme))
635 prefs.show_fps_counter = false;
636
[email protected]f98f5092012-05-19 00:08:14637 if (command_line.HasSwitch(switches::kDefaultTileWidth))
638 prefs.default_tile_width =
639 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
640 if (command_line.HasSwitch(switches::kDefaultTileHeight))
641 prefs.default_tile_height =
642 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
643 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
644 prefs.max_untiled_layer_width =
645 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
646 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
647 prefs.max_untiled_layer_height =
648 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
649
[email protected]ffabb1e2012-10-12 19:51:17650 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
651 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19652 // Only apply when using DIP coordinate system as this setting interferes
653 // with fixed layout mode.
[email protected]9bdcfd642012-11-14 21:24:26654 // TODO(danakj): Fixed layout mode is going away, so turn this on always.
[email protected]2486dce2012-05-23 17:18:19655 prefs.apply_default_device_scale_factor_in_compositor = true;
656 }
657
[email protected]9bdcfd642012-11-14 21:24:26658 prefs.apply_page_scale_factor_in_compositor =
[email protected]16ad47f82012-12-05 21:06:06659 command_line.HasSwitch(switches::kEnablePinch);
[email protected]f49dece2013-01-12 19:04:28660
661 if (command_line.HasSwitch(switches::kEnableCssTransformPinch)) {
662 prefs.apply_default_device_scale_factor_in_compositor = false;
663 prefs.apply_page_scale_factor_in_compositor = false;
664 }
665
[email protected]9bdcfd642012-11-14 21:24:26666 prefs.per_tile_painting_enabled =
667 command_line.HasSwitch(cc::switches::kEnablePerTilePainting);
[email protected]cf6cb622012-11-16 02:00:19668 prefs.accelerated_animation_enabled =
[email protected]9bdcfd642012-11-14 21:24:26669 !command_line.HasSwitch(cc::switches::kDisableThreadedAnimation);
670
[email protected]de023762012-07-26 17:10:17671 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
672 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10673
[email protected]e755a382012-09-13 17:16:35674 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
675 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12676
[email protected]6b4dcb072012-06-18 22:26:51677 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
678
[email protected]5c90d03d2013-01-10 17:16:02679 prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport);
680
[email protected]76f7d4882012-10-26 21:09:22681 prefs.deferred_image_decoding_enabled =
[email protected]b3dc5182013-01-24 15:16:25682 command_line.HasSwitch(switches::kEnableDeferredImageDecoding) ||
683 command_line.HasSwitch(cc::switches::kEnableImplSidePainting);
[email protected]76f7d4882012-10-26 21:09:22684
[email protected]8ff00d72012-10-23 19:12:21685 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54686
[email protected]97456602012-10-03 18:44:25687 // Disable compositing in guests until we have compositing path implemented
688 // for guests.
[email protected]747c30652012-12-18 20:35:53689 bool guest_compositing_enabled = command_line.HasSwitch(
690 switches::kEnableBrowserPluginCompositing);
691 if (rvh->GetProcess()->IsGuest() && !guest_compositing_enabled) {
[email protected]97456602012-10-03 18:44:25692 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06693 prefs.accelerated_compositing_enabled = false;
694 }
[email protected]97456602012-10-03 18:44:25695
[email protected]64d69de42012-02-06 00:19:54696 return prefs;
697}
698
[email protected]b172aee2012-04-10 17:05:26699RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28700 return &render_manager_;
701}
702
[email protected]7bb761892012-07-20 09:32:47703bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
704 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56705 if (GetWebUI() &&
706 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17707 return true;
[email protected]d2353452012-01-19 19:53:56708 }
[email protected]f82d57b52011-04-27 19:13:17709
[email protected]d8c660432011-12-22 20:51:25710 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
711 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10712 while ((observer = it.GetNext()) != NULL)
713 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53714 return true;
[email protected]403415a2011-01-10 18:57:53715
[email protected]7bb761892012-07-20 09:32:47716 // Message handlers should be aware of which RenderViewHost sent the
717 // message, which is temporarily stored in message_source_.
718 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18719 bool handled = true;
720 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26721 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58722 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
723 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24724 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
725 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18726 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
727 OnDidLoadResourceFromMemoryCache)
728 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
729 OnDidDisplayInsecureContent)
730 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
731 OnDidRunInsecureContent)
732 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
733 OnDocumentLoadedInFrame)
734 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26735 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
736 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17737 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
738 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25739 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26740 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59741 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21742 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20743 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
744 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
745 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16746 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45747 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10748 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20749 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
750 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
751 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
752 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29753 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50754 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50755 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
756 OnRequestPpapiBrokerPermission)
[email protected]b479912c2013-01-23 00:07:08757 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID,
758 OnBrowserPluginAllocateInstanceID)
[email protected]795c28972012-12-06 06:13:39759 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
760 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10761#if defined(OS_ANDROID)
762 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
763 OnFindMatchRectsReply)
764 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
765 OnOpenDateTimeDialog)
766#endif
[email protected]8607c832013-01-18 14:11:57767 IPC_MESSAGE_HANDLER(ViewHostMsg_FrameDetached, OnFrameDetached)
[email protected]724159a2010-12-30 01:11:18768 IPC_MESSAGE_UNHANDLED(handled = false)
769 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47770 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18771
772 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21773 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18774 GetRenderProcessHost()->ReceivedBadMessage();
775 }
776
777 return handled;
778}
779
[email protected]b172aee2012-04-10 17:05:26780void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18781 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21782 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43783 if (delegate_)
784 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18785}
786
[email protected]d1198fd2012-08-13 22:50:19787NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56788 return controller_;
789}
790
[email protected]d1198fd2012-08-13 22:50:19791const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56792 return controller_;
793}
794
[email protected]8ff00d72012-10-23 19:12:21795BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55796 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30797}
798
[email protected]b172aee2012-04-10 17:05:26799const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31800 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23801 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51802 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31803}
804
[email protected]8ff00d72012-10-23 19:12:21805WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31806 return delegate_;
807}
808
[email protected]8ff00d72012-10-23 19:12:21809void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31810 // TODO(cbentzel): remove this debugging code?
811 if (delegate == delegate_)
812 return;
813 if (delegate_)
814 delegate_->Detach(this);
815 delegate_ = delegate;
816 if (delegate_)
817 delegate_->Attach(this);
818}
819
[email protected]8ff00d72012-10-23 19:12:21820RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41821 RenderViewHostImpl* host = render_manager_.current_host();
822 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16823}
824
[email protected]b172aee2012-04-10 17:05:26825RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31826 return render_manager_.current_host();
827}
828
[email protected]a04c9d02012-11-14 21:04:34829void WebContentsImpl::GetRenderViewHostAtPosition(
830 int x,
831 int y,
832 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
833 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
834 if (embedder)
835 embedder->GetRenderViewHostAtPosition(x, y, callback);
836 else
837 callback.Run(GetRenderViewHost(), x, y);
838}
839
[email protected]6b618e62012-08-16 12:59:18840int WebContentsImpl::GetRoutingID() const {
841 if (!GetRenderViewHost())
842 return MSG_ROUTING_NONE;
843
844 return GetRenderViewHost()->GetRoutingID();
845}
846
[email protected]44470a22013-01-24 01:21:54847int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
848 return fullscreen_widget_routing_id_;
849}
850
[email protected]b172aee2012-04-10 17:05:26851RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31852 return render_manager_.GetRenderWidgetHostView();
853}
854
[email protected]8ff00d72012-10-23 19:12:21855WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return view_.get();
857}
858
[email protected]8ff00d72012-10-23 19:12:21859WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56860 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03861 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
862 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22863 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58864 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22865 web_ui->SetController(controller);
866 return web_ui;
867 }
868
869 delete web_ui;
870 return NULL;
871}
872
[email protected]8ff00d72012-10-23 19:12:21873WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31874 return render_manager_.web_ui() ? render_manager_.web_ui()
875 : render_manager_.pending_web_ui();
876}
877
[email protected]8ff00d72012-10-23 19:12:21878WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34880}
881
[email protected]86ef6a392012-05-11 22:03:11882void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22883 if (GetUserAgentOverride() == override)
884 return;
885
886 renderer_preferences_.user_agent_override = override;
887
888 // Send the new override string to the renderer.
889 RenderViewHost* host = GetRenderViewHost();
890 if (host)
891 host->SyncRendererPrefs();
892
893 // Reload the page if a load is currently in progress to avoid having
894 // different parts of the page loaded using different user agents.
895 NavigationEntry* entry = controller_.GetActiveEntry();
896 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
897 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53898
899 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
900 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11901}
902
903const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22904 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11905}
906
[email protected]b172aee2012-04-10 17:05:26907const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55908 // Transient entries take precedence. They are used for interstitial pages
909 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23910 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08911 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21912 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30913 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23914 if (entry) {
[email protected]b5cca982011-05-26 04:42:08915 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23916 }
[email protected]7ade2732011-02-10 00:13:58917 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
918 render_manager_.pending_web_ui() : render_manager_.web_ui();
919 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54920 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55921 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54922 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35923 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22924 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54925 if (!title.empty())
926 return title;
927 }
928 }
929
930 // We use the title for the last committed entry rather than a pending
931 // navigation entry. For example, when the user types in a URL, we want to
932 // keep the old page's title until the new load has committed and we get a new
933 // title.
[email protected]96d185d2009-04-24 03:28:54934 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23935 if (entry) {
[email protected]b5cca982011-05-26 04:42:08936 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23937 }
[email protected]987fc3a2011-05-26 14:18:09938
939 // |page_title_when_no_navigation_entry_| is finally used
940 // if no title cannot be retrieved.
941 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54942}
943
[email protected]b172aee2012-04-10 17:05:26944int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46945 return GetMaxPageIDForSiteInstance(GetSiteInstance());
946}
947
[email protected]b172aee2012-04-10 17:05:26948int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
949 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33950 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
951 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46952
[email protected]b6583592012-01-25 19:52:33953 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34954}
955
[email protected]b172aee2012-04-10 17:05:26956void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46957 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
958}
959
[email protected]b172aee2012-04-10 17:05:26960void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33961 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46962 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33963 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34964}
965
[email protected]b172aee2012-04-10 17:05:26966void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
967 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57968}
969
[email protected]b172aee2012-04-10 17:05:26970SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58971 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54972}
973
[email protected]b172aee2012-04-10 17:05:26974SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38975 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
976 render_manager_.pending_render_view_host() :
977 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58978 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38979}
980
[email protected]b172aee2012-04-10 17:05:26981bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31982 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49983}
984
[email protected]b172aee2012-04-10 17:05:26985bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31986 return waiting_for_response_;
987}
988
[email protected]b172aee2012-04-10 17:05:26989const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31990 return load_state_;
991}
992
[email protected]b172aee2012-04-10 17:05:26993const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31994 return load_state_host_;
995}
996
[email protected]b172aee2012-04-10 17:05:26997uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31998 return upload_size_;
999}
1000
[email protected]b172aee2012-04-10 17:05:261001uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311002 return upload_position_;
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:311006 return encoding_;
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311010 return displayed_insecure_content_;
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:311014 capturing_contents_ = cap;
1015}
1016
[email protected]b172aee2012-04-10 17:05:261017bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311018 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1019 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1020 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491021}
1022
[email protected]b172aee2012-04-10 17:05:261023void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1024 int error_code) {
[email protected]443b80e2010-12-14 00:42:231025 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341026 return;
1027
[email protected]443b80e2010-12-14 00:42:231028 crashed_status_ = status;
1029 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211030 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341031}
1032
[email protected]b172aee2012-04-10 17:05:261033base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311034 return crashed_status_;
1035}
1036
[email protected]b172aee2012-04-10 17:05:261037bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311038 return is_being_destroyed_;
1039}
1040
[email protected]b172aee2012-04-10 17:05:261041void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:341042 if (delegate_)
1043 delegate_->NavigationStateChanged(this, changed_flags);
1044}
1045
[email protected]3e324142012-06-25 18:26:331046base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
1047 return last_selected_time_;
1048}
1049
[email protected]9e2e4632012-07-27 16:38:411050void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541051 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:041052 RenderWidgetHostViewPort* rwhv =
1053 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161054 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411055 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431056#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161057 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431058#endif
1059 }
[email protected]96d185d2009-04-24 03:28:541060
[email protected]5ac20162010-11-24 23:33:111061 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381062
[email protected]9e2e4632012-07-27 16:38:411063 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591064
1065 // The resize rect might have changed while this was inactive -- send the new
1066 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581067 RenderViewHostImpl* rvh =
1068 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591069 if (rvh) {
1070 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1071 }
[email protected]96d185d2009-04-24 03:28:541072
[email protected]3e324142012-06-25 18:26:331073 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211074 NotificationService::current()->Notify(
1075 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1076 Source<WebContents>(this),
1077 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311078}
1079
[email protected]b172aee2012-04-10 17:05:261080void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311081 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521082 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1083 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261084 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521085 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331086 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521087 // calls us).
[email protected]c30585c2012-02-16 15:02:041088 RenderWidgetHostViewPort* rwhv =
1089 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161090 if (rwhv)
1091 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541092 }
1093
[email protected]375fa1b2012-05-22 22:05:371094 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211095 NotificationService::current()->Notify(
1096 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1097 Source<WebContents>(this),
1098 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371099}
1100
[email protected]b172aee2012-04-10 17:05:261101bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311102 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271103 return WillNotifyDisconnection() &&
1104 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581105 !static_cast<RenderViewHostImpl*>(
1106 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311107}
1108
[email protected]b172aee2012-04-10 17:05:261109void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271110 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251111 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271112}
1113
[email protected]b172aee2012-04-10 17:05:261114WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441115 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451116 // We pass our own opener so that the cloned page can access it if it was
1117 // before.
[email protected]54944cde2012-12-09 09:24:591118 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451119 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591120 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191121 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221122 FOR_EACH_OBSERVER(WebContentsObserver,
1123 observers_,
1124 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271125 return tc;
1126}
1127
[email protected]b172aee2012-04-10 17:05:261128gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271129 return view_->GetContentNativeView();
1130}
1131
[email protected]b172aee2012-04-10 17:05:261132gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271133 return view_->GetNativeView();
1134}
1135
[email protected]b172aee2012-04-10 17:05:261136void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271137 view_->GetContainerBounds(out);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271141 view_->Focus();
1142}
1143
[email protected]14392a52012-05-02 20:28:441144void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211145 const NotificationSource& source,
1146 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441147 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211148 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1149 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441150 break;
[email protected]8ff00d72012-10-23 19:12:211151 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1152 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501153 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1154 i != pending_widget_views_.end(); ++i) {
1155 if (host->GetView() == i->second) {
1156 pending_widget_views_.erase(i);
1157 break;
1158 }
1159 }
1160 break;
1161 }
[email protected]14392a52012-05-02 20:28:441162 default:
1163 NOTREACHED();
1164 }
1165}
1166
[email protected]54944cde2012-12-09 09:24:591167void WebContentsImpl::Init(const WebContents::CreateParams& params) {
1168 render_manager_.Init(
1169 params.browser_context, params.site_instance, params.routing_id);
[email protected]d1198fd2012-08-13 22:50:191170
[email protected]8ff00d72012-10-23 19:12:211171 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191172 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1173 if (view_.get()) {
1174 CHECK(render_view_host_delegate_view_);
1175 } else {
[email protected]b5a40842012-11-28 15:26:111176 if (browser_plugin_guest_.get() &&
1177 CommandLine::ForCurrentProcess()->HasSwitch(
1178 switches::kEnableBrowserPluginCompositing)) {
1179 WebContentsViewGuest* rv = new WebContentsViewGuest(
1180 this,
1181 browser_plugin_guest_.get());
1182 render_view_host_delegate_view_ = rv;
1183 view_.reset(rv);
1184 } else {
1185 WebContentsViewDelegate* delegate =
1186 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1187 view_.reset(CreateWebContentsView(
1188 this, delegate, &render_view_host_delegate_view_));
1189 }
[email protected]d1198fd2012-08-13 22:50:191190 CHECK(render_view_host_delegate_view_);
1191 }
1192 CHECK(view_.get());
1193
[email protected]ed245db2012-12-18 08:00:451194 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591195 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191196
1197 // Listen for whether our opener gets destroyed.
1198 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211199 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1200 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191201 }
1202
1203 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211204 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1205 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191206#if defined(ENABLE_JAVA_BRIDGE)
1207 java_bridge_dispatcher_host_manager_.reset(
1208 new JavaBridgeDispatcherHostManager(this));
1209#endif
[email protected]583418cc2013-01-17 14:01:101210
1211#if defined(OS_ANDROID)
1212 date_time_chooser_.reset(new DateTimeChooserAndroid());
1213#endif
[email protected]d1198fd2012-08-13 22:50:191214}
1215
[email protected]14392a52012-05-02 20:28:441216void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1217 // Clear the opener if it has been closed.
1218 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211219 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1220 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441221 opener_ = NULL;
1222 }
1223}
1224
[email protected]b172aee2012-04-10 17:05:261225void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311226 observers_.AddObserver(observer);
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311230 observers_.RemoveObserver(observer);
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341234 if (delegate_)
1235 delegate_->ActivateContents(this);
1236}
1237
[email protected]b172aee2012-04-10 17:05:261238void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121239 if (delegate_)
1240 delegate_->DeactivateContents(this);
1241}
1242
[email protected]b172aee2012-04-10 17:05:261243void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481244 if (delegate_)
1245 delegate_->LostCapture();
1246}
1247
[email protected]b24b68a2012-09-24 21:57:261248void WebContentsImpl::RenderWidgetDeleted(
1249 RenderWidgetHostImpl* render_widget_host) {
1250 if (is_being_destroyed_) {
1251 // |created_widgets_| might have been destroyed.
1252 return;
1253 }
1254
1255 std::set<RenderWidgetHostImpl*>::iterator iter =
1256 created_widgets_.find(render_widget_host);
1257 if (iter != created_widgets_.end())
1258 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541259
1260 if (render_widget_host &&
1261 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
1262 FOR_EACH_OBSERVER(WebContentsObserver,
1263 observers_,
1264 DidDestroyFullscreenWidget(
1265 fullscreen_widget_routing_id_));
1266 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1267 }
[email protected]b24b68a2012-09-24 21:57:261268}
1269
[email protected]b172aee2012-04-10 17:05:261270bool WebContentsImpl::PreHandleKeyboardEvent(
1271 const NativeWebKeyboardEvent& event,
1272 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481273 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131274 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481275}
1276
[email protected]b172aee2012-04-10 17:05:261277void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481278 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131279 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431283 if (delegate_)
1284 delegate_->HandleMouseDown();
1285}
1286
[email protected]b172aee2012-04-10 17:05:261287void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481288 if (delegate_)
1289 delegate_->HandleMouseUp();
1290}
1291
[email protected]590a634e2012-07-19 16:38:231292void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481293 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231294 delegate_->HandlePointerActivate();
1295}
1296
1297void WebContentsImpl::HandleGestureBegin() {
1298 if (delegate_)
1299 delegate_->HandleGestureBegin();
1300}
1301
1302void WebContentsImpl::HandleGestureEnd() {
1303 if (delegate_)
1304 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471308 if (delegate_)
1309 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1310}
1311
[email protected]b172aee2012-04-10 17:05:261312bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381313 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121314}
1315
[email protected]a9c81f02012-06-01 00:15:441316void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1317 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371318 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441319 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371320 } else {
1321 GotResponseToLockMouseRequest(false);
1322 }
1323}
1324
[email protected]b172aee2012-04-10 17:05:261325void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371326 if (delegate_)
1327 delegate_->LostMouseLock();
1328}
1329
[email protected]bafe6cd2012-05-23 23:09:501330void WebContentsImpl::CreateNewWindow(
1331 int route_id,
[email protected]97714c82012-06-06 10:15:131332 const ViewHostMsg_CreateWindow_Params& params,
1333 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501334 if (delegate_ && !delegate_->ShouldCreateWebContents(
1335 this, route_id, params.window_container_type, params.frame_name,
1336 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091337 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501338 return;
1339 }
1340
1341 // We usually create the new window in the same BrowsingInstance (group of
1342 // script-related windows), by passing in the current SiteInstance. However,
1343 // if the opener is being suppressed, we create a new SiteInstance in its own
1344 // BrowsingInstance.
1345 scoped_refptr<SiteInstance> site_instance =
1346 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571347 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501348 GetSiteInstance();
1349
1350 // Create the new web contents. This will automatically create the new
1351 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191352 WebContentsImpl* new_contents =
1353 new WebContentsImpl(GetBrowserContext(),
1354 params.opener_suppressed ? NULL : this);
1355
1356 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341357 //
1358 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191359 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211360 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571361 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591362 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211363 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341364 BrowserContext::GetStoragePartition(GetBrowserContext(),
1365 site_instance);
[email protected]d1198fd2012-08-13 22:50:191366 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341367 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191368 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1369 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1370 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1371 new_contents->GetController().SetSessionStorageNamespace(
1372 partition_id,
1373 session_storage_namespace);
[email protected]54944cde2012-12-09 09:24:591374 CreateParams create_params(GetBrowserContext(), site_instance);
1375 create_params.routing_id = route_id;
[email protected]ed245db2012-12-18 08:00:451376 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591377 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191378
[email protected]bafe6cd2012-05-23 23:09:501379 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1380
1381 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211382 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501383
1384 // TODO(brettw): It seems bogus that we have to call this function on the
1385 // newly created object and give it one of its own member variables.
1386 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1387
1388 // Save the created window associated with the route so we can show it
1389 // later.
1390 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1391 pending_contents_[route_id] = new_contents;
1392 }
1393
1394 if (delegate_) {
1395 delegate_->WebContentsCreated(
1396 this, params.opener_frame_id, params.target_url, new_contents);
1397 }
1398
1399 if (params.opener_suppressed) {
1400 // When the opener is suppressed, the original renderer cannot access the
1401 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001402 bool was_blocked = false;
1403 if (delegate_) {
1404 gfx::Rect initial_pos;
1405 delegate_->AddNewContents(
1406 this, new_contents, params.disposition, initial_pos,
1407 params.user_gesture, &was_blocked);
1408 }
1409 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211410 OpenURLParams open_params(params.target_url,
1411 Referrer(),
1412 CURRENT_TAB,
1413 PAGE_TRANSITION_LINK,
1414 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001415 new_contents->OpenURL(open_params);
1416 }
[email protected]bafe6cd2012-05-23 23:09:501417 }
1418}
1419
1420void WebContentsImpl::CreateNewWidget(int route_id,
1421 WebKit::WebPopupType popup_type) {
1422 CreateNewWidget(route_id, false, popup_type);
1423}
1424
1425void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1426 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1427}
1428
1429void WebContentsImpl::CreateNewWidget(int route_id,
1430 bool is_fullscreen,
1431 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211432 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501433 RenderWidgetHostImpl* widget_host =
1434 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261435 created_widgets_.insert(widget_host);
1436
[email protected]83918ec2013-01-10 15:37:191437 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1438 view_->CreateViewForPopupWidget(widget_host));
1439 if (!widget_view)
1440 return;
[email protected]bafe6cd2012-05-23 23:09:501441 if (!is_fullscreen) {
1442 // Popups should not get activated.
1443 widget_view->SetPopupType(popup_type);
1444 }
1445 // Save the created widget associated with the route so we can show it later.
1446 pending_widget_views_[route_id] = widget_view;
1447
1448#if defined(OS_MACOSX)
1449 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1450 // to allow it to survive the trip without being hosted.
1451 base::mac::NSObjectRetain(widget_view->GetNativeView());
1452#endif
1453}
1454
1455void WebContentsImpl::ShowCreatedWindow(int route_id,
1456 WindowOpenDisposition disposition,
1457 const gfx::Rect& initial_pos,
1458 bool user_gesture) {
1459 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001460 if (contents) {
1461 WebContentsDelegate* delegate = GetDelegate();
1462 if (delegate) {
1463 delegate->AddNewContents(
1464 this, contents, disposition, initial_pos, user_gesture, NULL);
1465 }
1466 }
[email protected]bafe6cd2012-05-23 23:09:501467}
1468
1469void WebContentsImpl::ShowCreatedWidget(int route_id,
1470 const gfx::Rect& initial_pos) {
1471 ShowCreatedWidget(route_id, false, initial_pos);
1472}
1473
1474void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1475 ShowCreatedWidget(route_id, true, gfx::Rect());
[email protected]44470a22013-01-24 01:21:541476
1477 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1478 fullscreen_widget_routing_id_ = route_id;
1479 FOR_EACH_OBSERVER(WebContentsObserver,
1480 observers_,
1481 DidShowFullscreenWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501482}
1483
1484void WebContentsImpl::ShowCreatedWidget(int route_id,
1485 bool is_fullscreen,
1486 const gfx::Rect& initial_pos) {
1487 if (delegate_)
1488 delegate_->RenderWidgetShowing();
1489
1490 RenderWidgetHostViewPort* widget_host_view =
1491 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1492 if (!widget_host_view)
1493 return;
1494 if (is_fullscreen) {
1495 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1496 } else {
1497 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1498 }
[email protected]89054502012-06-03 10:29:241499
1500 RenderWidgetHostImpl* render_widget_host_impl =
1501 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1502 render_widget_host_impl->Init();
1503 // Only allow privileged mouse lock for fullscreen render widget, which is
1504 // used to implement Pepper Flash fullscreen.
1505 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501506
1507#if defined(OS_MACOSX)
1508 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1509 // properly embedded (or purposefully ignored) we can release the retain we
1510 // took in CreateNewWidget().
1511 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1512#endif
1513}
1514
1515WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1516 PendingContents::iterator iter = pending_contents_.find(route_id);
1517
1518 // Certain systems can block the creation of new windows. If we didn't succeed
1519 // in creating one, just return NULL.
1520 if (iter == pending_contents_.end()) {
1521 return NULL;
1522 }
1523
1524 WebContentsImpl* new_contents = iter->second;
1525 pending_contents_.erase(route_id);
1526
1527 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1528 !new_contents->GetRenderViewHost()->GetView())
1529 return NULL;
1530
1531 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1532 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1533 return new_contents;
1534}
1535
1536RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1537 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1538 if (iter == pending_widget_views_.end()) {
1539 DCHECK(false);
1540 return NULL;
1541 }
1542
1543 RenderWidgetHostView* widget_host_view = iter->second;
1544 pending_widget_views_.erase(route_id);
1545
1546 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1547 if (!widget_host->GetProcess()->HasConnection()) {
1548 // The view has gone away or the renderer crashed. Nothing to do.
1549 return NULL;
1550 }
1551
1552 return widget_host_view;
1553}
1554
1555void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211556 const ContextMenuParams& params,
1557 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501558 // Allow WebContentsDelegates to handle the context menu operation first.
1559 if (delegate_ && delegate_->HandleContextMenu(params))
1560 return;
1561
[email protected]ba16e3a2012-09-07 04:14:521562 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501563}
1564
[email protected]f13b4202012-06-12 23:53:231565void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091566 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211567 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231568 if (delegate_)
1569 delegate_->RequestMediaAccessPermission(this, request, callback);
1570 else
[email protected]8ff00d72012-10-23 19:12:211571 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231572}
1573
[email protected]b172aee2012-04-10 17:05:261574void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231575 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331576 if (delegate_)
1577 delegate_->UpdatePreferredSize(this, pref_size);
1578}
1579
[email protected]b172aee2012-04-10 17:05:261580void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341581 if (delegate_)
1582 delegate_->ResizeDueToAutoResize(this, new_size);
1583}
1584
[email protected]b172aee2012-04-10 17:05:261585WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201586 if (!delegate_)
1587 return NULL;
[email protected]00c37fc2011-08-02 00:22:501588
[email protected]e5d549d2011-12-28 01:29:201589 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201590 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341591}
1592
[email protected]6b618e62012-08-16 12:59:181593bool WebContentsImpl::Send(IPC::Message* message) {
1594 if (!GetRenderViewHost()) {
1595 delete message;
1596 return false;
1597 }
1598
1599 return GetRenderViewHost()->Send(message);
1600}
1601
[email protected]b172aee2012-04-10 17:05:261602bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501603 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251604 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231605 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251606 reload_type);
[email protected]876bc832010-09-07 16:29:541607}
[email protected]96d185d2009-04-24 03:28:541608
[email protected]ba45bfd2012-05-22 21:51:441609void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211610 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441611 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1612 RenderViewForInterstitialPageCreated(render_view_host));
1613}
1614
[email protected]b172aee2012-04-10 17:05:261615bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231616 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501617 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401618 // The renderer will reject IPC messages with URLs longer than
1619 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211620 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401621 return false;
1622
[email protected]9f76c1e2012-03-05 15:15:581623 RenderViewHostImpl* dest_render_view_host =
1624 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401625 if (!dest_render_view_host)
1626 return false; // Unable to create the desired render view host.
1627
[email protected]80a8fad2011-01-29 04:02:381628 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071629 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581630 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271631 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501632 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031633 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1634 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211635 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231636 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271637 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211638 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231639 CHECK(0);
1640 }
[email protected]54ec6472010-04-09 19:39:581641
[email protected]7bb761892012-07-20 09:32:471642 // Notify observers that we will navigate in this RV.
1643 FOR_EACH_OBSERVER(WebContentsObserver,
1644 observers_,
1645 AboutToNavigateRenderView(dest_render_view_host));
1646
[email protected]96d185d2009-04-24 03:28:541647 // Used for page load time metrics.
1648 current_load_start_ = base::TimeTicks::Now();
1649
1650 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341651 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271652 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471653 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341654 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541655
[email protected]36fc0392011-12-25 03:59:511656 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541657 // HACK!! This code suppresses javascript: URLs from being added to
1658 // session history, which is what we want to do for javascript: URLs that
1659 // do not generate content. What we really need is a message from the
1660 // renderer telling us that a new page was not created. The same message
1661 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511662 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541663 return false;
1664 }
1665
[email protected]3c9e1872010-11-18 16:17:491666 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251667 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041668 observers_,
[email protected]36fc0392011-12-25 03:59:511669 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541670
[email protected]09b29342011-06-24 19:18:481671 if (delegate_)
1672 delegate_->DidNavigateToPendingEntry(this);
1673
[email protected]d5f942ba2008-09-26 19:30:341674 return true;
1675}
1676
[email protected]b172aee2012-04-10 17:05:261677void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331678 const SiteInstance* site_instance,
1679 int history_length,
1680 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411681 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1682 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191683 if (render_manager_.pending_render_view_host()) {
1684 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141685 return;
[email protected]9e1ad4b2011-08-14 16:49:191686 }
[email protected]9f76c1e2012-03-05 15:15:581687 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191688 if (!rvh) {
1689 NOTREACHED();
1690 return;
1691 }
[email protected]9f76c1e2012-03-05 15:15:581692 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191693 NOTREACHED();
1694 return;
1695 }
[email protected]6b618e62012-08-16 12:59:181696 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1697 history_length,
1698 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141699}
1700
[email protected]b172aee2012-04-10 17:05:261701void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271702 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541703 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1704 return;
1705 }
[email protected]9f76c1e2012-03-05 15:15:581706 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541707}
1708
[email protected]b172aee2012-04-10 17:05:261709bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271710 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541711}
1712
[email protected]b172aee2012-04-10 17:05:261713InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271714 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221715}
1716
[email protected]b172aee2012-04-10 17:05:261717bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161718 // WebKit creates Document object when MIME type is application/xhtml+xml,
1719 // so we also support this MIME type.
1720 return contents_mime_type_ == "text/html" ||
1721 contents_mime_type_ == "text/xml" ||
1722 contents_mime_type_ == "application/xhtml+xml" ||
1723 contents_mime_type_ == "text/plain" ||
1724 contents_mime_type_ == "text/css" ||
1725 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1726}
1727
[email protected]b172aee2012-04-10 17:05:261728void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591729 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161730 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551731 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211732 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141733 return;
[email protected]c7dd2f62011-07-18 15:57:591734 }
1735
1736 Stop();
1737
1738 // Create the save package and possibly prompt the user for the name to save
1739 // the page as. The user prompt is an asynchronous operation that runs on
1740 // another thread.
1741 save_package_ = new SavePackage(this);
1742 save_package_->GetSaveInfo();
1743}
1744
1745// Used in automated testing to bypass prompting the user for file names.
1746// Instead, the names and paths are hard coded rather than running them through
1747// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261748bool WebContentsImpl::SavePage(const FilePath& main_file,
1749 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211750 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591751 // Stop the page from navigating.
1752 Stop();
1753
1754 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211755 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591756}
1757
[email protected]b172aee2012-04-10 17:05:261758void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121759 const FilePath& file,
1760 const base::Callback<void(const FilePath&, int64)>& callback) {
1761 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1762}
1763
[email protected]b172aee2012-04-10 17:05:261764bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231765 NavigationEntryImpl* active_entry =
1766 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321767 return (active_entry != NULL &&
1768 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511769 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321770}
1771
[email protected]b172aee2012-04-10 17:05:261772const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271773 return contents_mime_type_;
1774}
1775
[email protected]b172aee2012-04-10 17:05:261776bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271777 return notify_disconnection_;
1778}
1779
[email protected]b172aee2012-04-10 17:05:261780void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311781 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181782 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161783}
1784
[email protected]b172aee2012-04-10 17:05:261785void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311786 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181787 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161788}
1789
[email protected]8ff00d72012-10-23 19:12:211790RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271791 return &renderer_preferences_;
1792}
1793
[email protected]b172aee2012-04-10 17:05:261794void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271795 new_tab_start_time_ = time;
1796}
1797
[email protected]b172aee2012-04-10 17:05:261798base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271799 return new_tab_start_time_;
1800}
1801
[email protected]e35ccd52012-05-23 16:22:471802void WebContentsImpl::Close() {
1803 Close(GetRenderViewHost());
1804}
1805
[email protected]b172aee2012-04-10 17:05:261806void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151807 if (close_start_time_.is_null())
1808 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011809}
1810
[email protected]b172aee2012-04-10 17:05:261811bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191812#if defined(OS_CHROMEOS)
1813 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1814 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511815 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201816 return false;
1817 return true;
[email protected]46624bf2010-06-09 16:04:191818#else
1819 return true;
1820#endif
1821}
1822
[email protected]b172aee2012-04-10 17:05:261823void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521824 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581825 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511826 if (delegate_)
1827 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341828}
1829
[email protected]e35ccd52012-05-23 16:22:471830void WebContentsImpl::UserGestureDone() {
1831 OnUserGesture();
1832}
1833
[email protected]b172aee2012-04-10 17:05:261834void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271835 closed_by_user_gesture_ = value;
1836}
1837
[email protected]b172aee2012-04-10 17:05:261838bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271839 return closed_by_user_gesture_;
1840}
1841
[email protected]b172aee2012-04-10 17:05:261842double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051843 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561844 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251845 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171846 return 0;
[email protected]b75b8292010-10-01 07:28:251847
1848 double zoom_level;
1849 if (temporary_zoom_settings_) {
1850 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581851 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251852 } else {
[email protected]2ae88d12011-10-14 09:11:191853 GURL url;
[email protected]10f417c52011-12-28 21:04:231854 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191855 // Since zoom map is updated using rewritten URL, use rewritten URL
1856 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511857 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191858 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251859 }
[email protected]d0b8d092010-10-25 04:05:171860 return zoom_level;
1861}
[email protected]b75b8292010-10-01 07:28:251862
[email protected]b172aee2012-04-10 17:05:261863int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591864 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171865 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011866 // Calculate the zoom percent from the factor. Round up to the nearest whole
1867 // number.
[email protected]b75b8292010-10-01 07:28:251868 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011869 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251870 *enable_decrement = percent > minimum_zoom_percent_;
1871 *enable_increment = percent < maximum_zoom_percent_;
1872 return percent;
1873}
1874
[email protected]b172aee2012-04-10 17:05:261875void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501876 if (!delegate_)
1877 return;
1878
[email protected]10f417c52011-12-28 21:04:231879 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501880 if (!active_entry)
1881 return;
1882
[email protected]36fc0392011-12-25 03:59:511883 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121884}
1885
[email protected]b172aee2012-04-10 17:05:261886void WebContentsImpl::ViewFrameSource(const GURL& url,
1887 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271888 if (!delegate_)
1889 return;
1890
1891 delegate_->ViewSourceForFrame(this, url, content_state);
1892}
1893
[email protected]b172aee2012-04-10 17:05:261894int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271895 return minimum_zoom_percent_;
1896}
1897
[email protected]b172aee2012-04-10 17:05:261898int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271899 return maximum_zoom_percent_;
1900}
1901
[email protected]b172aee2012-04-10 17:05:261902gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231903 return preferred_size_;
1904}
1905
[email protected]b172aee2012-04-10 17:05:261906int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271907 return content_restrictions_;
1908}
1909
[email protected]b172aee2012-04-10 17:05:261910WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]86a0a6e2013-01-28 06:33:031911 return WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
1912 GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271913}
1914
[email protected]8ff00d72012-10-23 19:12:211915WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271916 // When there is a pending navigation entry, we want to use the pending WebUI
1917 // that goes along with it to control the basic flags. For example, we want to
1918 // show the pending URL in the URL bar, so we want the display_url flag to
1919 // be from the pending entry.
1920 //
1921 // The confusion comes because there are multiple possibilities for the
1922 // initial load in a tab as a side effect of the way the RenderViewHostManager
1923 // works.
1924 //
1925 // - For the very first tab the load looks "normal". The new tab Web UI is
1926 // the pending one, and we want it to apply here.
1927 //
1928 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1929 // get switched to the one previously associated with the new tab pages.
1930 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1931 // have a committed Web UI in this case.
1932 //
1933 // This condition handles all of these cases:
1934 //
1935 // - First load in first tab: no committed nav entry + pending nav entry +
1936 // pending dom ui:
1937 // -> Use pending Web UI if any.
1938 //
1939 // - First load in second tab: no committed nav entry + pending nav entry +
1940 // no pending Web UI:
1941 // -> Use the committed Web UI if any.
1942 //
1943 // - Second navigation in any tab: committed nav entry + pending nav entry:
1944 // -> Use pending Web UI if any.
1945 //
1946 // - Normal state with no load: committed nav entry + no pending nav entry:
1947 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251948 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271949 (controller_.GetLastCommittedEntry() ||
1950 render_manager_.pending_web_ui()))
1951 return render_manager_.pending_web_ui();
1952 return render_manager_.web_ui();
1953}
1954
[email protected]b172aee2012-04-10 17:05:261955bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271956 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581957 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271958}
1959
[email protected]b172aee2012-04-10 17:05:261960bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441961 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501962}
1963
[email protected]b172aee2012-04-10 17:05:261964void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321965 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181966 Send(new ViewMsg_DidChooseColorResponse(
1967 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201968}
1969
[email protected]b172aee2012-04-10 17:05:261970void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181971 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201972 if (delegate_)
1973 delegate_->DidEndColorChooser();
1974 color_chooser_ = NULL;
1975}
1976
[email protected]795c28972012-12-06 06:13:391977int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
1978 const FaviconDownloadCallback& callback) {
1979 RenderViewHost* host = GetRenderViewHost();
1980 int id = StartDownload(host, url, image_size);
1981 favicon_download_map_[id] = callback;
1982 return id;
1983}
1984
[email protected]b172aee2012-04-10 17:05:261985bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211986 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271987 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221988 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231989 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411990 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271991}
1992
[email protected]b172aee2012-04-10 17:05:261993void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271994 if (delegate_)
1995 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211996}
1997
[email protected]3a3b75a2012-06-01 08:38:361998void WebContentsImpl::OnRegisterIntentService(
1999 const webkit_glue::WebIntentServiceData& data,
2000 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432001 if (delegate_)
2002 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:302003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::OnWebIntentDispatch(
2006 const webkit_glue::WebIntentData& intent,
2007 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:432008 if (!delegate_)
2009 return;
2010
[email protected]0d9989d2011-12-21 20:26:002011 WebIntentsDispatcherImpl* intents_dispatcher =
2012 new WebIntentsDispatcherImpl(this, intent, intent_id);
2013 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:302014}
2015
[email protected]54047eb52012-05-08 21:45:572016void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:212017 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:572018 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132019 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572020 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:572021 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:212022 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]ead9009e2013-01-07 22:06:322023 bool is_iframe_srcdoc = (url.spec() == chrome::kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182024 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212025 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572026 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082027 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182028
[email protected]d974a0a2013-01-10 01:43:572029 if (is_main_frame)
2030 DidChangeLoadProgress(0);
2031
[email protected]0d60f0192011-04-14 12:40:102032 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252033 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132034 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2035 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322036 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542037
2038 if (is_main_frame) {
2039 // Notify observers about the provisional change in the main frame URL.
2040 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2041 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542042 render_view_host));
2043 }
2044}
2045
2046void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212047 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542048 int32 page_id,
[email protected]400992b2012-06-14 00:03:542049 const GURL& source_url,
2050 const GURL& target_url) {
2051 // TODO(creis): Remove this method and have the pre-rendering code listen to
2052 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2053 // instead. See http://crbug.com/78512.
2054 GURL validated_source_url(source_url);
2055 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212056 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542057 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082058 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2059 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542060 NavigationEntry* entry;
2061 if (page_id == -1) {
2062 entry = controller_.GetPendingEntry();
2063 } else {
2064 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2065 page_id);
2066 }
2067 if (!entry || entry->GetURL() != validated_source_url)
2068 return;
2069
2070 // Notify observers about the provisional change in the main frame URL.
2071 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2072 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542073 render_view_host));
[email protected]724159a2010-12-30 01:11:182074}
2075
[email protected]54047eb52012-05-08 21:45:572076void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212077 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582078 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2079 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2080 << ", error_code: " << params.error_code
2081 << ", error_description: " << params.error_description
2082 << ", is_main_frame: " << params.is_main_frame
2083 << ", showing_repost_interstitial: " <<
2084 params.showing_repost_interstitial
2085 << ", frame_id: " << params.frame_id;
2086 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212087 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572088 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082089 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182090
[email protected]d7b175e2011-10-11 15:31:582091 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182092 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2093 // This means that the interstitial won't be torn down properly, which is
2094 // bad. But if we have an interstitial, go back to another tab type, and
2095 // then load the same interstitial again, we could end up getting the first
2096 // interstitial's "failed" message (as a result of the cancel) when we're on
2097 // the second one.
2098 //
2099 // We can't tell this apart, so we think we're tearing down the current page
2100 // which will cause a crash later one. There is also some code in
2101 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2102 // out because of this problem.
2103 //
2104 // http://code.google.com/p/chromium/issues/detail?id=2855
2105 // Because this will not tear down the interstitial properly, if "back" is
2106 // back to another tab type, the interstitial will still be somewhat alive
2107 // in the previous tab type. If you navigate somewhere that activates the
2108 // tab with the interstitial again, you'll see a flash before the new load
2109 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272110 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182111 LOG(WARNING) << "Discarding message during interstitial.";
2112 return;
2113 }
2114
[email protected]a16690732012-07-13 19:22:172115 // Do not clear the pending entry if one exists, so that the user's typed
2116 // URL is not lost when a navigation fails or is aborted. We'll allow
2117 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182118
[email protected]54047eb52012-05-08 21:45:572119 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182120 }
2121
[email protected]d8c660432011-12-22 20:51:252122 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582123 observers_,
2124 DidFailProvisionalLoad(params.frame_id,
2125 params.is_main_frame,
2126 validated_url,
2127 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462128 params.error_description,
2129 render_view_host));
[email protected]724159a2010-12-30 01:11:182130}
2131
[email protected]b172aee2012-04-10 17:05:262132void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182133 const GURL& url,
[email protected]70435962011-08-02 20:13:282134 const std::string& security_info,
2135 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182136 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282137 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192138 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182139 cache.Increment();
2140
2141 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082142 int cert_id = 0;
2143 net::CertStatus cert_status = 0;
2144 int security_bits = -1;
2145 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212146 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2147 &security_bits, &connection_status);
2148 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002149 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2150 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182151
[email protected]8ff00d72012-10-23 19:12:212152 NotificationService::current()->Notify(
2153 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2154 Source<NavigationController>(&controller_),
2155 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182156}
2157
[email protected]b172aee2012-04-10 17:05:262158void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212159 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182160 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192161 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182162}
2163
[email protected]b172aee2012-04-10 17:05:262164void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022165 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232166 LOG(INFO) << security_origin << " ran insecure content from "
2167 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212168 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412169 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212170 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182171 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412172 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192173 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182174}
2175
[email protected]b172aee2012-04-10 17:05:262176void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182177 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252178 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472179 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182180}
2181
[email protected]b172aee2012-04-10 17:05:262182void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312183 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062184 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312185 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062186 GURL validated_url(url);
2187 RenderProcessHost* render_process_host = message_source_->GetProcess();
2188 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252189 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472190 DidFinishLoad(frame_id, validated_url, is_main_frame,
2191 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312192}
2193
[email protected]b172aee2012-04-10 17:05:262194void WebContentsImpl::OnDidFailLoadWithError(
2195 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062196 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262197 bool is_main_frame,
2198 int error_code,
2199 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062200 GURL validated_url(url);
2201 RenderProcessHost* render_process_host = message_source_->GetProcess();
2202 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252203 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312204 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472205 error_code, error_description,
2206 message_source_));
[email protected]724159a2010-12-30 01:11:182207}
2208
[email protected]b172aee2012-04-10 17:05:262209void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272210 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432211 if (delegate_)
2212 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172213}
2214
[email protected]b172aee2012-04-10 17:05:262215void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262216 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232217 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252218 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262219 if (!entry)
2220 return;
2221 // Note that we don't call NavigationController::GotToOffset() as we don't
2222 // want to create a pending navigation entry (it might end up lingering
2223 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252224 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212225 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512226 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212227 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472228 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572229
2230 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2231 // it in now that we know. This allows us to find the entry when it commits.
2232 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232233 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332234 entry->set_site_instance(
2235 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572236 }
[email protected]216813952011-05-19 22:21:262237 }
2238}
2239
[email protected]b172aee2012-04-10 17:05:262240void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2241 int maximum_percent,
2242 bool remember) {
[email protected]216813952011-05-19 22:21:262243 minimum_zoom_percent_ = minimum_percent;
2244 maximum_zoom_percent_ = maximum_percent;
2245 temporary_zoom_settings_ = !remember;
2246}
2247
[email protected]20b433a2012-05-15 21:23:462248void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212249 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552250 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262251 // Check if the URL to save matches the URL of the main frame. Since this
2252 // message originates from Pepper plugins, it may not be the case if the
2253 // plugin is an embedded element.
2254 GURL main_frame_url = GetURL();
2255 if (!main_frame_url.is_valid())
2256 return;
2257 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462258 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272259}
2260
[email protected]b172aee2012-04-10 17:05:262261void WebContentsImpl::OnEnumerateDirectory(int request_id,
2262 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432263 if (!delegate_)
2264 return;
2265
[email protected]b9535422012-02-09 01:47:592266 ChildProcessSecurityPolicyImpl* policy =
2267 ChildProcessSecurityPolicyImpl::GetInstance();
2268 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2269 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432273 if (delegate_)
2274 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202275}
2276
[email protected]b172aee2012-04-10 17:05:262277void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2278 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362279 const string16& title,
2280 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432281 if (!delegate_)
2282 return;
2283
[email protected]b9535422012-02-09 01:47:592284 ChildProcessSecurityPolicyImpl* policy =
2285 ChildProcessSecurityPolicyImpl::GetInstance();
2286 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2287 return;
[email protected]3a3b75a2012-06-01 08:38:362288 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202289}
2290
[email protected]b172aee2012-04-10 17:05:262291void WebContentsImpl::OnFindReply(int request_id,
2292 int number_of_matches,
2293 const gfx::Rect& selection_rect,
2294 int active_match_ordinal,
2295 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432296 if (delegate_) {
2297 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2298 active_match_ordinal, final_update);
2299 }
[email protected]b888919c2011-09-02 00:32:162300}
2301
[email protected]59363fc92012-09-05 03:46:312302#if defined(OS_ANDROID)
2303void WebContentsImpl::OnFindMatchRectsReply(
2304 int version,
2305 const std::vector<gfx::RectF>& rects,
2306 const gfx::RectF& active_rect) {
2307 if (delegate_)
2308 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2309}
[email protected]583418cc2013-01-17 14:01:102310
2311void WebContentsImpl::OnOpenDateTimeDialog(int type, const std::string& value) {
2312 date_time_chooser_->ShowDialog(
2313 GetContentNativeView(), GetRenderViewHost(), type, value);
2314}
2315
[email protected]59363fc92012-09-05 03:46:312316#endif
2317
[email protected]cf4d6e742013-01-10 14:06:422318void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path,
2319 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422321 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452322}
2323
[email protected]b172aee2012-04-10 17:05:262324void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2325 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102326 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252327 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102328 AppCacheAccessed(manifest_url, blocked_by_policy));
2329}
2330
[email protected]b172aee2012-04-10 17:05:262331void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322332 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432333 color_chooser_ = delegate_ ?
2334 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202335}
2336
[email protected]b172aee2012-04-10 17:05:262337void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202338 if (color_chooser_ &&
2339 color_chooser_id == color_chooser_->identifier())
2340 color_chooser_->End();
2341}
2342
[email protected]b172aee2012-04-10 17:05:262343void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322344 SkColor color) {
[email protected]da8543762012-03-20 08:52:202345 if (color_chooser_ &&
2346 color_chooser_id == color_chooser_->identifier())
2347 color_chooser_->SetSelectedColor(color);
2348}
2349
[email protected]9f2a9d72012-04-16 16:02:222350void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2351 const FilePath& path,
2352 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552353 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2354
[email protected]3fc07c52012-04-20 00:27:442355 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2356 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292357}
2358
[email protected]d0759f492012-04-19 22:50:502359// This exists for render views that don't have a WebUI, but do have WebUI
2360// bindings enabled.
2361void WebContentsImpl::OnWebUISend(const GURL& source_url,
2362 const std::string& name,
2363 const base::ListValue& args) {
2364 if (delegate_)
2365 delegate_->WebUISend(this, source_url, name, args);
2366}
2367
[email protected]d8415ad92012-08-23 14:40:502368void WebContentsImpl::OnRequestPpapiBrokerPermission(
2369 int request_id,
2370 const GURL& url,
2371 const FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162372 if (!delegate_) {
2373 OnPpapiBrokerPermissionResult(request_id, false);
2374 return;
[email protected]d8415ad92012-08-23 14:40:502375 }
2376
[email protected]8c8fc292012-11-23 18:57:162377 if (!delegate_->RequestPpapiBrokerPermission(
2378 this, url, plugin_path,
2379 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2380 base::Unretained(this), request_id))) {
2381 NOTIMPLEMENTED();
2382 OnPpapiBrokerPermissionResult(request_id, false);
2383 }
[email protected]d8415ad92012-08-23 14:40:502384}
2385
2386void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2387 bool result) {
2388 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2389 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2390 request_id,
2391 result));
2392}
2393
[email protected]b479912c2013-01-23 00:07:082394void WebContentsImpl::OnBrowserPluginAllocateInstanceID(
2395 const IPC::Message& message, int request_id) {
[email protected]19be7a62012-10-01 23:03:372396 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082397 // specific messages for this WebContents. This means that any message from
2398 // a BrowserPlugin prior to AllocateInstanceID will be ignored.
[email protected]7a846df2012-09-20 19:17:392399 // For more info, see comment above classes BrowserPluginEmbedder and
2400 // BrowserPluginGuest.
[email protected]b479912c2013-01-23 00:07:082401 // The first BrowserPluginHostMsg_AllocateInstanceID message from this
2402 // WebContents' embedder render process is handled here. Once
2403 // BrowserPluginEmbedder is created, all subsequent BrowserPluginHostMsg_*
2404 // messages are handled in BrowserPluginEmbedder. Thus, this code will not be
2405 // executed if a BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392406 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392407 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212408 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]b479912c2013-01-23 00:07:082409 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372410}
2411
[email protected]795c28972012-12-06 06:13:392412void WebContentsImpl::OnDidDownloadFavicon(
2413 int id,
2414 const GURL& image_url,
[email protected]795c28972012-12-06 06:13:392415 int requested_size,
2416 const std::vector<SkBitmap>& bitmaps) {
2417 FaviconDownloadMap::iterator iter = favicon_download_map_.find(id);
2418 if (iter == favicon_download_map_.end()) {
2419 // Currently WebContents notifies us of ANY downloads so that it is
2420 // possible to get here.
2421 return;
2422 }
2423 if (!iter->second.is_null()) {
[email protected]8383aa962013-01-10 05:48:532424 iter->second.Run(id, image_url, requested_size, bitmaps);
[email protected]795c28972012-12-06 06:13:392425 }
2426 favicon_download_map_.erase(id);
2427}
2428
2429void WebContentsImpl::OnUpdateFaviconURL(
2430 int32 page_id,
2431 const std::vector<FaviconURL>& candidates) {
2432 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2433 DidUpdateFaviconURL(page_id, candidates));
2434}
2435
[email protected]8607c832013-01-18 14:11:572436void WebContentsImpl::OnFrameDetached(int64 frame_id) {
2437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2438 FrameDetached(message_source_, frame_id));
2439}
2440
[email protected]818915cd2012-11-20 13:14:112441void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
2442 ThreeDAPIType requester) {
2443 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2444 DidBlock3DAPIs(url, requester));
2445}
2446
[email protected]96d185d2009-04-24 03:28:542447// Notifies the RenderWidgetHost instance about the fact that the page is
2448// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262449void WebContentsImpl::SetIsLoading(bool is_loading,
2450 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542451 if (is_loading == is_loading_)
2452 return;
2453
2454 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212455 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542456 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562457 upload_size_ = 0;
2458 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542459 }
2460
2461 render_manager_.SetIsLoading(is_loading);
2462
2463 is_loading_ = is_loading;
2464 waiting_for_response_ = is_loading;
2465
[email protected]6ebdc9b2010-09-27 16:55:572466 if (delegate_)
2467 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212468 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542469
[email protected]8ff00d72012-10-23 19:12:212470 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2471 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542472 if (details)
[email protected]8ff00d72012-10-23 19:12:212473 det = Details<LoadNotificationDetails>(details);
2474 NotificationService::current()->Notify(
2475 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542476}
2477
[email protected]b172aee2012-04-10 17:05:262478void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212479 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322480 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562481 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382482 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442483 // that opened the window, as long as both renderers have the same
2484 // privileges.
[email protected]1fd1a502011-03-30 16:55:562485 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562486 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582487 // web_ui might be NULL if the URL refers to a non-existent extension.
2488 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402489 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522490 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442491 }
2492 }
[email protected]1fd1a502011-03-30 16:55:562493 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442494 }
2495
[email protected]4e697b042011-07-08 06:44:562496 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322497 // Clear the status bubble. This is a workaround for a bug where WebKit
2498 // doesn't let us know that the cursor left an element during a
2499 // transition (this is also why the mouse cursor remains as a hand after
2500 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2501 // clear the bubble when a user navigates to a named anchor in the same
2502 // page.
[email protected]36fc0392011-12-25 03:59:512503 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322504 }
2505
[email protected]a6e82fc2010-02-24 22:28:142506 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472507 // Once the main frame is navigated, we're no longer considered to have
2508 // displayed insecure content.
2509 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172510 }
[email protected]ce5c4502009-05-06 16:46:112511
[email protected]3c9e1872010-11-18 16:17:492512 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252513 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042514 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322515}
2516
[email protected]b172aee2012-04-10 17:05:262517void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322518 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212519 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322520 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062521 // If we navigate off the page, reset JavaScript state. This does nothing
2522 // to prevent a malicious script from spamming messages, since the script
2523 // could just reload the page to stop blocking.
2524 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552525 dialog_creator_->ResetJavaScriptState(this);
2526 dialog_creator_ = NULL;
2527 }
[email protected]420ae012009-04-24 05:16:322528
[email protected]3c9e1872010-11-18 16:17:492529 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252530 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042531 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322532}
2533
[email protected]b172aee2012-04-10 17:05:262534void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462535 // If we are creating a RVH for a restored controller, then we need to make
2536 // sure the RenderView starts with a next_page_id_ larger than the number
2537 // of restored entries. This must be called before the RenderView starts
2538 // navigating (to avoid a race between the browser updating max_page_id and
2539 // the renderer updating next_page_id_). Because of this, we only call this
2540 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562541 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582542 if (max_restored_page_id >
2543 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2544 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2545 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322546}
2547
[email protected]b172aee2012-04-10 17:05:262548bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2549 const string16& title) {
[email protected]420ae012009-04-24 05:16:322550 // For file URLs without a title, use the pathname instead. In the case of a
2551 // synthesized title, we don't want the update to count toward the "one set
2552 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512553 string16 final_title;
[email protected]420ae012009-04-24 05:16:322554 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512555 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2556 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322557 explicit_set = false; // Don't count synthetic titles toward the set limit.
2558 } else {
[email protected]acafd272011-07-26 17:35:572559 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322560 explicit_set = true;
2561 }
2562
[email protected]987fc3a2011-05-26 14:18:092563 // If a page is created via window.open and never navigated,
2564 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552565 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092566 if (entry) {
[email protected]36fc0392011-12-25 03:59:512567 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092568 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322569
[email protected]36fc0392011-12-25 03:59:512570 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092571 } else {
2572 if (page_title_when_no_navigation_entry_ == final_title)
2573 return false; // Nothing changed, don't bother.
2574
2575 page_title_when_no_navigation_entry_ = final_title;
2576 }
[email protected]420ae012009-04-24 05:16:322577
[email protected]420ae012009-04-24 05:16:322578 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232579 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322580
[email protected]8ff00d72012-10-23 19:12:212581 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462582 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142583
[email protected]8ff00d72012-10-23 19:12:212584 NotificationService::current()->Notify(
2585 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2586 Source<WebContents>(this),
2587 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042588
[email protected]420ae012009-04-24 05:16:322589 return true;
2590}
2591
[email protected]35e0e0792012-11-30 02:35:482592void WebContentsImpl::NotifySwapped(RenderViewHost* old_render_view_host) {
[email protected]420ae012009-04-24 05:16:322593 // After sending out a swap notification, we need to send a disconnect
2594 // notification so that clients that pick up a pointer to |this| can NULL the
2595 // pointer. See Bug 1230284.
2596 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212597 NotificationService::current()->Notify(
2598 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2599 Source<WebContents>(this),
[email protected]35e0e0792012-11-30 02:35:482600 Details<RenderViewHost>(old_render_view_host));
[email protected]7a846df2012-09-20 19:17:392601
2602 // Ensure that the associated embedder gets cleared after a RenderViewHost
2603 // gets swapped, so we don't reuse the same embedder next time a
2604 // RenderViewHost is attached to this WebContents.
2605 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322606}
2607
[email protected]b172aee2012-04-10 17:05:262608void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322609 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212610 NotificationService::current()->Notify(
2611 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2612 Source<WebContents>(this),
2613 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322614}
2615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322617 if (!notify_disconnection_)
2618 return;
2619
2620 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212621 NotificationService::current()->Notify(
2622 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2623 Source<WebContents>(this),
2624 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322625}
2626
[email protected]5a3bdf52012-05-24 15:12:572627RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2628 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322629}
2630
[email protected]8d3347f2009-07-09 22:00:212631RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262632WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212633 return &render_manager_;
2634}
2635
[email protected]8ff00d72012-10-23 19:12:212636RendererPreferences WebContentsImpl::GetRendererPrefs(
2637 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462638 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512639}
2640
[email protected]b172aee2012-04-10 17:05:262641WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172642 return this;
2643}
2644
[email protected]b172aee2012-04-10 17:05:262645gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172646 if (delegate_)
2647 return delegate_->GetRootWindowResizerRect();
2648 return gfx::Rect();
2649}
2650
[email protected]7a846df2012-09-20 19:17:392651void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2652 if (browser_plugin_embedder_.get())
2653 browser_plugin_embedder_.reset();
2654}
2655
[email protected]b172aee2012-04-10 17:05:262656void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442657 // Don't send notifications if we are just creating a swapped-out RVH for
2658 // the opener chain. These won't be used for view-source or WebUI, so it's
2659 // ok to return early.
2660 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2661 return;
2662
[email protected]8ff00d72012-10-23 19:12:212663 NotificationService::current()->Notify(
2664 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2665 Source<WebContents>(this),
2666 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232667 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322668 if (!entry)
2669 return;
2670
2671 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352672 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562673 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582674 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322675
2676 if (entry->IsViewSourceMode()) {
2677 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182678 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582679 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322680 }
[email protected]0666aef2009-05-13 19:48:082681
[email protected]d487beefe2011-12-21 05:41:212682 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262683
2684 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252685 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322686}
2687
[email protected]b172aee2012-04-10 17:05:262688void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522689 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322690 // Don't notify the world, since this came from a renderer in the
2691 // background.
2692 return;
2693 }
2694
2695 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312696 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232697 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302698
2699 // Restore the focus to the tab (otherwise the focus will be on the top
2700 // window).
[email protected]484ae5912010-09-29 19:16:142701 if (was_crashed && !FocusLocationBarByDefault() &&
2702 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302703 Focus();
[email protected]484ae5912010-09-29 19:16:142704 }
[email protected]32ded2212011-11-10 18:51:432705
[email protected]d8c660432011-12-22 20:51:252706 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322707}
2708
[email protected]b172aee2012-04-10 17:05:262709void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2710 base::TerminationStatus status,
2711 int error_code) {
[email protected]151a63d2011-12-20 22:32:522712 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322713 // The pending page's RenderViewHost is gone.
2714 return;
2715 }
2716
2717 SetIsLoading(false, NULL);
2718 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232719 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312720 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322721
[email protected]d8c660432011-12-22 20:51:252722 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272723 observers_,
[email protected]be1f56ab2011-12-22 06:55:312724 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322725}
2726
[email protected]b172aee2012-04-10 17:05:262727void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482728 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252729 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062730}
2731
[email protected]b172aee2012-04-10 17:05:262732void WebContentsImpl::DidNavigate(
2733 RenderViewHost* rvh,
2734 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e3d92a7f2013-01-10 02:35:052735 if (PageTransitionIsMainFrame(params.transition)) {
2736 // When overscroll navigation gesture is enabled, a screenshot of the page
2737 // in its current state is taken so that it can be used during the
2738 // nav-gesture. It is necessary to take the screenshot here, before calling
2739 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2740 // WebContents::GetRenderViewHost to return the new host, instead of the one
2741 // that may have just been swapped out.
2742 controller_.TakeScreenshot();
2743
[email protected]420ae012009-04-24 05:16:322744 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052745 }
[email protected]8030f012009-09-25 18:09:372746
[email protected]434f69f2012-02-06 21:56:522747 // Update the site of the SiteInstance if it doesn't have one yet, unless
2748 // this is for about:blank. In that case, the SiteInstance can still be
2749 // considered unused until a navigation to a real page.
2750 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2751 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332752 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522753 }
[email protected]420ae012009-04-24 05:16:322754
2755 // Need to update MIME type here because it's referred to in
2756 // UpdateNavigationCommands() called by RendererDidNavigate() to
2757 // determine whether or not to enable the encoding menu.
2758 // It's updated only for the main frame. For a subframe,
2759 // RenderView::UpdateURL does not set params.contents_mime_type.
2760 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2761 // TODO(jungshik): Add a test for the encoding menu to avoid
2762 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212763 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322764 contents_mime_type_ = params.contents_mime_type;
2765
[email protected]8ff00d72012-10-23 19:12:212766 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002767 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392768
[email protected]a9c0bfe2010-09-17 08:35:222769 // Send notification about committed provisional loads. This notification is
2770 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2771 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212772 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072773 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2774 // that is not recorded in the navigation history. For the purpose of
2775 // tracking navigation events, we treat this event as a sub frame navigation
2776 // event.
2777 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212778 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222779 // Whether or not a page transition was triggered by going backward or
2780 // forward in the history is only stored in the navigation controller's
2781 // entry list.
2782 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512783 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212784 PAGE_TRANSITION_FORWARD_BACK)) {
2785 transition_type = PageTransitionFromInt(
2786 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222787 }
[email protected]0d60f0192011-04-14 12:40:102788 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252789 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102790 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462791 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222792 }
2793
[email protected]76543b92009-08-31 17:27:452794 if (!did_navigate)
2795 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322796
2797 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2798 // for the appropriate notification (best) or you can add it to
2799 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2800 // necessary, please).
2801
2802 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002803 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322804 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512805 if (delegate_)
2806 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002807 }
[email protected]420ae012009-04-24 05:16:322808 DidNavigateAnyFramePostCommit(rvh, details, params);
2809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2812 int32 page_id,
2813 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152814 // Ensure that this state update comes from either the active RVH or one of
2815 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522816 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322817
2818 // We must be prepared to handle state updates for any page, these occur
2819 // when the user is scrolling and entering form data, as well as when we're
2820 // leaving a page, in which case our state may have already been moved to
2821 // the next page. The navigation controller will look up the appropriate
2822 // NavigationEntry and update it when it is notified via the delegate.
2823
2824 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582825 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322826 if (entry_index < 0)
2827 return;
[email protected]10f417c52011-12-28 21:04:232828 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322829
[email protected]36fc0392011-12-25 03:59:512830 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322831 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512832 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322833 controller_.NotifyEntryChanged(entry, entry_index);
2834}
2835
[email protected]b172aee2012-04-10 17:05:262836void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2837 int32 page_id,
2838 const string16& title,
2839 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322840 // If we have a title, that's a pretty good indication that we've started
2841 // getting useful data.
2842 SetNotWaitingForResponse();
2843
[email protected]73eb2602012-02-09 19:50:552844 // Try to find the navigation entry, which might not be the current one.
2845 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232846 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582847 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092848
[email protected]73eb2602012-02-09 19:50:552849 // We can handle title updates when we don't have an entry in
2850 // UpdateTitleForEntry, but only if the update is from the current RVH.
2851 if (!entry && rvh != GetRenderViewHost())
2852 return;
2853
[email protected]a49e10b2011-08-01 23:57:462854 // TODO(evan): make use of title_direction.
2855 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092856 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322857 return;
2858
2859 // Broadcast notifications when the UI should be updated.
2860 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212861 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322862}
2863
[email protected]b172aee2012-04-10 17:05:262864void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2865 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312866 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322867}
2868
[email protected]b172aee2012-04-10 17:05:262869void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512870 if (delegate_)
2871 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322872}
2873
[email protected]b172aee2012-04-10 17:05:262874void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292875 // The UI may be in an event-tracking loop, such as between the
2876 // mouse-down and mouse-up in text selection or a button click.
2877 // Defer the close until after tracking is complete, so that we
2878 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292879 // TODO(shess): This could get more fine-grained. For instance,
2880 // closing a tab in another window while selecting text in the
2881 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212882 if (GetView()->IsEventTracking()) {
2883 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292884 return;
2885 }
2886
[email protected]420ae012009-04-24 05:16:322887 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522888 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512889 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322890}
2891
[email protected]b172aee2012-04-10 17:05:262892void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522893 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512894 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572895}
2896
[email protected]b172aee2012-04-10 17:05:262897void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512898 if (delegate_ && delegate_->IsPopupOrPanel(this))
2899 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322900}
2901
[email protected]8ff00d72012-10-23 19:12:212902void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322903 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492904
[email protected]82114f52012-03-20 22:53:412905 if (delegate_ && content_restrictions_)
2906 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492907
2908 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292909 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2910 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]8ff00d72012-10-23 19:12:212913void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322914 scoped_ptr<LoadNotificationDetails> details;
2915
[email protected]10f417c52011-12-28 21:04:232916 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322917 // An entry may not exist for a stop when loading an initial blank page or
2918 // if an iframe injected by script into a blank page finishes loading.
2919 if (entry) {
[email protected]420ae012009-04-24 05:16:322920 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2921
2922 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512923 entry->GetVirtualURL(),
2924 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322925 elapsed,
2926 &controller_,
2927 controller_.GetCurrentEntryIndex()));
2928 }
2929
[email protected]420ae012009-04-24 05:16:322930 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492931
2932 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292933 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2934 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322935}
2936
[email protected]b172aee2012-04-10 17:05:262937void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162938 controller_.DiscardNonCommittedEntries();
2939
2940 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212941 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262945#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512946 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132947 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262948#endif
[email protected]1a3c3cb2010-12-16 21:03:402949}
2950
[email protected]7cc78902012-12-06 02:32:262951void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
2952 // Clear our opener so that future cross-process navigations don't have an
2953 // opener assigned.
2954 opener_ = NULL;
2955
2956 // Notify all swapped out RenderViewHosts for this tab. This is important
2957 // in case we go back to them, or if another window in those processes tries
2958 // to access window.opener.
2959 render_manager_.DidDisownOpener(rvh);
2960}
2961
[email protected]0720b532012-08-28 19:23:372962void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2963 render_manager_.DidUpdateFrameTree(rvh);
2964}
2965
[email protected]87717d0e2012-04-26 02:58:432966void WebContentsImpl::DocumentAvailableInMainFrame(
2967 RenderViewHost* render_view_host) {
2968 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2969 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102970}
2971
[email protected]b172aee2012-04-10 17:05:262972void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082973 RenderViewHost* render_view_host,
2974 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212975 NotificationService::current()->Notify(
2976 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2977 Source<WebContents>(this),
2978 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082979}
2980
[email protected]196159d2012-05-04 17:26:542981void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2982 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212983 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262984 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:182985 int64 source_frame_id,
2986 bool is_cross_site_redirect) {
[email protected]196159d2012-05-04 17:26:542987 // If this came from a swapped out RenderViewHost, we only allow the request
2988 // if we are still in the same BrowsingInstance.
2989 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2990 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2991 return;
2992 }
2993
[email protected]4ad5d77d2011-12-03 02:00:482994 // Delegate to RequestTransferURL because this is just the generic
2995 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582996 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]e2caa032012-11-15 23:29:182997 GlobalRequestID(), is_cross_site_redirect);
[email protected]4ad5d77d2011-12-03 02:00:482998}
2999
[email protected]b172aee2012-04-10 17:05:263000void WebContentsImpl::RequestTransferURL(
3001 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213002 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263003 WindowOpenDisposition disposition,
3004 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183005 const GlobalRequestID& old_request_id,
3006 bool is_cross_site_redirect) {
[email protected]e5d549d2011-12-28 01:29:203007 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:213008 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:583009 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:353010 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:323011 // is so the new tab page can specify AUTO_BOOKMARK for automatically
3012 // generated suggestions).
3013 //
[email protected]e0112912011-02-02 22:54:353014 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163015 // want web sites to see a referrer of "chrome://blah" (and some
3016 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323017 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:213018 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:223019 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:483020 false /* is_renderer_initiated */);
3021 params.transferred_global_request_id = old_request_id;
3022 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:223023 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:323024 } else {
[email protected]6bf6a6b52012-02-03 15:41:433025 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:213026 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:483027 params.transferred_global_request_id = old_request_id;
[email protected]e2caa032012-11-15 23:29:183028 params.is_cross_site_redirect = is_cross_site_redirect;
[email protected]4ad5d77d2011-12-03 02:00:483029 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:583030 }
3031 if (new_contents) {
3032 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253033 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583034 DidOpenRequestedURL(new_contents,
3035 url,
3036 referrer,
3037 disposition,
3038 transition_type,
3039 source_frame_id));
[email protected]420ae012009-04-24 05:16:323040 }
3041}
3042
[email protected]e1c3a552012-05-04 20:51:323043void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3044 // Tell the active RenderViewHost to run unload handlers and close, as long
3045 // as the request came from a RenderViewHost in the same BrowsingInstance.
3046 // In most cases, we receive this from a swapped out RenderViewHost.
3047 // It is possible to receive it from one that has just been swapped in,
3048 // in which case we might as well deliver the message anyway.
3049 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3050 GetRenderViewHost()->ClosePage();
3051}
3052
[email protected]f546640b2012-05-15 00:03:493053void WebContentsImpl::RouteMessageEvent(
3054 RenderViewHost* rvh,
3055 const ViewMsg_PostMessage_Params& params) {
3056 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363057 // came from a RenderViewHost in the same BrowsingInstance or if this
3058 // WebContents is dedicated to a browser plugin guest.
3059 // Note: This check means that an embedder could theoretically receive a
3060 // postMessage from anyone (not just its own guests). However, this is
3061 // probably not a risk for apps since other pages won't have references
3062 // to App windows.
3063 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3064 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493065 return;
3066
3067 ViewMsg_PostMessage_Params new_params(params);
3068
[email protected]0720b532012-08-28 19:23:373069 // If the renderer has changed while the post message is being routed,
3070 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:193071 // TODO(nasko): Check for process ID and target frame id mismatch, once
3072 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:373073
[email protected]f546640b2012-05-15 00:03:493074 // If there is a source_routing_id, translate it to the routing ID for
3075 // the equivalent swapped out RVH in the target process. If we need
3076 // to create a swapped out RVH for the source tab, we create its opener
3077 // chain as well, since those will also be accessible to the target page.
3078 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3079 // Try to look up the WebContents for the source page.
3080 WebContentsImpl* source_contents = NULL;
3081 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3082 rvh->GetProcess()->GetID(), params.source_routing_id);
3083 if (source_rvh) {
3084 source_contents = static_cast<WebContentsImpl*>(
3085 source_rvh->GetDelegate()->GetAsWebContents());
3086 }
3087
3088 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363089 if (GetBrowserPluginGuest()) {
3090 // We create a swapped out RenderView for the embedder in the guest's
3091 // render process but we intentionally do not expose the embedder's
3092 // opener chain to it.
3093 new_params.source_routing_id =
3094 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3095 } else {
3096 new_params.source_routing_id =
3097 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3098 }
[email protected]f546640b2012-05-15 00:03:493099 } else {
3100 // We couldn't find it, so don't pass a source frame.
3101 new_params.source_routing_id = MSG_ROUTING_NONE;
3102 }
3103 }
3104
3105 // In most cases, we receive this from a swapped out RenderViewHost.
3106 // It is possible to receive it from one that has just been swapped in,
3107 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183108 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343112 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413113 const string16& message,
3114 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323115 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213116 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323117 IPC::Message* reply_msg,
3118 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073119 // Suppress JavaScript dialogs when requested. Also suppress messages when
3120 // showing an interstitial as it's shown over the previous page and we don't
3121 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503122 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583123 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273124 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073125 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523126 delegate_->ShouldSuppressDialogs() ||
3127 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323128
3129 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213130 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433131 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553132 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523133 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433134 this,
3135 frame_url.GetOrigin(),
3136 accept_lang,
3137 javascript_message_type,
3138 message,
[email protected]51da7e32012-01-30 19:24:523139 default_prompt,
[email protected]b172aee2012-04-10 17:05:263140 base::Bind(&WebContentsImpl::OnDialogClosed,
3141 base::Unretained(this),
3142 rvh,
3143 reply_msg),
[email protected]51da7e32012-01-30 19:24:523144 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323145 }
[email protected]3ab9cb82011-06-03 18:02:073146
3147 if (suppress_this_message) {
3148 // If we are suppressing messages, just reply as if the user immediately
3149 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343150 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073151 }
3152
3153 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323154}
3155
[email protected]b172aee2012-04-10 17:05:263156void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3157 const string16& message,
3158 bool is_reload,
3159 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583160 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513161 if (delegate_)
3162 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073163
3164 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583165 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073166 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523167 delegate_->ShouldSuppressDialogs() ||
3168 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153169 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343170 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583171 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503172 return;
3173 }
[email protected]3ab9cb82011-06-03 18:02:073174
[email protected]7ab1e7d62009-10-14 23:32:013175 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553176 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523177 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323178 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263179 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523180 reply_msg));
[email protected]420ae012009-04-24 05:16:323181}
3182
[email protected]a796f202012-05-30 14:14:253183bool WebContentsImpl::AddMessageToConsole(int32 level,
3184 const string16& message,
3185 int32 line_no,
3186 const string16& source_id) {
3187 if (!delegate_)
3188 return false;
3189 return delegate_->AddMessageToConsole(this, level, message, line_no,
3190 source_id);
3191}
3192
[email protected]b172aee2012-04-10 17:05:263193WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333194 // We want to base the page config off of the real URL, rather than the
3195 // display URL.
3196 GURL url = controller_.GetActiveEntry()
3197 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3198 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323199}
3200
[email protected]0eba810b2012-10-18 03:19:363201int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213202 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363203 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3204}
3205
[email protected]b172aee2012-04-10 17:05:263206void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273207 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253208 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223209
[email protected]ea114722012-03-12 01:11:253210 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173211 if (rdh) // NULL in unittests.
3212 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253213}
3214
[email protected]b172aee2012-04-10 17:05:263215void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443216 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253217 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443218}
3219
[email protected]b172aee2012-04-10 17:05:263220void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3221 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153222 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523223 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153224 return;
3225
[email protected]9f76c1e2012-03-05 15:15:583226 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3227
[email protected]e5fc1632011-08-08 07:51:533228 // Ignore renderer unresponsive event if debugger is attached to the tab
3229 // since the event may be a result of the renderer sitting on a breakpoint.
3230 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363231 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533232 return;
3233
[email protected]420ae012009-04-24 05:16:323234 if (is_during_unload) {
3235 // Hang occurred while firing the beforeunload/unload handler.
3236 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583237 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323238
3239 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3240 return;
3241
3242 // If the tab hangs in the beforeunload/unload handler there's really
3243 // nothing we can do to recover. Pretend the unload listeners have
3244 // all fired and close the tab. If the hang is in the beforeunload handler
3245 // then the user will not have the option of cancelling the close.
3246 Close(rvh);
3247 return;
3248 }
3249
[email protected]9f76c1e2012-03-05 15:15:583250 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473251 return;
3252
[email protected]6934a702011-12-20 00:04:513253 if (delegate_)
3254 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323255}
3256
[email protected]b172aee2012-04-10 17:05:263257void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513258 if (delegate_)
3259 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323260}
3261
[email protected]b172aee2012-04-10 17:05:263262void WebContentsImpl::LoadStateChanged(
3263 const GURL& url,
3264 const net::LoadStateWithParam& load_state,
3265 uint64 upload_position,
3266 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323267 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563268 upload_position_ = upload_position;
3269 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503270 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213271 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303272 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213273 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323274 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463275 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213276 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463277 }
[email protected]420ae012009-04-24 05:16:323278}
3279
[email protected]b172aee2012-04-10 17:05:263280void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513281 if (delegate_)
3282 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253283}
3284
[email protected]b172aee2012-04-10 17:05:263285void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553286 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323287 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553288 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513289 if (delegate_)
3290 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323291}
3292
[email protected]b172aee2012-04-10 17:05:263293void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543294 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233295 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3296 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543297}
3298
[email protected]b172aee2012-04-10 17:05:263299void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103300 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263301 gfx::Size size = view_->GetContainerSize();
3302 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3303 // here during container initialization and normal window size will be set
3304 // later. In case of tab duplication this resizing to 0x0 prevents setting
3305 // normal size later so just ignore it.
3306 if (!size.IsEmpty())
3307 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323308}
3309
[email protected]35e0e0792012-11-30 02:35:483310void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* rvh) {
3311 NotifySwapped(rvh);
[email protected]3a3d47472010-07-15 21:03:543312}
3313
[email protected]14392a52012-05-02 20:28:443314int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3315 SiteInstance* instance) {
3316 if (!opener_)
3317 return MSG_ROUTING_NONE;
3318
3319 // Recursively create RenderViews for anything else in the opener chain.
3320 return opener_->CreateOpenerRenderViews(instance);
3321}
3322
3323int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3324 int opener_route_id = MSG_ROUTING_NONE;
3325
3326 // If this tab has an opener, ensure it has a RenderView in the given
3327 // SiteInstance as well.
3328 if (opener_)
3329 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3330
[email protected]0720b532012-08-28 19:23:373331 // If any of the renderers for this WebContents has the same SiteInstance,
3332 // use it.
3333 if (render_manager_.current_host()->GetSiteInstance() == instance)
3334 return render_manager_.current_host()->GetRoutingID();
3335
3336 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3337 instance);
3338 if (rvh)
3339 return rvh->GetRoutingID();
3340
[email protected]14392a52012-05-02 20:28:443341 // Create a swapped out RenderView in the given SiteInstance if none exists,
3342 // setting its opener to the given route_id. Return the new view's route_id.
3343 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3344}
3345
[email protected]b172aee2012-04-10 17:05:263346NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193347 return GetController();
[email protected]3a3d47472010-07-15 21:03:543348}
3349
[email protected]b172aee2012-04-10 17:05:263350WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563351 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323352}
3353
[email protected]10f417c52011-12-28 21:04:233354NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263355 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323356 return controller_.GetLastCommittedEntry();
3357}
3358
[email protected]b172aee2012-04-10 17:05:263359bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443360 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443361 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323362 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523363
[email protected]420ae012009-04-24 05:16:323364 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443365 if (rwh_view)
3366 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323367
[email protected]74ce1ad2011-12-16 21:51:463368 // Make sure we use the correct starting page_id in the new RenderView.
3369 UpdateMaxPageIDIfNecessary(render_view_host);
3370 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583371 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463372
[email protected]9f76c1e2012-03-05 15:15:583373 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493374 render_view_host)->CreateRenderView(string16(),
3375 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133376 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523377 return false;
[email protected]14392a52012-05-02 20:28:443378 }
[email protected]a4127722011-04-27 23:13:523379
[email protected]e60c0232011-11-11 19:56:353380#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503381 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3382 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443383 if (rwh_view) {
3384 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3385 render_widget_host->WasResized();
3386 }
[email protected]f8233cc2011-05-31 20:24:503387#endif
3388
[email protected]420ae012009-04-24 05:16:323389 return true;
3390}
3391
[email protected]b172aee2012-04-10 17:05:263392void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3393 IPC::Message* reply_msg,
3394 bool success,
3395 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543396 if (is_showing_before_unload_dialog_ && !success) {
3397 // If a beforeunload dialog is canceled, we need to stop the throbber from
3398 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293399 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353400 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543401
[email protected]3bbacc5b2012-04-17 17:46:153402 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553403 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543404 }
3405 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583406 static_cast<RenderViewHostImpl*>(
3407 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213411 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123412 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103413}
[email protected]f45d2a72010-03-08 23:28:353414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213416 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263417 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573418 DownloadManager* dlm =
3419 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143420 if (!dlm)
3421 return;
3422 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263423 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143424 const NavigationEntry* entry = controller_.GetActiveEntry();
3425 if (entry)
3426 post_id = entry->GetPostID();
3427 }
[email protected]c5a5c0842012-05-04 20:05:143428 scoped_ptr<DownloadUrlParameters> params(
[email protected]49d812e2012-11-06 21:18:123429 DownloadUrlParameters::FromWebContents(this, url));
[email protected]f859eba2012-05-30 17:22:493430 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143431 params->set_post_id(post_id);
3432 params->set_prefer_cache(true);
3433 if (post_id >= 0)
3434 params->set_method("POST");
[email protected]49d812e2012-11-06 21:18:123435 params->set_prompt(true);
[email protected]c5a5c0842012-05-04 20:05:143436 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143437}
3438
[email protected]b172aee2012-04-10 17:05:263439void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213440 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443441 // Can be NULL during tests.
3442 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213443 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363444}
[email protected]9f76c1e2012-03-05 15:15:583445
[email protected]b172aee2012-04-10 17:05:263446RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583447 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3448}
[email protected]7900bfdb2012-05-24 19:31:243449
[email protected]8ff00d72012-10-23 19:12:213450BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393451 return browser_plugin_guest_.get();
3452}
3453
[email protected]8ff00d72012-10-23 19:12:213454BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393455 return browser_plugin_embedder_.get();
3456}
[email protected]8ff00d72012-10-23 19:12:213457
3458} // namespace content