blob: e05cab0f097872512e1ae9eee65624193aa7bcf7 [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]348fbaac2013-06-11 06:31:5115#include "base/strings/string16.h"
16#include "base/strings/string_number_conversions.h"
17#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3719#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3920#include "content/browser/browser_plugin/browser_plugin_embedder.h"
21#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1422#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1924#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]d4a8ca482013-10-30 21:06:4030#include "content/browser/frame_host/interstitial_page_impl.h"
31#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]190b8c52013-11-09 01:35:4432#include "content/browser/frame_host/navigator.h"
[email protected]5c9250872012-01-30 17:24:0533#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4434#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5335#include "content/browser/message_port_message_filter.h"
36#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0637#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3038#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3239#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5040#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3341#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1142#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5843#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0344#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5645#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1446#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4247#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]41225fe2013-03-29 05:32:0248#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5149#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0250#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5751#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5852#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1153#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2054#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4455#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3656#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1757#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1458#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4659#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1560#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0061#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2762#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0063#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3764#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1465#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3266#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3467#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3868#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4269#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2570#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1071#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2172#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4873#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5474#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4975#include "content/public/common/page_zoom.h"
[email protected]a1d29162011-10-14 17:14:0376#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1677#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2978#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5379#include "net/http/http_cache.h"
80#include "net/http/http_transaction_factory.h"
81#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3482#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5683#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0184#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4185#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5286#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1887#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3188
[email protected]583418cc2013-01-17 14:01:1089#if defined(OS_ANDROID)
90#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3291#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
92#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0093#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:1094#endif
95
[email protected]f66df822012-05-18 16:52:1796#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5097#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:2798#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5799#endif
[email protected]3e45ba92009-02-20 21:09:00100
[email protected]420ae012009-04-24 05:16:32101// Cross-Site Navigations
102//
[email protected]b172aee2012-04-10 17:05:26103// If a WebContentsImpl is told to navigate to a different web site (as
104// determined by SiteInstance), it will replace its current RenderViewHost with
105// a new RenderViewHost dedicated to the new SiteInstance. This works as
106// follows:
[email protected]420ae012009-04-24 05:16:32107//
[email protected]fc6c1872013-10-03 01:22:35108// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46109// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32110// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35111// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32112// run in the current RVH.
113// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35114// that it has a pending cross-site request. We will check this on the IO
115// thread when deciding how to handle the response.
116// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46117// cancel all the pending logic. Otherwise we allow the pending RVH to send
118// the navigation request to its renderer.
119// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35120// main resource load on the pending RVH. It creates a
121// CrossSiteResourceHandler to check whether a process swap is needed when
122// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46123// - When RDH receives a response, the BufferedResourceHandler determines
124// whether it is a download. If so, it sends a message to the new renderer
125// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26126// pending RVH remains until the next DidNavigate event for this
127// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32128// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35129// download, the CrossSiteResourceHandler checks whether a process swap is
130// needed (either because CrossSiteRequestManager has state for it or because
131// a transfer was needed for a redirect).
132// - If so, CrossSiteResourceHandler pauses the response to first run the old
133// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36134// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
135// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35136// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
137// to a new process is needed, based on the stored pending_nav_params_. (This
138// is independent of whether we started out with a cross-process navigation.)
139// - If not, it just tells the ResourceDispatcherHost to resume the response
140// to its current RenderViewHost.
141// - If so, it cancels the current pending RenderViewHost and sets up a new
142// navigation using RequestTransferURL. When the transferred request
143// arrives in the ResourceDispatcherHost, we transfer the response and
144// resume it.
[email protected]420ae012009-04-24 05:16:32145// - The pending renderer sends a FrameNavigate message that invokes the
146// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46147// pending RVH.
[email protected]b0936d22013-11-28 06:47:36148// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15149// the user goes back. The process only stays live if another tab is using
150// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32151
[email protected]8ff00d72012-10-23 19:12:21152namespace content {
[email protected]420ae012009-04-24 05:16:32153namespace {
154
[email protected]82114f52012-03-20 22:53:41155const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05156
[email protected]e4abd3b42013-11-12 18:28:47157base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46158g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
159
[email protected]795c28972012-12-06 06:13:39160static int StartDownload(content::RenderViewHost* rvh,
161 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29162 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30163 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02164 static int g_next_image_download_id = 0;
165 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
166 ++g_next_image_download_id,
167 url,
168 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30169 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02170 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39171}
172
[email protected]2c5569662011-03-22 20:45:02173ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21174 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50175 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16176 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23181 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
182 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16184 break; // Fall through to rest of function.
185 }
[email protected]5e369672009-11-03 23:48:30186
[email protected]59246c572012-02-10 13:32:13187 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
188 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36189 if (entry.restore_type() ==
190 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13191 if (entry.GetHasPostData())
192 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13194 }
[email protected]5e369672009-11-03 23:48:30195
[email protected]2c5569662011-03-22 20:45:02196 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30197}
198
[email protected]10f417c52011-12-28 21:04:23199void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47200 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21201 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50202 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16203 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51204 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13205 params->should_clear_history_list = entry.should_clear_history_list();
[email protected]4972fc82013-11-19 04:33:42206 params->should_replace_current_entry = entry.should_replace_entry();
[email protected]60d6cca2013-04-30 08:47:13207 if (entry.should_clear_history_list()) {
208 // Set the history list related parameters to the same values a
209 // NavigationController would return before its first navigation. This will
210 // fully clear the RenderView's view of the session history.
211 params->pending_history_list_offset = -1;
212 params->current_history_list_offset = -1;
213 params->current_history_list_length = 0;
214 } else {
215 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
216 params->current_history_list_offset =
217 controller.GetLastCommittedEntryIndex();
218 params->current_history_list_length = controller.GetEntryCount();
219 }
[email protected]eaaba7dd2013-10-14 02:38:07220 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36221 if (!entry.GetBaseURLForDataURL().is_empty()) {
222 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
223 params->history_url_for_data_url = entry.GetVirtualURL();
224 }
[email protected]36fc0392011-12-25 03:59:51225 params->referrer = entry.GetReferrer();
226 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04227 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00228 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55229 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34230 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47231 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48232 params->transferred_request_child_id =
233 entry.transferred_global_request_id().child_id;
234 params->transferred_request_request_id =
235 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22236 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00237 // Avoid downloading when in view-source mode.
238 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44239 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07240 if (entry.GetBrowserInitiatedPostData()) {
241 params->browser_initiated_post_data.assign(
242 entry.GetBrowserInitiatedPostData()->front(),
243 entry.GetBrowserInitiatedPostData()->front() +
244 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23245 }
246
[email protected]f8872902013-10-30 03:18:57247 params->redirects = entry.redirect_chain();
248
[email protected]951a64832012-10-11 16:26:37249 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58250 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37251
[email protected]6c6b02d2011-09-02 03:36:47252 if (delegate)
253 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34254}
255
[email protected]8bfc8272013-09-09 20:10:53256void NotifyCacheOnIO(
257 scoped_refptr<net::URLRequestContextGetter> request_context,
258 const GURL& url,
259 const std::string& http_method) {
260 request_context->GetURLRequestContext()->http_transaction_factory()->
261 GetCache()->OnExternalCacheHit(url, http_method);
262}
263
[email protected]9b159a52013-10-03 17:24:55264// Helper function for retrieving all the sites in a frame tree.
265bool CollectSites(BrowserContext* context,
266 std::set<GURL>* sites,
267 FrameTreeNode* node) {
268 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
269 return true;
270}
271
[email protected]420ae012009-04-24 05:16:32272} // namespace
273
[email protected]54944cde2012-12-09 09:24:59274WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15275 return WebContentsImpl::CreateWithOpener(
276 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19277}
278
279WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59280 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30281 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59282 WebContentsImpl* new_contents = new WebContentsImpl(
283 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30284
285 for (SessionStorageNamespaceMap::const_iterator it =
286 session_storage_namespace_map.begin();
287 it != session_storage_namespace_map.end();
288 ++it) {
289 new_contents->GetController()
290 .SetSessionStorageNamespace(it->first, it->second.get());
291 }
292
[email protected]54944cde2012-12-09 09:24:59293 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19294 return new_contents;
[email protected]a81343d232011-12-27 07:39:20295}
[email protected]746d3052012-05-22 15:15:47296
[email protected]e4abd3b42013-11-12 18:28:47297void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46298 g_created_callbacks.Get().push_back(callback);
299}
300
[email protected]e4abd3b42013-11-12 18:28:47301void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46302 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
303 if (g_created_callbacks.Get().at(i).Equals(callback)) {
304 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
305 return;
306 }
307 }
308}
309
[email protected]299d7f12012-05-23 05:31:15310WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47311 return rvh->GetDelegate()->GetAsWebContents();
312}
313
[email protected]7fff43e2013-05-21 20:21:10314// WebContentsImpl::DestructionObserver ----------------------------------------
315
316class WebContentsImpl::DestructionObserver : public WebContentsObserver {
317 public:
318 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
319 : WebContentsObserver(watched_contents),
320 owner_(owner) {
321 }
322
323 // WebContentsObserver:
324 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
325 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
326 }
327
328 private:
329 WebContentsImpl* owner_;
330
331 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
332};
333
[email protected]b172aee2012-04-10 17:05:26334// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32335
[email protected]b172aee2012-04-10 17:05:26336WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21337 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19338 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42339 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22340 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57341 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44342 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41343#if defined(OS_WIN) && defined(USE_AURA)
344 accessible_parent_(NULL),
345#endif
[email protected]fa944cb82013-11-15 17:51:21346 frame_tree_(new Navigator(&controller_, this), this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34347 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23348 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
349 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34350 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21351 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56352 upload_size_(0),
353 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47354 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55355 capturer_count_(0),
356 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57357 is_being_destroyed_(false),
358 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15359 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01360 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38361 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21362 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
363 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00364 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21365 color_chooser_identifier_(0),
[email protected]f8bebfb2013-03-06 04:22:58366 message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54367 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46368 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
369 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55370 frame_tree_.SetFrameRemoveListener(
371 base::Bind(&WebContentsImpl::OnFrameRemoved,
372 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35373}
initial.commit09911bf2008-07-26 23:55:29374
[email protected]b172aee2012-04-10 17:05:26375WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32376 is_being_destroyed_ = true;
377
[email protected]d9030b82013-07-19 08:26:06378 ClearAllPowerSaveBlockers();
379
[email protected]b24b68a2012-09-24 21:57:26380 for (std::set<RenderWidgetHostImpl*>::iterator iter =
381 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
382 (*iter)->DetachDelegate();
383 }
384 created_widgets_.clear();
385
[email protected]3ab9cb82011-06-03 18:02:07386 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15387 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11388 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07389
[email protected]da8543762012-03-20 08:52:20390 if (color_chooser_)
391 color_chooser_->End();
392
[email protected]420ae012009-04-24 05:16:32393 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32394
[email protected]ca13a442012-04-17 14:00:12395 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21396 NotificationService::current()->Notify(
397 NOTIFICATION_WEB_CONTENTS_DESTROYED,
398 Source<WebContents>(this),
399 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32400
401 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07402#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32403 // If we still have a window handle, destroy it. GetNativeView can return
404 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06405 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52406 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58407 if (host && host->GetView())
408 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42409 }
[email protected]420ae012009-04-24 05:16:32410#endif
[email protected]7ab1e7d62009-10-14 23:32:01411
[email protected]fa944cb82013-11-15 17:51:21412 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27413 if (pending_rvh) {
414 FOR_EACH_OBSERVER(WebContentsObserver,
415 observers_,
416 RenderViewDeleted(pending_rvh));
417 }
418
419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
[email protected]fa944cb82013-11-15 17:51:21421 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27422
[email protected]2db9bd72012-04-13 20:20:56423 FOR_EACH_OBSERVER(WebContentsObserver,
424 observers_,
425 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08426
[email protected]6934a702011-12-20 00:04:51427 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10428
429 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
430 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42431}
432
[email protected]d1198fd2012-08-13 22:50:19433WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59434 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19435 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03436 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59437 WebContentsImpl* new_contents = new WebContentsImpl(
438 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19439
[email protected]54944cde2012-12-09 09:24:59440 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19441 return new_contents;
442}
443
[email protected]b371a5652013-02-20 11:25:51444// static
[email protected]8eb04562013-03-06 03:41:14445BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36446 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53447 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54448 int guest_instance_id,
449 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39450 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39451
452 // This makes |new_contents| act as a guest.
453 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54454 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19455 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11456
[email protected]3de10bb32013-01-08 21:57:33457 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33458 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11459
[email protected]216be772013-01-25 00:22:27460 // We are instantiating a WebContents for browser plugin. Set its subframe bit
461 // to true.
462 static_cast<RenderViewHostImpl*>(
463 new_contents->GetRenderViewHost())->set_is_subframe(true);
464
[email protected]8eb04562013-03-06 03:41:14465 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39466}
467
[email protected]b0936d22013-11-28 06:47:36468RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21469 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28470}
471
[email protected]7bb761892012-07-20 09:32:47472bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
473 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56474 if (GetWebUI() &&
475 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17476 return true;
[email protected]d2353452012-01-19 19:53:56477 }
[email protected]f82d57b52011-04-27 19:13:17478
[email protected]d8c660432011-12-22 20:51:25479 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
480 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10481 while ((observer = it.GetNext()) != NULL)
482 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53483 return true;
[email protected]403415a2011-01-10 18:57:53484
[email protected]7bb761892012-07-20 09:32:47485 // Message handlers should be aware of which RenderViewHost sent the
486 // message, which is temporarily stored in message_source_.
487 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18488 bool handled = true;
489 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26490 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]724159a2010-12-30 01:11:18491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
492 OnDidLoadResourceFromMemoryCache)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
494 OnDidDisplayInsecureContent)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
496 OnDidRunInsecureContent)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
498 OnDocumentLoadedInFrame)
499 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26500 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
501 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25502 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26503 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21504 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20505 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
507 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16508 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45509 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10510 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20511 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
514 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29515 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50516 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50517 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
518 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55519 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
520 OnBrowserPluginMessage(message))
521 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
522 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02523 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10525#if defined(OS_ANDROID)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
527 OnFindMatchRectsReply)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
529 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32530 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
531 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10532#endif
[email protected]d9030b82013-07-19 08:26:06533 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
535 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18536 IPC_MESSAGE_UNHANDLED(handled = false)
537 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47538 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18539
540 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21541 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18542 GetRenderProcessHost()->ReceivedBadMessage();
543 }
544
545 return handled;
546}
547
[email protected]b172aee2012-04-10 17:05:26548void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18549 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21550 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43551 if (delegate_)
552 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18553}
554
[email protected]d1198fd2012-08-13 22:50:19555NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56556 return controller_;
557}
558
[email protected]d1198fd2012-08-13 22:50:19559const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56560 return controller_;
561}
562
[email protected]8ff00d72012-10-23 19:12:21563BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55564 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30565}
566
[email protected]b172aee2012-04-10 17:05:26567const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24568 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32569 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51570 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31571}
572
[email protected]a093ce02013-07-22 20:53:14573const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24574 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32575 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24576 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
577}
578
579const GURL& WebContentsImpl::GetLastCommittedURL() const {
580 // We may not have a navigation entry yet.
581 NavigationEntry* entry = controller_.GetLastCommittedEntry();
582 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
583}
584
[email protected]8ff00d72012-10-23 19:12:21585WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31586 return delegate_;
587}
588
[email protected]8ff00d72012-10-23 19:12:21589void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31590 // TODO(cbentzel): remove this debugging code?
591 if (delegate == delegate_)
592 return;
593 if (delegate_)
594 delegate_->Detach(this);
595 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08596 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31597 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08598 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00599 if (view_)
600 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08601 }
[email protected]be1f56ab2011-12-22 06:55:31602}
603
[email protected]8ff00d72012-10-23 19:12:21604RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21605 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41606 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16607}
608
[email protected]b172aee2012-04-10 17:05:26609RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21610 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31611}
612
[email protected]a04c9d02012-11-14 21:04:34613void WebContentsImpl::GetRenderViewHostAtPosition(
614 int x,
615 int y,
616 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
617 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
618 if (embedder)
619 embedder->GetRenderViewHostAtPosition(x, y, callback);
620 else
621 callback.Run(GetRenderViewHost(), x, y);
622}
623
[email protected]bfcfa692013-02-07 06:17:02624WebContents* WebContentsImpl::GetEmbedderWebContents() const {
625 BrowserPluginGuest* guest = GetBrowserPluginGuest();
626 if (guest)
627 return guest->embedder_web_contents();
628 return NULL;
629}
630
631int WebContentsImpl::GetEmbeddedInstanceID() const {
632 BrowserPluginGuest* guest = GetBrowserPluginGuest();
633 if (guest)
634 return guest->instance_id();
635 return 0;
636}
637
[email protected]6b618e62012-08-16 12:59:18638int WebContentsImpl::GetRoutingID() const {
639 if (!GetRenderViewHost())
640 return MSG_ROUTING_NONE;
641
642 return GetRenderViewHost()->GetRoutingID();
643}
644
[email protected]44470a22013-01-24 01:21:54645int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
646 return fullscreen_widget_routing_id_;
647}
648
[email protected]b172aee2012-04-10 17:05:26649RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21650 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31651}
652
[email protected]f8497342013-02-05 22:15:02653RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
654 BrowserPluginGuest* guest = GetBrowserPluginGuest();
655 if (guest && guest->embedder_web_contents()) {
656 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
657 }
658 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
659}
660
[email protected]4aebbca2013-09-17 22:26:49661RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
662 const {
663 RenderWidgetHost* const widget_host =
664 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
665 GetFullscreenWidgetRoutingID());
666 return widget_host ? widget_host->GetView() : NULL;
667}
668
[email protected]8ff00d72012-10-23 19:12:21669WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31670 return view_.get();
671}
672
[email protected]8ff00d72012-10-23 19:12:21673WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56674 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03675 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
676 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22677 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58678 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22679 web_ui->SetController(controller);
680 return web_ui;
681 }
682
683 delete web_ui;
684 return NULL;
685}
686
[email protected]8ff00d72012-10-23 19:12:21687WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21688 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
689 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31690}
691
[email protected]8ff00d72012-10-23 19:12:21692WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21693 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34694}
695
[email protected]86ef6a392012-05-11 22:03:11696void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22697 if (GetUserAgentOverride() == override)
698 return;
699
700 renderer_preferences_.user_agent_override = override;
701
702 // Send the new override string to the renderer.
703 RenderViewHost* host = GetRenderViewHost();
704 if (host)
705 host->SyncRendererPrefs();
706
707 // Reload the page if a load is currently in progress to avoid having
708 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27709 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22710 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
711 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53712
713 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
714 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11715}
716
717const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22718 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11719}
720
[email protected]c73a2282013-04-29 21:10:41721#if defined(OS_WIN) && defined(USE_AURA)
722void WebContentsImpl::SetParentNativeViewAccessible(
723gfx::NativeViewAccessible accessible_parent) {
724 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45725 if (GetRenderViewHost())
726 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41727}
728#endif
729
[email protected]b172aee2012-04-10 17:05:26730const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55731 // Transient entries take precedence. They are used for interstitial pages
732 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23733 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08734 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21735 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30736 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23737 if (entry) {
[email protected]b5cca982011-05-26 04:42:08738 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23739 }
[email protected]fa944cb82013-11-15 17:51:21740 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
741 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58742 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54743 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32744 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54745 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35746 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22747 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54748 if (!title.empty())
749 return title;
750 }
751 }
752
753 // We use the title for the last committed entry rather than a pending
754 // navigation entry. For example, when the user types in a URL, we want to
755 // keep the old page's title until the new load has committed and we get a new
756 // title.
[email protected]96d185d2009-04-24 03:28:54757 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32758
[email protected]9eeafc012013-11-25 23:49:47759 // We make an exception for initial navigations.
760 if (controller_.IsInitialNavigation()) {
761 // We only want to use the title from the visible entry in one of two cases:
762 // 1. There's already a committed entry for an initial navigation, in which
763 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
764 // 2. The pending entry has been explicitly assigned a title to display.
765 //
766 // If there's no last committed entry and no assigned title, we should fall
767 // back to |page_title_when_no_navigation_entry_| rather than showing the
768 // URL.
769 if (entry ||
770 (controller_.GetVisibleEntry() &&
771 !controller_.GetVisibleEntry()->GetTitle().empty())) {
772 entry = controller_.GetVisibleEntry();
773 }
774 }
[email protected]59167c22013-06-03 18:07:32775
[email protected]45d0ef7f2011-01-05 13:46:23776 if (entry) {
[email protected]b5cca982011-05-26 04:42:08777 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23778 }
[email protected]987fc3a2011-05-26 14:18:09779
780 // |page_title_when_no_navigation_entry_| is finally used
781 // if no title cannot be retrieved.
782 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54783}
784
[email protected]b172aee2012-04-10 17:05:26785int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46786 return GetMaxPageIDForSiteInstance(GetSiteInstance());
787}
788
[email protected]b172aee2012-04-10 17:05:26789int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
790 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33791 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
792 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46793
[email protected]b6583592012-01-25 19:52:33794 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34795}
796
[email protected]b172aee2012-04-10 17:05:26797void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46798 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
799}
800
[email protected]b172aee2012-04-10 17:05:26801void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33802 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46803 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33804 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34805}
806
[email protected]ec6c05f2013-10-23 18:41:57807void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
808 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
809 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57810}
811
[email protected]b172aee2012-04-10 17:05:26812SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21813 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54814}
815
[email protected]b172aee2012-04-10 17:05:26816SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21817 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
818 GetRenderManager()->pending_render_view_host() :
819 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58820 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38821}
822
[email protected]b172aee2012-04-10 17:05:26823bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31824 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49825}
826
[email protected]b172aee2012-04-10 17:05:26827bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31828 return waiting_for_response_;
829}
830
[email protected]b172aee2012-04-10 17:05:26831const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31832 return load_state_;
833}
834
[email protected]b172aee2012-04-10 17:05:26835const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31836 return load_state_host_;
837}
838
[email protected]b172aee2012-04-10 17:05:26839uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31840 return upload_size_;
841}
842
[email protected]b172aee2012-04-10 17:05:26843uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31844 return upload_position_;
845}
846
[email protected]1ae93fb2013-06-14 03:38:56847std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56848 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55849 frame_tree_.ForEach(Bind(&CollectSites,
850 base::Unretained(GetBrowserContext()),
851 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56852 return sites;
853}
854
[email protected]b172aee2012-04-10 17:05:26855const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return encoding_;
857}
858
[email protected]b172aee2012-04-10 17:05:26859bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31860 return displayed_insecure_content_;
861}
862
[email protected]54597982013-02-06 01:59:55863void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25864 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55865 ++capturer_count_;
866 DVLOG(1) << "There are now " << capturer_count_
867 << " capturing(s) of WebContentsImpl@" << this;
868}
869
870void WebContentsImpl::DecrementCapturerCount() {
871 --capturer_count_;
872 DVLOG(1) << "There are now " << capturer_count_
873 << " capturing(s) of WebContentsImpl@" << this;
874 DCHECK_LE(0, capturer_count_);
875
[email protected]5a652232013-02-12 06:15:25876 if (is_being_destroyed_)
877 return;
878
[email protected]1ac10dca2013-08-20 20:47:04879 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55880 DVLOG(1) << "Executing delayed WasHidden().";
881 WasHidden();
882 }
[email protected]be1f56ab2011-12-22 06:55:31883}
884
[email protected]f2bd40812013-07-20 04:30:44885int WebContentsImpl::GetCapturerCount() const {
886 return capturer_count_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
891 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
892 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49893}
894
[email protected]b172aee2012-04-10 17:05:26895void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
896 int error_code) {
[email protected]443b80e2010-12-14 00:42:23897 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34898 return;
899
[email protected]443b80e2010-12-14 00:42:23900 crashed_status_ = status;
901 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21902 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34903}
904
[email protected]b172aee2012-04-10 17:05:26905base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return crashed_status_;
907}
908
[email protected]b172aee2012-04-10 17:05:26909bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31910 return is_being_destroyed_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34914 if (delegate_)
915 delegate_->NavigationStateChanged(this, changed_flags);
916}
917
[email protected]3e324142012-06-25 18:26:33918base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
919 return last_selected_time_;
920}
921
[email protected]9e2e4632012-07-27 16:38:41922void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54923 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04924 RenderWidgetHostViewPort* rwhv =
925 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16926 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29927 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43928#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16929 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43930#endif
931 }
[email protected]96d185d2009-04-24 03:28:54932
[email protected]5ac20162010-11-24 23:33:11933 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38934
[email protected]b9769d82012-02-10 00:23:59935 // The resize rect might have changed while this was inactive -- send the new
936 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58937 RenderViewHostImpl* rvh =
938 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59939 if (rvh) {
940 rvh->ResizeRectChanged(GetRootWindowResizerRect());
941 }
[email protected]96d185d2009-04-24 03:28:54942
[email protected]c0d9d5672013-10-09 07:38:03943 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
944
[email protected]54597982013-02-06 01:59:55945 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31946}
947
[email protected]b172aee2012-04-10 17:05:26948void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55949 // If there are entities capturing screenshots or video (e.g., mirroring),
950 // don't activate the "disable rendering" optimization.
951 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52952 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55953 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26954 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52955 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33956 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52957 // calls us).
[email protected]c30585c2012-02-16 15:02:04958 RenderWidgetHostViewPort* rwhv =
959 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16960 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29961 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54962 }
963
[email protected]c0d9d5672013-10-09 07:38:03964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
965
[email protected]54597982013-02-06 01:59:55966 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37967}
968
[email protected]b172aee2012-04-10 17:05:26969bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31970 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27971 return WillNotifyDisconnection() &&
972 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58973 !static_cast<RenderViewHostImpl*>(
974 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31975}
976
[email protected]b172aee2012-04-10 17:05:26977void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21978 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40979 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27980}
981
[email protected]b172aee2012-04-10 17:05:26982WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44983 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45984 // We pass our own opener so that the cloned page can access it if it was
985 // before.
[email protected]54944cde2012-12-09 09:24:59986 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45987 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59988 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19989 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22990 FOR_EACH_OBSERVER(WebContentsObserver,
991 observers_,
992 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27993 return tc;
994}
995
[email protected]14392a52012-05-02 20:28:44996void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21997 const NotificationSource& source,
998 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44999 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211000 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1001 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501002 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1003 i != pending_widget_views_.end(); ++i) {
1004 if (host->GetView() == i->second) {
1005 pending_widget_views_.erase(i);
1006 break;
1007 }
1008 }
1009 break;
1010 }
[email protected]14392a52012-05-02 20:28:441011 default:
1012 NOTREACHED();
1013 }
1014}
1015
[email protected]ec6c05f2013-10-23 18:41:571016WebContents* WebContentsImpl::GetWebContents() {
1017 return this;
1018}
1019
[email protected]54944cde2012-12-09 09:24:591020void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211021 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361022 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211023 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431024 should_normally_be_visible_ = !params.initially_hidden;
1025
[email protected]fa944cb82013-11-15 17:51:211026 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041027 params.browser_context, params.site_instance, params.routing_id,
1028 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191029
[email protected]8ff00d72012-10-23 19:12:211030 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191031 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271032 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191033 CHECK(render_view_host_delegate_view_);
1034 } else {
[email protected]f8497342013-02-05 22:15:021035 WebContentsViewDelegate* delegate =
1036 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1037
[email protected]59383c782013-04-17 16:43:271038 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381039 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1040 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021041
[email protected]b5a40842012-11-28 15:26:111042 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381043 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431044 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111045 render_view_host_delegate_view_ = rv;
1046 view_.reset(rv);
1047 } else {
[email protected]f8497342013-02-05 22:15:021048 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111049 view_.reset(CreateWebContentsView(
1050 this, delegate, &render_view_host_delegate_view_));
1051 }
[email protected]d1198fd2012-08-13 22:50:191052 CHECK(render_view_host_delegate_view_);
1053 }
1054 CHECK(view_.get());
1055
[email protected]ed245db2012-12-18 08:00:451056 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591057 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191058
1059 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101060 if (opener_)
1061 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191062
1063 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211064 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1065 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441066#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191067 java_bridge_dispatcher_host_manager_.reset(
1068 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101069 date_time_chooser_.reset(new DateTimeChooserAndroid());
1070#endif
[email protected]d1198fd2012-08-13 22:50:191071}
1072
[email protected]7fff43e2013-05-21 20:21:101073void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1074 RemoveDestructionObserver(web_contents);
1075
[email protected]14392a52012-05-02 20:28:441076 // Clear the opener if it has been closed.
1077 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441078 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511079 return;
[email protected]14392a52012-05-02 20:28:441080 }
[email protected]ceee8cd2013-03-08 04:59:511081 // Clear a pending contents that has been closed before being shown.
1082 for (PendingContents::iterator iter = pending_contents_.begin();
1083 iter != pending_contents_.end();
1084 ++iter) {
1085 if (iter->second != web_contents)
1086 continue;
1087 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511088 return;
1089 }
1090 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441091}
1092
[email protected]7fff43e2013-05-21 20:21:101093void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1094 if (!ContainsKey(destruction_observers_, web_contents)) {
1095 destruction_observers_[web_contents] =
1096 new DestructionObserver(this, web_contents);
1097 }
1098}
1099
1100void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1101 DestructionObservers::iterator iter =
1102 destruction_observers_.find(web_contents);
1103 if (iter != destruction_observers_.end()) {
1104 delete destruction_observers_[web_contents];
1105 destruction_observers_.erase(iter);
1106 }
1107}
1108
[email protected]b172aee2012-04-10 17:05:261109void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311110 observers_.AddObserver(observer);
1111}
1112
[email protected]b172aee2012-04-10 17:05:261113void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311114 observers_.RemoveObserver(observer);
1115}
1116
[email protected]b172aee2012-04-10 17:05:261117void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341118 if (delegate_)
1119 delegate_->ActivateContents(this);
1120}
1121
[email protected]b172aee2012-04-10 17:05:261122void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121123 if (delegate_)
1124 delegate_->DeactivateContents(this);
1125}
1126
[email protected]b172aee2012-04-10 17:05:261127void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481128 if (delegate_)
1129 delegate_->LostCapture();
1130}
1131
[email protected]b24b68a2012-09-24 21:57:261132void WebContentsImpl::RenderWidgetDeleted(
1133 RenderWidgetHostImpl* render_widget_host) {
1134 if (is_being_destroyed_) {
1135 // |created_widgets_| might have been destroyed.
1136 return;
1137 }
1138
1139 std::set<RenderWidgetHostImpl*>::iterator iter =
1140 created_widgets_.find(render_widget_host);
1141 if (iter != created_widgets_.end())
1142 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541143
1144 if (render_widget_host &&
1145 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491146 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1147 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541148 FOR_EACH_OBSERVER(WebContentsObserver,
1149 observers_,
1150 DidDestroyFullscreenWidget(
1151 fullscreen_widget_routing_id_));
1152 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1153 }
[email protected]b24b68a2012-09-24 21:57:261154}
1155
[email protected]b172aee2012-04-10 17:05:261156bool WebContentsImpl::PreHandleKeyboardEvent(
1157 const NativeWebKeyboardEvent& event,
1158 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481159 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131160 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481161}
1162
[email protected]b172aee2012-04-10 17:05:261163void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061164 if (browser_plugin_embedder_ &&
1165 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1166 return;
1167 }
1168
[email protected]63954792011-07-11 04:17:481169 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131170 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481171}
1172
[email protected]fb3f066e2013-02-12 19:12:521173bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461174 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191175#if !defined(OS_MACOSX)
1176 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1177 // isn't done for two reasons:
1178 // -the OS already has a gesture to do this through pinch-zoom
1179 // -if a user starts an inertial scroll, let's go, and presses control
1180 // (i.e. control+tab) then the OS's buffered scroll events will come in
1181 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521182 if (delegate_ &&
1183 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461184 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521185 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1186 return true;
1187 }
[email protected]bccc4472013-04-18 16:37:191188#endif
[email protected]fb3f066e2013-02-12 19:12:521189
1190 return false;
1191}
1192
[email protected]c73a2282013-04-29 21:10:411193#if defined(OS_WIN) && defined(USE_AURA)
1194gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1195 return accessible_parent_;
1196}
1197#endif
1198
[email protected]b172aee2012-04-10 17:05:261199void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431200 if (delegate_)
1201 delegate_->HandleMouseDown();
1202}
1203
[email protected]b172aee2012-04-10 17:05:261204void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481205 if (delegate_)
1206 delegate_->HandleMouseUp();
1207}
1208
[email protected]590a634e2012-07-19 16:38:231209void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481210 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231211 delegate_->HandlePointerActivate();
1212}
1213
1214void WebContentsImpl::HandleGestureBegin() {
1215 if (delegate_)
1216 delegate_->HandleGestureBegin();
1217}
1218
1219void WebContentsImpl::HandleGestureEnd() {
1220 if (delegate_)
1221 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481222}
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491225 // This method is being called to enter or leave renderer-initiated fullscreen
1226 // mode. Either way, make sure any existing fullscreen widget is shut down
1227 // first.
1228 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1229 if (widget_view)
1230 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1231
[email protected]8a5e0ca2011-08-25 06:30:471232 if (delegate_)
1233 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1234}
1235
[email protected]b172aee2012-04-10 17:05:261236bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381237 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121238}
1239
[email protected]a9c81f02012-06-01 00:15:441240void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1241 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371242 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441243 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371244 } else {
1245 GotResponseToLockMouseRequest(false);
1246 }
1247}
1248
[email protected]b172aee2012-04-10 17:05:261249void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371250 if (delegate_)
1251 delegate_->LostMouseLock();
1252}
1253
[email protected]bafe6cd2012-05-23 23:09:501254void WebContentsImpl::CreateNewWindow(
1255 int route_id,
[email protected]227692c52013-05-31 22:43:041256 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131257 const ViewHostMsg_CreateWindow_Params& params,
1258 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501259 // We usually create the new window in the same BrowsingInstance (group of
1260 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551261 // if the opener is being suppressed (in a non-guest), we create a new
1262 // SiteInstance in its own BrowsingInstance.
1263 bool is_guest = GetRenderProcessHost()->IsGuest();
1264
[email protected]bafe6cd2012-05-23 23:09:501265 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551266 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571267 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501268 GetSiteInstance();
1269
[email protected]d1198fd2012-08-13 22:50:191270 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341271 //
1272 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301273 const std::string& partition_id =
1274 GetContentClient()->browser()->
1275 GetStoragePartitionIdForSite(GetBrowserContext(),
1276 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461277 StoragePartition* partition = BrowserContext::GetStoragePartition(
1278 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411279 DOMStorageContextWrapper* dom_storage_context =
1280 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191281 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1282 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1283 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371284
1285 if (delegate_ &&
1286 !delegate_->ShouldCreateWebContents(this,
1287 route_id,
1288 params.window_container_type,
1289 params.frame_name,
1290 params.target_url,
1291 partition_id,
1292 session_storage_namespace)) {
1293 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1294 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1295 main_frame_route_id);
1296 return;
1297 }
1298
1299 // Create the new web contents. This will automatically create the new
1300 // WebContentsView. In the future, we may want to create the view separately.
1301 WebContentsImpl* new_contents =
1302 new WebContentsImpl(GetBrowserContext(),
1303 params.opener_suppressed ? NULL : this);
1304
[email protected]d1198fd2012-08-13 22:50:191305 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301306 partition_id,
[email protected]d1198fd2012-08-13 22:50:191307 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461308 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591309 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041310 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551311 if (!is_guest) {
1312 create_params.context = view_->GetNativeView();
1313 create_params.initial_size = view_->GetContainerSize();
1314 } else {
1315 // This makes |new_contents| act as a guest.
1316 // For more info, see comment above class BrowserPluginGuest.
1317 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1318 WebContentsImpl* new_contents_impl =
1319 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461320 BrowserPluginGuest::CreateWithOpener(instance_id,
1321 new_contents_impl->opener() != NULL,
1322 new_contents_impl,
1323 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551324 }
[email protected]1ac10dca2013-08-20 20:47:041325 if (params.disposition == NEW_BACKGROUND_TAB)
1326 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591327 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191328
[email protected]c4538072013-03-18 02:17:551329 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341330 // will be shown immediately).
1331 if (!params.opener_suppressed) {
1332 if (!is_guest) {
1333 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501334
[email protected]d70bea92013-04-05 04:23:341335 // TODO(brettw): It seems bogus that we have to call this function on the
1336 // newly created object and give it one of its own member variables.
1337 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1338 }
[email protected]bafe6cd2012-05-23 23:09:501339 // Save the created window associated with the route so we can show it
1340 // later.
1341 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1342 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101343 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501344 }
1345
1346 if (delegate_) {
1347 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131348 this, params.opener_frame_id, params.frame_name,
1349 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501350 }
1351
1352 if (params.opener_suppressed) {
1353 // When the opener is suppressed, the original renderer cannot access the
1354 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001355 bool was_blocked = false;
1356 if (delegate_) {
1357 gfx::Rect initial_pos;
1358 delegate_->AddNewContents(
1359 this, new_contents, params.disposition, initial_pos,
1360 params.user_gesture, &was_blocked);
1361 }
1362 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211363 OpenURLParams open_params(params.target_url,
1364 Referrer(),
1365 CURRENT_TAB,
1366 PAGE_TRANSITION_LINK,
1367 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301368 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001369 new_contents->OpenURL(open_params);
1370 }
[email protected]bafe6cd2012-05-23 23:09:501371 }
1372}
1373
1374void WebContentsImpl::CreateNewWidget(int route_id,
[email protected]180ef242013-11-07 06:50:461375 blink::WebPopupType popup_type) {
[email protected]bafe6cd2012-05-23 23:09:501376 CreateNewWidget(route_id, false, popup_type);
1377}
1378
1379void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
[email protected]180ef242013-11-07 06:50:461380 CreateNewWidget(route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501381}
1382
1383void WebContentsImpl::CreateNewWidget(int route_id,
1384 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461385 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211386 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501387 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041388 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261389 created_widgets_.insert(widget_host);
1390
[email protected]83918ec2013-01-10 15:37:191391 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1392 view_->CreateViewForPopupWidget(widget_host));
1393 if (!widget_view)
1394 return;
[email protected]bafe6cd2012-05-23 23:09:501395 if (!is_fullscreen) {
1396 // Popups should not get activated.
1397 widget_view->SetPopupType(popup_type);
1398 }
1399 // Save the created widget associated with the route so we can show it later.
1400 pending_widget_views_[route_id] = widget_view;
1401
1402#if defined(OS_MACOSX)
1403 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1404 // to allow it to survive the trip without being hosted.
1405 base::mac::NSObjectRetain(widget_view->GetNativeView());
1406#endif
1407}
1408
1409void WebContentsImpl::ShowCreatedWindow(int route_id,
1410 WindowOpenDisposition disposition,
1411 const gfx::Rect& initial_pos,
1412 bool user_gesture) {
1413 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001414 if (contents) {
1415 WebContentsDelegate* delegate = GetDelegate();
1416 if (delegate) {
1417 delegate->AddNewContents(
1418 this, contents, disposition, initial_pos, user_gesture, NULL);
1419 }
1420 }
[email protected]bafe6cd2012-05-23 23:09:501421}
1422
1423void WebContentsImpl::ShowCreatedWidget(int route_id,
1424 const gfx::Rect& initial_pos) {
1425 ShowCreatedWidget(route_id, false, initial_pos);
1426}
1427
1428void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1429 ShowCreatedWidget(route_id, true, gfx::Rect());
1430}
1431
1432void WebContentsImpl::ShowCreatedWidget(int route_id,
1433 bool is_fullscreen,
1434 const gfx::Rect& initial_pos) {
1435 if (delegate_)
1436 delegate_->RenderWidgetShowing();
1437
1438 RenderWidgetHostViewPort* widget_host_view =
1439 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1440 if (!widget_host_view)
1441 return;
[email protected]4aebbca2013-09-17 22:26:491442 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311443 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1444 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491445 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1446 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1447 delegate_->ToggleFullscreenModeForTab(this, true);
1448 } else {
1449 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491450 }
[email protected]4aebbca2013-09-17 22:26:491451 FOR_EACH_OBSERVER(WebContentsObserver,
1452 observers_,
1453 DidShowFullscreenWidget(route_id));
1454 if (!widget_host_view->HasFocus())
1455 widget_host_view->Focus();
1456 } else {
[email protected]f8497342013-02-05 22:15:021457 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491458 }
[email protected]89054502012-06-03 10:29:241459
1460 RenderWidgetHostImpl* render_widget_host_impl =
1461 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1462 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311463 // Only allow privileged mouse lock for fullscreen render widget, which is
1464 // used to implement Pepper Flash fullscreen.
1465 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501466
1467#if defined(OS_MACOSX)
1468 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1469 // properly embedded (or purposefully ignored) we can release the retain we
1470 // took in CreateNewWidget().
1471 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1472#endif
1473}
1474
1475WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1476 PendingContents::iterator iter = pending_contents_.find(route_id);
1477
1478 // Certain systems can block the creation of new windows. If we didn't succeed
1479 // in creating one, just return NULL.
1480 if (iter == pending_contents_.end()) {
1481 return NULL;
1482 }
1483
1484 WebContentsImpl* new_contents = iter->second;
1485 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101486 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501487
[email protected]d70bea92013-04-05 04:23:341488 // Don't initialize the guest WebContents immediately.
1489 if (new_contents->GetRenderProcessHost()->IsGuest())
1490 return new_contents;
1491
[email protected]bafe6cd2012-05-23 23:09:501492 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1493 !new_contents->GetRenderViewHost()->GetView())
1494 return NULL;
1495
1496 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1497 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1498 return new_contents;
1499}
1500
1501RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1502 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1503 if (iter == pending_widget_views_.end()) {
1504 DCHECK(false);
1505 return NULL;
1506 }
1507
1508 RenderWidgetHostView* widget_host_view = iter->second;
1509 pending_widget_views_.erase(route_id);
1510
1511 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1512 if (!widget_host->GetProcess()->HasConnection()) {
1513 // The view has gone away or the renderer crashed. Nothing to do.
1514 return NULL;
1515 }
1516
1517 return widget_host_view;
1518}
1519
[email protected]f56c7872013-06-18 12:31:571520void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501521 // Allow WebContentsDelegates to handle the context menu operation first.
1522 if (delegate_ && delegate_->HandleContextMenu(params))
1523 return;
1524
[email protected]f56c7872013-06-18 12:31:571525 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501526}
1527
[email protected]f13b4202012-06-12 23:53:231528void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091529 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211530 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231531 if (delegate_)
1532 delegate_->RequestMediaAccessPermission(this, request, callback);
1533 else
[email protected]b5f76742013-04-29 15:05:591534 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231535}
1536
[email protected]cc9200432013-07-23 23:02:401537SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1538 SiteInstance* instance) {
1539 return controller_.GetSessionStorageNamespace(instance);
1540}
1541
[email protected]9b159a52013-10-03 17:24:551542FrameTree* WebContentsImpl::GetFrameTree() {
1543 return &frame_tree_;
1544}
1545
[email protected]32deec62013-05-15 23:55:041546void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1547 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441548 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041549}
1550
[email protected]b172aee2012-04-10 17:05:261551void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231552 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331553 if (delegate_)
1554 delegate_->UpdatePreferredSize(this, pref_size);
1555}
1556
[email protected]b172aee2012-04-10 17:05:261557void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341558 if (delegate_)
1559 delegate_->ResizeDueToAutoResize(this, new_size);
1560}
1561
[email protected]b172aee2012-04-10 17:05:261562WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201563 if (!delegate_)
1564 return NULL;
[email protected]00c37fc2011-08-02 00:22:501565
[email protected]e5d549d2011-12-28 01:29:201566 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201567 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341568}
1569
[email protected]6b618e62012-08-16 12:59:181570bool WebContentsImpl::Send(IPC::Message* message) {
1571 if (!GetRenderViewHost()) {
1572 delete message;
1573 return false;
1574 }
1575
1576 return GetRenderViewHost()->Send(message);
1577}
1578
[email protected]b172aee2012-04-10 17:05:261579bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501580 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251581 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231582 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251583 reload_type);
[email protected]876bc832010-09-07 16:29:541584}
[email protected]96d185d2009-04-24 03:28:541585
[email protected]ba45bfd2012-05-22 21:51:441586void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211587 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441588 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1589 RenderViewForInterstitialPageCreated(render_view_host));
1590}
1591
[email protected]20ca0382013-02-28 19:50:071592void WebContentsImpl::AttachInterstitialPage(
1593 InterstitialPageImpl* interstitial_page) {
1594 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211595 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291596
1597 // Cancel any visible dialogs so that they don't interfere with the
1598 // interstitial.
1599 if (dialog_manager_)
1600 dialog_manager_->CancelActiveAndPendingDialogs(this);
1601
[email protected]20ca0382013-02-28 19:50:071602 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1603 DidAttachInterstitialPage());
1604}
1605
1606void WebContentsImpl::DetachInterstitialPage() {
1607 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211608 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071609 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1610 DidDetachInterstitialPage());
1611}
1612
[email protected]b172aee2012-04-10 17:05:261613bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231614 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501615 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031616 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1617
[email protected]19e81142011-10-03 16:19:401618 // The renderer will reject IPC messages with URLs longer than
1619 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431620 if (entry.GetURL().spec().size() > kMaxURLChars) {
1621 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1622 << " characters.";
[email protected]19e81142011-10-03 16:19:401623 return false;
[email protected]3adab1c2013-09-09 21:23:431624 }
[email protected]19e81142011-10-03 16:19:401625
[email protected]c80297782013-11-21 07:10:161626 // TODO(creis): Use entry->frame_tree_node_id() to pick which
[email protected]b0936d22013-11-28 06:47:361627 // RenderFrameHostManager to use.
[email protected]9f76c1e2012-03-05 15:15:581628 RenderViewHostImpl* dest_render_view_host =
[email protected]fa944cb82013-11-15 17:51:211629 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401630 if (!dest_render_view_host)
1631 return false; // Unable to create the desired render view host.
1632
[email protected]80a8fad2011-01-29 04:02:381633 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071634 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581635 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271636 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501637 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031638 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1639 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211640 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231641 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271642 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211643 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231644 CHECK(0);
1645 }
[email protected]54ec6472010-04-09 19:39:581646
[email protected]7bb761892012-07-20 09:32:471647 // Notify observers that we will navigate in this RV.
1648 FOR_EACH_OBSERVER(WebContentsObserver,
1649 observers_,
1650 AboutToNavigateRenderView(dest_render_view_host));
1651
[email protected]96d185d2009-04-24 03:28:541652 // Used for page load time metrics.
1653 current_load_start_ = base::TimeTicks::Now();
1654
1655 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341656 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271657 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471658 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341659 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541660
[email protected]36fc0392011-12-25 03:59:511661 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541662 // HACK!! This code suppresses javascript: URLs from being added to
1663 // session history, which is what we want to do for javascript: URLs that
1664 // do not generate content. What we really need is a message from the
1665 // renderer telling us that a new page was not created. The same message
1666 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351667 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541668 return false;
1669 }
1670
[email protected]3c9e1872010-11-18 16:17:491671 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391672 FOR_EACH_OBSERVER(
1673 WebContentsObserver,
1674 observers_,
1675 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541676
[email protected]09b29342011-06-24 19:18:481677 if (delegate_)
1678 delegate_->DidNavigateToPendingEntry(this);
1679
[email protected]d5f942ba2008-09-26 19:30:341680 return true;
1681}
1682
[email protected]b172aee2012-04-10 17:05:261683void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331684 const SiteInstance* site_instance,
1685 int history_length,
1686 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411687 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1688 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211689 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191690 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141691 return;
[email protected]9e1ad4b2011-08-14 16:49:191692 }
[email protected]9f76c1e2012-03-05 15:15:581693 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191694 if (!rvh) {
1695 NOTREACHED();
1696 return;
1697 }
[email protected]9f76c1e2012-03-05 15:15:581698 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191699 NOTREACHED();
1700 return;
1701 }
[email protected]6b618e62012-08-16 12:59:181702 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1703 history_length,
1704 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141705}
1706
[email protected]b172aee2012-04-10 17:05:261707void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271708 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211709 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541710 return;
1711 }
[email protected]9f76c1e2012-03-05 15:15:581712 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541713}
1714
[email protected]b172aee2012-04-10 17:05:261715bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211716 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541717}
1718
[email protected]b172aee2012-04-10 17:05:261719InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211720 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221721}
1722
[email protected]b172aee2012-04-10 17:05:261723bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161724 // WebKit creates Document object when MIME type is application/xhtml+xml,
1725 // so we also support this MIME type.
1726 return contents_mime_type_ == "text/html" ||
1727 contents_mime_type_ == "text/xml" ||
1728 contents_mime_type_ == "application/xhtml+xml" ||
1729 contents_mime_type_ == "text/plain" ||
1730 contents_mime_type_ == "text/css" ||
1731 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591735 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161736 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551737 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011738 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141739 return;
[email protected]c7dd2f62011-07-18 15:57:591740 }
1741
1742 Stop();
1743
1744 // Create the save package and possibly prompt the user for the name to save
1745 // the page as. The user prompt is an asynchronous operation that runs on
1746 // another thread.
1747 save_package_ = new SavePackage(this);
1748 save_package_->GetSaveInfo();
1749}
1750
1751// Used in automated testing to bypass prompting the user for file names.
1752// Instead, the names and paths are hard coded rather than running them through
1753// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341754bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1755 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211756 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591757 // Stop the page from navigating.
1758 Stop();
1759
1760 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211761 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591762}
1763
[email protected]3c71576ce2013-07-23 02:00:011764void WebContentsImpl::SaveFrame(const GURL& url,
1765 const Referrer& referrer) {
1766 if (!GetURL().is_valid())
1767 return;
1768 bool is_main_frame = (url == GetURL());
1769
1770 DownloadManager* dlm =
1771 BrowserContext::GetDownloadManager(GetBrowserContext());
1772 if (!dlm)
1773 return;
1774 int64 post_id = -1;
1775 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271776 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011777 if (entry)
1778 post_id = entry->GetPostID();
1779 }
1780 scoped_ptr<DownloadUrlParameters> params(
1781 DownloadUrlParameters::FromWebContents(this, url));
1782 params->set_referrer(referrer);
1783 params->set_post_id(post_id);
1784 params->set_prefer_cache(true);
1785 if (post_id >= 0)
1786 params->set_method("POST");
1787 params->set_prompt(true);
1788 dlm->DownloadUrl(params.Pass());
1789}
1790
[email protected]b172aee2012-04-10 17:05:261791void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341792 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481793 const base::Callback<void(int64)>& callback) {
1794 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121795}
1796
[email protected]6286a372013-10-09 04:03:271797// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261798bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271799 NavigationEntryImpl* visible_entry =
1800 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1801 return (visible_entry != NULL &&
1802 visible_entry->site_instance() == GetSiteInstance() &&
1803 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321804}
1805
[email protected]b172aee2012-04-10 17:05:261806const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271807 return contents_mime_type_;
1808}
1809
[email protected]b172aee2012-04-10 17:05:261810bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271811 return notify_disconnection_;
1812}
1813
[email protected]b172aee2012-04-10 17:05:261814void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311815 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181816 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161817}
1818
[email protected]b172aee2012-04-10 17:05:261819void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311820 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181821 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161822}
1823
[email protected]8ff00d72012-10-23 19:12:211824RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271825 return &renderer_preferences_;
1826}
1827
[email protected]e35ccd52012-05-23 16:22:471828void WebContentsImpl::Close() {
1829 Close(GetRenderViewHost());
1830}
1831
[email protected]cf200a562013-05-03 16:24:291832void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461833 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291834 if (browser_plugin_embedder_.get())
1835 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1836 screen_x, screen_y, operation);
1837 if (GetRenderViewHost())
1838 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1839 screen_x, screen_y, operation);
1840}
1841
1842void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1843 int screen_x, int screen_y) {
1844 if (browser_plugin_embedder_.get())
1845 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1846 screen_x, screen_y);
1847 if (GetRenderViewHost())
1848 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1849 screen_x, screen_y);
1850}
1851
[email protected]b172aee2012-04-10 17:05:261852void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521853 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581854 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511855 if (delegate_)
1856 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291857 if (browser_plugin_embedder_.get())
1858 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341859}
1860
[email protected]e35ccd52012-05-23 16:22:471861void WebContentsImpl::UserGestureDone() {
1862 OnUserGesture();
1863}
1864
[email protected]b172aee2012-04-10 17:05:261865void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271866 closed_by_user_gesture_ = value;
1867}
1868
[email protected]b172aee2012-04-10 17:05:261869bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271870 return closed_by_user_gesture_;
1871}
1872
[email protected]b172aee2012-04-10 17:05:261873double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051874 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561875 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251876 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171877 return 0;
[email protected]b75b8292010-10-01 07:28:251878
1879 double zoom_level;
1880 if (temporary_zoom_settings_) {
1881 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581882 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251883 } else {
[email protected]2ae88d12011-10-14 09:11:191884 GURL url;
[email protected]6286a372013-10-09 04:03:271885 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191886 // Since zoom map is updated using rewritten URL, use rewritten URL
1887 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271888 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021889 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1890 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251891 }
[email protected]d0b8d092010-10-25 04:05:171892 return zoom_level;
1893}
[email protected]b75b8292010-10-01 07:28:251894
[email protected]b172aee2012-04-10 17:05:261895int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591896 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171897 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011898 // Calculate the zoom percent from the factor. Round up to the nearest whole
1899 // number.
[email protected]b75b8292010-10-01 07:28:251900 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491901 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251902 *enable_decrement = percent > minimum_zoom_percent_;
1903 *enable_increment = percent < maximum_zoom_percent_;
1904 return percent;
1905}
1906
[email protected]b172aee2012-04-10 17:05:261907void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501908 if (!delegate_)
1909 return;
1910
[email protected]6286a372013-10-09 04:03:271911 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1912 if (!entry)
[email protected]1788e772010-12-15 16:40:501913 return;
1914
[email protected]6286a372013-10-09 04:03:271915 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121916}
1917
[email protected]b172aee2012-04-10 17:05:261918void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041919 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271920 if (!delegate_)
1921 return;
1922
[email protected]691aa2f2013-05-28 22:52:041923 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271924}
1925
[email protected]b172aee2012-04-10 17:05:261926int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271927 return minimum_zoom_percent_;
1928}
1929
[email protected]b172aee2012-04-10 17:05:261930int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271931 return maximum_zoom_percent_;
1932}
1933
[email protected]b172aee2012-04-10 17:05:261934gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231935 return preferred_size_;
1936}
1937
[email protected]b172aee2012-04-10 17:05:261938bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271939 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581940 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271941}
1942
[email protected]b172aee2012-04-10 17:05:261943bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441944 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501945}
1946
[email protected]cb805452013-05-22 15:16:211947void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181948 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211949 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201950}
1951
[email protected]cb805452013-05-22 15:16:211952void WebContentsImpl::DidEndColorChooser() {
1953 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1954 color_chooser_identifier_));
1955 color_chooser_.reset();
1956 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201957}
1958
[email protected]41225fe2013-03-29 05:32:021959int WebContentsImpl::DownloadImage(const GURL& url,
1960 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301961 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021962 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391963 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301964 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021965 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391966 return id;
1967}
1968
[email protected]b172aee2012-04-10 17:05:261969bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271970 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201971 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331972 return true;
1973 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271974}
1975
[email protected]b172aee2012-04-10 17:05:261976void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271977 if (delegate_)
1978 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211979}
1980
[email protected]54047eb52012-05-08 21:45:571981void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211982 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571983 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131984 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571985 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:571986 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211987 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]081dc522013-05-15 04:59:201988 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:181989 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:211990 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:571991 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:081992 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:181993
[email protected]442385d2013-08-09 02:38:411994 if (is_main_frame) {
[email protected]d974a0a2013-01-10 01:43:571995 DidChangeLoadProgress(0);
1996
[email protected]442385d2013-08-09 02:38:411997 // If there is no browser-initiated pending entry for this navigation and it
1998 // is not for the error URL, create a pending entry using the current
1999 // SiteInstance, and ensure the address bar updates accordingly. We don't
2000 // know the referrer or extra headers at this point, but the referrer will
2001 // be set properly upon commit.
[email protected]97d8f0d2013-10-29 16:49:212002 NavigationEntryImpl* pending_entry =
2003 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
[email protected]442385d2013-08-09 02:38:412004 bool has_browser_initiated_pending_entry = pending_entry &&
[email protected]97d8f0d2013-10-29 16:49:212005 !pending_entry->is_renderer_initiated();
[email protected]442385d2013-08-09 02:38:412006 if (!has_browser_initiated_pending_entry && !is_error_page) {
2007 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
2008 controller_.CreateNavigationEntry(validated_url,
2009 content::Referrer(),
2010 content::PAGE_TRANSITION_LINK,
2011 true /* is_renderer_initiated */,
2012 std::string(),
2013 GetBrowserContext()));
2014 entry->set_site_instance(
2015 static_cast<SiteInstanceImpl*>(GetSiteInstance()));
[email protected]3ed682bf2013-10-17 20:56:562016 // TODO(creis): If there's a pending entry already, find a safe way to
2017 // update it instead of replacing it and copying over things like this.
[email protected]97d8f0d2013-10-29 16:49:212018 if (pending_entry) {
2019 entry->set_transferred_global_request_id(
2020 pending_entry->transferred_global_request_id());
2021 entry->set_should_replace_entry(pending_entry->should_replace_entry());
[email protected]f8872902013-10-30 03:18:572022 entry->set_redirect_chain(pending_entry->redirect_chain());
[email protected]3ed682bf2013-10-17 20:56:562023 }
[email protected]442385d2013-08-09 02:38:412024 controller_.SetPendingEntry(entry);
2025 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
2026 }
[email protected]59167c22013-06-03 18:07:322027 }
2028
[email protected]0d60f0192011-04-14 12:40:102029 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252030 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132031 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2032 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322033 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542034
2035 if (is_main_frame) {
2036 // Notify observers about the provisional change in the main frame URL.
2037 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2038 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542039 render_view_host));
2040 }
2041}
2042
2043void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212044 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542045 int32 page_id,
[email protected]400992b2012-06-14 00:03:542046 const GURL& source_url,
2047 const GURL& target_url) {
2048 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132049 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2050 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542051 GURL validated_source_url(source_url);
2052 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212053 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542054 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082055 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2056 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542057 NavigationEntry* entry;
2058 if (page_id == -1) {
2059 entry = controller_.GetPendingEntry();
2060 } else {
2061 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2062 page_id);
2063 }
2064 if (!entry || entry->GetURL() != validated_source_url)
2065 return;
2066
2067 // Notify observers about the provisional change in the main frame URL.
2068 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2069 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542070 render_view_host));
[email protected]724159a2010-12-30 01:11:182071}
2072
[email protected]54047eb52012-05-08 21:45:572073void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212074 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582075 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2076 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2077 << ", error_code: " << params.error_code
2078 << ", error_description: " << params.error_description
2079 << ", is_main_frame: " << params.is_main_frame
2080 << ", showing_repost_interstitial: " <<
2081 params.showing_repost_interstitial
2082 << ", frame_id: " << params.frame_id;
2083 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212084 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572085 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082086 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182087
[email protected]d7b175e2011-10-11 15:31:582088 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182089 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2090 // This means that the interstitial won't be torn down properly, which is
2091 // bad. But if we have an interstitial, go back to another tab type, and
2092 // then load the same interstitial again, we could end up getting the first
2093 // interstitial's "failed" message (as a result of the cancel) when we're on
2094 // the second one.
2095 //
2096 // We can't tell this apart, so we think we're tearing down the current page
2097 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362098 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182099 // out because of this problem.
2100 //
2101 // http://code.google.com/p/chromium/issues/detail?id=2855
2102 // Because this will not tear down the interstitial properly, if "back" is
2103 // back to another tab type, the interstitial will still be somewhat alive
2104 // in the previous tab type. If you navigate somewhere that activates the
2105 // tab with the interstitial again, you'll see a flash before the new load
2106 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272107 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182108 LOG(WARNING) << "Discarding message during interstitial.";
2109 return;
2110 }
2111
[email protected]fa944cb82013-11-15 17:51:212112 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182113 }
2114
[email protected]b12eb222013-09-10 00:11:482115 // Do not usually clear the pending entry if one exists, so that the user's
2116 // typed URL is not lost when a navigation fails or is aborted. However, in
2117 // cases that we don't show the pending entry (e.g., renderer-initiated
2118 // navigations in an existing tab), we don't keep it around. That prevents
2119 // spoofs on in-page navigations that don't go through
2120 // DidStartProvisionalLoadForFrame.
2121 // In general, we allow the view to clear the pending entry and typed URL if
2122 // the user requests (e.g., hitting Escape with focus in the address bar).
2123 // Note: don't touch the transient entry, since an interstitial may exist.
2124 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2125 controller_.DiscardPendingEntry();
2126
[email protected]d8c660432011-12-22 20:51:252127 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582128 observers_,
2129 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442130 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582131 params.is_main_frame,
2132 validated_url,
2133 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462134 params.error_description,
2135 render_view_host));
[email protected]724159a2010-12-30 01:11:182136}
2137
[email protected]b172aee2012-04-10 17:05:262138void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182139 const GURL& url,
[email protected]70435962011-08-02 20:13:282140 const std::string& security_info,
2141 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182142 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282143 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192144 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182145 cache.Increment();
2146
2147 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082148 int cert_id = 0;
2149 net::CertStatus cert_status = 0;
2150 int security_bits = -1;
2151 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122152 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212153 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122154 &security_bits, &connection_status,
2155 &signed_certificate_timestamp_ids);
2156 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212157 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002158 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2159 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182160
[email protected]b0f724c2013-09-05 04:21:132161 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2162
2163 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2164 DidLoadResourceFromMemoryCache(details));
2165
[email protected]8bfc8272013-09-09 20:10:532166 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2167 scoped_refptr<net::URLRequestContextGetter> request_context(
2168 resource_type == ResourceType::MEDIA ?
2169 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2170 GetRenderProcessHost()->GetID()) :
2171 GetBrowserContext()->GetRequestContextForRenderProcess(
2172 GetRenderProcessHost()->GetID()));
2173 BrowserThread::PostTask(
2174 BrowserThread::IO,
2175 FROM_HERE,
2176 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2177 }
[email protected]724159a2010-12-30 01:11:182178}
2179
[email protected]b172aee2012-04-10 17:05:262180void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212181 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182182 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192183 SSLManager::NotifySSLInternalStateChanged(
2184 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182185}
2186
[email protected]b172aee2012-04-10 17:05:262187void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022188 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582189 LOG(WARNING) << security_origin << " ran insecure content from "
2190 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212191 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412192 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212193 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182194 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412195 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192196 SSLManager::NotifySSLInternalStateChanged(
2197 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182198}
2199
[email protected]b172aee2012-04-10 17:05:262200void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]d8c660432011-12-22 20:51:252201 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472202 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182203}
2204
[email protected]b172aee2012-04-10 17:05:262205void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312206 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062207 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312208 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062209 GURL validated_url(url);
2210 RenderProcessHost* render_process_host = message_source_->GetProcess();
2211 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252212 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472213 DidFinishLoad(frame_id, validated_url, is_main_frame,
2214 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::OnDidFailLoadWithError(
2218 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062219 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262220 bool is_main_frame,
2221 int error_code,
2222 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062223 GURL validated_url(url);
2224 RenderProcessHost* render_process_host = message_source_->GetProcess();
2225 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252226 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312227 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472228 error_code, error_description,
2229 message_source_));
[email protected]724159a2010-12-30 01:11:182230}
2231
[email protected]b172aee2012-04-10 17:05:262232void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262233 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232234 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252235 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262236 if (!entry)
2237 return;
2238 // Note that we don't call NavigationController::GotToOffset() as we don't
2239 // want to create a pending navigation entry (it might end up lingering
2240 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252241 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212242 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512243 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212244 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472245 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572246
2247 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2248 // it in now that we know. This allows us to find the entry when it commits.
2249 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232250 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332251 entry->set_site_instance(
2252 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572253 }
[email protected]216813952011-05-19 22:21:262254 }
2255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2258 int maximum_percent,
2259 bool remember) {
[email protected]216813952011-05-19 22:21:262260 minimum_zoom_percent_ = minimum_percent;
2261 maximum_zoom_percent_ = maximum_percent;
2262 temporary_zoom_settings_ = !remember;
2263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342266 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432267 if (!delegate_)
2268 return;
2269
[email protected]b9535422012-02-09 01:47:592270 ChildProcessSecurityPolicyImpl* policy =
2271 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222272 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592273 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212274}
2275
[email protected]b172aee2012-04-10 17:05:262276void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432277 if (delegate_)
2278 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202279}
2280
[email protected]b172aee2012-04-10 17:05:262281void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2282 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362283 const string16& title,
2284 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432285 if (!delegate_)
2286 return;
2287
[email protected]b9535422012-02-09 01:47:592288 ChildProcessSecurityPolicyImpl* policy =
2289 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322290 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592291 return;
[email protected]8f810632013-06-06 22:33:322292
[email protected]3a3b75a2012-06-01 08:38:362293 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::OnFindReply(int request_id,
2297 int number_of_matches,
2298 const gfx::Rect& selection_rect,
2299 int active_match_ordinal,
2300 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432301 if (delegate_) {
2302 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2303 active_match_ordinal, final_update);
2304 }
[email protected]b888919c2011-09-02 00:32:162305}
2306
[email protected]59363fc92012-09-05 03:46:312307#if defined(OS_ANDROID)
2308void WebContentsImpl::OnFindMatchRectsReply(
2309 int version,
2310 const std::vector<gfx::RectF>& rects,
2311 const gfx::RectF& active_rect) {
2312 if (delegate_)
2313 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2314}
[email protected]583418cc2013-01-17 14:01:102315
[email protected]1ff427972013-02-07 21:14:072316void WebContentsImpl::OnOpenDateTimeDialog(
2317 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092318 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2319 GetRenderViewHost(),
2320 value.dialog_type,
2321 value.year,
2322 value.month,
2323 value.day,
2324 value.hour,
2325 value.minute,
2326 value.second,
2327 value.milli,
2328 value.week,
2329 value.minimum,
2330 value.maximum,
2331 value.step);
[email protected]583418cc2013-01-17 14:01:102332}
2333
[email protected]a794f3a2013-10-30 17:00:322334void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2335 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
2336 message_source_, reply_msg);
2337}
2338
[email protected]59363fc92012-09-05 03:46:312339#endif
2340
[email protected]2dec8ec2013-02-07 19:20:342341void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422342 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442343 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422344 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452345}
2346
[email protected]b172aee2012-04-10 17:05:262347void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2348 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102349 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252350 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102351 AppCacheAccessed(manifest_url, blocked_by_policy));
2352}
2353
[email protected]8bc5ff02013-11-29 06:34:032354void WebContentsImpl::OnOpenColorChooser(
2355 int color_chooser_id,
2356 SkColor color,
2357 const std::vector<ColorSuggestion>& suggestions) {
2358 ColorChooser* new_color_chooser =
2359 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212360 if (color_chooser_ == new_color_chooser)
2361 return;
2362 color_chooser_.reset(new_color_chooser);
2363 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202364}
2365
[email protected]b172aee2012-04-10 17:05:262366void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202367 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212368 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202369 color_chooser_->End();
2370}
2371
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322373 SkColor color) {
[email protected]da8543762012-03-20 08:52:202374 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212375 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202376 color_chooser_->SetSelectedColor(color);
2377}
2378
[email protected]9f2a9d72012-04-16 16:02:222379void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
[email protected]2dec8ec2013-02-07 19:20:342380 const base::FilePath& path,
[email protected]9f2a9d72012-04-16 16:02:222381 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552382 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2383
[email protected]3fc07c52012-04-20 00:27:442384 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2385 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292386}
2387
[email protected]d0759f492012-04-19 22:50:502388// This exists for render views that don't have a WebUI, but do have WebUI
2389// bindings enabled.
2390void WebContentsImpl::OnWebUISend(const GURL& source_url,
2391 const std::string& name,
2392 const base::ListValue& args) {
2393 if (delegate_)
2394 delegate_->WebUISend(this, source_url, name, args);
2395}
2396
[email protected]d8415ad92012-08-23 14:40:502397void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442398 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502399 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342400 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162401 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442402 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162403 return;
[email protected]d8415ad92012-08-23 14:40:502404 }
2405
[email protected]8c8fc292012-11-23 18:57:162406 if (!delegate_->RequestPpapiBrokerPermission(
2407 this, url, plugin_path,
2408 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442409 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162410 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442411 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162412 }
[email protected]d8415ad92012-08-23 14:40:502413}
2414
[email protected]ea0309c2013-08-06 19:35:442415void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502416 bool result) {
[email protected]ea0309c2013-08-06 19:35:442417 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502418}
2419
[email protected]c4538072013-03-18 02:17:552420void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372421 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082422 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552423 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392424 // For more info, see comment above classes BrowserPluginEmbedder and
2425 // BrowserPluginGuest.
2426 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142427 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082428 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372429}
2430
[email protected]41225fe2013-03-29 05:32:022431void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392432 int id,
[email protected]749fadd2013-05-15 08:37:482433 int http_status_code,
[email protected]795c28972012-12-06 06:13:392434 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302435 const std::vector<SkBitmap>& bitmaps,
2436 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022437 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2438 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392439 // Currently WebContents notifies us of ANY downloads so that it is
2440 // possible to get here.
2441 return;
2442 }
2443 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302444 iter->second.Run(
2445 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392446 }
[email protected]41225fe2013-03-29 05:32:022447 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392448}
2449
2450void WebContentsImpl::OnUpdateFaviconURL(
2451 int32 page_id,
2452 const std::vector<FaviconURL>& candidates) {
2453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2454 DidUpdateFaviconURL(page_id, candidates));
2455}
2456
[email protected]d9030b82013-07-19 08:26:062457void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2458 bool has_video,
2459 bool has_audio,
2460 bool is_playing) {
2461 // Chrome OS does its own detection of audio and video.
2462#if !defined(OS_CHROMEOS)
2463 if (is_playing) {
2464 scoped_ptr<PowerSaveBlocker> blocker;
2465 if (has_video) {
2466 blocker = PowerSaveBlocker::Create(
2467 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2468 "Playing video");
2469#if defined(OS_ANDROID)
2470 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382471 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062472#endif
2473 } else if (has_audio) {
2474 blocker = PowerSaveBlocker::Create(
2475 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2476 "Playing audio");
2477 }
2478
2479 if (blocker)
2480 power_save_blockers_[message_source_][player_cookie] = blocker.release();
2481 } else {
2482 delete power_save_blockers_[message_source_][player_cookie];
2483 power_save_blockers_[message_source_].erase(player_cookie);
2484 }
2485#endif // !defined(OS_CHROMEOS)
2486}
2487
[email protected]9f268072013-11-07 00:02:152488void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2490 DidFirstVisuallyNonEmptyPaint(page_id));
2491}
[email protected]d9030b82013-07-19 08:26:062492
[email protected]e67ebf32013-02-13 11:07:192493void WebContentsImpl::DidChangeVisibleSSLState() {
2494 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2495 DidChangeVisibleSSLState());
2496}
2497
[email protected]17e286e2013-03-01 23:29:392498void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2499 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2500 BeforeFormRepostWarningShow());
2501}
2502
[email protected]ec6c05f2013-10-23 18:41:572503
2504void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2505 Activate();
2506 if (delegate_)
2507 delegate_->ShowRepostFormWarningDialog(this);
2508}
2509
[email protected]96d185d2009-04-24 03:28:542510// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592511// loading, or done loading.
2512void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2513 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262514 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542515 if (is_loading == is_loading_)
2516 return;
2517
2518 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212519 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542520 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562521 upload_size_ = 0;
2522 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542523 }
2524
[email protected]fa944cb82013-11-15 17:51:212525 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542526
2527 is_loading_ = is_loading;
2528 waiting_for_response_ = is_loading;
2529
[email protected]6ebdc9b2010-09-27 16:55:572530 if (delegate_)
2531 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212532 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542533
[email protected]eab61442013-11-14 18:35:482534 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592535 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482536 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2537 "URL", url);
[email protected]91621872013-10-08 04:04:592538 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2539 DidStartLoading(render_view_host));
2540 } else {
[email protected]eab61442013-11-14 18:35:482541 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2542 "URL", url);
[email protected]91621872013-10-08 04:04:592543 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2544 DidStopLoading(render_view_host));
2545 }
[email protected]66798902013-10-01 18:40:162546
2547 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212548 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2549 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542550 if (details)
[email protected]8ff00d72012-10-23 19:12:212551 det = Details<LoadNotificationDetails>(details);
2552 NotificationService::current()->Notify(
2553 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542554}
2555
[email protected]b172aee2012-04-10 17:05:262556void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212557 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322558 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562559 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322560 // Clear the status bubble. This is a workaround for a bug where WebKit
2561 // doesn't let us know that the cursor left an element during a
2562 // transition (this is also why the mouse cursor remains as a hand after
2563 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2564 // clear the bubble when a user navigates to a named anchor in the same
2565 // page.
[email protected]36fc0392011-12-25 03:59:512566 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322567 }
2568
[email protected]a6e82fc2010-02-24 22:28:142569 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472570 // Once the main frame is navigated, we're no longer considered to have
2571 // displayed insecure content.
2572 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352573 SSLManager::NotifySSLInternalStateChanged(
2574 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172575 }
[email protected]ce5c4502009-05-06 16:46:112576
[email protected]3c9e1872010-11-18 16:17:492577 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252578 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042579 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322580}
2581
[email protected]b172aee2012-04-10 17:05:262582void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322583 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212584 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322585 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112586 // If we navigate off the page, close all JavaScript dialogs.
2587 if (dialog_manager_ && !details.is_in_page)
2588 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322589
[email protected]3c9e1872010-11-18 16:17:492590 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252591 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042592 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322593}
2594
[email protected]2f7b3c5a2013-06-21 04:59:252595bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292596 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2597 // still be used for a normal web site.
2598 if (url == GURL(kAboutBlankURL))
2599 return false;
2600
2601 // The embedder will then have the opportunity to determine if the URL
2602 // should "use up" the SiteInstance.
2603 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252604}
2605
[email protected]b172aee2012-04-10 17:05:262606void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462607 // If we are creating a RVH for a restored controller, then we need to make
2608 // sure the RenderView starts with a next_page_id_ larger than the number
2609 // of restored entries. This must be called before the RenderView starts
2610 // navigating (to avoid a race between the browser updating max_page_id and
2611 // the renderer updating next_page_id_). Because of this, we only call this
2612 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562613 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582614 if (max_restored_page_id >
2615 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2616 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2617 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322618}
2619
[email protected]b172aee2012-04-10 17:05:262620bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2621 const string16& title) {
[email protected]420ae012009-04-24 05:16:322622 // For file URLs without a title, use the pathname instead. In the case of a
2623 // synthesized title, we don't want the update to count toward the "one set
2624 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512625 string16 final_title;
[email protected]420ae012009-04-24 05:16:322626 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512627 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2628 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322629 explicit_set = false; // Don't count synthetic titles toward the set limit.
2630 } else {
[email protected]acafd272011-07-26 17:35:572631 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322632 explicit_set = true;
2633 }
2634
[email protected]987fc3a2011-05-26 14:18:092635 // If a page is created via window.open and never navigated,
2636 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552637 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092638 if (entry) {
[email protected]36fc0392011-12-25 03:59:512639 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092640 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322641
[email protected]36fc0392011-12-25 03:59:512642 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092643 } else {
2644 if (page_title_when_no_navigation_entry_ == final_title)
2645 return false; // Nothing changed, don't bother.
2646
2647 page_title_when_no_navigation_entry_ = final_title;
2648 }
[email protected]420ae012009-04-24 05:16:322649
[email protected]420ae012009-04-24 05:16:322650 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232651 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322652
[email protected]66798902013-10-01 18:40:162653 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532654 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162655
2656 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212657 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462658 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212659 NotificationService::current()->Notify(
2660 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2661 Source<WebContents>(this),
2662 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042663
[email protected]420ae012009-04-24 05:16:322664 return true;
2665}
2666
[email protected]7b712ee22013-10-03 00:57:282667void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2668 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322669 // After sending out a swap notification, we need to send a disconnect
2670 // notification so that clients that pick up a pointer to |this| can NULL the
2671 // pointer. See Bug 1230284.
2672 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112673 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282674 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112675
2676 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282677 std::pair<RenderViewHost*, RenderViewHost*> details =
2678 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212679 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282680 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212681 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282682 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392683
2684 // Ensure that the associated embedder gets cleared after a RenderViewHost
2685 // gets swapped, so we don't reuse the same embedder next time a
2686 // RenderViewHost is attached to this WebContents.
2687 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322688}
2689
[email protected]da7a7182013-09-06 08:11:112690// TODO(avi): Remove this entire function because this notification is already
2691// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262692void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322693 if (!notify_disconnection_)
2694 return;
2695
2696 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212697 NotificationService::current()->Notify(
2698 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2699 Source<WebContents>(this),
2700 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322701}
2702
[email protected]cbb1ef592013-06-05 19:49:462703void WebContentsImpl::NotifyNavigationEntryCommitted(
2704 const LoadCommittedDetails& load_details) {
2705 FOR_EACH_OBSERVER(
2706 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2707}
2708
[email protected]5a3bdf52012-05-24 15:12:572709RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2710 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322711}
2712
[email protected]8d3347f2009-07-09 22:00:212713RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262714WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212715 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212716}
2717
[email protected]8ff00d72012-10-23 19:12:212718RendererPreferences WebContentsImpl::GetRendererPrefs(
2719 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462720 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512721}
2722
[email protected]b172aee2012-04-10 17:05:262723WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172724 return this;
2725}
2726
[email protected]b172aee2012-04-10 17:05:262727gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172728 if (delegate_)
2729 return delegate_->GetRootWindowResizerRect();
2730 return gfx::Rect();
2731}
2732
[email protected]7a846df2012-09-20 19:17:392733void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272734 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392735 browser_plugin_embedder_.reset();
2736}
2737
[email protected]b172aee2012-04-10 17:05:262738void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442739 // Don't send notifications if we are just creating a swapped-out RVH for
2740 // the opener chain. These won't be used for view-source or WebUI, so it's
2741 // ok to return early.
2742 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2743 return;
2744
[email protected]86f98a22013-03-20 14:35:002745 if (delegate_)
2746 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082747
[email protected]8ff00d72012-10-23 19:12:212748 NotificationService::current()->Notify(
2749 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2750 Source<WebContents>(this),
2751 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322752
2753 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352754 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212755 if (GetRenderManager()->pending_web_ui())
2756 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322757
[email protected]6286a372013-10-09 04:03:272758 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332759 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322760 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182761 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582762 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322763 }
[email protected]0666aef2009-05-13 19:48:082764
[email protected]60780f412013-02-25 16:34:102765 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262766
2767 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252768 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322769}
2770
[email protected]b172aee2012-04-10 17:05:262771void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522772 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322773 // Don't notify the world, since this came from a renderer in the
2774 // background.
2775 return;
2776 }
2777
[email protected]da7a7182013-09-06 08:11:112778 notify_disconnection_ = true;
2779 // TODO(avi): Remove. http://crbug.com/170921
2780 NotificationService::current()->Notify(
2781 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2782 Source<WebContents>(this),
2783 NotificationService::NoDetails());
2784
[email protected]be1f56ab2011-12-22 06:55:312785 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232786 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302787
2788 // Restore the focus to the tab (otherwise the focus will be on the top
2789 // window).
[email protected]484ae5912010-09-29 19:16:142790 if (was_crashed && !FocusLocationBarByDefault() &&
2791 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062792 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142793 }
[email protected]32ded2212011-11-10 18:51:432794
[email protected]d8c660432011-12-22 20:51:252795 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322796}
2797
[email protected]ec6a7eb2013-04-22 17:34:222798void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2799 base::TerminationStatus status,
2800 int error_code) {
[email protected]151a63d2011-12-20 22:32:522801 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322802 // The pending page's RenderViewHost is gone.
2803 return;
2804 }
2805
[email protected]d9030b82013-07-19 08:26:062806 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592807 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322808 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232809 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312810 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322811
[email protected]d8c660432011-12-22 20:51:252812 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272813 observers_,
[email protected]58d5cfe2013-07-10 02:40:522814 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062818 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212819 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252820 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062821}
2822
[email protected]b0f724c2013-09-05 04:21:132823void WebContentsImpl::DidGetResourceResponseStart(
2824 const ResourceRequestDetails& details) {
2825 controller_.ssl_manager()->DidStartResourceResponse(details);
2826
2827 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2828 DidGetResourceResponseStart(details));
2829
2830 // TODO(avi): Remove. http://crbug.com/170921
2831 NotificationService::current()->Notify(
2832 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2833 Source<WebContents>(this),
2834 Details<const ResourceRequestDetails>(&details));
2835}
2836
2837void WebContentsImpl::DidGetRedirectForResourceRequest(
2838 const ResourceRedirectDetails& details) {
2839 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2840
2841 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2842 DidGetRedirectForResourceRequest(details));
2843
2844 // TODO(avi): Remove. http://crbug.com/170921
2845 NotificationService::current()->Notify(
2846 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2847 Source<WebContents>(this),
2848 Details<const ResourceRedirectDetails>(&details));
2849}
2850
[email protected]b172aee2012-04-10 17:05:262851void WebContentsImpl::DidNavigate(
2852 RenderViewHost* rvh,
2853 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552854 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2855 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122856 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552857 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122858 }
2859
[email protected]e3d92a7f2013-01-10 02:35:052860 if (PageTransitionIsMainFrame(params.transition)) {
2861 // When overscroll navigation gesture is enabled, a screenshot of the page
2862 // in its current state is taken so that it can be used during the
2863 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362864 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052865 // WebContents::GetRenderViewHost to return the new host, instead of the one
2866 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482867 if (delegate_ && delegate_->CanOverscrollContent())
2868 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052869
[email protected]fa944cb82013-11-15 17:51:212870 GetRenderManager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052871 }
[email protected]8030f012009-09-25 18:09:372872
[email protected]434f69f2012-02-06 21:56:522873 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252874 // assigning a site is not necessary for this URL. In that case, the
2875 // SiteInstance can still be considered unused until a navigation to a real
2876 // page.
[email protected]434f69f2012-02-06 21:56:522877 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252878 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332879 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522880 }
[email protected]420ae012009-04-24 05:16:322881
2882 // Need to update MIME type here because it's referred to in
2883 // UpdateNavigationCommands() called by RendererDidNavigate() to
2884 // determine whether or not to enable the encoding menu.
2885 // It's updated only for the main frame. For a subframe,
2886 // RenderView::UpdateURL does not set params.contents_mime_type.
2887 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2888 // TODO(jungshik): Add a test for the encoding menu to avoid
2889 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212890 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322891 contents_mime_type_ = params.contents_mime_type;
2892
[email protected]8ff00d72012-10-23 19:12:212893 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002894 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392895
[email protected]1ae93fb2013-06-14 03:38:562896 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2897 // us estimate our process count for implementing OOP iframes.
2898 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552899 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562900
[email protected]a9c0bfe2010-09-17 08:35:222901 // Send notification about committed provisional loads. This notification is
2902 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2903 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212904 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072905 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2906 // that is not recorded in the navigation history. For the purpose of
2907 // tracking navigation events, we treat this event as a sub frame navigation
2908 // event.
2909 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212910 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222911 // Whether or not a page transition was triggered by going backward or
2912 // forward in the history is only stored in the navigation controller's
2913 // entry list.
2914 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272915 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212916 PAGE_TRANSITION_FORWARD_BACK)) {
2917 transition_type = PageTransitionFromInt(
2918 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222919 }
[email protected]0d60f0192011-04-14 12:40:102920 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442922 DidCommitProvisionalLoadForFrame(
2923 params.frame_id,
2924 params.frame_unique_name,
2925 is_main_frame,
2926 params.url,
2927 transition_type,
2928 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222929 }
2930
[email protected]76543b92009-08-31 17:27:452931 if (!did_navigate)
2932 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322933
2934 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2935 // for the appropriate notification (best) or you can add it to
2936 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2937 // necessary, please).
2938
2939 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002940 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322941 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002942 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512943 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002944 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2945 }
[email protected]93f230e02011-06-01 14:40:002946 }
[email protected]420ae012009-04-24 05:16:322947 DidNavigateAnyFramePostCommit(rvh, details, params);
2948}
2949
[email protected]b172aee2012-04-10 17:05:262950void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2951 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042952 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152953 // Ensure that this state update comes from either the active RVH or one of
2954 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]fa944cb82013-11-15 17:51:212955 DCHECK(rvh == GetRenderViewHost() ||
2956 GetRenderManager()->IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322957
2958 // We must be prepared to handle state updates for any page, these occur
2959 // when the user is scrolling and entering form data, as well as when we're
2960 // leaving a page, in which case our state may have already been moved to
2961 // the next page. The navigation controller will look up the appropriate
2962 // NavigationEntry and update it when it is notified via the delegate.
2963
2964 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582965 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322966 if (entry_index < 0)
2967 return;
[email protected]10f417c52011-12-28 21:04:232968 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322969
[email protected]691aa2f2013-05-28 22:52:042970 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322971 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042972 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322973 controller_.NotifyEntryChanged(entry, entry_index);
2974}
2975
[email protected]b172aee2012-04-10 17:05:262976void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2977 int32 page_id,
2978 const string16& title,
2979 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322980 // If we have a title, that's a pretty good indication that we've started
2981 // getting useful data.
2982 SetNotWaitingForResponse();
2983
[email protected]73eb2602012-02-09 19:50:552984 // Try to find the navigation entry, which might not be the current one.
2985 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232986 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582987 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092988
[email protected]73eb2602012-02-09 19:50:552989 // We can handle title updates when we don't have an entry in
2990 // UpdateTitleForEntry, but only if the update is from the current RVH.
2991 if (!entry && rvh != GetRenderViewHost())
2992 return;
2993
[email protected]a49e10b2011-08-01 23:57:462994 // TODO(evan): make use of title_direction.
2995 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092996 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322997 return;
2998
2999 // Broadcast notifications when the UI should be updated.
3000 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213001 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323002}
3003
[email protected]b172aee2012-04-10 17:05:263004void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3005 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313006 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323007}
3008
[email protected]b172aee2012-04-10 17:05:263009void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513010 if (delegate_)
3011 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323012}
3013
[email protected]b172aee2012-04-10 17:05:263014void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103015#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293016 // The UI may be in an event-tracking loop, such as between the
3017 // mouse-down and mouse-up in text selection or a button click.
3018 // Defer the close until after tracking is complete, so that we
3019 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293020 // TODO(shess): This could get more fine-grained. For instance,
3021 // closing a tab in another window while selecting text in the
3022 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103023 if (view_->IsEventTracking()) {
3024 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293025 return;
3026 }
[email protected]60780f412013-02-25 16:34:103027#endif
[email protected]07707302009-11-06 00:50:293028
[email protected]420ae012009-04-24 05:16:323029 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523030 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513031 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323032}
3033
[email protected]b172aee2012-04-10 17:05:263034void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523035 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513036 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283037
3038 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213039 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573040}
3041
[email protected]b172aee2012-04-10 17:05:263042void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513043 if (delegate_ && delegate_->IsPopupOrPanel(this))
3044 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323045}
3046
[email protected]8ff00d72012-10-23 19:12:213047void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593048 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323049}
3050
[email protected]8ff00d72012-10-23 19:12:213051void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323052 scoped_ptr<LoadNotificationDetails> details;
3053
[email protected]9595fd82013-04-19 21:28:493054 // Use the last committed entry rather than the active one, in case a
3055 // pending entry has been created.
3056 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3057
[email protected]420ae012009-04-24 05:16:323058 // An entry may not exist for a stop when loading an initial blank page or
3059 // if an iframe injected by script into a blank page finishes loading.
3060 if (entry) {
[email protected]420ae012009-04-24 05:16:323061 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3062
3063 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513064 entry->GetVirtualURL(),
3065 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323066 elapsed,
3067 &controller_,
3068 controller_.GetCurrentEntryIndex()));
3069 }
3070
[email protected]91621872013-10-08 04:04:593071 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323072}
3073
[email protected]b172aee2012-04-10 17:05:263074void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163075 controller_.DiscardNonCommittedEntries();
3076
3077 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213078 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163079}
3080
[email protected]b172aee2012-04-10 17:05:263081void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513082 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133083 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403084}
3085
[email protected]7cc78902012-12-06 02:32:263086void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393087 if (opener_) {
3088 // Clear our opener so that future cross-process navigations don't have an
3089 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103090 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393091 opener_ = NULL;
3092 }
[email protected]7cc78902012-12-06 02:32:263093
3094 // Notify all swapped out RenderViewHosts for this tab. This is important
3095 // in case we go back to them, or if another window in those processes tries
3096 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213097 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263098}
3099
[email protected]59167c22013-06-03 18:07:323100void WebContentsImpl::DidAccessInitialDocument() {
3101 // Update the URL display.
3102 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3103}
3104
[email protected]87717d0e2012-04-26 02:58:433105void WebContentsImpl::DocumentAvailableInMainFrame(
3106 RenderViewHost* render_view_host) {
3107 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3108 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083112 RenderViewHost* render_view_host,
3113 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093114 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3115 DocumentOnLoadCompletedInMainFrame(page_id));
3116
3117 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213118 NotificationService::current()->Notify(
3119 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3120 Source<WebContents>(this),
3121 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083122}
3123
[email protected]196159d2012-05-04 17:26:543124void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3125 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213126 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263127 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183128 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523129 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303130 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543131 // If this came from a swapped out RenderViewHost, we only allow the request
3132 // if we are still in the same BrowsingInstance.
3133 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3134 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3135 return;
3136 }
3137
[email protected]4ad5d77d2011-12-03 02:00:483138 // Delegate to RequestTransferURL because this is just the generic
3139 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573140 // TODO(creis): Pass the redirect_chain into this method to support client
3141 // redirects. http://crbug.com/311721.
3142 std::vector<GURL> redirect_chain;
3143 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3144 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523145 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483146}
3147
[email protected]b172aee2012-04-10 17:05:263148void WebContentsImpl::RequestTransferURL(
3149 const GURL& url,
[email protected]f8872902013-10-30 03:18:573150 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213151 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573152 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263153 WindowOpenDisposition disposition,
3154 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183155 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523156 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303157 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203158 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123159 GURL dest_url(url);
3160 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553161 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123162 dest_url = GURL(kAboutBlankURL);
3163
[email protected]c80297782013-11-21 07:10:163164 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id.
3165 int frame_tree_node_id = -1;
3166 OpenURLParams params(dest_url, referrer, source_frame_id,
3167 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573168 page_transition, true /* is_renderer_initiated */);
3169 if (redirect_chain.size() > 0)
3170 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553171 params.transferred_global_request_id = old_request_id;
3172 params.should_replace_current_entry = should_replace_current_entry;
3173 params.user_gesture = user_gesture;
3174
[email protected]fa944cb82013-11-15 17:51:213175 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573176 // Web UI pages sometimes want to override the page transition type for
3177 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3178 // automatically generated suggestions). We don't override other types
3179 // like TYPED because they have different implications (e.g., autocomplete).
3180 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213181 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553182
[email protected]e0112912011-02-02 22:54:353183 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163184 // want web sites to see a referrer of "chrome://blah" (and some
3185 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323186 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553187 params.referrer = Referrer();
3188
3189 // Navigations in Web UI pages count as browser-initiated navigations.
3190 params.is_renderer_initiated = false;
[email protected]16a13fa2013-11-07 01:03:533191
3192 // TODO(creis): Remove this line. In the short term, it fixes a regression
3193 // (http://crbug.com/313572) by partially reverting r231370.
3194 // The underlying problem is that WebDataSource::replacesCurrentHistoryItem
3195 // should be returning false when the CWS goes to the sign-in page.
3196 // See http://crbug.com/311721.
3197 params.should_replace_current_entry = false;
[email protected]ae5184d62011-10-06 19:25:583198 }
[email protected]44d0930a2013-10-28 18:53:553199
3200 new_contents = OpenURL(params);
3201
[email protected]ae5184d62011-10-06 19:25:583202 if (new_contents) {
3203 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583205 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123206 dest_url,
[email protected]ae5184d62011-10-06 19:25:583207 referrer,
3208 disposition,
[email protected]44d0930a2013-10-28 18:53:553209 params.transition,
[email protected]ae5184d62011-10-06 19:25:583210 source_frame_id));
[email protected]420ae012009-04-24 05:16:323211 }
3212}
3213
[email protected]e1c3a552012-05-04 20:51:323214void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3215 // Tell the active RenderViewHost to run unload handlers and close, as long
3216 // as the request came from a RenderViewHost in the same BrowsingInstance.
3217 // In most cases, we receive this from a swapped out RenderViewHost.
3218 // It is possible to receive it from one that has just been swapped in,
3219 // in which case we might as well deliver the message anyway.
3220 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3221 GetRenderViewHost()->ClosePage();
3222}
3223
[email protected]f546640b2012-05-15 00:03:493224void WebContentsImpl::RouteMessageEvent(
3225 RenderViewHost* rvh,
3226 const ViewMsg_PostMessage_Params& params) {
3227 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363228 // came from a RenderViewHost in the same BrowsingInstance or if this
3229 // WebContents is dedicated to a browser plugin guest.
3230 // Note: This check means that an embedder could theoretically receive a
3231 // postMessage from anyone (not just its own guests). However, this is
3232 // probably not a risk for apps since other pages won't have references
3233 // to App windows.
3234 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3235 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493236 return;
3237
3238 ViewMsg_PostMessage_Params new_params(params);
3239
[email protected]0bc7f3542013-10-21 15:05:533240 if (!params.message_port_ids.empty()) {
3241 MessagePortMessageFilter* message_port_message_filter =
3242 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3243 ->message_port_message_filter();
3244 std::vector<int> new_routing_ids(params.message_port_ids.size());
3245 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3246 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3247 MessagePortService::GetInstance()->UpdateMessagePort(
3248 params.message_port_ids[i],
3249 message_port_message_filter,
3250 new_routing_ids[i]);
3251 }
3252 new_params.new_routing_ids = new_routing_ids;
3253 }
3254
[email protected]f546640b2012-05-15 00:03:493255 // If there is a source_routing_id, translate it to the routing ID for
3256 // the equivalent swapped out RVH in the target process. If we need
3257 // to create a swapped out RVH for the source tab, we create its opener
3258 // chain as well, since those will also be accessible to the target page.
3259 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3260 // Try to look up the WebContents for the source page.
3261 WebContentsImpl* source_contents = NULL;
3262 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3263 rvh->GetProcess()->GetID(), params.source_routing_id);
3264 if (source_rvh) {
3265 source_contents = static_cast<WebContentsImpl*>(
3266 source_rvh->GetDelegate()->GetAsWebContents());
3267 }
3268
3269 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363270 if (GetBrowserPluginGuest()) {
3271 // We create a swapped out RenderView for the embedder in the guest's
3272 // render process but we intentionally do not expose the embedder's
3273 // opener chain to it.
3274 new_params.source_routing_id =
3275 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3276 } else {
3277 new_params.source_routing_id =
3278 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3279 }
[email protected]f546640b2012-05-15 00:03:493280 } else {
3281 // We couldn't find it, so don't pass a source frame.
3282 new_params.source_routing_id = MSG_ROUTING_NONE;
3283 }
3284 }
3285
3286 // In most cases, we receive this from a swapped out RenderViewHost.
3287 // It is possible to receive it from one that has just been swapped in,
3288 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183289 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493290}
3291
[email protected]b172aee2012-04-10 17:05:263292void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343293 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413294 const string16& message,
3295 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323296 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213297 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323298 IPC::Message* reply_msg,
3299 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073300 // Suppress JavaScript dialogs when requested. Also suppress messages when
3301 // showing an interstitial as it's shown over the previous page and we don't
3302 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503303 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583304 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273305 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073306 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523307 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153308 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323309
3310 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213311 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433312 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153313 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3314 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433315 this,
3316 frame_url.GetOrigin(),
3317 accept_lang,
3318 javascript_message_type,
3319 message,
[email protected]51da7e32012-01-30 19:24:523320 default_prompt,
[email protected]b172aee2012-04-10 17:05:263321 base::Bind(&WebContentsImpl::OnDialogClosed,
3322 base::Unretained(this),
3323 rvh,
3324 reply_msg),
[email protected]51da7e32012-01-30 19:24:523325 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323326 }
[email protected]3ab9cb82011-06-03 18:02:073327
[email protected]6dd2f1e2013-09-11 15:06:013328 *did_suppress_message = suppress_this_message;
3329
[email protected]3ab9cb82011-06-03 18:02:073330 if (suppress_this_message) {
3331 // If we are suppressing messages, just reply as if the user immediately
3332 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343333 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073334 }
3335
[email protected]6dd2f1e2013-09-11 15:06:013336 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3337 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323338}
3339
[email protected]b172aee2012-04-10 17:05:263340void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3341 const string16& message,
3342 bool is_reload,
3343 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583344 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513345 if (delegate_)
3346 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073347
3348 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583349 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073350 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523351 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153352 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153353 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343354 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583355 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503356 return;
3357 }
[email protected]3ab9cb82011-06-03 18:02:073358
[email protected]7ab1e7d62009-10-14 23:32:013359 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153360 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3361 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323362 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263363 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523364 reply_msg));
[email protected]420ae012009-04-24 05:16:323365}
3366
[email protected]a796f202012-05-30 14:14:253367bool WebContentsImpl::AddMessageToConsole(int32 level,
3368 const string16& message,
3369 int32 line_no,
[email protected]88b50b62013-09-01 23:05:063370 const string16& source_id) {
[email protected]a796f202012-05-30 14:14:253371 if (!delegate_)
3372 return false;
3373 return delegate_->AddMessageToConsole(this, level, message, line_no,
3374 source_id);
3375}
3376
[email protected]b172aee2012-04-10 17:05:263377WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273378 // We want to base the page config off of the actual URL, rather than the
3379 // virtual URL.
3380 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3381 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003382 GURL url = controller_.GetActiveEntry()
3383 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153384
[email protected]fa944cb82013-11-15 17:51:213385 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323386}
3387
[email protected]0eba810b2012-10-18 03:19:363388int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213389 SiteInstance* instance) {
[email protected]fa944cb82013-11-15 17:51:213390 return GetRenderManager()->CreateRenderView(instance, MSG_ROUTING_NONE,
3391 true, true);
[email protected]0eba810b2012-10-18 03:19:363392}
3393
[email protected]b172aee2012-04-10 17:05:263394void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273395 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253396 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223397
[email protected]ea114722012-03-12 01:11:253398 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173399 if (rdh) // NULL in unittests.
3400 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253401}
3402
[email protected]b172aee2012-04-10 17:05:263403void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443404 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253405 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443406}
3407
[email protected]b172aee2012-04-10 17:05:263408void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563409 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263410 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153411 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523412 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153413 return;
3414
[email protected]9f76c1e2012-03-05 15:15:583415 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3416
[email protected]e5fc1632011-08-08 07:51:533417 // Ignore renderer unresponsive event if debugger is attached to the tab
3418 // since the event may be a result of the renderer sitting on a breakpoint.
3419 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363420 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533421 return;
3422
[email protected]2e9d79f2013-08-16 05:45:563423 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323424 // Hang occurred while firing the beforeunload/unload handler.
3425 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583426 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323427
[email protected]fa944cb82013-11-15 17:51:213428 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323429 return;
3430
3431 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563432 // nothing we can do to recover. If the hang is in the beforeunload handler,
3433 // pretend the beforeunload listeners have all fired and allow the delegate
3434 // to continue closing; the user will not have the option of cancelling the
3435 // close. Otherwise, pretend the unload listeners have all fired and close
3436 // the tab.
3437 bool close = true;
3438 if (is_during_beforeunload) {
3439 delegate_->BeforeUnloadFired(this, true, &close);
3440 }
3441 if (close)
3442 Close(rvh);
[email protected]420ae012009-04-24 05:16:323443 return;
3444 }
3445
[email protected]9f76c1e2012-03-05 15:15:583446 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473447 return;
3448
[email protected]6934a702011-12-20 00:04:513449 if (delegate_)
3450 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323451}
3452
[email protected]b172aee2012-04-10 17:05:263453void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513454 if (delegate_)
3455 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323456}
3457
[email protected]b172aee2012-04-10 17:05:263458void WebContentsImpl::LoadStateChanged(
3459 const GURL& url,
3460 const net::LoadStateWithParam& load_state,
3461 uint64 upload_position,
3462 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323463 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563464 upload_position_ = upload_position;
3465 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503466 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213467 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303468 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213469 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323470 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463471 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213472 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463473 }
[email protected]420ae012009-04-24 05:16:323474}
3475
[email protected]b172aee2012-04-10 17:05:263476void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513477 if (delegate_)
3478 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253479}
3480
[email protected]b172aee2012-04-10 17:05:263481void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553482 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323483 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3485 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513486 if (delegate_)
3487 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093488 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323489}
3490
[email protected]58d5cfe2013-07-10 02:40:523491void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543492 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233493 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223494 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543495}
3496
[email protected]b172aee2012-04-10 17:05:263497void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103498 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213499 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263500 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3501 // here during container initialization and normal window size will be set
3502 // later. In case of tab duplication this resizing to 0x0 prevents setting
3503 // normal size later so just ignore it.
3504 if (!size.IsEmpty())
3505 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323506}
3507
[email protected]af905902013-10-01 21:38:513508void WebContentsImpl::CancelModalDialogsForRenderManager() {
3509 // We need to cancel modal dialogs when doing a process swap, since the load
3510 // deferrer would prevent us from swapping out.
3511 if (dialog_manager_)
3512 dialog_manager_->CancelActiveAndPendingDialogs(this);
3513}
3514
[email protected]7b712ee22013-10-03 00:57:283515void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3516 RenderViewHost* new_host) {
3517 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083518
3519 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003520 if (delegate_)
3521 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393522
[email protected]7b712ee22013-10-03 00:57:283523 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543524}
3525
[email protected]14392a52012-05-02 20:28:443526int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3527 SiteInstance* instance) {
3528 if (!opener_)
3529 return MSG_ROUTING_NONE;
3530
3531 // Recursively create RenderViews for anything else in the opener chain.
3532 return opener_->CreateOpenerRenderViews(instance);
3533}
3534
3535int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3536 int opener_route_id = MSG_ROUTING_NONE;
3537
3538 // If this tab has an opener, ensure it has a RenderView in the given
3539 // SiteInstance as well.
3540 if (opener_)
3541 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3542
[email protected]45a22ad2013-02-21 03:25:003543 // If any of the renderers (current, pending, or swapped out) for this
3544 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213545 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3546 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373547
[email protected]fa944cb82013-11-15 17:51:213548 if (GetRenderManager()->pending_render_view_host() &&
3549 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3550 instance)
3551 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003552
[email protected]fa944cb82013-11-15 17:51:213553 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373554 instance);
3555 if (rvh)
3556 return rvh->GetRoutingID();
3557
[email protected]14392a52012-05-02 20:28:443558 // Create a swapped out RenderView in the given SiteInstance if none exists,
3559 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]fa944cb82013-11-15 17:51:213560 return GetRenderManager()->CreateRenderView(instance, opener_route_id,
3561 true, true);
[email protected]14392a52012-05-02 20:28:443562}
3563
[email protected]b172aee2012-04-10 17:05:263564NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193565 return GetController();
[email protected]3a3d47472010-07-15 21:03:543566}
3567
[email protected]b172aee2012-04-10 17:05:263568WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563569 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323570}
3571
[email protected]10f417c52011-12-28 21:04:233572NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263573 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323574 return controller_.GetLastCommittedEntry();
3575}
3576
[email protected]b172aee2012-04-10 17:05:263577bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443578 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033579 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443580 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323581 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523582
[email protected]420ae012009-04-24 05:16:323583 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443584 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213585 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323586
[email protected]74ce1ad2011-12-16 21:51:463587 // Make sure we use the correct starting page_id in the new RenderView.
3588 UpdateMaxPageIDIfNecessary(render_view_host);
3589 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583590 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463591
[email protected]9f76c1e2012-03-05 15:15:583592 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493593 render_view_host)->CreateRenderView(string16(),
3594 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133595 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523596 return false;
[email protected]14392a52012-05-02 20:28:443597 }
[email protected]a4127722011-04-27 23:13:523598
[email protected]a220b5932013-09-21 03:47:443599#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503600 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3601 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443602 if (rwh_view) {
3603 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3604 render_widget_host->WasResized();
3605 }
[email protected]f8233cc2011-05-31 20:24:503606#endif
3607
[email protected]420ae012009-04-24 05:16:323608 return true;
3609}
3610
[email protected]7d244f12013-08-22 21:41:513611#if defined(OS_ANDROID)
3612bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3613 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3614 MSG_ROUTING_NONE);
3615}
3616#endif
3617
[email protected]b172aee2012-04-10 17:05:263618void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3619 IPC::Message* reply_msg,
3620 bool success,
3621 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543622 if (is_showing_before_unload_dialog_ && !success) {
3623 // If a beforeunload dialog is canceled, we need to stop the throbber from
3624 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293625 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353626 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103627
[email protected]6d65a462013-06-21 21:29:123628 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3629 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543630 }
3631 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583632 static_cast<RenderViewHostImpl*>(
3633 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543634}
3635
[email protected]b172aee2012-04-10 17:05:263636void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213637 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123638 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103639}
[email protected]f45d2a72010-03-08 23:28:353640
[email protected]b172aee2012-04-10 17:05:263641void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103642 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443643 // Can be NULL during tests.
3644 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213645 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363646}
[email protected]9f76c1e2012-03-05 15:15:583647
[email protected]1ac10dca2013-08-20 20:47:043648bool WebContentsImpl::IsHidden() {
3649 return capturer_count_ == 0 && !should_normally_be_visible_;
3650}
3651
[email protected]b0936d22013-11-28 06:47:363652RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213653 return frame_tree_.root()->render_manager();
3654}
3655
[email protected]b172aee2012-04-10 17:05:263656RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583657 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3658}
[email protected]7900bfdb2012-05-24 19:31:243659
[email protected]f8497342013-02-05 22:15:023660BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393661 return browser_plugin_guest_.get();
3662}
3663
[email protected]738f57a2013-06-29 21:06:543664void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3665 CHECK(!browser_plugin_guest_);
3666 browser_plugin_guest_.reset(guest);
3667}
3668
[email protected]f8497342013-02-05 22:15:023669BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393670 return browser_plugin_embedder_.get();
3671}
[email protected]8ff00d72012-10-23 19:12:213672
[email protected]8eb04562013-03-06 03:41:143673BrowserPluginGuestManager*
3674 WebContentsImpl::GetBrowserPluginGuestManager() const {
3675 return static_cast<BrowserPluginGuestManager*>(
3676 GetBrowserContext()->GetUserData(
3677 browser_plugin::kBrowserPluginGuestManagerKeyName));
3678}
3679
[email protected]d9030b82013-07-19 08:26:063680void WebContentsImpl::ClearPowerSaveBlockers(
3681 RenderViewHost* render_view_host) {
3682 STLDeleteValues(&power_save_blockers_[render_view_host]);
3683 power_save_blockers_.erase(render_view_host);
3684}
3685
3686void WebContentsImpl::ClearAllPowerSaveBlockers() {
3687 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3688 i != power_save_blockers_.end(); ++i)
3689 STLDeleteValues(&power_save_blockers_[i->first]);
3690 power_save_blockers_.clear();
3691}
3692
[email protected]dc0fd432013-08-27 15:29:213693gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3694 gfx::Size size;
3695 if (delegate_)
3696 size = delegate_->GetSizeForNewRenderView(this);
3697 if (size.IsEmpty())
3698 size = view_->GetContainerSize();
3699 return size;
3700}
3701
[email protected]9b159a52013-10-03 17:24:553702void WebContentsImpl::OnFrameRemoved(
3703 RenderViewHostImpl* render_view_host,
3704 int64 frame_id) {
3705 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3706 FrameDetached(render_view_host, frame_id));
3707}
3708
[email protected]8ff00d72012-10-23 19:12:213709} // namespace content