blob: 2236fa15fd73028833748ba90e8498356755436b [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1925#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]5c9250872012-01-30 17:24:0535#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4436#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5337#include "content/browser/message_port_message_filter.h"
38#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0639#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3040#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3241#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5042#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3343#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1144#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5845#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0346#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5647#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1448#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4249#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4450#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0251#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5152#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0253#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5754#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5855#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1156#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2057#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4458#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3659#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1760#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1461#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4662#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1563#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0064#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2765#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0066#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3767#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1468#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3269#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3470#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3871#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4272#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2573#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1074#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2175#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4876#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5477#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4978#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2079#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0380#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1681#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2982#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5383#include "net/http/http_cache.h"
84#include "net/http/http_transaction_factory.h"
85#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3486#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5687#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0188#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4189#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5290#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1891#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3192
[email protected]583418cc2013-01-17 14:01:1093#if defined(OS_ANDROID)
94#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3295#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:1896#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:3297#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0098#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:1099#endif
100
[email protected]f66df822012-05-18 16:52:17101#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50102#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27103#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57104#endif
[email protected]3e45ba92009-02-20 21:09:00105
[email protected]420ae012009-04-24 05:16:32106// Cross-Site Navigations
107//
[email protected]b172aee2012-04-10 17:05:26108// If a WebContentsImpl is told to navigate to a different web site (as
109// determined by SiteInstance), it will replace its current RenderViewHost with
110// a new RenderViewHost dedicated to the new SiteInstance. This works as
111// follows:
[email protected]420ae012009-04-24 05:16:32112//
[email protected]fc6c1872013-10-03 01:22:35113// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46114// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32115// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35116// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32117// run in the current RVH.
118// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35119// that it has a pending cross-site request. We will check this on the IO
120// thread when deciding how to handle the response.
121// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46122// cancel all the pending logic. Otherwise we allow the pending RVH to send
123// the navigation request to its renderer.
124// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35125// main resource load on the pending RVH. It creates a
126// CrossSiteResourceHandler to check whether a process swap is needed when
127// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46128// - When RDH receives a response, the BufferedResourceHandler determines
129// whether it is a download. If so, it sends a message to the new renderer
130// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26131// pending RVH remains until the next DidNavigate event for this
132// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32133// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35134// download, the CrossSiteResourceHandler checks whether a process swap is
135// needed (either because CrossSiteRequestManager has state for it or because
136// a transfer was needed for a redirect).
137// - If so, CrossSiteResourceHandler pauses the response to first run the old
138// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36139// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
140// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35141// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
142// to a new process is needed, based on the stored pending_nav_params_. (This
143// is independent of whether we started out with a cross-process navigation.)
144// - If not, it just tells the ResourceDispatcherHost to resume the response
145// to its current RenderViewHost.
146// - If so, it cancels the current pending RenderViewHost and sets up a new
147// navigation using RequestTransferURL. When the transferred request
148// arrives in the ResourceDispatcherHost, we transfer the response and
149// resume it.
[email protected]420ae012009-04-24 05:16:32150// - The pending renderer sends a FrameNavigate message that invokes the
151// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46152// pending RVH.
[email protected]b0936d22013-11-28 06:47:36153// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15154// the user goes back. The process only stays live if another tab is using
155// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32156
[email protected]8ff00d72012-10-23 19:12:21157namespace content {
[email protected]420ae012009-04-24 05:16:32158namespace {
159
[email protected]82114f52012-03-20 22:53:41160const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05161
[email protected]155c7f22013-12-09 17:07:18162#if defined(OS_ANDROID)
163const char kWebContentsAndroidKey[] = "web_contents_android";
164#endif // OS_ANDROID
165
[email protected]e4abd3b42013-11-12 18:28:47166base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46167g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
168
[email protected]795c28972012-12-06 06:13:39169static int StartDownload(content::RenderViewHost* rvh,
170 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29171 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30172 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02173 static int g_next_image_download_id = 0;
174 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
175 ++g_next_image_download_id,
176 url,
177 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30178 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02179 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39180}
181
[email protected]2c5569662011-03-22 20:45:02182ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21183 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50184 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16185 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47186 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23190 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
191 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47192 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16193 break; // Fall through to rest of function.
194 }
[email protected]5e369672009-11-03 23:48:30195
[email protected]59246c572012-02-10 13:32:13196 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
197 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36198 if (entry.restore_type() ==
199 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13200 if (entry.GetHasPostData())
201 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02202 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13203 }
[email protected]5e369672009-11-03 23:48:30204
[email protected]2c5569662011-03-22 20:45:02205 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30206}
207
[email protected]10f417c52011-12-28 21:04:23208void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47209 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21210 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50211 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16212 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51213 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13214 params->should_clear_history_list = entry.should_clear_history_list();
[email protected]4972fc82013-11-19 04:33:42215 params->should_replace_current_entry = entry.should_replace_entry();
[email protected]60d6cca2013-04-30 08:47:13216 if (entry.should_clear_history_list()) {
217 // Set the history list related parameters to the same values a
218 // NavigationController would return before its first navigation. This will
219 // fully clear the RenderView's view of the session history.
220 params->pending_history_list_offset = -1;
221 params->current_history_list_offset = -1;
222 params->current_history_list_length = 0;
223 } else {
224 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
225 params->current_history_list_offset =
226 controller.GetLastCommittedEntryIndex();
227 params->current_history_list_length = controller.GetEntryCount();
228 }
[email protected]eaaba7dd2013-10-14 02:38:07229 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36230 if (!entry.GetBaseURLForDataURL().is_empty()) {
231 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
232 params->history_url_for_data_url = entry.GetVirtualURL();
233 }
[email protected]36fc0392011-12-25 03:59:51234 params->referrer = entry.GetReferrer();
235 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04236 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00237 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55238 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34239 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47240 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48241 params->transferred_request_child_id =
242 entry.transferred_global_request_id().child_id;
243 params->transferred_request_request_id =
244 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22245 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00246 // Avoid downloading when in view-source mode.
247 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44248 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07249 if (entry.GetBrowserInitiatedPostData()) {
250 params->browser_initiated_post_data.assign(
251 entry.GetBrowserInitiatedPostData()->front(),
252 entry.GetBrowserInitiatedPostData()->front() +
253 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23254 }
255
[email protected]f8872902013-10-30 03:18:57256 params->redirects = entry.redirect_chain();
257
[email protected]951a64832012-10-11 16:26:37258 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58259 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37260
[email protected]6c6b02d2011-09-02 03:36:47261 if (delegate)
262 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34263}
264
[email protected]8bfc8272013-09-09 20:10:53265void NotifyCacheOnIO(
266 scoped_refptr<net::URLRequestContextGetter> request_context,
267 const GURL& url,
268 const std::string& http_method) {
269 request_context->GetURLRequestContext()->http_transaction_factory()->
270 GetCache()->OnExternalCacheHit(url, http_method);
271}
272
[email protected]9b159a52013-10-03 17:24:55273// Helper function for retrieving all the sites in a frame tree.
274bool CollectSites(BrowserContext* context,
275 std::set<GURL>* sites,
276 FrameTreeNode* node) {
277 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
278 return true;
279}
280
[email protected]420ae012009-04-24 05:16:32281} // namespace
282
[email protected]54944cde2012-12-09 09:24:59283WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15284 return WebContentsImpl::CreateWithOpener(
285 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19286}
287
288WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59289 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30290 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59291 WebContentsImpl* new_contents = new WebContentsImpl(
292 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30293
294 for (SessionStorageNamespaceMap::const_iterator it =
295 session_storage_namespace_map.begin();
296 it != session_storage_namespace_map.end();
297 ++it) {
298 new_contents->GetController()
299 .SetSessionStorageNamespace(it->first, it->second.get());
300 }
301
[email protected]54944cde2012-12-09 09:24:59302 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19303 return new_contents;
[email protected]a81343d232011-12-27 07:39:20304}
[email protected]746d3052012-05-22 15:15:47305
[email protected]e4abd3b42013-11-12 18:28:47306void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46307 g_created_callbacks.Get().push_back(callback);
308}
309
[email protected]e4abd3b42013-11-12 18:28:47310void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46311 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
312 if (g_created_callbacks.Get().at(i).Equals(callback)) {
313 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
314 return;
315 }
316 }
317}
318
[email protected]299d7f12012-05-23 05:31:15319WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47320 return rvh->GetDelegate()->GetAsWebContents();
321}
322
[email protected]7fff43e2013-05-21 20:21:10323// WebContentsImpl::DestructionObserver ----------------------------------------
324
325class WebContentsImpl::DestructionObserver : public WebContentsObserver {
326 public:
327 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
328 : WebContentsObserver(watched_contents),
329 owner_(owner) {
330 }
331
332 // WebContentsObserver:
333 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
334 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
335 }
336
337 private:
338 WebContentsImpl* owner_;
339
340 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
341};
342
[email protected]b172aee2012-04-10 17:05:26343// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32344
[email protected]b172aee2012-04-10 17:05:26345WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21346 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19347 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42348 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22349 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57350 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44351 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41352#if defined(OS_WIN) && defined(USE_AURA)
353 accessible_parent_(NULL),
354#endif
[email protected]6ea6bdf2013-12-06 13:35:01355 frame_tree_(new NavigatorImpl(&controller_, this),
356 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34357 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23358 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
359 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34360 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26361 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56362 upload_size_(0),
363 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47364 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55365 capturer_count_(0),
366 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57367 is_being_destroyed_(false),
368 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15369 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01370 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38371 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21372 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
373 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00374 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21375 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44376 render_view_message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54377 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46378 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
379 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55380 frame_tree_.SetFrameRemoveListener(
381 base::Bind(&WebContentsImpl::OnFrameRemoved,
382 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35383}
initial.commit09911bf2008-07-26 23:55:29384
[email protected]b172aee2012-04-10 17:05:26385WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32386 is_being_destroyed_ = true;
387
[email protected]d9030b82013-07-19 08:26:06388 ClearAllPowerSaveBlockers();
389
[email protected]b24b68a2012-09-24 21:57:26390 for (std::set<RenderWidgetHostImpl*>::iterator iter =
391 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
392 (*iter)->DetachDelegate();
393 }
394 created_widgets_.clear();
395
[email protected]3ab9cb82011-06-03 18:02:07396 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15397 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11398 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07399
[email protected]da8543762012-03-20 08:52:20400 if (color_chooser_)
401 color_chooser_->End();
402
[email protected]420ae012009-04-24 05:16:32403 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32404
[email protected]ca13a442012-04-17 14:00:12405 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21406 NotificationService::current()->Notify(
407 NOTIFICATION_WEB_CONTENTS_DESTROYED,
408 Source<WebContents>(this),
409 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32410
411 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07412#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32413 // If we still have a window handle, destroy it. GetNativeView can return
414 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06415 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52416 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58417 if (host && host->GetView())
418 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42419 }
[email protected]420ae012009-04-24 05:16:32420#endif
[email protected]7ab1e7d62009-10-14 23:32:01421
[email protected]fa944cb82013-11-15 17:51:21422 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27423 if (pending_rvh) {
424 FOR_EACH_OBSERVER(WebContentsObserver,
425 observers_,
426 RenderViewDeleted(pending_rvh));
427 }
428
429 FOR_EACH_OBSERVER(WebContentsObserver,
430 observers_,
[email protected]fa944cb82013-11-15 17:51:21431 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27432
[email protected]2db9bd72012-04-13 20:20:56433 FOR_EACH_OBSERVER(WebContentsObserver,
434 observers_,
435 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08436
[email protected]6934a702011-12-20 00:04:51437 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10438
439 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
440 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42441}
442
[email protected]d1198fd2012-08-13 22:50:19443WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59444 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19445 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03446 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59447 WebContentsImpl* new_contents = new WebContentsImpl(
448 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19449
[email protected]54944cde2012-12-09 09:24:59450 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19451 return new_contents;
452}
453
[email protected]b371a5652013-02-20 11:25:51454// static
[email protected]8eb04562013-03-06 03:41:14455BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36456 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53457 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54458 int guest_instance_id,
459 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39460 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39461
462 // This makes |new_contents| act as a guest.
463 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54464 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19465 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11466
[email protected]3de10bb32013-01-08 21:57:33467 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33468 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11469
[email protected]216be772013-01-25 00:22:27470 // We are instantiating a WebContents for browser plugin. Set its subframe bit
471 // to true.
472 static_cast<RenderViewHostImpl*>(
473 new_contents->GetRenderViewHost())->set_is_subframe(true);
474
[email protected]8eb04562013-03-06 03:41:14475 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39476}
477
[email protected]b0936d22013-11-28 06:47:36478RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21479 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28480}
481
[email protected]7bb761892012-07-20 09:32:47482bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
483 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44484 return OnMessageReceived(render_view_host, NULL, message);
485}
486
487bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
488 RenderFrameHost* render_frame_host,
489 const IPC::Message& message) {
490 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56491 if (GetWebUI() &&
492 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17493 return true;
[email protected]d2353452012-01-19 19:53:56494 }
[email protected]f82d57b52011-04-27 19:13:17495
[email protected]d8c660432011-12-22 20:51:25496 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
497 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10498 while ((observer = it.GetNext()) != NULL)
499 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53500 return true;
[email protected]403415a2011-01-10 18:57:53501
[email protected]c80725d52013-12-06 06:22:26502 // Message handlers should be aware of which RenderViewHost sent the
[email protected]f114fa42013-12-06 17:06:44503 // message, which is temporarily stored in render_view_message_source_.
504 render_view_message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18505 bool handled = true;
506 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26507 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44508 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18510 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
511 OnDidLoadResourceFromMemoryCache)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
513 OnDidDisplayInsecureContent)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
515 OnDidRunInsecureContent)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
517 OnDocumentLoadedInFrame)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26519 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
520 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25521 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26522 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21523 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20524 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
525 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
526 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16527 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10528 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20529 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
531 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
532 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50533 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50534 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
535 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55536 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
537 OnBrowserPluginMessage(message))
538 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
539 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02540 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
541 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10542#if defined(OS_ANDROID)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
544 OnFindMatchRectsReply)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
546 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32547 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
548 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10549#endif
[email protected]d9030b82013-07-19 08:26:06550 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15551 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
552 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07553 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
554 OnShowValidationMessage)
555 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
556 OnHideValidationMessage)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
558 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18559 IPC_MESSAGE_UNHANDLED(handled = false)
560 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44561 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18562
563 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21564 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18565 GetRenderProcessHost()->ReceivedBadMessage();
566 }
567
568 return handled;
569}
570
[email protected]b172aee2012-04-10 17:05:26571void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18572 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21573 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43574 if (delegate_)
575 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18576}
577
[email protected]d1198fd2012-08-13 22:50:19578NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56579 return controller_;
580}
581
[email protected]d1198fd2012-08-13 22:50:19582const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56583 return controller_;
584}
585
[email protected]8ff00d72012-10-23 19:12:21586BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55587 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30588}
589
[email protected]b172aee2012-04-10 17:05:26590const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24591 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32592 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51593 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31594}
595
[email protected]a093ce02013-07-22 20:53:14596const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24597 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32598 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24599 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
600}
601
602const GURL& WebContentsImpl::GetLastCommittedURL() const {
603 // We may not have a navigation entry yet.
604 NavigationEntry* entry = controller_.GetLastCommittedEntry();
605 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
606}
607
[email protected]8ff00d72012-10-23 19:12:21608WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31609 return delegate_;
610}
611
[email protected]8ff00d72012-10-23 19:12:21612void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31613 // TODO(cbentzel): remove this debugging code?
614 if (delegate == delegate_)
615 return;
616 if (delegate_)
617 delegate_->Detach(this);
618 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08619 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31620 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08621 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00622 if (view_)
623 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08624 }
[email protected]be1f56ab2011-12-22 06:55:31625}
626
[email protected]8ff00d72012-10-23 19:12:21627RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21628 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41629 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16630}
631
[email protected]60eca4eb2013-12-06 00:02:16632RenderFrameHost* WebContentsImpl::GetMainFrame() {
633 return frame_tree_.root()->render_frame_host();
634}
635
[email protected]b172aee2012-04-10 17:05:26636RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21637 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31638}
639
[email protected]a04c9d02012-11-14 21:04:34640void WebContentsImpl::GetRenderViewHostAtPosition(
641 int x,
642 int y,
643 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
644 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
645 if (embedder)
646 embedder->GetRenderViewHostAtPosition(x, y, callback);
647 else
648 callback.Run(GetRenderViewHost(), x, y);
649}
650
[email protected]bfcfa692013-02-07 06:17:02651WebContents* WebContentsImpl::GetEmbedderWebContents() const {
652 BrowserPluginGuest* guest = GetBrowserPluginGuest();
653 if (guest)
654 return guest->embedder_web_contents();
655 return NULL;
656}
657
658int WebContentsImpl::GetEmbeddedInstanceID() const {
659 BrowserPluginGuest* guest = GetBrowserPluginGuest();
660 if (guest)
661 return guest->instance_id();
662 return 0;
663}
664
[email protected]6b618e62012-08-16 12:59:18665int WebContentsImpl::GetRoutingID() const {
666 if (!GetRenderViewHost())
667 return MSG_ROUTING_NONE;
668
669 return GetRenderViewHost()->GetRoutingID();
670}
671
[email protected]44470a22013-01-24 01:21:54672int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
673 return fullscreen_widget_routing_id_;
674}
675
[email protected]b172aee2012-04-10 17:05:26676RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21677 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31678}
679
[email protected]f8497342013-02-05 22:15:02680RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
681 BrowserPluginGuest* guest = GetBrowserPluginGuest();
682 if (guest && guest->embedder_web_contents()) {
683 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
684 }
685 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
686}
687
[email protected]4aebbca2013-09-17 22:26:49688RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
689 const {
690 RenderWidgetHost* const widget_host =
691 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
692 GetFullscreenWidgetRoutingID());
693 return widget_host ? widget_host->GetView() : NULL;
694}
695
[email protected]8ff00d72012-10-23 19:12:21696WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31697 return view_.get();
698}
699
[email protected]8ff00d72012-10-23 19:12:21700WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56701 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03702 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
703 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22704 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58705 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22706 web_ui->SetController(controller);
707 return web_ui;
708 }
709
710 delete web_ui;
711 return NULL;
712}
713
[email protected]8ff00d72012-10-23 19:12:21714WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21715 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
716 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31717}
718
[email protected]8ff00d72012-10-23 19:12:21719WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21720 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34721}
722
[email protected]86ef6a392012-05-11 22:03:11723void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22724 if (GetUserAgentOverride() == override)
725 return;
726
727 renderer_preferences_.user_agent_override = override;
728
729 // Send the new override string to the renderer.
730 RenderViewHost* host = GetRenderViewHost();
731 if (host)
732 host->SyncRendererPrefs();
733
734 // Reload the page if a load is currently in progress to avoid having
735 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27736 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22737 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
738 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53739
740 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
741 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11742}
743
744const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22745 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11746}
747
[email protected]c73a2282013-04-29 21:10:41748#if defined(OS_WIN) && defined(USE_AURA)
749void WebContentsImpl::SetParentNativeViewAccessible(
750gfx::NativeViewAccessible accessible_parent) {
751 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45752 if (GetRenderViewHost())
753 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41754}
755#endif
756
[email protected]fcf75d42013-12-03 20:11:26757const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55758 // Transient entries take precedence. They are used for interstitial pages
759 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23760 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08761 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21762 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30763 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23764 if (entry) {
[email protected]b5cca982011-05-26 04:42:08765 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23766 }
[email protected]fa944cb82013-11-15 17:51:21767 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
768 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58769 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54770 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32771 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54772 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35773 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26774 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54775 if (!title.empty())
776 return title;
777 }
778 }
779
780 // We use the title for the last committed entry rather than a pending
781 // navigation entry. For example, when the user types in a URL, we want to
782 // keep the old page's title until the new load has committed and we get a new
783 // title.
[email protected]96d185d2009-04-24 03:28:54784 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32785
[email protected]9eeafc012013-11-25 23:49:47786 // We make an exception for initial navigations.
787 if (controller_.IsInitialNavigation()) {
788 // We only want to use the title from the visible entry in one of two cases:
789 // 1. There's already a committed entry for an initial navigation, in which
790 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
791 // 2. The pending entry has been explicitly assigned a title to display.
792 //
793 // If there's no last committed entry and no assigned title, we should fall
794 // back to |page_title_when_no_navigation_entry_| rather than showing the
795 // URL.
796 if (entry ||
797 (controller_.GetVisibleEntry() &&
798 !controller_.GetVisibleEntry()->GetTitle().empty())) {
799 entry = controller_.GetVisibleEntry();
800 }
801 }
[email protected]59167c22013-06-03 18:07:32802
[email protected]45d0ef7f2011-01-05 13:46:23803 if (entry) {
[email protected]b5cca982011-05-26 04:42:08804 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23805 }
[email protected]987fc3a2011-05-26 14:18:09806
807 // |page_title_when_no_navigation_entry_| is finally used
808 // if no title cannot be retrieved.
809 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54810}
811
[email protected]b172aee2012-04-10 17:05:26812int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46813 return GetMaxPageIDForSiteInstance(GetSiteInstance());
814}
815
[email protected]b172aee2012-04-10 17:05:26816int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
817 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33818 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
819 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46820
[email protected]b6583592012-01-25 19:52:33821 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34822}
823
[email protected]b172aee2012-04-10 17:05:26824void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46825 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
826}
827
[email protected]b172aee2012-04-10 17:05:26828void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33829 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46830 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33831 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34832}
833
[email protected]ec6c05f2013-10-23 18:41:57834void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
835 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
836 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57837}
838
[email protected]b172aee2012-04-10 17:05:26839SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21840 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54841}
842
[email protected]b172aee2012-04-10 17:05:26843SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21844 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
845 GetRenderManager()->pending_render_view_host() :
846 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58847 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38848}
849
[email protected]b172aee2012-04-10 17:05:26850bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49852}
853
[email protected]b172aee2012-04-10 17:05:26854bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return waiting_for_response_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return load_state_;
860}
861
[email protected]fcf75d42013-12-03 20:11:26862const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31863 return load_state_host_;
864}
865
[email protected]b172aee2012-04-10 17:05:26866uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return upload_size_;
868}
869
[email protected]b172aee2012-04-10 17:05:26870uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return upload_position_;
872}
873
[email protected]1ae93fb2013-06-14 03:38:56874std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56875 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55876 frame_tree_.ForEach(Bind(&CollectSites,
877 base::Unretained(GetBrowserContext()),
878 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56879 return sites;
880}
881
[email protected]b172aee2012-04-10 17:05:26882const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return encoding_;
884}
885
[email protected]b172aee2012-04-10 17:05:26886bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31887 return displayed_insecure_content_;
888}
889
[email protected]54597982013-02-06 01:59:55890void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25891 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55892 ++capturer_count_;
893 DVLOG(1) << "There are now " << capturer_count_
894 << " capturing(s) of WebContentsImpl@" << this;
895}
896
897void WebContentsImpl::DecrementCapturerCount() {
898 --capturer_count_;
899 DVLOG(1) << "There are now " << capturer_count_
900 << " capturing(s) of WebContentsImpl@" << this;
901 DCHECK_LE(0, capturer_count_);
902
[email protected]5a652232013-02-12 06:15:25903 if (is_being_destroyed_)
904 return;
905
[email protected]1ac10dca2013-08-20 20:47:04906 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55907 DVLOG(1) << "Executing delayed WasHidden().";
908 WasHidden();
909 }
[email protected]be1f56ab2011-12-22 06:55:31910}
911
[email protected]f2bd40812013-07-20 04:30:44912int WebContentsImpl::GetCapturerCount() const {
913 return capturer_count_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31917 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
918 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
919 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49920}
921
[email protected]b172aee2012-04-10 17:05:26922void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
923 int error_code) {
[email protected]443b80e2010-12-14 00:42:23924 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34925 return;
926
[email protected]443b80e2010-12-14 00:42:23927 crashed_status_ = status;
928 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21929 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34930}
931
[email protected]b172aee2012-04-10 17:05:26932base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return crashed_status_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31937 return is_being_destroyed_;
938}
939
[email protected]b172aee2012-04-10 17:05:26940void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34941 if (delegate_)
942 delegate_->NavigationStateChanged(this, changed_flags);
943}
944
[email protected]3e324142012-06-25 18:26:33945base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
946 return last_selected_time_;
947}
948
[email protected]9e2e4632012-07-27 16:38:41949void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54950 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04951 RenderWidgetHostViewPort* rwhv =
952 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16953 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29954 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43955#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16956 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43957#endif
958 }
[email protected]96d185d2009-04-24 03:28:54959
[email protected]5ac20162010-11-24 23:33:11960 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38961
[email protected]b9769d82012-02-10 00:23:59962 // The resize rect might have changed while this was inactive -- send the new
963 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58964 RenderViewHostImpl* rvh =
965 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59966 if (rvh) {
967 rvh->ResizeRectChanged(GetRootWindowResizerRect());
968 }
[email protected]96d185d2009-04-24 03:28:54969
[email protected]c0d9d5672013-10-09 07:38:03970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
971
[email protected]54597982013-02-06 01:59:55972 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31973}
974
[email protected]b172aee2012-04-10 17:05:26975void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55976 // If there are entities capturing screenshots or video (e.g., mirroring),
977 // don't activate the "disable rendering" optimization.
978 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52979 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55980 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26981 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52982 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33983 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52984 // calls us).
[email protected]c30585c2012-02-16 15:02:04985 RenderWidgetHostViewPort* rwhv =
986 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16987 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29988 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54989 }
990
[email protected]c0d9d5672013-10-09 07:38:03991 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
992
[email protected]54597982013-02-06 01:59:55993 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37994}
995
[email protected]b172aee2012-04-10 17:05:26996bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31997 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27998 return WillNotifyDisconnection() &&
999 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581000 !static_cast<RenderViewHostImpl*>(
1001 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311002}
1003
[email protected]b172aee2012-04-10 17:05:261004void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211005 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401006 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271007}
1008
[email protected]b172aee2012-04-10 17:05:261009WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441010 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451011 // We pass our own opener so that the cloned page can access it if it was
1012 // before.
[email protected]54944cde2012-12-09 09:24:591013 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451014 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591015 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191016 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221017 FOR_EACH_OBSERVER(WebContentsObserver,
1018 observers_,
1019 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271020 return tc;
1021}
1022
[email protected]14392a52012-05-02 20:28:441023void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211024 const NotificationSource& source,
1025 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441026 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211027 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1028 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501029 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1030 i != pending_widget_views_.end(); ++i) {
1031 if (host->GetView() == i->second) {
1032 pending_widget_views_.erase(i);
1033 break;
1034 }
1035 }
1036 break;
1037 }
[email protected]14392a52012-05-02 20:28:441038 default:
1039 NOTREACHED();
1040 }
1041}
1042
[email protected]ec6c05f2013-10-23 18:41:571043WebContents* WebContentsImpl::GetWebContents() {
1044 return this;
1045}
1046
[email protected]54944cde2012-12-09 09:24:591047void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211048 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361049 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211050 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431051 should_normally_be_visible_ = !params.initially_hidden;
1052
[email protected]fa944cb82013-11-15 17:51:211053 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041054 params.browser_context, params.site_instance, params.routing_id,
1055 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191056
[email protected]8ff00d72012-10-23 19:12:211057 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191058 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271059 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191060 CHECK(render_view_host_delegate_view_);
1061 } else {
[email protected]f8497342013-02-05 22:15:021062 WebContentsViewDelegate* delegate =
1063 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1064
[email protected]59383c782013-04-17 16:43:271065 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381066 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1067 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021068
[email protected]b5a40842012-11-28 15:26:111069 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381070 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431071 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111072 render_view_host_delegate_view_ = rv;
1073 view_.reset(rv);
1074 } else {
[email protected]f8497342013-02-05 22:15:021075 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111076 view_.reset(CreateWebContentsView(
1077 this, delegate, &render_view_host_delegate_view_));
1078 }
[email protected]d1198fd2012-08-13 22:50:191079 CHECK(render_view_host_delegate_view_);
1080 }
1081 CHECK(view_.get());
1082
[email protected]ed245db2012-12-18 08:00:451083 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591084 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191085
1086 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101087 if (opener_)
1088 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191089
1090 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211091 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1092 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441093#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191094 java_bridge_dispatcher_host_manager_.reset(
1095 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101096 date_time_chooser_.reset(new DateTimeChooserAndroid());
1097#endif
[email protected]d1198fd2012-08-13 22:50:191098}
1099
[email protected]7fff43e2013-05-21 20:21:101100void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1101 RemoveDestructionObserver(web_contents);
1102
[email protected]14392a52012-05-02 20:28:441103 // Clear the opener if it has been closed.
1104 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441105 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511106 return;
[email protected]14392a52012-05-02 20:28:441107 }
[email protected]ceee8cd2013-03-08 04:59:511108 // Clear a pending contents that has been closed before being shown.
1109 for (PendingContents::iterator iter = pending_contents_.begin();
1110 iter != pending_contents_.end();
1111 ++iter) {
1112 if (iter->second != web_contents)
1113 continue;
1114 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511115 return;
1116 }
1117 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441118}
1119
[email protected]7fff43e2013-05-21 20:21:101120void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1121 if (!ContainsKey(destruction_observers_, web_contents)) {
1122 destruction_observers_[web_contents] =
1123 new DestructionObserver(this, web_contents);
1124 }
1125}
1126
1127void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1128 DestructionObservers::iterator iter =
1129 destruction_observers_.find(web_contents);
1130 if (iter != destruction_observers_.end()) {
1131 delete destruction_observers_[web_contents];
1132 destruction_observers_.erase(iter);
1133 }
1134}
1135
[email protected]b172aee2012-04-10 17:05:261136void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311137 observers_.AddObserver(observer);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311141 observers_.RemoveObserver(observer);
1142}
1143
[email protected]b172aee2012-04-10 17:05:261144void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341145 if (delegate_)
1146 delegate_->ActivateContents(this);
1147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121150 if (delegate_)
1151 delegate_->DeactivateContents(this);
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481155 if (delegate_)
1156 delegate_->LostCapture();
1157}
1158
[email protected]b24b68a2012-09-24 21:57:261159void WebContentsImpl::RenderWidgetDeleted(
1160 RenderWidgetHostImpl* render_widget_host) {
1161 if (is_being_destroyed_) {
1162 // |created_widgets_| might have been destroyed.
1163 return;
1164 }
1165
1166 std::set<RenderWidgetHostImpl*>::iterator iter =
1167 created_widgets_.find(render_widget_host);
1168 if (iter != created_widgets_.end())
1169 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541170
1171 if (render_widget_host &&
1172 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491173 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1174 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541175 FOR_EACH_OBSERVER(WebContentsObserver,
1176 observers_,
1177 DidDestroyFullscreenWidget(
1178 fullscreen_widget_routing_id_));
1179 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1180 }
[email protected]b24b68a2012-09-24 21:57:261181}
1182
[email protected]b172aee2012-04-10 17:05:261183bool WebContentsImpl::PreHandleKeyboardEvent(
1184 const NativeWebKeyboardEvent& event,
1185 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481186 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131187 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481188}
1189
[email protected]b172aee2012-04-10 17:05:261190void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061191 if (browser_plugin_embedder_ &&
1192 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1193 return;
1194 }
1195
[email protected]63954792011-07-11 04:17:481196 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131197 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481198}
1199
[email protected]fb3f066e2013-02-12 19:12:521200bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461201 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191202#if !defined(OS_MACOSX)
1203 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1204 // isn't done for two reasons:
1205 // -the OS already has a gesture to do this through pinch-zoom
1206 // -if a user starts an inertial scroll, let's go, and presses control
1207 // (i.e. control+tab) then the OS's buffered scroll events will come in
1208 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521209 if (delegate_ &&
1210 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461211 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521212 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1213 return true;
1214 }
[email protected]bccc4472013-04-18 16:37:191215#endif
[email protected]fb3f066e2013-02-12 19:12:521216
1217 return false;
1218}
1219
[email protected]c73a2282013-04-29 21:10:411220#if defined(OS_WIN) && defined(USE_AURA)
1221gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1222 return accessible_parent_;
1223}
1224#endif
1225
[email protected]b172aee2012-04-10 17:05:261226void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431227 if (delegate_)
1228 delegate_->HandleMouseDown();
1229}
1230
[email protected]b172aee2012-04-10 17:05:261231void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481232 if (delegate_)
1233 delegate_->HandleMouseUp();
1234}
1235
[email protected]590a634e2012-07-19 16:38:231236void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481237 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231238 delegate_->HandlePointerActivate();
1239}
1240
1241void WebContentsImpl::HandleGestureBegin() {
1242 if (delegate_)
1243 delegate_->HandleGestureBegin();
1244}
1245
1246void WebContentsImpl::HandleGestureEnd() {
1247 if (delegate_)
1248 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481249}
1250
[email protected]b172aee2012-04-10 17:05:261251void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491252 // This method is being called to enter or leave renderer-initiated fullscreen
1253 // mode. Either way, make sure any existing fullscreen widget is shut down
1254 // first.
1255 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1256 if (widget_view)
1257 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1258
[email protected]8a5e0ca2011-08-25 06:30:471259 if (delegate_)
1260 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1261}
1262
[email protected]b172aee2012-04-10 17:05:261263bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381264 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121265}
1266
[email protected]a9c81f02012-06-01 00:15:441267void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1268 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371269 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441270 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371271 } else {
1272 GotResponseToLockMouseRequest(false);
1273 }
1274}
1275
[email protected]b172aee2012-04-10 17:05:261276void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371277 if (delegate_)
1278 delegate_->LostMouseLock();
1279}
1280
[email protected]bafe6cd2012-05-23 23:09:501281void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201282 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501283 int route_id,
[email protected]227692c52013-05-31 22:43:041284 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131285 const ViewHostMsg_CreateWindow_Params& params,
1286 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501287 // We usually create the new window in the same BrowsingInstance (group of
1288 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551289 // if the opener is being suppressed (in a non-guest), we create a new
1290 // SiteInstance in its own BrowsingInstance.
1291 bool is_guest = GetRenderProcessHost()->IsGuest();
1292
[email protected]04cbd3d2013-12-04 04:58:201293 // If the opener is to be suppressed, the new window can be in any process.
1294 // Since routing ids are process specific, we must not have one passed in
1295 // as argument here.
1296 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1297
[email protected]bafe6cd2012-05-23 23:09:501298 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551299 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571300 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501301 GetSiteInstance();
1302
[email protected]04cbd3d2013-12-04 04:58:201303 // A message to create a new window can only come from the active process for
1304 // this WebContentsImpl instance. If any other process sends the request,
1305 // it is invalid and the process must be terminated.
1306 if (GetRenderProcessHost()->GetID() != render_process_id) {
1307 base::ProcessHandle process_handle =
1308 RenderProcessHost::FromID(render_process_id)->GetHandle();
1309 if (process_handle != base::kNullProcessHandle) {
1310 RecordAction(
1311 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1312 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1313 }
1314 return;
1315 }
1316
[email protected]d1198fd2012-08-13 22:50:191317 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341318 //
1319 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301320 const std::string& partition_id =
1321 GetContentClient()->browser()->
1322 GetStoragePartitionIdForSite(GetBrowserContext(),
1323 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461324 StoragePartition* partition = BrowserContext::GetStoragePartition(
1325 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411326 DOMStorageContextWrapper* dom_storage_context =
1327 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191328 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1329 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1330 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371331
1332 if (delegate_ &&
1333 !delegate_->ShouldCreateWebContents(this,
1334 route_id,
1335 params.window_container_type,
1336 params.frame_name,
1337 params.target_url,
1338 partition_id,
1339 session_storage_namespace)) {
1340 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1341 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1342 main_frame_route_id);
1343 return;
1344 }
1345
1346 // Create the new web contents. This will automatically create the new
1347 // WebContentsView. In the future, we may want to create the view separately.
1348 WebContentsImpl* new_contents =
1349 new WebContentsImpl(GetBrowserContext(),
1350 params.opener_suppressed ? NULL : this);
1351
[email protected]d1198fd2012-08-13 22:50:191352 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301353 partition_id,
[email protected]d1198fd2012-08-13 22:50:191354 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461355 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591356 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041357 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551358 if (!is_guest) {
1359 create_params.context = view_->GetNativeView();
1360 create_params.initial_size = view_->GetContainerSize();
1361 } else {
1362 // This makes |new_contents| act as a guest.
1363 // For more info, see comment above class BrowserPluginGuest.
1364 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1365 WebContentsImpl* new_contents_impl =
1366 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461367 BrowserPluginGuest::CreateWithOpener(instance_id,
1368 new_contents_impl->opener() != NULL,
1369 new_contents_impl,
1370 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551371 }
[email protected]1ac10dca2013-08-20 20:47:041372 if (params.disposition == NEW_BACKGROUND_TAB)
1373 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591374 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191375
[email protected]c4538072013-03-18 02:17:551376 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341377 // will be shown immediately).
1378 if (!params.opener_suppressed) {
1379 if (!is_guest) {
1380 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501381
[email protected]d70bea92013-04-05 04:23:341382 // TODO(brettw): It seems bogus that we have to call this function on the
1383 // newly created object and give it one of its own member variables.
1384 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1385 }
[email protected]bafe6cd2012-05-23 23:09:501386 // Save the created window associated with the route so we can show it
1387 // later.
1388 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1389 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101390 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501391 }
1392
1393 if (delegate_) {
1394 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131395 this, params.opener_frame_id, params.frame_name,
1396 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501397 }
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]e7f2e7c2013-07-15 09:41:301415 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001416 new_contents->OpenURL(open_params);
1417 }
[email protected]bafe6cd2012-05-23 23:09:501418 }
1419}
1420
[email protected]a8504022013-12-04 20:23:511421void WebContentsImpl::CreateNewWidget(int render_process_id,
1422 int route_id,
[email protected]180ef242013-11-07 06:50:461423 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511424 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501425}
1426
[email protected]a8504022013-12-04 20:23:511427void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1428 int route_id) {
1429 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501430}
1431
[email protected]a8504022013-12-04 20:23:511432void WebContentsImpl::CreateNewWidget(int render_process_id,
1433 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501434 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461435 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211436 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511437 // A message to create a new widget can only come from the active process for
1438 // this WebContentsImpl instance. If any other process sends the request,
1439 // it is invalid and the process must be terminated.
1440 if (process->GetID() != render_process_id) {
1441 base::ProcessHandle process_handle =
1442 RenderProcessHost::FromID(render_process_id)->GetHandle();
1443 if (process_handle != base::kNullProcessHandle) {
1444 RecordAction(
1445 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1446 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1447 }
1448 return;
1449 }
1450
[email protected]bafe6cd2012-05-23 23:09:501451 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041452 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261453 created_widgets_.insert(widget_host);
1454
[email protected]83918ec2013-01-10 15:37:191455 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1456 view_->CreateViewForPopupWidget(widget_host));
1457 if (!widget_view)
1458 return;
[email protected]bafe6cd2012-05-23 23:09:501459 if (!is_fullscreen) {
1460 // Popups should not get activated.
1461 widget_view->SetPopupType(popup_type);
1462 }
1463 // Save the created widget associated with the route so we can show it later.
1464 pending_widget_views_[route_id] = widget_view;
1465
1466#if defined(OS_MACOSX)
1467 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1468 // to allow it to survive the trip without being hosted.
1469 base::mac::NSObjectRetain(widget_view->GetNativeView());
1470#endif
1471}
1472
1473void WebContentsImpl::ShowCreatedWindow(int route_id,
1474 WindowOpenDisposition disposition,
1475 const gfx::Rect& initial_pos,
1476 bool user_gesture) {
1477 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001478 if (contents) {
1479 WebContentsDelegate* delegate = GetDelegate();
1480 if (delegate) {
1481 delegate->AddNewContents(
1482 this, contents, disposition, initial_pos, user_gesture, NULL);
1483 }
1484 }
[email protected]bafe6cd2012-05-23 23:09:501485}
1486
1487void WebContentsImpl::ShowCreatedWidget(int route_id,
1488 const gfx::Rect& initial_pos) {
1489 ShowCreatedWidget(route_id, false, initial_pos);
1490}
1491
1492void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1493 ShowCreatedWidget(route_id, true, gfx::Rect());
1494}
1495
1496void WebContentsImpl::ShowCreatedWidget(int route_id,
1497 bool is_fullscreen,
1498 const gfx::Rect& initial_pos) {
1499 if (delegate_)
1500 delegate_->RenderWidgetShowing();
1501
1502 RenderWidgetHostViewPort* widget_host_view =
1503 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1504 if (!widget_host_view)
1505 return;
[email protected]4aebbca2013-09-17 22:26:491506 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311507 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1508 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491509 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1510 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1511 delegate_->ToggleFullscreenModeForTab(this, true);
1512 } else {
1513 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491514 }
[email protected]4aebbca2013-09-17 22:26:491515 FOR_EACH_OBSERVER(WebContentsObserver,
1516 observers_,
1517 DidShowFullscreenWidget(route_id));
1518 if (!widget_host_view->HasFocus())
1519 widget_host_view->Focus();
1520 } else {
[email protected]f8497342013-02-05 22:15:021521 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491522 }
[email protected]89054502012-06-03 10:29:241523
1524 RenderWidgetHostImpl* render_widget_host_impl =
1525 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1526 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311527 // Only allow privileged mouse lock for fullscreen render widget, which is
1528 // used to implement Pepper Flash fullscreen.
1529 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501530
1531#if defined(OS_MACOSX)
1532 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1533 // properly embedded (or purposefully ignored) we can release the retain we
1534 // took in CreateNewWidget().
1535 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1536#endif
1537}
1538
1539WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1540 PendingContents::iterator iter = pending_contents_.find(route_id);
1541
1542 // Certain systems can block the creation of new windows. If we didn't succeed
1543 // in creating one, just return NULL.
1544 if (iter == pending_contents_.end()) {
1545 return NULL;
1546 }
1547
1548 WebContentsImpl* new_contents = iter->second;
1549 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101550 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501551
[email protected]d70bea92013-04-05 04:23:341552 // Don't initialize the guest WebContents immediately.
1553 if (new_contents->GetRenderProcessHost()->IsGuest())
1554 return new_contents;
1555
[email protected]bafe6cd2012-05-23 23:09:501556 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1557 !new_contents->GetRenderViewHost()->GetView())
1558 return NULL;
1559
1560 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1561 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1562 return new_contents;
1563}
1564
1565RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1566 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1567 if (iter == pending_widget_views_.end()) {
1568 DCHECK(false);
1569 return NULL;
1570 }
1571
1572 RenderWidgetHostView* widget_host_view = iter->second;
1573 pending_widget_views_.erase(route_id);
1574
1575 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1576 if (!widget_host->GetProcess()->HasConnection()) {
1577 // The view has gone away or the renderer crashed. Nothing to do.
1578 return NULL;
1579 }
1580
1581 return widget_host_view;
1582}
1583
[email protected]f56c7872013-06-18 12:31:571584void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501585 // Allow WebContentsDelegates to handle the context menu operation first.
1586 if (delegate_ && delegate_->HandleContextMenu(params))
1587 return;
1588
[email protected]f56c7872013-06-18 12:31:571589 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501590}
1591
[email protected]f13b4202012-06-12 23:53:231592void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091593 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211594 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231595 if (delegate_)
1596 delegate_->RequestMediaAccessPermission(this, request, callback);
1597 else
[email protected]b5f76742013-04-29 15:05:591598 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231599}
1600
[email protected]cc9200432013-07-23 23:02:401601SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1602 SiteInstance* instance) {
1603 return controller_.GetSessionStorageNamespace(instance);
1604}
1605
[email protected]9b159a52013-10-03 17:24:551606FrameTree* WebContentsImpl::GetFrameTree() {
1607 return &frame_tree_;
1608}
1609
[email protected]edc3af82013-12-12 21:24:071610void WebContentsImpl::OnShowValidationMessage(
1611 const gfx::Rect& anchor_in_root_view,
1612 const string16& main_text,
1613 const string16& sub_text) {
1614 if (delegate_)
1615 delegate_->ShowValidationMessage(
1616 this, anchor_in_root_view, main_text, sub_text);
1617}
1618
1619void WebContentsImpl::OnHideValidationMessage() {
1620 if (delegate_)
1621 delegate_->HideValidationMessage(this);
1622}
1623
1624void WebContentsImpl::OnMoveValidationMessage(
1625 const gfx::Rect& anchor_in_root_view) {
1626 if (delegate_)
1627 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1628}
1629
[email protected]32deec62013-05-15 23:55:041630void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1631 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441632 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041633}
1634
[email protected]b172aee2012-04-10 17:05:261635void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231636 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331637 if (delegate_)
1638 delegate_->UpdatePreferredSize(this, pref_size);
1639}
1640
[email protected]b172aee2012-04-10 17:05:261641void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341642 if (delegate_)
1643 delegate_->ResizeDueToAutoResize(this, new_size);
1644}
1645
[email protected]b172aee2012-04-10 17:05:261646WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201647 if (!delegate_)
1648 return NULL;
[email protected]00c37fc2011-08-02 00:22:501649
[email protected]e5d549d2011-12-28 01:29:201650 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201651 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341652}
1653
[email protected]6b618e62012-08-16 12:59:181654bool WebContentsImpl::Send(IPC::Message* message) {
1655 if (!GetRenderViewHost()) {
1656 delete message;
1657 return false;
1658 }
1659
1660 return GetRenderViewHost()->Send(message);
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501664 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251665 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231666 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251667 reload_type);
[email protected]876bc832010-09-07 16:29:541668}
[email protected]96d185d2009-04-24 03:28:541669
[email protected]ba45bfd2012-05-22 21:51:441670void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211671 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441672 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1673 RenderViewForInterstitialPageCreated(render_view_host));
1674}
1675
[email protected]20ca0382013-02-28 19:50:071676void WebContentsImpl::AttachInterstitialPage(
1677 InterstitialPageImpl* interstitial_page) {
1678 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211679 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291680
1681 // Cancel any visible dialogs so that they don't interfere with the
1682 // interstitial.
1683 if (dialog_manager_)
1684 dialog_manager_->CancelActiveAndPendingDialogs(this);
1685
[email protected]20ca0382013-02-28 19:50:071686 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1687 DidAttachInterstitialPage());
1688}
1689
1690void WebContentsImpl::DetachInterstitialPage() {
1691 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211692 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071693 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1694 DidDetachInterstitialPage());
1695}
1696
[email protected]b172aee2012-04-10 17:05:261697bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231698 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501699 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031700 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1701
[email protected]19e81142011-10-03 16:19:401702 // The renderer will reject IPC messages with URLs longer than
1703 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431704 if (entry.GetURL().spec().size() > kMaxURLChars) {
1705 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1706 << " characters.";
[email protected]19e81142011-10-03 16:19:401707 return false;
[email protected]3adab1c2013-09-09 21:23:431708 }
[email protected]19e81142011-10-03 16:19:401709
[email protected]c80297782013-11-21 07:10:161710 // TODO(creis): Use entry->frame_tree_node_id() to pick which
[email protected]b0936d22013-11-28 06:47:361711 // RenderFrameHostManager to use.
[email protected]9f76c1e2012-03-05 15:15:581712 RenderViewHostImpl* dest_render_view_host =
[email protected]fa944cb82013-11-15 17:51:211713 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401714 if (!dest_render_view_host)
1715 return false; // Unable to create the desired render view host.
1716
[email protected]80a8fad2011-01-29 04:02:381717 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071718 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581719 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271720 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501721 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031722 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1723 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211724 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231725 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271726 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211727 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231728 CHECK(0);
1729 }
[email protected]54ec6472010-04-09 19:39:581730
[email protected]7bb761892012-07-20 09:32:471731 // Notify observers that we will navigate in this RV.
1732 FOR_EACH_OBSERVER(WebContentsObserver,
1733 observers_,
1734 AboutToNavigateRenderView(dest_render_view_host));
1735
[email protected]96d185d2009-04-24 03:28:541736 // Used for page load time metrics.
1737 current_load_start_ = base::TimeTicks::Now();
1738
1739 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341740 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271741 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471742 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341743 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541744
[email protected]36fc0392011-12-25 03:59:511745 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541746 // HACK!! This code suppresses javascript: URLs from being added to
1747 // session history, which is what we want to do for javascript: URLs that
1748 // do not generate content. What we really need is a message from the
1749 // renderer telling us that a new page was not created. The same message
1750 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351751 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541752 return false;
1753 }
1754
[email protected]3c9e1872010-11-18 16:17:491755 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391756 FOR_EACH_OBSERVER(
1757 WebContentsObserver,
1758 observers_,
1759 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541760
[email protected]09b29342011-06-24 19:18:481761 if (delegate_)
1762 delegate_->DidNavigateToPendingEntry(this);
1763
[email protected]d5f942ba2008-09-26 19:30:341764 return true;
1765}
1766
[email protected]b172aee2012-04-10 17:05:261767void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331768 const SiteInstance* site_instance,
1769 int history_length,
1770 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411771 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1772 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211773 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191774 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141775 return;
[email protected]9e1ad4b2011-08-14 16:49:191776 }
[email protected]9f76c1e2012-03-05 15:15:581777 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191778 if (!rvh) {
1779 NOTREACHED();
1780 return;
1781 }
[email protected]9f76c1e2012-03-05 15:15:581782 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191783 NOTREACHED();
1784 return;
1785 }
[email protected]6b618e62012-08-16 12:59:181786 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1787 history_length,
1788 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141789}
1790
[email protected]b172aee2012-04-10 17:05:261791void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271792 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211793 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541794 return;
1795 }
[email protected]9f76c1e2012-03-05 15:15:581796 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541797}
1798
[email protected]b172aee2012-04-10 17:05:261799bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211800 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541801}
1802
[email protected]b172aee2012-04-10 17:05:261803InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211804 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221805}
1806
[email protected]b172aee2012-04-10 17:05:261807bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161808 // WebKit creates Document object when MIME type is application/xhtml+xml,
1809 // so we also support this MIME type.
1810 return contents_mime_type_ == "text/html" ||
1811 contents_mime_type_ == "text/xml" ||
1812 contents_mime_type_ == "application/xhtml+xml" ||
1813 contents_mime_type_ == "text/plain" ||
1814 contents_mime_type_ == "text/css" ||
1815 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1816}
1817
[email protected]b172aee2012-04-10 17:05:261818void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591819 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161820 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551821 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011822 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141823 return;
[email protected]c7dd2f62011-07-18 15:57:591824 }
1825
1826 Stop();
1827
1828 // Create the save package and possibly prompt the user for the name to save
1829 // the page as. The user prompt is an asynchronous operation that runs on
1830 // another thread.
1831 save_package_ = new SavePackage(this);
1832 save_package_->GetSaveInfo();
1833}
1834
1835// Used in automated testing to bypass prompting the user for file names.
1836// Instead, the names and paths are hard coded rather than running them through
1837// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341838bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1839 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211840 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591841 // Stop the page from navigating.
1842 Stop();
1843
1844 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211845 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591846}
1847
[email protected]3c71576ce2013-07-23 02:00:011848void WebContentsImpl::SaveFrame(const GURL& url,
1849 const Referrer& referrer) {
1850 if (!GetURL().is_valid())
1851 return;
1852 bool is_main_frame = (url == GetURL());
1853
1854 DownloadManager* dlm =
1855 BrowserContext::GetDownloadManager(GetBrowserContext());
1856 if (!dlm)
1857 return;
1858 int64 post_id = -1;
1859 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271860 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011861 if (entry)
1862 post_id = entry->GetPostID();
1863 }
1864 scoped_ptr<DownloadUrlParameters> params(
1865 DownloadUrlParameters::FromWebContents(this, url));
1866 params->set_referrer(referrer);
1867 params->set_post_id(post_id);
1868 params->set_prefer_cache(true);
1869 if (post_id >= 0)
1870 params->set_method("POST");
1871 params->set_prompt(true);
1872 dlm->DownloadUrl(params.Pass());
1873}
1874
[email protected]b172aee2012-04-10 17:05:261875void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341876 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481877 const base::Callback<void(int64)>& callback) {
1878 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121879}
1880
[email protected]6286a372013-10-09 04:03:271881// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261882bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271883 NavigationEntryImpl* visible_entry =
1884 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1885 return (visible_entry != NULL &&
1886 visible_entry->site_instance() == GetSiteInstance() &&
1887 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321888}
1889
[email protected]b172aee2012-04-10 17:05:261890const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271891 return contents_mime_type_;
1892}
1893
[email protected]b172aee2012-04-10 17:05:261894bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271895 return notify_disconnection_;
1896}
1897
[email protected]b172aee2012-04-10 17:05:261898void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311899 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181900 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161901}
1902
[email protected]b172aee2012-04-10 17:05:261903void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311904 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181905 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161906}
1907
[email protected]8ff00d72012-10-23 19:12:211908RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271909 return &renderer_preferences_;
1910}
1911
[email protected]e35ccd52012-05-23 16:22:471912void WebContentsImpl::Close() {
1913 Close(GetRenderViewHost());
1914}
1915
[email protected]cf200a562013-05-03 16:24:291916void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461917 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291918 if (browser_plugin_embedder_.get())
1919 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1920 screen_x, screen_y, operation);
1921 if (GetRenderViewHost())
1922 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1923 screen_x, screen_y, operation);
1924}
1925
1926void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1927 int screen_x, int screen_y) {
1928 if (browser_plugin_embedder_.get())
1929 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1930 screen_x, screen_y);
1931 if (GetRenderViewHost())
1932 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1933 screen_x, screen_y);
1934}
1935
[email protected]b172aee2012-04-10 17:05:261936void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521937 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581938 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511939 if (delegate_)
1940 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291941 if (browser_plugin_embedder_.get())
1942 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341943}
1944
[email protected]e35ccd52012-05-23 16:22:471945void WebContentsImpl::UserGestureDone() {
1946 OnUserGesture();
1947}
1948
[email protected]b172aee2012-04-10 17:05:261949void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271950 closed_by_user_gesture_ = value;
1951}
1952
[email protected]b172aee2012-04-10 17:05:261953bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271954 return closed_by_user_gesture_;
1955}
1956
[email protected]b172aee2012-04-10 17:05:261957double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051958 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561959 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251960 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171961 return 0;
[email protected]b75b8292010-10-01 07:28:251962
1963 double zoom_level;
1964 if (temporary_zoom_settings_) {
1965 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581966 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251967 } else {
[email protected]2ae88d12011-10-14 09:11:191968 GURL url;
[email protected]6286a372013-10-09 04:03:271969 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191970 // Since zoom map is updated using rewritten URL, use rewritten URL
1971 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271972 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021973 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1974 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251975 }
[email protected]d0b8d092010-10-25 04:05:171976 return zoom_level;
1977}
[email protected]b75b8292010-10-01 07:28:251978
[email protected]b172aee2012-04-10 17:05:261979int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591980 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171981 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011982 // Calculate the zoom percent from the factor. Round up to the nearest whole
1983 // number.
[email protected]b75b8292010-10-01 07:28:251984 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491985 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251986 *enable_decrement = percent > minimum_zoom_percent_;
1987 *enable_increment = percent < maximum_zoom_percent_;
1988 return percent;
1989}
1990
[email protected]b172aee2012-04-10 17:05:261991void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501992 if (!delegate_)
1993 return;
1994
[email protected]6286a372013-10-09 04:03:271995 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1996 if (!entry)
[email protected]1788e772010-12-15 16:40:501997 return;
1998
[email protected]6286a372013-10-09 04:03:271999 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122000}
2001
[email protected]b172aee2012-04-10 17:05:262002void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042003 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272004 if (!delegate_)
2005 return;
2006
[email protected]691aa2f2013-05-28 22:52:042007 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272008}
2009
[email protected]b172aee2012-04-10 17:05:262010int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272011 return minimum_zoom_percent_;
2012}
2013
[email protected]b172aee2012-04-10 17:05:262014int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272015 return maximum_zoom_percent_;
2016}
2017
[email protected]b172aee2012-04-10 17:05:262018gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:232019 return preferred_size_;
2020}
2021
[email protected]b172aee2012-04-10 17:05:262022bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272023 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582024 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272025}
2026
[email protected]b172aee2012-04-10 17:05:262027bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442028 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502029}
2030
[email protected]cb805452013-05-22 15:16:212031void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182032 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212033 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202034}
2035
[email protected]cb805452013-05-22 15:16:212036void WebContentsImpl::DidEndColorChooser() {
2037 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2038 color_chooser_identifier_));
2039 color_chooser_.reset();
2040 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202041}
2042
[email protected]41225fe2013-03-29 05:32:022043int WebContentsImpl::DownloadImage(const GURL& url,
2044 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302045 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022046 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392047 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302048 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022049 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392050 return id;
2051}
2052
[email protected]b172aee2012-04-10 17:05:262053bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272054 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202055 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332056 return true;
2057 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272058}
2059
[email protected]b172aee2012-04-10 17:05:262060void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272061 if (delegate_)
2062 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212063}
2064
[email protected]52913802013-12-10 05:52:182065void WebContentsImpl::DidStartProvisionalLoad(
2066 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572067 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132068 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572069 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182070 const GURL& validated_url,
2071 bool is_error_page,
2072 bool is_iframe_srcdoc) {
2073 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572074 DidChangeLoadProgress(0);
2075
[email protected]0d60f0192011-04-14 12:40:102076 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252077 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132078 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2079 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182080 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542081
2082 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182083 FOR_EACH_OBSERVER(
2084 WebContentsObserver,
2085 observers_,
2086 ProvisionalChangeToMainFrameUrl(validated_url,
2087 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542088 }
2089}
2090
[email protected]52913802013-12-10 05:52:182091void WebContentsImpl::NotifyChangedNavigationState(
2092 InvalidateTypes changed_flags) {
2093 NotifyNavigationStateChanged(changed_flags);
2094}
2095
[email protected]400992b2012-06-14 00:03:542096void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212097 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542098 int32 page_id,
[email protected]400992b2012-06-14 00:03:542099 const GURL& source_url,
2100 const GURL& target_url) {
2101 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132102 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2103 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542104 GURL validated_source_url(source_url);
2105 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212106 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542107 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082108 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2109 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542110 NavigationEntry* entry;
2111 if (page_id == -1) {
2112 entry = controller_.GetPendingEntry();
2113 } else {
2114 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2115 page_id);
2116 }
2117 if (!entry || entry->GetURL() != validated_source_url)
2118 return;
2119
2120 // Notify observers about the provisional change in the main frame URL.
2121 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2122 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542123 render_view_host));
[email protected]724159a2010-12-30 01:11:182124}
2125
[email protected]54047eb52012-05-08 21:45:572126void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212127 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582128 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2129 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2130 << ", error_code: " << params.error_code
2131 << ", error_description: " << params.error_description
2132 << ", is_main_frame: " << params.is_main_frame
2133 << ", showing_repost_interstitial: " <<
2134 params.showing_repost_interstitial
2135 << ", frame_id: " << params.frame_id;
2136 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212137 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572138 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082139 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182140
[email protected]d7b175e2011-10-11 15:31:582141 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182142 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2143 // This means that the interstitial won't be torn down properly, which is
2144 // bad. But if we have an interstitial, go back to another tab type, and
2145 // then load the same interstitial again, we could end up getting the first
2146 // interstitial's "failed" message (as a result of the cancel) when we're on
2147 // the second one.
2148 //
2149 // We can't tell this apart, so we think we're tearing down the current page
2150 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362151 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182152 // out because of this problem.
2153 //
2154 // http://code.google.com/p/chromium/issues/detail?id=2855
2155 // Because this will not tear down the interstitial properly, if "back" is
2156 // back to another tab type, the interstitial will still be somewhat alive
2157 // in the previous tab type. If you navigate somewhere that activates the
2158 // tab with the interstitial again, you'll see a flash before the new load
2159 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272160 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182161 LOG(WARNING) << "Discarding message during interstitial.";
2162 return;
2163 }
2164
[email protected]fa944cb82013-11-15 17:51:212165 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182166 }
2167
[email protected]b12eb222013-09-10 00:11:482168 // Do not usually clear the pending entry if one exists, so that the user's
2169 // typed URL is not lost when a navigation fails or is aborted. However, in
2170 // cases that we don't show the pending entry (e.g., renderer-initiated
2171 // navigations in an existing tab), we don't keep it around. That prevents
2172 // spoofs on in-page navigations that don't go through
2173 // DidStartProvisionalLoadForFrame.
2174 // In general, we allow the view to clear the pending entry and typed URL if
2175 // the user requests (e.g., hitting Escape with focus in the address bar).
2176 // Note: don't touch the transient entry, since an interstitial may exist.
2177 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2178 controller_.DiscardPendingEntry();
2179
[email protected]d8c660432011-12-22 20:51:252180 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582181 observers_,
2182 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442183 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582184 params.is_main_frame,
2185 validated_url,
2186 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462187 params.error_description,
2188 render_view_host));
[email protected]724159a2010-12-30 01:11:182189}
2190
[email protected]b172aee2012-04-10 17:05:262191void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182192 const GURL& url,
[email protected]70435962011-08-02 20:13:282193 const std::string& security_info,
2194 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182195 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282196 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192197 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182198 cache.Increment();
2199
2200 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082201 int cert_id = 0;
2202 net::CertStatus cert_status = 0;
2203 int security_bits = -1;
2204 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122205 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212206 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122207 &security_bits, &connection_status,
2208 &signed_certificate_timestamp_ids);
2209 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212210 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002211 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2212 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182213
[email protected]b0f724c2013-09-05 04:21:132214 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2215
2216 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2217 DidLoadResourceFromMemoryCache(details));
2218
[email protected]8bfc8272013-09-09 20:10:532219 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2220 scoped_refptr<net::URLRequestContextGetter> request_context(
2221 resource_type == ResourceType::MEDIA ?
2222 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2223 GetRenderProcessHost()->GetID()) :
2224 GetBrowserContext()->GetRequestContextForRenderProcess(
2225 GetRenderProcessHost()->GetID()));
2226 BrowserThread::PostTask(
2227 BrowserThread::IO,
2228 FROM_HERE,
2229 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2230 }
[email protected]724159a2010-12-30 01:11:182231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212234 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182235 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192236 SSLManager::NotifySSLInternalStateChanged(
2237 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182238}
2239
[email protected]b172aee2012-04-10 17:05:262240void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022241 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582242 LOG(WARNING) << security_origin << " ran insecure content from "
2243 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212244 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412245 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212246 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182247 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412248 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192249 SSLManager::NotifySSLInternalStateChanged(
2250 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442254 FOR_EACH_OBSERVER(
2255 WebContentsObserver, observers_,
2256 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182257}
2258
[email protected]b172aee2012-04-10 17:05:262259void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312260 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062261 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312262 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062263 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442264 RenderProcessHost* render_process_host =
2265 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062266 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252267 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472268 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442269 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnDidFailLoadWithError(
2273 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062274 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262275 bool is_main_frame,
2276 int error_code,
[email protected]fcf75d42013-12-03 20:11:262277 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062278 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442279 RenderProcessHost* render_process_host =
2280 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062281 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252282 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312283 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472284 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442285 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182286}
2287
[email protected]b172aee2012-04-10 17:05:262288void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262289 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232290 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252291 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262292 if (!entry)
2293 return;
2294 // Note that we don't call NavigationController::GotToOffset() as we don't
2295 // want to create a pending navigation entry (it might end up lingering
2296 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252297 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212298 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512299 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212300 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472301 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572302
2303 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2304 // it in now that we know. This allows us to find the entry when it commits.
2305 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232306 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332307 entry->set_site_instance(
2308 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572309 }
[email protected]216813952011-05-19 22:21:262310 }
2311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2314 int maximum_percent,
2315 bool remember) {
[email protected]216813952011-05-19 22:21:262316 minimum_zoom_percent_ = minimum_percent;
2317 maximum_zoom_percent_ = maximum_percent;
2318 temporary_zoom_settings_ = !remember;
2319}
2320
[email protected]b172aee2012-04-10 17:05:262321void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342322 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432323 if (!delegate_)
2324 return;
2325
[email protected]b9535422012-02-09 01:47:592326 ChildProcessSecurityPolicyImpl* policy =
2327 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222328 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592329 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432333 if (delegate_)
2334 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202335}
2336
[email protected]b172aee2012-04-10 17:05:262337void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2338 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262339 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362340 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432341 if (!delegate_)
2342 return;
2343
[email protected]b9535422012-02-09 01:47:592344 ChildProcessSecurityPolicyImpl* policy =
2345 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322346 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592347 return;
[email protected]8f810632013-06-06 22:33:322348
[email protected]3a3b75a2012-06-01 08:38:362349 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202350}
2351
[email protected]b172aee2012-04-10 17:05:262352void WebContentsImpl::OnFindReply(int request_id,
2353 int number_of_matches,
2354 const gfx::Rect& selection_rect,
2355 int active_match_ordinal,
2356 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432357 if (delegate_) {
2358 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2359 active_match_ordinal, final_update);
2360 }
[email protected]b888919c2011-09-02 00:32:162361}
2362
[email protected]59363fc92012-09-05 03:46:312363#if defined(OS_ANDROID)
2364void WebContentsImpl::OnFindMatchRectsReply(
2365 int version,
2366 const std::vector<gfx::RectF>& rects,
2367 const gfx::RectF& active_rect) {
2368 if (delegate_)
2369 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2370}
[email protected]583418cc2013-01-17 14:01:102371
[email protected]1ff427972013-02-07 21:14:072372void WebContentsImpl::OnOpenDateTimeDialog(
2373 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092374 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2375 GetRenderViewHost(),
2376 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132377 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092378 value.minimum,
2379 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172380 value.step,
2381 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102382}
2383
[email protected]a794f3a2013-10-30 17:00:322384void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2385 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442386 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322387}
2388
[email protected]59363fc92012-09-05 03:46:312389#endif
2390
[email protected]f114fa42013-12-06 17:06:442391void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2392 const base::FilePath& path,
2393 bool is_hung) {
2394 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2395
2396 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2397 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2398}
2399
2400void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422401 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442402 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422403 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452404}
2405
[email protected]b172aee2012-04-10 17:05:262406void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2407 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102408 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252409 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102410 AppCacheAccessed(manifest_url, blocked_by_policy));
2411}
2412
[email protected]8bc5ff02013-11-29 06:34:032413void WebContentsImpl::OnOpenColorChooser(
2414 int color_chooser_id,
2415 SkColor color,
2416 const std::vector<ColorSuggestion>& suggestions) {
2417 ColorChooser* new_color_chooser =
2418 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212419 if (color_chooser_ == new_color_chooser)
2420 return;
2421 color_chooser_.reset(new_color_chooser);
2422 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202423}
2424
[email protected]b172aee2012-04-10 17:05:262425void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202426 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212427 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202428 color_chooser_->End();
2429}
2430
[email protected]b172aee2012-04-10 17:05:262431void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322432 SkColor color) {
[email protected]da8543762012-03-20 08:52:202433 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212434 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202435 color_chooser_->SetSelectedColor(color);
2436}
2437
[email protected]d0759f492012-04-19 22:50:502438// This exists for render views that don't have a WebUI, but do have WebUI
2439// bindings enabled.
2440void WebContentsImpl::OnWebUISend(const GURL& source_url,
2441 const std::string& name,
2442 const base::ListValue& args) {
2443 if (delegate_)
2444 delegate_->WebUISend(this, source_url, name, args);
2445}
2446
[email protected]d8415ad92012-08-23 14:40:502447void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442448 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502449 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342450 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162451 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442452 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162453 return;
[email protected]d8415ad92012-08-23 14:40:502454 }
2455
[email protected]8c8fc292012-11-23 18:57:162456 if (!delegate_->RequestPpapiBrokerPermission(
2457 this, url, plugin_path,
2458 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442459 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162460 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442461 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162462 }
[email protected]d8415ad92012-08-23 14:40:502463}
2464
[email protected]ea0309c2013-08-06 19:35:442465void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502466 bool result) {
[email protected]ea0309c2013-08-06 19:35:442467 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502468}
2469
[email protected]c4538072013-03-18 02:17:552470void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372471 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082472 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552473 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392474 // For more info, see comment above classes BrowserPluginEmbedder and
2475 // BrowserPluginGuest.
2476 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142477 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082478 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372479}
2480
[email protected]41225fe2013-03-29 05:32:022481void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392482 int id,
[email protected]749fadd2013-05-15 08:37:482483 int http_status_code,
[email protected]795c28972012-12-06 06:13:392484 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302485 const std::vector<SkBitmap>& bitmaps,
2486 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022487 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2488 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392489 // Currently WebContents notifies us of ANY downloads so that it is
2490 // possible to get here.
2491 return;
2492 }
2493 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302494 iter->second.Run(
2495 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392496 }
[email protected]41225fe2013-03-29 05:32:022497 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392498}
2499
2500void WebContentsImpl::OnUpdateFaviconURL(
2501 int32 page_id,
2502 const std::vector<FaviconURL>& candidates) {
2503 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2504 DidUpdateFaviconURL(page_id, candidates));
2505}
2506
[email protected]d9030b82013-07-19 08:26:062507void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2508 bool has_video,
2509 bool has_audio,
2510 bool is_playing) {
2511 // Chrome OS does its own detection of audio and video.
2512#if !defined(OS_CHROMEOS)
2513 if (is_playing) {
2514 scoped_ptr<PowerSaveBlocker> blocker;
2515 if (has_video) {
2516 blocker = PowerSaveBlocker::Create(
2517 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2518 "Playing video");
2519#if defined(OS_ANDROID)
2520 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382521 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062522#endif
2523 } else if (has_audio) {
2524 blocker = PowerSaveBlocker::Create(
2525 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2526 "Playing audio");
2527 }
2528
[email protected]f114fa42013-12-06 17:06:442529 if (blocker) {
2530 power_save_blockers_[render_view_message_source_][player_cookie] =
2531 blocker.release();
2532 }
[email protected]d9030b82013-07-19 08:26:062533 } else {
[email protected]f114fa42013-12-06 17:06:442534 delete power_save_blockers_[render_view_message_source_][player_cookie];
2535 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062536 }
2537#endif // !defined(OS_CHROMEOS)
2538}
2539
[email protected]9f268072013-11-07 00:02:152540void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2541 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2542 DidFirstVisuallyNonEmptyPaint(page_id));
2543}
[email protected]d9030b82013-07-19 08:26:062544
[email protected]e67ebf32013-02-13 11:07:192545void WebContentsImpl::DidChangeVisibleSSLState() {
2546 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2547 DidChangeVisibleSSLState());
2548}
2549
[email protected]17e286e2013-03-01 23:29:392550void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2551 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2552 BeforeFormRepostWarningShow());
2553}
2554
[email protected]ec6c05f2013-10-23 18:41:572555
2556void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2557 Activate();
2558 if (delegate_)
2559 delegate_->ShowRepostFormWarningDialog(this);
2560}
2561
[email protected]96d185d2009-04-24 03:28:542562// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592563// loading, or done loading.
2564void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2565 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262566 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542567 if (is_loading == is_loading_)
2568 return;
2569
2570 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262571 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2572 base::string16());
[email protected]96d185d2009-04-24 03:28:542573 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562574 upload_size_ = 0;
2575 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542576 }
2577
[email protected]fa944cb82013-11-15 17:51:212578 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542579
2580 is_loading_ = is_loading;
2581 waiting_for_response_ = is_loading;
2582
[email protected]6ebdc9b2010-09-27 16:55:572583 if (delegate_)
2584 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212585 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542586
[email protected]eab61442013-11-14 18:35:482587 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592588 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482589 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2590 "URL", url);
[email protected]91621872013-10-08 04:04:592591 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2592 DidStartLoading(render_view_host));
2593 } else {
[email protected]eab61442013-11-14 18:35:482594 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2595 "URL", url);
[email protected]91621872013-10-08 04:04:592596 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2597 DidStopLoading(render_view_host));
2598 }
[email protected]66798902013-10-01 18:40:162599
2600 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212601 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2602 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542603 if (details)
[email protected]8ff00d72012-10-23 19:12:212604 det = Details<LoadNotificationDetails>(details);
2605 NotificationService::current()->Notify(
2606 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212610 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322611 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562612 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322613 // Clear the status bubble. This is a workaround for a bug where WebKit
2614 // doesn't let us know that the cursor left an element during a
2615 // transition (this is also why the mouse cursor remains as a hand after
2616 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2617 // clear the bubble when a user navigates to a named anchor in the same
2618 // page.
[email protected]36fc0392011-12-25 03:59:512619 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322620 }
2621
[email protected]a6e82fc2010-02-24 22:28:142622 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472623 // Once the main frame is navigated, we're no longer considered to have
2624 // displayed insecure content.
2625 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352626 SSLManager::NotifySSLInternalStateChanged(
2627 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172628 }
[email protected]ce5c4502009-05-06 16:46:112629
[email protected]3c9e1872010-11-18 16:17:492630 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042632 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322633}
2634
[email protected]b172aee2012-04-10 17:05:262635void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322636 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212637 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322638 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112639 // If we navigate off the page, close all JavaScript dialogs.
2640 if (dialog_manager_ && !details.is_in_page)
2641 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322642
[email protected]3c9e1872010-11-18 16:17:492643 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252644 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042645 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322646}
2647
[email protected]2f7b3c5a2013-06-21 04:59:252648bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292649 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2650 // still be used for a normal web site.
2651 if (url == GURL(kAboutBlankURL))
2652 return false;
2653
2654 // The embedder will then have the opportunity to determine if the URL
2655 // should "use up" the SiteInstance.
2656 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252657}
2658
[email protected]b172aee2012-04-10 17:05:262659void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462660 // If we are creating a RVH for a restored controller, then we need to make
2661 // sure the RenderView starts with a next_page_id_ larger than the number
2662 // of restored entries. This must be called before the RenderView starts
2663 // navigating (to avoid a race between the browser updating max_page_id and
2664 // the renderer updating next_page_id_). Because of this, we only call this
2665 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562666 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582667 if (max_restored_page_id >
2668 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2669 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2670 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322671}
2672
[email protected]b172aee2012-04-10 17:05:262673bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262674 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322675 // For file URLs without a title, use the pathname instead. In the case of a
2676 // synthesized title, we don't want the update to count toward the "one set
2677 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262678 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322679 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512680 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2681 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322682 explicit_set = false; // Don't count synthetic titles toward the set limit.
2683 } else {
[email protected]acafd272011-07-26 17:35:572684 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322685 explicit_set = true;
2686 }
2687
[email protected]987fc3a2011-05-26 14:18:092688 // If a page is created via window.open and never navigated,
2689 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552690 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092691 if (entry) {
[email protected]36fc0392011-12-25 03:59:512692 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092693 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322694
[email protected]36fc0392011-12-25 03:59:512695 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092696 } else {
2697 if (page_title_when_no_navigation_entry_ == final_title)
2698 return false; // Nothing changed, don't bother.
2699
2700 page_title_when_no_navigation_entry_ = final_title;
2701 }
[email protected]420ae012009-04-24 05:16:322702
[email protected]420ae012009-04-24 05:16:322703 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232704 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322705
[email protected]66798902013-10-01 18:40:162706 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532707 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162708
2709 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212710 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462711 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212712 NotificationService::current()->Notify(
2713 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2714 Source<WebContents>(this),
2715 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042716
[email protected]420ae012009-04-24 05:16:322717 return true;
2718}
2719
[email protected]7b712ee22013-10-03 00:57:282720void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2721 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322722 // After sending out a swap notification, we need to send a disconnect
2723 // notification so that clients that pick up a pointer to |this| can NULL the
2724 // pointer. See Bug 1230284.
2725 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112726 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282727 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112728
2729 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282730 std::pair<RenderViewHost*, RenderViewHost*> details =
2731 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212732 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282733 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212734 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282735 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392736
2737 // Ensure that the associated embedder gets cleared after a RenderViewHost
2738 // gets swapped, so we don't reuse the same embedder next time a
2739 // RenderViewHost is attached to this WebContents.
2740 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322741}
2742
[email protected]da7a7182013-09-06 08:11:112743// TODO(avi): Remove this entire function because this notification is already
2744// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262745void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322746 if (!notify_disconnection_)
2747 return;
2748
2749 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212750 NotificationService::current()->Notify(
2751 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2752 Source<WebContents>(this),
2753 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322754}
2755
[email protected]cbb1ef592013-06-05 19:49:462756void WebContentsImpl::NotifyNavigationEntryCommitted(
2757 const LoadCommittedDetails& load_details) {
2758 FOR_EACH_OBSERVER(
2759 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2760}
2761
[email protected]f114fa42013-12-06 17:06:442762bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2763 const IPC::Message& message) {
2764 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312765}
2766
[email protected]b849847b2013-12-10 21:57:582767void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2768 // Note this is only for subframes, the notification for the main frame
2769 // happens in RenderViewCreated.
2770 FOR_EACH_OBSERVER(WebContentsObserver,
2771 observers_,
2772 RenderFrameCreated(render_frame_host));
2773}
2774
2775void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2776 FOR_EACH_OBSERVER(WebContentsObserver,
2777 observers_,
2778 RenderFrameDeleted(render_frame_host));
2779}
2780
[email protected]5a3bdf52012-05-24 15:12:572781RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2782 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322783}
2784
[email protected]8d3347f2009-07-09 22:00:212785RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262786WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212787 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212788}
2789
[email protected]8ff00d72012-10-23 19:12:212790RendererPreferences WebContentsImpl::GetRendererPrefs(
2791 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462792 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512793}
2794
[email protected]b172aee2012-04-10 17:05:262795WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172796 return this;
2797}
2798
[email protected]b172aee2012-04-10 17:05:262799gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172800 if (delegate_)
2801 return delegate_->GetRootWindowResizerRect();
2802 return gfx::Rect();
2803}
2804
[email protected]7a846df2012-09-20 19:17:392805void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272806 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392807 browser_plugin_embedder_.reset();
2808}
2809
[email protected]b172aee2012-04-10 17:05:262810void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442811 // Don't send notifications if we are just creating a swapped-out RVH for
2812 // the opener chain. These won't be used for view-source or WebUI, so it's
2813 // ok to return early.
2814 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2815 return;
2816
[email protected]86f98a22013-03-20 14:35:002817 if (delegate_)
2818 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082819
[email protected]8ff00d72012-10-23 19:12:212820 NotificationService::current()->Notify(
2821 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2822 Source<WebContents>(this),
2823 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322824
2825 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352826 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212827 if (GetRenderManager()->pending_web_ui())
2828 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322829
[email protected]6286a372013-10-09 04:03:272830 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332831 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322832 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182833 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582834 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322835 }
[email protected]0666aef2009-05-13 19:48:082836
[email protected]60780f412013-02-25 16:34:102837 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262838
2839 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252840 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582841
2842 // We tell the observers now instead of when the main RenderFrameHostImpl is
2843 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2844 // frame would be dropped because it's not created yet).
2845 RenderFrameHost* main_frame = GetMainFrame();
2846 FOR_EACH_OBSERVER(
2847 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322848}
2849
[email protected]b172aee2012-04-10 17:05:262850void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522851 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322852 // Don't notify the world, since this came from a renderer in the
2853 // background.
2854 return;
2855 }
2856
[email protected]da7a7182013-09-06 08:11:112857 notify_disconnection_ = true;
2858 // TODO(avi): Remove. http://crbug.com/170921
2859 NotificationService::current()->Notify(
2860 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2861 Source<WebContents>(this),
2862 NotificationService::NoDetails());
2863
[email protected]be1f56ab2011-12-22 06:55:312864 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232865 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302866
2867 // Restore the focus to the tab (otherwise the focus will be on the top
2868 // window).
[email protected]484ae5912010-09-29 19:16:142869 if (was_crashed && !FocusLocationBarByDefault() &&
2870 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062871 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142872 }
[email protected]32ded2212011-11-10 18:51:432873
[email protected]d8c660432011-12-22 20:51:252874 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322875}
2876
[email protected]ec6a7eb2013-04-22 17:34:222877void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2878 base::TerminationStatus status,
2879 int error_code) {
[email protected]151a63d2011-12-20 22:32:522880 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322881 // The pending page's RenderViewHost is gone.
2882 return;
2883 }
2884
[email protected]d9030b82013-07-19 08:26:062885 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592886 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322887 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232888 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312889 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322890
[email protected]d8c660432011-12-22 20:51:252891 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272892 observers_,
[email protected]58d5cfe2013-07-10 02:40:522893 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322894}
2895
[email protected]b172aee2012-04-10 17:05:262896void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062897 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212898 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252899 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062900}
2901
[email protected]b0f724c2013-09-05 04:21:132902void WebContentsImpl::DidGetResourceResponseStart(
2903 const ResourceRequestDetails& details) {
2904 controller_.ssl_manager()->DidStartResourceResponse(details);
2905
2906 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2907 DidGetResourceResponseStart(details));
2908
2909 // TODO(avi): Remove. http://crbug.com/170921
2910 NotificationService::current()->Notify(
2911 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2912 Source<WebContents>(this),
2913 Details<const ResourceRequestDetails>(&details));
2914}
2915
2916void WebContentsImpl::DidGetRedirectForResourceRequest(
2917 const ResourceRedirectDetails& details) {
2918 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2919
2920 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2921 DidGetRedirectForResourceRequest(details));
2922
2923 // TODO(avi): Remove. http://crbug.com/170921
2924 NotificationService::current()->Notify(
2925 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2926 Source<WebContents>(this),
2927 Details<const ResourceRedirectDetails>(&details));
2928}
2929
[email protected]b172aee2012-04-10 17:05:262930void WebContentsImpl::DidNavigate(
2931 RenderViewHost* rvh,
2932 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552933 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2934 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122935 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552936 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122937 }
2938
[email protected]e3d92a7f2013-01-10 02:35:052939 if (PageTransitionIsMainFrame(params.transition)) {
2940 // When overscroll navigation gesture is enabled, a screenshot of the page
2941 // in its current state is taken so that it can be used during the
2942 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362943 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052944 // WebContents::GetRenderViewHost to return the new host, instead of the one
2945 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482946 if (delegate_ && delegate_->CanOverscrollContent())
2947 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052948
[email protected]fa944cb82013-11-15 17:51:212949 GetRenderManager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052950 }
[email protected]8030f012009-09-25 18:09:372951
[email protected]434f69f2012-02-06 21:56:522952 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252953 // assigning a site is not necessary for this URL. In that case, the
2954 // SiteInstance can still be considered unused until a navigation to a real
2955 // page.
[email protected]434f69f2012-02-06 21:56:522956 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252957 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332958 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522959 }
[email protected]420ae012009-04-24 05:16:322960
2961 // Need to update MIME type here because it's referred to in
2962 // UpdateNavigationCommands() called by RendererDidNavigate() to
2963 // determine whether or not to enable the encoding menu.
2964 // It's updated only for the main frame. For a subframe,
2965 // RenderView::UpdateURL does not set params.contents_mime_type.
2966 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2967 // TODO(jungshik): Add a test for the encoding menu to avoid
2968 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212969 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322970 contents_mime_type_ = params.contents_mime_type;
2971
[email protected]8ff00d72012-10-23 19:12:212972 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002973 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392974
[email protected]1ae93fb2013-06-14 03:38:562975 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2976 // us estimate our process count for implementing OOP iframes.
2977 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552978 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562979
[email protected]a9c0bfe2010-09-17 08:35:222980 // Send notification about committed provisional loads. This notification is
2981 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2982 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212983 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072984 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2985 // that is not recorded in the navigation history. For the purpose of
2986 // tracking navigation events, we treat this event as a sub frame navigation
2987 // event.
2988 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212989 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222990 // Whether or not a page transition was triggered by going backward or
2991 // forward in the history is only stored in the navigation controller's
2992 // entry list.
2993 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272994 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212995 PAGE_TRANSITION_FORWARD_BACK)) {
2996 transition_type = PageTransitionFromInt(
2997 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222998 }
[email protected]0d60f0192011-04-14 12:40:102999 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:253000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:443001 DidCommitProvisionalLoadForFrame(
3002 params.frame_id,
3003 params.frame_unique_name,
3004 is_main_frame,
3005 params.url,
3006 transition_type,
3007 rvh));
[email protected]a9c0bfe2010-09-17 08:35:223008 }
3009
[email protected]76543b92009-08-31 17:27:453010 if (!did_navigate)
3011 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:323012
3013 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
3014 // for the appropriate notification (best) or you can add it to
3015 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
3016 // necessary, please).
3017
3018 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:003019 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:323020 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:003021 if (delegate_) {
[email protected]6934a702011-12-20 00:04:513022 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:003023 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
3024 }
[email protected]93f230e02011-06-01 14:40:003025 }
[email protected]420ae012009-04-24 05:16:323026 DidNavigateAnyFramePostCommit(rvh, details, params);
3027}
3028
[email protected]b172aee2012-04-10 17:05:263029void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3030 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043031 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153032 // Ensure that this state update comes from either the active RVH or one of
3033 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]fa944cb82013-11-15 17:51:213034 DCHECK(rvh == GetRenderViewHost() ||
3035 GetRenderManager()->IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:323036
3037 // We must be prepared to handle state updates for any page, these occur
3038 // when the user is scrolling and entering form data, as well as when we're
3039 // leaving a page, in which case our state may have already been moved to
3040 // the next page. The navigation controller will look up the appropriate
3041 // NavigationEntry and update it when it is notified via the delegate.
3042
3043 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583044 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323045 if (entry_index < 0)
3046 return;
[email protected]10f417c52011-12-28 21:04:233047 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323048
[email protected]691aa2f2013-05-28 22:52:043049 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323050 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043051 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323052 controller_.NotifyEntryChanged(entry, entry_index);
3053}
3054
[email protected]b172aee2012-04-10 17:05:263055void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3056 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263057 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263058 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323059 // If we have a title, that's a pretty good indication that we've started
3060 // getting useful data.
3061 SetNotWaitingForResponse();
3062
[email protected]73eb2602012-02-09 19:50:553063 // Try to find the navigation entry, which might not be the current one.
3064 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233065 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583066 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093067
[email protected]73eb2602012-02-09 19:50:553068 // We can handle title updates when we don't have an entry in
3069 // UpdateTitleForEntry, but only if the update is from the current RVH.
3070 if (!entry && rvh != GetRenderViewHost())
3071 return;
3072
[email protected]a49e10b2011-08-01 23:57:463073 // TODO(evan): make use of title_direction.
3074 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093075 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323076 return;
3077
3078 // Broadcast notifications when the UI should be updated.
3079 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213080 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323081}
3082
[email protected]b172aee2012-04-10 17:05:263083void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3084 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313085 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323086}
3087
[email protected]b172aee2012-04-10 17:05:263088void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513089 if (delegate_)
3090 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323091}
3092
[email protected]b172aee2012-04-10 17:05:263093void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103094#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293095 // The UI may be in an event-tracking loop, such as between the
3096 // mouse-down and mouse-up in text selection or a button click.
3097 // Defer the close until after tracking is complete, so that we
3098 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293099 // TODO(shess): This could get more fine-grained. For instance,
3100 // closing a tab in another window while selecting text in the
3101 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103102 if (view_->IsEventTracking()) {
3103 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293104 return;
3105 }
[email protected]60780f412013-02-25 16:34:103106#endif
[email protected]07707302009-11-06 00:50:293107
[email protected]420ae012009-04-24 05:16:323108 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523109 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513110 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523114 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513115 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283116
3117 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213118 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573119}
3120
[email protected]b172aee2012-04-10 17:05:263121void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513122 if (delegate_ && delegate_->IsPopupOrPanel(this))
3123 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323124}
3125
[email protected]8ff00d72012-10-23 19:12:213126void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593127 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323128}
3129
[email protected]8ff00d72012-10-23 19:12:213130void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323131 scoped_ptr<LoadNotificationDetails> details;
3132
[email protected]9595fd82013-04-19 21:28:493133 // Use the last committed entry rather than the active one, in case a
3134 // pending entry has been created.
3135 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3136
[email protected]420ae012009-04-24 05:16:323137 // An entry may not exist for a stop when loading an initial blank page or
3138 // if an iframe injected by script into a blank page finishes loading.
3139 if (entry) {
[email protected]420ae012009-04-24 05:16:323140 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3141
3142 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513143 entry->GetVirtualURL(),
3144 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323145 elapsed,
3146 &controller_,
3147 controller_.GetCurrentEntryIndex()));
3148 }
3149
[email protected]91621872013-10-08 04:04:593150 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323151}
3152
[email protected]b172aee2012-04-10 17:05:263153void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163154 controller_.DiscardNonCommittedEntries();
3155
3156 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213157 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163158}
3159
[email protected]b172aee2012-04-10 17:05:263160void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513161 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133162 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403163}
3164
[email protected]7cc78902012-12-06 02:32:263165void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393166 if (opener_) {
3167 // Clear our opener so that future cross-process navigations don't have an
3168 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103169 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393170 opener_ = NULL;
3171 }
[email protected]7cc78902012-12-06 02:32:263172
3173 // Notify all swapped out RenderViewHosts for this tab. This is important
3174 // in case we go back to them, or if another window in those processes tries
3175 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213176 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263177}
3178
[email protected]59167c22013-06-03 18:07:323179void WebContentsImpl::DidAccessInitialDocument() {
3180 // Update the URL display.
3181 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3182}
3183
[email protected]87717d0e2012-04-26 02:58:433184void WebContentsImpl::DocumentAvailableInMainFrame(
3185 RenderViewHost* render_view_host) {
3186 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3187 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103188}
3189
[email protected]b172aee2012-04-10 17:05:263190void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083191 RenderViewHost* render_view_host,
3192 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093193 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3194 DocumentOnLoadCompletedInMainFrame(page_id));
3195
3196 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213197 NotificationService::current()->Notify(
3198 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3199 Source<WebContents>(this),
3200 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083201}
3202
[email protected]196159d2012-05-04 17:26:543203void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3204 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213205 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263206 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183207 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523208 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303209 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543210 // If this came from a swapped out RenderViewHost, we only allow the request
3211 // if we are still in the same BrowsingInstance.
3212 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3213 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3214 return;
3215 }
3216
[email protected]4ad5d77d2011-12-03 02:00:483217 // Delegate to RequestTransferURL because this is just the generic
3218 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573219 // TODO(creis): Pass the redirect_chain into this method to support client
3220 // redirects. http://crbug.com/311721.
3221 std::vector<GURL> redirect_chain;
3222 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3223 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523224 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483225}
3226
[email protected]b172aee2012-04-10 17:05:263227void WebContentsImpl::RequestTransferURL(
3228 const GURL& url,
[email protected]f8872902013-10-30 03:18:573229 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213230 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573231 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263232 WindowOpenDisposition disposition,
3233 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183234 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523235 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303236 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203237 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123238 GURL dest_url(url);
3239 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553240 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123241 dest_url = GURL(kAboutBlankURL);
3242
[email protected]c80297782013-11-21 07:10:163243 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id.
3244 int frame_tree_node_id = -1;
3245 OpenURLParams params(dest_url, referrer, source_frame_id,
3246 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573247 page_transition, true /* is_renderer_initiated */);
3248 if (redirect_chain.size() > 0)
3249 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553250 params.transferred_global_request_id = old_request_id;
3251 params.should_replace_current_entry = should_replace_current_entry;
3252 params.user_gesture = user_gesture;
3253
[email protected]fa944cb82013-11-15 17:51:213254 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573255 // Web UI pages sometimes want to override the page transition type for
3256 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3257 // automatically generated suggestions). We don't override other types
3258 // like TYPED because they have different implications (e.g., autocomplete).
3259 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213260 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553261
[email protected]e0112912011-02-02 22:54:353262 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163263 // want web sites to see a referrer of "chrome://blah" (and some
3264 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323265 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553266 params.referrer = Referrer();
3267
3268 // Navigations in Web UI pages count as browser-initiated navigations.
3269 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583270 }
[email protected]44d0930a2013-10-28 18:53:553271
3272 new_contents = OpenURL(params);
3273
[email protected]ae5184d62011-10-06 19:25:583274 if (new_contents) {
3275 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253276 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583277 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123278 dest_url,
[email protected]ae5184d62011-10-06 19:25:583279 referrer,
3280 disposition,
[email protected]44d0930a2013-10-28 18:53:553281 params.transition,
[email protected]ae5184d62011-10-06 19:25:583282 source_frame_id));
[email protected]420ae012009-04-24 05:16:323283 }
3284}
3285
[email protected]e1c3a552012-05-04 20:51:323286void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3287 // Tell the active RenderViewHost to run unload handlers and close, as long
3288 // as the request came from a RenderViewHost in the same BrowsingInstance.
3289 // In most cases, we receive this from a swapped out RenderViewHost.
3290 // It is possible to receive it from one that has just been swapped in,
3291 // in which case we might as well deliver the message anyway.
3292 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3293 GetRenderViewHost()->ClosePage();
3294}
3295
[email protected]f546640b2012-05-15 00:03:493296void WebContentsImpl::RouteMessageEvent(
3297 RenderViewHost* rvh,
3298 const ViewMsg_PostMessage_Params& params) {
3299 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363300 // came from a RenderViewHost in the same BrowsingInstance or if this
3301 // WebContents is dedicated to a browser plugin guest.
3302 // Note: This check means that an embedder could theoretically receive a
3303 // postMessage from anyone (not just its own guests). However, this is
3304 // probably not a risk for apps since other pages won't have references
3305 // to App windows.
3306 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3307 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493308 return;
3309
3310 ViewMsg_PostMessage_Params new_params(params);
3311
[email protected]0bc7f3542013-10-21 15:05:533312 if (!params.message_port_ids.empty()) {
3313 MessagePortMessageFilter* message_port_message_filter =
3314 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3315 ->message_port_message_filter();
3316 std::vector<int> new_routing_ids(params.message_port_ids.size());
3317 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3318 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3319 MessagePortService::GetInstance()->UpdateMessagePort(
3320 params.message_port_ids[i],
3321 message_port_message_filter,
3322 new_routing_ids[i]);
3323 }
3324 new_params.new_routing_ids = new_routing_ids;
3325 }
3326
[email protected]f546640b2012-05-15 00:03:493327 // If there is a source_routing_id, translate it to the routing ID for
3328 // the equivalent swapped out RVH in the target process. If we need
3329 // to create a swapped out RVH for the source tab, we create its opener
3330 // chain as well, since those will also be accessible to the target page.
3331 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3332 // Try to look up the WebContents for the source page.
3333 WebContentsImpl* source_contents = NULL;
3334 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3335 rvh->GetProcess()->GetID(), params.source_routing_id);
3336 if (source_rvh) {
3337 source_contents = static_cast<WebContentsImpl*>(
3338 source_rvh->GetDelegate()->GetAsWebContents());
3339 }
3340
3341 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363342 if (GetBrowserPluginGuest()) {
3343 // We create a swapped out RenderView for the embedder in the guest's
3344 // render process but we intentionally do not expose the embedder's
3345 // opener chain to it.
3346 new_params.source_routing_id =
3347 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3348 } else {
3349 new_params.source_routing_id =
3350 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3351 }
[email protected]f546640b2012-05-15 00:03:493352 } else {
3353 // We couldn't find it, so don't pass a source frame.
3354 new_params.source_routing_id = MSG_ROUTING_NONE;
3355 }
3356 }
3357
3358 // In most cases, we receive this from a swapped out RenderViewHost.
3359 // It is possible to receive it from one that has just been swapped in,
3360 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183361 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493362}
3363
[email protected]b172aee2012-04-10 17:05:263364void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343365 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263366 const base::string16& message,
3367 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323368 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213369 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323370 IPC::Message* reply_msg,
3371 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073372 // Suppress JavaScript dialogs when requested. Also suppress messages when
3373 // showing an interstitial as it's shown over the previous page and we don't
3374 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503375 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583376 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273377 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073378 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523379 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153380 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323381
3382 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213383 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433384 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153385 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3386 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433387 this,
3388 frame_url.GetOrigin(),
3389 accept_lang,
3390 javascript_message_type,
3391 message,
[email protected]51da7e32012-01-30 19:24:523392 default_prompt,
[email protected]b172aee2012-04-10 17:05:263393 base::Bind(&WebContentsImpl::OnDialogClosed,
3394 base::Unretained(this),
3395 rvh,
3396 reply_msg),
[email protected]51da7e32012-01-30 19:24:523397 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323398 }
[email protected]3ab9cb82011-06-03 18:02:073399
[email protected]6dd2f1e2013-09-11 15:06:013400 *did_suppress_message = suppress_this_message;
3401
[email protected]3ab9cb82011-06-03 18:02:073402 if (suppress_this_message) {
3403 // If we are suppressing messages, just reply as if the user immediately
3404 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263405 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073406 }
3407
[email protected]6dd2f1e2013-09-11 15:06:013408 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3409 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323410}
3411
[email protected]b172aee2012-04-10 17:05:263412void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263413 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263414 bool is_reload,
3415 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583416 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513417 if (delegate_)
3418 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073419
3420 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583421 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073422 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523423 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153424 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153425 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343426 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263427 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503428 return;
3429 }
[email protected]3ab9cb82011-06-03 18:02:073430
[email protected]7ab1e7d62009-10-14 23:32:013431 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153432 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3433 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323434 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263435 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523436 reply_msg));
[email protected]420ae012009-04-24 05:16:323437}
3438
[email protected]a796f202012-05-30 14:14:253439bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263440 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253441 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263442 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253443 if (!delegate_)
3444 return false;
3445 return delegate_->AddMessageToConsole(this, level, message, line_no,
3446 source_id);
3447}
3448
[email protected]b172aee2012-04-10 17:05:263449WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273450 // We want to base the page config off of the actual URL, rather than the
3451 // virtual URL.
3452 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3453 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003454 GURL url = controller_.GetActiveEntry()
3455 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153456
[email protected]fa944cb82013-11-15 17:51:213457 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323458}
3459
[email protected]0eba810b2012-10-18 03:19:363460int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213461 SiteInstance* instance) {
[email protected]fa944cb82013-11-15 17:51:213462 return GetRenderManager()->CreateRenderView(instance, MSG_ROUTING_NONE,
3463 true, true);
[email protected]0eba810b2012-10-18 03:19:363464}
3465
[email protected]b172aee2012-04-10 17:05:263466void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273467 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253468 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223469
[email protected]ea114722012-03-12 01:11:253470 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173471 if (rdh) // NULL in unittests.
3472 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253473}
3474
[email protected]b172aee2012-04-10 17:05:263475void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443476 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253477 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443478}
3479
[email protected]b172aee2012-04-10 17:05:263480void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563481 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263482 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153483 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523484 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153485 return;
3486
[email protected]9f76c1e2012-03-05 15:15:583487 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3488
[email protected]e5fc1632011-08-08 07:51:533489 // Ignore renderer unresponsive event if debugger is attached to the tab
3490 // since the event may be a result of the renderer sitting on a breakpoint.
3491 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363492 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533493 return;
3494
[email protected]2e9d79f2013-08-16 05:45:563495 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323496 // Hang occurred while firing the beforeunload/unload handler.
3497 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583498 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323499
[email protected]fa944cb82013-11-15 17:51:213500 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323501 return;
3502
3503 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563504 // nothing we can do to recover. If the hang is in the beforeunload handler,
3505 // pretend the beforeunload listeners have all fired and allow the delegate
3506 // to continue closing; the user will not have the option of cancelling the
3507 // close. Otherwise, pretend the unload listeners have all fired and close
3508 // the tab.
3509 bool close = true;
3510 if (is_during_beforeunload) {
3511 delegate_->BeforeUnloadFired(this, true, &close);
3512 }
3513 if (close)
3514 Close(rvh);
[email protected]420ae012009-04-24 05:16:323515 return;
3516 }
3517
[email protected]9f76c1e2012-03-05 15:15:583518 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473519 return;
3520
[email protected]6934a702011-12-20 00:04:513521 if (delegate_)
3522 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323523}
3524
[email protected]b172aee2012-04-10 17:05:263525void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513526 if (delegate_)
3527 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323528}
3529
[email protected]b172aee2012-04-10 17:05:263530void WebContentsImpl::LoadStateChanged(
3531 const GURL& url,
3532 const net::LoadStateWithParam& load_state,
3533 uint64 upload_position,
3534 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323535 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563536 upload_position_ = upload_position;
3537 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503538 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213539 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303540 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213541 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323542 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463543 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213544 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463545 }
[email protected]420ae012009-04-24 05:16:323546}
3547
[email protected]b172aee2012-04-10 17:05:263548void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513549 if (delegate_)
3550 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253551}
3552
[email protected]b172aee2012-04-10 17:05:263553void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553554 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323555 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123556 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3557 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513558 if (delegate_)
3559 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093560 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323561}
3562
[email protected]58d5cfe2013-07-10 02:40:523563void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543564 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233565 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223566 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543567}
3568
[email protected]b172aee2012-04-10 17:05:263569void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103570 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213571 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263572 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3573 // here during container initialization and normal window size will be set
3574 // later. In case of tab duplication this resizing to 0x0 prevents setting
3575 // normal size later so just ignore it.
3576 if (!size.IsEmpty())
3577 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323578}
3579
[email protected]af905902013-10-01 21:38:513580void WebContentsImpl::CancelModalDialogsForRenderManager() {
3581 // We need to cancel modal dialogs when doing a process swap, since the load
3582 // deferrer would prevent us from swapping out.
3583 if (dialog_manager_)
3584 dialog_manager_->CancelActiveAndPendingDialogs(this);
3585}
3586
[email protected]7b712ee22013-10-03 00:57:283587void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3588 RenderViewHost* new_host) {
3589 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083590
3591 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003592 if (delegate_)
3593 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393594
[email protected]7b712ee22013-10-03 00:57:283595 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543596}
3597
[email protected]14392a52012-05-02 20:28:443598int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3599 SiteInstance* instance) {
3600 if (!opener_)
3601 return MSG_ROUTING_NONE;
3602
3603 // Recursively create RenderViews for anything else in the opener chain.
3604 return opener_->CreateOpenerRenderViews(instance);
3605}
3606
3607int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3608 int opener_route_id = MSG_ROUTING_NONE;
3609
3610 // If this tab has an opener, ensure it has a RenderView in the given
3611 // SiteInstance as well.
3612 if (opener_)
3613 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3614
[email protected]45a22ad2013-02-21 03:25:003615 // If any of the renderers (current, pending, or swapped out) for this
3616 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213617 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3618 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373619
[email protected]fa944cb82013-11-15 17:51:213620 if (GetRenderManager()->pending_render_view_host() &&
3621 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3622 instance)
3623 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003624
[email protected]fa944cb82013-11-15 17:51:213625 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373626 instance);
3627 if (rvh)
3628 return rvh->GetRoutingID();
3629
[email protected]14392a52012-05-02 20:28:443630 // Create a swapped out RenderView in the given SiteInstance if none exists,
3631 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]fa944cb82013-11-15 17:51:213632 return GetRenderManager()->CreateRenderView(instance, opener_route_id,
3633 true, true);
[email protected]14392a52012-05-02 20:28:443634}
3635
[email protected]b172aee2012-04-10 17:05:263636NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193637 return GetController();
[email protected]3a3d47472010-07-15 21:03:543638}
3639
[email protected]b172aee2012-04-10 17:05:263640WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563641 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323642}
3643
[email protected]10f417c52011-12-28 21:04:233644NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263645 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323646 return controller_.GetLastCommittedEntry();
3647}
3648
[email protected]b172aee2012-04-10 17:05:263649bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443650 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033651 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443652 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323653 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523654
[email protected]420ae012009-04-24 05:16:323655 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443656 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213657 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323658
[email protected]74ce1ad2011-12-16 21:51:463659 // Make sure we use the correct starting page_id in the new RenderView.
3660 UpdateMaxPageIDIfNecessary(render_view_host);
3661 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583662 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463663
[email protected]9f76c1e2012-03-05 15:15:583664 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263665 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493666 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133667 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523668 return false;
[email protected]14392a52012-05-02 20:28:443669 }
[email protected]a4127722011-04-27 23:13:523670
[email protected]a220b5932013-09-21 03:47:443671#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503672 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3673 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443674 if (rwh_view) {
3675 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3676 render_widget_host->WasResized();
3677 }
[email protected]f8233cc2011-05-31 20:24:503678#endif
3679
[email protected]420ae012009-04-24 05:16:323680 return true;
3681}
3682
[email protected]7d244f12013-08-22 21:41:513683#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183684base::android::ScopedJavaLocalRef<jobject>
3685WebContentsImpl::GetJavaWebContents() {
3686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3687
3688 WebContentsAndroid* web_contents_android =
3689 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3690 if (!web_contents_android) {
3691 web_contents_android = new WebContentsAndroid(this);
3692 SetUserData(kWebContentsAndroidKey, web_contents_android);
3693 }
3694 return web_contents_android->GetJavaObject();
3695}
3696
[email protected]7d244f12013-08-22 21:41:513697bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3698 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3699 MSG_ROUTING_NONE);
3700}
3701#endif
3702
[email protected]b172aee2012-04-10 17:05:263703void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3704 IPC::Message* reply_msg,
3705 bool success,
[email protected]fcf75d42013-12-03 20:11:263706 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543707 if (is_showing_before_unload_dialog_ && !success) {
3708 // If a beforeunload dialog is canceled, we need to stop the throbber from
3709 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293710 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353711 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103712
[email protected]6d65a462013-06-21 21:29:123713 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3714 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543715 }
3716 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583717 static_cast<RenderViewHostImpl*>(
3718 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543719}
3720
[email protected]b172aee2012-04-10 17:05:263721void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213722 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123723 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103724}
[email protected]f45d2a72010-03-08 23:28:353725
[email protected]b172aee2012-04-10 17:05:263726void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103727 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443728 // Can be NULL during tests.
3729 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213730 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363731}
[email protected]9f76c1e2012-03-05 15:15:583732
[email protected]1ac10dca2013-08-20 20:47:043733bool WebContentsImpl::IsHidden() {
3734 return capturer_count_ == 0 && !should_normally_be_visible_;
3735}
3736
[email protected]b0936d22013-11-28 06:47:363737RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213738 return frame_tree_.root()->render_manager();
3739}
3740
[email protected]b172aee2012-04-10 17:05:263741RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583742 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3743}
[email protected]7900bfdb2012-05-24 19:31:243744
[email protected]f8497342013-02-05 22:15:023745BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393746 return browser_plugin_guest_.get();
3747}
3748
[email protected]738f57a2013-06-29 21:06:543749void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3750 CHECK(!browser_plugin_guest_);
3751 browser_plugin_guest_.reset(guest);
3752}
3753
[email protected]f8497342013-02-05 22:15:023754BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393755 return browser_plugin_embedder_.get();
3756}
[email protected]8ff00d72012-10-23 19:12:213757
[email protected]8eb04562013-03-06 03:41:143758BrowserPluginGuestManager*
3759 WebContentsImpl::GetBrowserPluginGuestManager() const {
3760 return static_cast<BrowserPluginGuestManager*>(
3761 GetBrowserContext()->GetUserData(
3762 browser_plugin::kBrowserPluginGuestManagerKeyName));
3763}
3764
[email protected]d9030b82013-07-19 08:26:063765void WebContentsImpl::ClearPowerSaveBlockers(
3766 RenderViewHost* render_view_host) {
3767 STLDeleteValues(&power_save_blockers_[render_view_host]);
3768 power_save_blockers_.erase(render_view_host);
3769}
3770
3771void WebContentsImpl::ClearAllPowerSaveBlockers() {
3772 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3773 i != power_save_blockers_.end(); ++i)
3774 STLDeleteValues(&power_save_blockers_[i->first]);
3775 power_save_blockers_.clear();
3776}
3777
[email protected]dc0fd432013-08-27 15:29:213778gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3779 gfx::Size size;
3780 if (delegate_)
3781 size = delegate_->GetSizeForNewRenderView(this);
3782 if (size.IsEmpty())
3783 size = view_->GetContainerSize();
3784 return size;
3785}
3786
[email protected]9b159a52013-10-03 17:24:553787void WebContentsImpl::OnFrameRemoved(
3788 RenderViewHostImpl* render_view_host,
3789 int64 frame_id) {
3790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3791 FrameDetached(render_view_host, frame_id));
3792}
3793
[email protected]8ff00d72012-10-23 19:12:213794} // namespace content