blob: d3e808ee6095e450c5f4d18352dcd0f839551be4 [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]724159a2010-12-30 01:11:18553 IPC_MESSAGE_UNHANDLED(handled = false)
554 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44555 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18556
557 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21558 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18559 GetRenderProcessHost()->ReceivedBadMessage();
560 }
561
562 return handled;
563}
564
[email protected]b172aee2012-04-10 17:05:26565void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18566 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21567 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43568 if (delegate_)
569 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18570}
571
[email protected]d1198fd2012-08-13 22:50:19572NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56573 return controller_;
574}
575
[email protected]d1198fd2012-08-13 22:50:19576const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56577 return controller_;
578}
579
[email protected]8ff00d72012-10-23 19:12:21580BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55581 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30582}
583
[email protected]b172aee2012-04-10 17:05:26584const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24585 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32586 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51587 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31588}
589
[email protected]a093ce02013-07-22 20:53:14590const GURL& WebContentsImpl::GetVisibleURL() 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]c854a7e2013-05-21 16:42:24593 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
594}
595
596const GURL& WebContentsImpl::GetLastCommittedURL() const {
597 // We may not have a navigation entry yet.
598 NavigationEntry* entry = controller_.GetLastCommittedEntry();
599 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
600}
601
[email protected]8ff00d72012-10-23 19:12:21602WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31603 return delegate_;
604}
605
[email protected]8ff00d72012-10-23 19:12:21606void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31607 // TODO(cbentzel): remove this debugging code?
608 if (delegate == delegate_)
609 return;
610 if (delegate_)
611 delegate_->Detach(this);
612 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08613 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31614 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08615 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00616 if (view_)
617 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08618 }
[email protected]be1f56ab2011-12-22 06:55:31619}
620
[email protected]8ff00d72012-10-23 19:12:21621RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21622 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41623 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16624}
625
[email protected]60eca4eb2013-12-06 00:02:16626RenderFrameHost* WebContentsImpl::GetMainFrame() {
627 return frame_tree_.root()->render_frame_host();
628}
629
[email protected]b172aee2012-04-10 17:05:26630RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21631 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31632}
633
[email protected]a04c9d02012-11-14 21:04:34634void WebContentsImpl::GetRenderViewHostAtPosition(
635 int x,
636 int y,
637 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
638 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
639 if (embedder)
640 embedder->GetRenderViewHostAtPosition(x, y, callback);
641 else
642 callback.Run(GetRenderViewHost(), x, y);
643}
644
[email protected]bfcfa692013-02-07 06:17:02645WebContents* WebContentsImpl::GetEmbedderWebContents() const {
646 BrowserPluginGuest* guest = GetBrowserPluginGuest();
647 if (guest)
648 return guest->embedder_web_contents();
649 return NULL;
650}
651
652int WebContentsImpl::GetEmbeddedInstanceID() const {
653 BrowserPluginGuest* guest = GetBrowserPluginGuest();
654 if (guest)
655 return guest->instance_id();
656 return 0;
657}
658
[email protected]6b618e62012-08-16 12:59:18659int WebContentsImpl::GetRoutingID() const {
660 if (!GetRenderViewHost())
661 return MSG_ROUTING_NONE;
662
663 return GetRenderViewHost()->GetRoutingID();
664}
665
[email protected]44470a22013-01-24 01:21:54666int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
667 return fullscreen_widget_routing_id_;
668}
669
[email protected]b172aee2012-04-10 17:05:26670RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21671 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31672}
673
[email protected]f8497342013-02-05 22:15:02674RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
675 BrowserPluginGuest* guest = GetBrowserPluginGuest();
676 if (guest && guest->embedder_web_contents()) {
677 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
678 }
679 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
680}
681
[email protected]4aebbca2013-09-17 22:26:49682RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
683 const {
684 RenderWidgetHost* const widget_host =
685 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
686 GetFullscreenWidgetRoutingID());
687 return widget_host ? widget_host->GetView() : NULL;
688}
689
[email protected]8ff00d72012-10-23 19:12:21690WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31691 return view_.get();
692}
693
[email protected]8ff00d72012-10-23 19:12:21694WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56695 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03696 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
697 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22698 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58699 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22700 web_ui->SetController(controller);
701 return web_ui;
702 }
703
704 delete web_ui;
705 return NULL;
706}
707
[email protected]8ff00d72012-10-23 19:12:21708WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21709 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
710 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31711}
712
[email protected]8ff00d72012-10-23 19:12:21713WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21714 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34715}
716
[email protected]86ef6a392012-05-11 22:03:11717void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22718 if (GetUserAgentOverride() == override)
719 return;
720
721 renderer_preferences_.user_agent_override = override;
722
723 // Send the new override string to the renderer.
724 RenderViewHost* host = GetRenderViewHost();
725 if (host)
726 host->SyncRendererPrefs();
727
728 // Reload the page if a load is currently in progress to avoid having
729 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27730 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22731 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
732 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53733
734 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
735 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11736}
737
738const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22739 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11740}
741
[email protected]c73a2282013-04-29 21:10:41742#if defined(OS_WIN) && defined(USE_AURA)
743void WebContentsImpl::SetParentNativeViewAccessible(
744gfx::NativeViewAccessible accessible_parent) {
745 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45746 if (GetRenderViewHost())
747 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41748}
749#endif
750
[email protected]fcf75d42013-12-03 20:11:26751const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55752 // Transient entries take precedence. They are used for interstitial pages
753 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23754 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08755 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21756 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30757 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23758 if (entry) {
[email protected]b5cca982011-05-26 04:42:08759 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23760 }
[email protected]fa944cb82013-11-15 17:51:21761 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
762 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58763 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54764 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32765 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54766 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35767 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26768 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54769 if (!title.empty())
770 return title;
771 }
772 }
773
774 // We use the title for the last committed entry rather than a pending
775 // navigation entry. For example, when the user types in a URL, we want to
776 // keep the old page's title until the new load has committed and we get a new
777 // title.
[email protected]96d185d2009-04-24 03:28:54778 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32779
[email protected]9eeafc012013-11-25 23:49:47780 // We make an exception for initial navigations.
781 if (controller_.IsInitialNavigation()) {
782 // We only want to use the title from the visible entry in one of two cases:
783 // 1. There's already a committed entry for an initial navigation, in which
784 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
785 // 2. The pending entry has been explicitly assigned a title to display.
786 //
787 // If there's no last committed entry and no assigned title, we should fall
788 // back to |page_title_when_no_navigation_entry_| rather than showing the
789 // URL.
790 if (entry ||
791 (controller_.GetVisibleEntry() &&
792 !controller_.GetVisibleEntry()->GetTitle().empty())) {
793 entry = controller_.GetVisibleEntry();
794 }
795 }
[email protected]59167c22013-06-03 18:07:32796
[email protected]45d0ef7f2011-01-05 13:46:23797 if (entry) {
[email protected]b5cca982011-05-26 04:42:08798 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23799 }
[email protected]987fc3a2011-05-26 14:18:09800
801 // |page_title_when_no_navigation_entry_| is finally used
802 // if no title cannot be retrieved.
803 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54804}
805
[email protected]b172aee2012-04-10 17:05:26806int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46807 return GetMaxPageIDForSiteInstance(GetSiteInstance());
808}
809
[email protected]b172aee2012-04-10 17:05:26810int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
811 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33812 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
813 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46814
[email protected]b6583592012-01-25 19:52:33815 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34816}
817
[email protected]b172aee2012-04-10 17:05:26818void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46819 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
820}
821
[email protected]b172aee2012-04-10 17:05:26822void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33823 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46824 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33825 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34826}
827
[email protected]ec6c05f2013-10-23 18:41:57828void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
829 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
830 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57831}
832
[email protected]b172aee2012-04-10 17:05:26833SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21834 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54835}
836
[email protected]b172aee2012-04-10 17:05:26837SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21838 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
839 GetRenderManager()->pending_render_view_host() :
840 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58841 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38842}
843
[email protected]b172aee2012-04-10 17:05:26844bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49846}
847
[email protected]b172aee2012-04-10 17:05:26848bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return waiting_for_response_;
850}
851
[email protected]b172aee2012-04-10 17:05:26852const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31853 return load_state_;
854}
855
[email protected]fcf75d42013-12-03 20:11:26856const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31857 return load_state_host_;
858}
859
[email protected]b172aee2012-04-10 17:05:26860uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31861 return upload_size_;
862}
863
[email protected]b172aee2012-04-10 17:05:26864uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return upload_position_;
866}
867
[email protected]1ae93fb2013-06-14 03:38:56868std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56869 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55870 frame_tree_.ForEach(Bind(&CollectSites,
871 base::Unretained(GetBrowserContext()),
872 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56873 return sites;
874}
875
[email protected]b172aee2012-04-10 17:05:26876const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31877 return encoding_;
878}
879
[email protected]b172aee2012-04-10 17:05:26880bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31881 return displayed_insecure_content_;
882}
883
[email protected]54597982013-02-06 01:59:55884void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25885 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55886 ++capturer_count_;
887 DVLOG(1) << "There are now " << capturer_count_
888 << " capturing(s) of WebContentsImpl@" << this;
889}
890
891void WebContentsImpl::DecrementCapturerCount() {
892 --capturer_count_;
893 DVLOG(1) << "There are now " << capturer_count_
894 << " capturing(s) of WebContentsImpl@" << this;
895 DCHECK_LE(0, capturer_count_);
896
[email protected]5a652232013-02-12 06:15:25897 if (is_being_destroyed_)
898 return;
899
[email protected]1ac10dca2013-08-20 20:47:04900 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55901 DVLOG(1) << "Executing delayed WasHidden().";
902 WasHidden();
903 }
[email protected]be1f56ab2011-12-22 06:55:31904}
905
[email protected]f2bd40812013-07-20 04:30:44906int WebContentsImpl::GetCapturerCount() const {
907 return capturer_count_;
908}
909
[email protected]b172aee2012-04-10 17:05:26910bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31911 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
912 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
913 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49914}
915
[email protected]b172aee2012-04-10 17:05:26916void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
917 int error_code) {
[email protected]443b80e2010-12-14 00:42:23918 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34919 return;
920
[email protected]443b80e2010-12-14 00:42:23921 crashed_status_ = status;
922 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21923 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34924}
925
[email protected]b172aee2012-04-10 17:05:26926base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return crashed_status_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31931 return is_being_destroyed_;
932}
933
[email protected]b172aee2012-04-10 17:05:26934void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34935 if (delegate_)
936 delegate_->NavigationStateChanged(this, changed_flags);
937}
938
[email protected]3e324142012-06-25 18:26:33939base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
940 return last_selected_time_;
941}
942
[email protected]9e2e4632012-07-27 16:38:41943void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54944 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04945 RenderWidgetHostViewPort* rwhv =
946 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16947 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29948 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43949#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16950 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43951#endif
952 }
[email protected]96d185d2009-04-24 03:28:54953
[email protected]5ac20162010-11-24 23:33:11954 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38955
[email protected]b9769d82012-02-10 00:23:59956 // The resize rect might have changed while this was inactive -- send the new
957 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58958 RenderViewHostImpl* rvh =
959 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59960 if (rvh) {
961 rvh->ResizeRectChanged(GetRootWindowResizerRect());
962 }
[email protected]96d185d2009-04-24 03:28:54963
[email protected]c0d9d5672013-10-09 07:38:03964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
965
[email protected]54597982013-02-06 01:59:55966 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31967}
968
[email protected]b172aee2012-04-10 17:05:26969void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55970 // If there are entities capturing screenshots or video (e.g., mirroring),
971 // don't activate the "disable rendering" optimization.
972 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52973 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55974 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26975 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52976 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33977 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52978 // calls us).
[email protected]c30585c2012-02-16 15:02:04979 RenderWidgetHostViewPort* rwhv =
980 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16981 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29982 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54983 }
984
[email protected]c0d9d5672013-10-09 07:38:03985 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
986
[email protected]54597982013-02-06 01:59:55987 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37988}
989
[email protected]b172aee2012-04-10 17:05:26990bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31991 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27992 return WillNotifyDisconnection() &&
993 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58994 !static_cast<RenderViewHostImpl*>(
995 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21999 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401000 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271001}
1002
[email protected]b172aee2012-04-10 17:05:261003WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441004 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451005 // We pass our own opener so that the cloned page can access it if it was
1006 // before.
[email protected]54944cde2012-12-09 09:24:591007 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451008 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591009 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191010 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221011 FOR_EACH_OBSERVER(WebContentsObserver,
1012 observers_,
1013 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271014 return tc;
1015}
1016
[email protected]14392a52012-05-02 20:28:441017void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211018 const NotificationSource& source,
1019 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441020 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211021 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1022 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501023 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1024 i != pending_widget_views_.end(); ++i) {
1025 if (host->GetView() == i->second) {
1026 pending_widget_views_.erase(i);
1027 break;
1028 }
1029 }
1030 break;
1031 }
[email protected]14392a52012-05-02 20:28:441032 default:
1033 NOTREACHED();
1034 }
1035}
1036
[email protected]ec6c05f2013-10-23 18:41:571037WebContents* WebContentsImpl::GetWebContents() {
1038 return this;
1039}
1040
[email protected]54944cde2012-12-09 09:24:591041void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211042 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361043 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211044 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431045 should_normally_be_visible_ = !params.initially_hidden;
1046
[email protected]fa944cb82013-11-15 17:51:211047 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041048 params.browser_context, params.site_instance, params.routing_id,
1049 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191050
[email protected]8ff00d72012-10-23 19:12:211051 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191052 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271053 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191054 CHECK(render_view_host_delegate_view_);
1055 } else {
[email protected]f8497342013-02-05 22:15:021056 WebContentsViewDelegate* delegate =
1057 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1058
[email protected]59383c782013-04-17 16:43:271059 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381060 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1061 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021062
[email protected]b5a40842012-11-28 15:26:111063 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381064 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431065 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111066 render_view_host_delegate_view_ = rv;
1067 view_.reset(rv);
1068 } else {
[email protected]f8497342013-02-05 22:15:021069 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111070 view_.reset(CreateWebContentsView(
1071 this, delegate, &render_view_host_delegate_view_));
1072 }
[email protected]d1198fd2012-08-13 22:50:191073 CHECK(render_view_host_delegate_view_);
1074 }
1075 CHECK(view_.get());
1076
[email protected]ed245db2012-12-18 08:00:451077 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591078 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191079
1080 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101081 if (opener_)
1082 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191083
1084 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211085 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1086 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441087#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191088 java_bridge_dispatcher_host_manager_.reset(
1089 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101090 date_time_chooser_.reset(new DateTimeChooserAndroid());
1091#endif
[email protected]d1198fd2012-08-13 22:50:191092}
1093
[email protected]7fff43e2013-05-21 20:21:101094void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1095 RemoveDestructionObserver(web_contents);
1096
[email protected]14392a52012-05-02 20:28:441097 // Clear the opener if it has been closed.
1098 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441099 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511100 return;
[email protected]14392a52012-05-02 20:28:441101 }
[email protected]ceee8cd2013-03-08 04:59:511102 // Clear a pending contents that has been closed before being shown.
1103 for (PendingContents::iterator iter = pending_contents_.begin();
1104 iter != pending_contents_.end();
1105 ++iter) {
1106 if (iter->second != web_contents)
1107 continue;
1108 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511109 return;
1110 }
1111 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441112}
1113
[email protected]7fff43e2013-05-21 20:21:101114void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1115 if (!ContainsKey(destruction_observers_, web_contents)) {
1116 destruction_observers_[web_contents] =
1117 new DestructionObserver(this, web_contents);
1118 }
1119}
1120
1121void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1122 DestructionObservers::iterator iter =
1123 destruction_observers_.find(web_contents);
1124 if (iter != destruction_observers_.end()) {
1125 delete destruction_observers_[web_contents];
1126 destruction_observers_.erase(iter);
1127 }
1128}
1129
[email protected]b172aee2012-04-10 17:05:261130void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311131 observers_.AddObserver(observer);
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311135 observers_.RemoveObserver(observer);
1136}
1137
[email protected]b172aee2012-04-10 17:05:261138void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341139 if (delegate_)
1140 delegate_->ActivateContents(this);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121144 if (delegate_)
1145 delegate_->DeactivateContents(this);
1146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481149 if (delegate_)
1150 delegate_->LostCapture();
1151}
1152
[email protected]b24b68a2012-09-24 21:57:261153void WebContentsImpl::RenderWidgetDeleted(
1154 RenderWidgetHostImpl* render_widget_host) {
1155 if (is_being_destroyed_) {
1156 // |created_widgets_| might have been destroyed.
1157 return;
1158 }
1159
1160 std::set<RenderWidgetHostImpl*>::iterator iter =
1161 created_widgets_.find(render_widget_host);
1162 if (iter != created_widgets_.end())
1163 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541164
1165 if (render_widget_host &&
1166 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491167 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1168 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541169 FOR_EACH_OBSERVER(WebContentsObserver,
1170 observers_,
1171 DidDestroyFullscreenWidget(
1172 fullscreen_widget_routing_id_));
1173 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1174 }
[email protected]b24b68a2012-09-24 21:57:261175}
1176
[email protected]b172aee2012-04-10 17:05:261177bool WebContentsImpl::PreHandleKeyboardEvent(
1178 const NativeWebKeyboardEvent& event,
1179 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481180 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131181 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481182}
1183
[email protected]b172aee2012-04-10 17:05:261184void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061185 if (browser_plugin_embedder_ &&
1186 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1187 return;
1188 }
1189
[email protected]63954792011-07-11 04:17:481190 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131191 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481192}
1193
[email protected]fb3f066e2013-02-12 19:12:521194bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461195 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191196#if !defined(OS_MACOSX)
1197 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1198 // isn't done for two reasons:
1199 // -the OS already has a gesture to do this through pinch-zoom
1200 // -if a user starts an inertial scroll, let's go, and presses control
1201 // (i.e. control+tab) then the OS's buffered scroll events will come in
1202 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521203 if (delegate_ &&
1204 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461205 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521206 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1207 return true;
1208 }
[email protected]bccc4472013-04-18 16:37:191209#endif
[email protected]fb3f066e2013-02-12 19:12:521210
1211 return false;
1212}
1213
[email protected]c73a2282013-04-29 21:10:411214#if defined(OS_WIN) && defined(USE_AURA)
1215gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1216 return accessible_parent_;
1217}
1218#endif
1219
[email protected]b172aee2012-04-10 17:05:261220void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431221 if (delegate_)
1222 delegate_->HandleMouseDown();
1223}
1224
[email protected]b172aee2012-04-10 17:05:261225void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481226 if (delegate_)
1227 delegate_->HandleMouseUp();
1228}
1229
[email protected]590a634e2012-07-19 16:38:231230void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481231 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231232 delegate_->HandlePointerActivate();
1233}
1234
1235void WebContentsImpl::HandleGestureBegin() {
1236 if (delegate_)
1237 delegate_->HandleGestureBegin();
1238}
1239
1240void WebContentsImpl::HandleGestureEnd() {
1241 if (delegate_)
1242 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481243}
1244
[email protected]b172aee2012-04-10 17:05:261245void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491246 // This method is being called to enter or leave renderer-initiated fullscreen
1247 // mode. Either way, make sure any existing fullscreen widget is shut down
1248 // first.
1249 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1250 if (widget_view)
1251 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1252
[email protected]8a5e0ca2011-08-25 06:30:471253 if (delegate_)
1254 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1255}
1256
[email protected]b172aee2012-04-10 17:05:261257bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381258 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121259}
1260
[email protected]a9c81f02012-06-01 00:15:441261void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1262 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371263 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441264 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371265 } else {
1266 GotResponseToLockMouseRequest(false);
1267 }
1268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371271 if (delegate_)
1272 delegate_->LostMouseLock();
1273}
1274
[email protected]bafe6cd2012-05-23 23:09:501275void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201276 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501277 int route_id,
[email protected]227692c52013-05-31 22:43:041278 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131279 const ViewHostMsg_CreateWindow_Params& params,
1280 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501281 // We usually create the new window in the same BrowsingInstance (group of
1282 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551283 // if the opener is being suppressed (in a non-guest), we create a new
1284 // SiteInstance in its own BrowsingInstance.
1285 bool is_guest = GetRenderProcessHost()->IsGuest();
1286
[email protected]04cbd3d2013-12-04 04:58:201287 // If the opener is to be suppressed, the new window can be in any process.
1288 // Since routing ids are process specific, we must not have one passed in
1289 // as argument here.
1290 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1291
[email protected]bafe6cd2012-05-23 23:09:501292 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551293 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571294 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501295 GetSiteInstance();
1296
[email protected]04cbd3d2013-12-04 04:58:201297 // A message to create a new window can only come from the active process for
1298 // this WebContentsImpl instance. If any other process sends the request,
1299 // it is invalid and the process must be terminated.
1300 if (GetRenderProcessHost()->GetID() != render_process_id) {
1301 base::ProcessHandle process_handle =
1302 RenderProcessHost::FromID(render_process_id)->GetHandle();
1303 if (process_handle != base::kNullProcessHandle) {
1304 RecordAction(
1305 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1306 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1307 }
1308 return;
1309 }
1310
[email protected]d1198fd2012-08-13 22:50:191311 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341312 //
1313 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301314 const std::string& partition_id =
1315 GetContentClient()->browser()->
1316 GetStoragePartitionIdForSite(GetBrowserContext(),
1317 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461318 StoragePartition* partition = BrowserContext::GetStoragePartition(
1319 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411320 DOMStorageContextWrapper* dom_storage_context =
1321 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191322 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1323 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1324 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371325
1326 if (delegate_ &&
1327 !delegate_->ShouldCreateWebContents(this,
1328 route_id,
1329 params.window_container_type,
1330 params.frame_name,
1331 params.target_url,
1332 partition_id,
1333 session_storage_namespace)) {
1334 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1335 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1336 main_frame_route_id);
1337 return;
1338 }
1339
1340 // Create the new web contents. This will automatically create the new
1341 // WebContentsView. In the future, we may want to create the view separately.
1342 WebContentsImpl* new_contents =
1343 new WebContentsImpl(GetBrowserContext(),
1344 params.opener_suppressed ? NULL : this);
1345
[email protected]d1198fd2012-08-13 22:50:191346 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301347 partition_id,
[email protected]d1198fd2012-08-13 22:50:191348 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461349 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591350 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041351 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551352 if (!is_guest) {
1353 create_params.context = view_->GetNativeView();
1354 create_params.initial_size = view_->GetContainerSize();
1355 } else {
1356 // This makes |new_contents| act as a guest.
1357 // For more info, see comment above class BrowserPluginGuest.
1358 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1359 WebContentsImpl* new_contents_impl =
1360 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461361 BrowserPluginGuest::CreateWithOpener(instance_id,
1362 new_contents_impl->opener() != NULL,
1363 new_contents_impl,
1364 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551365 }
[email protected]1ac10dca2013-08-20 20:47:041366 if (params.disposition == NEW_BACKGROUND_TAB)
1367 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591368 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191369
[email protected]c4538072013-03-18 02:17:551370 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341371 // will be shown immediately).
1372 if (!params.opener_suppressed) {
1373 if (!is_guest) {
1374 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501375
[email protected]d70bea92013-04-05 04:23:341376 // TODO(brettw): It seems bogus that we have to call this function on the
1377 // newly created object and give it one of its own member variables.
1378 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1379 }
[email protected]bafe6cd2012-05-23 23:09:501380 // Save the created window associated with the route so we can show it
1381 // later.
1382 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1383 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101384 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501385 }
1386
1387 if (delegate_) {
1388 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131389 this, params.opener_frame_id, params.frame_name,
1390 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501391 }
1392
1393 if (params.opener_suppressed) {
1394 // When the opener is suppressed, the original renderer cannot access the
1395 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001396 bool was_blocked = false;
1397 if (delegate_) {
1398 gfx::Rect initial_pos;
1399 delegate_->AddNewContents(
1400 this, new_contents, params.disposition, initial_pos,
1401 params.user_gesture, &was_blocked);
1402 }
1403 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211404 OpenURLParams open_params(params.target_url,
1405 Referrer(),
1406 CURRENT_TAB,
1407 PAGE_TRANSITION_LINK,
1408 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301409 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001410 new_contents->OpenURL(open_params);
1411 }
[email protected]bafe6cd2012-05-23 23:09:501412 }
1413}
1414
[email protected]a8504022013-12-04 20:23:511415void WebContentsImpl::CreateNewWidget(int render_process_id,
1416 int route_id,
[email protected]180ef242013-11-07 06:50:461417 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511418 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501419}
1420
[email protected]a8504022013-12-04 20:23:511421void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1422 int route_id) {
1423 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501424}
1425
[email protected]a8504022013-12-04 20:23:511426void WebContentsImpl::CreateNewWidget(int render_process_id,
1427 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501428 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461429 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211430 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511431 // A message to create a new widget can only come from the active process for
1432 // this WebContentsImpl instance. If any other process sends the request,
1433 // it is invalid and the process must be terminated.
1434 if (process->GetID() != render_process_id) {
1435 base::ProcessHandle process_handle =
1436 RenderProcessHost::FromID(render_process_id)->GetHandle();
1437 if (process_handle != base::kNullProcessHandle) {
1438 RecordAction(
1439 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1440 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1441 }
1442 return;
1443 }
1444
[email protected]bafe6cd2012-05-23 23:09:501445 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041446 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261447 created_widgets_.insert(widget_host);
1448
[email protected]83918ec2013-01-10 15:37:191449 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1450 view_->CreateViewForPopupWidget(widget_host));
1451 if (!widget_view)
1452 return;
[email protected]bafe6cd2012-05-23 23:09:501453 if (!is_fullscreen) {
1454 // Popups should not get activated.
1455 widget_view->SetPopupType(popup_type);
1456 }
1457 // Save the created widget associated with the route so we can show it later.
1458 pending_widget_views_[route_id] = widget_view;
1459
1460#if defined(OS_MACOSX)
1461 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1462 // to allow it to survive the trip without being hosted.
1463 base::mac::NSObjectRetain(widget_view->GetNativeView());
1464#endif
1465}
1466
1467void WebContentsImpl::ShowCreatedWindow(int route_id,
1468 WindowOpenDisposition disposition,
1469 const gfx::Rect& initial_pos,
1470 bool user_gesture) {
1471 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001472 if (contents) {
1473 WebContentsDelegate* delegate = GetDelegate();
1474 if (delegate) {
1475 delegate->AddNewContents(
1476 this, contents, disposition, initial_pos, user_gesture, NULL);
1477 }
1478 }
[email protected]bafe6cd2012-05-23 23:09:501479}
1480
1481void WebContentsImpl::ShowCreatedWidget(int route_id,
1482 const gfx::Rect& initial_pos) {
1483 ShowCreatedWidget(route_id, false, initial_pos);
1484}
1485
1486void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1487 ShowCreatedWidget(route_id, true, gfx::Rect());
1488}
1489
1490void WebContentsImpl::ShowCreatedWidget(int route_id,
1491 bool is_fullscreen,
1492 const gfx::Rect& initial_pos) {
1493 if (delegate_)
1494 delegate_->RenderWidgetShowing();
1495
1496 RenderWidgetHostViewPort* widget_host_view =
1497 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1498 if (!widget_host_view)
1499 return;
[email protected]4aebbca2013-09-17 22:26:491500 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311501 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1502 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491503 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1504 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1505 delegate_->ToggleFullscreenModeForTab(this, true);
1506 } else {
1507 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491508 }
[email protected]4aebbca2013-09-17 22:26:491509 FOR_EACH_OBSERVER(WebContentsObserver,
1510 observers_,
1511 DidShowFullscreenWidget(route_id));
1512 if (!widget_host_view->HasFocus())
1513 widget_host_view->Focus();
1514 } else {
[email protected]f8497342013-02-05 22:15:021515 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491516 }
[email protected]89054502012-06-03 10:29:241517
1518 RenderWidgetHostImpl* render_widget_host_impl =
1519 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1520 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311521 // Only allow privileged mouse lock for fullscreen render widget, which is
1522 // used to implement Pepper Flash fullscreen.
1523 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501524
1525#if defined(OS_MACOSX)
1526 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1527 // properly embedded (or purposefully ignored) we can release the retain we
1528 // took in CreateNewWidget().
1529 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1530#endif
1531}
1532
1533WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1534 PendingContents::iterator iter = pending_contents_.find(route_id);
1535
1536 // Certain systems can block the creation of new windows. If we didn't succeed
1537 // in creating one, just return NULL.
1538 if (iter == pending_contents_.end()) {
1539 return NULL;
1540 }
1541
1542 WebContentsImpl* new_contents = iter->second;
1543 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101544 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501545
[email protected]d70bea92013-04-05 04:23:341546 // Don't initialize the guest WebContents immediately.
1547 if (new_contents->GetRenderProcessHost()->IsGuest())
1548 return new_contents;
1549
[email protected]bafe6cd2012-05-23 23:09:501550 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1551 !new_contents->GetRenderViewHost()->GetView())
1552 return NULL;
1553
1554 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1555 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1556 return new_contents;
1557}
1558
1559RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1560 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1561 if (iter == pending_widget_views_.end()) {
1562 DCHECK(false);
1563 return NULL;
1564 }
1565
1566 RenderWidgetHostView* widget_host_view = iter->second;
1567 pending_widget_views_.erase(route_id);
1568
1569 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1570 if (!widget_host->GetProcess()->HasConnection()) {
1571 // The view has gone away or the renderer crashed. Nothing to do.
1572 return NULL;
1573 }
1574
1575 return widget_host_view;
1576}
1577
[email protected]f56c7872013-06-18 12:31:571578void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501579 // Allow WebContentsDelegates to handle the context menu operation first.
1580 if (delegate_ && delegate_->HandleContextMenu(params))
1581 return;
1582
[email protected]f56c7872013-06-18 12:31:571583 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501584}
1585
[email protected]f13b4202012-06-12 23:53:231586void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091587 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211588 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231589 if (delegate_)
1590 delegate_->RequestMediaAccessPermission(this, request, callback);
1591 else
[email protected]b5f76742013-04-29 15:05:591592 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231593}
1594
[email protected]cc9200432013-07-23 23:02:401595SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1596 SiteInstance* instance) {
1597 return controller_.GetSessionStorageNamespace(instance);
1598}
1599
[email protected]9b159a52013-10-03 17:24:551600FrameTree* WebContentsImpl::GetFrameTree() {
1601 return &frame_tree_;
1602}
1603
[email protected]32deec62013-05-15 23:55:041604void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1605 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441606 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041607}
1608
[email protected]b172aee2012-04-10 17:05:261609void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231610 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331611 if (delegate_)
1612 delegate_->UpdatePreferredSize(this, pref_size);
1613}
1614
[email protected]b172aee2012-04-10 17:05:261615void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341616 if (delegate_)
1617 delegate_->ResizeDueToAutoResize(this, new_size);
1618}
1619
[email protected]b172aee2012-04-10 17:05:261620WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201621 if (!delegate_)
1622 return NULL;
[email protected]00c37fc2011-08-02 00:22:501623
[email protected]e5d549d2011-12-28 01:29:201624 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201625 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341626}
1627
[email protected]6b618e62012-08-16 12:59:181628bool WebContentsImpl::Send(IPC::Message* message) {
1629 if (!GetRenderViewHost()) {
1630 delete message;
1631 return false;
1632 }
1633
1634 return GetRenderViewHost()->Send(message);
1635}
1636
[email protected]b172aee2012-04-10 17:05:261637bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501638 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251639 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231640 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251641 reload_type);
[email protected]876bc832010-09-07 16:29:541642}
[email protected]96d185d2009-04-24 03:28:541643
[email protected]ba45bfd2012-05-22 21:51:441644void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211645 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441646 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1647 RenderViewForInterstitialPageCreated(render_view_host));
1648}
1649
[email protected]20ca0382013-02-28 19:50:071650void WebContentsImpl::AttachInterstitialPage(
1651 InterstitialPageImpl* interstitial_page) {
1652 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211653 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291654
1655 // Cancel any visible dialogs so that they don't interfere with the
1656 // interstitial.
1657 if (dialog_manager_)
1658 dialog_manager_->CancelActiveAndPendingDialogs(this);
1659
[email protected]20ca0382013-02-28 19:50:071660 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1661 DidAttachInterstitialPage());
1662}
1663
1664void WebContentsImpl::DetachInterstitialPage() {
1665 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211666 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1668 DidDetachInterstitialPage());
1669}
1670
[email protected]b172aee2012-04-10 17:05:261671bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231672 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501673 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031674 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1675
[email protected]19e81142011-10-03 16:19:401676 // The renderer will reject IPC messages with URLs longer than
1677 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431678 if (entry.GetURL().spec().size() > kMaxURLChars) {
1679 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1680 << " characters.";
[email protected]19e81142011-10-03 16:19:401681 return false;
[email protected]3adab1c2013-09-09 21:23:431682 }
[email protected]19e81142011-10-03 16:19:401683
[email protected]c80297782013-11-21 07:10:161684 // TODO(creis): Use entry->frame_tree_node_id() to pick which
[email protected]b0936d22013-11-28 06:47:361685 // RenderFrameHostManager to use.
[email protected]9f76c1e2012-03-05 15:15:581686 RenderViewHostImpl* dest_render_view_host =
[email protected]fa944cb82013-11-15 17:51:211687 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401688 if (!dest_render_view_host)
1689 return false; // Unable to create the desired render view host.
1690
[email protected]80a8fad2011-01-29 04:02:381691 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071692 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581693 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271694 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501695 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031696 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1697 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211698 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231699 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271700 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211701 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231702 CHECK(0);
1703 }
[email protected]54ec6472010-04-09 19:39:581704
[email protected]7bb761892012-07-20 09:32:471705 // Notify observers that we will navigate in this RV.
1706 FOR_EACH_OBSERVER(WebContentsObserver,
1707 observers_,
1708 AboutToNavigateRenderView(dest_render_view_host));
1709
[email protected]96d185d2009-04-24 03:28:541710 // Used for page load time metrics.
1711 current_load_start_ = base::TimeTicks::Now();
1712
1713 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341714 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271715 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471716 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341717 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541718
[email protected]36fc0392011-12-25 03:59:511719 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541720 // HACK!! This code suppresses javascript: URLs from being added to
1721 // session history, which is what we want to do for javascript: URLs that
1722 // do not generate content. What we really need is a message from the
1723 // renderer telling us that a new page was not created. The same message
1724 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351725 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541726 return false;
1727 }
1728
[email protected]3c9e1872010-11-18 16:17:491729 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391730 FOR_EACH_OBSERVER(
1731 WebContentsObserver,
1732 observers_,
1733 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541734
[email protected]09b29342011-06-24 19:18:481735 if (delegate_)
1736 delegate_->DidNavigateToPendingEntry(this);
1737
[email protected]d5f942ba2008-09-26 19:30:341738 return true;
1739}
1740
[email protected]b172aee2012-04-10 17:05:261741void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331742 const SiteInstance* site_instance,
1743 int history_length,
1744 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411745 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1746 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211747 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191748 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141749 return;
[email protected]9e1ad4b2011-08-14 16:49:191750 }
[email protected]9f76c1e2012-03-05 15:15:581751 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191752 if (!rvh) {
1753 NOTREACHED();
1754 return;
1755 }
[email protected]9f76c1e2012-03-05 15:15:581756 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191757 NOTREACHED();
1758 return;
1759 }
[email protected]6b618e62012-08-16 12:59:181760 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1761 history_length,
1762 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141763}
1764
[email protected]b172aee2012-04-10 17:05:261765void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271766 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211767 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541768 return;
1769 }
[email protected]9f76c1e2012-03-05 15:15:581770 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541771}
1772
[email protected]b172aee2012-04-10 17:05:261773bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211774 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541775}
1776
[email protected]b172aee2012-04-10 17:05:261777InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211778 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221779}
1780
[email protected]b172aee2012-04-10 17:05:261781bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161782 // WebKit creates Document object when MIME type is application/xhtml+xml,
1783 // so we also support this MIME type.
1784 return contents_mime_type_ == "text/html" ||
1785 contents_mime_type_ == "text/xml" ||
1786 contents_mime_type_ == "application/xhtml+xml" ||
1787 contents_mime_type_ == "text/plain" ||
1788 contents_mime_type_ == "text/css" ||
1789 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1790}
1791
[email protected]b172aee2012-04-10 17:05:261792void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591793 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161794 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551795 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011796 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141797 return;
[email protected]c7dd2f62011-07-18 15:57:591798 }
1799
1800 Stop();
1801
1802 // Create the save package and possibly prompt the user for the name to save
1803 // the page as. The user prompt is an asynchronous operation that runs on
1804 // another thread.
1805 save_package_ = new SavePackage(this);
1806 save_package_->GetSaveInfo();
1807}
1808
1809// Used in automated testing to bypass prompting the user for file names.
1810// Instead, the names and paths are hard coded rather than running them through
1811// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341812bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1813 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211814 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591815 // Stop the page from navigating.
1816 Stop();
1817
1818 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211819 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591820}
1821
[email protected]3c71576ce2013-07-23 02:00:011822void WebContentsImpl::SaveFrame(const GURL& url,
1823 const Referrer& referrer) {
1824 if (!GetURL().is_valid())
1825 return;
1826 bool is_main_frame = (url == GetURL());
1827
1828 DownloadManager* dlm =
1829 BrowserContext::GetDownloadManager(GetBrowserContext());
1830 if (!dlm)
1831 return;
1832 int64 post_id = -1;
1833 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271834 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011835 if (entry)
1836 post_id = entry->GetPostID();
1837 }
1838 scoped_ptr<DownloadUrlParameters> params(
1839 DownloadUrlParameters::FromWebContents(this, url));
1840 params->set_referrer(referrer);
1841 params->set_post_id(post_id);
1842 params->set_prefer_cache(true);
1843 if (post_id >= 0)
1844 params->set_method("POST");
1845 params->set_prompt(true);
1846 dlm->DownloadUrl(params.Pass());
1847}
1848
[email protected]b172aee2012-04-10 17:05:261849void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341850 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481851 const base::Callback<void(int64)>& callback) {
1852 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121853}
1854
[email protected]6286a372013-10-09 04:03:271855// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261856bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271857 NavigationEntryImpl* visible_entry =
1858 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1859 return (visible_entry != NULL &&
1860 visible_entry->site_instance() == GetSiteInstance() &&
1861 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321862}
1863
[email protected]b172aee2012-04-10 17:05:261864const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271865 return contents_mime_type_;
1866}
1867
[email protected]b172aee2012-04-10 17:05:261868bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271869 return notify_disconnection_;
1870}
1871
[email protected]b172aee2012-04-10 17:05:261872void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311873 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181874 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161875}
1876
[email protected]b172aee2012-04-10 17:05:261877void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311878 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181879 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161880}
1881
[email protected]8ff00d72012-10-23 19:12:211882RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271883 return &renderer_preferences_;
1884}
1885
[email protected]e35ccd52012-05-23 16:22:471886void WebContentsImpl::Close() {
1887 Close(GetRenderViewHost());
1888}
1889
[email protected]cf200a562013-05-03 16:24:291890void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461891 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291892 if (browser_plugin_embedder_.get())
1893 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1894 screen_x, screen_y, operation);
1895 if (GetRenderViewHost())
1896 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1897 screen_x, screen_y, operation);
1898}
1899
1900void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1901 int screen_x, int screen_y) {
1902 if (browser_plugin_embedder_.get())
1903 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1904 screen_x, screen_y);
1905 if (GetRenderViewHost())
1906 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1907 screen_x, screen_y);
1908}
1909
[email protected]b172aee2012-04-10 17:05:261910void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521911 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581912 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511913 if (delegate_)
1914 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291915 if (browser_plugin_embedder_.get())
1916 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341917}
1918
[email protected]e35ccd52012-05-23 16:22:471919void WebContentsImpl::UserGestureDone() {
1920 OnUserGesture();
1921}
1922
[email protected]b172aee2012-04-10 17:05:261923void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271924 closed_by_user_gesture_ = value;
1925}
1926
[email protected]b172aee2012-04-10 17:05:261927bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271928 return closed_by_user_gesture_;
1929}
1930
[email protected]b172aee2012-04-10 17:05:261931double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051932 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561933 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251934 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171935 return 0;
[email protected]b75b8292010-10-01 07:28:251936
1937 double zoom_level;
1938 if (temporary_zoom_settings_) {
1939 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581940 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251941 } else {
[email protected]2ae88d12011-10-14 09:11:191942 GURL url;
[email protected]6286a372013-10-09 04:03:271943 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191944 // Since zoom map is updated using rewritten URL, use rewritten URL
1945 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271946 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021947 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1948 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251949 }
[email protected]d0b8d092010-10-25 04:05:171950 return zoom_level;
1951}
[email protected]b75b8292010-10-01 07:28:251952
[email protected]b172aee2012-04-10 17:05:261953int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591954 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171955 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011956 // Calculate the zoom percent from the factor. Round up to the nearest whole
1957 // number.
[email protected]b75b8292010-10-01 07:28:251958 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491959 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251960 *enable_decrement = percent > minimum_zoom_percent_;
1961 *enable_increment = percent < maximum_zoom_percent_;
1962 return percent;
1963}
1964
[email protected]b172aee2012-04-10 17:05:261965void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501966 if (!delegate_)
1967 return;
1968
[email protected]6286a372013-10-09 04:03:271969 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1970 if (!entry)
[email protected]1788e772010-12-15 16:40:501971 return;
1972
[email protected]6286a372013-10-09 04:03:271973 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121974}
1975
[email protected]b172aee2012-04-10 17:05:261976void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041977 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271978 if (!delegate_)
1979 return;
1980
[email protected]691aa2f2013-05-28 22:52:041981 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271982}
1983
[email protected]b172aee2012-04-10 17:05:261984int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271985 return minimum_zoom_percent_;
1986}
1987
[email protected]b172aee2012-04-10 17:05:261988int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271989 return maximum_zoom_percent_;
1990}
1991
[email protected]b172aee2012-04-10 17:05:261992gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231993 return preferred_size_;
1994}
1995
[email protected]b172aee2012-04-10 17:05:261996bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271997 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581998 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271999}
2000
[email protected]b172aee2012-04-10 17:05:262001bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442002 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502003}
2004
[email protected]cb805452013-05-22 15:16:212005void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182006 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212007 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202008}
2009
[email protected]cb805452013-05-22 15:16:212010void WebContentsImpl::DidEndColorChooser() {
2011 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2012 color_chooser_identifier_));
2013 color_chooser_.reset();
2014 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202015}
2016
[email protected]41225fe2013-03-29 05:32:022017int WebContentsImpl::DownloadImage(const GURL& url,
2018 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302019 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022020 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392021 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302022 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022023 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392024 return id;
2025}
2026
[email protected]b172aee2012-04-10 17:05:262027bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272028 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202029 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332030 return true;
2031 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272032}
2033
[email protected]b172aee2012-04-10 17:05:262034void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272035 if (delegate_)
2036 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212037}
2038
[email protected]52913802013-12-10 05:52:182039void WebContentsImpl::DidStartProvisionalLoad(
2040 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572041 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132042 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572043 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182044 const GURL& validated_url,
2045 bool is_error_page,
2046 bool is_iframe_srcdoc) {
2047 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572048 DidChangeLoadProgress(0);
2049
[email protected]0d60f0192011-04-14 12:40:102050 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252051 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132052 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2053 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182054 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542055
2056 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182057 FOR_EACH_OBSERVER(
2058 WebContentsObserver,
2059 observers_,
2060 ProvisionalChangeToMainFrameUrl(validated_url,
2061 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542062 }
2063}
2064
[email protected]52913802013-12-10 05:52:182065void WebContentsImpl::NotifyChangedNavigationState(
2066 InvalidateTypes changed_flags) {
2067 NotifyNavigationStateChanged(changed_flags);
2068}
2069
[email protected]400992b2012-06-14 00:03:542070void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212071 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542072 int32 page_id,
[email protected]400992b2012-06-14 00:03:542073 const GURL& source_url,
2074 const GURL& target_url) {
2075 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132076 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2077 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542078 GURL validated_source_url(source_url);
2079 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212080 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542081 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082082 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2083 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542084 NavigationEntry* entry;
2085 if (page_id == -1) {
2086 entry = controller_.GetPendingEntry();
2087 } else {
2088 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2089 page_id);
2090 }
2091 if (!entry || entry->GetURL() != validated_source_url)
2092 return;
2093
2094 // Notify observers about the provisional change in the main frame URL.
2095 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2096 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542097 render_view_host));
[email protected]724159a2010-12-30 01:11:182098}
2099
[email protected]54047eb52012-05-08 21:45:572100void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212101 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582102 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2103 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2104 << ", error_code: " << params.error_code
2105 << ", error_description: " << params.error_description
2106 << ", is_main_frame: " << params.is_main_frame
2107 << ", showing_repost_interstitial: " <<
2108 params.showing_repost_interstitial
2109 << ", frame_id: " << params.frame_id;
2110 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212111 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572112 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082113 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182114
[email protected]d7b175e2011-10-11 15:31:582115 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182116 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2117 // This means that the interstitial won't be torn down properly, which is
2118 // bad. But if we have an interstitial, go back to another tab type, and
2119 // then load the same interstitial again, we could end up getting the first
2120 // interstitial's "failed" message (as a result of the cancel) when we're on
2121 // the second one.
2122 //
2123 // We can't tell this apart, so we think we're tearing down the current page
2124 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362125 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182126 // out because of this problem.
2127 //
2128 // http://code.google.com/p/chromium/issues/detail?id=2855
2129 // Because this will not tear down the interstitial properly, if "back" is
2130 // back to another tab type, the interstitial will still be somewhat alive
2131 // in the previous tab type. If you navigate somewhere that activates the
2132 // tab with the interstitial again, you'll see a flash before the new load
2133 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272134 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182135 LOG(WARNING) << "Discarding message during interstitial.";
2136 return;
2137 }
2138
[email protected]fa944cb82013-11-15 17:51:212139 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182140 }
2141
[email protected]b12eb222013-09-10 00:11:482142 // Do not usually clear the pending entry if one exists, so that the user's
2143 // typed URL is not lost when a navigation fails or is aborted. However, in
2144 // cases that we don't show the pending entry (e.g., renderer-initiated
2145 // navigations in an existing tab), we don't keep it around. That prevents
2146 // spoofs on in-page navigations that don't go through
2147 // DidStartProvisionalLoadForFrame.
2148 // In general, we allow the view to clear the pending entry and typed URL if
2149 // the user requests (e.g., hitting Escape with focus in the address bar).
2150 // Note: don't touch the transient entry, since an interstitial may exist.
2151 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2152 controller_.DiscardPendingEntry();
2153
[email protected]d8c660432011-12-22 20:51:252154 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582155 observers_,
2156 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442157 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582158 params.is_main_frame,
2159 validated_url,
2160 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462161 params.error_description,
2162 render_view_host));
[email protected]724159a2010-12-30 01:11:182163}
2164
[email protected]b172aee2012-04-10 17:05:262165void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182166 const GURL& url,
[email protected]70435962011-08-02 20:13:282167 const std::string& security_info,
2168 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182169 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282170 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192171 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182172 cache.Increment();
2173
2174 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082175 int cert_id = 0;
2176 net::CertStatus cert_status = 0;
2177 int security_bits = -1;
2178 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122179 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212180 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122181 &security_bits, &connection_status,
2182 &signed_certificate_timestamp_ids);
2183 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212184 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002185 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2186 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182187
[email protected]b0f724c2013-09-05 04:21:132188 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2189
2190 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2191 DidLoadResourceFromMemoryCache(details));
2192
[email protected]8bfc8272013-09-09 20:10:532193 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2194 scoped_refptr<net::URLRequestContextGetter> request_context(
2195 resource_type == ResourceType::MEDIA ?
2196 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2197 GetRenderProcessHost()->GetID()) :
2198 GetBrowserContext()->GetRequestContextForRenderProcess(
2199 GetRenderProcessHost()->GetID()));
2200 BrowserThread::PostTask(
2201 BrowserThread::IO,
2202 FROM_HERE,
2203 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2204 }
[email protected]724159a2010-12-30 01:11:182205}
2206
[email protected]b172aee2012-04-10 17:05:262207void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212208 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182209 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192210 SSLManager::NotifySSLInternalStateChanged(
2211 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182212}
2213
[email protected]b172aee2012-04-10 17:05:262214void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022215 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582216 LOG(WARNING) << security_origin << " ran insecure content from "
2217 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212218 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412219 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212220 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182221 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412222 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192223 SSLManager::NotifySSLInternalStateChanged(
2224 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442228 FOR_EACH_OBSERVER(
2229 WebContentsObserver, observers_,
2230 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312234 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062235 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312236 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062237 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442238 RenderProcessHost* render_process_host =
2239 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062240 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252241 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472242 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442243 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnDidFailLoadWithError(
2247 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062248 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262249 bool is_main_frame,
2250 int error_code,
[email protected]fcf75d42013-12-03 20:11:262251 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062252 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442253 RenderProcessHost* render_process_host =
2254 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062255 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252256 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312257 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472258 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442259 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182260}
2261
[email protected]b172aee2012-04-10 17:05:262262void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262263 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232264 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252265 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262266 if (!entry)
2267 return;
2268 // Note that we don't call NavigationController::GotToOffset() as we don't
2269 // want to create a pending navigation entry (it might end up lingering
2270 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252271 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212272 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512273 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212274 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472275 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572276
2277 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2278 // it in now that we know. This allows us to find the entry when it commits.
2279 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232280 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332281 entry->set_site_instance(
2282 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572283 }
[email protected]216813952011-05-19 22:21:262284 }
2285}
2286
[email protected]b172aee2012-04-10 17:05:262287void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2288 int maximum_percent,
2289 bool remember) {
[email protected]216813952011-05-19 22:21:262290 minimum_zoom_percent_ = minimum_percent;
2291 maximum_zoom_percent_ = maximum_percent;
2292 temporary_zoom_settings_ = !remember;
2293}
2294
[email protected]b172aee2012-04-10 17:05:262295void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342296 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432297 if (!delegate_)
2298 return;
2299
[email protected]b9535422012-02-09 01:47:592300 ChildProcessSecurityPolicyImpl* policy =
2301 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222302 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592303 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212304}
2305
[email protected]b172aee2012-04-10 17:05:262306void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432307 if (delegate_)
2308 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202309}
2310
[email protected]b172aee2012-04-10 17:05:262311void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2312 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262313 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362314 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432315 if (!delegate_)
2316 return;
2317
[email protected]b9535422012-02-09 01:47:592318 ChildProcessSecurityPolicyImpl* policy =
2319 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322320 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592321 return;
[email protected]8f810632013-06-06 22:33:322322
[email protected]3a3b75a2012-06-01 08:38:362323 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202324}
2325
[email protected]b172aee2012-04-10 17:05:262326void WebContentsImpl::OnFindReply(int request_id,
2327 int number_of_matches,
2328 const gfx::Rect& selection_rect,
2329 int active_match_ordinal,
2330 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432331 if (delegate_) {
2332 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2333 active_match_ordinal, final_update);
2334 }
[email protected]b888919c2011-09-02 00:32:162335}
2336
[email protected]59363fc92012-09-05 03:46:312337#if defined(OS_ANDROID)
2338void WebContentsImpl::OnFindMatchRectsReply(
2339 int version,
2340 const std::vector<gfx::RectF>& rects,
2341 const gfx::RectF& active_rect) {
2342 if (delegate_)
2343 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2344}
[email protected]583418cc2013-01-17 14:01:102345
[email protected]1ff427972013-02-07 21:14:072346void WebContentsImpl::OnOpenDateTimeDialog(
2347 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092348 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2349 GetRenderViewHost(),
2350 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132351 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092352 value.minimum,
2353 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172354 value.step,
2355 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102356}
2357
[email protected]a794f3a2013-10-30 17:00:322358void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2359 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442360 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322361}
2362
[email protected]59363fc92012-09-05 03:46:312363#endif
2364
[email protected]f114fa42013-12-06 17:06:442365void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2366 const base::FilePath& path,
2367 bool is_hung) {
2368 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2369
2370 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2371 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2372}
2373
2374void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422375 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442376 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422377 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452378}
2379
[email protected]b172aee2012-04-10 17:05:262380void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2381 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102382 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252383 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102384 AppCacheAccessed(manifest_url, blocked_by_policy));
2385}
2386
[email protected]8bc5ff02013-11-29 06:34:032387void WebContentsImpl::OnOpenColorChooser(
2388 int color_chooser_id,
2389 SkColor color,
2390 const std::vector<ColorSuggestion>& suggestions) {
2391 ColorChooser* new_color_chooser =
2392 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212393 if (color_chooser_ == new_color_chooser)
2394 return;
2395 color_chooser_.reset(new_color_chooser);
2396 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202397}
2398
[email protected]b172aee2012-04-10 17:05:262399void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202400 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212401 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202402 color_chooser_->End();
2403}
2404
[email protected]b172aee2012-04-10 17:05:262405void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322406 SkColor color) {
[email protected]da8543762012-03-20 08:52:202407 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212408 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202409 color_chooser_->SetSelectedColor(color);
2410}
2411
[email protected]d0759f492012-04-19 22:50:502412// This exists for render views that don't have a WebUI, but do have WebUI
2413// bindings enabled.
2414void WebContentsImpl::OnWebUISend(const GURL& source_url,
2415 const std::string& name,
2416 const base::ListValue& args) {
2417 if (delegate_)
2418 delegate_->WebUISend(this, source_url, name, args);
2419}
2420
[email protected]d8415ad92012-08-23 14:40:502421void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442422 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502423 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342424 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162425 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442426 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162427 return;
[email protected]d8415ad92012-08-23 14:40:502428 }
2429
[email protected]8c8fc292012-11-23 18:57:162430 if (!delegate_->RequestPpapiBrokerPermission(
2431 this, url, plugin_path,
2432 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442433 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162434 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442435 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162436 }
[email protected]d8415ad92012-08-23 14:40:502437}
2438
[email protected]ea0309c2013-08-06 19:35:442439void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502440 bool result) {
[email protected]ea0309c2013-08-06 19:35:442441 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502442}
2443
[email protected]c4538072013-03-18 02:17:552444void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372445 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082446 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552447 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392448 // For more info, see comment above classes BrowserPluginEmbedder and
2449 // BrowserPluginGuest.
2450 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142451 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082452 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372453}
2454
[email protected]41225fe2013-03-29 05:32:022455void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392456 int id,
[email protected]749fadd2013-05-15 08:37:482457 int http_status_code,
[email protected]795c28972012-12-06 06:13:392458 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302459 const std::vector<SkBitmap>& bitmaps,
2460 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022461 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2462 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392463 // Currently WebContents notifies us of ANY downloads so that it is
2464 // possible to get here.
2465 return;
2466 }
2467 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302468 iter->second.Run(
2469 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392470 }
[email protected]41225fe2013-03-29 05:32:022471 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392472}
2473
2474void WebContentsImpl::OnUpdateFaviconURL(
2475 int32 page_id,
2476 const std::vector<FaviconURL>& candidates) {
2477 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2478 DidUpdateFaviconURL(page_id, candidates));
2479}
2480
[email protected]d9030b82013-07-19 08:26:062481void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2482 bool has_video,
2483 bool has_audio,
2484 bool is_playing) {
2485 // Chrome OS does its own detection of audio and video.
2486#if !defined(OS_CHROMEOS)
2487 if (is_playing) {
2488 scoped_ptr<PowerSaveBlocker> blocker;
2489 if (has_video) {
2490 blocker = PowerSaveBlocker::Create(
2491 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2492 "Playing video");
2493#if defined(OS_ANDROID)
2494 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382495 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062496#endif
2497 } else if (has_audio) {
2498 blocker = PowerSaveBlocker::Create(
2499 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2500 "Playing audio");
2501 }
2502
[email protected]f114fa42013-12-06 17:06:442503 if (blocker) {
2504 power_save_blockers_[render_view_message_source_][player_cookie] =
2505 blocker.release();
2506 }
[email protected]d9030b82013-07-19 08:26:062507 } else {
[email protected]f114fa42013-12-06 17:06:442508 delete power_save_blockers_[render_view_message_source_][player_cookie];
2509 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062510 }
2511#endif // !defined(OS_CHROMEOS)
2512}
2513
[email protected]9f268072013-11-07 00:02:152514void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2515 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2516 DidFirstVisuallyNonEmptyPaint(page_id));
2517}
[email protected]d9030b82013-07-19 08:26:062518
[email protected]e67ebf32013-02-13 11:07:192519void WebContentsImpl::DidChangeVisibleSSLState() {
2520 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2521 DidChangeVisibleSSLState());
2522}
2523
[email protected]17e286e2013-03-01 23:29:392524void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2525 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2526 BeforeFormRepostWarningShow());
2527}
2528
[email protected]ec6c05f2013-10-23 18:41:572529
2530void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2531 Activate();
2532 if (delegate_)
2533 delegate_->ShowRepostFormWarningDialog(this);
2534}
2535
[email protected]96d185d2009-04-24 03:28:542536// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592537// loading, or done loading.
2538void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2539 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262540 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542541 if (is_loading == is_loading_)
2542 return;
2543
2544 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262545 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2546 base::string16());
[email protected]96d185d2009-04-24 03:28:542547 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562548 upload_size_ = 0;
2549 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542550 }
2551
[email protected]fa944cb82013-11-15 17:51:212552 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542553
2554 is_loading_ = is_loading;
2555 waiting_for_response_ = is_loading;
2556
[email protected]6ebdc9b2010-09-27 16:55:572557 if (delegate_)
2558 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212559 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542560
[email protected]eab61442013-11-14 18:35:482561 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592562 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482563 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2564 "URL", url);
[email protected]91621872013-10-08 04:04:592565 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2566 DidStartLoading(render_view_host));
2567 } else {
[email protected]eab61442013-11-14 18:35:482568 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2569 "URL", url);
[email protected]91621872013-10-08 04:04:592570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2571 DidStopLoading(render_view_host));
2572 }
[email protected]66798902013-10-01 18:40:162573
2574 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212575 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2576 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542577 if (details)
[email protected]8ff00d72012-10-23 19:12:212578 det = Details<LoadNotificationDetails>(details);
2579 NotificationService::current()->Notify(
2580 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542581}
2582
[email protected]b172aee2012-04-10 17:05:262583void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212584 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322585 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562586 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322587 // Clear the status bubble. This is a workaround for a bug where WebKit
2588 // doesn't let us know that the cursor left an element during a
2589 // transition (this is also why the mouse cursor remains as a hand after
2590 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2591 // clear the bubble when a user navigates to a named anchor in the same
2592 // page.
[email protected]36fc0392011-12-25 03:59:512593 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322594 }
2595
[email protected]a6e82fc2010-02-24 22:28:142596 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472597 // Once the main frame is navigated, we're no longer considered to have
2598 // displayed insecure content.
2599 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352600 SSLManager::NotifySSLInternalStateChanged(
2601 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172602 }
[email protected]ce5c4502009-05-06 16:46:112603
[email protected]3c9e1872010-11-18 16:17:492604 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252605 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042606 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322607}
2608
[email protected]b172aee2012-04-10 17:05:262609void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322610 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212611 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322612 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112613 // If we navigate off the page, close all JavaScript dialogs.
2614 if (dialog_manager_ && !details.is_in_page)
2615 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322616
[email protected]3c9e1872010-11-18 16:17:492617 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042619 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322620}
2621
[email protected]2f7b3c5a2013-06-21 04:59:252622bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292623 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2624 // still be used for a normal web site.
2625 if (url == GURL(kAboutBlankURL))
2626 return false;
2627
2628 // The embedder will then have the opportunity to determine if the URL
2629 // should "use up" the SiteInstance.
2630 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252631}
2632
[email protected]b172aee2012-04-10 17:05:262633void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462634 // If we are creating a RVH for a restored controller, then we need to make
2635 // sure the RenderView starts with a next_page_id_ larger than the number
2636 // of restored entries. This must be called before the RenderView starts
2637 // navigating (to avoid a race between the browser updating max_page_id and
2638 // the renderer updating next_page_id_). Because of this, we only call this
2639 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562640 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582641 if (max_restored_page_id >
2642 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2643 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2644 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322645}
2646
[email protected]b172aee2012-04-10 17:05:262647bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262648 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322649 // For file URLs without a title, use the pathname instead. In the case of a
2650 // synthesized title, we don't want the update to count toward the "one set
2651 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262652 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322653 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512654 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2655 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322656 explicit_set = false; // Don't count synthetic titles toward the set limit.
2657 } else {
[email protected]acafd272011-07-26 17:35:572658 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322659 explicit_set = true;
2660 }
2661
[email protected]987fc3a2011-05-26 14:18:092662 // If a page is created via window.open and never navigated,
2663 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552664 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092665 if (entry) {
[email protected]36fc0392011-12-25 03:59:512666 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092667 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322668
[email protected]36fc0392011-12-25 03:59:512669 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092670 } else {
2671 if (page_title_when_no_navigation_entry_ == final_title)
2672 return false; // Nothing changed, don't bother.
2673
2674 page_title_when_no_navigation_entry_ = final_title;
2675 }
[email protected]420ae012009-04-24 05:16:322676
[email protected]420ae012009-04-24 05:16:322677 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232678 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322679
[email protected]66798902013-10-01 18:40:162680 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532681 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162682
2683 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212684 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462685 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212686 NotificationService::current()->Notify(
2687 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2688 Source<WebContents>(this),
2689 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042690
[email protected]420ae012009-04-24 05:16:322691 return true;
2692}
2693
[email protected]7b712ee22013-10-03 00:57:282694void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2695 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322696 // After sending out a swap notification, we need to send a disconnect
2697 // notification so that clients that pick up a pointer to |this| can NULL the
2698 // pointer. See Bug 1230284.
2699 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112700 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282701 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112702
2703 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282704 std::pair<RenderViewHost*, RenderViewHost*> details =
2705 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212706 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282707 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212708 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282709 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392710
2711 // Ensure that the associated embedder gets cleared after a RenderViewHost
2712 // gets swapped, so we don't reuse the same embedder next time a
2713 // RenderViewHost is attached to this WebContents.
2714 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322715}
2716
[email protected]da7a7182013-09-06 08:11:112717// TODO(avi): Remove this entire function because this notification is already
2718// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262719void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322720 if (!notify_disconnection_)
2721 return;
2722
2723 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212724 NotificationService::current()->Notify(
2725 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2726 Source<WebContents>(this),
2727 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322728}
2729
[email protected]cbb1ef592013-06-05 19:49:462730void WebContentsImpl::NotifyNavigationEntryCommitted(
2731 const LoadCommittedDetails& load_details) {
2732 FOR_EACH_OBSERVER(
2733 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2734}
2735
[email protected]f114fa42013-12-06 17:06:442736bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2737 const IPC::Message& message) {
2738 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312739}
2740
[email protected]5a3bdf52012-05-24 15:12:572741RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2742 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322743}
2744
[email protected]8d3347f2009-07-09 22:00:212745RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262746WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212747 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212748}
2749
[email protected]8ff00d72012-10-23 19:12:212750RendererPreferences WebContentsImpl::GetRendererPrefs(
2751 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462752 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512753}
2754
[email protected]b172aee2012-04-10 17:05:262755WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172756 return this;
2757}
2758
[email protected]b172aee2012-04-10 17:05:262759gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172760 if (delegate_)
2761 return delegate_->GetRootWindowResizerRect();
2762 return gfx::Rect();
2763}
2764
[email protected]7a846df2012-09-20 19:17:392765void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272766 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392767 browser_plugin_embedder_.reset();
2768}
2769
[email protected]b172aee2012-04-10 17:05:262770void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442771 // Don't send notifications if we are just creating a swapped-out RVH for
2772 // the opener chain. These won't be used for view-source or WebUI, so it's
2773 // ok to return early.
2774 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2775 return;
2776
[email protected]86f98a22013-03-20 14:35:002777 if (delegate_)
2778 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082779
[email protected]8ff00d72012-10-23 19:12:212780 NotificationService::current()->Notify(
2781 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2782 Source<WebContents>(this),
2783 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322784
2785 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352786 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212787 if (GetRenderManager()->pending_web_ui())
2788 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322789
[email protected]6286a372013-10-09 04:03:272790 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332791 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322792 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182793 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582794 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322795 }
[email protected]0666aef2009-05-13 19:48:082796
[email protected]60780f412013-02-25 16:34:102797 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262798
2799 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252800 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522804 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322805 // Don't notify the world, since this came from a renderer in the
2806 // background.
2807 return;
2808 }
2809
[email protected]da7a7182013-09-06 08:11:112810 notify_disconnection_ = true;
2811 // TODO(avi): Remove. http://crbug.com/170921
2812 NotificationService::current()->Notify(
2813 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2814 Source<WebContents>(this),
2815 NotificationService::NoDetails());
2816
[email protected]be1f56ab2011-12-22 06:55:312817 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232818 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302819
2820 // Restore the focus to the tab (otherwise the focus will be on the top
2821 // window).
[email protected]484ae5912010-09-29 19:16:142822 if (was_crashed && !FocusLocationBarByDefault() &&
2823 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062824 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142825 }
[email protected]32ded2212011-11-10 18:51:432826
[email protected]d8c660432011-12-22 20:51:252827 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322828}
2829
[email protected]ec6a7eb2013-04-22 17:34:222830void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2831 base::TerminationStatus status,
2832 int error_code) {
[email protected]151a63d2011-12-20 22:32:522833 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322834 // The pending page's RenderViewHost is gone.
2835 return;
2836 }
2837
[email protected]d9030b82013-07-19 08:26:062838 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592839 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322840 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232841 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312842 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322843
[email protected]d8c660432011-12-22 20:51:252844 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272845 observers_,
[email protected]58d5cfe2013-07-10 02:40:522846 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322847}
2848
[email protected]b172aee2012-04-10 17:05:262849void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062850 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212851 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252852 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062853}
2854
[email protected]b0f724c2013-09-05 04:21:132855void WebContentsImpl::DidGetResourceResponseStart(
2856 const ResourceRequestDetails& details) {
2857 controller_.ssl_manager()->DidStartResourceResponse(details);
2858
2859 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2860 DidGetResourceResponseStart(details));
2861
2862 // TODO(avi): Remove. http://crbug.com/170921
2863 NotificationService::current()->Notify(
2864 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2865 Source<WebContents>(this),
2866 Details<const ResourceRequestDetails>(&details));
2867}
2868
2869void WebContentsImpl::DidGetRedirectForResourceRequest(
2870 const ResourceRedirectDetails& details) {
2871 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2872
2873 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2874 DidGetRedirectForResourceRequest(details));
2875
2876 // TODO(avi): Remove. http://crbug.com/170921
2877 NotificationService::current()->Notify(
2878 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2879 Source<WebContents>(this),
2880 Details<const ResourceRedirectDetails>(&details));
2881}
2882
[email protected]b172aee2012-04-10 17:05:262883void WebContentsImpl::DidNavigate(
2884 RenderViewHost* rvh,
2885 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552886 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2887 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122888 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552889 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122890 }
2891
[email protected]e3d92a7f2013-01-10 02:35:052892 if (PageTransitionIsMainFrame(params.transition)) {
2893 // When overscroll navigation gesture is enabled, a screenshot of the page
2894 // in its current state is taken so that it can be used during the
2895 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362896 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052897 // WebContents::GetRenderViewHost to return the new host, instead of the one
2898 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482899 if (delegate_ && delegate_->CanOverscrollContent())
2900 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052901
[email protected]fa944cb82013-11-15 17:51:212902 GetRenderManager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052903 }
[email protected]8030f012009-09-25 18:09:372904
[email protected]434f69f2012-02-06 21:56:522905 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252906 // assigning a site is not necessary for this URL. In that case, the
2907 // SiteInstance can still be considered unused until a navigation to a real
2908 // page.
[email protected]434f69f2012-02-06 21:56:522909 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252910 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332911 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522912 }
[email protected]420ae012009-04-24 05:16:322913
2914 // Need to update MIME type here because it's referred to in
2915 // UpdateNavigationCommands() called by RendererDidNavigate() to
2916 // determine whether or not to enable the encoding menu.
2917 // It's updated only for the main frame. For a subframe,
2918 // RenderView::UpdateURL does not set params.contents_mime_type.
2919 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2920 // TODO(jungshik): Add a test for the encoding menu to avoid
2921 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212922 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322923 contents_mime_type_ = params.contents_mime_type;
2924
[email protected]8ff00d72012-10-23 19:12:212925 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002926 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392927
[email protected]1ae93fb2013-06-14 03:38:562928 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2929 // us estimate our process count for implementing OOP iframes.
2930 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552931 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562932
[email protected]a9c0bfe2010-09-17 08:35:222933 // Send notification about committed provisional loads. This notification is
2934 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2935 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212936 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072937 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2938 // that is not recorded in the navigation history. For the purpose of
2939 // tracking navigation events, we treat this event as a sub frame navigation
2940 // event.
2941 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212942 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222943 // Whether or not a page transition was triggered by going backward or
2944 // forward in the history is only stored in the navigation controller's
2945 // entry list.
2946 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272947 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212948 PAGE_TRANSITION_FORWARD_BACK)) {
2949 transition_type = PageTransitionFromInt(
2950 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222951 }
[email protected]0d60f0192011-04-14 12:40:102952 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252953 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442954 DidCommitProvisionalLoadForFrame(
2955 params.frame_id,
2956 params.frame_unique_name,
2957 is_main_frame,
2958 params.url,
2959 transition_type,
2960 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222961 }
2962
[email protected]76543b92009-08-31 17:27:452963 if (!did_navigate)
2964 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322965
2966 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2967 // for the appropriate notification (best) or you can add it to
2968 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2969 // necessary, please).
2970
2971 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002972 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322973 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002974 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512975 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002976 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2977 }
[email protected]93f230e02011-06-01 14:40:002978 }
[email protected]420ae012009-04-24 05:16:322979 DidNavigateAnyFramePostCommit(rvh, details, params);
2980}
2981
[email protected]b172aee2012-04-10 17:05:262982void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2983 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042984 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152985 // Ensure that this state update comes from either the active RVH or one of
2986 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]fa944cb82013-11-15 17:51:212987 DCHECK(rvh == GetRenderViewHost() ||
2988 GetRenderManager()->IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322989
2990 // We must be prepared to handle state updates for any page, these occur
2991 // when the user is scrolling and entering form data, as well as when we're
2992 // leaving a page, in which case our state may have already been moved to
2993 // the next page. The navigation controller will look up the appropriate
2994 // NavigationEntry and update it when it is notified via the delegate.
2995
2996 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582997 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322998 if (entry_index < 0)
2999 return;
[email protected]10f417c52011-12-28 21:04:233000 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323001
[email protected]691aa2f2013-05-28 22:52:043002 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323003 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043004 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323005 controller_.NotifyEntryChanged(entry, entry_index);
3006}
3007
[email protected]b172aee2012-04-10 17:05:263008void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3009 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263010 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263011 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323012 // If we have a title, that's a pretty good indication that we've started
3013 // getting useful data.
3014 SetNotWaitingForResponse();
3015
[email protected]73eb2602012-02-09 19:50:553016 // Try to find the navigation entry, which might not be the current one.
3017 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233018 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583019 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093020
[email protected]73eb2602012-02-09 19:50:553021 // We can handle title updates when we don't have an entry in
3022 // UpdateTitleForEntry, but only if the update is from the current RVH.
3023 if (!entry && rvh != GetRenderViewHost())
3024 return;
3025
[email protected]a49e10b2011-08-01 23:57:463026 // TODO(evan): make use of title_direction.
3027 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093028 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323029 return;
3030
3031 // Broadcast notifications when the UI should be updated.
3032 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213033 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323034}
3035
[email protected]b172aee2012-04-10 17:05:263036void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3037 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313038 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323039}
3040
[email protected]b172aee2012-04-10 17:05:263041void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513042 if (delegate_)
3043 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103047#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293048 // The UI may be in an event-tracking loop, such as between the
3049 // mouse-down and mouse-up in text selection or a button click.
3050 // Defer the close until after tracking is complete, so that we
3051 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293052 // TODO(shess): This could get more fine-grained. For instance,
3053 // closing a tab in another window while selecting text in the
3054 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103055 if (view_->IsEventTracking()) {
3056 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293057 return;
3058 }
[email protected]60780f412013-02-25 16:34:103059#endif
[email protected]07707302009-11-06 00:50:293060
[email protected]420ae012009-04-24 05:16:323061 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523062 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513063 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323064}
3065
[email protected]b172aee2012-04-10 17:05:263066void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523067 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513068 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283069
3070 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213071 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573072}
3073
[email protected]b172aee2012-04-10 17:05:263074void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513075 if (delegate_ && delegate_->IsPopupOrPanel(this))
3076 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323077}
3078
[email protected]8ff00d72012-10-23 19:12:213079void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593080 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323081}
3082
[email protected]8ff00d72012-10-23 19:12:213083void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323084 scoped_ptr<LoadNotificationDetails> details;
3085
[email protected]9595fd82013-04-19 21:28:493086 // Use the last committed entry rather than the active one, in case a
3087 // pending entry has been created.
3088 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3089
[email protected]420ae012009-04-24 05:16:323090 // An entry may not exist for a stop when loading an initial blank page or
3091 // if an iframe injected by script into a blank page finishes loading.
3092 if (entry) {
[email protected]420ae012009-04-24 05:16:323093 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3094
3095 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513096 entry->GetVirtualURL(),
3097 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323098 elapsed,
3099 &controller_,
3100 controller_.GetCurrentEntryIndex()));
3101 }
3102
[email protected]91621872013-10-08 04:04:593103 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323104}
3105
[email protected]b172aee2012-04-10 17:05:263106void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163107 controller_.DiscardNonCommittedEntries();
3108
3109 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213110 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513114 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133115 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403116}
3117
[email protected]7cc78902012-12-06 02:32:263118void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393119 if (opener_) {
3120 // Clear our opener so that future cross-process navigations don't have an
3121 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103122 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393123 opener_ = NULL;
3124 }
[email protected]7cc78902012-12-06 02:32:263125
3126 // Notify all swapped out RenderViewHosts for this tab. This is important
3127 // in case we go back to them, or if another window in those processes tries
3128 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213129 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263130}
3131
[email protected]59167c22013-06-03 18:07:323132void WebContentsImpl::DidAccessInitialDocument() {
3133 // Update the URL display.
3134 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3135}
3136
[email protected]87717d0e2012-04-26 02:58:433137void WebContentsImpl::DocumentAvailableInMainFrame(
3138 RenderViewHost* render_view_host) {
3139 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3140 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103141}
3142
[email protected]b172aee2012-04-10 17:05:263143void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083144 RenderViewHost* render_view_host,
3145 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093146 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3147 DocumentOnLoadCompletedInMainFrame(page_id));
3148
3149 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213150 NotificationService::current()->Notify(
3151 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3152 Source<WebContents>(this),
3153 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083154}
3155
[email protected]196159d2012-05-04 17:26:543156void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3157 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213158 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263159 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183160 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523161 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303162 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543163 // If this came from a swapped out RenderViewHost, we only allow the request
3164 // if we are still in the same BrowsingInstance.
3165 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3166 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3167 return;
3168 }
3169
[email protected]4ad5d77d2011-12-03 02:00:483170 // Delegate to RequestTransferURL because this is just the generic
3171 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573172 // TODO(creis): Pass the redirect_chain into this method to support client
3173 // redirects. http://crbug.com/311721.
3174 std::vector<GURL> redirect_chain;
3175 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3176 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523177 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483178}
3179
[email protected]b172aee2012-04-10 17:05:263180void WebContentsImpl::RequestTransferURL(
3181 const GURL& url,
[email protected]f8872902013-10-30 03:18:573182 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213183 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573184 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263185 WindowOpenDisposition disposition,
3186 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183187 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523188 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303189 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203190 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123191 GURL dest_url(url);
3192 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553193 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123194 dest_url = GURL(kAboutBlankURL);
3195
[email protected]c80297782013-11-21 07:10:163196 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id.
3197 int frame_tree_node_id = -1;
3198 OpenURLParams params(dest_url, referrer, source_frame_id,
3199 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573200 page_transition, true /* is_renderer_initiated */);
3201 if (redirect_chain.size() > 0)
3202 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553203 params.transferred_global_request_id = old_request_id;
3204 params.should_replace_current_entry = should_replace_current_entry;
3205 params.user_gesture = user_gesture;
3206
[email protected]fa944cb82013-11-15 17:51:213207 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573208 // Web UI pages sometimes want to override the page transition type for
3209 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3210 // automatically generated suggestions). We don't override other types
3211 // like TYPED because they have different implications (e.g., autocomplete).
3212 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213213 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553214
[email protected]e0112912011-02-02 22:54:353215 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163216 // want web sites to see a referrer of "chrome://blah" (and some
3217 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323218 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553219 params.referrer = Referrer();
3220
3221 // Navigations in Web UI pages count as browser-initiated navigations.
3222 params.is_renderer_initiated = false;
[email protected]16a13fa2013-11-07 01:03:533223
3224 // TODO(creis): Remove this line. In the short term, it fixes a regression
3225 // (http://crbug.com/313572) by partially reverting r231370.
3226 // The underlying problem is that WebDataSource::replacesCurrentHistoryItem
3227 // should be returning false when the CWS goes to the sign-in page.
3228 // See http://crbug.com/311721.
3229 params.should_replace_current_entry = false;
[email protected]ae5184d62011-10-06 19:25:583230 }
[email protected]44d0930a2013-10-28 18:53:553231
3232 new_contents = OpenURL(params);
3233
[email protected]ae5184d62011-10-06 19:25:583234 if (new_contents) {
3235 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253236 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583237 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123238 dest_url,
[email protected]ae5184d62011-10-06 19:25:583239 referrer,
3240 disposition,
[email protected]44d0930a2013-10-28 18:53:553241 params.transition,
[email protected]ae5184d62011-10-06 19:25:583242 source_frame_id));
[email protected]420ae012009-04-24 05:16:323243 }
3244}
3245
[email protected]e1c3a552012-05-04 20:51:323246void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3247 // Tell the active RenderViewHost to run unload handlers and close, as long
3248 // as the request came from a RenderViewHost in the same BrowsingInstance.
3249 // In most cases, we receive this from a swapped out RenderViewHost.
3250 // It is possible to receive it from one that has just been swapped in,
3251 // in which case we might as well deliver the message anyway.
3252 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3253 GetRenderViewHost()->ClosePage();
3254}
3255
[email protected]f546640b2012-05-15 00:03:493256void WebContentsImpl::RouteMessageEvent(
3257 RenderViewHost* rvh,
3258 const ViewMsg_PostMessage_Params& params) {
3259 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363260 // came from a RenderViewHost in the same BrowsingInstance or if this
3261 // WebContents is dedicated to a browser plugin guest.
3262 // Note: This check means that an embedder could theoretically receive a
3263 // postMessage from anyone (not just its own guests). However, this is
3264 // probably not a risk for apps since other pages won't have references
3265 // to App windows.
3266 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3267 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493268 return;
3269
3270 ViewMsg_PostMessage_Params new_params(params);
3271
[email protected]0bc7f3542013-10-21 15:05:533272 if (!params.message_port_ids.empty()) {
3273 MessagePortMessageFilter* message_port_message_filter =
3274 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3275 ->message_port_message_filter();
3276 std::vector<int> new_routing_ids(params.message_port_ids.size());
3277 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3278 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3279 MessagePortService::GetInstance()->UpdateMessagePort(
3280 params.message_port_ids[i],
3281 message_port_message_filter,
3282 new_routing_ids[i]);
3283 }
3284 new_params.new_routing_ids = new_routing_ids;
3285 }
3286
[email protected]f546640b2012-05-15 00:03:493287 // If there is a source_routing_id, translate it to the routing ID for
3288 // the equivalent swapped out RVH in the target process. If we need
3289 // to create a swapped out RVH for the source tab, we create its opener
3290 // chain as well, since those will also be accessible to the target page.
3291 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3292 // Try to look up the WebContents for the source page.
3293 WebContentsImpl* source_contents = NULL;
3294 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3295 rvh->GetProcess()->GetID(), params.source_routing_id);
3296 if (source_rvh) {
3297 source_contents = static_cast<WebContentsImpl*>(
3298 source_rvh->GetDelegate()->GetAsWebContents());
3299 }
3300
3301 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363302 if (GetBrowserPluginGuest()) {
3303 // We create a swapped out RenderView for the embedder in the guest's
3304 // render process but we intentionally do not expose the embedder's
3305 // opener chain to it.
3306 new_params.source_routing_id =
3307 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3308 } else {
3309 new_params.source_routing_id =
3310 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3311 }
[email protected]f546640b2012-05-15 00:03:493312 } else {
3313 // We couldn't find it, so don't pass a source frame.
3314 new_params.source_routing_id = MSG_ROUTING_NONE;
3315 }
3316 }
3317
3318 // In most cases, we receive this from a swapped out RenderViewHost.
3319 // It is possible to receive it from one that has just been swapped in,
3320 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183321 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493322}
3323
[email protected]b172aee2012-04-10 17:05:263324void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343325 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263326 const base::string16& message,
3327 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323328 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213329 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323330 IPC::Message* reply_msg,
3331 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073332 // Suppress JavaScript dialogs when requested. Also suppress messages when
3333 // showing an interstitial as it's shown over the previous page and we don't
3334 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503335 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583336 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273337 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073338 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523339 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153340 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323341
3342 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213343 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433344 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153345 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3346 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433347 this,
3348 frame_url.GetOrigin(),
3349 accept_lang,
3350 javascript_message_type,
3351 message,
[email protected]51da7e32012-01-30 19:24:523352 default_prompt,
[email protected]b172aee2012-04-10 17:05:263353 base::Bind(&WebContentsImpl::OnDialogClosed,
3354 base::Unretained(this),
3355 rvh,
3356 reply_msg),
[email protected]51da7e32012-01-30 19:24:523357 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323358 }
[email protected]3ab9cb82011-06-03 18:02:073359
[email protected]6dd2f1e2013-09-11 15:06:013360 *did_suppress_message = suppress_this_message;
3361
[email protected]3ab9cb82011-06-03 18:02:073362 if (suppress_this_message) {
3363 // If we are suppressing messages, just reply as if the user immediately
3364 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263365 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073366 }
3367
[email protected]6dd2f1e2013-09-11 15:06:013368 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3369 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323370}
3371
[email protected]b172aee2012-04-10 17:05:263372void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263373 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263374 bool is_reload,
3375 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583376 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513377 if (delegate_)
3378 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073379
3380 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583381 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073382 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523383 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153384 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153385 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343386 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263387 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503388 return;
3389 }
[email protected]3ab9cb82011-06-03 18:02:073390
[email protected]7ab1e7d62009-10-14 23:32:013391 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153392 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3393 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323394 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263395 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523396 reply_msg));
[email protected]420ae012009-04-24 05:16:323397}
3398
[email protected]a796f202012-05-30 14:14:253399bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263400 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253401 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263402 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253403 if (!delegate_)
3404 return false;
3405 return delegate_->AddMessageToConsole(this, level, message, line_no,
3406 source_id);
3407}
3408
[email protected]b172aee2012-04-10 17:05:263409WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273410 // We want to base the page config off of the actual URL, rather than the
3411 // virtual URL.
3412 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3413 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003414 GURL url = controller_.GetActiveEntry()
3415 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153416
[email protected]fa944cb82013-11-15 17:51:213417 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323418}
3419
[email protected]0eba810b2012-10-18 03:19:363420int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213421 SiteInstance* instance) {
[email protected]fa944cb82013-11-15 17:51:213422 return GetRenderManager()->CreateRenderView(instance, MSG_ROUTING_NONE,
3423 true, true);
[email protected]0eba810b2012-10-18 03:19:363424}
3425
[email protected]b172aee2012-04-10 17:05:263426void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273427 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253428 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223429
[email protected]ea114722012-03-12 01:11:253430 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173431 if (rdh) // NULL in unittests.
3432 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253433}
3434
[email protected]b172aee2012-04-10 17:05:263435void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443436 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253437 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443438}
3439
[email protected]b172aee2012-04-10 17:05:263440void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563441 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263442 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153443 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523444 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153445 return;
3446
[email protected]9f76c1e2012-03-05 15:15:583447 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3448
[email protected]e5fc1632011-08-08 07:51:533449 // Ignore renderer unresponsive event if debugger is attached to the tab
3450 // since the event may be a result of the renderer sitting on a breakpoint.
3451 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363452 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533453 return;
3454
[email protected]2e9d79f2013-08-16 05:45:563455 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323456 // Hang occurred while firing the beforeunload/unload handler.
3457 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583458 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323459
[email protected]fa944cb82013-11-15 17:51:213460 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323461 return;
3462
3463 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563464 // nothing we can do to recover. If the hang is in the beforeunload handler,
3465 // pretend the beforeunload listeners have all fired and allow the delegate
3466 // to continue closing; the user will not have the option of cancelling the
3467 // close. Otherwise, pretend the unload listeners have all fired and close
3468 // the tab.
3469 bool close = true;
3470 if (is_during_beforeunload) {
3471 delegate_->BeforeUnloadFired(this, true, &close);
3472 }
3473 if (close)
3474 Close(rvh);
[email protected]420ae012009-04-24 05:16:323475 return;
3476 }
3477
[email protected]9f76c1e2012-03-05 15:15:583478 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473479 return;
3480
[email protected]6934a702011-12-20 00:04:513481 if (delegate_)
3482 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323483}
3484
[email protected]b172aee2012-04-10 17:05:263485void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513486 if (delegate_)
3487 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323488}
3489
[email protected]b172aee2012-04-10 17:05:263490void WebContentsImpl::LoadStateChanged(
3491 const GURL& url,
3492 const net::LoadStateWithParam& load_state,
3493 uint64 upload_position,
3494 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323495 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563496 upload_position_ = upload_position;
3497 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503498 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213499 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303500 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213501 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323502 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463503 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213504 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463505 }
[email protected]420ae012009-04-24 05:16:323506}
3507
[email protected]b172aee2012-04-10 17:05:263508void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513509 if (delegate_)
3510 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253511}
3512
[email protected]b172aee2012-04-10 17:05:263513void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553514 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323515 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3517 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513518 if (delegate_)
3519 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093520 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323521}
3522
[email protected]58d5cfe2013-07-10 02:40:523523void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543524 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233525 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223526 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543527}
3528
[email protected]b172aee2012-04-10 17:05:263529void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103530 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213531 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263532 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3533 // here during container initialization and normal window size will be set
3534 // later. In case of tab duplication this resizing to 0x0 prevents setting
3535 // normal size later so just ignore it.
3536 if (!size.IsEmpty())
3537 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323538}
3539
[email protected]af905902013-10-01 21:38:513540void WebContentsImpl::CancelModalDialogsForRenderManager() {
3541 // We need to cancel modal dialogs when doing a process swap, since the load
3542 // deferrer would prevent us from swapping out.
3543 if (dialog_manager_)
3544 dialog_manager_->CancelActiveAndPendingDialogs(this);
3545}
3546
[email protected]7b712ee22013-10-03 00:57:283547void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3548 RenderViewHost* new_host) {
3549 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083550
3551 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003552 if (delegate_)
3553 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393554
[email protected]7b712ee22013-10-03 00:57:283555 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543556}
3557
[email protected]14392a52012-05-02 20:28:443558int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3559 SiteInstance* instance) {
3560 if (!opener_)
3561 return MSG_ROUTING_NONE;
3562
3563 // Recursively create RenderViews for anything else in the opener chain.
3564 return opener_->CreateOpenerRenderViews(instance);
3565}
3566
3567int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3568 int opener_route_id = MSG_ROUTING_NONE;
3569
3570 // If this tab has an opener, ensure it has a RenderView in the given
3571 // SiteInstance as well.
3572 if (opener_)
3573 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3574
[email protected]45a22ad2013-02-21 03:25:003575 // If any of the renderers (current, pending, or swapped out) for this
3576 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213577 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3578 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373579
[email protected]fa944cb82013-11-15 17:51:213580 if (GetRenderManager()->pending_render_view_host() &&
3581 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3582 instance)
3583 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003584
[email protected]fa944cb82013-11-15 17:51:213585 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373586 instance);
3587 if (rvh)
3588 return rvh->GetRoutingID();
3589
[email protected]14392a52012-05-02 20:28:443590 // Create a swapped out RenderView in the given SiteInstance if none exists,
3591 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]fa944cb82013-11-15 17:51:213592 return GetRenderManager()->CreateRenderView(instance, opener_route_id,
3593 true, true);
[email protected]14392a52012-05-02 20:28:443594}
3595
[email protected]b172aee2012-04-10 17:05:263596NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193597 return GetController();
[email protected]3a3d47472010-07-15 21:03:543598}
3599
[email protected]b172aee2012-04-10 17:05:263600WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563601 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323602}
3603
[email protected]10f417c52011-12-28 21:04:233604NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263605 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323606 return controller_.GetLastCommittedEntry();
3607}
3608
[email protected]b172aee2012-04-10 17:05:263609bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443610 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033611 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443612 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323613 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523614
[email protected]420ae012009-04-24 05:16:323615 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443616 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213617 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323618
[email protected]74ce1ad2011-12-16 21:51:463619 // Make sure we use the correct starting page_id in the new RenderView.
3620 UpdateMaxPageIDIfNecessary(render_view_host);
3621 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583622 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463623
[email protected]9f76c1e2012-03-05 15:15:583624 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263625 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493626 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133627 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523628 return false;
[email protected]14392a52012-05-02 20:28:443629 }
[email protected]a4127722011-04-27 23:13:523630
[email protected]a220b5932013-09-21 03:47:443631#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503632 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3633 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443634 if (rwh_view) {
3635 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3636 render_widget_host->WasResized();
3637 }
[email protected]f8233cc2011-05-31 20:24:503638#endif
3639
[email protected]420ae012009-04-24 05:16:323640 return true;
3641}
3642
[email protected]7d244f12013-08-22 21:41:513643#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183644base::android::ScopedJavaLocalRef<jobject>
3645WebContentsImpl::GetJavaWebContents() {
3646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3647
3648 WebContentsAndroid* web_contents_android =
3649 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3650 if (!web_contents_android) {
3651 web_contents_android = new WebContentsAndroid(this);
3652 SetUserData(kWebContentsAndroidKey, web_contents_android);
3653 }
3654 return web_contents_android->GetJavaObject();
3655}
3656
[email protected]7d244f12013-08-22 21:41:513657bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3658 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3659 MSG_ROUTING_NONE);
3660}
3661#endif
3662
[email protected]b172aee2012-04-10 17:05:263663void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3664 IPC::Message* reply_msg,
3665 bool success,
[email protected]fcf75d42013-12-03 20:11:263666 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543667 if (is_showing_before_unload_dialog_ && !success) {
3668 // If a beforeunload dialog is canceled, we need to stop the throbber from
3669 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293670 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353671 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103672
[email protected]6d65a462013-06-21 21:29:123673 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3674 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543675 }
3676 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583677 static_cast<RenderViewHostImpl*>(
3678 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543679}
3680
[email protected]b172aee2012-04-10 17:05:263681void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213682 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123683 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103684}
[email protected]f45d2a72010-03-08 23:28:353685
[email protected]b172aee2012-04-10 17:05:263686void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103687 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443688 // Can be NULL during tests.
3689 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213690 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363691}
[email protected]9f76c1e2012-03-05 15:15:583692
[email protected]1ac10dca2013-08-20 20:47:043693bool WebContentsImpl::IsHidden() {
3694 return capturer_count_ == 0 && !should_normally_be_visible_;
3695}
3696
[email protected]b0936d22013-11-28 06:47:363697RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213698 return frame_tree_.root()->render_manager();
3699}
3700
[email protected]b172aee2012-04-10 17:05:263701RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583702 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3703}
[email protected]7900bfdb2012-05-24 19:31:243704
[email protected]f8497342013-02-05 22:15:023705BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393706 return browser_plugin_guest_.get();
3707}
3708
[email protected]738f57a2013-06-29 21:06:543709void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3710 CHECK(!browser_plugin_guest_);
3711 browser_plugin_guest_.reset(guest);
3712}
3713
[email protected]f8497342013-02-05 22:15:023714BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393715 return browser_plugin_embedder_.get();
3716}
[email protected]8ff00d72012-10-23 19:12:213717
[email protected]8eb04562013-03-06 03:41:143718BrowserPluginGuestManager*
3719 WebContentsImpl::GetBrowserPluginGuestManager() const {
3720 return static_cast<BrowserPluginGuestManager*>(
3721 GetBrowserContext()->GetUserData(
3722 browser_plugin::kBrowserPluginGuestManagerKeyName));
3723}
3724
[email protected]d9030b82013-07-19 08:26:063725void WebContentsImpl::ClearPowerSaveBlockers(
3726 RenderViewHost* render_view_host) {
3727 STLDeleteValues(&power_save_blockers_[render_view_host]);
3728 power_save_blockers_.erase(render_view_host);
3729}
3730
3731void WebContentsImpl::ClearAllPowerSaveBlockers() {
3732 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3733 i != power_save_blockers_.end(); ++i)
3734 STLDeleteValues(&power_save_blockers_[i->first]);
3735 power_save_blockers_.clear();
3736}
3737
[email protected]dc0fd432013-08-27 15:29:213738gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3739 gfx::Size size;
3740 if (delegate_)
3741 size = delegate_->GetSizeForNewRenderView(this);
3742 if (size.IsEmpty())
3743 size = view_->GetContainerSize();
3744 return size;
3745}
3746
[email protected]9b159a52013-10-03 17:24:553747void WebContentsImpl::OnFrameRemoved(
3748 RenderViewHostImpl* render_view_host,
3749 int64 frame_id) {
3750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3751 FrameDetached(render_view_host, frame_id));
3752}
3753
[email protected]8ff00d72012-10-23 19:12:213754} // namespace content