blob: aa5193d06ee7ab4ebb4194b89dc31aad5a895293 [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]44470a22013-01-24 01:21:54398 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46399 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
400 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55401 frame_tree_.SetFrameRemoveListener(
402 base::Bind(&WebContentsImpl::OnFrameRemoved,
403 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35404}
initial.commit09911bf2008-07-26 23:55:29405
[email protected]b172aee2012-04-10 17:05:26406WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32407 is_being_destroyed_ = true;
408
[email protected]d9030b82013-07-19 08:26:06409 ClearAllPowerSaveBlockers();
410
[email protected]b24b68a2012-09-24 21:57:26411 for (std::set<RenderWidgetHostImpl*>::iterator iter =
412 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
413 (*iter)->DetachDelegate();
414 }
415 created_widgets_.clear();
416
[email protected]3ab9cb82011-06-03 18:02:07417 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15418 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11419 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07420
[email protected]da8543762012-03-20 08:52:20421 if (color_chooser_)
422 color_chooser_->End();
423
[email protected]420ae012009-04-24 05:16:32424 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32425
[email protected]ca13a442012-04-17 14:00:12426 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21427 NotificationService::current()->Notify(
428 NOTIFICATION_WEB_CONTENTS_DESTROYED,
429 Source<WebContents>(this),
430 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32431
432 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07433#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32434 // If we still have a window handle, destroy it. GetNativeView can return
435 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06436 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52437 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58438 if (host && host->GetView())
439 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42440 }
[email protected]420ae012009-04-24 05:16:32441#endif
[email protected]7ab1e7d62009-10-14 23:32:01442
[email protected]fa944cb82013-11-15 17:51:21443 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27444 if (pending_rvh) {
445 FOR_EACH_OBSERVER(WebContentsObserver,
446 observers_,
447 RenderViewDeleted(pending_rvh));
448 }
449
450 FOR_EACH_OBSERVER(WebContentsObserver,
451 observers_,
[email protected]fa944cb82013-11-15 17:51:21452 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27453
[email protected]2db9bd72012-04-13 20:20:56454 FOR_EACH_OBSERVER(WebContentsObserver,
455 observers_,
456 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08457
[email protected]6934a702011-12-20 00:04:51458 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10459
460 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
461 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42462}
463
[email protected]d1198fd2012-08-13 22:50:19464WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59465 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19466 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03467 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59468 WebContentsImpl* new_contents = new WebContentsImpl(
469 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19470
[email protected]54944cde2012-12-09 09:24:59471 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19472 return new_contents;
473}
474
[email protected]b371a5652013-02-20 11:25:51475// static
[email protected]8eb04562013-03-06 03:41:14476BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36477 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53478 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54479 int guest_instance_id,
480 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39481 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39482
483 // This makes |new_contents| act as a guest.
484 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54485 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19486 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11487
[email protected]3de10bb32013-01-08 21:57:33488 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33489 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11490
[email protected]216be772013-01-25 00:22:27491 // We are instantiating a WebContents for browser plugin. Set its subframe bit
492 // to true.
493 static_cast<RenderViewHostImpl*>(
494 new_contents->GetRenderViewHost())->set_is_subframe(true);
495
[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)) {
1371 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1372 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1373 main_frame_route_id);
1374 return;
1375 }
1376
1377 // Create the new web contents. This will automatically create the new
1378 // WebContentsView. In the future, we may want to create the view separately.
1379 WebContentsImpl* new_contents =
1380 new WebContentsImpl(GetBrowserContext(),
1381 params.opener_suppressed ? NULL : this);
1382
[email protected]d1198fd2012-08-13 22:50:191383 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301384 partition_id,
[email protected]d1198fd2012-08-13 22:50:191385 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461386 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591387 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041388 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551389 if (!is_guest) {
1390 create_params.context = view_->GetNativeView();
1391 create_params.initial_size = view_->GetContainerSize();
1392 } else {
1393 // This makes |new_contents| act as a guest.
1394 // For more info, see comment above class BrowserPluginGuest.
1395 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1396 WebContentsImpl* new_contents_impl =
1397 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461398 BrowserPluginGuest::CreateWithOpener(instance_id,
1399 new_contents_impl->opener() != NULL,
1400 new_contents_impl,
1401 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551402 }
[email protected]1ac10dca2013-08-20 20:47:041403 if (params.disposition == NEW_BACKGROUND_TAB)
1404 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591405 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191406
[email protected]c4538072013-03-18 02:17:551407 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341408 // will be shown immediately).
1409 if (!params.opener_suppressed) {
1410 if (!is_guest) {
1411 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501412
[email protected]d70bea92013-04-05 04:23:341413 // TODO(brettw): It seems bogus that we have to call this function on the
1414 // newly created object and give it one of its own member variables.
1415 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1416 }
[email protected]bafe6cd2012-05-23 23:09:501417 // Save the created window associated with the route so we can show it
1418 // later.
1419 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1420 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101421 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501422 }
1423
1424 if (delegate_) {
1425 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131426 this, params.opener_frame_id, params.frame_name,
1427 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501428 }
1429
1430 if (params.opener_suppressed) {
1431 // When the opener is suppressed, the original renderer cannot access the
1432 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001433 bool was_blocked = false;
1434 if (delegate_) {
1435 gfx::Rect initial_pos;
1436 delegate_->AddNewContents(
1437 this, new_contents, params.disposition, initial_pos,
1438 params.user_gesture, &was_blocked);
1439 }
1440 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211441 OpenURLParams open_params(params.target_url,
1442 Referrer(),
1443 CURRENT_TAB,
1444 PAGE_TRANSITION_LINK,
1445 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301446 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001447 new_contents->OpenURL(open_params);
1448 }
[email protected]bafe6cd2012-05-23 23:09:501449 }
1450}
1451
[email protected]a8504022013-12-04 20:23:511452void WebContentsImpl::CreateNewWidget(int render_process_id,
1453 int route_id,
[email protected]180ef242013-11-07 06:50:461454 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511455 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501456}
1457
[email protected]a8504022013-12-04 20:23:511458void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1459 int route_id) {
1460 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501461}
1462
[email protected]a8504022013-12-04 20:23:511463void WebContentsImpl::CreateNewWidget(int render_process_id,
1464 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501465 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461466 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211467 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511468 // A message to create a new widget can only come from the active process for
1469 // this WebContentsImpl instance. If any other process sends the request,
1470 // it is invalid and the process must be terminated.
1471 if (process->GetID() != render_process_id) {
1472 base::ProcessHandle process_handle =
1473 RenderProcessHost::FromID(render_process_id)->GetHandle();
1474 if (process_handle != base::kNullProcessHandle) {
1475 RecordAction(
1476 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1477 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1478 }
1479 return;
1480 }
1481
[email protected]bafe6cd2012-05-23 23:09:501482 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041483 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261484 created_widgets_.insert(widget_host);
1485
[email protected]83918ec2013-01-10 15:37:191486 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1487 view_->CreateViewForPopupWidget(widget_host));
1488 if (!widget_view)
1489 return;
[email protected]bafe6cd2012-05-23 23:09:501490 if (!is_fullscreen) {
1491 // Popups should not get activated.
1492 widget_view->SetPopupType(popup_type);
1493 }
1494 // Save the created widget associated with the route so we can show it later.
1495 pending_widget_views_[route_id] = widget_view;
1496
1497#if defined(OS_MACOSX)
1498 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1499 // to allow it to survive the trip without being hosted.
1500 base::mac::NSObjectRetain(widget_view->GetNativeView());
1501#endif
1502}
1503
1504void WebContentsImpl::ShowCreatedWindow(int route_id,
1505 WindowOpenDisposition disposition,
1506 const gfx::Rect& initial_pos,
1507 bool user_gesture) {
1508 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001509 if (contents) {
1510 WebContentsDelegate* delegate = GetDelegate();
1511 if (delegate) {
1512 delegate->AddNewContents(
1513 this, contents, disposition, initial_pos, user_gesture, NULL);
1514 }
1515 }
[email protected]bafe6cd2012-05-23 23:09:501516}
1517
1518void WebContentsImpl::ShowCreatedWidget(int route_id,
1519 const gfx::Rect& initial_pos) {
1520 ShowCreatedWidget(route_id, false, initial_pos);
1521}
1522
1523void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1524 ShowCreatedWidget(route_id, true, gfx::Rect());
1525}
1526
1527void WebContentsImpl::ShowCreatedWidget(int route_id,
1528 bool is_fullscreen,
1529 const gfx::Rect& initial_pos) {
1530 if (delegate_)
1531 delegate_->RenderWidgetShowing();
1532
1533 RenderWidgetHostViewPort* widget_host_view =
1534 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1535 if (!widget_host_view)
1536 return;
[email protected]4aebbca2013-09-17 22:26:491537 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311538 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1539 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491540 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1541 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1542 delegate_->ToggleFullscreenModeForTab(this, true);
1543 } else {
1544 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491545 }
[email protected]4aebbca2013-09-17 22:26:491546 FOR_EACH_OBSERVER(WebContentsObserver,
1547 observers_,
1548 DidShowFullscreenWidget(route_id));
1549 if (!widget_host_view->HasFocus())
1550 widget_host_view->Focus();
1551 } else {
[email protected]f8497342013-02-05 22:15:021552 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491553 }
[email protected]89054502012-06-03 10:29:241554
1555 RenderWidgetHostImpl* render_widget_host_impl =
1556 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1557 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311558 // Only allow privileged mouse lock for fullscreen render widget, which is
1559 // used to implement Pepper Flash fullscreen.
1560 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501561
1562#if defined(OS_MACOSX)
1563 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1564 // properly embedded (or purposefully ignored) we can release the retain we
1565 // took in CreateNewWidget().
1566 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1567#endif
1568}
1569
1570WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1571 PendingContents::iterator iter = pending_contents_.find(route_id);
1572
1573 // Certain systems can block the creation of new windows. If we didn't succeed
1574 // in creating one, just return NULL.
1575 if (iter == pending_contents_.end()) {
1576 return NULL;
1577 }
1578
1579 WebContentsImpl* new_contents = iter->second;
1580 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101581 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501582
[email protected]d70bea92013-04-05 04:23:341583 // Don't initialize the guest WebContents immediately.
1584 if (new_contents->GetRenderProcessHost()->IsGuest())
1585 return new_contents;
1586
[email protected]bafe6cd2012-05-23 23:09:501587 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1588 !new_contents->GetRenderViewHost()->GetView())
1589 return NULL;
1590
1591 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1592 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1593 return new_contents;
1594}
1595
1596RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1597 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1598 if (iter == pending_widget_views_.end()) {
1599 DCHECK(false);
1600 return NULL;
1601 }
1602
1603 RenderWidgetHostView* widget_host_view = iter->second;
1604 pending_widget_views_.erase(route_id);
1605
1606 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1607 if (!widget_host->GetProcess()->HasConnection()) {
1608 // The view has gone away or the renderer crashed. Nothing to do.
1609 return NULL;
1610 }
1611
1612 return widget_host_view;
1613}
1614
[email protected]f56c7872013-06-18 12:31:571615void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501616 // Allow WebContentsDelegates to handle the context menu operation first.
1617 if (delegate_ && delegate_->HandleContextMenu(params))
1618 return;
1619
[email protected]f56c7872013-06-18 12:31:571620 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501621}
1622
[email protected]f13b4202012-06-12 23:53:231623void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091624 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211625 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231626 if (delegate_)
1627 delegate_->RequestMediaAccessPermission(this, request, callback);
1628 else
[email protected]b5f76742013-04-29 15:05:591629 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231630}
1631
[email protected]cc9200432013-07-23 23:02:401632SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1633 SiteInstance* instance) {
1634 return controller_.GetSessionStorageNamespace(instance);
1635}
1636
[email protected]9b159a52013-10-03 17:24:551637FrameTree* WebContentsImpl::GetFrameTree() {
1638 return &frame_tree_;
1639}
1640
[email protected]edc3af82013-12-12 21:24:071641void WebContentsImpl::OnShowValidationMessage(
1642 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291643 const base::string16& main_text,
1644 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071645 if (delegate_)
1646 delegate_->ShowValidationMessage(
1647 this, anchor_in_root_view, main_text, sub_text);
1648}
1649
1650void WebContentsImpl::OnHideValidationMessage() {
1651 if (delegate_)
1652 delegate_->HideValidationMessage(this);
1653}
1654
1655void WebContentsImpl::OnMoveValidationMessage(
1656 const gfx::Rect& anchor_in_root_view) {
1657 if (delegate_)
1658 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1659}
1660
[email protected]32deec62013-05-15 23:55:041661void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1662 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441663 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041664}
1665
[email protected]b172aee2012-04-10 17:05:261666void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231667 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331668 if (delegate_)
1669 delegate_->UpdatePreferredSize(this, pref_size);
1670}
1671
[email protected]b172aee2012-04-10 17:05:261672void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341673 if (delegate_)
1674 delegate_->ResizeDueToAutoResize(this, new_size);
1675}
1676
[email protected]b172aee2012-04-10 17:05:261677WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201678 if (!delegate_)
1679 return NULL;
[email protected]00c37fc2011-08-02 00:22:501680
[email protected]e5d549d2011-12-28 01:29:201681 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201682 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341683}
1684
[email protected]6b618e62012-08-16 12:59:181685bool WebContentsImpl::Send(IPC::Message* message) {
1686 if (!GetRenderViewHost()) {
1687 delete message;
1688 return false;
1689 }
1690
1691 return GetRenderViewHost()->Send(message);
1692}
1693
[email protected]b172aee2012-04-10 17:05:261694bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501695 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251696 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231697 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251698 reload_type);
[email protected]876bc832010-09-07 16:29:541699}
[email protected]96d185d2009-04-24 03:28:541700
[email protected]a86c0e962013-12-17 17:10:391701void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1702 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441703 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391704 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441705}
1706
[email protected]20ca0382013-02-28 19:50:071707void WebContentsImpl::AttachInterstitialPage(
1708 InterstitialPageImpl* interstitial_page) {
1709 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211710 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291711
1712 // Cancel any visible dialogs so that they don't interfere with the
1713 // interstitial.
1714 if (dialog_manager_)
1715 dialog_manager_->CancelActiveAndPendingDialogs(this);
1716
[email protected]20ca0382013-02-28 19:50:071717 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1718 DidAttachInterstitialPage());
1719}
1720
1721void WebContentsImpl::DetachInterstitialPage() {
1722 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211723 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1725 DidDetachInterstitialPage());
1726}
1727
[email protected]b172aee2012-04-10 17:05:261728bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231729 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501730 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031731 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1732
[email protected]19e81142011-10-03 16:19:401733 // The renderer will reject IPC messages with URLs longer than
1734 // this limit, so don't attempt to navigate with a longer URL.
[email protected]f16cc6782013-12-16 23:42:571735 if (entry.GetURL().spec().size() > GetMaxURLChars()) {
1736 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars()
[email protected]3adab1c2013-09-09 21:23:431737 << " characters.";
[email protected]19e81142011-10-03 16:19:401738 return false;
[email protected]3adab1c2013-09-09 21:23:431739 }
[email protected]19e81142011-10-03 16:19:401740
[email protected]a1b99262013-12-27 21:56:221741 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to
1742 // use when --site-per-process is used.
1743 RenderFrameHostManager* manager = GetRenderManager();
1744 if (entry.frame_tree_node_id() != -1 &&
1745 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) {
1746 int64 frame_tree_node_id = entry.frame_tree_node_id();
1747 manager = frame_tree_.FindByID(frame_tree_node_id)->render_manager();
1748 }
1749
[email protected]9f76c1e2012-03-05 15:15:581750 RenderViewHostImpl* dest_render_view_host =
[email protected]a1b99262013-12-27 21:56:221751 static_cast<RenderViewHostImpl*>(manager->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401752 if (!dest_render_view_host)
1753 return false; // Unable to create the desired render view host.
1754
[email protected]80a8fad2011-01-29 04:02:381755 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071756 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581757 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271758 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501759 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031760 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1761 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211762 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231763 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271764 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211765 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231766 CHECK(0);
1767 }
[email protected]54ec6472010-04-09 19:39:581768
[email protected]7bb761892012-07-20 09:32:471769 // Notify observers that we will navigate in this RV.
1770 FOR_EACH_OBSERVER(WebContentsObserver,
1771 observers_,
1772 AboutToNavigateRenderView(dest_render_view_host));
1773
[email protected]96d185d2009-04-24 03:28:541774 // Used for page load time metrics.
1775 current_load_start_ = base::TimeTicks::Now();
1776
1777 // Navigate in the desired RenderViewHost.
[email protected]a1b99262013-12-27 21:56:221778 // TODO(creis): As a temporary hack, we currently do cross-process subframe
1779 // navigations in a top-level frame of the new process. Thus, we don't yet
1780 // need to store the correct frame ID in ViewMsg_Navigate_Params.
[email protected]056de2d2009-06-26 16:41:341781 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271782 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471783 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341784 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541785
[email protected]36fc0392011-12-25 03:59:511786 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541787 // HACK!! This code suppresses javascript: URLs from being added to
1788 // session history, which is what we want to do for javascript: URLs that
1789 // do not generate content. What we really need is a message from the
1790 // renderer telling us that a new page was not created. The same message
1791 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351792 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541793 return false;
1794 }
1795
[email protected]3c9e1872010-11-18 16:17:491796 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391797 FOR_EACH_OBSERVER(
1798 WebContentsObserver,
1799 observers_,
1800 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541801
[email protected]09b29342011-06-24 19:18:481802 if (delegate_)
1803 delegate_->DidNavigateToPendingEntry(this);
1804
[email protected]d5f942ba2008-09-26 19:30:341805 return true;
1806}
1807
[email protected]b172aee2012-04-10 17:05:261808void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331809 const SiteInstance* site_instance,
1810 int history_length,
1811 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411812 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1813 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211814 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191815 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141816 return;
[email protected]9e1ad4b2011-08-14 16:49:191817 }
[email protected]9f76c1e2012-03-05 15:15:581818 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191819 if (!rvh) {
1820 NOTREACHED();
1821 return;
1822 }
[email protected]9f76c1e2012-03-05 15:15:581823 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191824 NOTREACHED();
1825 return;
1826 }
[email protected]6b618e62012-08-16 12:59:181827 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1828 history_length,
1829 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141830}
1831
[email protected]b172aee2012-04-10 17:05:261832void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271833 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211834 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541835 return;
1836 }
[email protected]9f76c1e2012-03-05 15:15:581837 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541838}
1839
[email protected]b172aee2012-04-10 17:05:261840bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211841 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541842}
1843
[email protected]b172aee2012-04-10 17:05:261844InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211845 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221846}
1847
[email protected]b172aee2012-04-10 17:05:261848bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161849 // WebKit creates Document object when MIME type is application/xhtml+xml,
1850 // so we also support this MIME type.
1851 return contents_mime_type_ == "text/html" ||
1852 contents_mime_type_ == "text/xml" ||
1853 contents_mime_type_ == "application/xhtml+xml" ||
1854 contents_mime_type_ == "text/plain" ||
1855 contents_mime_type_ == "text/css" ||
1856 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1857}
1858
[email protected]b172aee2012-04-10 17:05:261859void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591860 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161861 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551862 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011863 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141864 return;
[email protected]c7dd2f62011-07-18 15:57:591865 }
1866
1867 Stop();
1868
1869 // Create the save package and possibly prompt the user for the name to save
1870 // the page as. The user prompt is an asynchronous operation that runs on
1871 // another thread.
1872 save_package_ = new SavePackage(this);
1873 save_package_->GetSaveInfo();
1874}
1875
1876// Used in automated testing to bypass prompting the user for file names.
1877// Instead, the names and paths are hard coded rather than running them through
1878// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341879bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1880 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211881 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591882 // Stop the page from navigating.
1883 Stop();
1884
1885 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211886 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591887}
1888
[email protected]3c71576ce2013-07-23 02:00:011889void WebContentsImpl::SaveFrame(const GURL& url,
1890 const Referrer& referrer) {
1891 if (!GetURL().is_valid())
1892 return;
1893 bool is_main_frame = (url == GetURL());
1894
1895 DownloadManager* dlm =
1896 BrowserContext::GetDownloadManager(GetBrowserContext());
1897 if (!dlm)
1898 return;
1899 int64 post_id = -1;
1900 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271901 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011902 if (entry)
1903 post_id = entry->GetPostID();
1904 }
1905 scoped_ptr<DownloadUrlParameters> params(
1906 DownloadUrlParameters::FromWebContents(this, url));
1907 params->set_referrer(referrer);
1908 params->set_post_id(post_id);
1909 params->set_prefer_cache(true);
1910 if (post_id >= 0)
1911 params->set_method("POST");
1912 params->set_prompt(true);
1913 dlm->DownloadUrl(params.Pass());
1914}
1915
[email protected]b172aee2012-04-10 17:05:261916void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341917 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481918 const base::Callback<void(int64)>& callback) {
1919 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121920}
1921
[email protected]6286a372013-10-09 04:03:271922// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261923bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271924 NavigationEntryImpl* visible_entry =
1925 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1926 return (visible_entry != NULL &&
1927 visible_entry->site_instance() == GetSiteInstance() &&
1928 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321929}
1930
[email protected]b172aee2012-04-10 17:05:261931const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271932 return contents_mime_type_;
1933}
1934
[email protected]b172aee2012-04-10 17:05:261935bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271936 return notify_disconnection_;
1937}
1938
[email protected]b172aee2012-04-10 17:05:261939void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311940 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181941 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311945 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181946 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161947}
1948
[email protected]8ff00d72012-10-23 19:12:211949RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271950 return &renderer_preferences_;
1951}
1952
[email protected]e35ccd52012-05-23 16:22:471953void WebContentsImpl::Close() {
1954 Close(GetRenderViewHost());
1955}
1956
[email protected]cf200a562013-05-03 16:24:291957void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461958 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291959 if (browser_plugin_embedder_.get())
1960 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1961 screen_x, screen_y, operation);
1962 if (GetRenderViewHost())
1963 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1964 screen_x, screen_y, operation);
1965}
1966
1967void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1968 int screen_x, int screen_y) {
1969 if (browser_plugin_embedder_.get())
1970 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1971 screen_x, screen_y);
1972 if (GetRenderViewHost())
1973 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1974 screen_x, screen_y);
1975}
1976
[email protected]d60f3702013-12-26 16:30:241977void WebContentsImpl::DidGetResourceResponseStart(
1978 const ResourceRequestDetails& details) {
1979 controller_.ssl_manager()->DidStartResourceResponse(details);
1980
1981 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1982 DidGetResourceResponseStart(details));
1983
1984 // TODO(avi): Remove. http://crbug.com/170921
1985 NotificationService::current()->Notify(
1986 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1987 Source<WebContents>(this),
1988 Details<const ResourceRequestDetails>(&details));
1989}
1990
1991void WebContentsImpl::DidGetRedirectForResourceRequest(
1992 RenderViewHost* render_view_host,
1993 const ResourceRedirectDetails& details) {
1994 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1995
1996 FOR_EACH_OBSERVER(
1997 WebContentsObserver,
1998 observers_,
1999 DidGetRedirectForResourceRequest(render_view_host, details));
2000
2001 // TODO(avi): Remove. http://crbug.com/170921
2002 NotificationService::current()->Notify(
2003 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2004 Source<WebContents>(this),
2005 Details<const ResourceRedirectDetails>(&details));
2006}
2007
[email protected]b172aee2012-04-10 17:05:262008void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522009 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582010 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512011 if (delegate_)
2012 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292013 if (browser_plugin_embedder_.get())
2014 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342015}
2016
[email protected]e35ccd52012-05-23 16:22:472017void WebContentsImpl::UserGestureDone() {
2018 OnUserGesture();
2019}
2020
[email protected]b172aee2012-04-10 17:05:262021void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272022 closed_by_user_gesture_ = value;
2023}
2024
[email protected]b172aee2012-04-10 17:05:262025bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272026 return closed_by_user_gesture_;
2027}
2028
[email protected]b172aee2012-04-10 17:05:262029double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052030 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562031 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252032 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172033 return 0;
[email protected]b75b8292010-10-01 07:28:252034
2035 double zoom_level;
2036 if (temporary_zoom_settings_) {
2037 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582038 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252039 } else {
[email protected]2ae88d12011-10-14 09:11:192040 GURL url;
[email protected]6286a372013-10-09 04:03:272041 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192042 // Since zoom map is updated using rewritten URL, use rewritten URL
2043 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272044 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022045 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2046 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252047 }
[email protected]d0b8d092010-10-25 04:05:172048 return zoom_level;
2049}
[email protected]b75b8292010-10-01 07:28:252050
[email protected]b172aee2012-04-10 17:05:262051int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592052 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172053 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012054 // Calculate the zoom percent from the factor. Round up to the nearest whole
2055 // number.
[email protected]b75b8292010-10-01 07:28:252056 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492057 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252058 *enable_decrement = percent > minimum_zoom_percent_;
2059 *enable_increment = percent < maximum_zoom_percent_;
2060 return percent;
2061}
2062
[email protected]b172aee2012-04-10 17:05:262063void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502064 if (!delegate_)
2065 return;
2066
[email protected]6286a372013-10-09 04:03:272067 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2068 if (!entry)
[email protected]1788e772010-12-15 16:40:502069 return;
2070
[email protected]6286a372013-10-09 04:03:272071 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122072}
2073
[email protected]b172aee2012-04-10 17:05:262074void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042075 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272076 if (!delegate_)
2077 return;
2078
[email protected]691aa2f2013-05-28 22:52:042079 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272080}
2081
[email protected]b172aee2012-04-10 17:05:262082int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272083 return minimum_zoom_percent_;
2084}
2085
[email protected]b172aee2012-04-10 17:05:262086int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272087 return maximum_zoom_percent_;
2088}
2089
[email protected]b172aee2012-04-10 17:05:262090gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:232091 return preferred_size_;
2092}
2093
[email protected]b172aee2012-04-10 17:05:262094bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272095 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582096 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272097}
2098
[email protected]b172aee2012-04-10 17:05:262099bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442100 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502101}
2102
[email protected]cb805452013-05-22 15:16:212103void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182104 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212105 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202106}
2107
[email protected]cb805452013-05-22 15:16:212108void WebContentsImpl::DidEndColorChooser() {
2109 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2110 color_chooser_identifier_));
2111 color_chooser_.reset();
2112 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202113}
2114
[email protected]41225fe2013-03-29 05:32:022115int WebContentsImpl::DownloadImage(const GURL& url,
2116 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302117 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022118 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392119 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302120 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022121 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392122 return id;
2123}
2124
[email protected]b172aee2012-04-10 17:05:262125bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272126 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202127 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332128 return true;
2129 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272130}
2131
[email protected]b172aee2012-04-10 17:05:262132void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272133 if (delegate_)
2134 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212135}
2136
[email protected]52913802013-12-10 05:52:182137void WebContentsImpl::DidStartProvisionalLoad(
2138 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572139 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132140 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572141 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182142 const GURL& validated_url,
2143 bool is_error_page,
2144 bool is_iframe_srcdoc) {
2145 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572146 DidChangeLoadProgress(0);
2147
[email protected]0d60f0192011-04-14 12:40:102148 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252149 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132150 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2151 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182152 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542153
2154 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182155 FOR_EACH_OBSERVER(
2156 WebContentsObserver,
2157 observers_,
2158 ProvisionalChangeToMainFrameUrl(validated_url,
2159 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542160 }
2161}
2162
[email protected]52913802013-12-10 05:52:182163void WebContentsImpl::NotifyChangedNavigationState(
2164 InvalidateTypes changed_flags) {
2165 NotifyNavigationStateChanged(changed_flags);
2166}
2167
[email protected]400992b2012-06-14 00:03:542168void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212169 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542170 int32 page_id,
[email protected]400992b2012-06-14 00:03:542171 const GURL& source_url,
2172 const GURL& target_url) {
2173 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132174 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2175 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542176 GURL validated_source_url(source_url);
2177 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212178 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542179 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082180 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2181 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542182 NavigationEntry* entry;
2183 if (page_id == -1) {
2184 entry = controller_.GetPendingEntry();
2185 } else {
2186 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2187 page_id);
2188 }
2189 if (!entry || entry->GetURL() != validated_source_url)
2190 return;
2191
2192 // Notify observers about the provisional change in the main frame URL.
2193 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2194 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542195 render_view_host));
[email protected]724159a2010-12-30 01:11:182196}
2197
[email protected]54047eb52012-05-08 21:45:572198void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212199 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582200 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2201 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2202 << ", error_code: " << params.error_code
2203 << ", error_description: " << params.error_description
2204 << ", is_main_frame: " << params.is_main_frame
2205 << ", showing_repost_interstitial: " <<
2206 params.showing_repost_interstitial
2207 << ", frame_id: " << params.frame_id;
2208 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212209 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572210 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082211 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182212
[email protected]d7b175e2011-10-11 15:31:582213 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182214 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2215 // This means that the interstitial won't be torn down properly, which is
2216 // bad. But if we have an interstitial, go back to another tab type, and
2217 // then load the same interstitial again, we could end up getting the first
2218 // interstitial's "failed" message (as a result of the cancel) when we're on
2219 // the second one.
2220 //
2221 // We can't tell this apart, so we think we're tearing down the current page
2222 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362223 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182224 // out because of this problem.
2225 //
2226 // http://code.google.com/p/chromium/issues/detail?id=2855
2227 // Because this will not tear down the interstitial properly, if "back" is
2228 // back to another tab type, the interstitial will still be somewhat alive
2229 // in the previous tab type. If you navigate somewhere that activates the
2230 // tab with the interstitial again, you'll see a flash before the new load
2231 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272232 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182233 LOG(WARNING) << "Discarding message during interstitial.";
2234 return;
2235 }
2236
[email protected]fa944cb82013-11-15 17:51:212237 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182238 }
2239
[email protected]b12eb222013-09-10 00:11:482240 // Do not usually clear the pending entry if one exists, so that the user's
2241 // typed URL is not lost when a navigation fails or is aborted. However, in
2242 // cases that we don't show the pending entry (e.g., renderer-initiated
2243 // navigations in an existing tab), we don't keep it around. That prevents
2244 // spoofs on in-page navigations that don't go through
2245 // DidStartProvisionalLoadForFrame.
2246 // In general, we allow the view to clear the pending entry and typed URL if
2247 // the user requests (e.g., hitting Escape with focus in the address bar).
2248 // Note: don't touch the transient entry, since an interstitial may exist.
2249 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2250 controller_.DiscardPendingEntry();
2251
[email protected]d8c660432011-12-22 20:51:252252 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582253 observers_,
2254 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442255 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582256 params.is_main_frame,
2257 validated_url,
2258 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462259 params.error_description,
2260 render_view_host));
[email protected]724159a2010-12-30 01:11:182261}
2262
[email protected]b172aee2012-04-10 17:05:262263void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182264 const GURL& url,
[email protected]70435962011-08-02 20:13:282265 const std::string& security_info,
2266 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182267 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282268 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192269 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182270 cache.Increment();
2271
2272 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082273 int cert_id = 0;
2274 net::CertStatus cert_status = 0;
2275 int security_bits = -1;
2276 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122277 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212278 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122279 &security_bits, &connection_status,
2280 &signed_certificate_timestamp_ids);
2281 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212282 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002283 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2284 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182285
[email protected]b0f724c2013-09-05 04:21:132286 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2287
2288 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2289 DidLoadResourceFromMemoryCache(details));
2290
[email protected]8bfc8272013-09-09 20:10:532291 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2292 scoped_refptr<net::URLRequestContextGetter> request_context(
2293 resource_type == ResourceType::MEDIA ?
2294 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2295 GetRenderProcessHost()->GetID()) :
2296 GetBrowserContext()->GetRequestContextForRenderProcess(
2297 GetRenderProcessHost()->GetID()));
2298 BrowserThread::PostTask(
2299 BrowserThread::IO,
2300 FROM_HERE,
2301 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2302 }
[email protected]724159a2010-12-30 01:11:182303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212306 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182307 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192308 SSLManager::NotifySSLInternalStateChanged(
2309 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182310}
2311
[email protected]b172aee2012-04-10 17:05:262312void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022313 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582314 LOG(WARNING) << security_origin << " ran insecure content from "
2315 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212316 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412317 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212318 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182319 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412320 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192321 SSLManager::NotifySSLInternalStateChanged(
2322 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182323}
2324
[email protected]b172aee2012-04-10 17:05:262325void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442326 FOR_EACH_OBSERVER(
2327 WebContentsObserver, observers_,
2328 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182329}
2330
[email protected]b172aee2012-04-10 17:05:262331void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312332 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062333 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312334 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062335 GURL validated_url(url);
[email protected]a1b99262013-12-27 21:56:222336
2337 // --site-per-process mode has a short-term hack allowing cross-process
2338 // subframe pages to commit thinking they are top-level. Correct it here to
2339 // avoid confusing the observers.
2340 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2341 render_view_message_source_ != GetRenderViewHost())
2342 is_main_frame = false;
2343
[email protected]f114fa42013-12-06 17:06:442344 RenderProcessHost* render_process_host =
2345 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062346 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252347 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472348 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442349 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312350}
2351
[email protected]b172aee2012-04-10 17:05:262352void WebContentsImpl::OnDidFailLoadWithError(
2353 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062354 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262355 bool is_main_frame,
2356 int error_code,
[email protected]fcf75d42013-12-03 20:11:262357 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062358 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442359 RenderProcessHost* render_process_host =
2360 render_view_message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062361 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252362 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312363 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472364 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442365 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182366}
2367
[email protected]b172aee2012-04-10 17:05:262368void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262369 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232370 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252371 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262372 if (!entry)
2373 return;
2374 // Note that we don't call NavigationController::GotToOffset() as we don't
2375 // want to create a pending navigation entry (it might end up lingering
2376 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252377 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212378 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512379 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212380 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472381 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572382
2383 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2384 // it in now that we know. This allows us to find the entry when it commits.
2385 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232386 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332387 entry->set_site_instance(
2388 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572389 }
[email protected]216813952011-05-19 22:21:262390 }
2391}
2392
[email protected]b172aee2012-04-10 17:05:262393void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2394 int maximum_percent,
2395 bool remember) {
[email protected]216813952011-05-19 22:21:262396 minimum_zoom_percent_ = minimum_percent;
2397 maximum_zoom_percent_ = maximum_percent;
2398 temporary_zoom_settings_ = !remember;
2399}
2400
[email protected]b172aee2012-04-10 17:05:262401void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342402 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432403 if (!delegate_)
2404 return;
2405
[email protected]b9535422012-02-09 01:47:592406 ChildProcessSecurityPolicyImpl* policy =
2407 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222408 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592409 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212410}
2411
[email protected]b172aee2012-04-10 17:05:262412void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432413 if (delegate_)
2414 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202415}
2416
[email protected]b172aee2012-04-10 17:05:262417void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2418 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262419 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362420 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432421 if (!delegate_)
2422 return;
2423
[email protected]b9535422012-02-09 01:47:592424 ChildProcessSecurityPolicyImpl* policy =
2425 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322426 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592427 return;
[email protected]8f810632013-06-06 22:33:322428
[email protected]3a3b75a2012-06-01 08:38:362429 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202430}
2431
[email protected]b172aee2012-04-10 17:05:262432void WebContentsImpl::OnFindReply(int request_id,
2433 int number_of_matches,
2434 const gfx::Rect& selection_rect,
2435 int active_match_ordinal,
2436 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432437 if (delegate_) {
2438 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2439 active_match_ordinal, final_update);
2440 }
[email protected]b888919c2011-09-02 00:32:162441}
2442
[email protected]59363fc92012-09-05 03:46:312443#if defined(OS_ANDROID)
2444void WebContentsImpl::OnFindMatchRectsReply(
2445 int version,
2446 const std::vector<gfx::RectF>& rects,
2447 const gfx::RectF& active_rect) {
2448 if (delegate_)
2449 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2450}
[email protected]583418cc2013-01-17 14:01:102451
[email protected]1ff427972013-02-07 21:14:072452void WebContentsImpl::OnOpenDateTimeDialog(
2453 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092454 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2455 GetRenderViewHost(),
2456 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132457 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092458 value.minimum,
2459 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172460 value.step,
2461 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102462}
2463
[email protected]a794f3a2013-10-30 17:00:322464void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2465 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442466 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322467}
2468
[email protected]59363fc92012-09-05 03:46:312469#endif
2470
[email protected]f114fa42013-12-06 17:06:442471void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2472 const base::FilePath& path,
2473 bool is_hung) {
2474 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2475
2476 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2477 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2478}
2479
2480void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422481 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422483 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452484}
2485
[email protected]b172aee2012-04-10 17:05:262486void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2487 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102488 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102490 AppCacheAccessed(manifest_url, blocked_by_policy));
2491}
2492
[email protected]8bc5ff02013-11-29 06:34:032493void WebContentsImpl::OnOpenColorChooser(
2494 int color_chooser_id,
2495 SkColor color,
2496 const std::vector<ColorSuggestion>& suggestions) {
2497 ColorChooser* new_color_chooser =
2498 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212499 if (color_chooser_ == new_color_chooser)
2500 return;
2501 color_chooser_.reset(new_color_chooser);
2502 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202503}
2504
[email protected]b172aee2012-04-10 17:05:262505void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202506 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212507 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202508 color_chooser_->End();
2509}
2510
[email protected]b172aee2012-04-10 17:05:262511void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322512 SkColor color) {
[email protected]da8543762012-03-20 08:52:202513 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212514 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202515 color_chooser_->SetSelectedColor(color);
2516}
2517
[email protected]d0759f492012-04-19 22:50:502518// This exists for render views that don't have a WebUI, but do have WebUI
2519// bindings enabled.
2520void WebContentsImpl::OnWebUISend(const GURL& source_url,
2521 const std::string& name,
2522 const base::ListValue& args) {
2523 if (delegate_)
2524 delegate_->WebUISend(this, source_url, name, args);
2525}
2526
[email protected]d8415ad92012-08-23 14:40:502527void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442528 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502529 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342530 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162531 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442532 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162533 return;
[email protected]d8415ad92012-08-23 14:40:502534 }
2535
[email protected]8c8fc292012-11-23 18:57:162536 if (!delegate_->RequestPpapiBrokerPermission(
2537 this, url, plugin_path,
2538 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442539 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162540 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442541 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162542 }
[email protected]d8415ad92012-08-23 14:40:502543}
2544
[email protected]ea0309c2013-08-06 19:35:442545void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502546 bool result) {
[email protected]ea0309c2013-08-06 19:35:442547 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502548}
2549
[email protected]c4538072013-03-18 02:17:552550void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372551 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082552 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552553 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392554 // For more info, see comment above classes BrowserPluginEmbedder and
2555 // BrowserPluginGuest.
2556 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142557 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082558 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372559}
2560
[email protected]41225fe2013-03-29 05:32:022561void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392562 int id,
[email protected]749fadd2013-05-15 08:37:482563 int http_status_code,
[email protected]795c28972012-12-06 06:13:392564 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302565 const std::vector<SkBitmap>& bitmaps,
2566 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022567 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2568 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392569 // Currently WebContents notifies us of ANY downloads so that it is
2570 // possible to get here.
2571 return;
2572 }
2573 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302574 iter->second.Run(
2575 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392576 }
[email protected]41225fe2013-03-29 05:32:022577 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392578}
2579
2580void WebContentsImpl::OnUpdateFaviconURL(
2581 int32 page_id,
2582 const std::vector<FaviconURL>& candidates) {
2583 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2584 DidUpdateFaviconURL(page_id, candidates));
2585}
2586
[email protected]d9030b82013-07-19 08:26:062587void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2588 bool has_video,
2589 bool has_audio,
2590 bool is_playing) {
2591 // Chrome OS does its own detection of audio and video.
2592#if !defined(OS_CHROMEOS)
2593 if (is_playing) {
2594 scoped_ptr<PowerSaveBlocker> blocker;
2595 if (has_video) {
2596 blocker = PowerSaveBlocker::Create(
2597 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2598 "Playing video");
2599#if defined(OS_ANDROID)
2600 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382601 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062602#endif
2603 } else if (has_audio) {
2604 blocker = PowerSaveBlocker::Create(
2605 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2606 "Playing audio");
2607 }
2608
[email protected]f114fa42013-12-06 17:06:442609 if (blocker) {
2610 power_save_blockers_[render_view_message_source_][player_cookie] =
2611 blocker.release();
2612 }
[email protected]d9030b82013-07-19 08:26:062613 } else {
[email protected]f114fa42013-12-06 17:06:442614 delete power_save_blockers_[render_view_message_source_][player_cookie];
2615 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062616 }
2617#endif // !defined(OS_CHROMEOS)
2618}
2619
[email protected]9f268072013-11-07 00:02:152620void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2621 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2622 DidFirstVisuallyNonEmptyPaint(page_id));
2623}
[email protected]d9030b82013-07-19 08:26:062624
[email protected]e67ebf32013-02-13 11:07:192625void WebContentsImpl::DidChangeVisibleSSLState() {
2626 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2627 DidChangeVisibleSSLState());
2628}
2629
[email protected]17e286e2013-03-01 23:29:392630void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2632 BeforeFormRepostWarningShow());
2633}
2634
[email protected]ec6c05f2013-10-23 18:41:572635
2636void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2637 Activate();
2638 if (delegate_)
2639 delegate_->ShowRepostFormWarningDialog(this);
2640}
2641
[email protected]96d185d2009-04-24 03:28:542642// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592643// loading, or done loading.
2644void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2645 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262646 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542647 if (is_loading == is_loading_)
2648 return;
2649
2650 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262651 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2652 base::string16());
[email protected]96d185d2009-04-24 03:28:542653 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562654 upload_size_ = 0;
2655 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542656 }
2657
[email protected]fa944cb82013-11-15 17:51:212658 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542659
2660 is_loading_ = is_loading;
2661 waiting_for_response_ = is_loading;
2662
[email protected]6ebdc9b2010-09-27 16:55:572663 if (delegate_)
2664 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212665 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542666
[email protected]eab61442013-11-14 18:35:482667 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592668 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482669 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2670 "URL", url);
[email protected]91621872013-10-08 04:04:592671 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2672 DidStartLoading(render_view_host));
2673 } else {
[email protected]eab61442013-11-14 18:35:482674 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2675 "URL", url);
[email protected]91621872013-10-08 04:04:592676 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2677 DidStopLoading(render_view_host));
2678 }
[email protected]66798902013-10-01 18:40:162679
2680 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212681 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2682 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542683 if (details)
[email protected]8ff00d72012-10-23 19:12:212684 det = Details<LoadNotificationDetails>(details);
2685 NotificationService::current()->Notify(
2686 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542687}
2688
[email protected]b172aee2012-04-10 17:05:262689void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212690 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322691 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562692 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322693 // Clear the status bubble. This is a workaround for a bug where WebKit
2694 // doesn't let us know that the cursor left an element during a
2695 // transition (this is also why the mouse cursor remains as a hand after
2696 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2697 // clear the bubble when a user navigates to a named anchor in the same
2698 // page.
[email protected]36fc0392011-12-25 03:59:512699 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322700 }
2701
[email protected]a6e82fc2010-02-24 22:28:142702 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472703 // Once the main frame is navigated, we're no longer considered to have
2704 // displayed insecure content.
2705 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352706 SSLManager::NotifySSLInternalStateChanged(
2707 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172708 }
[email protected]ce5c4502009-05-06 16:46:112709
[email protected]3c9e1872010-11-18 16:17:492710 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252711 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042712 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322713}
2714
[email protected]b172aee2012-04-10 17:05:262715void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322716 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212717 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322718 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112719 // If we navigate off the page, close all JavaScript dialogs.
2720 if (dialog_manager_ && !details.is_in_page)
2721 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322722
[email protected]3c9e1872010-11-18 16:17:492723 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042725 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322726}
2727
[email protected]2f7b3c5a2013-06-21 04:59:252728bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292729 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2730 // still be used for a normal web site.
2731 if (url == GURL(kAboutBlankURL))
2732 return false;
2733
2734 // The embedder will then have the opportunity to determine if the URL
2735 // should "use up" the SiteInstance.
2736 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252737}
2738
[email protected]b172aee2012-04-10 17:05:262739void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462740 // If we are creating a RVH for a restored controller, then we need to make
2741 // sure the RenderView starts with a next_page_id_ larger than the number
2742 // of restored entries. This must be called before the RenderView starts
2743 // navigating (to avoid a race between the browser updating max_page_id and
2744 // the renderer updating next_page_id_). Because of this, we only call this
2745 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562746 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582747 if (max_restored_page_id >
2748 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2749 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2750 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322751}
2752
[email protected]b172aee2012-04-10 17:05:262753bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262754 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322755 // For file URLs without a title, use the pathname instead. In the case of a
2756 // synthesized title, we don't want the update to count toward the "one set
2757 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262758 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322759 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512760 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242761 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322762 explicit_set = false; // Don't count synthetic titles toward the set limit.
2763 } else {
[email protected]acafd272011-07-26 17:35:572764 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322765 explicit_set = true;
2766 }
2767
[email protected]987fc3a2011-05-26 14:18:092768 // If a page is created via window.open and never navigated,
2769 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552770 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092771 if (entry) {
[email protected]36fc0392011-12-25 03:59:512772 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092773 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322774
[email protected]36fc0392011-12-25 03:59:512775 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092776 } else {
2777 if (page_title_when_no_navigation_entry_ == final_title)
2778 return false; // Nothing changed, don't bother.
2779
2780 page_title_when_no_navigation_entry_ = final_title;
2781 }
[email protected]420ae012009-04-24 05:16:322782
[email protected]420ae012009-04-24 05:16:322783 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232784 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322785
[email protected]66798902013-10-01 18:40:162786 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532787 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162788
2789 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212790 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462791 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212792 NotificationService::current()->Notify(
2793 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2794 Source<WebContents>(this),
2795 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042796
[email protected]420ae012009-04-24 05:16:322797 return true;
2798}
2799
[email protected]7b712ee22013-10-03 00:57:282800void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2801 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322802 // After sending out a swap notification, we need to send a disconnect
2803 // notification so that clients that pick up a pointer to |this| can NULL the
2804 // pointer. See Bug 1230284.
2805 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282807 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112808
2809 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282810 std::pair<RenderViewHost*, RenderViewHost*> details =
2811 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212812 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282813 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212814 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282815 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392816
2817 // Ensure that the associated embedder gets cleared after a RenderViewHost
2818 // gets swapped, so we don't reuse the same embedder next time a
2819 // RenderViewHost is attached to this WebContents.
2820 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322821}
2822
[email protected]da7a7182013-09-06 08:11:112823// TODO(avi): Remove this entire function because this notification is already
2824// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262825void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322826 if (!notify_disconnection_)
2827 return;
2828
2829 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212830 NotificationService::current()->Notify(
2831 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2832 Source<WebContents>(this),
2833 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322834}
2835
[email protected]cbb1ef592013-06-05 19:49:462836void WebContentsImpl::NotifyNavigationEntryCommitted(
2837 const LoadCommittedDetails& load_details) {
2838 FOR_EACH_OBSERVER(
2839 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2840}
2841
[email protected]f114fa42013-12-06 17:06:442842bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2843 const IPC::Message& message) {
2844 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312845}
2846
[email protected]b849847b2013-12-10 21:57:582847void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2848 // Note this is only for subframes, the notification for the main frame
2849 // happens in RenderViewCreated.
2850 FOR_EACH_OBSERVER(WebContentsObserver,
2851 observers_,
2852 RenderFrameCreated(render_frame_host));
2853}
2854
2855void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2856 FOR_EACH_OBSERVER(WebContentsObserver,
2857 observers_,
2858 RenderFrameDeleted(render_frame_host));
2859}
2860
[email protected]b765deb2013-12-18 06:43:302861void WebContentsImpl::WorkerCrashed() {
2862 if (delegate_)
2863 delegate_->WorkerCrashed(this);
2864}
2865
[email protected]a86c0e962013-12-17 17:10:392866WebContents* WebContentsImpl::GetAsWebContents() {
2867 return this;
2868}
2869
[email protected]5a3bdf52012-05-24 15:12:572870RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2871 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322872}
2873
[email protected]8d3347f2009-07-09 22:00:212874RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262875WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212876 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212877}
2878
[email protected]8ff00d72012-10-23 19:12:212879RendererPreferences WebContentsImpl::GetRendererPrefs(
2880 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462881 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512882}
2883
[email protected]b172aee2012-04-10 17:05:262884gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172885 if (delegate_)
2886 return delegate_->GetRootWindowResizerRect();
2887 return gfx::Rect();
2888}
2889
[email protected]7a846df2012-09-20 19:17:392890void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272891 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392892 browser_plugin_embedder_.reset();
2893}
2894
[email protected]b172aee2012-04-10 17:05:262895void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442896 // Don't send notifications if we are just creating a swapped-out RVH for
2897 // the opener chain. These won't be used for view-source or WebUI, so it's
2898 // ok to return early.
2899 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2900 return;
2901
[email protected]86f98a22013-03-20 14:35:002902 if (delegate_)
2903 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082904
[email protected]8ff00d72012-10-23 19:12:212905 NotificationService::current()->Notify(
2906 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2907 Source<WebContents>(this),
2908 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322909
2910 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352911 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212912 if (GetRenderManager()->pending_web_ui())
2913 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322914
[email protected]6286a372013-10-09 04:03:272915 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332916 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322917 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182918 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582919 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322920 }
[email protected]0666aef2009-05-13 19:48:082921
[email protected]60780f412013-02-25 16:34:102922 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262923
2924 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252925 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582926
2927 // We tell the observers now instead of when the main RenderFrameHostImpl is
2928 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2929 // frame would be dropped because it's not created yet).
2930 RenderFrameHost* main_frame = GetMainFrame();
2931 FOR_EACH_OBSERVER(
2932 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322933}
2934
[email protected]b172aee2012-04-10 17:05:262935void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522936 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322937 // Don't notify the world, since this came from a renderer in the
2938 // background.
2939 return;
2940 }
2941
[email protected]da7a7182013-09-06 08:11:112942 notify_disconnection_ = true;
2943 // TODO(avi): Remove. http://crbug.com/170921
2944 NotificationService::current()->Notify(
2945 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2946 Source<WebContents>(this),
2947 NotificationService::NoDetails());
2948
[email protected]be1f56ab2011-12-22 06:55:312949 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232950 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302951
2952 // Restore the focus to the tab (otherwise the focus will be on the top
2953 // window).
[email protected]484ae5912010-09-29 19:16:142954 if (was_crashed && !FocusLocationBarByDefault() &&
2955 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062956 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142957 }
[email protected]32ded2212011-11-10 18:51:432958
[email protected]d8c660432011-12-22 20:51:252959 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322960}
2961
[email protected]ec6a7eb2013-04-22 17:34:222962void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2963 base::TerminationStatus status,
2964 int error_code) {
[email protected]151a63d2011-12-20 22:32:522965 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322966 // The pending page's RenderViewHost is gone.
2967 return;
2968 }
2969
[email protected]d9030b82013-07-19 08:26:062970 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592971 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322972 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232973 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312974 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322975
[email protected]d8c660432011-12-22 20:51:252976 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272977 observers_,
[email protected]58d5cfe2013-07-10 02:40:522978 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322979}
2980
[email protected]b172aee2012-04-10 17:05:262981void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062982 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212983 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252984 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062985}
2986
[email protected]b172aee2012-04-10 17:05:262987void WebContentsImpl::DidNavigate(
2988 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222989 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2990 ViewHostMsg_FrameNavigate_Params params(orig_params);
2991 bool use_site_per_process =
2992 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552993 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2994 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222995 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2996 // because cross-process subframe navigations still have a main frame
2997 // PageTransition.
2998 if (!use_site_per_process)
2999 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:553000 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:123001 }
3002
[email protected]a1b99262013-12-27 21:56:223003 // When using --site-per-process, look up the FrameTreeNode ID that the
3004 // renderer-specific frame ID corresponds to.
3005 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
3006 if (use_site_per_process) {
3007 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
3008 if (source_node)
3009 frame_tree_node_id = source_node->frame_tree_node_id();
3010
3011 // TODO(creis): In the short term, cross-process subframe navigations are
3012 // happening in the pending RenderViewHost's top-level frame. (We need to
3013 // both mirror the frame tree and get the navigation to occur in the correct
3014 // subframe to fix this.) Until then, we should check whether we have a
3015 // pending NavigationEntry with a frame ID and if so, treat the
3016 // cross-process "main frame" navigation as a subframe navigation. This
3017 // limits us to a single cross-process subframe per RVH, and it affects
3018 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
3019 // OnDidFinishLoad.
3020 NavigationEntryImpl* pending_entry =
3021 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
3022 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
3023 if (pending_entry &&
3024 pending_entry->frame_tree_node_id() != -1 &&
3025 pending_entry->frame_tree_node_id() != root_ftn_id) {
3026 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
3027 frame_tree_node_id = pending_entry->frame_tree_node_id();
3028 }
3029 }
3030
[email protected]e3d92a7f2013-01-10 02:35:053031 if (PageTransitionIsMainFrame(params.transition)) {
3032 // When overscroll navigation gesture is enabled, a screenshot of the page
3033 // in its current state is taken so that it can be used during the
3034 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:363035 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:053036 // WebContents::GetRenderViewHost to return the new host, instead of the one
3037 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:483038 if (delegate_ && delegate_->CanOverscrollContent())
3039 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:053040
[email protected]a1b99262013-12-27 21:56:223041 if (!use_site_per_process)
3042 GetRenderManager()->DidNavigateMainFrame(rvh);
3043 }
3044
3045 // When using --site-per-process, we notify the RFHM for all navigations,
3046 // not just main frame navigations.
3047 if (use_site_per_process) {
3048 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
3049 // TODO(creis): Rename to DidNavigateFrame.
3050 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:053051 }
[email protected]8030f012009-09-25 18:09:373052
[email protected]434f69f2012-02-06 21:56:523053 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:253054 // assigning a site is not necessary for this URL. In that case, the
3055 // SiteInstance can still be considered unused until a navigation to a real
3056 // page.
[email protected]434f69f2012-02-06 21:56:523057 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:253058 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:333059 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:523060 }
[email protected]420ae012009-04-24 05:16:323061
3062 // Need to update MIME type here because it's referred to in
3063 // UpdateNavigationCommands() called by RendererDidNavigate() to
3064 // determine whether or not to enable the encoding menu.
3065 // It's updated only for the main frame. For a subframe,
3066 // RenderView::UpdateURL does not set params.contents_mime_type.
3067 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
3068 // TODO(jungshik): Add a test for the encoding menu to avoid
3069 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:213070 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:323071 contents_mime_type_ = params.contents_mime_type;
3072
[email protected]8ff00d72012-10-23 19:12:213073 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:223074 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:393075
[email protected]1ae93fb2013-06-14 03:38:563076 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
3077 // us estimate our process count for implementing OOP iframes.
3078 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:553079 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:563080
[email protected]a9c0bfe2010-09-17 08:35:223081 // Send notification about committed provisional loads. This notification is
3082 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
3083 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:213084 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:073085 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
3086 // that is not recorded in the navigation history. For the purpose of
3087 // tracking navigation events, we treat this event as a sub frame navigation
3088 // event.
3089 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:213090 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:223091 // Whether or not a page transition was triggered by going backward or
3092 // forward in the history is only stored in the navigation controller's
3093 // entry list.
3094 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:273095 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:213096 PAGE_TRANSITION_FORWARD_BACK)) {
3097 transition_type = PageTransitionFromInt(
3098 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:223099 }
[email protected]0d60f0192011-04-14 12:40:103100 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:253101 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:443102 DidCommitProvisionalLoadForFrame(
3103 params.frame_id,
3104 params.frame_unique_name,
3105 is_main_frame,
3106 params.url,
3107 transition_type,
3108 rvh));
[email protected]a9c0bfe2010-09-17 08:35:223109 }
3110
[email protected]76543b92009-08-31 17:27:453111 if (!did_navigate)
3112 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:323113
3114 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
3115 // for the appropriate notification (best) or you can add it to
3116 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
3117 // necessary, please).
3118
3119 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:003120 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:323121 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:003122 if (delegate_) {
[email protected]6934a702011-12-20 00:04:513123 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:003124 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
3125 }
[email protected]93f230e02011-06-01 14:40:003126 }
[email protected]420ae012009-04-24 05:16:323127 DidNavigateAnyFramePostCommit(rvh, details, params);
3128}
3129
[email protected]b172aee2012-04-10 17:05:263130void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3131 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043132 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153133 // Ensure that this state update comes from either the active RVH or one of
3134 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413135 // TODO(nasko): This should go through RenderFrameHost.
3136 // TODO(creis): We can't update state for cross-process subframes until we
3137 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3138 if (rvh != GetRenderViewHost() &&
3139 !GetRenderManager()->IsRVHOnSwappedOutList(
3140 static_cast<RenderViewHostImpl*>(rvh)))
3141 return;
[email protected]420ae012009-04-24 05:16:323142
3143 // We must be prepared to handle state updates for any page, these occur
3144 // when the user is scrolling and entering form data, as well as when we're
3145 // leaving a page, in which case our state may have already been moved to
3146 // the next page. The navigation controller will look up the appropriate
3147 // NavigationEntry and update it when it is notified via the delegate.
3148
3149 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583150 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323151 if (entry_index < 0)
3152 return;
[email protected]10f417c52011-12-28 21:04:233153 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323154
[email protected]691aa2f2013-05-28 22:52:043155 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323156 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043157 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323158 controller_.NotifyEntryChanged(entry, entry_index);
3159}
3160
[email protected]b172aee2012-04-10 17:05:263161void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3162 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263163 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263164 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323165 // If we have a title, that's a pretty good indication that we've started
3166 // getting useful data.
3167 SetNotWaitingForResponse();
3168
[email protected]73eb2602012-02-09 19:50:553169 // Try to find the navigation entry, which might not be the current one.
3170 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233171 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583172 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093173
[email protected]73eb2602012-02-09 19:50:553174 // We can handle title updates when we don't have an entry in
3175 // UpdateTitleForEntry, but only if the update is from the current RVH.
3176 if (!entry && rvh != GetRenderViewHost())
3177 return;
3178
[email protected]a49e10b2011-08-01 23:57:463179 // TODO(evan): make use of title_direction.
3180 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093181 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323182 return;
3183
3184 // Broadcast notifications when the UI should be updated.
3185 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213186 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323187}
3188
[email protected]b172aee2012-04-10 17:05:263189void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3190 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313191 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323192}
3193
[email protected]b172aee2012-04-10 17:05:263194void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513195 if (delegate_)
3196 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323197}
3198
[email protected]b172aee2012-04-10 17:05:263199void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103200#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293201 // The UI may be in an event-tracking loop, such as between the
3202 // mouse-down and mouse-up in text selection or a button click.
3203 // Defer the close until after tracking is complete, so that we
3204 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293205 // TODO(shess): This could get more fine-grained. For instance,
3206 // closing a tab in another window while selecting text in the
3207 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103208 if (view_->IsEventTracking()) {
3209 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293210 return;
3211 }
[email protected]60780f412013-02-25 16:34:103212#endif
[email protected]07707302009-11-06 00:50:293213
[email protected]420ae012009-04-24 05:16:323214 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523215 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513216 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323217}
3218
[email protected]b172aee2012-04-10 17:05:263219void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523220 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513221 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283222
3223 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213224 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573225}
3226
[email protected]b172aee2012-04-10 17:05:263227void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513228 if (delegate_ && delegate_->IsPopupOrPanel(this))
3229 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323230}
3231
[email protected]8ff00d72012-10-23 19:12:213232void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593233 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323234}
3235
[email protected]8ff00d72012-10-23 19:12:213236void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323237 scoped_ptr<LoadNotificationDetails> details;
3238
[email protected]9595fd82013-04-19 21:28:493239 // Use the last committed entry rather than the active one, in case a
3240 // pending entry has been created.
3241 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3242
[email protected]420ae012009-04-24 05:16:323243 // An entry may not exist for a stop when loading an initial blank page or
3244 // if an iframe injected by script into a blank page finishes loading.
3245 if (entry) {
[email protected]420ae012009-04-24 05:16:323246 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3247
3248 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513249 entry->GetVirtualURL(),
3250 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323251 elapsed,
3252 &controller_,
3253 controller_.GetCurrentEntryIndex()));
3254 }
3255
[email protected]91621872013-10-08 04:04:593256 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323257}
3258
[email protected]b172aee2012-04-10 17:05:263259void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163260 controller_.DiscardNonCommittedEntries();
3261
3262 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213263 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163264}
3265
[email protected]b172aee2012-04-10 17:05:263266void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513267 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133268 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403269}
3270
[email protected]7cc78902012-12-06 02:32:263271void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393272 if (opener_) {
3273 // Clear our opener so that future cross-process navigations don't have an
3274 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103275 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393276 opener_ = NULL;
3277 }
[email protected]7cc78902012-12-06 02:32:263278
3279 // Notify all swapped out RenderViewHosts for this tab. This is important
3280 // in case we go back to them, or if another window in those processes tries
3281 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213282 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263283}
3284
[email protected]59167c22013-06-03 18:07:323285void WebContentsImpl::DidAccessInitialDocument() {
3286 // Update the URL display.
3287 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3288}
3289
[email protected]87717d0e2012-04-26 02:58:433290void WebContentsImpl::DocumentAvailableInMainFrame(
3291 RenderViewHost* render_view_host) {
3292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3293 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103294}
3295
[email protected]b172aee2012-04-10 17:05:263296void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083297 RenderViewHost* render_view_host,
3298 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093299 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3300 DocumentOnLoadCompletedInMainFrame(page_id));
3301
3302 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213303 NotificationService::current()->Notify(
3304 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3305 Source<WebContents>(this),
3306 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083307}
3308
[email protected]196159d2012-05-04 17:26:543309void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3310 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213311 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263312 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183313 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523314 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303315 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543316 // If this came from a swapped out RenderViewHost, we only allow the request
3317 // if we are still in the same BrowsingInstance.
3318 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3319 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3320 return;
3321 }
3322
[email protected]4ad5d77d2011-12-03 02:00:483323 // Delegate to RequestTransferURL because this is just the generic
3324 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573325 // TODO(creis): Pass the redirect_chain into this method to support client
3326 // redirects. http://crbug.com/311721.
3327 std::vector<GURL> redirect_chain;
3328 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3329 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523330 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483331}
3332
[email protected]b172aee2012-04-10 17:05:263333void WebContentsImpl::RequestTransferURL(
3334 const GURL& url,
[email protected]f8872902013-10-30 03:18:573335 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213336 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573337 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263338 WindowOpenDisposition disposition,
3339 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183340 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523341 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303342 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203343 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123344 GURL dest_url(url);
3345 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553346 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123347 dest_url = GURL(kAboutBlankURL);
3348
[email protected]a1b99262013-12-27 21:56:223349 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3350 int64 frame_tree_node_id = -1;
3351 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3352 source_frame_id != -1) {
3353 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3354 if (source_node)
3355 frame_tree_node_id = source_node->frame_tree_node_id();
3356 }
[email protected]c80297782013-11-21 07:10:163357 OpenURLParams params(dest_url, referrer, source_frame_id,
3358 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573359 page_transition, true /* is_renderer_initiated */);
3360 if (redirect_chain.size() > 0)
3361 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553362 params.transferred_global_request_id = old_request_id;
3363 params.should_replace_current_entry = should_replace_current_entry;
3364 params.user_gesture = user_gesture;
3365
[email protected]fa944cb82013-11-15 17:51:213366 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573367 // Web UI pages sometimes want to override the page transition type for
3368 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3369 // automatically generated suggestions). We don't override other types
3370 // like TYPED because they have different implications (e.g., autocomplete).
3371 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213372 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553373
[email protected]e0112912011-02-02 22:54:353374 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163375 // want web sites to see a referrer of "chrome://blah" (and some
3376 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323377 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553378 params.referrer = Referrer();
3379
3380 // Navigations in Web UI pages count as browser-initiated navigations.
3381 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583382 }
[email protected]44d0930a2013-10-28 18:53:553383
3384 new_contents = OpenURL(params);
3385
[email protected]ae5184d62011-10-06 19:25:583386 if (new_contents) {
3387 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253388 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583389 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123390 dest_url,
[email protected]ae5184d62011-10-06 19:25:583391 referrer,
3392 disposition,
[email protected]44d0930a2013-10-28 18:53:553393 params.transition,
[email protected]ae5184d62011-10-06 19:25:583394 source_frame_id));
[email protected]420ae012009-04-24 05:16:323395 }
3396}
3397
[email protected]e1c3a552012-05-04 20:51:323398void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3399 // Tell the active RenderViewHost to run unload handlers and close, as long
3400 // as the request came from a RenderViewHost in the same BrowsingInstance.
3401 // In most cases, we receive this from a swapped out RenderViewHost.
3402 // It is possible to receive it from one that has just been swapped in,
3403 // in which case we might as well deliver the message anyway.
3404 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3405 GetRenderViewHost()->ClosePage();
3406}
3407
[email protected]f546640b2012-05-15 00:03:493408void WebContentsImpl::RouteMessageEvent(
3409 RenderViewHost* rvh,
3410 const ViewMsg_PostMessage_Params& params) {
3411 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363412 // came from a RenderViewHost in the same BrowsingInstance or if this
3413 // WebContents is dedicated to a browser plugin guest.
3414 // Note: This check means that an embedder could theoretically receive a
3415 // postMessage from anyone (not just its own guests). However, this is
3416 // probably not a risk for apps since other pages won't have references
3417 // to App windows.
3418 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3419 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493420 return;
3421
3422 ViewMsg_PostMessage_Params new_params(params);
3423
[email protected]0bc7f3542013-10-21 15:05:533424 if (!params.message_port_ids.empty()) {
3425 MessagePortMessageFilter* message_port_message_filter =
3426 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3427 ->message_port_message_filter();
3428 std::vector<int> new_routing_ids(params.message_port_ids.size());
3429 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3430 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3431 MessagePortService::GetInstance()->UpdateMessagePort(
3432 params.message_port_ids[i],
3433 message_port_message_filter,
3434 new_routing_ids[i]);
3435 }
3436 new_params.new_routing_ids = new_routing_ids;
3437 }
3438
[email protected]f546640b2012-05-15 00:03:493439 // If there is a source_routing_id, translate it to the routing ID for
3440 // the equivalent swapped out RVH in the target process. If we need
3441 // to create a swapped out RVH for the source tab, we create its opener
3442 // chain as well, since those will also be accessible to the target page.
3443 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3444 // Try to look up the WebContents for the source page.
3445 WebContentsImpl* source_contents = NULL;
3446 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3447 rvh->GetProcess()->GetID(), params.source_routing_id);
3448 if (source_rvh) {
3449 source_contents = static_cast<WebContentsImpl*>(
3450 source_rvh->GetDelegate()->GetAsWebContents());
3451 }
3452
3453 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363454 if (GetBrowserPluginGuest()) {
3455 // We create a swapped out RenderView for the embedder in the guest's
3456 // render process but we intentionally do not expose the embedder's
3457 // opener chain to it.
3458 new_params.source_routing_id =
3459 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3460 } else {
3461 new_params.source_routing_id =
3462 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3463 }
[email protected]f546640b2012-05-15 00:03:493464 } else {
3465 // We couldn't find it, so don't pass a source frame.
3466 new_params.source_routing_id = MSG_ROUTING_NONE;
3467 }
3468 }
3469
3470 // In most cases, we receive this from a swapped out RenderViewHost.
3471 // It is possible to receive it from one that has just been swapped in,
3472 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183473 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493474}
3475
[email protected]b172aee2012-04-10 17:05:263476void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343477 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263478 const base::string16& message,
3479 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323480 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213481 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323482 IPC::Message* reply_msg,
3483 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073484 // Suppress JavaScript dialogs when requested. Also suppress messages when
3485 // showing an interstitial as it's shown over the previous page and we don't
3486 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503487 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583488 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273489 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073490 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523491 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153492 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323493
3494 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213495 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433496 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153497 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3498 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433499 this,
3500 frame_url.GetOrigin(),
3501 accept_lang,
3502 javascript_message_type,
3503 message,
[email protected]51da7e32012-01-30 19:24:523504 default_prompt,
[email protected]b172aee2012-04-10 17:05:263505 base::Bind(&WebContentsImpl::OnDialogClosed,
3506 base::Unretained(this),
3507 rvh,
3508 reply_msg),
[email protected]51da7e32012-01-30 19:24:523509 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323510 }
[email protected]3ab9cb82011-06-03 18:02:073511
[email protected]6dd2f1e2013-09-11 15:06:013512 *did_suppress_message = suppress_this_message;
3513
[email protected]3ab9cb82011-06-03 18:02:073514 if (suppress_this_message) {
3515 // If we are suppressing messages, just reply as if the user immediately
3516 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263517 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073518 }
3519
[email protected]6dd2f1e2013-09-11 15:06:013520 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3521 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323522}
3523
[email protected]b172aee2012-04-10 17:05:263524void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263525 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263526 bool is_reload,
3527 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583528 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513529 if (delegate_)
3530 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073531
3532 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583533 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073534 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523535 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153536 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153537 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343538 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263539 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503540 return;
3541 }
[email protected]3ab9cb82011-06-03 18:02:073542
[email protected]7ab1e7d62009-10-14 23:32:013543 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153544 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3545 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323546 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263547 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523548 reply_msg));
[email protected]420ae012009-04-24 05:16:323549}
3550
[email protected]a796f202012-05-30 14:14:253551bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263552 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253553 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263554 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253555 if (!delegate_)
3556 return false;
3557 return delegate_->AddMessageToConsole(this, level, message, line_no,
3558 source_id);
3559}
3560
[email protected]b172aee2012-04-10 17:05:263561WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273562 // We want to base the page config off of the actual URL, rather than the
3563 // virtual URL.
3564 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3565 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003566 GURL url = controller_.GetActiveEntry()
3567 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153568
[email protected]fa944cb82013-11-15 17:51:213569 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323570}
3571
[email protected]0eba810b2012-10-18 03:19:363572int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213573 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413574 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3575 true, true);
[email protected]0eba810b2012-10-18 03:19:363576}
3577
[email protected]b172aee2012-04-10 17:05:263578void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273579 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253580 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223581
[email protected]ea114722012-03-12 01:11:253582 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173583 if (rdh) // NULL in unittests.
3584 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253585}
3586
[email protected]b172aee2012-04-10 17:05:263587void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443588 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253589 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443590}
3591
[email protected]b172aee2012-04-10 17:05:263592void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563593 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263594 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153595 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523596 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153597 return;
3598
[email protected]9f76c1e2012-03-05 15:15:583599 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3600
[email protected]e5fc1632011-08-08 07:51:533601 // Ignore renderer unresponsive event if debugger is attached to the tab
3602 // since the event may be a result of the renderer sitting on a breakpoint.
3603 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363604 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533605 return;
3606
[email protected]2e9d79f2013-08-16 05:45:563607 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323608 // Hang occurred while firing the beforeunload/unload handler.
3609 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583610 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323611
[email protected]fa944cb82013-11-15 17:51:213612 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323613 return;
3614
3615 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563616 // nothing we can do to recover. If the hang is in the beforeunload handler,
3617 // pretend the beforeunload listeners have all fired and allow the delegate
3618 // to continue closing; the user will not have the option of cancelling the
3619 // close. Otherwise, pretend the unload listeners have all fired and close
3620 // the tab.
3621 bool close = true;
3622 if (is_during_beforeunload) {
3623 delegate_->BeforeUnloadFired(this, true, &close);
3624 }
3625 if (close)
3626 Close(rvh);
[email protected]420ae012009-04-24 05:16:323627 return;
3628 }
3629
[email protected]9f76c1e2012-03-05 15:15:583630 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473631 return;
3632
[email protected]6934a702011-12-20 00:04:513633 if (delegate_)
3634 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323635}
3636
[email protected]b172aee2012-04-10 17:05:263637void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513638 if (delegate_)
3639 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323640}
3641
[email protected]b172aee2012-04-10 17:05:263642void WebContentsImpl::LoadStateChanged(
3643 const GURL& url,
3644 const net::LoadStateWithParam& load_state,
3645 uint64 upload_position,
3646 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323647 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563648 upload_position_ = upload_position;
3649 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503650 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213651 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303652 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213653 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323654 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463655 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213656 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463657 }
[email protected]420ae012009-04-24 05:16:323658}
3659
[email protected]b172aee2012-04-10 17:05:263660void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553661 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323662 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123663 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3664 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513665 if (delegate_)
3666 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093667 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323668}
3669
[email protected]58d5cfe2013-07-10 02:40:523670void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543671 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233672 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223673 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543674}
3675
[email protected]b172aee2012-04-10 17:05:263676void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103677 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213678 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263679 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3680 // here during container initialization and normal window size will be set
3681 // later. In case of tab duplication this resizing to 0x0 prevents setting
3682 // normal size later so just ignore it.
3683 if (!size.IsEmpty())
3684 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323685}
3686
[email protected]af905902013-10-01 21:38:513687void WebContentsImpl::CancelModalDialogsForRenderManager() {
3688 // We need to cancel modal dialogs when doing a process swap, since the load
3689 // deferrer would prevent us from swapping out.
3690 if (dialog_manager_)
3691 dialog_manager_->CancelActiveAndPendingDialogs(this);
3692}
3693
[email protected]7b712ee22013-10-03 00:57:283694void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3695 RenderViewHost* new_host) {
3696 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083697
3698 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003699 if (delegate_)
3700 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393701
[email protected]7b712ee22013-10-03 00:57:283702 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543703}
3704
[email protected]14392a52012-05-02 20:28:443705int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3706 SiteInstance* instance) {
3707 if (!opener_)
3708 return MSG_ROUTING_NONE;
3709
3710 // Recursively create RenderViews for anything else in the opener chain.
3711 return opener_->CreateOpenerRenderViews(instance);
3712}
3713
3714int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3715 int opener_route_id = MSG_ROUTING_NONE;
3716
3717 // If this tab has an opener, ensure it has a RenderView in the given
3718 // SiteInstance as well.
3719 if (opener_)
3720 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3721
[email protected]45a22ad2013-02-21 03:25:003722 // If any of the renderers (current, pending, or swapped out) for this
3723 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213724 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3725 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373726
[email protected]fa944cb82013-11-15 17:51:213727 if (GetRenderManager()->pending_render_view_host() &&
3728 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3729 instance)
3730 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003731
[email protected]fa944cb82013-11-15 17:51:213732 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373733 instance);
3734 if (rvh)
3735 return rvh->GetRoutingID();
3736
[email protected]14392a52012-05-02 20:28:443737 // Create a swapped out RenderView in the given SiteInstance if none exists,
3738 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413739 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3740 true, true);
[email protected]14392a52012-05-02 20:28:443741}
3742
[email protected]b172aee2012-04-10 17:05:263743NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193744 return GetController();
[email protected]3a3d47472010-07-15 21:03:543745}
3746
[email protected]b172aee2012-04-10 17:05:263747WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563748 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323749}
3750
[email protected]10f417c52011-12-28 21:04:233751NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263752 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323753 return controller_.GetLastCommittedEntry();
3754}
3755
[email protected]b172aee2012-04-10 17:05:263756bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443757 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033758 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443759 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323760 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523761
[email protected]420ae012009-04-24 05:16:323762 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443763 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213764 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323765
[email protected]74ce1ad2011-12-16 21:51:463766 // Make sure we use the correct starting page_id in the new RenderView.
3767 UpdateMaxPageIDIfNecessary(render_view_host);
3768 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583769 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463770
[email protected]9f76c1e2012-03-05 15:15:583771 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263772 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493773 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133774 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523775 return false;
[email protected]14392a52012-05-02 20:28:443776 }
[email protected]a4127722011-04-27 23:13:523777
[email protected]a220b5932013-09-21 03:47:443778#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503779 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3780 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443781 if (rwh_view) {
3782 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3783 render_widget_host->WasResized();
3784 }
[email protected]f8233cc2011-05-31 20:24:503785#endif
3786
[email protected]420ae012009-04-24 05:16:323787 return true;
3788}
3789
[email protected]7d244f12013-08-22 21:41:513790#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183791base::android::ScopedJavaLocalRef<jobject>
3792WebContentsImpl::GetJavaWebContents() {
3793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3794
3795 WebContentsAndroid* web_contents_android =
3796 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3797 if (!web_contents_android) {
3798 web_contents_android = new WebContentsAndroid(this);
3799 SetUserData(kWebContentsAndroidKey, web_contents_android);
3800 }
3801 return web_contents_android->GetJavaObject();
3802}
3803
[email protected]7d244f12013-08-22 21:41:513804bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3805 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3806 MSG_ROUTING_NONE);
3807}
3808#endif
3809
[email protected]b172aee2012-04-10 17:05:263810void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3811 IPC::Message* reply_msg,
3812 bool success,
[email protected]fcf75d42013-12-03 20:11:263813 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543814 if (is_showing_before_unload_dialog_ && !success) {
3815 // If a beforeunload dialog is canceled, we need to stop the throbber from
3816 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293817 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353818 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103819
[email protected]6d65a462013-06-21 21:29:123820 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3821 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543822 }
3823 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583824 static_cast<RenderViewHostImpl*>(
3825 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543826}
3827
[email protected]b172aee2012-04-10 17:05:263828void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213829 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123830 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103831}
[email protected]f45d2a72010-03-08 23:28:353832
[email protected]b172aee2012-04-10 17:05:263833void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103834 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443835 // Can be NULL during tests.
3836 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213837 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363838}
[email protected]9f76c1e2012-03-05 15:15:583839
[email protected]1ac10dca2013-08-20 20:47:043840bool WebContentsImpl::IsHidden() {
3841 return capturer_count_ == 0 && !should_normally_be_visible_;
3842}
3843
[email protected]b0936d22013-11-28 06:47:363844RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213845 return frame_tree_.root()->render_manager();
3846}
3847
[email protected]b172aee2012-04-10 17:05:263848RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583849 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3850}
[email protected]7900bfdb2012-05-24 19:31:243851
[email protected]f8497342013-02-05 22:15:023852BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393853 return browser_plugin_guest_.get();
3854}
3855
[email protected]738f57a2013-06-29 21:06:543856void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3857 CHECK(!browser_plugin_guest_);
3858 browser_plugin_guest_.reset(guest);
3859}
3860
[email protected]f8497342013-02-05 22:15:023861BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393862 return browser_plugin_embedder_.get();
3863}
[email protected]8ff00d72012-10-23 19:12:213864
[email protected]8eb04562013-03-06 03:41:143865BrowserPluginGuestManager*
3866 WebContentsImpl::GetBrowserPluginGuestManager() const {
3867 return static_cast<BrowserPluginGuestManager*>(
3868 GetBrowserContext()->GetUserData(
3869 browser_plugin::kBrowserPluginGuestManagerKeyName));
3870}
3871
[email protected]d9030b82013-07-19 08:26:063872void WebContentsImpl::ClearPowerSaveBlockers(
3873 RenderViewHost* render_view_host) {
3874 STLDeleteValues(&power_save_blockers_[render_view_host]);
3875 power_save_blockers_.erase(render_view_host);
3876}
3877
3878void WebContentsImpl::ClearAllPowerSaveBlockers() {
3879 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3880 i != power_save_blockers_.end(); ++i)
3881 STLDeleteValues(&power_save_blockers_[i->first]);
3882 power_save_blockers_.clear();
3883}
3884
[email protected]dc0fd432013-08-27 15:29:213885gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3886 gfx::Size size;
3887 if (delegate_)
3888 size = delegate_->GetSizeForNewRenderView(this);
3889 if (size.IsEmpty())
3890 size = view_->GetContainerSize();
3891 return size;
3892}
3893
[email protected]9b159a52013-10-03 17:24:553894void WebContentsImpl::OnFrameRemoved(
3895 RenderViewHostImpl* render_view_host,
3896 int64 frame_id) {
3897 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3898 FrameDetached(render_view_host, frame_id));
3899}
3900
[email protected]8ff00d72012-10-23 19:12:213901} // namespace content