blob: 9c088eaf8881b704e06a770567d42a677c624f46 [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]c73a2282013-04-29 21:10:41373#if defined(OS_WIN) && defined(USE_AURA)
374 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
433 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07434#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32435 // If we still have a window handle, destroy it. GetNativeView can return
436 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06437 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52438 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58439 if (host && host->GetView())
440 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42441 }
[email protected]420ae012009-04-24 05:16:32442#endif
[email protected]7ab1e7d62009-10-14 23:32:01443
[email protected]fa944cb82013-11-15 17:51:21444 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27445 if (pending_rvh) {
446 FOR_EACH_OBSERVER(WebContentsObserver,
447 observers_,
448 RenderViewDeleted(pending_rvh));
449 }
450
451 FOR_EACH_OBSERVER(WebContentsObserver,
452 observers_,
[email protected]fa944cb82013-11-15 17:51:21453 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27454
[email protected]2db9bd72012-04-13 20:20:56455 FOR_EACH_OBSERVER(WebContentsObserver,
456 observers_,
457 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08458
[email protected]6934a702011-12-20 00:04:51459 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10460
461 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
462 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42463}
464
[email protected]d1198fd2012-08-13 22:50:19465WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59466 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19467 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03468 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59469 WebContentsImpl* new_contents = new WebContentsImpl(
470 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19471
[email protected]54944cde2012-12-09 09:24:59472 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19473 return new_contents;
474}
475
[email protected]b371a5652013-02-20 11:25:51476// static
[email protected]8eb04562013-03-06 03:41:14477BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36478 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53479 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54480 int guest_instance_id,
481 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39482 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39483
484 // This makes |new_contents| act as a guest.
485 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54486 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19487 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11488
[email protected]3de10bb32013-01-08 21:57:33489 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33490 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11491
[email protected]216be772013-01-25 00:22:27492 // We are instantiating a WebContents for browser plugin. Set its subframe bit
493 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42494 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27495
[email protected]8eb04562013-03-06 03:41:14496 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39497}
498
[email protected]b0936d22013-11-28 06:47:36499RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21500 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28501}
502
[email protected]7bb761892012-07-20 09:32:47503bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
504 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44505 return OnMessageReceived(render_view_host, NULL, message);
506}
507
508bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
509 RenderFrameHost* render_frame_host,
510 const IPC::Message& message) {
511 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56512 if (GetWebUI() &&
513 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17514 return true;
[email protected]d2353452012-01-19 19:53:56515 }
[email protected]f82d57b52011-04-27 19:13:17516
[email protected]d8c660432011-12-22 20:51:25517 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
518 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10519 while ((observer = it.GetNext()) != NULL)
520 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53521 return true;
[email protected]403415a2011-01-10 18:57:53522
[email protected]c80725d52013-12-06 06:22:26523 // Message handlers should be aware of which RenderViewHost sent the
[email protected]f114fa42013-12-06 17:06:44524 // message, which is temporarily stored in render_view_message_source_.
525 render_view_message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18526 bool handled = true;
527 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26528 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44529 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
530 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18531 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
532 OnDidLoadResourceFromMemoryCache)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
534 OnDidDisplayInsecureContent)
535 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
536 OnDidRunInsecureContent)
537 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
538 OnDocumentLoadedInFrame)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26540 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
541 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25542 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26543 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21544 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20545 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
547 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16548 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10549 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20550 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
553 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50554 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50555 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
556 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55557 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
558 OnBrowserPluginMessage(message))
559 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
560 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02561 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
562 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10563#if defined(OS_ANDROID)
564 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
565 OnFindMatchRectsReply)
566 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
567 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32568 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
569 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10570#endif
[email protected]d9030b82013-07-19 08:26:06571 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15572 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
573 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07574 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
575 OnShowValidationMessage)
576 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
577 OnHideValidationMessage)
578 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
579 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18580 IPC_MESSAGE_UNHANDLED(handled = false)
581 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44582 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18583
584 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21585 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18586 GetRenderProcessHost()->ReceivedBadMessage();
587 }
588
589 return handled;
590}
591
[email protected]b172aee2012-04-10 17:05:26592void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18593 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21594 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43595 if (delegate_)
596 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18597}
598
[email protected]d1198fd2012-08-13 22:50:19599NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56600 return controller_;
601}
602
[email protected]d1198fd2012-08-13 22:50:19603const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56604 return controller_;
605}
606
[email protected]8ff00d72012-10-23 19:12:21607BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55608 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30609}
610
[email protected]b172aee2012-04-10 17:05:26611const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24612 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32613 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51614 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31615}
616
[email protected]a093ce02013-07-22 20:53:14617const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24618 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32619 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24620 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
621}
622
623const GURL& WebContentsImpl::GetLastCommittedURL() const {
624 // We may not have a navigation entry yet.
625 NavigationEntry* entry = controller_.GetLastCommittedEntry();
626 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
627}
628
[email protected]8ff00d72012-10-23 19:12:21629WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31630 return delegate_;
631}
632
[email protected]8ff00d72012-10-23 19:12:21633void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31634 // TODO(cbentzel): remove this debugging code?
635 if (delegate == delegate_)
636 return;
637 if (delegate_)
638 delegate_->Detach(this);
639 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08640 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31641 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08642 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00643 if (view_)
644 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08645 }
[email protected]be1f56ab2011-12-22 06:55:31646}
647
[email protected]8ff00d72012-10-23 19:12:21648RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21649 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41650 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16651}
652
[email protected]60eca4eb2013-12-06 00:02:16653RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41654 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16655}
656
[email protected]a86c0e962013-12-17 17:10:39657void WebContentsImpl::ForEachFrame(
658 const base::Callback<void(RenderFrameHost*)>& on_frame) {
659 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
660}
661
662void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
663 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
664 delete message;
665}
666
[email protected]b172aee2012-04-10 17:05:26667RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21668 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31669}
670
[email protected]a04c9d02012-11-14 21:04:34671void WebContentsImpl::GetRenderViewHostAtPosition(
672 int x,
673 int y,
674 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
675 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
676 if (embedder)
677 embedder->GetRenderViewHostAtPosition(x, y, callback);
678 else
679 callback.Run(GetRenderViewHost(), x, y);
680}
681
[email protected]bfcfa692013-02-07 06:17:02682WebContents* WebContentsImpl::GetEmbedderWebContents() const {
683 BrowserPluginGuest* guest = GetBrowserPluginGuest();
684 if (guest)
685 return guest->embedder_web_contents();
686 return NULL;
687}
688
689int WebContentsImpl::GetEmbeddedInstanceID() const {
690 BrowserPluginGuest* guest = GetBrowserPluginGuest();
691 if (guest)
692 return guest->instance_id();
693 return 0;
694}
695
[email protected]6b618e62012-08-16 12:59:18696int WebContentsImpl::GetRoutingID() const {
697 if (!GetRenderViewHost())
698 return MSG_ROUTING_NONE;
699
700 return GetRenderViewHost()->GetRoutingID();
701}
702
[email protected]44470a22013-01-24 01:21:54703int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
704 return fullscreen_widget_routing_id_;
705}
706
[email protected]b172aee2012-04-10 17:05:26707RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21708 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31709}
710
[email protected]f8497342013-02-05 22:15:02711RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
712 BrowserPluginGuest* guest = GetBrowserPluginGuest();
713 if (guest && guest->embedder_web_contents()) {
714 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
715 }
716 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
717}
718
[email protected]4aebbca2013-09-17 22:26:49719RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
720 const {
721 RenderWidgetHost* const widget_host =
722 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
723 GetFullscreenWidgetRoutingID());
724 return widget_host ? widget_host->GetView() : NULL;
725}
726
[email protected]8ff00d72012-10-23 19:12:21727WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31728 return view_.get();
729}
730
[email protected]8ff00d72012-10-23 19:12:21731WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56732 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03733 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
734 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22735 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58736 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22737 web_ui->SetController(controller);
738 return web_ui;
739 }
740
741 delete web_ui;
742 return NULL;
743}
744
[email protected]8ff00d72012-10-23 19:12:21745WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21746 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
747 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31748}
749
[email protected]8ff00d72012-10-23 19:12:21750WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21751 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34752}
753
[email protected]86ef6a392012-05-11 22:03:11754void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22755 if (GetUserAgentOverride() == override)
756 return;
757
758 renderer_preferences_.user_agent_override = override;
759
760 // Send the new override string to the renderer.
761 RenderViewHost* host = GetRenderViewHost();
762 if (host)
763 host->SyncRendererPrefs();
764
765 // Reload the page if a load is currently in progress to avoid having
766 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27767 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22768 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
769 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53770
771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
772 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11773}
774
775const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22776 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11777}
778
[email protected]c73a2282013-04-29 21:10:41779#if defined(OS_WIN) && defined(USE_AURA)
780void WebContentsImpl::SetParentNativeViewAccessible(
781gfx::NativeViewAccessible accessible_parent) {
782 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45783 if (GetRenderViewHost())
784 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41785}
786#endif
787
[email protected]fcf75d42013-12-03 20:11:26788const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55789 // Transient entries take precedence. They are used for interstitial pages
790 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23791 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08792 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21793 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30794 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23795 if (entry) {
[email protected]b5cca982011-05-26 04:42:08796 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23797 }
[email protected]fa944cb82013-11-15 17:51:21798 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
799 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58800 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54801 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32802 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54803 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35804 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26805 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54806 if (!title.empty())
807 return title;
808 }
809 }
810
811 // We use the title for the last committed entry rather than a pending
812 // navigation entry. For example, when the user types in a URL, we want to
813 // keep the old page's title until the new load has committed and we get a new
814 // title.
[email protected]96d185d2009-04-24 03:28:54815 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32816
[email protected]9eeafc012013-11-25 23:49:47817 // We make an exception for initial navigations.
818 if (controller_.IsInitialNavigation()) {
819 // We only want to use the title from the visible entry in one of two cases:
820 // 1. There's already a committed entry for an initial navigation, in which
821 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
822 // 2. The pending entry has been explicitly assigned a title to display.
823 //
824 // If there's no last committed entry and no assigned title, we should fall
825 // back to |page_title_when_no_navigation_entry_| rather than showing the
826 // URL.
827 if (entry ||
828 (controller_.GetVisibleEntry() &&
829 !controller_.GetVisibleEntry()->GetTitle().empty())) {
830 entry = controller_.GetVisibleEntry();
831 }
832 }
[email protected]59167c22013-06-03 18:07:32833
[email protected]45d0ef7f2011-01-05 13:46:23834 if (entry) {
[email protected]b5cca982011-05-26 04:42:08835 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23836 }
[email protected]987fc3a2011-05-26 14:18:09837
838 // |page_title_when_no_navigation_entry_| is finally used
839 // if no title cannot be retrieved.
840 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54841}
842
[email protected]b172aee2012-04-10 17:05:26843int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46844 return GetMaxPageIDForSiteInstance(GetSiteInstance());
845}
846
[email protected]b172aee2012-04-10 17:05:26847int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
848 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33849 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
850 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46851
[email protected]b6583592012-01-25 19:52:33852 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34853}
854
[email protected]b172aee2012-04-10 17:05:26855void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46856 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
857}
858
[email protected]b172aee2012-04-10 17:05:26859void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33860 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46861 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33862 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34863}
864
[email protected]ec6c05f2013-10-23 18:41:57865void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
866 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
867 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57868}
869
[email protected]b172aee2012-04-10 17:05:26870SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21871 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54872}
873
[email protected]b172aee2012-04-10 17:05:26874SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21875 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
876 GetRenderManager()->pending_render_view_host() :
877 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58878 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38879}
880
[email protected]b172aee2012-04-10 17:05:26881bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return waiting_for_response_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return load_state_;
891}
892
[email protected]fcf75d42013-12-03 20:11:26893const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return load_state_host_;
895}
896
[email protected]b172aee2012-04-10 17:05:26897uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return upload_size_;
899}
900
[email protected]b172aee2012-04-10 17:05:26901uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return upload_position_;
903}
904
[email protected]1ae93fb2013-06-14 03:38:56905std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56906 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39907 frame_tree_.ForEach(base::Bind(&CollectSites,
908 base::Unretained(GetBrowserContext()),
909 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56910 return sites;
911}
912
[email protected]b172aee2012-04-10 17:05:26913const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return encoding_;
915}
916
[email protected]b172aee2012-04-10 17:05:26917bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return displayed_insecure_content_;
919}
920
[email protected]54597982013-02-06 01:59:55921void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25922 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55923 ++capturer_count_;
924 DVLOG(1) << "There are now " << capturer_count_
925 << " capturing(s) of WebContentsImpl@" << this;
926}
927
928void WebContentsImpl::DecrementCapturerCount() {
929 --capturer_count_;
930 DVLOG(1) << "There are now " << capturer_count_
931 << " capturing(s) of WebContentsImpl@" << this;
932 DCHECK_LE(0, capturer_count_);
933
[email protected]5a652232013-02-12 06:15:25934 if (is_being_destroyed_)
935 return;
936
[email protected]1ac10dca2013-08-20 20:47:04937 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55938 DVLOG(1) << "Executing delayed WasHidden().";
939 WasHidden();
940 }
[email protected]be1f56ab2011-12-22 06:55:31941}
942
[email protected]f2bd40812013-07-20 04:30:44943int WebContentsImpl::GetCapturerCount() const {
944 return capturer_count_;
945}
946
[email protected]b172aee2012-04-10 17:05:26947bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31948 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
949 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
950 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49951}
952
[email protected]b172aee2012-04-10 17:05:26953void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
954 int error_code) {
[email protected]443b80e2010-12-14 00:42:23955 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34956 return;
957
[email protected]443b80e2010-12-14 00:42:23958 crashed_status_ = status;
959 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21960 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34961}
962
[email protected]b172aee2012-04-10 17:05:26963base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31964 return crashed_status_;
965}
966
[email protected]b172aee2012-04-10 17:05:26967bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31968 return is_being_destroyed_;
969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34972 if (delegate_)
973 delegate_->NavigationStateChanged(this, changed_flags);
974}
975
[email protected]3e324142012-06-25 18:26:33976base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
977 return last_selected_time_;
978}
979
[email protected]9e2e4632012-07-27 16:38:41980void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54981 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04982 RenderWidgetHostViewPort* rwhv =
983 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16984 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29985 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43986#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16987 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43988#endif
989 }
[email protected]96d185d2009-04-24 03:28:54990
[email protected]5ac20162010-11-24 23:33:11991 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38992
[email protected]b9769d82012-02-10 00:23:59993 // The resize rect might have changed while this was inactive -- send the new
994 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58995 RenderViewHostImpl* rvh =
996 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59997 if (rvh) {
998 rvh->ResizeRectChanged(GetRootWindowResizerRect());
999 }
[email protected]96d185d2009-04-24 03:28:541000
[email protected]c0d9d5672013-10-09 07:38:031001 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1002
[email protected]54597982013-02-06 01:59:551003 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311004}
1005
[email protected]b172aee2012-04-10 17:05:261006void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551007 // If there are entities capturing screenshots or video (e.g., mirroring),
1008 // don't activate the "disable rendering" optimization.
1009 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521010 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551011 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261012 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521013 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331014 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521015 // calls us).
[email protected]c30585c2012-02-16 15:02:041016 RenderWidgetHostViewPort* rwhv =
1017 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161018 if (rwhv)
[email protected]68ef3962013-09-26 06:45:291019 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:541020 }
1021
[email protected]c0d9d5672013-10-09 07:38:031022 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1023
[email protected]54597982013-02-06 01:59:551024 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371025}
1026
[email protected]b172aee2012-04-10 17:05:261027bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311028 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271029 return WillNotifyDisconnection() &&
1030 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581031 !static_cast<RenderViewHostImpl*>(
1032 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311033}
1034
[email protected]b172aee2012-04-10 17:05:261035void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211036 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401037 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271038}
1039
[email protected]b172aee2012-04-10 17:05:261040WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441041 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451042 // We pass our own opener so that the cloned page can access it if it was
1043 // before.
[email protected]54944cde2012-12-09 09:24:591044 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451045 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591046 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191047 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221048 FOR_EACH_OBSERVER(WebContentsObserver,
1049 observers_,
1050 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271051 return tc;
1052}
1053
[email protected]14392a52012-05-02 20:28:441054void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211055 const NotificationSource& source,
1056 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441057 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211058 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1059 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501060 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1061 i != pending_widget_views_.end(); ++i) {
1062 if (host->GetView() == i->second) {
1063 pending_widget_views_.erase(i);
1064 break;
1065 }
1066 }
1067 break;
1068 }
[email protected]14392a52012-05-02 20:28:441069 default:
1070 NOTREACHED();
1071 }
1072}
1073
[email protected]ec6c05f2013-10-23 18:41:571074WebContents* WebContentsImpl::GetWebContents() {
1075 return this;
1076}
1077
[email protected]54944cde2012-12-09 09:24:591078void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211079 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361080 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211081 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431082 should_normally_be_visible_ = !params.initially_hidden;
1083
[email protected]fa944cb82013-11-15 17:51:211084 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041085 params.browser_context, params.site_instance, params.routing_id,
1086 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191087
[email protected]8ff00d72012-10-23 19:12:211088 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191089 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271090 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191091 CHECK(render_view_host_delegate_view_);
1092 } else {
[email protected]f8497342013-02-05 22:15:021093 WebContentsViewDelegate* delegate =
1094 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1095
[email protected]59383c782013-04-17 16:43:271096 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381097 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1098 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021099
[email protected]b5a40842012-11-28 15:26:111100 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381101 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431102 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111103 render_view_host_delegate_view_ = rv;
1104 view_.reset(rv);
1105 } else {
[email protected]f8497342013-02-05 22:15:021106 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111107 view_.reset(CreateWebContentsView(
1108 this, delegate, &render_view_host_delegate_view_));
1109 }
[email protected]d1198fd2012-08-13 22:50:191110 CHECK(render_view_host_delegate_view_);
1111 }
1112 CHECK(view_.get());
1113
[email protected]ed245db2012-12-18 08:00:451114 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591115 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191116
1117 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101118 if (opener_)
1119 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191120
1121 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211122 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1123 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441124#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191125 java_bridge_dispatcher_host_manager_.reset(
1126 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101127 date_time_chooser_.reset(new DateTimeChooserAndroid());
1128#endif
[email protected]d1198fd2012-08-13 22:50:191129}
1130
[email protected]7fff43e2013-05-21 20:21:101131void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1132 RemoveDestructionObserver(web_contents);
1133
[email protected]14392a52012-05-02 20:28:441134 // Clear the opener if it has been closed.
1135 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441136 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511137 return;
[email protected]14392a52012-05-02 20:28:441138 }
[email protected]ceee8cd2013-03-08 04:59:511139 // Clear a pending contents that has been closed before being shown.
1140 for (PendingContents::iterator iter = pending_contents_.begin();
1141 iter != pending_contents_.end();
1142 ++iter) {
1143 if (iter->second != web_contents)
1144 continue;
1145 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511146 return;
1147 }
1148 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441149}
1150
[email protected]7fff43e2013-05-21 20:21:101151void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1152 if (!ContainsKey(destruction_observers_, web_contents)) {
1153 destruction_observers_[web_contents] =
1154 new DestructionObserver(this, web_contents);
1155 }
1156}
1157
1158void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1159 DestructionObservers::iterator iter =
1160 destruction_observers_.find(web_contents);
1161 if (iter != destruction_observers_.end()) {
1162 delete destruction_observers_[web_contents];
1163 destruction_observers_.erase(iter);
1164 }
1165}
1166
[email protected]b172aee2012-04-10 17:05:261167void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311168 observers_.AddObserver(observer);
1169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311172 observers_.RemoveObserver(observer);
1173}
1174
[email protected]b172aee2012-04-10 17:05:261175void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341176 if (delegate_)
1177 delegate_->ActivateContents(this);
1178}
1179
[email protected]b172aee2012-04-10 17:05:261180void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121181 if (delegate_)
1182 delegate_->DeactivateContents(this);
1183}
1184
[email protected]b172aee2012-04-10 17:05:261185void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481186 if (delegate_)
1187 delegate_->LostCapture();
1188}
1189
[email protected]b24b68a2012-09-24 21:57:261190void WebContentsImpl::RenderWidgetDeleted(
1191 RenderWidgetHostImpl* render_widget_host) {
1192 if (is_being_destroyed_) {
1193 // |created_widgets_| might have been destroyed.
1194 return;
1195 }
1196
1197 std::set<RenderWidgetHostImpl*>::iterator iter =
1198 created_widgets_.find(render_widget_host);
1199 if (iter != created_widgets_.end())
1200 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541201
1202 if (render_widget_host &&
1203 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491204 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1205 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541206 FOR_EACH_OBSERVER(WebContentsObserver,
1207 observers_,
1208 DidDestroyFullscreenWidget(
1209 fullscreen_widget_routing_id_));
1210 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1211 }
[email protected]b24b68a2012-09-24 21:57:261212}
1213
[email protected]b172aee2012-04-10 17:05:261214bool WebContentsImpl::PreHandleKeyboardEvent(
1215 const NativeWebKeyboardEvent& event,
1216 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481217 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131218 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481219}
1220
[email protected]b172aee2012-04-10 17:05:261221void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061222 if (browser_plugin_embedder_ &&
1223 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1224 return;
1225 }
1226
[email protected]63954792011-07-11 04:17:481227 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131228 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481229}
1230
[email protected]fb3f066e2013-02-12 19:12:521231bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461232 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191233#if !defined(OS_MACOSX)
1234 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1235 // isn't done for two reasons:
1236 // -the OS already has a gesture to do this through pinch-zoom
1237 // -if a user starts an inertial scroll, let's go, and presses control
1238 // (i.e. control+tab) then the OS's buffered scroll events will come in
1239 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521240 if (delegate_ &&
1241 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461242 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521243 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1244 return true;
1245 }
[email protected]bccc4472013-04-18 16:37:191246#endif
[email protected]fb3f066e2013-02-12 19:12:521247
1248 return false;
1249}
1250
[email protected]c73a2282013-04-29 21:10:411251#if defined(OS_WIN) && defined(USE_AURA)
1252gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1253 return accessible_parent_;
1254}
1255#endif
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431258 if (delegate_)
1259 delegate_->HandleMouseDown();
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481263 if (delegate_)
1264 delegate_->HandleMouseUp();
1265}
1266
[email protected]590a634e2012-07-19 16:38:231267void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481268 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231269 delegate_->HandlePointerActivate();
1270}
1271
1272void WebContentsImpl::HandleGestureBegin() {
1273 if (delegate_)
1274 delegate_->HandleGestureBegin();
1275}
1276
1277void WebContentsImpl::HandleGestureEnd() {
1278 if (delegate_)
1279 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491283 // This method is being called to enter or leave renderer-initiated fullscreen
1284 // mode. Either way, make sure any existing fullscreen widget is shut down
1285 // first.
1286 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1287 if (widget_view)
1288 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1289
[email protected]8a5e0ca2011-08-25 06:30:471290 if (delegate_)
1291 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1292}
1293
[email protected]b172aee2012-04-10 17:05:261294bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381295 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121296}
1297
[email protected]a9c81f02012-06-01 00:15:441298void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1299 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371300 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441301 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371302 } else {
1303 GotResponseToLockMouseRequest(false);
1304 }
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371308 if (delegate_)
1309 delegate_->LostMouseLock();
1310}
1311
[email protected]bafe6cd2012-05-23 23:09:501312void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201313 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501314 int route_id,
[email protected]227692c52013-05-31 22:43:041315 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131316 const ViewHostMsg_CreateWindow_Params& params,
1317 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501318 // We usually create the new window in the same BrowsingInstance (group of
1319 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551320 // if the opener is being suppressed (in a non-guest), we create a new
1321 // SiteInstance in its own BrowsingInstance.
1322 bool is_guest = GetRenderProcessHost()->IsGuest();
1323
[email protected]04cbd3d2013-12-04 04:58:201324 // If the opener is to be suppressed, the new window can be in any process.
1325 // Since routing ids are process specific, we must not have one passed in
1326 // as argument here.
1327 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1328
[email protected]bafe6cd2012-05-23 23:09:501329 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551330 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571331 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501332 GetSiteInstance();
1333
[email protected]04cbd3d2013-12-04 04:58:201334 // A message to create a new window can only come from the active process for
1335 // this WebContentsImpl instance. If any other process sends the request,
1336 // it is invalid and the process must be terminated.
1337 if (GetRenderProcessHost()->GetID() != render_process_id) {
1338 base::ProcessHandle process_handle =
1339 RenderProcessHost::FromID(render_process_id)->GetHandle();
1340 if (process_handle != base::kNullProcessHandle) {
1341 RecordAction(
1342 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1343 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1344 }
1345 return;
1346 }
1347
[email protected]d1198fd2012-08-13 22:50:191348 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341349 //
1350 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301351 const std::string& partition_id =
1352 GetContentClient()->browser()->
1353 GetStoragePartitionIdForSite(GetBrowserContext(),
1354 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461355 StoragePartition* partition = BrowserContext::GetStoragePartition(
1356 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411357 DOMStorageContextWrapper* dom_storage_context =
1358 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191359 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1360 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1361 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371362
1363 if (delegate_ &&
1364 !delegate_->ShouldCreateWebContents(this,
1365 route_id,
1366 params.window_container_type,
1367 params.frame_name,
1368 params.target_url,
1369 partition_id,
1370 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011371 if (route_id != MSG_ROUTING_NONE &&
1372 !RenderViewHost::FromID(render_process_id, route_id)) {
1373 // If the embedder didn't create a WebContents for this route, we need to
1374 // delete the RenderView that had already been created.
1375 Send(new ViewMsg_Close(route_id));
1376 }
[email protected]dd6730412013-08-14 15:03:371377 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1378 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1379 main_frame_route_id);
1380 return;
1381 }
1382
1383 // Create the new web contents. This will automatically create the new
1384 // WebContentsView. In the future, we may want to create the view separately.
1385 WebContentsImpl* new_contents =
1386 new WebContentsImpl(GetBrowserContext(),
1387 params.opener_suppressed ? NULL : this);
1388
[email protected]d1198fd2012-08-13 22:50:191389 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301390 partition_id,
[email protected]d1198fd2012-08-13 22:50:191391 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461392 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591393 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041394 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551395 if (!is_guest) {
1396 create_params.context = view_->GetNativeView();
1397 create_params.initial_size = view_->GetContainerSize();
1398 } else {
1399 // This makes |new_contents| act as a guest.
1400 // For more info, see comment above class BrowserPluginGuest.
1401 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1402 WebContentsImpl* new_contents_impl =
1403 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461404 BrowserPluginGuest::CreateWithOpener(instance_id,
1405 new_contents_impl->opener() != NULL,
1406 new_contents_impl,
1407 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551408 }
[email protected]1ac10dca2013-08-20 20:47:041409 if (params.disposition == NEW_BACKGROUND_TAB)
1410 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591411 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191412
[email protected]c4538072013-03-18 02:17:551413 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341414 // will be shown immediately).
1415 if (!params.opener_suppressed) {
1416 if (!is_guest) {
1417 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501418
[email protected]d70bea92013-04-05 04:23:341419 // TODO(brettw): It seems bogus that we have to call this function on the
1420 // newly created object and give it one of its own member variables.
1421 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1422 }
[email protected]bafe6cd2012-05-23 23:09:501423 // Save the created window associated with the route so we can show it
1424 // later.
1425 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1426 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101427 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501428 }
1429
1430 if (delegate_) {
1431 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131432 this, params.opener_frame_id, params.frame_name,
1433 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501434 }
1435
1436 if (params.opener_suppressed) {
1437 // When the opener is suppressed, the original renderer cannot access the
1438 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001439 bool was_blocked = false;
1440 if (delegate_) {
1441 gfx::Rect initial_pos;
1442 delegate_->AddNewContents(
1443 this, new_contents, params.disposition, initial_pos,
1444 params.user_gesture, &was_blocked);
1445 }
1446 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211447 OpenURLParams open_params(params.target_url,
1448 Referrer(),
1449 CURRENT_TAB,
1450 PAGE_TRANSITION_LINK,
1451 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301452 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001453 new_contents->OpenURL(open_params);
1454 }
[email protected]bafe6cd2012-05-23 23:09:501455 }
1456}
1457
[email protected]a8504022013-12-04 20:23:511458void WebContentsImpl::CreateNewWidget(int render_process_id,
1459 int route_id,
[email protected]180ef242013-11-07 06:50:461460 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511461 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501462}
1463
[email protected]a8504022013-12-04 20:23:511464void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1465 int route_id) {
1466 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501467}
1468
[email protected]a8504022013-12-04 20:23:511469void WebContentsImpl::CreateNewWidget(int render_process_id,
1470 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501471 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461472 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211473 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511474 // A message to create a new widget can only come from the active process for
1475 // this WebContentsImpl instance. If any other process sends the request,
1476 // it is invalid and the process must be terminated.
1477 if (process->GetID() != render_process_id) {
1478 base::ProcessHandle process_handle =
1479 RenderProcessHost::FromID(render_process_id)->GetHandle();
1480 if (process_handle != base::kNullProcessHandle) {
1481 RecordAction(
1482 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1483 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1484 }
1485 return;
1486 }
1487
[email protected]bafe6cd2012-05-23 23:09:501488 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041489 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261490 created_widgets_.insert(widget_host);
1491
[email protected]83918ec2013-01-10 15:37:191492 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1493 view_->CreateViewForPopupWidget(widget_host));
1494 if (!widget_view)
1495 return;
[email protected]bafe6cd2012-05-23 23:09:501496 if (!is_fullscreen) {
1497 // Popups should not get activated.
1498 widget_view->SetPopupType(popup_type);
1499 }
1500 // Save the created widget associated with the route so we can show it later.
1501 pending_widget_views_[route_id] = widget_view;
1502
1503#if defined(OS_MACOSX)
1504 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1505 // to allow it to survive the trip without being hosted.
1506 base::mac::NSObjectRetain(widget_view->GetNativeView());
1507#endif
1508}
1509
1510void WebContentsImpl::ShowCreatedWindow(int route_id,
1511 WindowOpenDisposition disposition,
1512 const gfx::Rect& initial_pos,
1513 bool user_gesture) {
1514 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001515 if (contents) {
1516 WebContentsDelegate* delegate = GetDelegate();
1517 if (delegate) {
1518 delegate->AddNewContents(
1519 this, contents, disposition, initial_pos, user_gesture, NULL);
1520 }
1521 }
[email protected]bafe6cd2012-05-23 23:09:501522}
1523
1524void WebContentsImpl::ShowCreatedWidget(int route_id,
1525 const gfx::Rect& initial_pos) {
1526 ShowCreatedWidget(route_id, false, initial_pos);
1527}
1528
1529void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1530 ShowCreatedWidget(route_id, true, gfx::Rect());
1531}
1532
1533void WebContentsImpl::ShowCreatedWidget(int route_id,
1534 bool is_fullscreen,
1535 const gfx::Rect& initial_pos) {
1536 if (delegate_)
1537 delegate_->RenderWidgetShowing();
1538
1539 RenderWidgetHostViewPort* widget_host_view =
1540 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1541 if (!widget_host_view)
1542 return;
[email protected]4aebbca2013-09-17 22:26:491543 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311544 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1545 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491546 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1547 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1548 delegate_->ToggleFullscreenModeForTab(this, true);
1549 } else {
1550 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491551 }
[email protected]4aebbca2013-09-17 22:26:491552 FOR_EACH_OBSERVER(WebContentsObserver,
1553 observers_,
1554 DidShowFullscreenWidget(route_id));
1555 if (!widget_host_view->HasFocus())
1556 widget_host_view->Focus();
1557 } else {
[email protected]f8497342013-02-05 22:15:021558 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491559 }
[email protected]89054502012-06-03 10:29:241560
1561 RenderWidgetHostImpl* render_widget_host_impl =
1562 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1563 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311564 // Only allow privileged mouse lock for fullscreen render widget, which is
1565 // used to implement Pepper Flash fullscreen.
1566 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501567
1568#if defined(OS_MACOSX)
1569 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1570 // properly embedded (or purposefully ignored) we can release the retain we
1571 // took in CreateNewWidget().
1572 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1573#endif
1574}
1575
1576WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1577 PendingContents::iterator iter = pending_contents_.find(route_id);
1578
1579 // Certain systems can block the creation of new windows. If we didn't succeed
1580 // in creating one, just return NULL.
1581 if (iter == pending_contents_.end()) {
1582 return NULL;
1583 }
1584
1585 WebContentsImpl* new_contents = iter->second;
1586 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101587 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501588
[email protected]d70bea92013-04-05 04:23:341589 // Don't initialize the guest WebContents immediately.
1590 if (new_contents->GetRenderProcessHost()->IsGuest())
1591 return new_contents;
1592
[email protected]bafe6cd2012-05-23 23:09:501593 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1594 !new_contents->GetRenderViewHost()->GetView())
1595 return NULL;
1596
1597 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1598 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1599 return new_contents;
1600}
1601
1602RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1603 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1604 if (iter == pending_widget_views_.end()) {
1605 DCHECK(false);
1606 return NULL;
1607 }
1608
1609 RenderWidgetHostView* widget_host_view = iter->second;
1610 pending_widget_views_.erase(route_id);
1611
1612 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1613 if (!widget_host->GetProcess()->HasConnection()) {
1614 // The view has gone away or the renderer crashed. Nothing to do.
1615 return NULL;
1616 }
1617
1618 return widget_host_view;
1619}
1620
[email protected]f56c7872013-06-18 12:31:571621void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501622 // Allow WebContentsDelegates to handle the context menu operation first.
1623 if (delegate_ && delegate_->HandleContextMenu(params))
1624 return;
1625
[email protected]f56c7872013-06-18 12:31:571626 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501627}
1628
[email protected]f13b4202012-06-12 23:53:231629void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091630 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211631 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231632 if (delegate_)
1633 delegate_->RequestMediaAccessPermission(this, request, callback);
1634 else
[email protected]b5f76742013-04-29 15:05:591635 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231636}
1637
[email protected]cc9200432013-07-23 23:02:401638SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1639 SiteInstance* instance) {
1640 return controller_.GetSessionStorageNamespace(instance);
1641}
1642
[email protected]9b159a52013-10-03 17:24:551643FrameTree* WebContentsImpl::GetFrameTree() {
1644 return &frame_tree_;
1645}
1646
[email protected]edc3af82013-12-12 21:24:071647void WebContentsImpl::OnShowValidationMessage(
1648 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291649 const base::string16& main_text,
1650 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071651 if (delegate_)
1652 delegate_->ShowValidationMessage(
1653 this, anchor_in_root_view, main_text, sub_text);
1654}
1655
1656void WebContentsImpl::OnHideValidationMessage() {
1657 if (delegate_)
1658 delegate_->HideValidationMessage(this);
1659}
1660
1661void WebContentsImpl::OnMoveValidationMessage(
1662 const gfx::Rect& anchor_in_root_view) {
1663 if (delegate_)
1664 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1665}
1666
[email protected]32deec62013-05-15 23:55:041667void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1668 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441669 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041670}
1671
[email protected]b172aee2012-04-10 17:05:261672void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231673 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331674 if (delegate_)
1675 delegate_->UpdatePreferredSize(this, pref_size);
1676}
1677
[email protected]b172aee2012-04-10 17:05:261678void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341679 if (delegate_)
1680 delegate_->ResizeDueToAutoResize(this, new_size);
1681}
1682
[email protected]b172aee2012-04-10 17:05:261683WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201684 if (!delegate_)
1685 return NULL;
[email protected]00c37fc2011-08-02 00:22:501686
[email protected]e5d549d2011-12-28 01:29:201687 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201688 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341689}
1690
[email protected]6b618e62012-08-16 12:59:181691bool WebContentsImpl::Send(IPC::Message* message) {
1692 if (!GetRenderViewHost()) {
1693 delete message;
1694 return false;
1695 }
1696
1697 return GetRenderViewHost()->Send(message);
1698}
1699
[email protected]b172aee2012-04-10 17:05:261700bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501701 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251702 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231703 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251704 reload_type);
[email protected]876bc832010-09-07 16:29:541705}
[email protected]96d185d2009-04-24 03:28:541706
[email protected]a86c0e962013-12-17 17:10:391707void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1708 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391710 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441711}
1712
[email protected]20ca0382013-02-28 19:50:071713void WebContentsImpl::AttachInterstitialPage(
1714 InterstitialPageImpl* interstitial_page) {
1715 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211716 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291717
1718 // Cancel any visible dialogs so that they don't interfere with the
1719 // interstitial.
1720 if (dialog_manager_)
1721 dialog_manager_->CancelActiveAndPendingDialogs(this);
1722
[email protected]20ca0382013-02-28 19:50:071723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1724 DidAttachInterstitialPage());
1725}
1726
1727void WebContentsImpl::DetachInterstitialPage() {
1728 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211729 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1731 DidDetachInterstitialPage());
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231735 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501736 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031737 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1738
[email protected]19e81142011-10-03 16:19:401739 // The renderer will reject IPC messages with URLs longer than
1740 // this limit, so don't attempt to navigate with a longer URL.
[email protected]f16cc6782013-12-16 23:42:571741 if (entry.GetURL().spec().size() > GetMaxURLChars()) {
1742 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars()
[email protected]3adab1c2013-09-09 21:23:431743 << " characters.";
[email protected]19e81142011-10-03 16:19:401744 return false;
[email protected]3adab1c2013-09-09 21:23:431745 }
[email protected]19e81142011-10-03 16:19:401746
[email protected]a1b99262013-12-27 21:56:221747 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to
1748 // use when --site-per-process is used.
1749 RenderFrameHostManager* manager = GetRenderManager();
1750 if (entry.frame_tree_node_id() != -1 &&
1751 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) {
1752 int64 frame_tree_node_id = entry.frame_tree_node_id();
1753 manager = frame_tree_.FindByID(frame_tree_node_id)->render_manager();
1754 }
1755
[email protected]9f76c1e2012-03-05 15:15:581756 RenderViewHostImpl* dest_render_view_host =
[email protected]a1b99262013-12-27 21:56:221757 static_cast<RenderViewHostImpl*>(manager->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401758 if (!dest_render_view_host)
1759 return false; // Unable to create the desired render view host.
1760
[email protected]80a8fad2011-01-29 04:02:381761 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071762 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581763 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271764 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501765 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031766 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1767 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211768 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231769 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271770 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211771 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231772 CHECK(0);
1773 }
[email protected]54ec6472010-04-09 19:39:581774
[email protected]7bb761892012-07-20 09:32:471775 // Notify observers that we will navigate in this RV.
1776 FOR_EACH_OBSERVER(WebContentsObserver,
1777 observers_,
1778 AboutToNavigateRenderView(dest_render_view_host));
1779
[email protected]96d185d2009-04-24 03:28:541780 // Used for page load time metrics.
1781 current_load_start_ = base::TimeTicks::Now();
1782
1783 // Navigate in the desired RenderViewHost.
[email protected]a1b99262013-12-27 21:56:221784 // TODO(creis): As a temporary hack, we currently do cross-process subframe
1785 // navigations in a top-level frame of the new process. Thus, we don't yet
1786 // need to store the correct frame ID in ViewMsg_Navigate_Params.
[email protected]056de2d2009-06-26 16:41:341787 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271788 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471789 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341790 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541791
[email protected]36fc0392011-12-25 03:59:511792 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541793 // HACK!! This code suppresses javascript: URLs from being added to
1794 // session history, which is what we want to do for javascript: URLs that
1795 // do not generate content. What we really need is a message from the
1796 // renderer telling us that a new page was not created. The same message
1797 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351798 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541799 return false;
1800 }
1801
[email protected]3c9e1872010-11-18 16:17:491802 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391803 FOR_EACH_OBSERVER(
1804 WebContentsObserver,
1805 observers_,
1806 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541807
[email protected]09b29342011-06-24 19:18:481808 if (delegate_)
1809 delegate_->DidNavigateToPendingEntry(this);
1810
[email protected]d5f942ba2008-09-26 19:30:341811 return true;
1812}
1813
[email protected]b172aee2012-04-10 17:05:261814void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331815 const SiteInstance* site_instance,
1816 int history_length,
1817 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411818 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1819 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211820 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191821 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141822 return;
[email protected]9e1ad4b2011-08-14 16:49:191823 }
[email protected]9f76c1e2012-03-05 15:15:581824 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191825 if (!rvh) {
1826 NOTREACHED();
1827 return;
1828 }
[email protected]9f76c1e2012-03-05 15:15:581829 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191830 NOTREACHED();
1831 return;
1832 }
[email protected]6b618e62012-08-16 12:59:181833 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1834 history_length,
1835 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141836}
1837
[email protected]b172aee2012-04-10 17:05:261838void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271839 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211840 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541841 return;
1842 }
[email protected]9f76c1e2012-03-05 15:15:581843 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541844}
1845
[email protected]b172aee2012-04-10 17:05:261846bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211847 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541848}
1849
[email protected]b172aee2012-04-10 17:05:261850InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211851 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221852}
1853
[email protected]b172aee2012-04-10 17:05:261854bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161855 // WebKit creates Document object when MIME type is application/xhtml+xml,
1856 // so we also support this MIME type.
1857 return contents_mime_type_ == "text/html" ||
1858 contents_mime_type_ == "text/xml" ||
1859 contents_mime_type_ == "application/xhtml+xml" ||
1860 contents_mime_type_ == "text/plain" ||
1861 contents_mime_type_ == "text/css" ||
1862 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1863}
1864
[email protected]b172aee2012-04-10 17:05:261865void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591866 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161867 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551868 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011869 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141870 return;
[email protected]c7dd2f62011-07-18 15:57:591871 }
1872
1873 Stop();
1874
1875 // Create the save package and possibly prompt the user for the name to save
1876 // the page as. The user prompt is an asynchronous operation that runs on
1877 // another thread.
1878 save_package_ = new SavePackage(this);
1879 save_package_->GetSaveInfo();
1880}
1881
1882// Used in automated testing to bypass prompting the user for file names.
1883// Instead, the names and paths are hard coded rather than running them through
1884// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341885bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1886 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211887 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591888 // Stop the page from navigating.
1889 Stop();
1890
1891 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211892 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591893}
1894
[email protected]3c71576ce2013-07-23 02:00:011895void WebContentsImpl::SaveFrame(const GURL& url,
1896 const Referrer& referrer) {
1897 if (!GetURL().is_valid())
1898 return;
1899 bool is_main_frame = (url == GetURL());
1900
1901 DownloadManager* dlm =
1902 BrowserContext::GetDownloadManager(GetBrowserContext());
1903 if (!dlm)
1904 return;
1905 int64 post_id = -1;
1906 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271907 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011908 if (entry)
1909 post_id = entry->GetPostID();
1910 }
1911 scoped_ptr<DownloadUrlParameters> params(
1912 DownloadUrlParameters::FromWebContents(this, url));
1913 params->set_referrer(referrer);
1914 params->set_post_id(post_id);
1915 params->set_prefer_cache(true);
1916 if (post_id >= 0)
1917 params->set_method("POST");
1918 params->set_prompt(true);
1919 dlm->DownloadUrl(params.Pass());
1920}
1921
[email protected]b172aee2012-04-10 17:05:261922void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341923 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481924 const base::Callback<void(int64)>& callback) {
1925 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121926}
1927
[email protected]6286a372013-10-09 04:03:271928// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261929bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271930 NavigationEntryImpl* visible_entry =
1931 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1932 return (visible_entry != NULL &&
1933 visible_entry->site_instance() == GetSiteInstance() &&
1934 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321935}
1936
[email protected]b172aee2012-04-10 17:05:261937const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271938 return contents_mime_type_;
1939}
1940
[email protected]b172aee2012-04-10 17:05:261941bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271942 return notify_disconnection_;
1943}
1944
[email protected]b172aee2012-04-10 17:05:261945void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311946 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181947 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311951 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181952 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161953}
1954
[email protected]8ff00d72012-10-23 19:12:211955RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271956 return &renderer_preferences_;
1957}
1958
[email protected]e35ccd52012-05-23 16:22:471959void WebContentsImpl::Close() {
1960 Close(GetRenderViewHost());
1961}
1962
[email protected]cf200a562013-05-03 16:24:291963void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461964 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291965 if (browser_plugin_embedder_.get())
1966 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1967 screen_x, screen_y, operation);
1968 if (GetRenderViewHost())
1969 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1970 screen_x, screen_y, operation);
1971}
1972
1973void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1974 int screen_x, int screen_y) {
1975 if (browser_plugin_embedder_.get())
1976 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1977 screen_x, screen_y);
1978 if (GetRenderViewHost())
1979 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1980 screen_x, screen_y);
1981}
1982
[email protected]d60f3702013-12-26 16:30:241983void WebContentsImpl::DidGetResourceResponseStart(
1984 const ResourceRequestDetails& details) {
1985 controller_.ssl_manager()->DidStartResourceResponse(details);
1986
1987 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1988 DidGetResourceResponseStart(details));
1989
1990 // TODO(avi): Remove. http://crbug.com/170921
1991 NotificationService::current()->Notify(
1992 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1993 Source<WebContents>(this),
1994 Details<const ResourceRequestDetails>(&details));
1995}
1996
1997void WebContentsImpl::DidGetRedirectForResourceRequest(
1998 RenderViewHost* render_view_host,
1999 const ResourceRedirectDetails& details) {
2000 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2001
2002 FOR_EACH_OBSERVER(
2003 WebContentsObserver,
2004 observers_,
2005 DidGetRedirectForResourceRequest(render_view_host, details));
2006
2007 // TODO(avi): Remove. http://crbug.com/170921
2008 NotificationService::current()->Notify(
2009 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2010 Source<WebContents>(this),
2011 Details<const ResourceRedirectDetails>(&details));
2012}
2013
[email protected]b172aee2012-04-10 17:05:262014void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522015 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582016 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512017 if (delegate_)
2018 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292019 if (browser_plugin_embedder_.get())
2020 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342021}
2022
[email protected]e35ccd52012-05-23 16:22:472023void WebContentsImpl::UserGestureDone() {
2024 OnUserGesture();
2025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272028 closed_by_user_gesture_ = value;
2029}
2030
[email protected]b172aee2012-04-10 17:05:262031bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272032 return closed_by_user_gesture_;
2033}
2034
[email protected]b172aee2012-04-10 17:05:262035double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052036 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562037 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252038 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172039 return 0;
[email protected]b75b8292010-10-01 07:28:252040
2041 double zoom_level;
2042 if (temporary_zoom_settings_) {
2043 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582044 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252045 } else {
[email protected]2ae88d12011-10-14 09:11:192046 GURL url;
[email protected]6286a372013-10-09 04:03:272047 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192048 // Since zoom map is updated using rewritten URL, use rewritten URL
2049 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272050 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022051 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2052 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252053 }
[email protected]d0b8d092010-10-25 04:05:172054 return zoom_level;
2055}
[email protected]b75b8292010-10-01 07:28:252056
[email protected]b172aee2012-04-10 17:05:262057int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592058 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172059 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012060 // Calculate the zoom percent from the factor. Round up to the nearest whole
2061 // number.
[email protected]b75b8292010-10-01 07:28:252062 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492063 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252064 *enable_decrement = percent > minimum_zoom_percent_;
2065 *enable_increment = percent < maximum_zoom_percent_;
2066 return percent;
2067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502070 if (!delegate_)
2071 return;
2072
[email protected]6286a372013-10-09 04:03:272073 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2074 if (!entry)
[email protected]1788e772010-12-15 16:40:502075 return;
2076
[email protected]6286a372013-10-09 04:03:272077 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122078}
2079
[email protected]b172aee2012-04-10 17:05:262080void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042081 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272082 if (!delegate_)
2083 return;
2084
[email protected]691aa2f2013-05-28 22:52:042085 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272086}
2087
[email protected]b172aee2012-04-10 17:05:262088int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272089 return minimum_zoom_percent_;
2090}
2091
[email protected]b172aee2012-04-10 17:05:262092int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272093 return maximum_zoom_percent_;
2094}
2095
[email protected]b172aee2012-04-10 17:05:262096gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:232097 return preferred_size_;
2098}
2099
[email protected]b172aee2012-04-10 17:05:262100bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272101 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582102 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272103}
2104
[email protected]b172aee2012-04-10 17:05:262105bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442106 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502107}
2108
[email protected]cb805452013-05-22 15:16:212109void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182110 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212111 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202112}
2113
[email protected]cb805452013-05-22 15:16:212114void WebContentsImpl::DidEndColorChooser() {
2115 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2116 color_chooser_identifier_));
2117 color_chooser_.reset();
2118 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202119}
2120
[email protected]41225fe2013-03-29 05:32:022121int WebContentsImpl::DownloadImage(const GURL& url,
2122 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302123 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022124 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392125 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302126 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022127 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392128 return id;
2129}
2130
[email protected]5dcaf8e2013-12-28 01:31:422131bool WebContentsImpl::IsSubframe() const {
2132 return is_subframe_;
2133}
2134
[email protected]9649d492014-01-10 07:15:522135void WebContentsImpl::SetZoomLevel(double level) {
2136 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2137 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2138 if (embedder)
2139 embedder->SetZoomLevel(level);
2140}
2141
[email protected]36ec24f2014-01-09 00:32:082142void WebContentsImpl::Find(int request_id,
2143 const base::string16& search_text,
2144 const blink::WebFindOptions& options) {
2145 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2146}
2147
2148void WebContentsImpl::StopFinding(StopFindAction action) {
2149 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2150}
2151
[email protected]b172aee2012-04-10 17:05:262152bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272153 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202154 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332155 return true;
2156 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272160 if (delegate_)
2161 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212162}
2163
[email protected]52913802013-12-10 05:52:182164void WebContentsImpl::DidStartProvisionalLoad(
2165 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572166 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132167 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572168 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182169 const GURL& validated_url,
2170 bool is_error_page,
2171 bool is_iframe_srcdoc) {
2172 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572173 DidChangeLoadProgress(0);
2174
[email protected]0d60f0192011-04-14 12:40:102175 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132177 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2178 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182179 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542180
2181 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182182 FOR_EACH_OBSERVER(
2183 WebContentsObserver,
2184 observers_,
2185 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582186 render_frame_host));
[email protected]400992b2012-06-14 00:03:542187 }
2188}
2189
[email protected]3109fbb72014-01-06 23:57:152190void WebContentsImpl::DidFailProvisionalLoadWithError(
2191 RenderFrameHostImpl* render_frame_host,
2192 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2193 GURL validated_url(params.url);
2194 FOR_EACH_OBSERVER(
2195 WebContentsObserver,
2196 observers_,
2197 DidFailProvisionalLoad(params.frame_id,
2198 params.frame_unique_name,
2199 params.is_main_frame,
2200 validated_url,
2201 params.error_code,
2202 params.error_description,
2203 render_frame_host->render_view_host()));
2204}
2205
[email protected]52913802013-12-10 05:52:182206void WebContentsImpl::NotifyChangedNavigationState(
2207 InvalidateTypes changed_flags) {
2208 NotifyNavigationStateChanged(changed_flags);
2209}
2210
[email protected]400992b2012-06-14 00:03:542211void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582212 RenderFrameHostImpl* render_frame_host,
2213 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542214 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582215 FOR_EACH_OBSERVER(
2216 WebContentsObserver,
2217 observers_,
2218 ProvisionalChangeToMainFrameUrl(validated_target_url,
2219 render_frame_host));
[email protected]724159a2010-12-30 01:11:182220}
2221
[email protected]b172aee2012-04-10 17:05:262222void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182223 const GURL& url,
[email protected]70435962011-08-02 20:13:282224 const std::string& security_info,
2225 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182226 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282227 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192228 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182229 cache.Increment();
2230
2231 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082232 int cert_id = 0;
2233 net::CertStatus cert_status = 0;
2234 int security_bits = -1;
2235 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122236 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212237 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122238 &security_bits, &connection_status,
2239 &signed_certificate_timestamp_ids);
2240 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212241 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002242 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2243 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182244
[email protected]b0f724c2013-09-05 04:21:132245 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2246
2247 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2248 DidLoadResourceFromMemoryCache(details));
2249
[email protected]8bfc8272013-09-09 20:10:532250 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2251 scoped_refptr<net::URLRequestContextGetter> request_context(
2252 resource_type == ResourceType::MEDIA ?
2253 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2254 GetRenderProcessHost()->GetID()) :
2255 GetBrowserContext()->GetRequestContextForRenderProcess(
2256 GetRenderProcessHost()->GetID()));
2257 BrowserThread::PostTask(
2258 BrowserThread::IO,
2259 FROM_HERE,
2260 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2261 }
[email protected]724159a2010-12-30 01:11:182262}
2263
[email protected]b172aee2012-04-10 17:05:262264void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212265 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182266 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192267 SSLManager::NotifySSLInternalStateChanged(
2268 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182269}
2270
[email protected]b172aee2012-04-10 17:05:262271void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022272 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582273 LOG(WARNING) << security_origin << " ran insecure content from "
2274 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212275 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412276 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212277 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182278 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412279 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192280 SSLManager::NotifySSLInternalStateChanged(
2281 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182282}
2283
[email protected]b172aee2012-04-10 17:05:262284void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442285 FOR_EACH_OBSERVER(
2286 WebContentsObserver, observers_,
2287 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182288}
2289
[email protected]b172aee2012-04-10 17:05:262290void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312291 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062292 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312293 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062294 GURL validated_url(url);
[email protected]a1b99262013-12-27 21:56:222295
2296 // --site-per-process mode has a short-term hack allowing cross-process
2297 // subframe pages to commit thinking they are top-level. Correct it here to
2298 // avoid confusing the observers.
2299 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2300 render_view_message_source_ != GetRenderViewHost())
2301 is_main_frame = false;
2302
[email protected]f114fa42013-12-06 17:06:442303 RenderProcessHost* render_process_host =
2304 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422305 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252306 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472307 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442308 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312309}
2310
[email protected]b172aee2012-04-10 17:05:262311void WebContentsImpl::OnDidFailLoadWithError(
2312 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062313 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262314 bool is_main_frame,
2315 int error_code,
[email protected]fcf75d42013-12-03 20:11:262316 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062317 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442318 RenderProcessHost* render_process_host =
2319 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422320 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252321 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312322 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472323 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442324 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182325}
2326
[email protected]b172aee2012-04-10 17:05:262327void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262328 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232329 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252330 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262331 if (!entry)
2332 return;
2333 // Note that we don't call NavigationController::GotToOffset() as we don't
2334 // want to create a pending navigation entry (it might end up lingering
2335 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252336 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212337 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512338 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212339 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472340 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572341
2342 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2343 // it in now that we know. This allows us to find the entry when it commits.
2344 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232345 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332346 entry->set_site_instance(
2347 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572348 }
[email protected]216813952011-05-19 22:21:262349 }
2350}
2351
[email protected]b172aee2012-04-10 17:05:262352void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2353 int maximum_percent,
2354 bool remember) {
[email protected]216813952011-05-19 22:21:262355 minimum_zoom_percent_ = minimum_percent;
2356 maximum_zoom_percent_ = maximum_percent;
2357 temporary_zoom_settings_ = !remember;
2358}
2359
[email protected]b172aee2012-04-10 17:05:262360void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342361 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432362 if (!delegate_)
2363 return;
2364
[email protected]b9535422012-02-09 01:47:592365 ChildProcessSecurityPolicyImpl* policy =
2366 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222367 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592368 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212369}
2370
[email protected]b172aee2012-04-10 17:05:262371void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432372 if (delegate_)
2373 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202374}
2375
[email protected]b172aee2012-04-10 17:05:262376void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2377 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262378 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362379 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432380 if (!delegate_)
2381 return;
2382
[email protected]b9535422012-02-09 01:47:592383 ChildProcessSecurityPolicyImpl* policy =
2384 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322385 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592386 return;
[email protected]8f810632013-06-06 22:33:322387
[email protected]3a3b75a2012-06-01 08:38:362388 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202389}
2390
[email protected]b172aee2012-04-10 17:05:262391void WebContentsImpl::OnFindReply(int request_id,
2392 int number_of_matches,
2393 const gfx::Rect& selection_rect,
2394 int active_match_ordinal,
2395 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432396 if (delegate_) {
2397 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2398 active_match_ordinal, final_update);
2399 }
[email protected]b888919c2011-09-02 00:32:162400}
2401
[email protected]59363fc92012-09-05 03:46:312402#if defined(OS_ANDROID)
2403void WebContentsImpl::OnFindMatchRectsReply(
2404 int version,
2405 const std::vector<gfx::RectF>& rects,
2406 const gfx::RectF& active_rect) {
2407 if (delegate_)
2408 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2409}
[email protected]583418cc2013-01-17 14:01:102410
[email protected]1ff427972013-02-07 21:14:072411void WebContentsImpl::OnOpenDateTimeDialog(
2412 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092413 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2414 GetRenderViewHost(),
2415 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132416 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092417 value.minimum,
2418 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172419 value.step,
2420 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102421}
2422
[email protected]a794f3a2013-10-30 17:00:322423void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2424 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442425 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322426}
2427
[email protected]59363fc92012-09-05 03:46:312428#endif
2429
[email protected]f114fa42013-12-06 17:06:442430void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2431 const base::FilePath& path,
2432 bool is_hung) {
2433 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2434
2435 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2436 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2437}
2438
2439void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422440 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442441 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422442 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452443}
2444
[email protected]b172aee2012-04-10 17:05:262445void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2446 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102447 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252448 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102449 AppCacheAccessed(manifest_url, blocked_by_policy));
2450}
2451
[email protected]8bc5ff02013-11-29 06:34:032452void WebContentsImpl::OnOpenColorChooser(
2453 int color_chooser_id,
2454 SkColor color,
2455 const std::vector<ColorSuggestion>& suggestions) {
2456 ColorChooser* new_color_chooser =
2457 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212458 if (color_chooser_ == new_color_chooser)
2459 return;
2460 color_chooser_.reset(new_color_chooser);
2461 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202462}
2463
[email protected]b172aee2012-04-10 17:05:262464void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202465 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212466 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202467 color_chooser_->End();
2468}
2469
[email protected]b172aee2012-04-10 17:05:262470void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322471 SkColor color) {
[email protected]da8543762012-03-20 08:52:202472 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212473 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202474 color_chooser_->SetSelectedColor(color);
2475}
2476
[email protected]d0759f492012-04-19 22:50:502477// This exists for render views that don't have a WebUI, but do have WebUI
2478// bindings enabled.
2479void WebContentsImpl::OnWebUISend(const GURL& source_url,
2480 const std::string& name,
2481 const base::ListValue& args) {
2482 if (delegate_)
2483 delegate_->WebUISend(this, source_url, name, args);
2484}
2485
[email protected]d8415ad92012-08-23 14:40:502486void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442487 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502488 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342489 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162490 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442491 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162492 return;
[email protected]d8415ad92012-08-23 14:40:502493 }
2494
[email protected]8c8fc292012-11-23 18:57:162495 if (!delegate_->RequestPpapiBrokerPermission(
2496 this, url, plugin_path,
2497 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442498 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162499 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442500 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162501 }
[email protected]d8415ad92012-08-23 14:40:502502}
2503
[email protected]ea0309c2013-08-06 19:35:442504void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502505 bool result) {
[email protected]ea0309c2013-08-06 19:35:442506 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502507}
2508
[email protected]c4538072013-03-18 02:17:552509void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372510 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082511 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552512 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392513 // For more info, see comment above classes BrowserPluginEmbedder and
2514 // BrowserPluginGuest.
2515 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142516 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082517 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372518}
2519
[email protected]41225fe2013-03-29 05:32:022520void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392521 int id,
[email protected]749fadd2013-05-15 08:37:482522 int http_status_code,
[email protected]795c28972012-12-06 06:13:392523 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302524 const std::vector<SkBitmap>& bitmaps,
2525 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022526 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2527 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392528 // Currently WebContents notifies us of ANY downloads so that it is
2529 // possible to get here.
2530 return;
2531 }
2532 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302533 iter->second.Run(
2534 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392535 }
[email protected]41225fe2013-03-29 05:32:022536 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392537}
2538
2539void WebContentsImpl::OnUpdateFaviconURL(
2540 int32 page_id,
2541 const std::vector<FaviconURL>& candidates) {
2542 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2543 DidUpdateFaviconURL(page_id, candidates));
2544}
2545
[email protected]d9030b82013-07-19 08:26:062546void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2547 bool has_video,
2548 bool has_audio,
2549 bool is_playing) {
2550 // Chrome OS does its own detection of audio and video.
2551#if !defined(OS_CHROMEOS)
2552 if (is_playing) {
2553 scoped_ptr<PowerSaveBlocker> blocker;
2554 if (has_video) {
2555 blocker = PowerSaveBlocker::Create(
2556 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2557 "Playing video");
2558#if defined(OS_ANDROID)
2559 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382560 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062561#endif
2562 } else if (has_audio) {
2563 blocker = PowerSaveBlocker::Create(
2564 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2565 "Playing audio");
2566 }
2567
[email protected]f114fa42013-12-06 17:06:442568 if (blocker) {
2569 power_save_blockers_[render_view_message_source_][player_cookie] =
2570 blocker.release();
2571 }
[email protected]d9030b82013-07-19 08:26:062572 } else {
[email protected]f114fa42013-12-06 17:06:442573 delete power_save_blockers_[render_view_message_source_][player_cookie];
2574 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062575 }
2576#endif // !defined(OS_CHROMEOS)
2577}
2578
[email protected]9f268072013-11-07 00:02:152579void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2580 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2581 DidFirstVisuallyNonEmptyPaint(page_id));
2582}
[email protected]d9030b82013-07-19 08:26:062583
[email protected]e67ebf32013-02-13 11:07:192584void WebContentsImpl::DidChangeVisibleSSLState() {
2585 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2586 DidChangeVisibleSSLState());
2587}
2588
[email protected]17e286e2013-03-01 23:29:392589void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2590 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2591 BeforeFormRepostWarningShow());
2592}
2593
[email protected]ec6c05f2013-10-23 18:41:572594
2595void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2596 Activate();
2597 if (delegate_)
2598 delegate_->ShowRepostFormWarningDialog(this);
2599}
2600
[email protected]96d185d2009-04-24 03:28:542601// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592602// loading, or done loading.
2603void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2604 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262605 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542606 if (is_loading == is_loading_)
2607 return;
2608
2609 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262610 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2611 base::string16());
[email protected]96d185d2009-04-24 03:28:542612 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562613 upload_size_ = 0;
2614 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542615 }
2616
[email protected]fa944cb82013-11-15 17:51:212617 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542618
2619 is_loading_ = is_loading;
2620 waiting_for_response_ = is_loading;
2621
[email protected]6ebdc9b2010-09-27 16:55:572622 if (delegate_)
2623 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212624 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542625
[email protected]eab61442013-11-14 18:35:482626 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592627 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482628 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2629 "URL", url);
[email protected]91621872013-10-08 04:04:592630 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2631 DidStartLoading(render_view_host));
2632 } else {
[email protected]eab61442013-11-14 18:35:482633 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2634 "URL", url);
[email protected]91621872013-10-08 04:04:592635 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2636 DidStopLoading(render_view_host));
2637 }
[email protected]66798902013-10-01 18:40:162638
2639 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212640 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2641 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542642 if (details)
[email protected]8ff00d72012-10-23 19:12:212643 det = Details<LoadNotificationDetails>(details);
2644 NotificationService::current()->Notify(
2645 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542646}
2647
[email protected]b172aee2012-04-10 17:05:262648void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212649 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322650 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562651 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322652 // Clear the status bubble. This is a workaround for a bug where WebKit
2653 // doesn't let us know that the cursor left an element during a
2654 // transition (this is also why the mouse cursor remains as a hand after
2655 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2656 // clear the bubble when a user navigates to a named anchor in the same
2657 // page.
[email protected]36fc0392011-12-25 03:59:512658 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322659 }
2660
[email protected]a6e82fc2010-02-24 22:28:142661 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472662 // Once the main frame is navigated, we're no longer considered to have
2663 // displayed insecure content.
2664 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352665 SSLManager::NotifySSLInternalStateChanged(
2666 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172667 }
[email protected]ce5c4502009-05-06 16:46:112668
[email protected]3c9e1872010-11-18 16:17:492669 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252670 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042671 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322672}
2673
[email protected]b172aee2012-04-10 17:05:262674void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322675 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212676 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322677 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112678 // If we navigate off the page, close all JavaScript dialogs.
2679 if (dialog_manager_ && !details.is_in_page)
2680 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322681
[email protected]3c9e1872010-11-18 16:17:492682 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252683 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042684 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322685}
2686
[email protected]2f7b3c5a2013-06-21 04:59:252687bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292688 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2689 // still be used for a normal web site.
2690 if (url == GURL(kAboutBlankURL))
2691 return false;
2692
2693 // The embedder will then have the opportunity to determine if the URL
2694 // should "use up" the SiteInstance.
2695 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252696}
2697
[email protected]b172aee2012-04-10 17:05:262698void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462699 // If we are creating a RVH for a restored controller, then we need to make
2700 // sure the RenderView starts with a next_page_id_ larger than the number
2701 // of restored entries. This must be called before the RenderView starts
2702 // navigating (to avoid a race between the browser updating max_page_id and
2703 // the renderer updating next_page_id_). Because of this, we only call this
2704 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562705 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582706 if (max_restored_page_id >
2707 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2708 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2709 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322710}
2711
[email protected]b172aee2012-04-10 17:05:262712bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262713 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322714 // For file URLs without a title, use the pathname instead. In the case of a
2715 // synthesized title, we don't want the update to count toward the "one set
2716 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262717 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322718 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512719 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242720 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322721 explicit_set = false; // Don't count synthetic titles toward the set limit.
2722 } else {
[email protected]acafd272011-07-26 17:35:572723 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322724 explicit_set = true;
2725 }
2726
[email protected]987fc3a2011-05-26 14:18:092727 // If a page is created via window.open and never navigated,
2728 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552729 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092730 if (entry) {
[email protected]36fc0392011-12-25 03:59:512731 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092732 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322733
[email protected]36fc0392011-12-25 03:59:512734 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092735 } else {
2736 if (page_title_when_no_navigation_entry_ == final_title)
2737 return false; // Nothing changed, don't bother.
2738
2739 page_title_when_no_navigation_entry_ = final_title;
2740 }
[email protected]420ae012009-04-24 05:16:322741
[email protected]420ae012009-04-24 05:16:322742 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232743 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322744
[email protected]66798902013-10-01 18:40:162745 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532746 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162747
2748 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212749 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462750 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212751 NotificationService::current()->Notify(
2752 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2753 Source<WebContents>(this),
2754 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042755
[email protected]420ae012009-04-24 05:16:322756 return true;
2757}
2758
[email protected]7b712ee22013-10-03 00:57:282759void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2760 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322761 // After sending out a swap notification, we need to send a disconnect
2762 // notification so that clients that pick up a pointer to |this| can NULL the
2763 // pointer. See Bug 1230284.
2764 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112765 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282766 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112767
2768 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282769 std::pair<RenderViewHost*, RenderViewHost*> details =
2770 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212771 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282772 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212773 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282774 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392775
2776 // Ensure that the associated embedder gets cleared after a RenderViewHost
2777 // gets swapped, so we don't reuse the same embedder next time a
2778 // RenderViewHost is attached to this WebContents.
2779 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322780}
2781
[email protected]da7a7182013-09-06 08:11:112782// TODO(avi): Remove this entire function because this notification is already
2783// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262784void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322785 if (!notify_disconnection_)
2786 return;
2787
2788 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212789 NotificationService::current()->Notify(
2790 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2791 Source<WebContents>(this),
2792 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322793}
2794
[email protected]cbb1ef592013-06-05 19:49:462795void WebContentsImpl::NotifyNavigationEntryCommitted(
2796 const LoadCommittedDetails& load_details) {
2797 FOR_EACH_OBSERVER(
2798 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2799}
2800
[email protected]f114fa42013-12-06 17:06:442801bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2802 const IPC::Message& message) {
2803 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312804}
2805
[email protected]b849847b2013-12-10 21:57:582806void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2807 // Note this is only for subframes, the notification for the main frame
2808 // happens in RenderViewCreated.
2809 FOR_EACH_OBSERVER(WebContentsObserver,
2810 observers_,
2811 RenderFrameCreated(render_frame_host));
2812}
2813
2814void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2815 FOR_EACH_OBSERVER(WebContentsObserver,
2816 observers_,
2817 RenderFrameDeleted(render_frame_host));
2818}
2819
[email protected]b765deb2013-12-18 06:43:302820void WebContentsImpl::WorkerCrashed() {
2821 if (delegate_)
2822 delegate_->WorkerCrashed(this);
2823}
2824
[email protected]a86c0e962013-12-17 17:10:392825WebContents* WebContentsImpl::GetAsWebContents() {
2826 return this;
2827}
2828
[email protected]5a3bdf52012-05-24 15:12:572829RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2830 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322831}
2832
[email protected]8d3347f2009-07-09 22:00:212833RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262834WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212835 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212836}
2837
[email protected]8ff00d72012-10-23 19:12:212838RendererPreferences WebContentsImpl::GetRendererPrefs(
2839 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462840 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512841}
2842
[email protected]b172aee2012-04-10 17:05:262843gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172844 if (delegate_)
2845 return delegate_->GetRootWindowResizerRect();
2846 return gfx::Rect();
2847}
2848
[email protected]7a846df2012-09-20 19:17:392849void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272850 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392851 browser_plugin_embedder_.reset();
2852}
2853
[email protected]b172aee2012-04-10 17:05:262854void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442855 // Don't send notifications if we are just creating a swapped-out RVH for
2856 // the opener chain. These won't be used for view-source or WebUI, so it's
2857 // ok to return early.
2858 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2859 return;
2860
[email protected]86f98a22013-03-20 14:35:002861 if (delegate_)
2862 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082863
[email protected]8ff00d72012-10-23 19:12:212864 NotificationService::current()->Notify(
2865 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2866 Source<WebContents>(this),
2867 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322868
2869 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352870 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212871 if (GetRenderManager()->pending_web_ui())
2872 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322873
[email protected]6286a372013-10-09 04:03:272874 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332875 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322876 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182877 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582878 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322879 }
[email protected]0666aef2009-05-13 19:48:082880
[email protected]60780f412013-02-25 16:34:102881 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262882
2883 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252884 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582885
2886 // We tell the observers now instead of when the main RenderFrameHostImpl is
2887 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2888 // frame would be dropped because it's not created yet).
2889 RenderFrameHost* main_frame = GetMainFrame();
2890 FOR_EACH_OBSERVER(
2891 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322892}
2893
[email protected]b172aee2012-04-10 17:05:262894void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522895 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322896 // Don't notify the world, since this came from a renderer in the
2897 // background.
2898 return;
2899 }
2900
[email protected]da7a7182013-09-06 08:11:112901 notify_disconnection_ = true;
2902 // TODO(avi): Remove. http://crbug.com/170921
2903 NotificationService::current()->Notify(
2904 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2905 Source<WebContents>(this),
2906 NotificationService::NoDetails());
2907
[email protected]be1f56ab2011-12-22 06:55:312908 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232909 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302910
2911 // Restore the focus to the tab (otherwise the focus will be on the top
2912 // window).
[email protected]484ae5912010-09-29 19:16:142913 if (was_crashed && !FocusLocationBarByDefault() &&
2914 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062915 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142916 }
[email protected]32ded2212011-11-10 18:51:432917
[email protected]d8c660432011-12-22 20:51:252918 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322919}
2920
[email protected]ec6a7eb2013-04-22 17:34:222921void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2922 base::TerminationStatus status,
2923 int error_code) {
[email protected]151a63d2011-12-20 22:32:522924 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322925 // The pending page's RenderViewHost is gone.
2926 return;
2927 }
2928
[email protected]d9030b82013-07-19 08:26:062929 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592930 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322931 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232932 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312933 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322934
[email protected]d8c660432011-12-22 20:51:252935 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272936 observers_,
[email protected]58d5cfe2013-07-10 02:40:522937 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322938}
2939
[email protected]b172aee2012-04-10 17:05:262940void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062941 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212942 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252943 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062944}
2945
[email protected]b172aee2012-04-10 17:05:262946void WebContentsImpl::DidNavigate(
2947 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222948 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2949 ViewHostMsg_FrameNavigate_Params params(orig_params);
2950 bool use_site_per_process =
2951 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552952 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2953 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222954 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2955 // because cross-process subframe navigations still have a main frame
2956 // PageTransition.
2957 if (!use_site_per_process)
2958 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552959 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122960 }
2961
[email protected]a1b99262013-12-27 21:56:222962 // When using --site-per-process, look up the FrameTreeNode ID that the
2963 // renderer-specific frame ID corresponds to.
2964 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2965 if (use_site_per_process) {
2966 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2967 if (source_node)
2968 frame_tree_node_id = source_node->frame_tree_node_id();
2969
2970 // TODO(creis): In the short term, cross-process subframe navigations are
2971 // happening in the pending RenderViewHost's top-level frame. (We need to
2972 // both mirror the frame tree and get the navigation to occur in the correct
2973 // subframe to fix this.) Until then, we should check whether we have a
2974 // pending NavigationEntry with a frame ID and if so, treat the
2975 // cross-process "main frame" navigation as a subframe navigation. This
2976 // limits us to a single cross-process subframe per RVH, and it affects
2977 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2978 // OnDidFinishLoad.
2979 NavigationEntryImpl* pending_entry =
2980 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2981 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2982 if (pending_entry &&
2983 pending_entry->frame_tree_node_id() != -1 &&
2984 pending_entry->frame_tree_node_id() != root_ftn_id) {
2985 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2986 frame_tree_node_id = pending_entry->frame_tree_node_id();
2987 }
2988 }
2989
[email protected]e3d92a7f2013-01-10 02:35:052990 if (PageTransitionIsMainFrame(params.transition)) {
2991 // When overscroll navigation gesture is enabled, a screenshot of the page
2992 // in its current state is taken so that it can be used during the
2993 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362994 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052995 // WebContents::GetRenderViewHost to return the new host, instead of the one
2996 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482997 if (delegate_ && delegate_->CanOverscrollContent())
2998 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052999
[email protected]a1b99262013-12-27 21:56:223000 if (!use_site_per_process)
3001 GetRenderManager()->DidNavigateMainFrame(rvh);
3002 }
3003
3004 // When using --site-per-process, we notify the RFHM for all navigations,
3005 // not just main frame navigations.
3006 if (use_site_per_process) {
3007 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
3008 // TODO(creis): Rename to DidNavigateFrame.
3009 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:053010 }
[email protected]8030f012009-09-25 18:09:373011
[email protected]434f69f2012-02-06 21:56:523012 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:253013 // assigning a site is not necessary for this URL. In that case, the
3014 // SiteInstance can still be considered unused until a navigation to a real
3015 // page.
[email protected]434f69f2012-02-06 21:56:523016 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:253017 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:333018 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:523019 }
[email protected]420ae012009-04-24 05:16:323020
3021 // Need to update MIME type here because it's referred to in
3022 // UpdateNavigationCommands() called by RendererDidNavigate() to
3023 // determine whether or not to enable the encoding menu.
3024 // It's updated only for the main frame. For a subframe,
3025 // RenderView::UpdateURL does not set params.contents_mime_type.
3026 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
3027 // TODO(jungshik): Add a test for the encoding menu to avoid
3028 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:213029 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:323030 contents_mime_type_ = params.contents_mime_type;
3031
[email protected]8ff00d72012-10-23 19:12:213032 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:223033 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:393034
[email protected]1ae93fb2013-06-14 03:38:563035 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
3036 // us estimate our process count for implementing OOP iframes.
3037 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:553038 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:563039
[email protected]a9c0bfe2010-09-17 08:35:223040 // Send notification about committed provisional loads. This notification is
3041 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
3042 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:213043 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:073044 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
3045 // that is not recorded in the navigation history. For the purpose of
3046 // tracking navigation events, we treat this event as a sub frame navigation
3047 // event.
3048 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:213049 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:223050 // Whether or not a page transition was triggered by going backward or
3051 // forward in the history is only stored in the navigation controller's
3052 // entry list.
3053 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:273054 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:213055 PAGE_TRANSITION_FORWARD_BACK)) {
3056 transition_type = PageTransitionFromInt(
3057 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:223058 }
[email protected]0d60f0192011-04-14 12:40:103059 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:253060 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:443061 DidCommitProvisionalLoadForFrame(
3062 params.frame_id,
3063 params.frame_unique_name,
3064 is_main_frame,
3065 params.url,
3066 transition_type,
3067 rvh));
[email protected]a9c0bfe2010-09-17 08:35:223068 }
3069
[email protected]76543b92009-08-31 17:27:453070 if (!did_navigate)
3071 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:323072
3073 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
3074 // for the appropriate notification (best) or you can add it to
3075 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
3076 // necessary, please).
3077
3078 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:003079 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:323080 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:003081 if (delegate_) {
[email protected]6934a702011-12-20 00:04:513082 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:003083 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
3084 }
[email protected]93f230e02011-06-01 14:40:003085 }
[email protected]420ae012009-04-24 05:16:323086 DidNavigateAnyFramePostCommit(rvh, details, params);
3087}
3088
[email protected]b172aee2012-04-10 17:05:263089void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3090 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043091 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153092 // Ensure that this state update comes from either the active RVH or one of
3093 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413094 // TODO(nasko): This should go through RenderFrameHost.
3095 // TODO(creis): We can't update state for cross-process subframes until we
3096 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3097 if (rvh != GetRenderViewHost() &&
3098 !GetRenderManager()->IsRVHOnSwappedOutList(
3099 static_cast<RenderViewHostImpl*>(rvh)))
3100 return;
[email protected]420ae012009-04-24 05:16:323101
3102 // We must be prepared to handle state updates for any page, these occur
3103 // when the user is scrolling and entering form data, as well as when we're
3104 // leaving a page, in which case our state may have already been moved to
3105 // the next page. The navigation controller will look up the appropriate
3106 // NavigationEntry and update it when it is notified via the delegate.
3107
3108 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583109 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323110 if (entry_index < 0)
3111 return;
[email protected]10f417c52011-12-28 21:04:233112 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323113
[email protected]691aa2f2013-05-28 22:52:043114 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323115 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043116 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323117 controller_.NotifyEntryChanged(entry, entry_index);
3118}
3119
[email protected]b172aee2012-04-10 17:05:263120void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3121 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263122 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263123 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323124 // If we have a title, that's a pretty good indication that we've started
3125 // getting useful data.
3126 SetNotWaitingForResponse();
3127
[email protected]73eb2602012-02-09 19:50:553128 // Try to find the navigation entry, which might not be the current one.
3129 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233130 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583131 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093132
[email protected]73eb2602012-02-09 19:50:553133 // We can handle title updates when we don't have an entry in
3134 // UpdateTitleForEntry, but only if the update is from the current RVH.
3135 if (!entry && rvh != GetRenderViewHost())
3136 return;
3137
[email protected]a49e10b2011-08-01 23:57:463138 // TODO(evan): make use of title_direction.
3139 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093140 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323141 return;
3142
3143 // Broadcast notifications when the UI should be updated.
3144 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213145 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323146}
3147
[email protected]b172aee2012-04-10 17:05:263148void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3149 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313150 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323151}
3152
[email protected]b172aee2012-04-10 17:05:263153void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513154 if (delegate_)
3155 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323156}
3157
[email protected]b172aee2012-04-10 17:05:263158void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103159#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293160 // The UI may be in an event-tracking loop, such as between the
3161 // mouse-down and mouse-up in text selection or a button click.
3162 // Defer the close until after tracking is complete, so that we
3163 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293164 // TODO(shess): This could get more fine-grained. For instance,
3165 // closing a tab in another window while selecting text in the
3166 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103167 if (view_->IsEventTracking()) {
3168 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293169 return;
3170 }
[email protected]60780f412013-02-25 16:34:103171#endif
[email protected]07707302009-11-06 00:50:293172
[email protected]420ae012009-04-24 05:16:323173 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523174 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513175 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323176}
3177
[email protected]b172aee2012-04-10 17:05:263178void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523179 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513180 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283181
3182 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213183 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573184}
3185
[email protected]b172aee2012-04-10 17:05:263186void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513187 if (delegate_ && delegate_->IsPopupOrPanel(this))
3188 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323189}
3190
[email protected]8ff00d72012-10-23 19:12:213191void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593192 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323193}
3194
[email protected]8ff00d72012-10-23 19:12:213195void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323196 scoped_ptr<LoadNotificationDetails> details;
3197
[email protected]9595fd82013-04-19 21:28:493198 // Use the last committed entry rather than the active one, in case a
3199 // pending entry has been created.
3200 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3201
[email protected]420ae012009-04-24 05:16:323202 // An entry may not exist for a stop when loading an initial blank page or
3203 // if an iframe injected by script into a blank page finishes loading.
3204 if (entry) {
[email protected]420ae012009-04-24 05:16:323205 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3206
3207 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513208 entry->GetVirtualURL(),
3209 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323210 elapsed,
3211 &controller_,
3212 controller_.GetCurrentEntryIndex()));
3213 }
3214
[email protected]91621872013-10-08 04:04:593215 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323216}
3217
[email protected]b172aee2012-04-10 17:05:263218void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163219 controller_.DiscardNonCommittedEntries();
3220
3221 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213222 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163223}
3224
[email protected]b172aee2012-04-10 17:05:263225void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513226 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133227 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403228}
3229
[email protected]7cc78902012-12-06 02:32:263230void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393231 if (opener_) {
3232 // Clear our opener so that future cross-process navigations don't have an
3233 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103234 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393235 opener_ = NULL;
3236 }
[email protected]7cc78902012-12-06 02:32:263237
3238 // Notify all swapped out RenderViewHosts for this tab. This is important
3239 // in case we go back to them, or if another window in those processes tries
3240 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213241 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263242}
3243
[email protected]59167c22013-06-03 18:07:323244void WebContentsImpl::DidAccessInitialDocument() {
3245 // Update the URL display.
3246 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3247}
3248
[email protected]87717d0e2012-04-26 02:58:433249void WebContentsImpl::DocumentAvailableInMainFrame(
3250 RenderViewHost* render_view_host) {
3251 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3252 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103253}
3254
[email protected]b172aee2012-04-10 17:05:263255void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083256 RenderViewHost* render_view_host,
3257 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093258 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3259 DocumentOnLoadCompletedInMainFrame(page_id));
3260
3261 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213262 NotificationService::current()->Notify(
3263 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3264 Source<WebContents>(this),
3265 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083266}
3267
[email protected]196159d2012-05-04 17:26:543268void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3269 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213270 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263271 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183272 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523273 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303274 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543275 // If this came from a swapped out RenderViewHost, we only allow the request
3276 // if we are still in the same BrowsingInstance.
3277 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3278 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3279 return;
3280 }
3281
[email protected]4ad5d77d2011-12-03 02:00:483282 // Delegate to RequestTransferURL because this is just the generic
3283 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573284 // TODO(creis): Pass the redirect_chain into this method to support client
3285 // redirects. http://crbug.com/311721.
3286 std::vector<GURL> redirect_chain;
3287 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3288 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523289 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483290}
3291
[email protected]b172aee2012-04-10 17:05:263292void WebContentsImpl::RequestTransferURL(
3293 const GURL& url,
[email protected]f8872902013-10-30 03:18:573294 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213295 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573296 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263297 WindowOpenDisposition disposition,
3298 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183299 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523300 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303301 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203302 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123303 GURL dest_url(url);
3304 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553305 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123306 dest_url = GURL(kAboutBlankURL);
3307
[email protected]a1b99262013-12-27 21:56:223308 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3309 int64 frame_tree_node_id = -1;
3310 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3311 source_frame_id != -1) {
3312 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3313 if (source_node)
3314 frame_tree_node_id = source_node->frame_tree_node_id();
3315 }
[email protected]c80297782013-11-21 07:10:163316 OpenURLParams params(dest_url, referrer, source_frame_id,
3317 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573318 page_transition, true /* is_renderer_initiated */);
3319 if (redirect_chain.size() > 0)
3320 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553321 params.transferred_global_request_id = old_request_id;
3322 params.should_replace_current_entry = should_replace_current_entry;
3323 params.user_gesture = user_gesture;
3324
[email protected]fa944cb82013-11-15 17:51:213325 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573326 // Web UI pages sometimes want to override the page transition type for
3327 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3328 // automatically generated suggestions). We don't override other types
3329 // like TYPED because they have different implications (e.g., autocomplete).
3330 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213331 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553332
[email protected]e0112912011-02-02 22:54:353333 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163334 // want web sites to see a referrer of "chrome://blah" (and some
3335 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323336 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553337 params.referrer = Referrer();
3338
3339 // Navigations in Web UI pages count as browser-initiated navigations.
3340 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583341 }
[email protected]44d0930a2013-10-28 18:53:553342
3343 new_contents = OpenURL(params);
3344
[email protected]ae5184d62011-10-06 19:25:583345 if (new_contents) {
3346 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253347 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583348 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123349 dest_url,
[email protected]ae5184d62011-10-06 19:25:583350 referrer,
3351 disposition,
[email protected]44d0930a2013-10-28 18:53:553352 params.transition,
[email protected]ae5184d62011-10-06 19:25:583353 source_frame_id));
[email protected]420ae012009-04-24 05:16:323354 }
3355}
3356
[email protected]e1c3a552012-05-04 20:51:323357void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3358 // Tell the active RenderViewHost to run unload handlers and close, as long
3359 // as the request came from a RenderViewHost in the same BrowsingInstance.
3360 // In most cases, we receive this from a swapped out RenderViewHost.
3361 // It is possible to receive it from one that has just been swapped in,
3362 // in which case we might as well deliver the message anyway.
3363 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3364 GetRenderViewHost()->ClosePage();
3365}
3366
[email protected]f546640b2012-05-15 00:03:493367void WebContentsImpl::RouteMessageEvent(
3368 RenderViewHost* rvh,
3369 const ViewMsg_PostMessage_Params& params) {
3370 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363371 // came from a RenderViewHost in the same BrowsingInstance or if this
3372 // WebContents is dedicated to a browser plugin guest.
3373 // Note: This check means that an embedder could theoretically receive a
3374 // postMessage from anyone (not just its own guests). However, this is
3375 // probably not a risk for apps since other pages won't have references
3376 // to App windows.
3377 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3378 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493379 return;
3380
3381 ViewMsg_PostMessage_Params new_params(params);
3382
[email protected]0bc7f3542013-10-21 15:05:533383 if (!params.message_port_ids.empty()) {
3384 MessagePortMessageFilter* message_port_message_filter =
3385 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3386 ->message_port_message_filter();
3387 std::vector<int> new_routing_ids(params.message_port_ids.size());
3388 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3389 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3390 MessagePortService::GetInstance()->UpdateMessagePort(
3391 params.message_port_ids[i],
3392 message_port_message_filter,
3393 new_routing_ids[i]);
3394 }
3395 new_params.new_routing_ids = new_routing_ids;
3396 }
3397
[email protected]f546640b2012-05-15 00:03:493398 // If there is a source_routing_id, translate it to the routing ID for
3399 // the equivalent swapped out RVH in the target process. If we need
3400 // to create a swapped out RVH for the source tab, we create its opener
3401 // chain as well, since those will also be accessible to the target page.
3402 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3403 // Try to look up the WebContents for the source page.
3404 WebContentsImpl* source_contents = NULL;
3405 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3406 rvh->GetProcess()->GetID(), params.source_routing_id);
3407 if (source_rvh) {
3408 source_contents = static_cast<WebContentsImpl*>(
3409 source_rvh->GetDelegate()->GetAsWebContents());
3410 }
3411
3412 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363413 if (GetBrowserPluginGuest()) {
3414 // We create a swapped out RenderView for the embedder in the guest's
3415 // render process but we intentionally do not expose the embedder's
3416 // opener chain to it.
3417 new_params.source_routing_id =
3418 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3419 } else {
3420 new_params.source_routing_id =
3421 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3422 }
[email protected]f546640b2012-05-15 00:03:493423 } else {
3424 // We couldn't find it, so don't pass a source frame.
3425 new_params.source_routing_id = MSG_ROUTING_NONE;
3426 }
3427 }
3428
3429 // In most cases, we receive this from a swapped out RenderViewHost.
3430 // It is possible to receive it from one that has just been swapped in,
3431 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183432 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493433}
3434
[email protected]b172aee2012-04-10 17:05:263435void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343436 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263437 const base::string16& message,
3438 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323439 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213440 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323441 IPC::Message* reply_msg,
3442 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073443 // Suppress JavaScript dialogs when requested. Also suppress messages when
3444 // showing an interstitial as it's shown over the previous page and we don't
3445 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503446 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583447 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273448 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073449 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523450 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153451 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323452
3453 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213454 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433455 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153456 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3457 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433458 this,
3459 frame_url.GetOrigin(),
3460 accept_lang,
3461 javascript_message_type,
3462 message,
[email protected]51da7e32012-01-30 19:24:523463 default_prompt,
[email protected]b172aee2012-04-10 17:05:263464 base::Bind(&WebContentsImpl::OnDialogClosed,
3465 base::Unretained(this),
3466 rvh,
3467 reply_msg),
[email protected]51da7e32012-01-30 19:24:523468 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323469 }
[email protected]3ab9cb82011-06-03 18:02:073470
[email protected]6dd2f1e2013-09-11 15:06:013471 *did_suppress_message = suppress_this_message;
3472
[email protected]3ab9cb82011-06-03 18:02:073473 if (suppress_this_message) {
3474 // If we are suppressing messages, just reply as if the user immediately
3475 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263476 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073477 }
3478
[email protected]6dd2f1e2013-09-11 15:06:013479 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3480 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323481}
3482
[email protected]b172aee2012-04-10 17:05:263483void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263484 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263485 bool is_reload,
3486 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583487 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513488 if (delegate_)
3489 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073490
3491 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583492 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073493 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523494 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153495 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153496 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343497 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263498 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503499 return;
3500 }
[email protected]3ab9cb82011-06-03 18:02:073501
[email protected]7ab1e7d62009-10-14 23:32:013502 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153503 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3504 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323505 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263506 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523507 reply_msg));
[email protected]420ae012009-04-24 05:16:323508}
3509
[email protected]a796f202012-05-30 14:14:253510bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263511 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253512 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263513 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253514 if (!delegate_)
3515 return false;
3516 return delegate_->AddMessageToConsole(this, level, message, line_no,
3517 source_id);
3518}
3519
[email protected]b172aee2012-04-10 17:05:263520WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273521 // We want to base the page config off of the actual URL, rather than the
3522 // virtual URL.
3523 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3524 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003525 GURL url = controller_.GetActiveEntry()
3526 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153527
[email protected]fa944cb82013-11-15 17:51:213528 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323529}
3530
[email protected]0eba810b2012-10-18 03:19:363531int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213532 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413533 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3534 true, true);
[email protected]0eba810b2012-10-18 03:19:363535}
3536
[email protected]b172aee2012-04-10 17:05:263537void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273538 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253539 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223540
[email protected]ea114722012-03-12 01:11:253541 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173542 if (rdh) // NULL in unittests.
3543 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253544}
3545
[email protected]b172aee2012-04-10 17:05:263546void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443547 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253548 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443549}
3550
[email protected]b172aee2012-04-10 17:05:263551void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563552 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263553 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153554 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523555 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153556 return;
3557
[email protected]9f76c1e2012-03-05 15:15:583558 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3559
[email protected]e5fc1632011-08-08 07:51:533560 // Ignore renderer unresponsive event if debugger is attached to the tab
3561 // since the event may be a result of the renderer sitting on a breakpoint.
3562 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363563 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533564 return;
3565
[email protected]2e9d79f2013-08-16 05:45:563566 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323567 // Hang occurred while firing the beforeunload/unload handler.
3568 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583569 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323570
[email protected]fa944cb82013-11-15 17:51:213571 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323572 return;
3573
3574 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563575 // nothing we can do to recover. If the hang is in the beforeunload handler,
3576 // pretend the beforeunload listeners have all fired and allow the delegate
3577 // to continue closing; the user will not have the option of cancelling the
3578 // close. Otherwise, pretend the unload listeners have all fired and close
3579 // the tab.
3580 bool close = true;
3581 if (is_during_beforeunload) {
3582 delegate_->BeforeUnloadFired(this, true, &close);
3583 }
3584 if (close)
3585 Close(rvh);
[email protected]420ae012009-04-24 05:16:323586 return;
3587 }
3588
[email protected]9f76c1e2012-03-05 15:15:583589 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473590 return;
3591
[email protected]6934a702011-12-20 00:04:513592 if (delegate_)
3593 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323594}
3595
[email protected]b172aee2012-04-10 17:05:263596void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513597 if (delegate_)
3598 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323599}
3600
[email protected]b172aee2012-04-10 17:05:263601void WebContentsImpl::LoadStateChanged(
3602 const GURL& url,
3603 const net::LoadStateWithParam& load_state,
3604 uint64 upload_position,
3605 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323606 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563607 upload_position_ = upload_position;
3608 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503609 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213610 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303611 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213612 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323613 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463614 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213615 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463616 }
[email protected]420ae012009-04-24 05:16:323617}
3618
[email protected]b172aee2012-04-10 17:05:263619void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553620 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323621 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123622 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3623 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513624 if (delegate_)
3625 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093626 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323627}
3628
[email protected]58d5cfe2013-07-10 02:40:523629void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543630 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233631 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223632 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543633}
3634
[email protected]b172aee2012-04-10 17:05:263635void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103636 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213637 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263638 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3639 // here during container initialization and normal window size will be set
3640 // later. In case of tab duplication this resizing to 0x0 prevents setting
3641 // normal size later so just ignore it.
3642 if (!size.IsEmpty())
3643 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323644}
3645
[email protected]af905902013-10-01 21:38:513646void WebContentsImpl::CancelModalDialogsForRenderManager() {
3647 // We need to cancel modal dialogs when doing a process swap, since the load
3648 // deferrer would prevent us from swapping out.
3649 if (dialog_manager_)
3650 dialog_manager_->CancelActiveAndPendingDialogs(this);
3651}
3652
[email protected]7b712ee22013-10-03 00:57:283653void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3654 RenderViewHost* new_host) {
3655 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083656
3657 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003658 if (delegate_)
3659 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393660
[email protected]7b712ee22013-10-03 00:57:283661 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543662}
3663
[email protected]14392a52012-05-02 20:28:443664int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3665 SiteInstance* instance) {
3666 if (!opener_)
3667 return MSG_ROUTING_NONE;
3668
3669 // Recursively create RenderViews for anything else in the opener chain.
3670 return opener_->CreateOpenerRenderViews(instance);
3671}
3672
3673int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3674 int opener_route_id = MSG_ROUTING_NONE;
3675
3676 // If this tab has an opener, ensure it has a RenderView in the given
3677 // SiteInstance as well.
3678 if (opener_)
3679 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3680
[email protected]45a22ad2013-02-21 03:25:003681 // If any of the renderers (current, pending, or swapped out) for this
3682 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213683 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3684 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373685
[email protected]fa944cb82013-11-15 17:51:213686 if (GetRenderManager()->pending_render_view_host() &&
3687 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3688 instance)
3689 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003690
[email protected]fa944cb82013-11-15 17:51:213691 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373692 instance);
3693 if (rvh)
3694 return rvh->GetRoutingID();
3695
[email protected]14392a52012-05-02 20:28:443696 // Create a swapped out RenderView in the given SiteInstance if none exists,
3697 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413698 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3699 true, true);
[email protected]14392a52012-05-02 20:28:443700}
3701
[email protected]b172aee2012-04-10 17:05:263702NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193703 return GetController();
[email protected]3a3d47472010-07-15 21:03:543704}
3705
[email protected]b172aee2012-04-10 17:05:263706WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563707 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323708}
3709
[email protected]10f417c52011-12-28 21:04:233710NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263711 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323712 return controller_.GetLastCommittedEntry();
3713}
3714
[email protected]b172aee2012-04-10 17:05:263715bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443716 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033717 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443718 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323719 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523720
[email protected]420ae012009-04-24 05:16:323721 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443722 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213723 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323724
[email protected]74ce1ad2011-12-16 21:51:463725 // Make sure we use the correct starting page_id in the new RenderView.
3726 UpdateMaxPageIDIfNecessary(render_view_host);
3727 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583728 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463729
[email protected]9f76c1e2012-03-05 15:15:583730 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263731 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493732 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133733 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523734 return false;
[email protected]14392a52012-05-02 20:28:443735 }
[email protected]a4127722011-04-27 23:13:523736
[email protected]a220b5932013-09-21 03:47:443737#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503738 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3739 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443740 if (rwh_view) {
3741 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3742 render_widget_host->WasResized();
3743 }
[email protected]f8233cc2011-05-31 20:24:503744#endif
3745
[email protected]420ae012009-04-24 05:16:323746 return true;
3747}
3748
[email protected]7d244f12013-08-22 21:41:513749#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183750base::android::ScopedJavaLocalRef<jobject>
3751WebContentsImpl::GetJavaWebContents() {
3752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3753
3754 WebContentsAndroid* web_contents_android =
3755 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3756 if (!web_contents_android) {
3757 web_contents_android = new WebContentsAndroid(this);
3758 SetUserData(kWebContentsAndroidKey, web_contents_android);
3759 }
3760 return web_contents_android->GetJavaObject();
3761}
3762
[email protected]7d244f12013-08-22 21:41:513763bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3764 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3765 MSG_ROUTING_NONE);
3766}
3767#endif
3768
[email protected]b172aee2012-04-10 17:05:263769void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3770 IPC::Message* reply_msg,
3771 bool success,
[email protected]fcf75d42013-12-03 20:11:263772 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543773 if (is_showing_before_unload_dialog_ && !success) {
3774 // If a beforeunload dialog is canceled, we need to stop the throbber from
3775 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293776 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353777 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103778
[email protected]6d65a462013-06-21 21:29:123779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3780 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543781 }
3782 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583783 static_cast<RenderViewHostImpl*>(
3784 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543785}
3786
[email protected]b172aee2012-04-10 17:05:263787void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213788 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123789 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103790}
[email protected]f45d2a72010-03-08 23:28:353791
[email protected]b172aee2012-04-10 17:05:263792void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103793 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443794 // Can be NULL during tests.
3795 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213796 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363797}
[email protected]9f76c1e2012-03-05 15:15:583798
[email protected]1ac10dca2013-08-20 20:47:043799bool WebContentsImpl::IsHidden() {
3800 return capturer_count_ == 0 && !should_normally_be_visible_;
3801}
3802
[email protected]b0936d22013-11-28 06:47:363803RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213804 return frame_tree_.root()->render_manager();
3805}
3806
[email protected]b172aee2012-04-10 17:05:263807RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583808 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3809}
[email protected]7900bfdb2012-05-24 19:31:243810
[email protected]f8497342013-02-05 22:15:023811BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393812 return browser_plugin_guest_.get();
3813}
3814
[email protected]738f57a2013-06-29 21:06:543815void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3816 CHECK(!browser_plugin_guest_);
3817 browser_plugin_guest_.reset(guest);
3818}
3819
[email protected]f8497342013-02-05 22:15:023820BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393821 return browser_plugin_embedder_.get();
3822}
[email protected]8ff00d72012-10-23 19:12:213823
[email protected]8eb04562013-03-06 03:41:143824BrowserPluginGuestManager*
3825 WebContentsImpl::GetBrowserPluginGuestManager() const {
3826 return static_cast<BrowserPluginGuestManager*>(
3827 GetBrowserContext()->GetUserData(
3828 browser_plugin::kBrowserPluginGuestManagerKeyName));
3829}
3830
[email protected]d9030b82013-07-19 08:26:063831void WebContentsImpl::ClearPowerSaveBlockers(
3832 RenderViewHost* render_view_host) {
3833 STLDeleteValues(&power_save_blockers_[render_view_host]);
3834 power_save_blockers_.erase(render_view_host);
3835}
3836
3837void WebContentsImpl::ClearAllPowerSaveBlockers() {
3838 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3839 i != power_save_blockers_.end(); ++i)
3840 STLDeleteValues(&power_save_blockers_[i->first]);
3841 power_save_blockers_.clear();
3842}
3843
[email protected]dc0fd432013-08-27 15:29:213844gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3845 gfx::Size size;
3846 if (delegate_)
3847 size = delegate_->GetSizeForNewRenderView(this);
3848 if (size.IsEmpty())
3849 size = view_->GetContainerSize();
3850 return size;
3851}
3852
[email protected]9b159a52013-10-03 17:24:553853void WebContentsImpl::OnFrameRemoved(
3854 RenderViewHostImpl* render_view_host,
3855 int64 frame_id) {
3856 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3857 FrameDetached(render_view_host, frame_id));
3858}
3859
[email protected]8ff00d72012-10-23 19:12:213860} // namespace content