blob: 457d9518dd53510884bebf23cfbfd99178720651 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1925#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]5c9250872012-01-30 17:24:0535#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4436#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5337#include "content/browser/message_port_message_filter.h"
38#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0639#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3040#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3241#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5042#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3343#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1144#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5845#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0346#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5647#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1448#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4249#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4450#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0251#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5152#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0253#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5754#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5855#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1156#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2057#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4458#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3659#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1760#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1461#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4662#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1563#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0064#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2765#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0066#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3767#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1468#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3269#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3470#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3871#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4272#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2573#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1074#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2175#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4876#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5477#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4978#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2079#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0380#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5781#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1682#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2983#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5384#include "net/http/http_cache.h"
85#include "net/http/http_transaction_factory.h"
86#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3487#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5688#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0189#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4190#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5291#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1892#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3193
[email protected]583418cc2013-01-17 14:01:1094#if defined(OS_ANDROID)
95#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3296#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:1897#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:3298#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0099#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10100#endif
101
[email protected]f66df822012-05-18 16:52:17102#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50103#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27104#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57105#endif
[email protected]3e45ba92009-02-20 21:09:00106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
[email protected]b172aee2012-04-10 17:05:26109// If a WebContentsImpl is told to navigate to a different web site (as
110// determined by SiteInstance), it will replace its current RenderViewHost with
111// a new RenderViewHost dedicated to the new SiteInstance. This works as
112// follows:
[email protected]420ae012009-04-24 05:16:32113//
[email protected]fc6c1872013-10-03 01:22:35114// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46115// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32116// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35117// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35120// that it has a pending cross-site request. We will check this on the IO
121// thread when deciding how to handle the response.
122// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46123// cancel all the pending logic. Otherwise we allow the pending RVH to send
124// the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35126// main resource load on the pending RVH. It creates a
127// CrossSiteResourceHandler to check whether a process swap is needed when
128// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46129// - When RDH receives a response, the BufferedResourceHandler determines
130// whether it is a download. If so, it sends a message to the new renderer
131// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26132// pending RVH remains until the next DidNavigate event for this
133// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32134// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35135// download, the CrossSiteResourceHandler checks whether a process swap is
136// needed (either because CrossSiteRequestManager has state for it or because
137// a transfer was needed for a redirect).
138// - If so, CrossSiteResourceHandler pauses the response to first run the old
139// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36140// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
141// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35142// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
143// to a new process is needed, based on the stored pending_nav_params_. (This
144// is independent of whether we started out with a cross-process navigation.)
145// - If not, it just tells the ResourceDispatcherHost to resume the response
146// to its current RenderViewHost.
147// - If so, it cancels the current pending RenderViewHost and sets up a new
148// navigation using RequestTransferURL. When the transferred request
149// arrives in the ResourceDispatcherHost, we transfer the response and
150// resume it.
[email protected]420ae012009-04-24 05:16:32151// - The pending renderer sends a FrameNavigate message that invokes the
152// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46153// pending RVH.
[email protected]b0936d22013-11-28 06:47:36154// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15155// the user goes back. The process only stays live if another tab is using
156// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32157
[email protected]8ff00d72012-10-23 19:12:21158namespace content {
[email protected]420ae012009-04-24 05:16:32159namespace {
160
[email protected]82114f52012-03-20 22:53:41161const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05162
[email protected]155c7f22013-12-09 17:07:18163#if defined(OS_ANDROID)
164const char kWebContentsAndroidKey[] = "web_contents_android";
165#endif // OS_ANDROID
166
[email protected]e4abd3b42013-11-12 18:28:47167base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46168g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
169
[email protected]795c28972012-12-06 06:13:39170static int StartDownload(content::RenderViewHost* rvh,
171 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29172 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30173 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02174 static int g_next_image_download_id = 0;
175 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
176 ++g_next_image_download_id,
177 url,
178 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30179 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02180 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39181}
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21184 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50185 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16186 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47189 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23191 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
192 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47193 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16194 break; // Fall through to rest of function.
195 }
[email protected]5e369672009-11-03 23:48:30196
[email protected]59246c572012-02-10 13:32:13197 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
198 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36199 if (entry.restore_type() ==
200 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13201 if (entry.GetHasPostData())
202 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02203 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13204 }
[email protected]5e369672009-11-03 23:48:30205
[email protected]2c5569662011-03-22 20:45:02206 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30207}
208
[email protected]10f417c52011-12-28 21:04:23209void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47210 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21211 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50212 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16213 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51214 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13215 params->should_clear_history_list = entry.should_clear_history_list();
[email protected]4972fc82013-11-19 04:33:42216 params->should_replace_current_entry = entry.should_replace_entry();
[email protected]60d6cca2013-04-30 08:47:13217 if (entry.should_clear_history_list()) {
218 // Set the history list related parameters to the same values a
219 // NavigationController would return before its first navigation. This will
220 // fully clear the RenderView's view of the session history.
221 params->pending_history_list_offset = -1;
222 params->current_history_list_offset = -1;
223 params->current_history_list_length = 0;
224 } else {
225 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
226 params->current_history_list_offset =
227 controller.GetLastCommittedEntryIndex();
228 params->current_history_list_length = controller.GetEntryCount();
229 }
[email protected]eaaba7dd2013-10-14 02:38:07230 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36231 if (!entry.GetBaseURLForDataURL().is_empty()) {
232 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
233 params->history_url_for_data_url = entry.GetVirtualURL();
234 }
[email protected]36fc0392011-12-25 03:59:51235 params->referrer = entry.GetReferrer();
236 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04237 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00238 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55239 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34240 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47241 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48242 params->transferred_request_child_id =
243 entry.transferred_global_request_id().child_id;
244 params->transferred_request_request_id =
245 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22246 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00247 // Avoid downloading when in view-source mode.
248 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44249 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07250 if (entry.GetBrowserInitiatedPostData()) {
251 params->browser_initiated_post_data.assign(
252 entry.GetBrowserInitiatedPostData()->front(),
253 entry.GetBrowserInitiatedPostData()->front() +
254 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23255 }
256
[email protected]f8872902013-10-30 03:18:57257 params->redirects = entry.redirect_chain();
258
[email protected]951a64832012-10-11 16:26:37259 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58260 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37261
[email protected]6c6b02d2011-09-02 03:36:47262 if (delegate)
263 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34264}
265
[email protected]8bfc8272013-09-09 20:10:53266void NotifyCacheOnIO(
267 scoped_refptr<net::URLRequestContextGetter> request_context,
268 const GURL& url,
269 const std::string& http_method) {
270 request_context->GetURLRequestContext()->http_transaction_factory()->
271 GetCache()->OnExternalCacheHit(url, http_method);
272}
273
[email protected]9b159a52013-10-03 17:24:55274// Helper function for retrieving all the sites in a frame tree.
275bool CollectSites(BrowserContext* context,
276 std::set<GURL>* sites,
277 FrameTreeNode* node) {
278 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
279 return true;
280}
281
[email protected]a86c0e962013-12-17 17:10:39282bool ForEachFrameInternal(
283 const base::Callback<void(RenderFrameHost*)>& on_frame,
284 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41285 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39286 return true;
287}
288
289void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
290 IPC::Message* message_copy = new IPC::Message(*message);
291 message_copy->set_routing_id(rfh->GetRoutingID());
292 rfh->Send(message_copy);
293}
294
[email protected]420ae012009-04-24 05:16:32295} // namespace
296
[email protected]54944cde2012-12-09 09:24:59297WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15298 return WebContentsImpl::CreateWithOpener(
299 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19300}
301
302WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59303 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30304 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59305 WebContentsImpl* new_contents = new WebContentsImpl(
306 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30307
308 for (SessionStorageNamespaceMap::const_iterator it =
309 session_storage_namespace_map.begin();
310 it != session_storage_namespace_map.end();
311 ++it) {
312 new_contents->GetController()
313 .SetSessionStorageNamespace(it->first, it->second.get());
314 }
315
[email protected]54944cde2012-12-09 09:24:59316 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19317 return new_contents;
[email protected]a81343d232011-12-27 07:39:20318}
[email protected]746d3052012-05-22 15:15:47319
[email protected]e4abd3b42013-11-12 18:28:47320void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46321 g_created_callbacks.Get().push_back(callback);
322}
323
[email protected]e4abd3b42013-11-12 18:28:47324void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46325 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
326 if (g_created_callbacks.Get().at(i).Equals(callback)) {
327 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
328 return;
329 }
330 }
331}
332
[email protected]299d7f12012-05-23 05:31:15333WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47334 return rvh->GetDelegate()->GetAsWebContents();
335}
336
[email protected]a86c0e962013-12-17 17:10:39337WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
338 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
339 if (!rfh_impl)
340 return NULL;
341 return rfh_impl->delegate()->GetAsWebContents();
342}
343
[email protected]7fff43e2013-05-21 20:21:10344// WebContentsImpl::DestructionObserver ----------------------------------------
345
346class WebContentsImpl::DestructionObserver : public WebContentsObserver {
347 public:
348 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
349 : WebContentsObserver(watched_contents),
350 owner_(owner) {
351 }
352
353 // WebContentsObserver:
354 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
355 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
356 }
357
358 private:
359 WebContentsImpl* owner_;
360
361 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
362};
363
[email protected]b172aee2012-04-10 17:05:26364// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32365
[email protected]b172aee2012-04-10 17:05:26366WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21367 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19368 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42369 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22370 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57371 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44372 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41373#if defined(OS_WIN) && defined(USE_AURA)
374 accessible_parent_(NULL),
375#endif
[email protected]6ea6bdf2013-12-06 13:35:01376 frame_tree_(new NavigatorImpl(&controller_, this),
377 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34378 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23379 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
380 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34381 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26382 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56383 upload_size_(0),
384 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47385 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55386 capturer_count_(0),
387 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57388 is_being_destroyed_(false),
389 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15390 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01391 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38392 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21393 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
394 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00395 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21396 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44397 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42398 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
399 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46400 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
401 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55402 frame_tree_.SetFrameRemoveListener(
403 base::Bind(&WebContentsImpl::OnFrameRemoved,
404 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35405}
initial.commit09911bf2008-07-26 23:55:29406
[email protected]b172aee2012-04-10 17:05:26407WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32408 is_being_destroyed_ = true;
409
[email protected]d9030b82013-07-19 08:26:06410 ClearAllPowerSaveBlockers();
411
[email protected]b24b68a2012-09-24 21:57:26412 for (std::set<RenderWidgetHostImpl*>::iterator iter =
413 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
414 (*iter)->DetachDelegate();
415 }
416 created_widgets_.clear();
417
[email protected]3ab9cb82011-06-03 18:02:07418 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15419 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11420 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07421
[email protected]da8543762012-03-20 08:52:20422 if (color_chooser_)
423 color_chooser_->End();
424
[email protected]420ae012009-04-24 05:16:32425 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32426
[email protected]ca13a442012-04-17 14:00:12427 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21428 NotificationService::current()->Notify(
429 NOTIFICATION_WEB_CONTENTS_DESTROYED,
430 Source<WebContents>(this),
431 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32432
433 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07434#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32435 // If we still have a window handle, destroy it. GetNativeView can return
436 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06437 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52438 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58439 if (host && host->GetView())
440 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42441 }
[email protected]420ae012009-04-24 05:16:32442#endif
[email protected]7ab1e7d62009-10-14 23:32:01443
[email protected]fa944cb82013-11-15 17:51:21444 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27445 if (pending_rvh) {
446 FOR_EACH_OBSERVER(WebContentsObserver,
447 observers_,
448 RenderViewDeleted(pending_rvh));
449 }
450
451 FOR_EACH_OBSERVER(WebContentsObserver,
452 observers_,
[email protected]fa944cb82013-11-15 17:51:21453 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27454
[email protected]2db9bd72012-04-13 20:20:56455 FOR_EACH_OBSERVER(WebContentsObserver,
456 observers_,
457 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08458
[email protected]6934a702011-12-20 00:04:51459 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10460
461 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
462 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42463}
464
[email protected]d1198fd2012-08-13 22:50:19465WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59466 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19467 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03468 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59469 WebContentsImpl* new_contents = new WebContentsImpl(
470 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19471
[email protected]54944cde2012-12-09 09:24:59472 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19473 return new_contents;
474}
475
[email protected]b371a5652013-02-20 11:25:51476// static
[email protected]8eb04562013-03-06 03:41:14477BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36478 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53479 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54480 int guest_instance_id,
481 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39482 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39483
484 // This makes |new_contents| act as a guest.
485 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54486 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19487 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11488
[email protected]3de10bb32013-01-08 21:57:33489 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33490 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11491
[email protected]216be772013-01-25 00:22:27492 // We are instantiating a WebContents for browser plugin. Set its subframe bit
493 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42494 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27495
[email protected]8eb04562013-03-06 03:41:14496 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39497}
498
[email protected]b0936d22013-11-28 06:47:36499RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21500 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28501}
502
[email protected]7bb761892012-07-20 09:32:47503bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
504 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44505 return OnMessageReceived(render_view_host, NULL, message);
506}
507
508bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
509 RenderFrameHost* render_frame_host,
510 const IPC::Message& message) {
511 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56512 if (GetWebUI() &&
513 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17514 return true;
[email protected]d2353452012-01-19 19:53:56515 }
[email protected]f82d57b52011-04-27 19:13:17516
[email protected]d8c660432011-12-22 20:51:25517 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
518 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10519 while ((observer = it.GetNext()) != NULL)
520 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53521 return true;
[email protected]403415a2011-01-10 18:57:53522
[email protected]c80725d52013-12-06 06:22:26523 // Message handlers should be aware of which RenderViewHost sent the
[email protected]f114fa42013-12-06 17:06:44524 // message, which is temporarily stored in render_view_message_source_.
525 render_view_message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18526 bool handled = true;
527 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26528 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44529 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
530 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18531 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
532 OnDidLoadResourceFromMemoryCache)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
534 OnDidDisplayInsecureContent)
535 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
536 OnDidRunInsecureContent)
537 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
538 OnDocumentLoadedInFrame)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26540 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
541 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25542 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26543 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21544 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20545 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
547 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16548 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10549 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20550 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
553 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50554 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50555 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
556 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55557 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
558 OnBrowserPluginMessage(message))
559 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
560 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02561 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
562 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10563#if defined(OS_ANDROID)
564 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
565 OnFindMatchRectsReply)
566 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
567 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32568 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
569 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10570#endif
[email protected]d9030b82013-07-19 08:26:06571 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15572 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
573 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07574 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
575 OnShowValidationMessage)
576 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
577 OnHideValidationMessage)
578 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
579 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18580 IPC_MESSAGE_UNHANDLED(handled = false)
581 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44582 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18583
584 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21585 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18586 GetRenderProcessHost()->ReceivedBadMessage();
587 }
588
589 return handled;
590}
591
[email protected]b172aee2012-04-10 17:05:26592void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18593 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21594 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43595 if (delegate_)
596 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18597}
598
[email protected]d1198fd2012-08-13 22:50:19599NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56600 return controller_;
601}
602
[email protected]d1198fd2012-08-13 22:50:19603const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56604 return controller_;
605}
606
[email protected]8ff00d72012-10-23 19:12:21607BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55608 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30609}
610
[email protected]b172aee2012-04-10 17:05:26611const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24612 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32613 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51614 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31615}
616
[email protected]a093ce02013-07-22 20:53:14617const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24618 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32619 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24620 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
621}
622
623const GURL& WebContentsImpl::GetLastCommittedURL() const {
624 // We may not have a navigation entry yet.
625 NavigationEntry* entry = controller_.GetLastCommittedEntry();
626 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
627}
628
[email protected]8ff00d72012-10-23 19:12:21629WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31630 return delegate_;
631}
632
[email protected]8ff00d72012-10-23 19:12:21633void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31634 // TODO(cbentzel): remove this debugging code?
635 if (delegate == delegate_)
636 return;
637 if (delegate_)
638 delegate_->Detach(this);
639 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08640 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31641 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08642 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00643 if (view_)
644 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08645 }
[email protected]be1f56ab2011-12-22 06:55:31646}
647
[email protected]8ff00d72012-10-23 19:12:21648RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21649 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41650 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16651}
652
[email protected]60eca4eb2013-12-06 00:02:16653RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41654 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16655}
656
[email protected]a86c0e962013-12-17 17:10:39657void WebContentsImpl::ForEachFrame(
658 const base::Callback<void(RenderFrameHost*)>& on_frame) {
659 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
660}
661
662void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
663 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
664 delete message;
665}
666
[email protected]b172aee2012-04-10 17:05:26667RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21668 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31669}
670
[email protected]a04c9d02012-11-14 21:04:34671void WebContentsImpl::GetRenderViewHostAtPosition(
672 int x,
673 int y,
674 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
675 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
676 if (embedder)
677 embedder->GetRenderViewHostAtPosition(x, y, callback);
678 else
679 callback.Run(GetRenderViewHost(), x, y);
680}
681
[email protected]bfcfa692013-02-07 06:17:02682WebContents* WebContentsImpl::GetEmbedderWebContents() const {
683 BrowserPluginGuest* guest = GetBrowserPluginGuest();
684 if (guest)
685 return guest->embedder_web_contents();
686 return NULL;
687}
688
689int WebContentsImpl::GetEmbeddedInstanceID() const {
690 BrowserPluginGuest* guest = GetBrowserPluginGuest();
691 if (guest)
692 return guest->instance_id();
693 return 0;
694}
695
[email protected]6b618e62012-08-16 12:59:18696int WebContentsImpl::GetRoutingID() const {
697 if (!GetRenderViewHost())
698 return MSG_ROUTING_NONE;
699
700 return GetRenderViewHost()->GetRoutingID();
701}
702
[email protected]44470a22013-01-24 01:21:54703int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
704 return fullscreen_widget_routing_id_;
705}
706
[email protected]b172aee2012-04-10 17:05:26707RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21708 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31709}
710
[email protected]f8497342013-02-05 22:15:02711RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
712 BrowserPluginGuest* guest = GetBrowserPluginGuest();
713 if (guest && guest->embedder_web_contents()) {
714 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
715 }
716 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
717}
718
[email protected]4aebbca2013-09-17 22:26:49719RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
720 const {
721 RenderWidgetHost* const widget_host =
722 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
723 GetFullscreenWidgetRoutingID());
724 return widget_host ? widget_host->GetView() : NULL;
725}
726
[email protected]8ff00d72012-10-23 19:12:21727WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31728 return view_.get();
729}
730
[email protected]8ff00d72012-10-23 19:12:21731WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56732 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03733 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
734 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22735 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58736 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22737 web_ui->SetController(controller);
738 return web_ui;
739 }
740
741 delete web_ui;
742 return NULL;
743}
744
[email protected]8ff00d72012-10-23 19:12:21745WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21746 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
747 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31748}
749
[email protected]8ff00d72012-10-23 19:12:21750WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21751 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34752}
753
[email protected]86ef6a392012-05-11 22:03:11754void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22755 if (GetUserAgentOverride() == override)
756 return;
757
758 renderer_preferences_.user_agent_override = override;
759
760 // Send the new override string to the renderer.
761 RenderViewHost* host = GetRenderViewHost();
762 if (host)
763 host->SyncRendererPrefs();
764
765 // Reload the page if a load is currently in progress to avoid having
766 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27767 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22768 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
769 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53770
771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
772 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11773}
774
775const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22776 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11777}
778
[email protected]c73a2282013-04-29 21:10:41779#if defined(OS_WIN) && defined(USE_AURA)
780void WebContentsImpl::SetParentNativeViewAccessible(
781gfx::NativeViewAccessible accessible_parent) {
782 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45783 if (GetRenderViewHost())
784 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41785}
786#endif
787
[email protected]fcf75d42013-12-03 20:11:26788const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55789 // Transient entries take precedence. They are used for interstitial pages
790 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23791 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08792 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21793 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30794 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23795 if (entry) {
[email protected]b5cca982011-05-26 04:42:08796 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23797 }
[email protected]fa944cb82013-11-15 17:51:21798 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
799 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58800 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54801 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32802 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54803 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35804 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26805 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54806 if (!title.empty())
807 return title;
808 }
809 }
810
811 // We use the title for the last committed entry rather than a pending
812 // navigation entry. For example, when the user types in a URL, we want to
813 // keep the old page's title until the new load has committed and we get a new
814 // title.
[email protected]96d185d2009-04-24 03:28:54815 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32816
[email protected]9eeafc012013-11-25 23:49:47817 // We make an exception for initial navigations.
818 if (controller_.IsInitialNavigation()) {
819 // We only want to use the title from the visible entry in one of two cases:
820 // 1. There's already a committed entry for an initial navigation, in which
821 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
822 // 2. The pending entry has been explicitly assigned a title to display.
823 //
824 // If there's no last committed entry and no assigned title, we should fall
825 // back to |page_title_when_no_navigation_entry_| rather than showing the
826 // URL.
827 if (entry ||
828 (controller_.GetVisibleEntry() &&
829 !controller_.GetVisibleEntry()->GetTitle().empty())) {
830 entry = controller_.GetVisibleEntry();
831 }
832 }
[email protected]59167c22013-06-03 18:07:32833
[email protected]45d0ef7f2011-01-05 13:46:23834 if (entry) {
[email protected]b5cca982011-05-26 04:42:08835 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23836 }
[email protected]987fc3a2011-05-26 14:18:09837
838 // |page_title_when_no_navigation_entry_| is finally used
839 // if no title cannot be retrieved.
840 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54841}
842
[email protected]b172aee2012-04-10 17:05:26843int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46844 return GetMaxPageIDForSiteInstance(GetSiteInstance());
845}
846
[email protected]b172aee2012-04-10 17:05:26847int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
848 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33849 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
850 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46851
[email protected]b6583592012-01-25 19:52:33852 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34853}
854
[email protected]b172aee2012-04-10 17:05:26855void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46856 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
857}
858
[email protected]b172aee2012-04-10 17:05:26859void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33860 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46861 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33862 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34863}
864
[email protected]ec6c05f2013-10-23 18:41:57865void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
866 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
867 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57868}
869
[email protected]b172aee2012-04-10 17:05:26870SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21871 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54872}
873
[email protected]b172aee2012-04-10 17:05:26874SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21875 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
876 GetRenderManager()->pending_render_view_host() :
877 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58878 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38879}
880
[email protected]b172aee2012-04-10 17:05:26881bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return waiting_for_response_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return load_state_;
891}
892
[email protected]fcf75d42013-12-03 20:11:26893const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return load_state_host_;
895}
896
[email protected]b172aee2012-04-10 17:05:26897uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return upload_size_;
899}
900
[email protected]b172aee2012-04-10 17:05:26901uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31902 return upload_position_;
903}
904
[email protected]1ae93fb2013-06-14 03:38:56905std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56906 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39907 frame_tree_.ForEach(base::Bind(&CollectSites,
908 base::Unretained(GetBrowserContext()),
909 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56910 return sites;
911}
912
[email protected]b172aee2012-04-10 17:05:26913const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return encoding_;
915}
916
[email protected]b172aee2012-04-10 17:05:26917bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return displayed_insecure_content_;
919}
920
[email protected]54597982013-02-06 01:59:55921void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25922 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55923 ++capturer_count_;
924 DVLOG(1) << "There are now " << capturer_count_
925 << " capturing(s) of WebContentsImpl@" << this;
926}
927
928void WebContentsImpl::DecrementCapturerCount() {
929 --capturer_count_;
930 DVLOG(1) << "There are now " << capturer_count_
931 << " capturing(s) of WebContentsImpl@" << this;
932 DCHECK_LE(0, capturer_count_);
933
[email protected]5a652232013-02-12 06:15:25934 if (is_being_destroyed_)
935 return;
936
[email protected]1ac10dca2013-08-20 20:47:04937 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55938 DVLOG(1) << "Executing delayed WasHidden().";
939 WasHidden();
940 }
[email protected]be1f56ab2011-12-22 06:55:31941}
942
[email protected]f2bd40812013-07-20 04:30:44943int WebContentsImpl::GetCapturerCount() const {
944 return capturer_count_;
945}
946
[email protected]b172aee2012-04-10 17:05:26947bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31948 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
949 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
950 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49951}
952
[email protected]b172aee2012-04-10 17:05:26953void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
954 int error_code) {
[email protected]443b80e2010-12-14 00:42:23955 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34956 return;
957
[email protected]443b80e2010-12-14 00:42:23958 crashed_status_ = status;
959 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21960 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34961}
962
[email protected]b172aee2012-04-10 17:05:26963base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31964 return crashed_status_;
965}
966
[email protected]b172aee2012-04-10 17:05:26967bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31968 return is_being_destroyed_;
969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34972 if (delegate_)
973 delegate_->NavigationStateChanged(this, changed_flags);
974}
975
[email protected]3e324142012-06-25 18:26:33976base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
977 return last_selected_time_;
978}
979
[email protected]9e2e4632012-07-27 16:38:41980void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54981 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04982 RenderWidgetHostViewPort* rwhv =
983 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16984 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29985 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43986#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16987 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43988#endif
989 }
[email protected]96d185d2009-04-24 03:28:54990
[email protected]5ac20162010-11-24 23:33:11991 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38992
[email protected]b9769d82012-02-10 00:23:59993 // The resize rect might have changed while this was inactive -- send the new
994 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58995 RenderViewHostImpl* rvh =
996 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59997 if (rvh) {
998 rvh->ResizeRectChanged(GetRootWindowResizerRect());
999 }
[email protected]96d185d2009-04-24 03:28:541000
[email protected]c0d9d5672013-10-09 07:38:031001 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1002
[email protected]54597982013-02-06 01:59:551003 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311004}
1005
[email protected]b172aee2012-04-10 17:05:261006void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551007 // If there are entities capturing screenshots or video (e.g., mirroring),
1008 // don't activate the "disable rendering" optimization.
1009 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521010 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551011 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261012 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521013 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331014 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521015 // calls us).
[email protected]c30585c2012-02-16 15:02:041016 RenderWidgetHostViewPort* rwhv =
1017 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161018 if (rwhv)
[email protected]68ef3962013-09-26 06:45:291019 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:541020 }
1021
[email protected]c0d9d5672013-10-09 07:38:031022 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1023
[email protected]54597982013-02-06 01:59:551024 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371025}
1026
[email protected]b172aee2012-04-10 17:05:261027bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311028 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271029 return WillNotifyDisconnection() &&
1030 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581031 !static_cast<RenderViewHostImpl*>(
1032 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311033}
1034
[email protected]b172aee2012-04-10 17:05:261035void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211036 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401037 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271038}
1039
[email protected]b172aee2012-04-10 17:05:261040WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441041 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451042 // We pass our own opener so that the cloned page can access it if it was
1043 // before.
[email protected]54944cde2012-12-09 09:24:591044 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451045 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591046 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191047 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221048 FOR_EACH_OBSERVER(WebContentsObserver,
1049 observers_,
1050 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271051 return tc;
1052}
1053
[email protected]14392a52012-05-02 20:28:441054void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211055 const NotificationSource& source,
1056 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441057 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211058 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1059 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501060 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1061 i != pending_widget_views_.end(); ++i) {
1062 if (host->GetView() == i->second) {
1063 pending_widget_views_.erase(i);
1064 break;
1065 }
1066 }
1067 break;
1068 }
[email protected]14392a52012-05-02 20:28:441069 default:
1070 NOTREACHED();
1071 }
1072}
1073
[email protected]ec6c05f2013-10-23 18:41:571074WebContents* WebContentsImpl::GetWebContents() {
1075 return this;
1076}
1077
[email protected]54944cde2012-12-09 09:24:591078void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211079 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361080 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211081 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431082 should_normally_be_visible_ = !params.initially_hidden;
1083
[email protected]fa944cb82013-11-15 17:51:211084 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041085 params.browser_context, params.site_instance, params.routing_id,
1086 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191087
[email protected]8ff00d72012-10-23 19:12:211088 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191089 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271090 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191091 CHECK(render_view_host_delegate_view_);
1092 } else {
[email protected]f8497342013-02-05 22:15:021093 WebContentsViewDelegate* delegate =
1094 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1095
[email protected]59383c782013-04-17 16:43:271096 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381097 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1098 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021099
[email protected]b5a40842012-11-28 15:26:111100 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381101 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431102 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111103 render_view_host_delegate_view_ = rv;
1104 view_.reset(rv);
1105 } else {
[email protected]f8497342013-02-05 22:15:021106 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111107 view_.reset(CreateWebContentsView(
1108 this, delegate, &render_view_host_delegate_view_));
1109 }
[email protected]d1198fd2012-08-13 22:50:191110 CHECK(render_view_host_delegate_view_);
1111 }
1112 CHECK(view_.get());
1113
[email protected]ed245db2012-12-18 08:00:451114 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591115 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191116
1117 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101118 if (opener_)
1119 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191120
1121 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211122 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1123 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441124#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191125 java_bridge_dispatcher_host_manager_.reset(
1126 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101127 date_time_chooser_.reset(new DateTimeChooserAndroid());
1128#endif
[email protected]d1198fd2012-08-13 22:50:191129}
1130
[email protected]7fff43e2013-05-21 20:21:101131void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1132 RemoveDestructionObserver(web_contents);
1133
[email protected]14392a52012-05-02 20:28:441134 // Clear the opener if it has been closed.
1135 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441136 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511137 return;
[email protected]14392a52012-05-02 20:28:441138 }
[email protected]ceee8cd2013-03-08 04:59:511139 // Clear a pending contents that has been closed before being shown.
1140 for (PendingContents::iterator iter = pending_contents_.begin();
1141 iter != pending_contents_.end();
1142 ++iter) {
1143 if (iter->second != web_contents)
1144 continue;
1145 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511146 return;
1147 }
1148 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441149}
1150
[email protected]7fff43e2013-05-21 20:21:101151void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1152 if (!ContainsKey(destruction_observers_, web_contents)) {
1153 destruction_observers_[web_contents] =
1154 new DestructionObserver(this, web_contents);
1155 }
1156}
1157
1158void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1159 DestructionObservers::iterator iter =
1160 destruction_observers_.find(web_contents);
1161 if (iter != destruction_observers_.end()) {
1162 delete destruction_observers_[web_contents];
1163 destruction_observers_.erase(iter);
1164 }
1165}
1166
[email protected]b172aee2012-04-10 17:05:261167void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311168 observers_.AddObserver(observer);
1169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311172 observers_.RemoveObserver(observer);
1173}
1174
[email protected]b172aee2012-04-10 17:05:261175void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341176 if (delegate_)
1177 delegate_->ActivateContents(this);
1178}
1179
[email protected]b172aee2012-04-10 17:05:261180void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121181 if (delegate_)
1182 delegate_->DeactivateContents(this);
1183}
1184
[email protected]b172aee2012-04-10 17:05:261185void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481186 if (delegate_)
1187 delegate_->LostCapture();
1188}
1189
[email protected]b24b68a2012-09-24 21:57:261190void WebContentsImpl::RenderWidgetDeleted(
1191 RenderWidgetHostImpl* render_widget_host) {
1192 if (is_being_destroyed_) {
1193 // |created_widgets_| might have been destroyed.
1194 return;
1195 }
1196
1197 std::set<RenderWidgetHostImpl*>::iterator iter =
1198 created_widgets_.find(render_widget_host);
1199 if (iter != created_widgets_.end())
1200 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541201
1202 if (render_widget_host &&
1203 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491204 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1205 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541206 FOR_EACH_OBSERVER(WebContentsObserver,
1207 observers_,
1208 DidDestroyFullscreenWidget(
1209 fullscreen_widget_routing_id_));
1210 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1211 }
[email protected]b24b68a2012-09-24 21:57:261212}
1213
[email protected]b172aee2012-04-10 17:05:261214bool WebContentsImpl::PreHandleKeyboardEvent(
1215 const NativeWebKeyboardEvent& event,
1216 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481217 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131218 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481219}
1220
[email protected]b172aee2012-04-10 17:05:261221void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061222 if (browser_plugin_embedder_ &&
1223 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1224 return;
1225 }
1226
[email protected]63954792011-07-11 04:17:481227 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131228 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481229}
1230
[email protected]fb3f066e2013-02-12 19:12:521231bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461232 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191233#if !defined(OS_MACOSX)
1234 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1235 // isn't done for two reasons:
1236 // -the OS already has a gesture to do this through pinch-zoom
1237 // -if a user starts an inertial scroll, let's go, and presses control
1238 // (i.e. control+tab) then the OS's buffered scroll events will come in
1239 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521240 if (delegate_ &&
1241 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461242 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521243 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1244 return true;
1245 }
[email protected]bccc4472013-04-18 16:37:191246#endif
[email protected]fb3f066e2013-02-12 19:12:521247
1248 return false;
1249}
1250
[email protected]c73a2282013-04-29 21:10:411251#if defined(OS_WIN) && defined(USE_AURA)
1252gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1253 return accessible_parent_;
1254}
1255#endif
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431258 if (delegate_)
1259 delegate_->HandleMouseDown();
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481263 if (delegate_)
1264 delegate_->HandleMouseUp();
1265}
1266
[email protected]590a634e2012-07-19 16:38:231267void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481268 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231269 delegate_->HandlePointerActivate();
1270}
1271
1272void WebContentsImpl::HandleGestureBegin() {
1273 if (delegate_)
1274 delegate_->HandleGestureBegin();
1275}
1276
1277void WebContentsImpl::HandleGestureEnd() {
1278 if (delegate_)
1279 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481280}
1281
[email protected]b172aee2012-04-10 17:05:261282void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491283 // This method is being called to enter or leave renderer-initiated fullscreen
1284 // mode. Either way, make sure any existing fullscreen widget is shut down
1285 // first.
1286 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1287 if (widget_view)
1288 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1289
[email protected]8a5e0ca2011-08-25 06:30:471290 if (delegate_)
1291 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1292}
1293
[email protected]b172aee2012-04-10 17:05:261294bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381295 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121296}
1297
[email protected]a9c81f02012-06-01 00:15:441298void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1299 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371300 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441301 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371302 } else {
1303 GotResponseToLockMouseRequest(false);
1304 }
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371308 if (delegate_)
1309 delegate_->LostMouseLock();
1310}
1311
[email protected]bafe6cd2012-05-23 23:09:501312void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201313 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501314 int route_id,
[email protected]227692c52013-05-31 22:43:041315 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131316 const ViewHostMsg_CreateWindow_Params& params,
1317 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501318 // We usually create the new window in the same BrowsingInstance (group of
1319 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551320 // if the opener is being suppressed (in a non-guest), we create a new
1321 // SiteInstance in its own BrowsingInstance.
1322 bool is_guest = GetRenderProcessHost()->IsGuest();
1323
[email protected]04cbd3d2013-12-04 04:58:201324 // If the opener is to be suppressed, the new window can be in any process.
1325 // Since routing ids are process specific, we must not have one passed in
1326 // as argument here.
1327 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1328
[email protected]bafe6cd2012-05-23 23:09:501329 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551330 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571331 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501332 GetSiteInstance();
1333
[email protected]04cbd3d2013-12-04 04:58:201334 // A message to create a new window can only come from the active process for
1335 // this WebContentsImpl instance. If any other process sends the request,
1336 // it is invalid and the process must be terminated.
1337 if (GetRenderProcessHost()->GetID() != render_process_id) {
1338 base::ProcessHandle process_handle =
1339 RenderProcessHost::FromID(render_process_id)->GetHandle();
1340 if (process_handle != base::kNullProcessHandle) {
1341 RecordAction(
1342 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1343 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1344 }
1345 return;
1346 }
1347
[email protected]d1198fd2012-08-13 22:50:191348 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341349 //
1350 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301351 const std::string& partition_id =
1352 GetContentClient()->browser()->
1353 GetStoragePartitionIdForSite(GetBrowserContext(),
1354 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461355 StoragePartition* partition = BrowserContext::GetStoragePartition(
1356 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411357 DOMStorageContextWrapper* dom_storage_context =
1358 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191359 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1360 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1361 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371362
1363 if (delegate_ &&
1364 !delegate_->ShouldCreateWebContents(this,
1365 route_id,
1366 params.window_container_type,
1367 params.frame_name,
1368 params.target_url,
1369 partition_id,
1370 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011371 if (route_id != MSG_ROUTING_NONE &&
1372 !RenderViewHost::FromID(render_process_id, route_id)) {
1373 // If the embedder didn't create a WebContents for this route, we need to
1374 // delete the RenderView that had already been created.
1375 Send(new ViewMsg_Close(route_id));
1376 }
[email protected]dd6730412013-08-14 15:03:371377 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1378 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1379 main_frame_route_id);
1380 return;
1381 }
1382
1383 // Create the new web contents. This will automatically create the new
1384 // WebContentsView. In the future, we may want to create the view separately.
1385 WebContentsImpl* new_contents =
1386 new WebContentsImpl(GetBrowserContext(),
1387 params.opener_suppressed ? NULL : this);
1388
[email protected]d1198fd2012-08-13 22:50:191389 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301390 partition_id,
[email protected]d1198fd2012-08-13 22:50:191391 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461392 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591393 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041394 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551395 if (!is_guest) {
1396 create_params.context = view_->GetNativeView();
1397 create_params.initial_size = view_->GetContainerSize();
1398 } else {
1399 // This makes |new_contents| act as a guest.
1400 // For more info, see comment above class BrowserPluginGuest.
1401 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1402 WebContentsImpl* new_contents_impl =
1403 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461404 BrowserPluginGuest::CreateWithOpener(instance_id,
1405 new_contents_impl->opener() != NULL,
1406 new_contents_impl,
1407 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551408 }
[email protected]1ac10dca2013-08-20 20:47:041409 if (params.disposition == NEW_BACKGROUND_TAB)
1410 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591411 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191412
[email protected]c4538072013-03-18 02:17:551413 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341414 // will be shown immediately).
1415 if (!params.opener_suppressed) {
1416 if (!is_guest) {
1417 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501418
[email protected]d70bea92013-04-05 04:23:341419 // TODO(brettw): It seems bogus that we have to call this function on the
1420 // newly created object and give it one of its own member variables.
1421 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1422 }
[email protected]bafe6cd2012-05-23 23:09:501423 // Save the created window associated with the route so we can show it
1424 // later.
1425 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1426 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101427 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501428 }
1429
1430 if (delegate_) {
1431 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131432 this, params.opener_frame_id, params.frame_name,
1433 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501434 }
1435
1436 if (params.opener_suppressed) {
1437 // When the opener is suppressed, the original renderer cannot access the
1438 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001439 bool was_blocked = false;
1440 if (delegate_) {
1441 gfx::Rect initial_pos;
1442 delegate_->AddNewContents(
1443 this, new_contents, params.disposition, initial_pos,
1444 params.user_gesture, &was_blocked);
1445 }
1446 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211447 OpenURLParams open_params(params.target_url,
1448 Referrer(),
1449 CURRENT_TAB,
1450 PAGE_TRANSITION_LINK,
1451 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301452 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001453 new_contents->OpenURL(open_params);
1454 }
[email protected]bafe6cd2012-05-23 23:09:501455 }
1456}
1457
[email protected]a8504022013-12-04 20:23:511458void WebContentsImpl::CreateNewWidget(int render_process_id,
1459 int route_id,
[email protected]180ef242013-11-07 06:50:461460 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511461 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501462}
1463
[email protected]a8504022013-12-04 20:23:511464void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1465 int route_id) {
1466 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501467}
1468
[email protected]a8504022013-12-04 20:23:511469void WebContentsImpl::CreateNewWidget(int render_process_id,
1470 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501471 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461472 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211473 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511474 // A message to create a new widget can only come from the active process for
1475 // this WebContentsImpl instance. If any other process sends the request,
1476 // it is invalid and the process must be terminated.
1477 if (process->GetID() != render_process_id) {
1478 base::ProcessHandle process_handle =
1479 RenderProcessHost::FromID(render_process_id)->GetHandle();
1480 if (process_handle != base::kNullProcessHandle) {
1481 RecordAction(
1482 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1483 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1484 }
1485 return;
1486 }
1487
[email protected]bafe6cd2012-05-23 23:09:501488 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041489 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261490 created_widgets_.insert(widget_host);
1491
[email protected]83918ec2013-01-10 15:37:191492 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1493 view_->CreateViewForPopupWidget(widget_host));
1494 if (!widget_view)
1495 return;
[email protected]bafe6cd2012-05-23 23:09:501496 if (!is_fullscreen) {
1497 // Popups should not get activated.
1498 widget_view->SetPopupType(popup_type);
1499 }
1500 // Save the created widget associated with the route so we can show it later.
1501 pending_widget_views_[route_id] = widget_view;
1502
1503#if defined(OS_MACOSX)
1504 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1505 // to allow it to survive the trip without being hosted.
1506 base::mac::NSObjectRetain(widget_view->GetNativeView());
1507#endif
1508}
1509
1510void WebContentsImpl::ShowCreatedWindow(int route_id,
1511 WindowOpenDisposition disposition,
1512 const gfx::Rect& initial_pos,
1513 bool user_gesture) {
1514 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001515 if (contents) {
1516 WebContentsDelegate* delegate = GetDelegate();
1517 if (delegate) {
1518 delegate->AddNewContents(
1519 this, contents, disposition, initial_pos, user_gesture, NULL);
1520 }
1521 }
[email protected]bafe6cd2012-05-23 23:09:501522}
1523
1524void WebContentsImpl::ShowCreatedWidget(int route_id,
1525 const gfx::Rect& initial_pos) {
1526 ShowCreatedWidget(route_id, false, initial_pos);
1527}
1528
1529void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1530 ShowCreatedWidget(route_id, true, gfx::Rect());
1531}
1532
1533void WebContentsImpl::ShowCreatedWidget(int route_id,
1534 bool is_fullscreen,
1535 const gfx::Rect& initial_pos) {
1536 if (delegate_)
1537 delegate_->RenderWidgetShowing();
1538
1539 RenderWidgetHostViewPort* widget_host_view =
1540 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1541 if (!widget_host_view)
1542 return;
[email protected]4aebbca2013-09-17 22:26:491543 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311544 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1545 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491546 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1547 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1548 delegate_->ToggleFullscreenModeForTab(this, true);
1549 } else {
1550 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491551 }
[email protected]4aebbca2013-09-17 22:26:491552 FOR_EACH_OBSERVER(WebContentsObserver,
1553 observers_,
1554 DidShowFullscreenWidget(route_id));
1555 if (!widget_host_view->HasFocus())
1556 widget_host_view->Focus();
1557 } else {
[email protected]f8497342013-02-05 22:15:021558 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491559 }
[email protected]89054502012-06-03 10:29:241560
1561 RenderWidgetHostImpl* render_widget_host_impl =
1562 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1563 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311564 // Only allow privileged mouse lock for fullscreen render widget, which is
1565 // used to implement Pepper Flash fullscreen.
1566 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501567
1568#if defined(OS_MACOSX)
1569 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1570 // properly embedded (or purposefully ignored) we can release the retain we
1571 // took in CreateNewWidget().
1572 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1573#endif
1574}
1575
1576WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1577 PendingContents::iterator iter = pending_contents_.find(route_id);
1578
1579 // Certain systems can block the creation of new windows. If we didn't succeed
1580 // in creating one, just return NULL.
1581 if (iter == pending_contents_.end()) {
1582 return NULL;
1583 }
1584
1585 WebContentsImpl* new_contents = iter->second;
1586 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101587 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501588
[email protected]d70bea92013-04-05 04:23:341589 // Don't initialize the guest WebContents immediately.
1590 if (new_contents->GetRenderProcessHost()->IsGuest())
1591 return new_contents;
1592
[email protected]bafe6cd2012-05-23 23:09:501593 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1594 !new_contents->GetRenderViewHost()->GetView())
1595 return NULL;
1596
1597 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1598 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1599 return new_contents;
1600}
1601
1602RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1603 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1604 if (iter == pending_widget_views_.end()) {
1605 DCHECK(false);
1606 return NULL;
1607 }
1608
1609 RenderWidgetHostView* widget_host_view = iter->second;
1610 pending_widget_views_.erase(route_id);
1611
1612 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1613 if (!widget_host->GetProcess()->HasConnection()) {
1614 // The view has gone away or the renderer crashed. Nothing to do.
1615 return NULL;
1616 }
1617
1618 return widget_host_view;
1619}
1620
[email protected]f56c7872013-06-18 12:31:571621void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501622 // Allow WebContentsDelegates to handle the context menu operation first.
1623 if (delegate_ && delegate_->HandleContextMenu(params))
1624 return;
1625
[email protected]f56c7872013-06-18 12:31:571626 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501627}
1628
[email protected]f13b4202012-06-12 23:53:231629void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091630 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211631 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231632 if (delegate_)
1633 delegate_->RequestMediaAccessPermission(this, request, callback);
1634 else
[email protected]b5f76742013-04-29 15:05:591635 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231636}
1637
[email protected]cc9200432013-07-23 23:02:401638SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1639 SiteInstance* instance) {
1640 return controller_.GetSessionStorageNamespace(instance);
1641}
1642
[email protected]9b159a52013-10-03 17:24:551643FrameTree* WebContentsImpl::GetFrameTree() {
1644 return &frame_tree_;
1645}
1646
[email protected]edc3af82013-12-12 21:24:071647void WebContentsImpl::OnShowValidationMessage(
1648 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291649 const base::string16& main_text,
1650 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071651 if (delegate_)
1652 delegate_->ShowValidationMessage(
1653 this, anchor_in_root_view, main_text, sub_text);
1654}
1655
1656void WebContentsImpl::OnHideValidationMessage() {
1657 if (delegate_)
1658 delegate_->HideValidationMessage(this);
1659}
1660
1661void WebContentsImpl::OnMoveValidationMessage(
1662 const gfx::Rect& anchor_in_root_view) {
1663 if (delegate_)
1664 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1665}
1666
[email protected]32deec62013-05-15 23:55:041667void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1668 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441669 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041670}
1671
[email protected]b172aee2012-04-10 17:05:261672void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231673 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331674 if (delegate_)
1675 delegate_->UpdatePreferredSize(this, pref_size);
1676}
1677
[email protected]b172aee2012-04-10 17:05:261678void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341679 if (delegate_)
1680 delegate_->ResizeDueToAutoResize(this, new_size);
1681}
1682
[email protected]b172aee2012-04-10 17:05:261683WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201684 if (!delegate_)
1685 return NULL;
[email protected]00c37fc2011-08-02 00:22:501686
[email protected]e5d549d2011-12-28 01:29:201687 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201688 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341689}
1690
[email protected]6b618e62012-08-16 12:59:181691bool WebContentsImpl::Send(IPC::Message* message) {
1692 if (!GetRenderViewHost()) {
1693 delete message;
1694 return false;
1695 }
1696
1697 return GetRenderViewHost()->Send(message);
1698}
1699
[email protected]b172aee2012-04-10 17:05:261700bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501701 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251702 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231703 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251704 reload_type);
[email protected]876bc832010-09-07 16:29:541705}
[email protected]96d185d2009-04-24 03:28:541706
[email protected]a86c0e962013-12-17 17:10:391707void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1708 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391710 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441711}
1712
[email protected]20ca0382013-02-28 19:50:071713void WebContentsImpl::AttachInterstitialPage(
1714 InterstitialPageImpl* interstitial_page) {
1715 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211716 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291717
1718 // Cancel any visible dialogs so that they don't interfere with the
1719 // interstitial.
1720 if (dialog_manager_)
1721 dialog_manager_->CancelActiveAndPendingDialogs(this);
1722
[email protected]20ca0382013-02-28 19:50:071723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1724 DidAttachInterstitialPage());
1725}
1726
1727void WebContentsImpl::DetachInterstitialPage() {
1728 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211729 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1731 DidDetachInterstitialPage());
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231735 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501736 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031737 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1738
[email protected]19e81142011-10-03 16:19:401739 // The renderer will reject IPC messages with URLs longer than
1740 // this limit, so don't attempt to navigate with a longer URL.
[email protected]f16cc6782013-12-16 23:42:571741 if (entry.GetURL().spec().size() > GetMaxURLChars()) {
1742 LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars()
[email protected]3adab1c2013-09-09 21:23:431743 << " characters.";
[email protected]19e81142011-10-03 16:19:401744 return false;
[email protected]3adab1c2013-09-09 21:23:431745 }
[email protected]19e81142011-10-03 16:19:401746
[email protected]a1b99262013-12-27 21:56:221747 // Use entry->frame_tree_node_id() to pick which RenderFrameHostManager to
1748 // use when --site-per-process is used.
1749 RenderFrameHostManager* manager = GetRenderManager();
1750 if (entry.frame_tree_node_id() != -1 &&
1751 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) {
1752 int64 frame_tree_node_id = entry.frame_tree_node_id();
1753 manager = frame_tree_.FindByID(frame_tree_node_id)->render_manager();
1754 }
1755
[email protected]9f76c1e2012-03-05 15:15:581756 RenderViewHostImpl* dest_render_view_host =
[email protected]a1b99262013-12-27 21:56:221757 static_cast<RenderViewHostImpl*>(manager->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401758 if (!dest_render_view_host)
1759 return false; // Unable to create the desired render view host.
1760
[email protected]80a8fad2011-01-29 04:02:381761 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071762 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581763 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271764 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501765 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031766 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1767 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211768 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231769 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271770 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211771 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231772 CHECK(0);
1773 }
[email protected]54ec6472010-04-09 19:39:581774
[email protected]7bb761892012-07-20 09:32:471775 // Notify observers that we will navigate in this RV.
1776 FOR_EACH_OBSERVER(WebContentsObserver,
1777 observers_,
1778 AboutToNavigateRenderView(dest_render_view_host));
1779
[email protected]96d185d2009-04-24 03:28:541780 // Used for page load time metrics.
1781 current_load_start_ = base::TimeTicks::Now();
1782
1783 // Navigate in the desired RenderViewHost.
[email protected]a1b99262013-12-27 21:56:221784 // TODO(creis): As a temporary hack, we currently do cross-process subframe
1785 // navigations in a top-level frame of the new process. Thus, we don't yet
1786 // need to store the correct frame ID in ViewMsg_Navigate_Params.
[email protected]056de2d2009-06-26 16:41:341787 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271788 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471789 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341790 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541791
[email protected]36fc0392011-12-25 03:59:511792 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541793 // HACK!! This code suppresses javascript: URLs from being added to
1794 // session history, which is what we want to do for javascript: URLs that
1795 // do not generate content. What we really need is a message from the
1796 // renderer telling us that a new page was not created. The same message
1797 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351798 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541799 return false;
1800 }
1801
[email protected]3c9e1872010-11-18 16:17:491802 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391803 FOR_EACH_OBSERVER(
1804 WebContentsObserver,
1805 observers_,
1806 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541807
[email protected]09b29342011-06-24 19:18:481808 if (delegate_)
1809 delegate_->DidNavigateToPendingEntry(this);
1810
[email protected]d5f942ba2008-09-26 19:30:341811 return true;
1812}
1813
[email protected]b172aee2012-04-10 17:05:261814void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331815 const SiteInstance* site_instance,
1816 int history_length,
1817 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411818 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1819 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211820 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191821 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141822 return;
[email protected]9e1ad4b2011-08-14 16:49:191823 }
[email protected]9f76c1e2012-03-05 15:15:581824 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191825 if (!rvh) {
1826 NOTREACHED();
1827 return;
1828 }
[email protected]9f76c1e2012-03-05 15:15:581829 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191830 NOTREACHED();
1831 return;
1832 }
[email protected]6b618e62012-08-16 12:59:181833 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1834 history_length,
1835 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141836}
1837
[email protected]b172aee2012-04-10 17:05:261838void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271839 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211840 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541841 return;
1842 }
[email protected]9f76c1e2012-03-05 15:15:581843 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541844}
1845
[email protected]b172aee2012-04-10 17:05:261846bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211847 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541848}
1849
[email protected]b172aee2012-04-10 17:05:261850InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211851 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221852}
1853
[email protected]b172aee2012-04-10 17:05:261854bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161855 // WebKit creates Document object when MIME type is application/xhtml+xml,
1856 // so we also support this MIME type.
1857 return contents_mime_type_ == "text/html" ||
1858 contents_mime_type_ == "text/xml" ||
1859 contents_mime_type_ == "application/xhtml+xml" ||
1860 contents_mime_type_ == "text/plain" ||
1861 contents_mime_type_ == "text/css" ||
1862 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1863}
1864
[email protected]b172aee2012-04-10 17:05:261865void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591866 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161867 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551868 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011869 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141870 return;
[email protected]c7dd2f62011-07-18 15:57:591871 }
1872
1873 Stop();
1874
1875 // Create the save package and possibly prompt the user for the name to save
1876 // the page as. The user prompt is an asynchronous operation that runs on
1877 // another thread.
1878 save_package_ = new SavePackage(this);
1879 save_package_->GetSaveInfo();
1880}
1881
1882// Used in automated testing to bypass prompting the user for file names.
1883// Instead, the names and paths are hard coded rather than running them through
1884// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341885bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1886 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211887 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591888 // Stop the page from navigating.
1889 Stop();
1890
1891 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211892 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591893}
1894
[email protected]3c71576ce2013-07-23 02:00:011895void WebContentsImpl::SaveFrame(const GURL& url,
1896 const Referrer& referrer) {
1897 if (!GetURL().is_valid())
1898 return;
1899 bool is_main_frame = (url == GetURL());
1900
1901 DownloadManager* dlm =
1902 BrowserContext::GetDownloadManager(GetBrowserContext());
1903 if (!dlm)
1904 return;
1905 int64 post_id = -1;
1906 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271907 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011908 if (entry)
1909 post_id = entry->GetPostID();
1910 }
1911 scoped_ptr<DownloadUrlParameters> params(
1912 DownloadUrlParameters::FromWebContents(this, url));
1913 params->set_referrer(referrer);
1914 params->set_post_id(post_id);
1915 params->set_prefer_cache(true);
1916 if (post_id >= 0)
1917 params->set_method("POST");
1918 params->set_prompt(true);
1919 dlm->DownloadUrl(params.Pass());
1920}
1921
[email protected]b172aee2012-04-10 17:05:261922void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341923 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481924 const base::Callback<void(int64)>& callback) {
1925 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121926}
1927
[email protected]6286a372013-10-09 04:03:271928// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261929bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271930 NavigationEntryImpl* visible_entry =
1931 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1932 return (visible_entry != NULL &&
1933 visible_entry->site_instance() == GetSiteInstance() &&
1934 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321935}
1936
[email protected]b172aee2012-04-10 17:05:261937const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271938 return contents_mime_type_;
1939}
1940
[email protected]b172aee2012-04-10 17:05:261941bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271942 return notify_disconnection_;
1943}
1944
[email protected]b172aee2012-04-10 17:05:261945void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311946 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181947 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311951 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181952 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161953}
1954
[email protected]8ff00d72012-10-23 19:12:211955RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271956 return &renderer_preferences_;
1957}
1958
[email protected]e35ccd52012-05-23 16:22:471959void WebContentsImpl::Close() {
1960 Close(GetRenderViewHost());
1961}
1962
[email protected]cf200a562013-05-03 16:24:291963void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461964 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291965 if (browser_plugin_embedder_.get())
1966 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1967 screen_x, screen_y, operation);
1968 if (GetRenderViewHost())
1969 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1970 screen_x, screen_y, operation);
1971}
1972
1973void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1974 int screen_x, int screen_y) {
1975 if (browser_plugin_embedder_.get())
1976 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1977 screen_x, screen_y);
1978 if (GetRenderViewHost())
1979 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1980 screen_x, screen_y);
1981}
1982
[email protected]d60f3702013-12-26 16:30:241983void WebContentsImpl::DidGetResourceResponseStart(
1984 const ResourceRequestDetails& details) {
1985 controller_.ssl_manager()->DidStartResourceResponse(details);
1986
1987 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1988 DidGetResourceResponseStart(details));
1989
1990 // TODO(avi): Remove. http://crbug.com/170921
1991 NotificationService::current()->Notify(
1992 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1993 Source<WebContents>(this),
1994 Details<const ResourceRequestDetails>(&details));
1995}
1996
1997void WebContentsImpl::DidGetRedirectForResourceRequest(
1998 RenderViewHost* render_view_host,
1999 const ResourceRedirectDetails& details) {
2000 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2001
2002 FOR_EACH_OBSERVER(
2003 WebContentsObserver,
2004 observers_,
2005 DidGetRedirectForResourceRequest(render_view_host, details));
2006
2007 // TODO(avi): Remove. http://crbug.com/170921
2008 NotificationService::current()->Notify(
2009 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2010 Source<WebContents>(this),
2011 Details<const ResourceRedirectDetails>(&details));
2012}
2013
[email protected]b172aee2012-04-10 17:05:262014void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522015 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582016 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512017 if (delegate_)
2018 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292019 if (browser_plugin_embedder_.get())
2020 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342021}
2022
[email protected]e35ccd52012-05-23 16:22:472023void WebContentsImpl::UserGestureDone() {
2024 OnUserGesture();
2025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272028 closed_by_user_gesture_ = value;
2029}
2030
[email protected]b172aee2012-04-10 17:05:262031bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272032 return closed_by_user_gesture_;
2033}
2034
[email protected]b172aee2012-04-10 17:05:262035double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052036 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562037 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252038 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172039 return 0;
[email protected]b75b8292010-10-01 07:28:252040
2041 double zoom_level;
2042 if (temporary_zoom_settings_) {
2043 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582044 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252045 } else {
[email protected]2ae88d12011-10-14 09:11:192046 GURL url;
[email protected]6286a372013-10-09 04:03:272047 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192048 // Since zoom map is updated using rewritten URL, use rewritten URL
2049 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272050 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022051 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2052 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252053 }
[email protected]d0b8d092010-10-25 04:05:172054 return zoom_level;
2055}
[email protected]b75b8292010-10-01 07:28:252056
[email protected]b172aee2012-04-10 17:05:262057int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592058 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172059 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012060 // Calculate the zoom percent from the factor. Round up to the nearest whole
2061 // number.
[email protected]b75b8292010-10-01 07:28:252062 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492063 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252064 *enable_decrement = percent > minimum_zoom_percent_;
2065 *enable_increment = percent < maximum_zoom_percent_;
2066 return percent;
2067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502070 if (!delegate_)
2071 return;
2072
[email protected]6286a372013-10-09 04:03:272073 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2074 if (!entry)
[email protected]1788e772010-12-15 16:40:502075 return;
2076
[email protected]6286a372013-10-09 04:03:272077 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122078}
2079
[email protected]b172aee2012-04-10 17:05:262080void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042081 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272082 if (!delegate_)
2083 return;
2084
[email protected]691aa2f2013-05-28 22:52:042085 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272086}
2087
[email protected]b172aee2012-04-10 17:05:262088int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272089 return minimum_zoom_percent_;
2090}
2091
[email protected]b172aee2012-04-10 17:05:262092int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272093 return maximum_zoom_percent_;
2094}
2095
[email protected]b172aee2012-04-10 17:05:262096gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:232097 return preferred_size_;
2098}
2099
[email protected]b172aee2012-04-10 17:05:262100bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272101 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582102 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272103}
2104
[email protected]b172aee2012-04-10 17:05:262105bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442106 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502107}
2108
[email protected]cb805452013-05-22 15:16:212109void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182110 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212111 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202112}
2113
[email protected]cb805452013-05-22 15:16:212114void WebContentsImpl::DidEndColorChooser() {
2115 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2116 color_chooser_identifier_));
2117 color_chooser_.reset();
2118 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202119}
2120
[email protected]41225fe2013-03-29 05:32:022121int WebContentsImpl::DownloadImage(const GURL& url,
2122 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302123 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022124 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392125 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302126 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022127 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392128 return id;
2129}
2130
[email protected]5dcaf8e2013-12-28 01:31:422131bool WebContentsImpl::IsSubframe() const {
2132 return is_subframe_;
2133}
2134
[email protected]9649d492014-01-10 07:15:522135void WebContentsImpl::SetZoomLevel(double level) {
2136 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2137 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2138 if (embedder)
2139 embedder->SetZoomLevel(level);
2140}
2141
[email protected]36ec24f2014-01-09 00:32:082142void WebContentsImpl::Find(int request_id,
2143 const base::string16& search_text,
2144 const blink::WebFindOptions& options) {
2145 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2146}
2147
2148void WebContentsImpl::StopFinding(StopFindAction action) {
2149 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2150}
2151
[email protected]b172aee2012-04-10 17:05:262152bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272153 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202154 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332155 return true;
2156 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272160 if (delegate_)
2161 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212162}
2163
[email protected]52913802013-12-10 05:52:182164void WebContentsImpl::DidStartProvisionalLoad(
2165 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572166 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132167 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572168 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182169 const GURL& validated_url,
2170 bool is_error_page,
2171 bool is_iframe_srcdoc) {
2172 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572173 DidChangeLoadProgress(0);
2174
[email protected]0d60f0192011-04-14 12:40:102175 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252176 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132177 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2178 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182179 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542180
2181 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182182 FOR_EACH_OBSERVER(
2183 WebContentsObserver,
2184 observers_,
2185 ProvisionalChangeToMainFrameUrl(validated_url,
2186 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542187 }
2188}
2189
[email protected]3109fbb72014-01-06 23:57:152190void WebContentsImpl::DidFailProvisionalLoadWithError(
2191 RenderFrameHostImpl* render_frame_host,
2192 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2193 GURL validated_url(params.url);
2194 FOR_EACH_OBSERVER(
2195 WebContentsObserver,
2196 observers_,
2197 DidFailProvisionalLoad(params.frame_id,
2198 params.frame_unique_name,
2199 params.is_main_frame,
2200 validated_url,
2201 params.error_code,
2202 params.error_description,
2203 render_frame_host->render_view_host()));
2204}
2205
[email protected]52913802013-12-10 05:52:182206void WebContentsImpl::NotifyChangedNavigationState(
2207 InvalidateTypes changed_flags) {
2208 NotifyNavigationStateChanged(changed_flags);
2209}
2210
[email protected]400992b2012-06-14 00:03:542211void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212212 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542213 int32 page_id,
[email protected]400992b2012-06-14 00:03:542214 const GURL& source_url,
2215 const GURL& target_url) {
2216 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132217 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2218 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542219 GURL validated_source_url(source_url);
2220 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212221 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542222 render_view_host->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422223 render_process_host->FilterURL(false, &validated_source_url);
2224 render_process_host->FilterURL(false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542225 NavigationEntry* entry;
2226 if (page_id == -1) {
2227 entry = controller_.GetPendingEntry();
2228 } else {
2229 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2230 page_id);
2231 }
2232 if (!entry || entry->GetURL() != validated_source_url)
2233 return;
2234
2235 // Notify observers about the provisional change in the main frame URL.
2236 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2237 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542238 render_view_host));
[email protected]724159a2010-12-30 01:11:182239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182242 const GURL& url,
[email protected]70435962011-08-02 20:13:282243 const std::string& security_info,
2244 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182245 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282246 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192247 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182248 cache.Increment();
2249
2250 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082251 int cert_id = 0;
2252 net::CertStatus cert_status = 0;
2253 int security_bits = -1;
2254 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122255 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212256 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122257 &security_bits, &connection_status,
2258 &signed_certificate_timestamp_ids);
2259 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212260 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002261 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2262 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182263
[email protected]b0f724c2013-09-05 04:21:132264 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2265
2266 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2267 DidLoadResourceFromMemoryCache(details));
2268
[email protected]8bfc8272013-09-09 20:10:532269 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2270 scoped_refptr<net::URLRequestContextGetter> request_context(
2271 resource_type == ResourceType::MEDIA ?
2272 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2273 GetRenderProcessHost()->GetID()) :
2274 GetBrowserContext()->GetRequestContextForRenderProcess(
2275 GetRenderProcessHost()->GetID()));
2276 BrowserThread::PostTask(
2277 BrowserThread::IO,
2278 FROM_HERE,
2279 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2280 }
[email protected]724159a2010-12-30 01:11:182281}
2282
[email protected]b172aee2012-04-10 17:05:262283void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212284 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182285 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192286 SSLManager::NotifySSLInternalStateChanged(
2287 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182288}
2289
[email protected]b172aee2012-04-10 17:05:262290void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022291 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582292 LOG(WARNING) << security_origin << " ran insecure content from "
2293 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212294 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412295 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212296 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182297 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412298 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192299 SSLManager::NotifySSLInternalStateChanged(
2300 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442304 FOR_EACH_OBSERVER(
2305 WebContentsObserver, observers_,
2306 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182307}
2308
[email protected]b172aee2012-04-10 17:05:262309void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312310 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062311 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312312 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062313 GURL validated_url(url);
[email protected]a1b99262013-12-27 21:56:222314
2315 // --site-per-process mode has a short-term hack allowing cross-process
2316 // subframe pages to commit thinking they are top-level. Correct it here to
2317 // avoid confusing the observers.
2318 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2319 render_view_message_source_ != GetRenderViewHost())
2320 is_main_frame = false;
2321
[email protected]f114fa42013-12-06 17:06:442322 RenderProcessHost* render_process_host =
2323 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422324 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252325 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472326 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442327 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312328}
2329
[email protected]b172aee2012-04-10 17:05:262330void WebContentsImpl::OnDidFailLoadWithError(
2331 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062332 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262333 bool is_main_frame,
2334 int error_code,
[email protected]fcf75d42013-12-03 20:11:262335 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062336 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442337 RenderProcessHost* render_process_host =
2338 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422339 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252340 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312341 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472342 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442343 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262347 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232348 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252349 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262350 if (!entry)
2351 return;
2352 // Note that we don't call NavigationController::GotToOffset() as we don't
2353 // want to create a pending navigation entry (it might end up lingering
2354 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252355 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212356 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512357 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212358 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472359 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572360
2361 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2362 // it in now that we know. This allows us to find the entry when it commits.
2363 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232364 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332365 entry->set_site_instance(
2366 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572367 }
[email protected]216813952011-05-19 22:21:262368 }
2369}
2370
[email protected]b172aee2012-04-10 17:05:262371void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2372 int maximum_percent,
2373 bool remember) {
[email protected]216813952011-05-19 22:21:262374 minimum_zoom_percent_ = minimum_percent;
2375 maximum_zoom_percent_ = maximum_percent;
2376 temporary_zoom_settings_ = !remember;
2377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342380 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432381 if (!delegate_)
2382 return;
2383
[email protected]b9535422012-02-09 01:47:592384 ChildProcessSecurityPolicyImpl* policy =
2385 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222386 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592387 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432391 if (delegate_)
2392 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202393}
2394
[email protected]b172aee2012-04-10 17:05:262395void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2396 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262397 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362398 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432399 if (!delegate_)
2400 return;
2401
[email protected]b9535422012-02-09 01:47:592402 ChildProcessSecurityPolicyImpl* policy =
2403 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322404 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592405 return;
[email protected]8f810632013-06-06 22:33:322406
[email protected]3a3b75a2012-06-01 08:38:362407 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202408}
2409
[email protected]b172aee2012-04-10 17:05:262410void WebContentsImpl::OnFindReply(int request_id,
2411 int number_of_matches,
2412 const gfx::Rect& selection_rect,
2413 int active_match_ordinal,
2414 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432415 if (delegate_) {
2416 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2417 active_match_ordinal, final_update);
2418 }
[email protected]b888919c2011-09-02 00:32:162419}
2420
[email protected]59363fc92012-09-05 03:46:312421#if defined(OS_ANDROID)
2422void WebContentsImpl::OnFindMatchRectsReply(
2423 int version,
2424 const std::vector<gfx::RectF>& rects,
2425 const gfx::RectF& active_rect) {
2426 if (delegate_)
2427 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2428}
[email protected]583418cc2013-01-17 14:01:102429
[email protected]1ff427972013-02-07 21:14:072430void WebContentsImpl::OnOpenDateTimeDialog(
2431 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092432 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2433 GetRenderViewHost(),
2434 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132435 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092436 value.minimum,
2437 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172438 value.step,
2439 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102440}
2441
[email protected]a794f3a2013-10-30 17:00:322442void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2443 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442444 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322445}
2446
[email protected]59363fc92012-09-05 03:46:312447#endif
2448
[email protected]f114fa42013-12-06 17:06:442449void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2450 const base::FilePath& path,
2451 bool is_hung) {
2452 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2453
2454 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2455 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2456}
2457
2458void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422459 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442460 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422461 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452462}
2463
[email protected]b172aee2012-04-10 17:05:262464void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2465 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102466 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252467 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102468 AppCacheAccessed(manifest_url, blocked_by_policy));
2469}
2470
[email protected]8bc5ff02013-11-29 06:34:032471void WebContentsImpl::OnOpenColorChooser(
2472 int color_chooser_id,
2473 SkColor color,
2474 const std::vector<ColorSuggestion>& suggestions) {
2475 ColorChooser* new_color_chooser =
2476 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212477 if (color_chooser_ == new_color_chooser)
2478 return;
2479 color_chooser_.reset(new_color_chooser);
2480 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202481}
2482
[email protected]b172aee2012-04-10 17:05:262483void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202484 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212485 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202486 color_chooser_->End();
2487}
2488
[email protected]b172aee2012-04-10 17:05:262489void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322490 SkColor color) {
[email protected]da8543762012-03-20 08:52:202491 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212492 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202493 color_chooser_->SetSelectedColor(color);
2494}
2495
[email protected]d0759f492012-04-19 22:50:502496// This exists for render views that don't have a WebUI, but do have WebUI
2497// bindings enabled.
2498void WebContentsImpl::OnWebUISend(const GURL& source_url,
2499 const std::string& name,
2500 const base::ListValue& args) {
2501 if (delegate_)
2502 delegate_->WebUISend(this, source_url, name, args);
2503}
2504
[email protected]d8415ad92012-08-23 14:40:502505void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442506 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502507 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342508 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162509 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442510 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162511 return;
[email protected]d8415ad92012-08-23 14:40:502512 }
2513
[email protected]8c8fc292012-11-23 18:57:162514 if (!delegate_->RequestPpapiBrokerPermission(
2515 this, url, plugin_path,
2516 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442517 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162518 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442519 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162520 }
[email protected]d8415ad92012-08-23 14:40:502521}
2522
[email protected]ea0309c2013-08-06 19:35:442523void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502524 bool result) {
[email protected]ea0309c2013-08-06 19:35:442525 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502526}
2527
[email protected]c4538072013-03-18 02:17:552528void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372529 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082530 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552531 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392532 // For more info, see comment above classes BrowserPluginEmbedder and
2533 // BrowserPluginGuest.
2534 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142535 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082536 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372537}
2538
[email protected]41225fe2013-03-29 05:32:022539void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392540 int id,
[email protected]749fadd2013-05-15 08:37:482541 int http_status_code,
[email protected]795c28972012-12-06 06:13:392542 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302543 const std::vector<SkBitmap>& bitmaps,
2544 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022545 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2546 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392547 // Currently WebContents notifies us of ANY downloads so that it is
2548 // possible to get here.
2549 return;
2550 }
2551 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302552 iter->second.Run(
2553 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392554 }
[email protected]41225fe2013-03-29 05:32:022555 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392556}
2557
2558void WebContentsImpl::OnUpdateFaviconURL(
2559 int32 page_id,
2560 const std::vector<FaviconURL>& candidates) {
2561 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2562 DidUpdateFaviconURL(page_id, candidates));
2563}
2564
[email protected]d9030b82013-07-19 08:26:062565void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2566 bool has_video,
2567 bool has_audio,
2568 bool is_playing) {
2569 // Chrome OS does its own detection of audio and video.
2570#if !defined(OS_CHROMEOS)
2571 if (is_playing) {
2572 scoped_ptr<PowerSaveBlocker> blocker;
2573 if (has_video) {
2574 blocker = PowerSaveBlocker::Create(
2575 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2576 "Playing video");
2577#if defined(OS_ANDROID)
2578 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382579 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062580#endif
2581 } else if (has_audio) {
2582 blocker = PowerSaveBlocker::Create(
2583 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2584 "Playing audio");
2585 }
2586
[email protected]f114fa42013-12-06 17:06:442587 if (blocker) {
2588 power_save_blockers_[render_view_message_source_][player_cookie] =
2589 blocker.release();
2590 }
[email protected]d9030b82013-07-19 08:26:062591 } else {
[email protected]f114fa42013-12-06 17:06:442592 delete power_save_blockers_[render_view_message_source_][player_cookie];
2593 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062594 }
2595#endif // !defined(OS_CHROMEOS)
2596}
2597
[email protected]9f268072013-11-07 00:02:152598void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2599 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2600 DidFirstVisuallyNonEmptyPaint(page_id));
2601}
[email protected]d9030b82013-07-19 08:26:062602
[email protected]e67ebf32013-02-13 11:07:192603void WebContentsImpl::DidChangeVisibleSSLState() {
2604 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2605 DidChangeVisibleSSLState());
2606}
2607
[email protected]17e286e2013-03-01 23:29:392608void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2609 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2610 BeforeFormRepostWarningShow());
2611}
2612
[email protected]ec6c05f2013-10-23 18:41:572613
2614void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2615 Activate();
2616 if (delegate_)
2617 delegate_->ShowRepostFormWarningDialog(this);
2618}
2619
[email protected]96d185d2009-04-24 03:28:542620// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592621// loading, or done loading.
2622void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2623 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262624 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542625 if (is_loading == is_loading_)
2626 return;
2627
2628 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262629 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2630 base::string16());
[email protected]96d185d2009-04-24 03:28:542631 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562632 upload_size_ = 0;
2633 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542634 }
2635
[email protected]fa944cb82013-11-15 17:51:212636 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542637
2638 is_loading_ = is_loading;
2639 waiting_for_response_ = is_loading;
2640
[email protected]6ebdc9b2010-09-27 16:55:572641 if (delegate_)
2642 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212643 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542644
[email protected]eab61442013-11-14 18:35:482645 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592646 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482647 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2648 "URL", url);
[email protected]91621872013-10-08 04:04:592649 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2650 DidStartLoading(render_view_host));
2651 } else {
[email protected]eab61442013-11-14 18:35:482652 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2653 "URL", url);
[email protected]91621872013-10-08 04:04:592654 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2655 DidStopLoading(render_view_host));
2656 }
[email protected]66798902013-10-01 18:40:162657
2658 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212659 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2660 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542661 if (details)
[email protected]8ff00d72012-10-23 19:12:212662 det = Details<LoadNotificationDetails>(details);
2663 NotificationService::current()->Notify(
2664 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542665}
2666
[email protected]b172aee2012-04-10 17:05:262667void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212668 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322669 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562670 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322671 // Clear the status bubble. This is a workaround for a bug where WebKit
2672 // doesn't let us know that the cursor left an element during a
2673 // transition (this is also why the mouse cursor remains as a hand after
2674 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2675 // clear the bubble when a user navigates to a named anchor in the same
2676 // page.
[email protected]36fc0392011-12-25 03:59:512677 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322678 }
2679
[email protected]a6e82fc2010-02-24 22:28:142680 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472681 // Once the main frame is navigated, we're no longer considered to have
2682 // displayed insecure content.
2683 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352684 SSLManager::NotifySSLInternalStateChanged(
2685 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172686 }
[email protected]ce5c4502009-05-06 16:46:112687
[email protected]3c9e1872010-11-18 16:17:492688 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252689 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042690 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322691}
2692
[email protected]b172aee2012-04-10 17:05:262693void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322694 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212695 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322696 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112697 // If we navigate off the page, close all JavaScript dialogs.
2698 if (dialog_manager_ && !details.is_in_page)
2699 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322700
[email protected]3c9e1872010-11-18 16:17:492701 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252702 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042703 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322704}
2705
[email protected]2f7b3c5a2013-06-21 04:59:252706bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292707 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2708 // still be used for a normal web site.
2709 if (url == GURL(kAboutBlankURL))
2710 return false;
2711
2712 // The embedder will then have the opportunity to determine if the URL
2713 // should "use up" the SiteInstance.
2714 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252715}
2716
[email protected]b172aee2012-04-10 17:05:262717void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462718 // If we are creating a RVH for a restored controller, then we need to make
2719 // sure the RenderView starts with a next_page_id_ larger than the number
2720 // of restored entries. This must be called before the RenderView starts
2721 // navigating (to avoid a race between the browser updating max_page_id and
2722 // the renderer updating next_page_id_). Because of this, we only call this
2723 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562724 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582725 if (max_restored_page_id >
2726 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2727 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2728 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322729}
2730
[email protected]b172aee2012-04-10 17:05:262731bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262732 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322733 // For file URLs without a title, use the pathname instead. In the case of a
2734 // synthesized title, we don't want the update to count toward the "one set
2735 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262736 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322737 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512738 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242739 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322740 explicit_set = false; // Don't count synthetic titles toward the set limit.
2741 } else {
[email protected]acafd272011-07-26 17:35:572742 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322743 explicit_set = true;
2744 }
2745
[email protected]987fc3a2011-05-26 14:18:092746 // If a page is created via window.open and never navigated,
2747 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552748 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092749 if (entry) {
[email protected]36fc0392011-12-25 03:59:512750 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092751 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322752
[email protected]36fc0392011-12-25 03:59:512753 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092754 } else {
2755 if (page_title_when_no_navigation_entry_ == final_title)
2756 return false; // Nothing changed, don't bother.
2757
2758 page_title_when_no_navigation_entry_ = final_title;
2759 }
[email protected]420ae012009-04-24 05:16:322760
[email protected]420ae012009-04-24 05:16:322761 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232762 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322763
[email protected]66798902013-10-01 18:40:162764 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532765 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162766
2767 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212768 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462769 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212770 NotificationService::current()->Notify(
2771 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2772 Source<WebContents>(this),
2773 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042774
[email protected]420ae012009-04-24 05:16:322775 return true;
2776}
2777
[email protected]7b712ee22013-10-03 00:57:282778void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2779 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322780 // After sending out a swap notification, we need to send a disconnect
2781 // notification so that clients that pick up a pointer to |this| can NULL the
2782 // pointer. See Bug 1230284.
2783 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112784 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282785 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112786
2787 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282788 std::pair<RenderViewHost*, RenderViewHost*> details =
2789 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212790 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282791 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212792 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282793 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392794
2795 // Ensure that the associated embedder gets cleared after a RenderViewHost
2796 // gets swapped, so we don't reuse the same embedder next time a
2797 // RenderViewHost is attached to this WebContents.
2798 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322799}
2800
[email protected]da7a7182013-09-06 08:11:112801// TODO(avi): Remove this entire function because this notification is already
2802// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322804 if (!notify_disconnection_)
2805 return;
2806
2807 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212808 NotificationService::current()->Notify(
2809 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2810 Source<WebContents>(this),
2811 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322812}
2813
[email protected]cbb1ef592013-06-05 19:49:462814void WebContentsImpl::NotifyNavigationEntryCommitted(
2815 const LoadCommittedDetails& load_details) {
2816 FOR_EACH_OBSERVER(
2817 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2818}
2819
[email protected]f114fa42013-12-06 17:06:442820bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2821 const IPC::Message& message) {
2822 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312823}
2824
[email protected]b849847b2013-12-10 21:57:582825void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2826 // Note this is only for subframes, the notification for the main frame
2827 // happens in RenderViewCreated.
2828 FOR_EACH_OBSERVER(WebContentsObserver,
2829 observers_,
2830 RenderFrameCreated(render_frame_host));
2831}
2832
2833void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2834 FOR_EACH_OBSERVER(WebContentsObserver,
2835 observers_,
2836 RenderFrameDeleted(render_frame_host));
2837}
2838
[email protected]b765deb2013-12-18 06:43:302839void WebContentsImpl::WorkerCrashed() {
2840 if (delegate_)
2841 delegate_->WorkerCrashed(this);
2842}
2843
[email protected]a86c0e962013-12-17 17:10:392844WebContents* WebContentsImpl::GetAsWebContents() {
2845 return this;
2846}
2847
[email protected]5a3bdf52012-05-24 15:12:572848RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2849 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322850}
2851
[email protected]8d3347f2009-07-09 22:00:212852RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262853WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212854 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212855}
2856
[email protected]8ff00d72012-10-23 19:12:212857RendererPreferences WebContentsImpl::GetRendererPrefs(
2858 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462859 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512860}
2861
[email protected]b172aee2012-04-10 17:05:262862gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172863 if (delegate_)
2864 return delegate_->GetRootWindowResizerRect();
2865 return gfx::Rect();
2866}
2867
[email protected]7a846df2012-09-20 19:17:392868void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272869 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392870 browser_plugin_embedder_.reset();
2871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442874 // Don't send notifications if we are just creating a swapped-out RVH for
2875 // the opener chain. These won't be used for view-source or WebUI, so it's
2876 // ok to return early.
2877 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2878 return;
2879
[email protected]86f98a22013-03-20 14:35:002880 if (delegate_)
2881 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082882
[email protected]8ff00d72012-10-23 19:12:212883 NotificationService::current()->Notify(
2884 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2885 Source<WebContents>(this),
2886 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322887
2888 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352889 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212890 if (GetRenderManager()->pending_web_ui())
2891 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322892
[email protected]6286a372013-10-09 04:03:272893 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332894 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322895 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182896 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582897 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322898 }
[email protected]0666aef2009-05-13 19:48:082899
[email protected]60780f412013-02-25 16:34:102900 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262901
2902 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252903 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582904
2905 // We tell the observers now instead of when the main RenderFrameHostImpl is
2906 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2907 // frame would be dropped because it's not created yet).
2908 RenderFrameHost* main_frame = GetMainFrame();
2909 FOR_EACH_OBSERVER(
2910 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]b172aee2012-04-10 17:05:262913void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522914 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322915 // Don't notify the world, since this came from a renderer in the
2916 // background.
2917 return;
2918 }
2919
[email protected]da7a7182013-09-06 08:11:112920 notify_disconnection_ = true;
2921 // TODO(avi): Remove. http://crbug.com/170921
2922 NotificationService::current()->Notify(
2923 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2924 Source<WebContents>(this),
2925 NotificationService::NoDetails());
2926
[email protected]be1f56ab2011-12-22 06:55:312927 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232928 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302929
2930 // Restore the focus to the tab (otherwise the focus will be on the top
2931 // window).
[email protected]484ae5912010-09-29 19:16:142932 if (was_crashed && !FocusLocationBarByDefault() &&
2933 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062934 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142935 }
[email protected]32ded2212011-11-10 18:51:432936
[email protected]d8c660432011-12-22 20:51:252937 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322938}
2939
[email protected]ec6a7eb2013-04-22 17:34:222940void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2941 base::TerminationStatus status,
2942 int error_code) {
[email protected]151a63d2011-12-20 22:32:522943 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322944 // The pending page's RenderViewHost is gone.
2945 return;
2946 }
2947
[email protected]d9030b82013-07-19 08:26:062948 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592949 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322950 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232951 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312952 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322953
[email protected]d8c660432011-12-22 20:51:252954 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272955 observers_,
[email protected]58d5cfe2013-07-10 02:40:522956 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322957}
2958
[email protected]b172aee2012-04-10 17:05:262959void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062960 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212961 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252962 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062963}
2964
[email protected]b172aee2012-04-10 17:05:262965void WebContentsImpl::DidNavigate(
2966 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222967 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2968 ViewHostMsg_FrameNavigate_Params params(orig_params);
2969 bool use_site_per_process =
2970 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552971 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2972 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222973 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2974 // because cross-process subframe navigations still have a main frame
2975 // PageTransition.
2976 if (!use_site_per_process)
2977 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552978 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122979 }
2980
[email protected]a1b99262013-12-27 21:56:222981 // When using --site-per-process, look up the FrameTreeNode ID that the
2982 // renderer-specific frame ID corresponds to.
2983 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2984 if (use_site_per_process) {
2985 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2986 if (source_node)
2987 frame_tree_node_id = source_node->frame_tree_node_id();
2988
2989 // TODO(creis): In the short term, cross-process subframe navigations are
2990 // happening in the pending RenderViewHost's top-level frame. (We need to
2991 // both mirror the frame tree and get the navigation to occur in the correct
2992 // subframe to fix this.) Until then, we should check whether we have a
2993 // pending NavigationEntry with a frame ID and if so, treat the
2994 // cross-process "main frame" navigation as a subframe navigation. This
2995 // limits us to a single cross-process subframe per RVH, and it affects
2996 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2997 // OnDidFinishLoad.
2998 NavigationEntryImpl* pending_entry =
2999 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
3000 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
3001 if (pending_entry &&
3002 pending_entry->frame_tree_node_id() != -1 &&
3003 pending_entry->frame_tree_node_id() != root_ftn_id) {
3004 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
3005 frame_tree_node_id = pending_entry->frame_tree_node_id();
3006 }
3007 }
3008
[email protected]e3d92a7f2013-01-10 02:35:053009 if (PageTransitionIsMainFrame(params.transition)) {
3010 // When overscroll navigation gesture is enabled, a screenshot of the page
3011 // in its current state is taken so that it can be used during the
3012 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:363013 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:053014 // WebContents::GetRenderViewHost to return the new host, instead of the one
3015 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:483016 if (delegate_ && delegate_->CanOverscrollContent())
3017 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:053018
[email protected]a1b99262013-12-27 21:56:223019 if (!use_site_per_process)
3020 GetRenderManager()->DidNavigateMainFrame(rvh);
3021 }
3022
3023 // When using --site-per-process, we notify the RFHM for all navigations,
3024 // not just main frame navigations.
3025 if (use_site_per_process) {
3026 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
3027 // TODO(creis): Rename to DidNavigateFrame.
3028 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:053029 }
[email protected]8030f012009-09-25 18:09:373030
[email protected]434f69f2012-02-06 21:56:523031 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:253032 // assigning a site is not necessary for this URL. In that case, the
3033 // SiteInstance can still be considered unused until a navigation to a real
3034 // page.
[email protected]434f69f2012-02-06 21:56:523035 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:253036 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:333037 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:523038 }
[email protected]420ae012009-04-24 05:16:323039
3040 // Need to update MIME type here because it's referred to in
3041 // UpdateNavigationCommands() called by RendererDidNavigate() to
3042 // determine whether or not to enable the encoding menu.
3043 // It's updated only for the main frame. For a subframe,
3044 // RenderView::UpdateURL does not set params.contents_mime_type.
3045 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
3046 // TODO(jungshik): Add a test for the encoding menu to avoid
3047 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:213048 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:323049 contents_mime_type_ = params.contents_mime_type;
3050
[email protected]8ff00d72012-10-23 19:12:213051 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:223052 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:393053
[email protected]1ae93fb2013-06-14 03:38:563054 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
3055 // us estimate our process count for implementing OOP iframes.
3056 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:553057 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:563058
[email protected]a9c0bfe2010-09-17 08:35:223059 // Send notification about committed provisional loads. This notification is
3060 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
3061 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:213062 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:073063 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
3064 // that is not recorded in the navigation history. For the purpose of
3065 // tracking navigation events, we treat this event as a sub frame navigation
3066 // event.
3067 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:213068 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:223069 // Whether or not a page transition was triggered by going backward or
3070 // forward in the history is only stored in the navigation controller's
3071 // entry list.
3072 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:273073 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:213074 PAGE_TRANSITION_FORWARD_BACK)) {
3075 transition_type = PageTransitionFromInt(
3076 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:223077 }
[email protected]0d60f0192011-04-14 12:40:103078 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:253079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:443080 DidCommitProvisionalLoadForFrame(
3081 params.frame_id,
3082 params.frame_unique_name,
3083 is_main_frame,
3084 params.url,
3085 transition_type,
3086 rvh));
[email protected]a9c0bfe2010-09-17 08:35:223087 }
3088
[email protected]76543b92009-08-31 17:27:453089 if (!did_navigate)
3090 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:323091
3092 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
3093 // for the appropriate notification (best) or you can add it to
3094 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
3095 // necessary, please).
3096
3097 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:003098 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:323099 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:003100 if (delegate_) {
[email protected]6934a702011-12-20 00:04:513101 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:003102 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
3103 }
[email protected]93f230e02011-06-01 14:40:003104 }
[email protected]420ae012009-04-24 05:16:323105 DidNavigateAnyFramePostCommit(rvh, details, params);
3106}
3107
[email protected]b172aee2012-04-10 17:05:263108void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3109 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043110 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153111 // Ensure that this state update comes from either the active RVH or one of
3112 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413113 // TODO(nasko): This should go through RenderFrameHost.
3114 // TODO(creis): We can't update state for cross-process subframes until we
3115 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3116 if (rvh != GetRenderViewHost() &&
3117 !GetRenderManager()->IsRVHOnSwappedOutList(
3118 static_cast<RenderViewHostImpl*>(rvh)))
3119 return;
[email protected]420ae012009-04-24 05:16:323120
3121 // We must be prepared to handle state updates for any page, these occur
3122 // when the user is scrolling and entering form data, as well as when we're
3123 // leaving a page, in which case our state may have already been moved to
3124 // the next page. The navigation controller will look up the appropriate
3125 // NavigationEntry and update it when it is notified via the delegate.
3126
3127 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583128 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323129 if (entry_index < 0)
3130 return;
[email protected]10f417c52011-12-28 21:04:233131 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323132
[email protected]691aa2f2013-05-28 22:52:043133 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323134 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043135 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323136 controller_.NotifyEntryChanged(entry, entry_index);
3137}
3138
[email protected]b172aee2012-04-10 17:05:263139void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3140 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263141 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263142 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323143 // If we have a title, that's a pretty good indication that we've started
3144 // getting useful data.
3145 SetNotWaitingForResponse();
3146
[email protected]73eb2602012-02-09 19:50:553147 // Try to find the navigation entry, which might not be the current one.
3148 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233149 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583150 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093151
[email protected]73eb2602012-02-09 19:50:553152 // We can handle title updates when we don't have an entry in
3153 // UpdateTitleForEntry, but only if the update is from the current RVH.
3154 if (!entry && rvh != GetRenderViewHost())
3155 return;
3156
[email protected]a49e10b2011-08-01 23:57:463157 // TODO(evan): make use of title_direction.
3158 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093159 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323160 return;
3161
3162 // Broadcast notifications when the UI should be updated.
3163 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213164 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323165}
3166
[email protected]b172aee2012-04-10 17:05:263167void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3168 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313169 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323170}
3171
[email protected]b172aee2012-04-10 17:05:263172void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513173 if (delegate_)
3174 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323175}
3176
[email protected]b172aee2012-04-10 17:05:263177void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103178#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293179 // The UI may be in an event-tracking loop, such as between the
3180 // mouse-down and mouse-up in text selection or a button click.
3181 // Defer the close until after tracking is complete, so that we
3182 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293183 // TODO(shess): This could get more fine-grained. For instance,
3184 // closing a tab in another window while selecting text in the
3185 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103186 if (view_->IsEventTracking()) {
3187 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293188 return;
3189 }
[email protected]60780f412013-02-25 16:34:103190#endif
[email protected]07707302009-11-06 00:50:293191
[email protected]420ae012009-04-24 05:16:323192 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523193 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513194 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323195}
3196
[email protected]b172aee2012-04-10 17:05:263197void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523198 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513199 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283200
3201 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213202 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573203}
3204
[email protected]b172aee2012-04-10 17:05:263205void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513206 if (delegate_ && delegate_->IsPopupOrPanel(this))
3207 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323208}
3209
[email protected]8ff00d72012-10-23 19:12:213210void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593211 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323212}
3213
[email protected]8ff00d72012-10-23 19:12:213214void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323215 scoped_ptr<LoadNotificationDetails> details;
3216
[email protected]9595fd82013-04-19 21:28:493217 // Use the last committed entry rather than the active one, in case a
3218 // pending entry has been created.
3219 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3220
[email protected]420ae012009-04-24 05:16:323221 // An entry may not exist for a stop when loading an initial blank page or
3222 // if an iframe injected by script into a blank page finishes loading.
3223 if (entry) {
[email protected]420ae012009-04-24 05:16:323224 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3225
3226 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513227 entry->GetVirtualURL(),
3228 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323229 elapsed,
3230 &controller_,
3231 controller_.GetCurrentEntryIndex()));
3232 }
3233
[email protected]91621872013-10-08 04:04:593234 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323235}
3236
[email protected]b172aee2012-04-10 17:05:263237void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163238 controller_.DiscardNonCommittedEntries();
3239
3240 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213241 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163242}
3243
[email protected]b172aee2012-04-10 17:05:263244void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513245 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133246 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403247}
3248
[email protected]7cc78902012-12-06 02:32:263249void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393250 if (opener_) {
3251 // Clear our opener so that future cross-process navigations don't have an
3252 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103253 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393254 opener_ = NULL;
3255 }
[email protected]7cc78902012-12-06 02:32:263256
3257 // Notify all swapped out RenderViewHosts for this tab. This is important
3258 // in case we go back to them, or if another window in those processes tries
3259 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213260 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263261}
3262
[email protected]59167c22013-06-03 18:07:323263void WebContentsImpl::DidAccessInitialDocument() {
3264 // Update the URL display.
3265 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3266}
3267
[email protected]87717d0e2012-04-26 02:58:433268void WebContentsImpl::DocumentAvailableInMainFrame(
3269 RenderViewHost* render_view_host) {
3270 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3271 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103272}
3273
[email protected]b172aee2012-04-10 17:05:263274void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083275 RenderViewHost* render_view_host,
3276 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093277 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3278 DocumentOnLoadCompletedInMainFrame(page_id));
3279
3280 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213281 NotificationService::current()->Notify(
3282 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3283 Source<WebContents>(this),
3284 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083285}
3286
[email protected]196159d2012-05-04 17:26:543287void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3288 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213289 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263290 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183291 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523292 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303293 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543294 // If this came from a swapped out RenderViewHost, we only allow the request
3295 // if we are still in the same BrowsingInstance.
3296 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3297 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3298 return;
3299 }
3300
[email protected]4ad5d77d2011-12-03 02:00:483301 // Delegate to RequestTransferURL because this is just the generic
3302 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573303 // TODO(creis): Pass the redirect_chain into this method to support client
3304 // redirects. http://crbug.com/311721.
3305 std::vector<GURL> redirect_chain;
3306 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3307 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523308 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483309}
3310
[email protected]b172aee2012-04-10 17:05:263311void WebContentsImpl::RequestTransferURL(
3312 const GURL& url,
[email protected]f8872902013-10-30 03:18:573313 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213314 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573315 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263316 WindowOpenDisposition disposition,
3317 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183318 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523319 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303320 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203321 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123322 GURL dest_url(url);
3323 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553324 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123325 dest_url = GURL(kAboutBlankURL);
3326
[email protected]a1b99262013-12-27 21:56:223327 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3328 int64 frame_tree_node_id = -1;
3329 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3330 source_frame_id != -1) {
3331 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3332 if (source_node)
3333 frame_tree_node_id = source_node->frame_tree_node_id();
3334 }
[email protected]c80297782013-11-21 07:10:163335 OpenURLParams params(dest_url, referrer, source_frame_id,
3336 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573337 page_transition, true /* is_renderer_initiated */);
3338 if (redirect_chain.size() > 0)
3339 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553340 params.transferred_global_request_id = old_request_id;
3341 params.should_replace_current_entry = should_replace_current_entry;
3342 params.user_gesture = user_gesture;
3343
[email protected]fa944cb82013-11-15 17:51:213344 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573345 // Web UI pages sometimes want to override the page transition type for
3346 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3347 // automatically generated suggestions). We don't override other types
3348 // like TYPED because they have different implications (e.g., autocomplete).
3349 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213350 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553351
[email protected]e0112912011-02-02 22:54:353352 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163353 // want web sites to see a referrer of "chrome://blah" (and some
3354 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323355 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553356 params.referrer = Referrer();
3357
3358 // Navigations in Web UI pages count as browser-initiated navigations.
3359 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583360 }
[email protected]44d0930a2013-10-28 18:53:553361
3362 new_contents = OpenURL(params);
3363
[email protected]ae5184d62011-10-06 19:25:583364 if (new_contents) {
3365 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253366 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583367 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123368 dest_url,
[email protected]ae5184d62011-10-06 19:25:583369 referrer,
3370 disposition,
[email protected]44d0930a2013-10-28 18:53:553371 params.transition,
[email protected]ae5184d62011-10-06 19:25:583372 source_frame_id));
[email protected]420ae012009-04-24 05:16:323373 }
3374}
3375
[email protected]e1c3a552012-05-04 20:51:323376void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3377 // Tell the active RenderViewHost to run unload handlers and close, as long
3378 // as the request came from a RenderViewHost in the same BrowsingInstance.
3379 // In most cases, we receive this from a swapped out RenderViewHost.
3380 // It is possible to receive it from one that has just been swapped in,
3381 // in which case we might as well deliver the message anyway.
3382 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3383 GetRenderViewHost()->ClosePage();
3384}
3385
[email protected]f546640b2012-05-15 00:03:493386void WebContentsImpl::RouteMessageEvent(
3387 RenderViewHost* rvh,
3388 const ViewMsg_PostMessage_Params& params) {
3389 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363390 // came from a RenderViewHost in the same BrowsingInstance or if this
3391 // WebContents is dedicated to a browser plugin guest.
3392 // Note: This check means that an embedder could theoretically receive a
3393 // postMessage from anyone (not just its own guests). However, this is
3394 // probably not a risk for apps since other pages won't have references
3395 // to App windows.
3396 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3397 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493398 return;
3399
3400 ViewMsg_PostMessage_Params new_params(params);
3401
[email protected]0bc7f3542013-10-21 15:05:533402 if (!params.message_port_ids.empty()) {
3403 MessagePortMessageFilter* message_port_message_filter =
3404 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3405 ->message_port_message_filter();
3406 std::vector<int> new_routing_ids(params.message_port_ids.size());
3407 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3408 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3409 MessagePortService::GetInstance()->UpdateMessagePort(
3410 params.message_port_ids[i],
3411 message_port_message_filter,
3412 new_routing_ids[i]);
3413 }
3414 new_params.new_routing_ids = new_routing_ids;
3415 }
3416
[email protected]f546640b2012-05-15 00:03:493417 // If there is a source_routing_id, translate it to the routing ID for
3418 // the equivalent swapped out RVH in the target process. If we need
3419 // to create a swapped out RVH for the source tab, we create its opener
3420 // chain as well, since those will also be accessible to the target page.
3421 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3422 // Try to look up the WebContents for the source page.
3423 WebContentsImpl* source_contents = NULL;
3424 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3425 rvh->GetProcess()->GetID(), params.source_routing_id);
3426 if (source_rvh) {
3427 source_contents = static_cast<WebContentsImpl*>(
3428 source_rvh->GetDelegate()->GetAsWebContents());
3429 }
3430
3431 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363432 if (GetBrowserPluginGuest()) {
3433 // We create a swapped out RenderView for the embedder in the guest's
3434 // render process but we intentionally do not expose the embedder's
3435 // opener chain to it.
3436 new_params.source_routing_id =
3437 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3438 } else {
3439 new_params.source_routing_id =
3440 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3441 }
[email protected]f546640b2012-05-15 00:03:493442 } else {
3443 // We couldn't find it, so don't pass a source frame.
3444 new_params.source_routing_id = MSG_ROUTING_NONE;
3445 }
3446 }
3447
3448 // In most cases, we receive this from a swapped out RenderViewHost.
3449 // It is possible to receive it from one that has just been swapped in,
3450 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183451 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493452}
3453
[email protected]b172aee2012-04-10 17:05:263454void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343455 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263456 const base::string16& message,
3457 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323458 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213459 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323460 IPC::Message* reply_msg,
3461 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073462 // Suppress JavaScript dialogs when requested. Also suppress messages when
3463 // showing an interstitial as it's shown over the previous page and we don't
3464 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503465 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583466 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273467 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073468 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523469 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153470 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323471
3472 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213473 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433474 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153475 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3476 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433477 this,
3478 frame_url.GetOrigin(),
3479 accept_lang,
3480 javascript_message_type,
3481 message,
[email protected]51da7e32012-01-30 19:24:523482 default_prompt,
[email protected]b172aee2012-04-10 17:05:263483 base::Bind(&WebContentsImpl::OnDialogClosed,
3484 base::Unretained(this),
3485 rvh,
3486 reply_msg),
[email protected]51da7e32012-01-30 19:24:523487 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323488 }
[email protected]3ab9cb82011-06-03 18:02:073489
[email protected]6dd2f1e2013-09-11 15:06:013490 *did_suppress_message = suppress_this_message;
3491
[email protected]3ab9cb82011-06-03 18:02:073492 if (suppress_this_message) {
3493 // If we are suppressing messages, just reply as if the user immediately
3494 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263495 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073496 }
3497
[email protected]6dd2f1e2013-09-11 15:06:013498 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3499 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323500}
3501
[email protected]b172aee2012-04-10 17:05:263502void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263503 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263504 bool is_reload,
3505 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583506 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513507 if (delegate_)
3508 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073509
3510 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583511 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073512 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523513 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153514 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153515 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343516 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263517 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503518 return;
3519 }
[email protected]3ab9cb82011-06-03 18:02:073520
[email protected]7ab1e7d62009-10-14 23:32:013521 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153522 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3523 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323524 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263525 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523526 reply_msg));
[email protected]420ae012009-04-24 05:16:323527}
3528
[email protected]a796f202012-05-30 14:14:253529bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263530 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253531 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263532 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253533 if (!delegate_)
3534 return false;
3535 return delegate_->AddMessageToConsole(this, level, message, line_no,
3536 source_id);
3537}
3538
[email protected]b172aee2012-04-10 17:05:263539WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273540 // We want to base the page config off of the actual URL, rather than the
3541 // virtual URL.
3542 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3543 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003544 GURL url = controller_.GetActiveEntry()
3545 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153546
[email protected]fa944cb82013-11-15 17:51:213547 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323548}
3549
[email protected]0eba810b2012-10-18 03:19:363550int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213551 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413552 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3553 true, true);
[email protected]0eba810b2012-10-18 03:19:363554}
3555
[email protected]b172aee2012-04-10 17:05:263556void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273557 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253558 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223559
[email protected]ea114722012-03-12 01:11:253560 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173561 if (rdh) // NULL in unittests.
3562 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253563}
3564
[email protected]b172aee2012-04-10 17:05:263565void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443566 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253567 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443568}
3569
[email protected]b172aee2012-04-10 17:05:263570void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563571 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263572 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153573 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523574 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153575 return;
3576
[email protected]9f76c1e2012-03-05 15:15:583577 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3578
[email protected]e5fc1632011-08-08 07:51:533579 // Ignore renderer unresponsive event if debugger is attached to the tab
3580 // since the event may be a result of the renderer sitting on a breakpoint.
3581 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363582 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533583 return;
3584
[email protected]2e9d79f2013-08-16 05:45:563585 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323586 // Hang occurred while firing the beforeunload/unload handler.
3587 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583588 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323589
[email protected]fa944cb82013-11-15 17:51:213590 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323591 return;
3592
3593 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563594 // nothing we can do to recover. If the hang is in the beforeunload handler,
3595 // pretend the beforeunload listeners have all fired and allow the delegate
3596 // to continue closing; the user will not have the option of cancelling the
3597 // close. Otherwise, pretend the unload listeners have all fired and close
3598 // the tab.
3599 bool close = true;
3600 if (is_during_beforeunload) {
3601 delegate_->BeforeUnloadFired(this, true, &close);
3602 }
3603 if (close)
3604 Close(rvh);
[email protected]420ae012009-04-24 05:16:323605 return;
3606 }
3607
[email protected]9f76c1e2012-03-05 15:15:583608 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473609 return;
3610
[email protected]6934a702011-12-20 00:04:513611 if (delegate_)
3612 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323613}
3614
[email protected]b172aee2012-04-10 17:05:263615void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513616 if (delegate_)
3617 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323618}
3619
[email protected]b172aee2012-04-10 17:05:263620void WebContentsImpl::LoadStateChanged(
3621 const GURL& url,
3622 const net::LoadStateWithParam& load_state,
3623 uint64 upload_position,
3624 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323625 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563626 upload_position_ = upload_position;
3627 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503628 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213629 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303630 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213631 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323632 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463633 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213634 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463635 }
[email protected]420ae012009-04-24 05:16:323636}
3637
[email protected]b172aee2012-04-10 17:05:263638void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553639 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323640 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3642 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513643 if (delegate_)
3644 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093645 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323646}
3647
[email protected]58d5cfe2013-07-10 02:40:523648void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543649 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233650 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223651 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543652}
3653
[email protected]b172aee2012-04-10 17:05:263654void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103655 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213656 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263657 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3658 // here during container initialization and normal window size will be set
3659 // later. In case of tab duplication this resizing to 0x0 prevents setting
3660 // normal size later so just ignore it.
3661 if (!size.IsEmpty())
3662 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323663}
3664
[email protected]af905902013-10-01 21:38:513665void WebContentsImpl::CancelModalDialogsForRenderManager() {
3666 // We need to cancel modal dialogs when doing a process swap, since the load
3667 // deferrer would prevent us from swapping out.
3668 if (dialog_manager_)
3669 dialog_manager_->CancelActiveAndPendingDialogs(this);
3670}
3671
[email protected]7b712ee22013-10-03 00:57:283672void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3673 RenderViewHost* new_host) {
3674 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083675
3676 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003677 if (delegate_)
3678 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393679
[email protected]7b712ee22013-10-03 00:57:283680 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543681}
3682
[email protected]14392a52012-05-02 20:28:443683int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3684 SiteInstance* instance) {
3685 if (!opener_)
3686 return MSG_ROUTING_NONE;
3687
3688 // Recursively create RenderViews for anything else in the opener chain.
3689 return opener_->CreateOpenerRenderViews(instance);
3690}
3691
3692int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3693 int opener_route_id = MSG_ROUTING_NONE;
3694
3695 // If this tab has an opener, ensure it has a RenderView in the given
3696 // SiteInstance as well.
3697 if (opener_)
3698 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3699
[email protected]45a22ad2013-02-21 03:25:003700 // If any of the renderers (current, pending, or swapped out) for this
3701 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213702 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3703 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373704
[email protected]fa944cb82013-11-15 17:51:213705 if (GetRenderManager()->pending_render_view_host() &&
3706 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3707 instance)
3708 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003709
[email protected]fa944cb82013-11-15 17:51:213710 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373711 instance);
3712 if (rvh)
3713 return rvh->GetRoutingID();
3714
[email protected]14392a52012-05-02 20:28:443715 // Create a swapped out RenderView in the given SiteInstance if none exists,
3716 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413717 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3718 true, true);
[email protected]14392a52012-05-02 20:28:443719}
3720
[email protected]b172aee2012-04-10 17:05:263721NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193722 return GetController();
[email protected]3a3d47472010-07-15 21:03:543723}
3724
[email protected]b172aee2012-04-10 17:05:263725WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563726 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323727}
3728
[email protected]10f417c52011-12-28 21:04:233729NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263730 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323731 return controller_.GetLastCommittedEntry();
3732}
3733
[email protected]b172aee2012-04-10 17:05:263734bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443735 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033736 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443737 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323738 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523739
[email protected]420ae012009-04-24 05:16:323740 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443741 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213742 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323743
[email protected]74ce1ad2011-12-16 21:51:463744 // Make sure we use the correct starting page_id in the new RenderView.
3745 UpdateMaxPageIDIfNecessary(render_view_host);
3746 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583747 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463748
[email protected]9f76c1e2012-03-05 15:15:583749 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263750 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493751 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133752 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523753 return false;
[email protected]14392a52012-05-02 20:28:443754 }
[email protected]a4127722011-04-27 23:13:523755
[email protected]a220b5932013-09-21 03:47:443756#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503757 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3758 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443759 if (rwh_view) {
3760 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3761 render_widget_host->WasResized();
3762 }
[email protected]f8233cc2011-05-31 20:24:503763#endif
3764
[email protected]420ae012009-04-24 05:16:323765 return true;
3766}
3767
[email protected]7d244f12013-08-22 21:41:513768#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183769base::android::ScopedJavaLocalRef<jobject>
3770WebContentsImpl::GetJavaWebContents() {
3771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3772
3773 WebContentsAndroid* web_contents_android =
3774 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3775 if (!web_contents_android) {
3776 web_contents_android = new WebContentsAndroid(this);
3777 SetUserData(kWebContentsAndroidKey, web_contents_android);
3778 }
3779 return web_contents_android->GetJavaObject();
3780}
3781
[email protected]7d244f12013-08-22 21:41:513782bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3783 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3784 MSG_ROUTING_NONE);
3785}
3786#endif
3787
[email protected]b172aee2012-04-10 17:05:263788void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3789 IPC::Message* reply_msg,
3790 bool success,
[email protected]fcf75d42013-12-03 20:11:263791 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543792 if (is_showing_before_unload_dialog_ && !success) {
3793 // If a beforeunload dialog is canceled, we need to stop the throbber from
3794 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293795 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353796 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103797
[email protected]6d65a462013-06-21 21:29:123798 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3799 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543800 }
3801 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583802 static_cast<RenderViewHostImpl*>(
3803 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543804}
3805
[email protected]b172aee2012-04-10 17:05:263806void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213807 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123808 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103809}
[email protected]f45d2a72010-03-08 23:28:353810
[email protected]b172aee2012-04-10 17:05:263811void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103812 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443813 // Can be NULL during tests.
3814 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213815 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363816}
[email protected]9f76c1e2012-03-05 15:15:583817
[email protected]1ac10dca2013-08-20 20:47:043818bool WebContentsImpl::IsHidden() {
3819 return capturer_count_ == 0 && !should_normally_be_visible_;
3820}
3821
[email protected]b0936d22013-11-28 06:47:363822RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213823 return frame_tree_.root()->render_manager();
3824}
3825
[email protected]b172aee2012-04-10 17:05:263826RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583827 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3828}
[email protected]7900bfdb2012-05-24 19:31:243829
[email protected]f8497342013-02-05 22:15:023830BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393831 return browser_plugin_guest_.get();
3832}
3833
[email protected]738f57a2013-06-29 21:06:543834void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3835 CHECK(!browser_plugin_guest_);
3836 browser_plugin_guest_.reset(guest);
3837}
3838
[email protected]f8497342013-02-05 22:15:023839BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393840 return browser_plugin_embedder_.get();
3841}
[email protected]8ff00d72012-10-23 19:12:213842
[email protected]8eb04562013-03-06 03:41:143843BrowserPluginGuestManager*
3844 WebContentsImpl::GetBrowserPluginGuestManager() const {
3845 return static_cast<BrowserPluginGuestManager*>(
3846 GetBrowserContext()->GetUserData(
3847 browser_plugin::kBrowserPluginGuestManagerKeyName));
3848}
3849
[email protected]d9030b82013-07-19 08:26:063850void WebContentsImpl::ClearPowerSaveBlockers(
3851 RenderViewHost* render_view_host) {
3852 STLDeleteValues(&power_save_blockers_[render_view_host]);
3853 power_save_blockers_.erase(render_view_host);
3854}
3855
3856void WebContentsImpl::ClearAllPowerSaveBlockers() {
3857 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3858 i != power_save_blockers_.end(); ++i)
3859 STLDeleteValues(&power_save_blockers_[i->first]);
3860 power_save_blockers_.clear();
3861}
3862
[email protected]dc0fd432013-08-27 15:29:213863gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3864 gfx::Size size;
3865 if (delegate_)
3866 size = delegate_->GetSizeForNewRenderView(this);
3867 if (size.IsEmpty())
3868 size = view_->GetContainerSize();
3869 return size;
3870}
3871
[email protected]9b159a52013-10-03 17:24:553872void WebContentsImpl::OnFrameRemoved(
3873 RenderViewHostImpl* render_view_host,
3874 int64 frame_id) {
3875 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3876 FrameDetached(render_view_host, frame_id));
3877}
3878
[email protected]8ff00d72012-10-23 19:12:213879} // namespace content