blob: 5c26297e7df4b6c7fbe6e21898b0131720b19854 [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]f16cc6782013-12-16 23:42:5781#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1682#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2983#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5384#include "net/http/http_cache.h"
85#include "net/http/http_transaction_factory.h"
86#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3487#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5688#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0189#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4190#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5291#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1892#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3193
[email protected]583418cc2013-01-17 14:01:1094#if defined(OS_ANDROID)
95#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3296#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:1897#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:3298#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0099#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10100#endif
101
[email protected]f66df822012-05-18 16:52:17102#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50103#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27104#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57105#endif
[email protected]3e45ba92009-02-20 21:09:00106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
[email protected]b172aee2012-04-10 17:05:26109// If a WebContentsImpl is told to navigate to a different web site (as
110// determined by SiteInstance), it will replace its current RenderViewHost with
111// a new RenderViewHost dedicated to the new SiteInstance. This works as
112// follows:
[email protected]420ae012009-04-24 05:16:32113//
[email protected]fc6c1872013-10-03 01:22:35114// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46115// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32116// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35117// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35120// that it has a pending cross-site request. We will check this on the IO
121// thread when deciding how to handle the response.
122// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46123// cancel all the pending logic. Otherwise we allow the pending RVH to send
124// the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35126// main resource load on the pending RVH. It creates a
127// CrossSiteResourceHandler to check whether a process swap is needed when
128// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46129// - When RDH receives a response, the BufferedResourceHandler determines
130// whether it is a download. If so, it sends a message to the new renderer
131// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26132// pending RVH remains until the next DidNavigate event for this
133// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32134// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35135// download, the CrossSiteResourceHandler checks whether a process swap is
136// needed (either because CrossSiteRequestManager has state for it or because
137// a transfer was needed for a redirect).
138// - If so, CrossSiteResourceHandler pauses the response to first run the old
139// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36140// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
141// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35142// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
143// to a new process is needed, based on the stored pending_nav_params_. (This
144// is independent of whether we started out with a cross-process navigation.)
145// - If not, it just tells the ResourceDispatcherHost to resume the response
146// to its current RenderViewHost.
147// - If so, it cancels the current pending RenderViewHost and sets up a new
148// navigation using RequestTransferURL. When the transferred request
149// arrives in the ResourceDispatcherHost, we transfer the response and
150// resume it.
[email protected]420ae012009-04-24 05:16:32151// - The pending renderer sends a FrameNavigate message that invokes the
152// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46153// pending RVH.
[email protected]b0936d22013-11-28 06:47:36154// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15155// the user goes back. The process only stays live if another tab is using
156// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32157
[email protected]8ff00d72012-10-23 19:12:21158namespace content {
[email protected]420ae012009-04-24 05:16:32159namespace {
160
[email protected]82114f52012-03-20 22:53:41161const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05162
[email protected]155c7f22013-12-09 17:07:18163#if defined(OS_ANDROID)
164const char kWebContentsAndroidKey[] = "web_contents_android";
165#endif // OS_ANDROID
166
[email protected]e4abd3b42013-11-12 18:28:47167base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46168g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
169
[email protected]795c28972012-12-06 06:13:39170static int StartDownload(content::RenderViewHost* rvh,
171 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29172 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30173 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02174 static int g_next_image_download_id = 0;
175 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
176 ++g_next_image_download_id,
177 url,
178 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30179 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02180 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39181}
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21184 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16186 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47189 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23191 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
192 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47193 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16194 break; // Fall through to rest of function.
195 }
[email protected]5e369672009-11-03 23:48:30196
[email protected]59246c572012-02-10 13:32:13197 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
198 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36199 if (entry.restore_type() ==
200 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13201 if (entry.GetHasPostData())
202 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02203 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13204 }
[email protected]5e369672009-11-03 23:48:30205
[email protected]2c5569662011-03-22 20:45:02206 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30207}
208
[email protected]10f417c52011-12-28 21:04:23209void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47210 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21211 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50212 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16213 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51214 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13215 params->should_clear_history_list = entry.should_clear_history_list();
[email protected]4972fc82013-11-19 04:33:42216 params->should_replace_current_entry = entry.should_replace_entry();
[email protected]60d6cca2013-04-30 08:47:13217 if (entry.should_clear_history_list()) {
218 // Set the history list related parameters to the same values a
219 // NavigationController would return before its first navigation. This will
220 // fully clear the RenderView's view of the session history.
221 params->pending_history_list_offset = -1;
222 params->current_history_list_offset = -1;
223 params->current_history_list_length = 0;
224 } else {
225 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
226 params->current_history_list_offset =
227 controller.GetLastCommittedEntryIndex();
228 params->current_history_list_length = controller.GetEntryCount();
229 }
[email protected]eaaba7dd2013-10-14 02:38:07230 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36231 if (!entry.GetBaseURLForDataURL().is_empty()) {
232 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
233 params->history_url_for_data_url = entry.GetVirtualURL();
234 }
[email protected]36fc0392011-12-25 03:59:51235 params->referrer = entry.GetReferrer();
236 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04237 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00238 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55239 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34240 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47241 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48242 params->transferred_request_child_id =
243 entry.transferred_global_request_id().child_id;
244 params->transferred_request_request_id =
245 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22246 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00247 // Avoid downloading when in view-source mode.
248 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44249 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07250 if (entry.GetBrowserInitiatedPostData()) {
251 params->browser_initiated_post_data.assign(
252 entry.GetBrowserInitiatedPostData()->front(),
253 entry.GetBrowserInitiatedPostData()->front() +
254 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23255 }
256
[email protected]f8872902013-10-30 03:18:57257 params->redirects = entry.redirect_chain();
258
[email protected]951a64832012-10-11 16:26:37259 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58260 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37261
[email protected]6c6b02d2011-09-02 03:36:47262 if (delegate)
263 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34264}
265
[email protected]8bfc8272013-09-09 20:10:53266void NotifyCacheOnIO(
267 scoped_refptr<net::URLRequestContextGetter> request_context,
268 const GURL& url,
269 const std::string& http_method) {
270 request_context->GetURLRequestContext()->http_transaction_factory()->
271 GetCache()->OnExternalCacheHit(url, http_method);
272}
273
[email protected]9b159a52013-10-03 17:24:55274// Helper function for retrieving all the sites in a frame tree.
275bool CollectSites(BrowserContext* context,
276 std::set<GURL>* sites,
277 FrameTreeNode* node) {
278 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
279 return true;
280}
281
[email protected]a86c0e962013-12-17 17:10:39282bool ForEachFrameInternal(
283 const base::Callback<void(RenderFrameHost*)>& on_frame,
284 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41285 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39286 return true;
287}
288
289void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
290 IPC::Message* message_copy = new IPC::Message(*message);
291 message_copy->set_routing_id(rfh->GetRoutingID());
292 rfh->Send(message_copy);
293}
294
[email protected]420ae012009-04-24 05:16:32295} // namespace
296
[email protected]54944cde2012-12-09 09:24:59297WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15298 return WebContentsImpl::CreateWithOpener(
299 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19300}
301
302WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59303 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30304 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59305 WebContentsImpl* new_contents = new WebContentsImpl(
306 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30307
308 for (SessionStorageNamespaceMap::const_iterator it =
309 session_storage_namespace_map.begin();
310 it != session_storage_namespace_map.end();
311 ++it) {
312 new_contents->GetController()
313 .SetSessionStorageNamespace(it->first, it->second.get());
314 }
315
[email protected]54944cde2012-12-09 09:24:59316 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19317 return new_contents;
[email protected]a81343d232011-12-27 07:39:20318}
[email protected]746d3052012-05-22 15:15:47319
[email protected]e4abd3b42013-11-12 18:28:47320void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46321 g_created_callbacks.Get().push_back(callback);
322}
323
[email protected]e4abd3b42013-11-12 18:28:47324void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46325 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
326 if (g_created_callbacks.Get().at(i).Equals(callback)) {
327 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
328 return;
329 }
330 }
331}
332
[email protected]299d7f12012-05-23 05:31:15333WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47334 return rvh->GetDelegate()->GetAsWebContents();
335}
336
[email protected]a86c0e962013-12-17 17:10:39337WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
338 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
339 if (!rfh_impl)
340 return NULL;
341 return rfh_impl->delegate()->GetAsWebContents();
342}
343
[email protected]7fff43e2013-05-21 20:21:10344// WebContentsImpl::DestructionObserver ----------------------------------------
345
346class WebContentsImpl::DestructionObserver : public WebContentsObserver {
347 public:
348 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
349 : WebContentsObserver(watched_contents),
350 owner_(owner) {
351 }
352
353 // WebContentsObserver:
354 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
355 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
356 }
357
358 private:
359 WebContentsImpl* owner_;
360
361 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
362};
363
[email protected]b172aee2012-04-10 17:05:26364// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32365
[email protected]b172aee2012-04-10 17:05:26366WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21367 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19368 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42369 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22370 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57371 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44372 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08373#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41374 accessible_parent_(NULL),
375#endif
[email protected]6ea6bdf2013-12-06 13:35:01376 frame_tree_(new NavigatorImpl(&controller_, this),
377 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34378 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23379 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
380 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34381 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26382 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56383 upload_size_(0),
384 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47385 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55386 capturer_count_(0),
387 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57388 is_being_destroyed_(false),
389 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15390 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01391 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38392 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21393 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
394 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00395 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21396 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44397 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42398 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
399 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46400 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
401 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55402 frame_tree_.SetFrameRemoveListener(
403 base::Bind(&WebContentsImpl::OnFrameRemoved,
404 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35405}
initial.commit09911bf2008-07-26 23:55:29406
[email protected]b172aee2012-04-10 17:05:26407WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32408 is_being_destroyed_ = true;
409
[email protected]d9030b82013-07-19 08:26:06410 ClearAllPowerSaveBlockers();
411
[email protected]b24b68a2012-09-24 21:57:26412 for (std::set<RenderWidgetHostImpl*>::iterator iter =
413 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
414 (*iter)->DetachDelegate();
415 }
416 created_widgets_.clear();
417
[email protected]3ab9cb82011-06-03 18:02:07418 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15419 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11420 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07421
[email protected]da8543762012-03-20 08:52:20422 if (color_chooser_)
423 color_chooser_->End();
424
[email protected]420ae012009-04-24 05:16:32425 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32426
[email protected]ca13a442012-04-17 14:00:12427 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21428 NotificationService::current()->Notify(
429 NOTIFICATION_WEB_CONTENTS_DESTROYED,
430 Source<WebContents>(this),
431 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32432
[email protected]fa944cb82013-11-15 17:51:21433 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27434 if (pending_rvh) {
435 FOR_EACH_OBSERVER(WebContentsObserver,
436 observers_,
437 RenderViewDeleted(pending_rvh));
438 }
439
440 FOR_EACH_OBSERVER(WebContentsObserver,
441 observers_,
[email protected]fa944cb82013-11-15 17:51:21442 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27443
[email protected]2db9bd72012-04-13 20:20:56444 FOR_EACH_OBSERVER(WebContentsObserver,
445 observers_,
446 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08447
[email protected]6934a702011-12-20 00:04:51448 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10449
450 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
451 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42452}
453
[email protected]d1198fd2012-08-13 22:50:19454WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59455 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19456 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03457 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59458 WebContentsImpl* new_contents = new WebContentsImpl(
459 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19460
[email protected]54944cde2012-12-09 09:24:59461 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19462 return new_contents;
463}
464
[email protected]b371a5652013-02-20 11:25:51465// static
[email protected]8eb04562013-03-06 03:41:14466BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36467 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53468 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54469 int guest_instance_id,
470 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39471 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39472
473 // This makes |new_contents| act as a guest.
474 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54475 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19476 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11477
[email protected]3de10bb32013-01-08 21:57:33478 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33479 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11480
[email protected]216be772013-01-25 00:22:27481 // We are instantiating a WebContents for browser plugin. Set its subframe bit
482 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42483 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27484
[email protected]8eb04562013-03-06 03:41:14485 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39486}
487
[email protected]b0936d22013-11-28 06:47:36488RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21489 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28490}
491
[email protected]7bb761892012-07-20 09:32:47492bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
493 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44494 return OnMessageReceived(render_view_host, NULL, message);
495}
496
497bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
498 RenderFrameHost* render_frame_host,
499 const IPC::Message& message) {
500 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56501 if (GetWebUI() &&
502 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17503 return true;
[email protected]d2353452012-01-19 19:53:56504 }
[email protected]f82d57b52011-04-27 19:13:17505
[email protected]d8c660432011-12-22 20:51:25506 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
507 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10508 while ((observer = it.GetNext()) != NULL)
509 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53510 return true;
[email protected]403415a2011-01-10 18:57:53511
[email protected]c80725d52013-12-06 06:22:26512 // Message handlers should be aware of which RenderViewHost sent the
[email protected]f114fa42013-12-06 17:06:44513 // message, which is temporarily stored in render_view_message_source_.
514 render_view_message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18515 bool handled = true;
516 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26517 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44518 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18520 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
521 OnDidLoadResourceFromMemoryCache)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
523 OnDidDisplayInsecureContent)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
525 OnDidRunInsecureContent)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
527 OnDocumentLoadedInFrame)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26529 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
530 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25531 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26532 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21533 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20534 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
535 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
536 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16537 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10538 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20539 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
541 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
542 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50543 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50544 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
545 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55546 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
547 OnBrowserPluginMessage(message))
548 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
549 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02550 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10552#if defined(OS_ANDROID)
553 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
554 OnFindMatchRectsReply)
555 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
556 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32557 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
558 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10559#endif
[email protected]d9030b82013-07-19 08:26:06560 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15561 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
562 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07563 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
564 OnShowValidationMessage)
565 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
566 OnHideValidationMessage)
567 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
568 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18569 IPC_MESSAGE_UNHANDLED(handled = false)
570 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44571 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18572
573 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39574 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18575 GetRenderProcessHost()->ReceivedBadMessage();
576 }
577
578 return handled;
579}
580
[email protected]b172aee2012-04-10 17:05:26581void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18582 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21583 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43584 if (delegate_)
585 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18586}
587
[email protected]d1198fd2012-08-13 22:50:19588NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56589 return controller_;
590}
591
[email protected]d1198fd2012-08-13 22:50:19592const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56593 return controller_;
594}
595
[email protected]8ff00d72012-10-23 19:12:21596BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55597 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30598}
599
[email protected]b172aee2012-04-10 17:05:26600const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24601 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32602 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51603 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31604}
605
[email protected]a093ce02013-07-22 20:53:14606const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24607 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32608 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24609 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
610}
611
612const GURL& WebContentsImpl::GetLastCommittedURL() const {
613 // We may not have a navigation entry yet.
614 NavigationEntry* entry = controller_.GetLastCommittedEntry();
615 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
616}
617
[email protected]8ff00d72012-10-23 19:12:21618WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31619 return delegate_;
620}
621
[email protected]8ff00d72012-10-23 19:12:21622void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31623 // TODO(cbentzel): remove this debugging code?
624 if (delegate == delegate_)
625 return;
626 if (delegate_)
627 delegate_->Detach(this);
628 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08629 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31630 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08631 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00632 if (view_)
633 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08634 }
[email protected]be1f56ab2011-12-22 06:55:31635}
636
[email protected]8ff00d72012-10-23 19:12:21637RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21638 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41639 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16640}
641
[email protected]60eca4eb2013-12-06 00:02:16642RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41643 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16644}
645
[email protected]a86c0e962013-12-17 17:10:39646void WebContentsImpl::ForEachFrame(
647 const base::Callback<void(RenderFrameHost*)>& on_frame) {
648 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
649}
650
651void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
652 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
653 delete message;
654}
655
[email protected]b172aee2012-04-10 17:05:26656RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21657 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31658}
659
[email protected]a04c9d02012-11-14 21:04:34660void WebContentsImpl::GetRenderViewHostAtPosition(
661 int x,
662 int y,
663 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
664 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
665 if (embedder)
666 embedder->GetRenderViewHostAtPosition(x, y, callback);
667 else
668 callback.Run(GetRenderViewHost(), x, y);
669}
670
[email protected]bfcfa692013-02-07 06:17:02671WebContents* WebContentsImpl::GetEmbedderWebContents() const {
672 BrowserPluginGuest* guest = GetBrowserPluginGuest();
673 if (guest)
674 return guest->embedder_web_contents();
675 return NULL;
676}
677
678int WebContentsImpl::GetEmbeddedInstanceID() const {
679 BrowserPluginGuest* guest = GetBrowserPluginGuest();
680 if (guest)
681 return guest->instance_id();
682 return 0;
683}
684
[email protected]6b618e62012-08-16 12:59:18685int WebContentsImpl::GetRoutingID() const {
686 if (!GetRenderViewHost())
687 return MSG_ROUTING_NONE;
688
689 return GetRenderViewHost()->GetRoutingID();
690}
691
[email protected]44470a22013-01-24 01:21:54692int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
693 return fullscreen_widget_routing_id_;
694}
695
[email protected]b172aee2012-04-10 17:05:26696RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21697 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31698}
699
[email protected]f8497342013-02-05 22:15:02700RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
701 BrowserPluginGuest* guest = GetBrowserPluginGuest();
702 if (guest && guest->embedder_web_contents()) {
703 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
704 }
705 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
706}
707
[email protected]4aebbca2013-09-17 22:26:49708RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
709 const {
710 RenderWidgetHost* const widget_host =
711 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
712 GetFullscreenWidgetRoutingID());
713 return widget_host ? widget_host->GetView() : NULL;
714}
715
[email protected]8ff00d72012-10-23 19:12:21716WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return view_.get();
718}
719
[email protected]8ff00d72012-10-23 19:12:21720WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56721 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03722 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
723 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22724 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58725 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22726 web_ui->SetController(controller);
727 return web_ui;
728 }
729
730 delete web_ui;
731 return NULL;
732}
733
[email protected]8ff00d72012-10-23 19:12:21734WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21735 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
736 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31737}
738
[email protected]8ff00d72012-10-23 19:12:21739WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21740 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34741}
742
[email protected]86ef6a392012-05-11 22:03:11743void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22744 if (GetUserAgentOverride() == override)
745 return;
746
747 renderer_preferences_.user_agent_override = override;
748
749 // Send the new override string to the renderer.
750 RenderViewHost* host = GetRenderViewHost();
751 if (host)
752 host->SyncRendererPrefs();
753
754 // Reload the page if a load is currently in progress to avoid having
755 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27756 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22757 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
758 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53759
760 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
761 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11762}
763
764const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22765 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11766}
767
[email protected]2ceee8f2014-01-14 18:02:08768#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41769void WebContentsImpl::SetParentNativeViewAccessible(
770gfx::NativeViewAccessible accessible_parent) {
771 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45772 if (GetRenderViewHost())
773 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41774}
775#endif
776
[email protected]fcf75d42013-12-03 20:11:26777const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55778 // Transient entries take precedence. They are used for interstitial pages
779 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23780 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08781 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21782 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30783 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23784 if (entry) {
[email protected]b5cca982011-05-26 04:42:08785 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23786 }
[email protected]fa944cb82013-11-15 17:51:21787 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
788 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58789 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54790 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32791 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54792 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35793 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26794 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54795 if (!title.empty())
796 return title;
797 }
798 }
799
800 // We use the title for the last committed entry rather than a pending
801 // navigation entry. For example, when the user types in a URL, we want to
802 // keep the old page's title until the new load has committed and we get a new
803 // title.
[email protected]96d185d2009-04-24 03:28:54804 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32805
[email protected]9eeafc012013-11-25 23:49:47806 // We make an exception for initial navigations.
807 if (controller_.IsInitialNavigation()) {
808 // We only want to use the title from the visible entry in one of two cases:
809 // 1. There's already a committed entry for an initial navigation, in which
810 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
811 // 2. The pending entry has been explicitly assigned a title to display.
812 //
813 // If there's no last committed entry and no assigned title, we should fall
814 // back to |page_title_when_no_navigation_entry_| rather than showing the
815 // URL.
816 if (entry ||
817 (controller_.GetVisibleEntry() &&
818 !controller_.GetVisibleEntry()->GetTitle().empty())) {
819 entry = controller_.GetVisibleEntry();
820 }
821 }
[email protected]59167c22013-06-03 18:07:32822
[email protected]45d0ef7f2011-01-05 13:46:23823 if (entry) {
[email protected]b5cca982011-05-26 04:42:08824 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23825 }
[email protected]987fc3a2011-05-26 14:18:09826
827 // |page_title_when_no_navigation_entry_| is finally used
828 // if no title cannot be retrieved.
829 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54830}
831
[email protected]b172aee2012-04-10 17:05:26832int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46833 return GetMaxPageIDForSiteInstance(GetSiteInstance());
834}
835
[email protected]b172aee2012-04-10 17:05:26836int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
837 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33838 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
839 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46840
[email protected]b6583592012-01-25 19:52:33841 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34842}
843
[email protected]b172aee2012-04-10 17:05:26844void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46845 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
846}
847
[email protected]b172aee2012-04-10 17:05:26848void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33849 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46850 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33851 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34852}
853
[email protected]ec6c05f2013-10-23 18:41:57854void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
855 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
856 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57857}
858
[email protected]b172aee2012-04-10 17:05:26859SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21860 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54861}
862
[email protected]b172aee2012-04-10 17:05:26863SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21864 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
865 GetRenderManager()->pending_render_view_host() :
866 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58867 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38868}
869
[email protected]b172aee2012-04-10 17:05:26870bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return waiting_for_response_;
876}
877
[email protected]b172aee2012-04-10 17:05:26878const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return load_state_;
880}
881
[email protected]fcf75d42013-12-03 20:11:26882const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return load_state_host_;
884}
885
[email protected]b172aee2012-04-10 17:05:26886uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31887 return upload_size_;
888}
889
[email protected]b172aee2012-04-10 17:05:26890uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31891 return upload_position_;
892}
893
[email protected]1ae93fb2013-06-14 03:38:56894std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56895 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39896 frame_tree_.ForEach(base::Bind(&CollectSites,
897 base::Unretained(GetBrowserContext()),
898 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56899 return sites;
900}
901
[email protected]b172aee2012-04-10 17:05:26902const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31903 return encoding_;
904}
905
[email protected]b172aee2012-04-10 17:05:26906bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31907 return displayed_insecure_content_;
908}
909
[email protected]54597982013-02-06 01:59:55910void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25911 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55912 ++capturer_count_;
913 DVLOG(1) << "There are now " << capturer_count_
914 << " capturing(s) of WebContentsImpl@" << this;
915}
916
917void WebContentsImpl::DecrementCapturerCount() {
918 --capturer_count_;
919 DVLOG(1) << "There are now " << capturer_count_
920 << " capturing(s) of WebContentsImpl@" << this;
921 DCHECK_LE(0, capturer_count_);
922
[email protected]5a652232013-02-12 06:15:25923 if (is_being_destroyed_)
924 return;
925
[email protected]1ac10dca2013-08-20 20:47:04926 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55927 DVLOG(1) << "Executing delayed WasHidden().";
928 WasHidden();
929 }
[email protected]be1f56ab2011-12-22 06:55:31930}
931
[email protected]f2bd40812013-07-20 04:30:44932int WebContentsImpl::GetCapturerCount() const {
933 return capturer_count_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31937 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
938 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
939 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49940}
941
[email protected]b172aee2012-04-10 17:05:26942void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
943 int error_code) {
[email protected]443b80e2010-12-14 00:42:23944 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34945 return;
946
[email protected]443b80e2010-12-14 00:42:23947 crashed_status_ = status;
948 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21949 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34950}
951
[email protected]b172aee2012-04-10 17:05:26952base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31953 return crashed_status_;
954}
955
[email protected]b172aee2012-04-10 17:05:26956bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31957 return is_being_destroyed_;
958}
959
[email protected]b172aee2012-04-10 17:05:26960void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34961 if (delegate_)
962 delegate_->NavigationStateChanged(this, changed_flags);
963}
964
[email protected]3e324142012-06-25 18:26:33965base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
966 return last_selected_time_;
967}
968
[email protected]9e2e4632012-07-27 16:38:41969void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54970 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04971 RenderWidgetHostViewPort* rwhv =
972 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16973 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29974 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43975#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16976 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43977#endif
978 }
[email protected]96d185d2009-04-24 03:28:54979
[email protected]5ac20162010-11-24 23:33:11980 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38981
[email protected]b9769d82012-02-10 00:23:59982 // The resize rect might have changed while this was inactive -- send the new
983 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58984 RenderViewHostImpl* rvh =
985 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59986 if (rvh) {
987 rvh->ResizeRectChanged(GetRootWindowResizerRect());
988 }
[email protected]96d185d2009-04-24 03:28:54989
[email protected]c0d9d5672013-10-09 07:38:03990 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
991
[email protected]54597982013-02-06 01:59:55992 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31993}
994
[email protected]b172aee2012-04-10 17:05:26995void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55996 // If there are entities capturing screenshots or video (e.g., mirroring),
997 // don't activate the "disable rendering" optimization.
998 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52999 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551000 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261001 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521002 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331003 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521004 // calls us).
[email protected]c30585c2012-02-16 15:02:041005 RenderWidgetHostViewPort* rwhv =
1006 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161007 if (rwhv)
[email protected]68ef3962013-09-26 06:45:291008 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:541009 }
1010
[email protected]c0d9d5672013-10-09 07:38:031011 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1012
[email protected]54597982013-02-06 01:59:551013 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371014}
1015
[email protected]b172aee2012-04-10 17:05:261016bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311017 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271018 return WillNotifyDisconnection() &&
1019 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581020 !static_cast<RenderViewHostImpl*>(
1021 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211025 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401026 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271027}
1028
[email protected]b172aee2012-04-10 17:05:261029WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441030 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451031 // We pass our own opener so that the cloned page can access it if it was
1032 // before.
[email protected]54944cde2012-12-09 09:24:591033 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451034 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591035 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191036 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221037 FOR_EACH_OBSERVER(WebContentsObserver,
1038 observers_,
1039 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271040 return tc;
1041}
1042
[email protected]14392a52012-05-02 20:28:441043void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211044 const NotificationSource& source,
1045 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441046 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211047 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1048 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501049 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1050 i != pending_widget_views_.end(); ++i) {
1051 if (host->GetView() == i->second) {
1052 pending_widget_views_.erase(i);
1053 break;
1054 }
1055 }
1056 break;
1057 }
[email protected]14392a52012-05-02 20:28:441058 default:
1059 NOTREACHED();
1060 }
1061}
1062
[email protected]ec6c05f2013-10-23 18:41:571063WebContents* WebContentsImpl::GetWebContents() {
1064 return this;
1065}
1066
[email protected]54944cde2012-12-09 09:24:591067void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211068 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361069 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211070 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431071 should_normally_be_visible_ = !params.initially_hidden;
1072
[email protected]fa944cb82013-11-15 17:51:211073 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041074 params.browser_context, params.site_instance, params.routing_id,
1075 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191076
[email protected]8ff00d72012-10-23 19:12:211077 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191078 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271079 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191080 CHECK(render_view_host_delegate_view_);
1081 } else {
[email protected]f8497342013-02-05 22:15:021082 WebContentsViewDelegate* delegate =
1083 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1084
[email protected]59383c782013-04-17 16:43:271085 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381086 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1087 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021088
[email protected]b5a40842012-11-28 15:26:111089 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381090 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431091 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111092 render_view_host_delegate_view_ = rv;
1093 view_.reset(rv);
1094 } else {
[email protected]f8497342013-02-05 22:15:021095 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111096 view_.reset(CreateWebContentsView(
1097 this, delegate, &render_view_host_delegate_view_));
1098 }
[email protected]d1198fd2012-08-13 22:50:191099 CHECK(render_view_host_delegate_view_);
1100 }
1101 CHECK(view_.get());
1102
[email protected]ed245db2012-12-18 08:00:451103 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591104 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191105
1106 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101107 if (opener_)
1108 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191109
1110 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211111 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1112 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441113#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191114 java_bridge_dispatcher_host_manager_.reset(
1115 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101116 date_time_chooser_.reset(new DateTimeChooserAndroid());
1117#endif
[email protected]d1198fd2012-08-13 22:50:191118}
1119
[email protected]7fff43e2013-05-21 20:21:101120void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1121 RemoveDestructionObserver(web_contents);
1122
[email protected]14392a52012-05-02 20:28:441123 // Clear the opener if it has been closed.
1124 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441125 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511126 return;
[email protected]14392a52012-05-02 20:28:441127 }
[email protected]ceee8cd2013-03-08 04:59:511128 // Clear a pending contents that has been closed before being shown.
1129 for (PendingContents::iterator iter = pending_contents_.begin();
1130 iter != pending_contents_.end();
1131 ++iter) {
1132 if (iter->second != web_contents)
1133 continue;
1134 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511135 return;
1136 }
1137 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441138}
1139
[email protected]7fff43e2013-05-21 20:21:101140void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1141 if (!ContainsKey(destruction_observers_, web_contents)) {
1142 destruction_observers_[web_contents] =
1143 new DestructionObserver(this, web_contents);
1144 }
1145}
1146
1147void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1148 DestructionObservers::iterator iter =
1149 destruction_observers_.find(web_contents);
1150 if (iter != destruction_observers_.end()) {
1151 delete destruction_observers_[web_contents];
1152 destruction_observers_.erase(iter);
1153 }
1154}
1155
[email protected]b172aee2012-04-10 17:05:261156void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311157 observers_.AddObserver(observer);
1158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311161 observers_.RemoveObserver(observer);
1162}
1163
[email protected]b172aee2012-04-10 17:05:261164void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341165 if (delegate_)
1166 delegate_->ActivateContents(this);
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121170 if (delegate_)
1171 delegate_->DeactivateContents(this);
1172}
1173
[email protected]b172aee2012-04-10 17:05:261174void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481175 if (delegate_)
1176 delegate_->LostCapture();
1177}
1178
[email protected]b24b68a2012-09-24 21:57:261179void WebContentsImpl::RenderWidgetDeleted(
1180 RenderWidgetHostImpl* render_widget_host) {
1181 if (is_being_destroyed_) {
1182 // |created_widgets_| might have been destroyed.
1183 return;
1184 }
1185
1186 std::set<RenderWidgetHostImpl*>::iterator iter =
1187 created_widgets_.find(render_widget_host);
1188 if (iter != created_widgets_.end())
1189 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541190
1191 if (render_widget_host &&
1192 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491193 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1194 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541195 FOR_EACH_OBSERVER(WebContentsObserver,
1196 observers_,
1197 DidDestroyFullscreenWidget(
1198 fullscreen_widget_routing_id_));
1199 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1200 }
[email protected]b24b68a2012-09-24 21:57:261201}
1202
[email protected]b172aee2012-04-10 17:05:261203bool WebContentsImpl::PreHandleKeyboardEvent(
1204 const NativeWebKeyboardEvent& event,
1205 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481206 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131207 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481208}
1209
[email protected]b172aee2012-04-10 17:05:261210void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061211 if (browser_plugin_embedder_ &&
1212 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1213 return;
1214 }
1215
[email protected]63954792011-07-11 04:17:481216 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131217 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481218}
1219
[email protected]fb3f066e2013-02-12 19:12:521220bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461221 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191222#if !defined(OS_MACOSX)
1223 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1224 // isn't done for two reasons:
1225 // -the OS already has a gesture to do this through pinch-zoom
1226 // -if a user starts an inertial scroll, let's go, and presses control
1227 // (i.e. control+tab) then the OS's buffered scroll events will come in
1228 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521229 if (delegate_ &&
1230 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461231 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521232 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1233 return true;
1234 }
[email protected]bccc4472013-04-18 16:37:191235#endif
[email protected]fb3f066e2013-02-12 19:12:521236
1237 return false;
1238}
1239
[email protected]2ceee8f2014-01-14 18:02:081240#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411241gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1242 return accessible_parent_;
1243}
1244#endif
1245
[email protected]b172aee2012-04-10 17:05:261246void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431247 if (delegate_)
1248 delegate_->HandleMouseDown();
1249}
1250
[email protected]b172aee2012-04-10 17:05:261251void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481252 if (delegate_)
1253 delegate_->HandleMouseUp();
1254}
1255
[email protected]590a634e2012-07-19 16:38:231256void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481257 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231258 delegate_->HandlePointerActivate();
1259}
1260
1261void WebContentsImpl::HandleGestureBegin() {
1262 if (delegate_)
1263 delegate_->HandleGestureBegin();
1264}
1265
1266void WebContentsImpl::HandleGestureEnd() {
1267 if (delegate_)
1268 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481269}
1270
[email protected]b172aee2012-04-10 17:05:261271void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491272 // This method is being called to enter or leave renderer-initiated fullscreen
1273 // mode. Either way, make sure any existing fullscreen widget is shut down
1274 // first.
1275 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1276 if (widget_view)
1277 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1278
[email protected]8a5e0ca2011-08-25 06:30:471279 if (delegate_)
1280 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1281}
1282
[email protected]b172aee2012-04-10 17:05:261283bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381284 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121285}
1286
[email protected]a9c81f02012-06-01 00:15:441287void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1288 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371289 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441290 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371291 } else {
1292 GotResponseToLockMouseRequest(false);
1293 }
1294}
1295
[email protected]b172aee2012-04-10 17:05:261296void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371297 if (delegate_)
1298 delegate_->LostMouseLock();
1299}
1300
[email protected]bafe6cd2012-05-23 23:09:501301void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201302 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501303 int route_id,
[email protected]227692c52013-05-31 22:43:041304 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131305 const ViewHostMsg_CreateWindow_Params& params,
1306 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501307 // We usually create the new window in the same BrowsingInstance (group of
1308 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551309 // if the opener is being suppressed (in a non-guest), we create a new
1310 // SiteInstance in its own BrowsingInstance.
1311 bool is_guest = GetRenderProcessHost()->IsGuest();
1312
[email protected]04cbd3d2013-12-04 04:58:201313 // If the opener is to be suppressed, the new window can be in any process.
1314 // Since routing ids are process specific, we must not have one passed in
1315 // as argument here.
1316 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1317
[email protected]bafe6cd2012-05-23 23:09:501318 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551319 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571320 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501321 GetSiteInstance();
1322
[email protected]04cbd3d2013-12-04 04:58:201323 // A message to create a new window can only come from the active process for
1324 // this WebContentsImpl instance. If any other process sends the request,
1325 // it is invalid and the process must be terminated.
1326 if (GetRenderProcessHost()->GetID() != render_process_id) {
1327 base::ProcessHandle process_handle =
1328 RenderProcessHost::FromID(render_process_id)->GetHandle();
1329 if (process_handle != base::kNullProcessHandle) {
1330 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391331 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201332 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1333 }
1334 return;
1335 }
1336
[email protected]d1198fd2012-08-13 22:50:191337 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341338 //
1339 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301340 const std::string& partition_id =
1341 GetContentClient()->browser()->
1342 GetStoragePartitionIdForSite(GetBrowserContext(),
1343 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461344 StoragePartition* partition = BrowserContext::GetStoragePartition(
1345 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411346 DOMStorageContextWrapper* dom_storage_context =
1347 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191348 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1349 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1350 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371351
1352 if (delegate_ &&
1353 !delegate_->ShouldCreateWebContents(this,
1354 route_id,
1355 params.window_container_type,
1356 params.frame_name,
1357 params.target_url,
1358 partition_id,
1359 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011360 if (route_id != MSG_ROUTING_NONE &&
1361 !RenderViewHost::FromID(render_process_id, route_id)) {
1362 // If the embedder didn't create a WebContents for this route, we need to
1363 // delete the RenderView that had already been created.
1364 Send(new ViewMsg_Close(route_id));
1365 }
[email protected]dd6730412013-08-14 15:03:371366 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1367 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1368 main_frame_route_id);
1369 return;
1370 }
1371
1372 // Create the new web contents. This will automatically create the new
1373 // WebContentsView. In the future, we may want to create the view separately.
1374 WebContentsImpl* new_contents =
1375 new WebContentsImpl(GetBrowserContext(),
1376 params.opener_suppressed ? NULL : this);
1377
[email protected]d1198fd2012-08-13 22:50:191378 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301379 partition_id,
[email protected]d1198fd2012-08-13 22:50:191380 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461381 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591382 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041383 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551384 if (!is_guest) {
1385 create_params.context = view_->GetNativeView();
1386 create_params.initial_size = view_->GetContainerSize();
1387 } else {
1388 // This makes |new_contents| act as a guest.
1389 // For more info, see comment above class BrowserPluginGuest.
1390 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1391 WebContentsImpl* new_contents_impl =
1392 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461393 BrowserPluginGuest::CreateWithOpener(instance_id,
1394 new_contents_impl->opener() != NULL,
1395 new_contents_impl,
1396 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551397 }
[email protected]1ac10dca2013-08-20 20:47:041398 if (params.disposition == NEW_BACKGROUND_TAB)
1399 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591400 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191401
[email protected]c4538072013-03-18 02:17:551402 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341403 // will be shown immediately).
1404 if (!params.opener_suppressed) {
1405 if (!is_guest) {
1406 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501407
[email protected]d70bea92013-04-05 04:23:341408 // TODO(brettw): It seems bogus that we have to call this function on the
1409 // newly created object and give it one of its own member variables.
1410 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1411 }
[email protected]bafe6cd2012-05-23 23:09:501412 // Save the created window associated with the route so we can show it
1413 // later.
1414 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1415 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101416 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501417 }
1418
1419 if (delegate_) {
1420 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131421 this, params.opener_frame_id, params.frame_name,
1422 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501423 }
1424
1425 if (params.opener_suppressed) {
1426 // When the opener is suppressed, the original renderer cannot access the
1427 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001428 bool was_blocked = false;
1429 if (delegate_) {
1430 gfx::Rect initial_pos;
1431 delegate_->AddNewContents(
1432 this, new_contents, params.disposition, initial_pos,
1433 params.user_gesture, &was_blocked);
1434 }
1435 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211436 OpenURLParams open_params(params.target_url,
1437 Referrer(),
1438 CURRENT_TAB,
1439 PAGE_TRANSITION_LINK,
1440 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301441 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001442 new_contents->OpenURL(open_params);
1443 }
[email protected]bafe6cd2012-05-23 23:09:501444 }
1445}
1446
[email protected]a8504022013-12-04 20:23:511447void WebContentsImpl::CreateNewWidget(int render_process_id,
1448 int route_id,
[email protected]180ef242013-11-07 06:50:461449 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511450 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501451}
1452
[email protected]a8504022013-12-04 20:23:511453void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1454 int route_id) {
1455 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501456}
1457
[email protected]a8504022013-12-04 20:23:511458void WebContentsImpl::CreateNewWidget(int render_process_id,
1459 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501460 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461461 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211462 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511463 // A message to create a new widget can only come from the active process for
1464 // this WebContentsImpl instance. If any other process sends the request,
1465 // it is invalid and the process must be terminated.
1466 if (process->GetID() != render_process_id) {
1467 base::ProcessHandle process_handle =
1468 RenderProcessHost::FromID(render_process_id)->GetHandle();
1469 if (process_handle != base::kNullProcessHandle) {
1470 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391471 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511472 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1473 }
1474 return;
1475 }
1476
[email protected]bafe6cd2012-05-23 23:09:501477 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041478 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261479 created_widgets_.insert(widget_host);
1480
[email protected]83918ec2013-01-10 15:37:191481 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1482 view_->CreateViewForPopupWidget(widget_host));
1483 if (!widget_view)
1484 return;
[email protected]bafe6cd2012-05-23 23:09:501485 if (!is_fullscreen) {
1486 // Popups should not get activated.
1487 widget_view->SetPopupType(popup_type);
1488 }
1489 // Save the created widget associated with the route so we can show it later.
1490 pending_widget_views_[route_id] = widget_view;
1491
1492#if defined(OS_MACOSX)
1493 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1494 // to allow it to survive the trip without being hosted.
1495 base::mac::NSObjectRetain(widget_view->GetNativeView());
1496#endif
1497}
1498
1499void WebContentsImpl::ShowCreatedWindow(int route_id,
1500 WindowOpenDisposition disposition,
1501 const gfx::Rect& initial_pos,
1502 bool user_gesture) {
1503 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001504 if (contents) {
1505 WebContentsDelegate* delegate = GetDelegate();
1506 if (delegate) {
1507 delegate->AddNewContents(
1508 this, contents, disposition, initial_pos, user_gesture, NULL);
1509 }
1510 }
[email protected]bafe6cd2012-05-23 23:09:501511}
1512
1513void WebContentsImpl::ShowCreatedWidget(int route_id,
1514 const gfx::Rect& initial_pos) {
1515 ShowCreatedWidget(route_id, false, initial_pos);
1516}
1517
1518void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1519 ShowCreatedWidget(route_id, true, gfx::Rect());
1520}
1521
1522void WebContentsImpl::ShowCreatedWidget(int route_id,
1523 bool is_fullscreen,
1524 const gfx::Rect& initial_pos) {
1525 if (delegate_)
1526 delegate_->RenderWidgetShowing();
1527
1528 RenderWidgetHostViewPort* widget_host_view =
1529 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1530 if (!widget_host_view)
1531 return;
[email protected]4aebbca2013-09-17 22:26:491532 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311533 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1534 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491535 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1536 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1537 delegate_->ToggleFullscreenModeForTab(this, true);
1538 } else {
1539 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491540 }
[email protected]4aebbca2013-09-17 22:26:491541 FOR_EACH_OBSERVER(WebContentsObserver,
1542 observers_,
1543 DidShowFullscreenWidget(route_id));
1544 if (!widget_host_view->HasFocus())
1545 widget_host_view->Focus();
1546 } else {
[email protected]f8497342013-02-05 22:15:021547 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491548 }
[email protected]89054502012-06-03 10:29:241549
1550 RenderWidgetHostImpl* render_widget_host_impl =
1551 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1552 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311553 // Only allow privileged mouse lock for fullscreen render widget, which is
1554 // used to implement Pepper Flash fullscreen.
1555 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501556
1557#if defined(OS_MACOSX)
1558 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1559 // properly embedded (or purposefully ignored) we can release the retain we
1560 // took in CreateNewWidget().
1561 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1562#endif
1563}
1564
1565WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1566 PendingContents::iterator iter = pending_contents_.find(route_id);
1567
1568 // Certain systems can block the creation of new windows. If we didn't succeed
1569 // in creating one, just return NULL.
1570 if (iter == pending_contents_.end()) {
1571 return NULL;
1572 }
1573
1574 WebContentsImpl* new_contents = iter->second;
1575 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101576 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501577
[email protected]d70bea92013-04-05 04:23:341578 // Don't initialize the guest WebContents immediately.
1579 if (new_contents->GetRenderProcessHost()->IsGuest())
1580 return new_contents;
1581
[email protected]bafe6cd2012-05-23 23:09:501582 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1583 !new_contents->GetRenderViewHost()->GetView())
1584 return NULL;
1585
1586 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1587 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1588 return new_contents;
1589}
1590
1591RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1592 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1593 if (iter == pending_widget_views_.end()) {
1594 DCHECK(false);
1595 return NULL;
1596 }
1597
1598 RenderWidgetHostView* widget_host_view = iter->second;
1599 pending_widget_views_.erase(route_id);
1600
1601 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1602 if (!widget_host->GetProcess()->HasConnection()) {
1603 // The view has gone away or the renderer crashed. Nothing to do.
1604 return NULL;
1605 }
1606
1607 return widget_host_view;
1608}
1609
[email protected]f56c7872013-06-18 12:31:571610void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501611 // Allow WebContentsDelegates to handle the context menu operation first.
1612 if (delegate_ && delegate_->HandleContextMenu(params))
1613 return;
1614
[email protected]f56c7872013-06-18 12:31:571615 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501616}
1617
[email protected]f13b4202012-06-12 23:53:231618void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091619 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211620 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231621 if (delegate_)
1622 delegate_->RequestMediaAccessPermission(this, request, callback);
1623 else
[email protected]b5f76742013-04-29 15:05:591624 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231625}
1626
[email protected]cc9200432013-07-23 23:02:401627SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1628 SiteInstance* instance) {
1629 return controller_.GetSessionStorageNamespace(instance);
1630}
1631
[email protected]9b159a52013-10-03 17:24:551632FrameTree* WebContentsImpl::GetFrameTree() {
1633 return &frame_tree_;
1634}
1635
[email protected]edc3af82013-12-12 21:24:071636void WebContentsImpl::OnShowValidationMessage(
1637 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291638 const base::string16& main_text,
1639 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071640 if (delegate_)
1641 delegate_->ShowValidationMessage(
1642 this, anchor_in_root_view, main_text, sub_text);
1643}
1644
1645void WebContentsImpl::OnHideValidationMessage() {
1646 if (delegate_)
1647 delegate_->HideValidationMessage(this);
1648}
1649
1650void WebContentsImpl::OnMoveValidationMessage(
1651 const gfx::Rect& anchor_in_root_view) {
1652 if (delegate_)
1653 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1654}
1655
[email protected]32deec62013-05-15 23:55:041656void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1657 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441658 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041659}
1660
[email protected]b172aee2012-04-10 17:05:261661void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231662 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331663 if (delegate_)
1664 delegate_->UpdatePreferredSize(this, pref_size);
1665}
1666
[email protected]b172aee2012-04-10 17:05:261667void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341668 if (delegate_)
1669 delegate_->ResizeDueToAutoResize(this, new_size);
1670}
1671
[email protected]b172aee2012-04-10 17:05:261672WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201673 if (!delegate_)
1674 return NULL;
[email protected]00c37fc2011-08-02 00:22:501675
[email protected]e5d549d2011-12-28 01:29:201676 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201677 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341678}
1679
[email protected]6b618e62012-08-16 12:59:181680bool WebContentsImpl::Send(IPC::Message* message) {
1681 if (!GetRenderViewHost()) {
1682 delete message;
1683 return false;
1684 }
1685
1686 return GetRenderViewHost()->Send(message);
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501690 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251691 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231692 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251693 reload_type);
[email protected]876bc832010-09-07 16:29:541694}
[email protected]96d185d2009-04-24 03:28:541695
[email protected]a86c0e962013-12-17 17:10:391696void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1697 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391699 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441700}
1701
[email protected]20ca0382013-02-28 19:50:071702void WebContentsImpl::AttachInterstitialPage(
1703 InterstitialPageImpl* interstitial_page) {
1704 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211705 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291706
1707 // Cancel any visible dialogs so that they don't interfere with the
1708 // interstitial.
1709 if (dialog_manager_)
1710 dialog_manager_->CancelActiveAndPendingDialogs(this);
1711
[email protected]20ca0382013-02-28 19:50:071712 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1713 DidAttachInterstitialPage());
1714}
1715
1716void WebContentsImpl::DetachInterstitialPage() {
1717 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211718 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1720 DidDetachInterstitialPage());
1721}
1722
[email protected]b172aee2012-04-10 17:05:261723bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231724 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501725 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031726 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1727
[email protected]19e81142011-10-03 16:19:401728 // The renderer will reject IPC messages with URLs longer than
1729 // this limit, so don't attempt to navigate with a longer URL.
[email protected]f16cc6782013-12-16 23:42:571730 if (entry.GetURL().spec().size() > GetMaxURLChars()) {
1731 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars()
[email protected]3adab1c2013-09-09 21:23:431732 << " characters.";
[email protected]19e81142011-10-03 16:19:401733 return false;
[email protected]3adab1c2013-09-09 21:23:431734 }
[email protected]19e81142011-10-03 16:19:401735
[email protected]a1b99262013-12-27 21:56:221736 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to
1737 // use when --site-per-process is used.
1738 RenderFrameHostManager* manager = GetRenderManager();
1739 if (entry.frame_tree_node_id() != -1 &&
1740 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) {
1741 int64 frame_tree_node_id = entry.frame_tree_node_id();
1742 manager = frame_tree_.FindByID(frame_tree_node_id)->render_manager();
1743 }
1744
[email protected]9f76c1e2012-03-05 15:15:581745 RenderViewHostImpl* dest_render_view_host =
[email protected]a1b99262013-12-27 21:56:221746 static_cast<RenderViewHostImpl*>(manager->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401747 if (!dest_render_view_host)
1748 return false; // Unable to create the desired render view host.
1749
[email protected]80a8fad2011-01-29 04:02:381750 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071751 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581752 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271753 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501754 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031755 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1756 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211757 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231758 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271759 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211760 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231761 CHECK(0);
1762 }
[email protected]54ec6472010-04-09 19:39:581763
[email protected]7bb761892012-07-20 09:32:471764 // Notify observers that we will navigate in this RV.
1765 FOR_EACH_OBSERVER(WebContentsObserver,
1766 observers_,
1767 AboutToNavigateRenderView(dest_render_view_host));
1768
[email protected]96d185d2009-04-24 03:28:541769 // Used for page load time metrics.
1770 current_load_start_ = base::TimeTicks::Now();
1771
1772 // Navigate in the desired RenderViewHost.
[email protected]a1b99262013-12-27 21:56:221773 // TODO(creis): As a temporary hack, we currently do cross-process subframe
1774 // navigations in a top-level frame of the new process. Thus, we don't yet
1775 // need to store the correct frame ID in ViewMsg_Navigate_Params.
[email protected]056de2d2009-06-26 16:41:341776 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271777 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471778 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341779 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541780
[email protected]36fc0392011-12-25 03:59:511781 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541782 // HACK!! This code suppresses javascript: URLs from being added to
1783 // session history, which is what we want to do for javascript: URLs that
1784 // do not generate content. What we really need is a message from the
1785 // renderer telling us that a new page was not created. The same message
1786 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351787 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541788 return false;
1789 }
1790
[email protected]3c9e1872010-11-18 16:17:491791 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391792 FOR_EACH_OBSERVER(
1793 WebContentsObserver,
1794 observers_,
1795 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541796
[email protected]09b29342011-06-24 19:18:481797 if (delegate_)
1798 delegate_->DidNavigateToPendingEntry(this);
1799
[email protected]d5f942ba2008-09-26 19:30:341800 return true;
1801}
1802
[email protected]b172aee2012-04-10 17:05:261803void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331804 const SiteInstance* site_instance,
1805 int history_length,
1806 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411807 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1808 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211809 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191810 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141811 return;
[email protected]9e1ad4b2011-08-14 16:49:191812 }
[email protected]9f76c1e2012-03-05 15:15:581813 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191814 if (!rvh) {
1815 NOTREACHED();
1816 return;
1817 }
[email protected]9f76c1e2012-03-05 15:15:581818 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191819 NOTREACHED();
1820 return;
1821 }
[email protected]6b618e62012-08-16 12:59:181822 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1823 history_length,
1824 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141825}
1826
[email protected]b172aee2012-04-10 17:05:261827void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271828 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211829 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541830 return;
1831 }
[email protected]9f76c1e2012-03-05 15:15:581832 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541833}
1834
[email protected]b172aee2012-04-10 17:05:261835bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211836 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541837}
1838
[email protected]b172aee2012-04-10 17:05:261839InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211840 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221841}
1842
[email protected]b172aee2012-04-10 17:05:261843bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161844 // WebKit creates Document object when MIME type is application/xhtml+xml,
1845 // so we also support this MIME type.
1846 return contents_mime_type_ == "text/html" ||
1847 contents_mime_type_ == "text/xml" ||
1848 contents_mime_type_ == "application/xhtml+xml" ||
1849 contents_mime_type_ == "text/plain" ||
1850 contents_mime_type_ == "text/css" ||
1851 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1852}
1853
[email protected]b172aee2012-04-10 17:05:261854void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591855 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161856 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551857 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011858 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141859 return;
[email protected]c7dd2f62011-07-18 15:57:591860 }
1861
1862 Stop();
1863
1864 // Create the save package and possibly prompt the user for the name to save
1865 // the page as. The user prompt is an asynchronous operation that runs on
1866 // another thread.
1867 save_package_ = new SavePackage(this);
1868 save_package_->GetSaveInfo();
1869}
1870
1871// Used in automated testing to bypass prompting the user for file names.
1872// Instead, the names and paths are hard coded rather than running them through
1873// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341874bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1875 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211876 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591877 // Stop the page from navigating.
1878 Stop();
1879
1880 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211881 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591882}
1883
[email protected]3c71576ce2013-07-23 02:00:011884void WebContentsImpl::SaveFrame(const GURL& url,
1885 const Referrer& referrer) {
1886 if (!GetURL().is_valid())
1887 return;
1888 bool is_main_frame = (url == GetURL());
1889
1890 DownloadManager* dlm =
1891 BrowserContext::GetDownloadManager(GetBrowserContext());
1892 if (!dlm)
1893 return;
1894 int64 post_id = -1;
1895 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271896 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011897 if (entry)
1898 post_id = entry->GetPostID();
1899 }
1900 scoped_ptr<DownloadUrlParameters> params(
1901 DownloadUrlParameters::FromWebContents(this, url));
1902 params->set_referrer(referrer);
1903 params->set_post_id(post_id);
1904 params->set_prefer_cache(true);
1905 if (post_id >= 0)
1906 params->set_method("POST");
1907 params->set_prompt(true);
1908 dlm->DownloadUrl(params.Pass());
1909}
1910
[email protected]b172aee2012-04-10 17:05:261911void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341912 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481913 const base::Callback<void(int64)>& callback) {
1914 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121915}
1916
[email protected]6286a372013-10-09 04:03:271917// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261918bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271919 NavigationEntryImpl* visible_entry =
1920 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1921 return (visible_entry != NULL &&
1922 visible_entry->site_instance() == GetSiteInstance() &&
1923 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321924}
1925
[email protected]b172aee2012-04-10 17:05:261926const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271927 return contents_mime_type_;
1928}
1929
[email protected]b172aee2012-04-10 17:05:261930bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271931 return notify_disconnection_;
1932}
1933
[email protected]b172aee2012-04-10 17:05:261934void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311935 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181936 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161937}
1938
[email protected]b172aee2012-04-10 17:05:261939void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311940 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181941 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161942}
1943
[email protected]8ff00d72012-10-23 19:12:211944RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271945 return &renderer_preferences_;
1946}
1947
[email protected]e35ccd52012-05-23 16:22:471948void WebContentsImpl::Close() {
1949 Close(GetRenderViewHost());
1950}
1951
[email protected]cf200a562013-05-03 16:24:291952void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461953 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291954 if (browser_plugin_embedder_.get())
1955 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1956 screen_x, screen_y, operation);
1957 if (GetRenderViewHost())
1958 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1959 screen_x, screen_y, operation);
1960}
1961
1962void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1963 int screen_x, int screen_y) {
1964 if (browser_plugin_embedder_.get())
1965 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1966 screen_x, screen_y);
1967 if (GetRenderViewHost())
1968 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1969 screen_x, screen_y);
1970}
1971
[email protected]d60f3702013-12-26 16:30:241972void WebContentsImpl::DidGetResourceResponseStart(
1973 const ResourceRequestDetails& details) {
1974 controller_.ssl_manager()->DidStartResourceResponse(details);
1975
1976 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1977 DidGetResourceResponseStart(details));
1978
1979 // TODO(avi): Remove. http://crbug.com/170921
1980 NotificationService::current()->Notify(
1981 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1982 Source<WebContents>(this),
1983 Details<const ResourceRequestDetails>(&details));
1984}
1985
1986void WebContentsImpl::DidGetRedirectForResourceRequest(
1987 RenderViewHost* render_view_host,
1988 const ResourceRedirectDetails& details) {
1989 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1990
1991 FOR_EACH_OBSERVER(
1992 WebContentsObserver,
1993 observers_,
1994 DidGetRedirectForResourceRequest(render_view_host, details));
1995
1996 // TODO(avi): Remove. http://crbug.com/170921
1997 NotificationService::current()->Notify(
1998 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1999 Source<WebContents>(this),
2000 Details<const ResourceRedirectDetails>(&details));
2001}
2002
[email protected]b172aee2012-04-10 17:05:262003void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522004 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582005 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512006 if (delegate_)
2007 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292008 if (browser_plugin_embedder_.get())
2009 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342010}
2011
[email protected]e35ccd52012-05-23 16:22:472012void WebContentsImpl::UserGestureDone() {
2013 OnUserGesture();
2014}
2015
[email protected]b172aee2012-04-10 17:05:262016void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272017 closed_by_user_gesture_ = value;
2018}
2019
[email protected]b172aee2012-04-10 17:05:262020bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272021 return closed_by_user_gesture_;
2022}
2023
[email protected]b172aee2012-04-10 17:05:262024double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052025 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562026 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252027 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172028 return 0;
[email protected]b75b8292010-10-01 07:28:252029
2030 double zoom_level;
2031 if (temporary_zoom_settings_) {
2032 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582033 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252034 } else {
[email protected]2ae88d12011-10-14 09:11:192035 GURL url;
[email protected]6286a372013-10-09 04:03:272036 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192037 // Since zoom map is updated using rewritten URL, use rewritten URL
2038 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272039 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022040 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2041 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252042 }
[email protected]d0b8d092010-10-25 04:05:172043 return zoom_level;
2044}
[email protected]b75b8292010-10-01 07:28:252045
[email protected]b172aee2012-04-10 17:05:262046int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592047 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172048 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012049 // Calculate the zoom percent from the factor. Round up to the nearest whole
2050 // number.
[email protected]b75b8292010-10-01 07:28:252051 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492052 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252053 *enable_decrement = percent > minimum_zoom_percent_;
2054 *enable_increment = percent < maximum_zoom_percent_;
2055 return percent;
2056}
2057
[email protected]b172aee2012-04-10 17:05:262058void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502059 if (!delegate_)
2060 return;
2061
[email protected]6286a372013-10-09 04:03:272062 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2063 if (!entry)
[email protected]1788e772010-12-15 16:40:502064 return;
2065
[email protected]6286a372013-10-09 04:03:272066 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042070 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272071 if (!delegate_)
2072 return;
2073
[email protected]691aa2f2013-05-28 22:52:042074 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272075}
2076
[email protected]b172aee2012-04-10 17:05:262077int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272078 return minimum_zoom_percent_;
2079}
2080
[email protected]b172aee2012-04-10 17:05:262081int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272082 return maximum_zoom_percent_;
2083}
2084
[email protected]b172aee2012-04-10 17:05:262085gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:232086 return preferred_size_;
2087}
2088
[email protected]b172aee2012-04-10 17:05:262089bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272090 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582091 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272092}
2093
[email protected]b172aee2012-04-10 17:05:262094bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442095 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502096}
2097
[email protected]cb805452013-05-22 15:16:212098void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182099 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212100 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202101}
2102
[email protected]cb805452013-05-22 15:16:212103void WebContentsImpl::DidEndColorChooser() {
2104 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2105 color_chooser_identifier_));
2106 color_chooser_.reset();
2107 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202108}
2109
[email protected]41225fe2013-03-29 05:32:022110int WebContentsImpl::DownloadImage(const GURL& url,
2111 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302112 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022113 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392114 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302115 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022116 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392117 return id;
2118}
2119
[email protected]5dcaf8e2013-12-28 01:31:422120bool WebContentsImpl::IsSubframe() const {
2121 return is_subframe_;
2122}
2123
[email protected]9649d492014-01-10 07:15:522124void WebContentsImpl::SetZoomLevel(double level) {
2125 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2126 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2127 if (embedder)
2128 embedder->SetZoomLevel(level);
2129}
2130
[email protected]36ec24f2014-01-09 00:32:082131void WebContentsImpl::Find(int request_id,
2132 const base::string16& search_text,
2133 const blink::WebFindOptions& options) {
2134 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2135}
2136
2137void WebContentsImpl::StopFinding(StopFindAction action) {
2138 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2139}
2140
[email protected]b172aee2012-04-10 17:05:262141bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272142 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202143 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332144 return true;
2145 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272149 if (delegate_)
2150 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212151}
2152
[email protected]52913802013-12-10 05:52:182153void WebContentsImpl::DidStartProvisionalLoad(
2154 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572155 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132156 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572157 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182158 const GURL& validated_url,
2159 bool is_error_page,
2160 bool is_iframe_srcdoc) {
2161 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572162 DidChangeLoadProgress(0);
2163
[email protected]0d60f0192011-04-14 12:40:102164 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132166 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2167 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182168 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542169
2170 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182171 FOR_EACH_OBSERVER(
2172 WebContentsObserver,
2173 observers_,
2174 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582175 render_frame_host));
[email protected]400992b2012-06-14 00:03:542176 }
2177}
2178
[email protected]3109fbb72014-01-06 23:57:152179void WebContentsImpl::DidFailProvisionalLoadWithError(
2180 RenderFrameHostImpl* render_frame_host,
2181 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2182 GURL validated_url(params.url);
2183 FOR_EACH_OBSERVER(
2184 WebContentsObserver,
2185 observers_,
2186 DidFailProvisionalLoad(params.frame_id,
2187 params.frame_unique_name,
2188 params.is_main_frame,
2189 validated_url,
2190 params.error_code,
2191 params.error_description,
2192 render_frame_host->render_view_host()));
2193}
2194
[email protected]52913802013-12-10 05:52:182195void WebContentsImpl::NotifyChangedNavigationState(
2196 InvalidateTypes changed_flags) {
2197 NotifyNavigationStateChanged(changed_flags);
2198}
2199
[email protected]400992b2012-06-14 00:03:542200void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582201 RenderFrameHostImpl* render_frame_host,
2202 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542203 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582204 FOR_EACH_OBSERVER(
2205 WebContentsObserver,
2206 observers_,
2207 ProvisionalChangeToMainFrameUrl(validated_target_url,
2208 render_frame_host));
[email protected]724159a2010-12-30 01:11:182209}
2210
[email protected]b172aee2012-04-10 17:05:262211void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182212 const GURL& url,
[email protected]70435962011-08-02 20:13:282213 const std::string& security_info,
2214 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182215 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282216 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192217 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182218 cache.Increment();
2219
2220 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082221 int cert_id = 0;
2222 net::CertStatus cert_status = 0;
2223 int security_bits = -1;
2224 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122225 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212226 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122227 &security_bits, &connection_status,
2228 &signed_certificate_timestamp_ids);
2229 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212230 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002231 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2232 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182233
[email protected]b0f724c2013-09-05 04:21:132234 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2235
2236 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2237 DidLoadResourceFromMemoryCache(details));
2238
[email protected]8bfc8272013-09-09 20:10:532239 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2240 scoped_refptr<net::URLRequestContextGetter> request_context(
2241 resource_type == ResourceType::MEDIA ?
2242 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2243 GetRenderProcessHost()->GetID()) :
2244 GetBrowserContext()->GetRequestContextForRenderProcess(
2245 GetRenderProcessHost()->GetID()));
2246 BrowserThread::PostTask(
2247 BrowserThread::IO,
2248 FROM_HERE,
2249 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2250 }
[email protected]724159a2010-12-30 01:11:182251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392254 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182255 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192256 SSLManager::NotifySSLInternalStateChanged(
2257 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022261 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582262 LOG(WARNING) << security_origin << " ran insecure content from "
2263 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392264 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412265 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392266 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182267 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412268 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192269 SSLManager::NotifySSLInternalStateChanged(
2270 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182271}
2272
[email protected]b172aee2012-04-10 17:05:262273void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442274 FOR_EACH_OBSERVER(
2275 WebContentsObserver, observers_,
2276 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312280 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062281 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312282 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062283 GURL validated_url(url);
[email protected]a1b99262013-12-27 21:56:222284
2285 // --site-per-process mode has a short-term hack allowing cross-process
2286 // subframe pages to commit thinking they are top-level. Correct it here to
2287 // avoid confusing the observers.
2288 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2289 render_view_message_source_ != GetRenderViewHost())
2290 is_main_frame = false;
2291
[email protected]f114fa42013-12-06 17:06:442292 RenderProcessHost* render_process_host =
2293 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422294 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252295 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472296 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442297 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312298}
2299
[email protected]b172aee2012-04-10 17:05:262300void WebContentsImpl::OnDidFailLoadWithError(
2301 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062302 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262303 bool is_main_frame,
2304 int error_code,
[email protected]fcf75d42013-12-03 20:11:262305 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062306 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442307 RenderProcessHost* render_process_host =
2308 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422309 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252310 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312311 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472312 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442313 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182314}
2315
[email protected]b172aee2012-04-10 17:05:262316void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262317 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232318 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252319 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262320 if (!entry)
2321 return;
2322 // Note that we don't call NavigationController::GotToOffset() as we don't
2323 // want to create a pending navigation entry (it might end up lingering
2324 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252325 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212326 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512327 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212328 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472329 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572330
2331 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2332 // it in now that we know. This allows us to find the entry when it commits.
2333 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232334 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332335 entry->set_site_instance(
2336 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572337 }
[email protected]216813952011-05-19 22:21:262338 }
2339}
2340
[email protected]b172aee2012-04-10 17:05:262341void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2342 int maximum_percent,
2343 bool remember) {
[email protected]216813952011-05-19 22:21:262344 minimum_zoom_percent_ = minimum_percent;
2345 maximum_zoom_percent_ = maximum_percent;
2346 temporary_zoom_settings_ = !remember;
2347}
2348
[email protected]b172aee2012-04-10 17:05:262349void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342350 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432351 if (!delegate_)
2352 return;
2353
[email protected]b9535422012-02-09 01:47:592354 ChildProcessSecurityPolicyImpl* policy =
2355 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222356 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592357 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212358}
2359
[email protected]b172aee2012-04-10 17:05:262360void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432361 if (delegate_)
2362 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202363}
2364
[email protected]b172aee2012-04-10 17:05:262365void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2366 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262367 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362368 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432369 if (!delegate_)
2370 return;
2371
[email protected]b9535422012-02-09 01:47:592372 ChildProcessSecurityPolicyImpl* policy =
2373 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322374 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592375 return;
[email protected]8f810632013-06-06 22:33:322376
[email protected]3a3b75a2012-06-01 08:38:362377 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202378}
2379
[email protected]b172aee2012-04-10 17:05:262380void WebContentsImpl::OnFindReply(int request_id,
2381 int number_of_matches,
2382 const gfx::Rect& selection_rect,
2383 int active_match_ordinal,
2384 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432385 if (delegate_) {
2386 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2387 active_match_ordinal, final_update);
2388 }
[email protected]b888919c2011-09-02 00:32:162389}
2390
[email protected]59363fc92012-09-05 03:46:312391#if defined(OS_ANDROID)
2392void WebContentsImpl::OnFindMatchRectsReply(
2393 int version,
2394 const std::vector<gfx::RectF>& rects,
2395 const gfx::RectF& active_rect) {
2396 if (delegate_)
2397 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2398}
[email protected]583418cc2013-01-17 14:01:102399
[email protected]1ff427972013-02-07 21:14:072400void WebContentsImpl::OnOpenDateTimeDialog(
2401 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092402 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2403 GetRenderViewHost(),
2404 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132405 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092406 value.minimum,
2407 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172408 value.step,
2409 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102410}
2411
[email protected]a794f3a2013-10-30 17:00:322412void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2413 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442414 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322415}
2416
[email protected]59363fc92012-09-05 03:46:312417#endif
2418
[email protected]f114fa42013-12-06 17:06:442419void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2420 const base::FilePath& path,
2421 bool is_hung) {
2422 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2423
2424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2425 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2426}
2427
2428void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422429 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442430 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422431 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452432}
2433
[email protected]b172aee2012-04-10 17:05:262434void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2435 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102436 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102438 AppCacheAccessed(manifest_url, blocked_by_policy));
2439}
2440
[email protected]8bc5ff02013-11-29 06:34:032441void WebContentsImpl::OnOpenColorChooser(
2442 int color_chooser_id,
2443 SkColor color,
2444 const std::vector<ColorSuggestion>& suggestions) {
2445 ColorChooser* new_color_chooser =
2446 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302447 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212448 return;
[email protected]820957a2014-01-14 14:56:302449 if (color_chooser_)
2450 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212451 color_chooser_.reset(new_color_chooser);
2452 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202453}
2454
[email protected]b172aee2012-04-10 17:05:262455void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202456 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212457 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202458 color_chooser_->End();
2459}
2460
[email protected]b172aee2012-04-10 17:05:262461void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322462 SkColor color) {
[email protected]da8543762012-03-20 08:52:202463 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212464 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202465 color_chooser_->SetSelectedColor(color);
2466}
2467
[email protected]d0759f492012-04-19 22:50:502468// This exists for render views that don't have a WebUI, but do have WebUI
2469// bindings enabled.
2470void WebContentsImpl::OnWebUISend(const GURL& source_url,
2471 const std::string& name,
2472 const base::ListValue& args) {
2473 if (delegate_)
2474 delegate_->WebUISend(this, source_url, name, args);
2475}
2476
[email protected]d8415ad92012-08-23 14:40:502477void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442478 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502479 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342480 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162481 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442482 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162483 return;
[email protected]d8415ad92012-08-23 14:40:502484 }
2485
[email protected]8c8fc292012-11-23 18:57:162486 if (!delegate_->RequestPpapiBrokerPermission(
2487 this, url, plugin_path,
2488 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442489 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162490 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442491 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162492 }
[email protected]d8415ad92012-08-23 14:40:502493}
2494
[email protected]ea0309c2013-08-06 19:35:442495void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502496 bool result) {
[email protected]ea0309c2013-08-06 19:35:442497 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502498}
2499
[email protected]c4538072013-03-18 02:17:552500void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372501 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082502 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552503 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392504 // For more info, see comment above classes BrowserPluginEmbedder and
2505 // BrowserPluginGuest.
2506 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142507 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082508 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372509}
2510
[email protected]41225fe2013-03-29 05:32:022511void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392512 int id,
[email protected]749fadd2013-05-15 08:37:482513 int http_status_code,
[email protected]795c28972012-12-06 06:13:392514 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302515 const std::vector<SkBitmap>& bitmaps,
2516 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022517 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2518 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392519 // Currently WebContents notifies us of ANY downloads so that it is
2520 // possible to get here.
2521 return;
2522 }
2523 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302524 iter->second.Run(
2525 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392526 }
[email protected]41225fe2013-03-29 05:32:022527 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392528}
2529
2530void WebContentsImpl::OnUpdateFaviconURL(
2531 int32 page_id,
2532 const std::vector<FaviconURL>& candidates) {
2533 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2534 DidUpdateFaviconURL(page_id, candidates));
2535}
2536
[email protected]d9030b82013-07-19 08:26:062537void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2538 bool has_video,
2539 bool has_audio,
2540 bool is_playing) {
2541 // Chrome OS does its own detection of audio and video.
2542#if !defined(OS_CHROMEOS)
2543 if (is_playing) {
2544 scoped_ptr<PowerSaveBlocker> blocker;
2545 if (has_video) {
2546 blocker = PowerSaveBlocker::Create(
2547 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2548 "Playing video");
2549#if defined(OS_ANDROID)
2550 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382551 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062552#endif
2553 } else if (has_audio) {
2554 blocker = PowerSaveBlocker::Create(
2555 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2556 "Playing audio");
2557 }
2558
[email protected]f114fa42013-12-06 17:06:442559 if (blocker) {
2560 power_save_blockers_[render_view_message_source_][player_cookie] =
2561 blocker.release();
2562 }
[email protected]d9030b82013-07-19 08:26:062563 } else {
[email protected]f114fa42013-12-06 17:06:442564 delete power_save_blockers_[render_view_message_source_][player_cookie];
2565 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062566 }
2567#endif // !defined(OS_CHROMEOS)
2568}
2569
[email protected]9f268072013-11-07 00:02:152570void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2571 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2572 DidFirstVisuallyNonEmptyPaint(page_id));
2573}
[email protected]d9030b82013-07-19 08:26:062574
[email protected]e67ebf32013-02-13 11:07:192575void WebContentsImpl::DidChangeVisibleSSLState() {
2576 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2577 DidChangeVisibleSSLState());
2578}
2579
[email protected]17e286e2013-03-01 23:29:392580void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2582 BeforeFormRepostWarningShow());
2583}
2584
[email protected]ec6c05f2013-10-23 18:41:572585
2586void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2587 Activate();
2588 if (delegate_)
2589 delegate_->ShowRepostFormWarningDialog(this);
2590}
2591
[email protected]96d185d2009-04-24 03:28:542592// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592593// loading, or done loading.
2594void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2595 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262596 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542597 if (is_loading == is_loading_)
2598 return;
2599
2600 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262601 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2602 base::string16());
[email protected]96d185d2009-04-24 03:28:542603 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562604 upload_size_ = 0;
2605 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542606 }
2607
[email protected]fa944cb82013-11-15 17:51:212608 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542609
2610 is_loading_ = is_loading;
2611 waiting_for_response_ = is_loading;
2612
[email protected]6ebdc9b2010-09-27 16:55:572613 if (delegate_)
2614 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212615 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542616
[email protected]eab61442013-11-14 18:35:482617 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592618 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482619 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2620 "URL", url);
[email protected]91621872013-10-08 04:04:592621 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2622 DidStartLoading(render_view_host));
2623 } else {
[email protected]eab61442013-11-14 18:35:482624 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2625 "URL", url);
[email protected]91621872013-10-08 04:04:592626 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2627 DidStopLoading(render_view_host));
2628 }
[email protected]66798902013-10-01 18:40:162629
2630 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212631 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2632 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542633 if (details)
[email protected]8ff00d72012-10-23 19:12:212634 det = Details<LoadNotificationDetails>(details);
2635 NotificationService::current()->Notify(
2636 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542637}
2638
[email protected]b172aee2012-04-10 17:05:262639void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212640 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322641 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562642 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322643 // Clear the status bubble. This is a workaround for a bug where WebKit
2644 // doesn't let us know that the cursor left an element during a
2645 // transition (this is also why the mouse cursor remains as a hand after
2646 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2647 // clear the bubble when a user navigates to a named anchor in the same
2648 // page.
[email protected]36fc0392011-12-25 03:59:512649 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322650 }
2651
[email protected]a6e82fc2010-02-24 22:28:142652 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472653 // Once the main frame is navigated, we're no longer considered to have
2654 // displayed insecure content.
2655 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352656 SSLManager::NotifySSLInternalStateChanged(
2657 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172658 }
[email protected]ce5c4502009-05-06 16:46:112659
[email protected]3c9e1872010-11-18 16:17:492660 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252661 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042662 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322663}
2664
[email protected]b172aee2012-04-10 17:05:262665void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322666 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212667 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322668 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112669 // If we navigate off the page, close all JavaScript dialogs.
2670 if (dialog_manager_ && !details.is_in_page)
2671 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322672
[email protected]3c9e1872010-11-18 16:17:492673 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252674 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042675 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322676}
2677
[email protected]2f7b3c5a2013-06-21 04:59:252678bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292679 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2680 // still be used for a normal web site.
2681 if (url == GURL(kAboutBlankURL))
2682 return false;
2683
2684 // The embedder will then have the opportunity to determine if the URL
2685 // should "use up" the SiteInstance.
2686 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252687}
2688
[email protected]b172aee2012-04-10 17:05:262689void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462690 // If we are creating a RVH for a restored controller, then we need to make
2691 // sure the RenderView starts with a next_page_id_ larger than the number
2692 // of restored entries. This must be called before the RenderView starts
2693 // navigating (to avoid a race between the browser updating max_page_id and
2694 // the renderer updating next_page_id_). Because of this, we only call this
2695 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562696 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582697 if (max_restored_page_id >
2698 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2699 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2700 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322701}
2702
[email protected]b172aee2012-04-10 17:05:262703bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262704 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322705 // For file URLs without a title, use the pathname instead. In the case of a
2706 // synthesized title, we don't want the update to count toward the "one set
2707 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262708 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322709 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512710 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242711 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322712 explicit_set = false; // Don't count synthetic titles toward the set limit.
2713 } else {
[email protected]acafd272011-07-26 17:35:572714 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322715 explicit_set = true;
2716 }
2717
[email protected]987fc3a2011-05-26 14:18:092718 // If a page is created via window.open and never navigated,
2719 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552720 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092721 if (entry) {
[email protected]36fc0392011-12-25 03:59:512722 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092723 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322724
[email protected]36fc0392011-12-25 03:59:512725 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092726 } else {
2727 if (page_title_when_no_navigation_entry_ == final_title)
2728 return false; // Nothing changed, don't bother.
2729
2730 page_title_when_no_navigation_entry_ = final_title;
2731 }
[email protected]420ae012009-04-24 05:16:322732
[email protected]420ae012009-04-24 05:16:322733 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232734 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322735
[email protected]66798902013-10-01 18:40:162736 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532737 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162738
2739 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212740 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462741 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212742 NotificationService::current()->Notify(
2743 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2744 Source<WebContents>(this),
2745 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042746
[email protected]420ae012009-04-24 05:16:322747 return true;
2748}
2749
[email protected]7b712ee22013-10-03 00:57:282750void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2751 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322752 // After sending out a swap notification, we need to send a disconnect
2753 // notification so that clients that pick up a pointer to |this| can NULL the
2754 // pointer. See Bug 1230284.
2755 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112756 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282757 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112758
2759 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282760 std::pair<RenderViewHost*, RenderViewHost*> details =
2761 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212762 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282763 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212764 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282765 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392766
2767 // Ensure that the associated embedder gets cleared after a RenderViewHost
2768 // gets swapped, so we don't reuse the same embedder next time a
2769 // RenderViewHost is attached to this WebContents.
2770 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322771}
2772
[email protected]da7a7182013-09-06 08:11:112773// TODO(avi): Remove this entire function because this notification is already
2774// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322776 if (!notify_disconnection_)
2777 return;
2778
2779 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212780 NotificationService::current()->Notify(
2781 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2782 Source<WebContents>(this),
2783 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322784}
2785
[email protected]cbb1ef592013-06-05 19:49:462786void WebContentsImpl::NotifyNavigationEntryCommitted(
2787 const LoadCommittedDetails& load_details) {
2788 FOR_EACH_OBSERVER(
2789 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2790}
2791
[email protected]f114fa42013-12-06 17:06:442792bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2793 const IPC::Message& message) {
2794 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312795}
2796
[email protected]b849847b2013-12-10 21:57:582797void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2798 // Note this is only for subframes, the notification for the main frame
2799 // happens in RenderViewCreated.
2800 FOR_EACH_OBSERVER(WebContentsObserver,
2801 observers_,
2802 RenderFrameCreated(render_frame_host));
2803}
2804
2805void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2806 FOR_EACH_OBSERVER(WebContentsObserver,
2807 observers_,
2808 RenderFrameDeleted(render_frame_host));
2809}
2810
[email protected]b765deb2013-12-18 06:43:302811void WebContentsImpl::WorkerCrashed() {
2812 if (delegate_)
2813 delegate_->WorkerCrashed(this);
2814}
2815
[email protected]a86c0e962013-12-17 17:10:392816WebContents* WebContentsImpl::GetAsWebContents() {
2817 return this;
2818}
2819
[email protected]5a3bdf52012-05-24 15:12:572820RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2821 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322822}
2823
[email protected]8d3347f2009-07-09 22:00:212824RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262825WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212826 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212827}
2828
[email protected]8ff00d72012-10-23 19:12:212829RendererPreferences WebContentsImpl::GetRendererPrefs(
2830 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462831 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512832}
2833
[email protected]b172aee2012-04-10 17:05:262834gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172835 if (delegate_)
2836 return delegate_->GetRootWindowResizerRect();
2837 return gfx::Rect();
2838}
2839
[email protected]7a846df2012-09-20 19:17:392840void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272841 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392842 browser_plugin_embedder_.reset();
2843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442846 // Don't send notifications if we are just creating a swapped-out RVH for
2847 // the opener chain. These won't be used for view-source or WebUI, so it's
2848 // ok to return early.
2849 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2850 return;
2851
[email protected]86f98a22013-03-20 14:35:002852 if (delegate_)
2853 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082854
[email protected]8ff00d72012-10-23 19:12:212855 NotificationService::current()->Notify(
2856 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2857 Source<WebContents>(this),
2858 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322859
2860 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352861 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212862 if (GetRenderManager()->pending_web_ui())
2863 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322864
[email protected]6286a372013-10-09 04:03:272865 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332866 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322867 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182868 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582869 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322870 }
[email protected]0666aef2009-05-13 19:48:082871
[email protected]60780f412013-02-25 16:34:102872 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262873
2874 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252875 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582876
2877 // We tell the observers now instead of when the main RenderFrameHostImpl is
2878 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2879 // frame would be dropped because it's not created yet).
2880 RenderFrameHost* main_frame = GetMainFrame();
2881 FOR_EACH_OBSERVER(
2882 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322883}
2884
[email protected]b172aee2012-04-10 17:05:262885void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522886 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322887 // Don't notify the world, since this came from a renderer in the
2888 // background.
2889 return;
2890 }
2891
[email protected]da7a7182013-09-06 08:11:112892 notify_disconnection_ = true;
2893 // TODO(avi): Remove. http://crbug.com/170921
2894 NotificationService::current()->Notify(
2895 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2896 Source<WebContents>(this),
2897 NotificationService::NoDetails());
2898
[email protected]be1f56ab2011-12-22 06:55:312899 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232900 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302901
2902 // Restore the focus to the tab (otherwise the focus will be on the top
2903 // window).
[email protected]484ae5912010-09-29 19:16:142904 if (was_crashed && !FocusLocationBarByDefault() &&
2905 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062906 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142907 }
[email protected]32ded2212011-11-10 18:51:432908
[email protected]d8c660432011-12-22 20:51:252909 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322910}
2911
[email protected]ec6a7eb2013-04-22 17:34:222912void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2913 base::TerminationStatus status,
2914 int error_code) {
[email protected]151a63d2011-12-20 22:32:522915 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322916 // The pending page's RenderViewHost is gone.
2917 return;
2918 }
2919
[email protected]d9030b82013-07-19 08:26:062920 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592921 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322922 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232923 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312924 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322925
[email protected]d8c660432011-12-22 20:51:252926 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272927 observers_,
[email protected]58d5cfe2013-07-10 02:40:522928 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322929}
2930
[email protected]b172aee2012-04-10 17:05:262931void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062932 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212933 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252934 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062935}
2936
[email protected]b172aee2012-04-10 17:05:262937void WebContentsImpl::DidNavigate(
2938 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222939 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2940 ViewHostMsg_FrameNavigate_Params params(orig_params);
2941 bool use_site_per_process =
2942 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552943 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2944 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222945 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2946 // because cross-process subframe navigations still have a main frame
2947 // PageTransition.
2948 if (!use_site_per_process)
2949 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552950 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122951 }
2952
[email protected]a1b99262013-12-27 21:56:222953 // When using --site-per-process, look up the FrameTreeNode ID that the
2954 // renderer-specific frame ID corresponds to.
2955 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2956 if (use_site_per_process) {
2957 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2958 if (source_node)
2959 frame_tree_node_id = source_node->frame_tree_node_id();
2960
2961 // TODO(creis): In the short term, cross-process subframe navigations are
2962 // happening in the pending RenderViewHost's top-level frame. (We need to
2963 // both mirror the frame tree and get the navigation to occur in the correct
2964 // subframe to fix this.) Until then, we should check whether we have a
2965 // pending NavigationEntry with a frame ID and if so, treat the
2966 // cross-process "main frame" navigation as a subframe navigation. This
2967 // limits us to a single cross-process subframe per RVH, and it affects
2968 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2969 // OnDidFinishLoad.
2970 NavigationEntryImpl* pending_entry =
2971 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2972 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2973 if (pending_entry &&
2974 pending_entry->frame_tree_node_id() != -1 &&
2975 pending_entry->frame_tree_node_id() != root_ftn_id) {
2976 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2977 frame_tree_node_id = pending_entry->frame_tree_node_id();
2978 }
2979 }
2980
[email protected]e3d92a7f2013-01-10 02:35:052981 if (PageTransitionIsMainFrame(params.transition)) {
2982 // When overscroll navigation gesture is enabled, a screenshot of the page
2983 // in its current state is taken so that it can be used during the
2984 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362985 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052986 // WebContents::GetRenderViewHost to return the new host, instead of the one
2987 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482988 if (delegate_ && delegate_->CanOverscrollContent())
2989 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052990
[email protected]a1b99262013-12-27 21:56:222991 if (!use_site_per_process)
2992 GetRenderManager()->DidNavigateMainFrame(rvh);
2993 }
2994
2995 // When using --site-per-process, we notify the RFHM for all navigations,
2996 // not just main frame navigations.
2997 if (use_site_per_process) {
2998 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2999 // TODO(creis): Rename to DidNavigateFrame.
3000 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:053001 }
[email protected]8030f012009-09-25 18:09:373002
[email protected]434f69f2012-02-06 21:56:523003 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:253004 // assigning a site is not necessary for this URL. In that case, the
3005 // SiteInstance can still be considered unused until a navigation to a real
3006 // page.
[email protected]434f69f2012-02-06 21:56:523007 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:253008 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:333009 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:523010 }
[email protected]420ae012009-04-24 05:16:323011
3012 // Need to update MIME type here because it's referred to in
3013 // UpdateNavigationCommands() called by RendererDidNavigate() to
3014 // determine whether or not to enable the encoding menu.
3015 // It's updated only for the main frame. For a subframe,
3016 // RenderView::UpdateURL does not set params.contents_mime_type.
3017 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
3018 // TODO(jungshik): Add a test for the encoding menu to avoid
3019 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:213020 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:323021 contents_mime_type_ = params.contents_mime_type;
3022
[email protected]8ff00d72012-10-23 19:12:213023 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:223024 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:393025
[email protected]1ae93fb2013-06-14 03:38:563026 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
3027 // us estimate our process count for implementing OOP iframes.
3028 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:553029 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:563030
[email protected]a9c0bfe2010-09-17 08:35:223031 // Send notification about committed provisional loads. This notification is
3032 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
3033 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:213034 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:073035 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
3036 // that is not recorded in the navigation history. For the purpose of
3037 // tracking navigation events, we treat this event as a sub frame navigation
3038 // event.
3039 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:213040 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:223041 // Whether or not a page transition was triggered by going backward or
3042 // forward in the history is only stored in the navigation controller's
3043 // entry list.
3044 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:273045 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:213046 PAGE_TRANSITION_FORWARD_BACK)) {
3047 transition_type = PageTransitionFromInt(
3048 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:223049 }
[email protected]0d60f0192011-04-14 12:40:103050 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:253051 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:443052 DidCommitProvisionalLoadForFrame(
3053 params.frame_id,
3054 params.frame_unique_name,
3055 is_main_frame,
3056 params.url,
3057 transition_type,
3058 rvh));
[email protected]a9c0bfe2010-09-17 08:35:223059 }
3060
[email protected]76543b92009-08-31 17:27:453061 if (!did_navigate)
3062 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:323063
3064 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
3065 // for the appropriate notification (best) or you can add it to
3066 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
3067 // necessary, please).
3068
3069 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:003070 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:323071 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:003072 if (delegate_) {
[email protected]6934a702011-12-20 00:04:513073 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:003074 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
3075 }
[email protected]93f230e02011-06-01 14:40:003076 }
[email protected]420ae012009-04-24 05:16:323077 DidNavigateAnyFramePostCommit(rvh, details, params);
3078}
3079
[email protected]b172aee2012-04-10 17:05:263080void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3081 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043082 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153083 // Ensure that this state update comes from either the active RVH or one of
3084 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413085 // TODO(nasko): This should go through RenderFrameHost.
3086 // TODO(creis): We can't update state for cross-process subframes until we
3087 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3088 if (rvh != GetRenderViewHost() &&
3089 !GetRenderManager()->IsRVHOnSwappedOutList(
3090 static_cast<RenderViewHostImpl*>(rvh)))
3091 return;
[email protected]420ae012009-04-24 05:16:323092
3093 // We must be prepared to handle state updates for any page, these occur
3094 // when the user is scrolling and entering form data, as well as when we're
3095 // leaving a page, in which case our state may have already been moved to
3096 // the next page. The navigation controller will look up the appropriate
3097 // NavigationEntry and update it when it is notified via the delegate.
3098
3099 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583100 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323101 if (entry_index < 0)
3102 return;
[email protected]10f417c52011-12-28 21:04:233103 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323104
[email protected]691aa2f2013-05-28 22:52:043105 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323106 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043107 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323108 controller_.NotifyEntryChanged(entry, entry_index);
3109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3112 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263113 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263114 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323115 // If we have a title, that's a pretty good indication that we've started
3116 // getting useful data.
3117 SetNotWaitingForResponse();
3118
[email protected]73eb2602012-02-09 19:50:553119 // Try to find the navigation entry, which might not be the current one.
3120 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233121 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583122 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093123
[email protected]73eb2602012-02-09 19:50:553124 // We can handle title updates when we don't have an entry in
3125 // UpdateTitleForEntry, but only if the update is from the current RVH.
3126 if (!entry && rvh != GetRenderViewHost())
3127 return;
3128
[email protected]a49e10b2011-08-01 23:57:463129 // TODO(evan): make use of title_direction.
3130 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093131 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323132 return;
3133
3134 // Broadcast notifications when the UI should be updated.
3135 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213136 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323137}
3138
[email protected]b172aee2012-04-10 17:05:263139void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3140 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313141 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323142}
3143
[email protected]b172aee2012-04-10 17:05:263144void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513145 if (delegate_)
3146 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323147}
3148
[email protected]b172aee2012-04-10 17:05:263149void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103150#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293151 // The UI may be in an event-tracking loop, such as between the
3152 // mouse-down and mouse-up in text selection or a button click.
3153 // Defer the close until after tracking is complete, so that we
3154 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293155 // TODO(shess): This could get more fine-grained. For instance,
3156 // closing a tab in another window while selecting text in the
3157 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103158 if (view_->IsEventTracking()) {
3159 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293160 return;
3161 }
[email protected]60780f412013-02-25 16:34:103162#endif
[email protected]07707302009-11-06 00:50:293163
[email protected]420ae012009-04-24 05:16:323164 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523165 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513166 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323167}
3168
[email protected]b172aee2012-04-10 17:05:263169void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523170 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513171 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283172
3173 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213174 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573175}
3176
[email protected]b172aee2012-04-10 17:05:263177void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513178 if (delegate_ && delegate_->IsPopupOrPanel(this))
3179 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323180}
3181
[email protected]8ff00d72012-10-23 19:12:213182void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593183 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323184}
3185
[email protected]8ff00d72012-10-23 19:12:213186void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323187 scoped_ptr<LoadNotificationDetails> details;
3188
[email protected]9595fd82013-04-19 21:28:493189 // Use the last committed entry rather than the active one, in case a
3190 // pending entry has been created.
3191 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3192
[email protected]420ae012009-04-24 05:16:323193 // An entry may not exist for a stop when loading an initial blank page or
3194 // if an iframe injected by script into a blank page finishes loading.
3195 if (entry) {
[email protected]420ae012009-04-24 05:16:323196 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3197
3198 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513199 entry->GetVirtualURL(),
3200 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323201 elapsed,
3202 &controller_,
3203 controller_.GetCurrentEntryIndex()));
3204 }
3205
[email protected]91621872013-10-08 04:04:593206 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323207}
3208
[email protected]b172aee2012-04-10 17:05:263209void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163210 controller_.DiscardNonCommittedEntries();
3211
3212 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213213 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163214}
3215
[email protected]b172aee2012-04-10 17:05:263216void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513217 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133218 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403219}
3220
[email protected]7cc78902012-12-06 02:32:263221void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393222 if (opener_) {
3223 // Clear our opener so that future cross-process navigations don't have an
3224 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103225 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393226 opener_ = NULL;
3227 }
[email protected]7cc78902012-12-06 02:32:263228
3229 // Notify all swapped out RenderViewHosts for this tab. This is important
3230 // in case we go back to them, or if another window in those processes tries
3231 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213232 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263233}
3234
[email protected]59167c22013-06-03 18:07:323235void WebContentsImpl::DidAccessInitialDocument() {
3236 // Update the URL display.
3237 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3238}
3239
[email protected]87717d0e2012-04-26 02:58:433240void WebContentsImpl::DocumentAvailableInMainFrame(
3241 RenderViewHost* render_view_host) {
3242 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3243 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103244}
3245
[email protected]b172aee2012-04-10 17:05:263246void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083247 RenderViewHost* render_view_host,
3248 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093249 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3250 DocumentOnLoadCompletedInMainFrame(page_id));
3251
3252 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213253 NotificationService::current()->Notify(
3254 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3255 Source<WebContents>(this),
3256 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083257}
3258
[email protected]196159d2012-05-04 17:26:543259void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3260 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213261 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263262 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183263 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523264 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303265 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543266 // If this came from a swapped out RenderViewHost, we only allow the request
3267 // if we are still in the same BrowsingInstance.
3268 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3269 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3270 return;
3271 }
3272
[email protected]4ad5d77d2011-12-03 02:00:483273 // Delegate to RequestTransferURL because this is just the generic
3274 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573275 // TODO(creis): Pass the redirect_chain into this method to support client
3276 // redirects. http://crbug.com/311721.
3277 std::vector<GURL> redirect_chain;
3278 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3279 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523280 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483281}
3282
[email protected]b172aee2012-04-10 17:05:263283void WebContentsImpl::RequestTransferURL(
3284 const GURL& url,
[email protected]f8872902013-10-30 03:18:573285 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213286 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573287 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263288 WindowOpenDisposition disposition,
3289 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183290 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523291 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303292 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203293 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123294 GURL dest_url(url);
3295 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553296 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123297 dest_url = GURL(kAboutBlankURL);
3298
[email protected]a1b99262013-12-27 21:56:223299 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3300 int64 frame_tree_node_id = -1;
3301 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3302 source_frame_id != -1) {
3303 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3304 if (source_node)
3305 frame_tree_node_id = source_node->frame_tree_node_id();
3306 }
[email protected]c80297782013-11-21 07:10:163307 OpenURLParams params(dest_url, referrer, source_frame_id,
3308 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573309 page_transition, true /* is_renderer_initiated */);
3310 if (redirect_chain.size() > 0)
3311 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553312 params.transferred_global_request_id = old_request_id;
3313 params.should_replace_current_entry = should_replace_current_entry;
3314 params.user_gesture = user_gesture;
3315
[email protected]fa944cb82013-11-15 17:51:213316 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573317 // Web UI pages sometimes want to override the page transition type for
3318 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3319 // automatically generated suggestions). We don't override other types
3320 // like TYPED because they have different implications (e.g., autocomplete).
3321 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213322 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553323
[email protected]e0112912011-02-02 22:54:353324 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163325 // want web sites to see a referrer of "chrome://blah" (and some
3326 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323327 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553328 params.referrer = Referrer();
3329
3330 // Navigations in Web UI pages count as browser-initiated navigations.
3331 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583332 }
[email protected]44d0930a2013-10-28 18:53:553333
3334 new_contents = OpenURL(params);
3335
[email protected]ae5184d62011-10-06 19:25:583336 if (new_contents) {
3337 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583339 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123340 dest_url,
[email protected]ae5184d62011-10-06 19:25:583341 referrer,
3342 disposition,
[email protected]44d0930a2013-10-28 18:53:553343 params.transition,
[email protected]ae5184d62011-10-06 19:25:583344 source_frame_id));
[email protected]420ae012009-04-24 05:16:323345 }
3346}
3347
[email protected]e1c3a552012-05-04 20:51:323348void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3349 // Tell the active RenderViewHost to run unload handlers and close, as long
3350 // as the request came from a RenderViewHost in the same BrowsingInstance.
3351 // In most cases, we receive this from a swapped out RenderViewHost.
3352 // It is possible to receive it from one that has just been swapped in,
3353 // in which case we might as well deliver the message anyway.
3354 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3355 GetRenderViewHost()->ClosePage();
3356}
3357
[email protected]f546640b2012-05-15 00:03:493358void WebContentsImpl::RouteMessageEvent(
3359 RenderViewHost* rvh,
3360 const ViewMsg_PostMessage_Params& params) {
3361 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363362 // came from a RenderViewHost in the same BrowsingInstance or if this
3363 // WebContents is dedicated to a browser plugin guest.
3364 // Note: This check means that an embedder could theoretically receive a
3365 // postMessage from anyone (not just its own guests). However, this is
3366 // probably not a risk for apps since other pages won't have references
3367 // to App windows.
3368 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3369 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493370 return;
3371
3372 ViewMsg_PostMessage_Params new_params(params);
3373
[email protected]0bc7f3542013-10-21 15:05:533374 if (!params.message_port_ids.empty()) {
3375 MessagePortMessageFilter* message_port_message_filter =
3376 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3377 ->message_port_message_filter();
3378 std::vector<int> new_routing_ids(params.message_port_ids.size());
3379 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3380 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3381 MessagePortService::GetInstance()->UpdateMessagePort(
3382 params.message_port_ids[i],
3383 message_port_message_filter,
3384 new_routing_ids[i]);
3385 }
3386 new_params.new_routing_ids = new_routing_ids;
3387 }
3388
[email protected]f546640b2012-05-15 00:03:493389 // If there is a source_routing_id, translate it to the routing ID for
3390 // the equivalent swapped out RVH in the target process. If we need
3391 // to create a swapped out RVH for the source tab, we create its opener
3392 // chain as well, since those will also be accessible to the target page.
3393 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3394 // Try to look up the WebContents for the source page.
3395 WebContentsImpl* source_contents = NULL;
3396 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3397 rvh->GetProcess()->GetID(), params.source_routing_id);
3398 if (source_rvh) {
3399 source_contents = static_cast<WebContentsImpl*>(
3400 source_rvh->GetDelegate()->GetAsWebContents());
3401 }
3402
3403 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363404 if (GetBrowserPluginGuest()) {
3405 // We create a swapped out RenderView for the embedder in the guest's
3406 // render process but we intentionally do not expose the embedder's
3407 // opener chain to it.
3408 new_params.source_routing_id =
3409 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3410 } else {
3411 new_params.source_routing_id =
3412 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3413 }
[email protected]f546640b2012-05-15 00:03:493414 } else {
3415 // We couldn't find it, so don't pass a source frame.
3416 new_params.source_routing_id = MSG_ROUTING_NONE;
3417 }
3418 }
3419
3420 // In most cases, we receive this from a swapped out RenderViewHost.
3421 // It is possible to receive it from one that has just been swapped in,
3422 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183423 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493424}
3425
[email protected]b172aee2012-04-10 17:05:263426void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343427 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263428 const base::string16& message,
3429 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323430 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213431 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323432 IPC::Message* reply_msg,
3433 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073434 // Suppress JavaScript dialogs when requested. Also suppress messages when
3435 // showing an interstitial as it's shown over the previous page and we don't
3436 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503437 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583438 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273439 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073440 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523441 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153442 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323443
3444 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213445 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433446 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153447 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3448 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433449 this,
3450 frame_url.GetOrigin(),
3451 accept_lang,
3452 javascript_message_type,
3453 message,
[email protected]51da7e32012-01-30 19:24:523454 default_prompt,
[email protected]b172aee2012-04-10 17:05:263455 base::Bind(&WebContentsImpl::OnDialogClosed,
3456 base::Unretained(this),
3457 rvh,
3458 reply_msg),
[email protected]51da7e32012-01-30 19:24:523459 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323460 }
[email protected]3ab9cb82011-06-03 18:02:073461
[email protected]6dd2f1e2013-09-11 15:06:013462 *did_suppress_message = suppress_this_message;
3463
[email protected]3ab9cb82011-06-03 18:02:073464 if (suppress_this_message) {
3465 // If we are suppressing messages, just reply as if the user immediately
3466 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263467 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073468 }
3469
[email protected]6dd2f1e2013-09-11 15:06:013470 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3471 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323472}
3473
[email protected]b172aee2012-04-10 17:05:263474void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263475 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263476 bool is_reload,
3477 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583478 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513479 if (delegate_)
3480 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073481
3482 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583483 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073484 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523485 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153486 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153487 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343488 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263489 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503490 return;
3491 }
[email protected]3ab9cb82011-06-03 18:02:073492
[email protected]7ab1e7d62009-10-14 23:32:013493 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153494 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3495 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323496 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263497 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523498 reply_msg));
[email protected]420ae012009-04-24 05:16:323499}
3500
[email protected]a796f202012-05-30 14:14:253501bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263502 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253503 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263504 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253505 if (!delegate_)
3506 return false;
3507 return delegate_->AddMessageToConsole(this, level, message, line_no,
3508 source_id);
3509}
3510
[email protected]b172aee2012-04-10 17:05:263511WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273512 // We want to base the page config off of the actual URL, rather than the
3513 // virtual URL.
3514 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3515 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003516 GURL url = controller_.GetActiveEntry()
3517 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153518
[email protected]fa944cb82013-11-15 17:51:213519 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323520}
3521
[email protected]0eba810b2012-10-18 03:19:363522int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213523 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413524 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3525 true, true);
[email protected]0eba810b2012-10-18 03:19:363526}
3527
[email protected]b172aee2012-04-10 17:05:263528void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273529 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253530 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223531
[email protected]ea114722012-03-12 01:11:253532 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173533 if (rdh) // NULL in unittests.
3534 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253535}
3536
[email protected]b172aee2012-04-10 17:05:263537void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443538 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253539 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443540}
3541
[email protected]b172aee2012-04-10 17:05:263542void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563543 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263544 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153545 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523546 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153547 return;
3548
[email protected]9f76c1e2012-03-05 15:15:583549 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3550
[email protected]e5fc1632011-08-08 07:51:533551 // Ignore renderer unresponsive event if debugger is attached to the tab
3552 // since the event may be a result of the renderer sitting on a breakpoint.
3553 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363554 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533555 return;
3556
[email protected]2e9d79f2013-08-16 05:45:563557 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323558 // Hang occurred while firing the beforeunload/unload handler.
3559 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583560 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323561
[email protected]fa944cb82013-11-15 17:51:213562 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323563 return;
3564
3565 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563566 // nothing we can do to recover. If the hang is in the beforeunload handler,
3567 // pretend the beforeunload listeners have all fired and allow the delegate
3568 // to continue closing; the user will not have the option of cancelling the
3569 // close. Otherwise, pretend the unload listeners have all fired and close
3570 // the tab.
3571 bool close = true;
3572 if (is_during_beforeunload) {
3573 delegate_->BeforeUnloadFired(this, true, &close);
3574 }
3575 if (close)
3576 Close(rvh);
[email protected]420ae012009-04-24 05:16:323577 return;
3578 }
3579
[email protected]9f76c1e2012-03-05 15:15:583580 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473581 return;
3582
[email protected]6934a702011-12-20 00:04:513583 if (delegate_)
3584 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323585}
3586
[email protected]b172aee2012-04-10 17:05:263587void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513588 if (delegate_)
3589 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323590}
3591
[email protected]b172aee2012-04-10 17:05:263592void WebContentsImpl::LoadStateChanged(
3593 const GURL& url,
3594 const net::LoadStateWithParam& load_state,
3595 uint64 upload_position,
3596 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323597 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563598 upload_position_ = upload_position;
3599 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503600 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213601 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303602 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213603 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323604 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463605 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213606 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463607 }
[email protected]420ae012009-04-24 05:16:323608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553611 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323612 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123613 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3614 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513615 if (delegate_)
3616 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093617 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323618}
3619
[email protected]58d5cfe2013-07-10 02:40:523620void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543621 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233622 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223623 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543624}
3625
[email protected]b172aee2012-04-10 17:05:263626void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103627 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213628 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263629 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3630 // here during container initialization and normal window size will be set
3631 // later. In case of tab duplication this resizing to 0x0 prevents setting
3632 // normal size later so just ignore it.
3633 if (!size.IsEmpty())
3634 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323635}
3636
[email protected]af905902013-10-01 21:38:513637void WebContentsImpl::CancelModalDialogsForRenderManager() {
3638 // We need to cancel modal dialogs when doing a process swap, since the load
3639 // deferrer would prevent us from swapping out.
3640 if (dialog_manager_)
3641 dialog_manager_->CancelActiveAndPendingDialogs(this);
3642}
3643
[email protected]7b712ee22013-10-03 00:57:283644void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3645 RenderViewHost* new_host) {
3646 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083647
3648 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003649 if (delegate_)
3650 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393651
[email protected]7b712ee22013-10-03 00:57:283652 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543653}
3654
[email protected]14392a52012-05-02 20:28:443655int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3656 SiteInstance* instance) {
3657 if (!opener_)
3658 return MSG_ROUTING_NONE;
3659
3660 // Recursively create RenderViews for anything else in the opener chain.
3661 return opener_->CreateOpenerRenderViews(instance);
3662}
3663
3664int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3665 int opener_route_id = MSG_ROUTING_NONE;
3666
3667 // If this tab has an opener, ensure it has a RenderView in the given
3668 // SiteInstance as well.
3669 if (opener_)
3670 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3671
[email protected]45a22ad2013-02-21 03:25:003672 // If any of the renderers (current, pending, or swapped out) for this
3673 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213674 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3675 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373676
[email protected]fa944cb82013-11-15 17:51:213677 if (GetRenderManager()->pending_render_view_host() &&
3678 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3679 instance)
3680 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003681
[email protected]fa944cb82013-11-15 17:51:213682 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373683 instance);
3684 if (rvh)
3685 return rvh->GetRoutingID();
3686
[email protected]14392a52012-05-02 20:28:443687 // Create a swapped out RenderView in the given SiteInstance if none exists,
3688 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413689 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3690 true, true);
[email protected]14392a52012-05-02 20:28:443691}
3692
[email protected]b172aee2012-04-10 17:05:263693NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193694 return GetController();
[email protected]3a3d47472010-07-15 21:03:543695}
3696
[email protected]b172aee2012-04-10 17:05:263697WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563698 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323699}
3700
[email protected]10f417c52011-12-28 21:04:233701NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263702 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323703 return controller_.GetLastCommittedEntry();
3704}
3705
[email protected]b172aee2012-04-10 17:05:263706bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443707 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033708 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443709 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323710 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523711
[email protected]420ae012009-04-24 05:16:323712 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443713 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213714 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323715
[email protected]74ce1ad2011-12-16 21:51:463716 // Make sure we use the correct starting page_id in the new RenderView.
3717 UpdateMaxPageIDIfNecessary(render_view_host);
3718 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583719 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463720
[email protected]9f76c1e2012-03-05 15:15:583721 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263722 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493723 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133724 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523725 return false;
[email protected]14392a52012-05-02 20:28:443726 }
[email protected]a4127722011-04-27 23:13:523727
[email protected]a220b5932013-09-21 03:47:443728#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503729 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3730 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443731 if (rwh_view) {
3732 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3733 render_widget_host->WasResized();
3734 }
[email protected]f8233cc2011-05-31 20:24:503735#endif
3736
[email protected]420ae012009-04-24 05:16:323737 return true;
3738}
3739
[email protected]7d244f12013-08-22 21:41:513740#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183741base::android::ScopedJavaLocalRef<jobject>
3742WebContentsImpl::GetJavaWebContents() {
3743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3744
3745 WebContentsAndroid* web_contents_android =
3746 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3747 if (!web_contents_android) {
3748 web_contents_android = new WebContentsAndroid(this);
3749 SetUserData(kWebContentsAndroidKey, web_contents_android);
3750 }
3751 return web_contents_android->GetJavaObject();
3752}
3753
[email protected]7d244f12013-08-22 21:41:513754bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3755 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3756 MSG_ROUTING_NONE);
3757}
3758#endif
3759
[email protected]b172aee2012-04-10 17:05:263760void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3761 IPC::Message* reply_msg,
3762 bool success,
[email protected]fcf75d42013-12-03 20:11:263763 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543764 if (is_showing_before_unload_dialog_ && !success) {
3765 // If a beforeunload dialog is canceled, we need to stop the throbber from
3766 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293767 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353768 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103769
[email protected]6d65a462013-06-21 21:29:123770 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3771 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543772 }
3773 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583774 static_cast<RenderViewHostImpl*>(
3775 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543776}
3777
[email protected]b172aee2012-04-10 17:05:263778void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213779 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123780 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103781}
[email protected]f45d2a72010-03-08 23:28:353782
[email protected]b172aee2012-04-10 17:05:263783void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103784 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443785 // Can be NULL during tests.
3786 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213787 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363788}
[email protected]9f76c1e2012-03-05 15:15:583789
[email protected]1ac10dca2013-08-20 20:47:043790bool WebContentsImpl::IsHidden() {
3791 return capturer_count_ == 0 && !should_normally_be_visible_;
3792}
3793
[email protected]b0936d22013-11-28 06:47:363794RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213795 return frame_tree_.root()->render_manager();
3796}
3797
[email protected]b172aee2012-04-10 17:05:263798RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583799 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3800}
[email protected]7900bfdb2012-05-24 19:31:243801
[email protected]f8497342013-02-05 22:15:023802BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393803 return browser_plugin_guest_.get();
3804}
3805
[email protected]738f57a2013-06-29 21:06:543806void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3807 CHECK(!browser_plugin_guest_);
3808 browser_plugin_guest_.reset(guest);
3809}
3810
[email protected]f8497342013-02-05 22:15:023811BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393812 return browser_plugin_embedder_.get();
3813}
[email protected]8ff00d72012-10-23 19:12:213814
[email protected]8eb04562013-03-06 03:41:143815BrowserPluginGuestManager*
3816 WebContentsImpl::GetBrowserPluginGuestManager() const {
3817 return static_cast<BrowserPluginGuestManager*>(
3818 GetBrowserContext()->GetUserData(
3819 browser_plugin::kBrowserPluginGuestManagerKeyName));
3820}
3821
[email protected]d9030b82013-07-19 08:26:063822void WebContentsImpl::ClearPowerSaveBlockers(
3823 RenderViewHost* render_view_host) {
3824 STLDeleteValues(&power_save_blockers_[render_view_host]);
3825 power_save_blockers_.erase(render_view_host);
3826}
3827
3828void WebContentsImpl::ClearAllPowerSaveBlockers() {
3829 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3830 i != power_save_blockers_.end(); ++i)
3831 STLDeleteValues(&power_save_blockers_[i->first]);
3832 power_save_blockers_.clear();
3833}
3834
[email protected]dc0fd432013-08-27 15:29:213835gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3836 gfx::Size size;
3837 if (delegate_)
3838 size = delegate_->GetSizeForNewRenderView(this);
3839 if (size.IsEmpty())
3840 size = view_->GetContainerSize();
3841 return size;
3842}
3843
[email protected]9b159a52013-10-03 17:24:553844void WebContentsImpl::OnFrameRemoved(
3845 RenderViewHostImpl* render_view_host,
3846 int64 frame_id) {
3847 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3848 FrameDetached(render_view_host, frame_id));
3849}
3850
[email protected]8ff00d72012-10-23 19:12:213851} // namespace content