blob: 54f768215abe49d4b2cfa1c0661c8a62fd38ff61 [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]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]6b4dcb072012-06-18 22:26:5115#include "base/sys_info.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]65bfd9972012-10-19 03:39:3718#include "cc/switches.h"
[email protected]7a846df2012-09-20 19:17:3919#include "content/browser/browser_plugin/browser_plugin_embedder.h"
20#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]cc510d7e2012-08-08 04:40:1021#include "content/browser/browser_plugin/old/old_browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5922#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4423#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1924#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0425#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4626#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1227#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1628#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3229#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5430#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0531#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0032#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3033#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3234#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5035#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2536#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3337#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3738#include "content/browser/web_contents/interstitial_page_impl.h"
39#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5640#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3941#include "content/common/browser_plugin_messages.h"
[email protected]ce9751942011-09-21 01:57:2442#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5143#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0244#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5745#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5846#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1147#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2048#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4449#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4450#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1751#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1452#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4653#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1554#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0055#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2756#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0057#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3758#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1459#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3260#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3461#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3862#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4263#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2564#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1065#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5066#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2167#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4868#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1869#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5470#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0371#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1672#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2973#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5474#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3475#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3776#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5677#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1678#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4179#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0180#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5282#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2483#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3684#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3185#include "webkit/glue/webpreferences.h"
86
[email protected]f66df822012-05-18 16:52:1787#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5088#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4189#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5790#endif
[email protected]3e45ba92009-02-20 21:09:0091
[email protected]c71fe6402012-08-15 15:22:5592#if defined(USE_AURA) && defined(USE_X11)
93#include "ui/base/touch/touch_factory.h"
94#endif // defined (USE_AURA) && defined(USE_X11)
95
[email protected]420ae012009-04-24 05:16:3296// Cross-Site Navigations
97//
[email protected]b172aee2012-04-10 17:05:2698// If a WebContentsImpl is told to navigate to a different web site (as
99// determined by SiteInstance), it will replace its current RenderViewHost with
100// a new RenderViewHost dedicated to the new SiteInstance. This works as
101// follows:
[email protected]420ae012009-04-24 05:16:32102//
103// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46104// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32105// - The pending RVH is "suspended," so that no navigation messages are sent to
106// its renderer until the onbeforeunload JavaScript handler has a chance to
107// run in the current RVH.
108// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
109// that it has a pending cross-site request. ResourceDispatcherHost will
110// check for this when the response arrives.
111// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46112// cancel all the pending logic. Otherwise we allow the pending RVH to send
113// the navigation request to its renderer.
114// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
115// main resource load on the pending RVH. It checks CrossSiteRequestManager
116// to see that it is a cross-site request, and installs a
117// CrossSiteResourceHandler.
118// - When RDH receives a response, the BufferedResourceHandler determines
119// whether it is a download. If so, it sends a message to the new renderer
120// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26121// pending RVH remains until the next DidNavigate event for this
122// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32123// - After RDH receives a response and determines that it is safe and not a
124// download, it pauses the response to first run the old page's onunload
125// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26126// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32127// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15128// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32129// the ResourceDispatcherHost, who unpauses the response. Data is then sent
130// to the pending RVH.
131// - The pending renderer sends a FrameNavigate message that invokes the
132// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46133// pending RVH.
[email protected]992db4c2011-05-12 15:37:15134// - The previous renderer is kept swapped out in RenderViewHostManager in case
135// the user goes back. The process only stays live if another tab is using
136// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32137
[email protected]6717bf272012-05-11 23:31:25138using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44139
[email protected]8ff00d72012-10-23 19:12:21140namespace content {
[email protected]420ae012009-04-24 05:16:32141namespace {
142
143// Amount of time we wait between when a key event is received and the renderer
144// is queried for its state and pushed to the NavigationEntry.
145const int kQueryStateDelay = 5000;
146
[email protected]6ebdc9b2010-09-27 16:55:57147const int kSyncWaitDelay = 40;
148
[email protected]82114f52012-03-20 22:53:41149const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05150
[email protected]420ae012009-04-24 05:16:32151#if defined(OS_WIN)
152
153BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
154 // Note: erase is required to properly paint some widgets borders. This can
155 // be seen with textfields.
156 InvalidateRect(hwnd, NULL, TRUE);
157 return TRUE;
158}
159#endif
160
[email protected]2c5569662011-03-22 20:45:02161ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21162 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50163 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16164 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47165 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02166 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47167 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02168 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23169 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
170 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47171 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16172 break; // Fall through to rest of function.
173 }
[email protected]5e369672009-11-03 23:48:30174
[email protected]59246c572012-02-10 13:32:13175 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
176 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36177 if (entry.restore_type() ==
178 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13179 if (entry.GetHasPostData())
180 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02181 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13182 }
[email protected]5e369672009-11-03 23:48:30183
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30185}
186
[email protected]10f417c52011-12-28 21:04:23187void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47188 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21189 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50190 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24191 const std::string& embedder_channel_name,
192 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16193 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51194 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54195 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55196 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
197 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36198 if (!entry.GetBaseURLForDataURL().is_empty()) {
199 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
200 params->history_url_for_data_url = entry.GetVirtualURL();
201 }
[email protected]36fc0392011-12-25 03:59:51202 params->referrer = entry.GetReferrer();
203 params->transition = entry.GetTransitionType();
204 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00205 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55206 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34207 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47208 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48209 params->transferred_request_child_id =
210 entry.transferred_global_request_id().child_id;
211 params->transferred_request_request_id =
212 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22213 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00214 // Avoid downloading when in view-source mode.
215 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24216 params->embedder_channel_name = embedder_channel_name;
217 params->embedder_container_id = embedder_container_id;
[email protected]132e281a2012-07-31 18:32:44218 params->is_post = entry.GetHasPostData();
219 if(entry.GetBrowserInitiatedPostData()) {
220 params->browser_initiated_post_data.assign(
221 entry.GetBrowserInitiatedPostData()->front(),
222 entry.GetBrowserInitiatedPostData()->front() +
223 entry.GetBrowserInitiatedPostData()->size());
224
225 }
[email protected]6c6b02d2011-09-02 03:36:47226
[email protected]7c16976c2012-08-04 02:38:23227 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
228 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
229 // We may have been redirected when navigating to the current URL.
230 // Use the URL the user originally intended to visit, if it's valid and if a
231 // POST wasn't involved; the latter case avoids issues with sending data to
232 // the wrong page.
233 params->url = entry.GetOriginalRequestURL();
234 } else {
235 params->url = entry.GetURL();
236 }
237
[email protected]951a64832012-10-11 16:26:37238 params->can_load_local_resources = entry.GetCanLoadLocalResources();
239
[email protected]6c6b02d2011-09-02 03:36:47240 if (delegate)
241 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34242}
243
[email protected]f98f5092012-05-19 00:08:14244int GetSwitchValueAsInt(
245 const CommandLine& command_line,
246 const std::string& switch_string,
247 int min_value) {
248 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
249 int int_value;
250 if (base::StringToInt(string_value, &int_value))
251 return std::max(min_value, int_value);
252 else
253 return min_value;
254}
255
[email protected]420ae012009-04-24 05:16:32256} // namespace
257
[email protected]a81343d232011-12-27 07:39:20258WebContents* WebContents::Create(
259 BrowserContext* browser_context,
260 SiteInstance* site_instance,
261 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19262 const WebContents* base_web_contents) {
263 return WebContentsImpl::Create(
264 browser_context, site_instance, routing_id,
265 static_cast<const WebContentsImpl*>(base_web_contents));
266}
267
268WebContents* WebContents::CreateWithSessionStorage(
269 BrowserContext* browser_context,
270 SiteInstance* site_instance,
271 int routing_id,
[email protected]b172aee2012-04-10 17:05:26272 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19273 const SessionStorageNamespaceMap& session_storage_namespace_map) {
274 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
275
276 for (SessionStorageNamespaceMap::const_iterator it =
277 session_storage_namespace_map.begin();
278 it != session_storage_namespace_map.end();
279 ++it) {
280 new_contents->GetController().SetSessionStorageNamespace(it->first,
281 it->second);
282 }
283
284 new_contents->Init(browser_context, site_instance, routing_id,
285 static_cast<const WebContentsImpl*>(base_web_contents));
286 return new_contents;
[email protected]a81343d232011-12-27 07:39:20287}
[email protected]746d3052012-05-22 15:15:47288
[email protected]299d7f12012-05-23 05:31:15289WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47290 return rvh->GetDelegate()->GetAsWebContents();
291}
292
[email protected]b172aee2012-04-10 17:05:26293// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32294
[email protected]b172aee2012-04-10 17:05:26295WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21296 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19297 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42298 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19299 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57300 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44301 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05302 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34303 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23304 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
305 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34306 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21307 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56308 upload_size_(0),
309 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47310 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57311 capturing_contents_(false),
312 is_being_destroyed_(false),
313 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55314 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57315#if defined(OS_WIN)
316 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
317#endif
[email protected]7ab1e7d62009-10-14 23:32:01318 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56319 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38320 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21321 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
322 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00323 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43324 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20325 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35326}
initial.commit09911bf2008-07-26 23:55:29327
[email protected]b172aee2012-04-10 17:05:26328WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32329 is_being_destroyed_ = true;
330
[email protected]b24b68a2012-09-24 21:57:26331 for (std::set<RenderWidgetHostImpl*>::iterator iter =
332 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
333 (*iter)->DetachDelegate();
334 }
335 created_widgets_.clear();
336
[email protected]3ab9cb82011-06-03 18:02:07337 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55338 if (dialog_creator_)
339 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07340
[email protected]da8543762012-03-20 08:52:20341 if (color_chooser_)
342 color_chooser_->End();
343
[email protected]420ae012009-04-24 05:16:32344 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32345
[email protected]ca13a442012-04-17 14:00:12346 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21347 NotificationService::current()->Notify(
348 NOTIFICATION_WEB_CONTENTS_DESTROYED,
349 Source<WebContents>(this),
350 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32351
352 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07353#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32354 // If we still have a window handle, destroy it. GetNativeView can return
355 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42356 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52357 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58358 if (host && host->GetView())
359 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42360 }
[email protected]420ae012009-04-24 05:16:32361#endif
[email protected]7ab1e7d62009-10-14 23:32:01362
363 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15364 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55365 base::TimeTicks now = base::TimeTicks::Now();
366 base::TimeTicks unload_start_time = close_start_time_;
367 if (!before_unload_end_time_.is_null())
368 unload_start_time = before_unload_end_time_;
369 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
370 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01371 }
[email protected]b5a1d11c2011-02-17 03:09:42372
[email protected]2db9bd72012-04-13 20:20:56373 FOR_EACH_OBSERVER(WebContentsObserver,
374 observers_,
375 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08376
[email protected]6934a702011-12-20 00:04:51377 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42378}
379
[email protected]d1198fd2012-08-13 22:50:19380WebContentsImpl* WebContentsImpl::Create(
381 BrowserContext* browser_context,
382 SiteInstance* site_instance,
383 int routing_id,
384 const WebContentsImpl* base_web_contents) {
385 return CreateWithOpener(browser_context, site_instance, routing_id,
386 base_web_contents, NULL);
387}
388
389WebContentsImpl* WebContentsImpl::CreateWithOpener(
390 BrowserContext* browser_context,
391 SiteInstance* site_instance,
392 int routing_id,
393 const WebContentsImpl* base_web_contents,
394 WebContentsImpl* opener) {
395 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
396
397 new_contents->Init(browser_context, site_instance, routing_id,
398 static_cast<const WebContentsImpl*>(base_web_contents));
399 return new_contents;
400}
401
[email protected]7a846df2012-09-20 19:17:39402WebContentsImpl* WebContentsImpl::CreateGuest(BrowserContext* browser_context,
403 const std::string& host_url,
404 int guest_instance_id) {
405 // The SiteInstance of a given guest is based on the fact that it's a guest
406 // in addition to which platform application the guest belongs to, rather
407 // than the URL that the guest is being navigated to.
408 GURL guest_site(
409 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str()));
410 SiteInstance* guest_site_instance =
411 SiteInstance::CreateForURL(browser_context, guest_site);
412 WebContentsImpl* new_contents = WebContentsImpl::Create(
413 browser_context,
414 guest_site_instance,
415 MSG_ROUTING_NONE,
416 NULL); // base WebContents
417 WebContentsImpl* new_contents_impl =
418 static_cast<WebContentsImpl*>(new_contents);
419
420 // This makes |new_contents| act as a guest.
421 // For more info, see comment above class BrowserPluginGuest.
422 new_contents_impl->browser_plugin_guest_.reset(
[email protected]8ff00d72012-10-23 19:12:21423 BrowserPluginGuest::Create(
[email protected]7a846df2012-09-20 19:17:39424 guest_instance_id,
425 new_contents_impl,
426 new_contents_impl->GetRenderViewHost()));
427 return new_contents;
428}
429
[email protected]b172aee2012-04-10 17:05:26430WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
431 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54432 WebPreferences prefs;
433
434 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
435
436 prefs.developer_extras_enabled = true;
437 prefs.javascript_enabled =
438 !command_line.HasSwitch(switches::kDisableJavaScript);
439 prefs.web_security_enabled =
440 !command_line.HasSwitch(switches::kDisableWebSecurity);
441 prefs.plugins_enabled =
442 !command_line.HasSwitch(switches::kDisablePlugins);
443 prefs.java_enabled =
444 !command_line.HasSwitch(switches::kDisableJava);
445
446 prefs.uses_page_cache =
447 command_line.HasSwitch(switches::kEnableFastback);
448 prefs.remote_fonts_enabled =
449 !command_line.HasSwitch(switches::kDisableRemoteFonts);
450 prefs.xss_auditor_enabled =
451 !command_line.HasSwitch(switches::kDisableXSSAuditor);
452 prefs.application_cache_enabled =
453 !command_line.HasSwitch(switches::kDisableApplicationCache);
454
455 prefs.local_storage_enabled =
456 !command_line.HasSwitch(switches::kDisableLocalStorage);
457 prefs.databases_enabled =
458 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01459#if defined(OS_ANDROID)
460 prefs.webaudio_enabled =
461 command_line.HasSwitch(switches::kEnableWebAudio);
462#else
[email protected]64d69de42012-02-06 00:19:54463 prefs.webaudio_enabled =
464 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01465#endif
[email protected]64d69de42012-02-06 00:19:54466
467 prefs.experimental_webgl_enabled =
468 GpuProcessHost::gpu_enabled() &&
469 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07470#if defined(OS_ANDROID)
471 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
472#else
[email protected]64d69de42012-02-06 00:19:54473 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07474#endif
[email protected]64d69de42012-02-06 00:19:54475
[email protected]5a073092012-06-08 00:42:51476 prefs.flash_3d_enabled =
477 GpuProcessHost::gpu_enabled() &&
478 !command_line.HasSwitch(switches::kDisableFlash3d);
479 prefs.flash_stage3d_enabled =
480 GpuProcessHost::gpu_enabled() &&
481 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19482
[email protected]64d69de42012-02-06 00:19:54483 prefs.gl_multisampling_enabled =
484 !command_line.HasSwitch(switches::kDisableGLMultisampling);
485 prefs.privileged_webgl_extensions_enabled =
486 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
487 prefs.site_specific_quirks_enabled =
488 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
489 prefs.allow_file_access_from_file_urls =
490 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
491 prefs.show_composited_layer_borders =
492 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
493 prefs.show_composited_layer_tree =
494 command_line.HasSwitch(switches::kShowCompositedLayerTree);
495 prefs.show_fps_counter =
496 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08497 prefs.accelerated_compositing_for_overflow_scroll_enabled =
498 command_line.HasSwitch(
499 switches::kEnableAcceleratedCompositingForOverflowScroll);
[email protected]8611a852012-05-23 22:11:19500 prefs.show_paint_rects =
501 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52502 prefs.render_vsync_enabled =
503 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54504 prefs.accelerated_compositing_enabled =
505 GpuProcessHost::gpu_enabled() &&
506 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54507 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23508 command_line.HasSwitch(switches::kForceCompositingMode) &&
509 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54510 prefs.fixed_position_compositing_enabled =
511 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
512 prefs.accelerated_2d_canvas_enabled =
513 GpuProcessHost::gpu_enabled() &&
514 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58515 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27516 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54517 prefs.accelerated_painting_enabled =
518 GpuProcessHost::gpu_enabled() &&
519 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
520 prefs.accelerated_filters_enabled =
521 GpuProcessHost::gpu_enabled() &&
522 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
523 prefs.accelerated_layers_enabled =
524 prefs.accelerated_animation_enabled =
525 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54526 prefs.accelerated_plugins_enabled =
527 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
528 prefs.accelerated_video_enabled =
529 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54530 prefs.fullscreen_enabled =
531 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43532 prefs.css_sticky_position_enabled =
533 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]37ac2a82012-03-01 05:30:16534 prefs.css_regions_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03535 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29536 prefs.css_shaders_enabled =
537 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01538 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03539 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]c71fe6402012-08-15 15:22:55540#if defined(USE_AURA) && defined(USE_X11)
541 prefs.device_supports_touch |=
542 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
543#endif
[email protected]25ee94f2012-09-11 19:16:16544#if defined(OS_WIN)
545 prefs.device_supports_touch = ui::IsTouchDevicePresent();
546#endif
[email protected]d849b122012-07-18 07:35:26547#if defined(OS_ANDROID)
548 prefs.device_supports_mouse = false;
549#endif
[email protected]64d69de42012-02-06 00:19:54550
551#if defined(OS_MACOSX)
552 bool default_enable_scroll_animator = true;
553#else
554 // On CrOS, the launcher always passes in the --enable flag.
555 bool default_enable_scroll_animator = false;
556#endif
557 prefs.enable_scroll_animator = default_enable_scroll_animator;
558 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
559 prefs.enable_scroll_animator = true;
560 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
561 prefs.enable_scroll_animator = false;
562
563 prefs.visual_word_movement_enabled =
564 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54565
566 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32567 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54568 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39569 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21570 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54571 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21572 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54573 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21574 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19575 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21576 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19577 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21578 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54579 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21580 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54581 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21582 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]c521d7462012-10-03 22:28:20583 prefs.accelerated_layers_enabled = false;
584 prefs.accelerated_animation_enabled = false;
585 }
[email protected]8ff00d72012-10-23 19:12:21586 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]c521d7462012-10-03 22:28:20587 prefs.accelerated_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54588
589 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45590 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32591 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54592 prefs.accelerated_video_enabled = false;
593 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45594 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09595 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54596 }
597 }
598
[email protected]b9535422012-02-09 01:47:59599 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58600 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54601 prefs.loads_images_automatically = true;
602 prefs.javascript_enabled = true;
603 }
604
605 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
606
607 // Force accelerated compositing and 2d canvas off for chrome:, about: and
608 // chrome-devtools: pages (unless it's specifically allowed).
609 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54610 url.SchemeIs(chrome::kChromeUIScheme) ||
611 (url.SchemeIs(chrome::kAboutScheme) &&
612 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25613 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54614 prefs.accelerated_compositing_enabled = false;
615 prefs.accelerated_2d_canvas_enabled = false;
616 }
[email protected]43d9d782012-03-01 15:40:09617
[email protected]f98f5092012-05-19 00:08:14618 if (command_line.HasSwitch(switches::kDefaultTileWidth))
619 prefs.default_tile_width =
620 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
621 if (command_line.HasSwitch(switches::kDefaultTileHeight))
622 prefs.default_tile_height =
623 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
624 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
625 prefs.max_untiled_layer_width =
626 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
627 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
628 prefs.max_untiled_layer_height =
629 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
630
[email protected]ffabb1e2012-10-12 19:51:17631 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
632 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19633 // Only apply when using DIP coordinate system as this setting interferes
634 // with fixed layout mode.
635 prefs.apply_default_device_scale_factor_in_compositor = true;
636 }
637
[email protected]de023762012-07-26 17:10:17638 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
639 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10640
[email protected]e755a382012-09-13 17:16:35641 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
642 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12643
[email protected]6b4dcb072012-06-18 22:26:51644 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
645
[email protected]1c0c9bc2012-10-08 22:41:48646 prefs.apply_page_scale_factor_in_compositor =
[email protected]65bfd9972012-10-19 03:39:37647 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:48648
[email protected]8ff00d72012-10-23 19:12:21649 GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54650
[email protected]97456602012-10-03 18:44:25651 // Disable compositing in guests until we have compositing path implemented
652 // for guests.
[email protected]ba415072012-10-15 15:58:06653 if (rvh->GetProcess()->IsGuest()) {
[email protected]97456602012-10-03 18:44:25654 prefs.force_compositing_mode = false;
[email protected]ba415072012-10-15 15:58:06655 prefs.accelerated_compositing_enabled = false;
656 }
[email protected]97456602012-10-03 18:44:25657
[email protected]64d69de42012-02-06 00:19:54658 return prefs;
659}
660
[email protected]b172aee2012-04-10 17:05:26661RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28662 return &render_manager_;
663}
664
[email protected]7bb761892012-07-20 09:32:47665bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
666 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56667 if (GetWebUI() &&
668 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17669 return true;
[email protected]d2353452012-01-19 19:53:56670 }
[email protected]f82d57b52011-04-27 19:13:17671
[email protected]d8c660432011-12-22 20:51:25672 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
673 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10674 while ((observer = it.GetNext()) != NULL)
675 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53676 return true;
[email protected]403415a2011-01-10 18:57:53677
[email protected]7bb761892012-07-20 09:32:47678 // Message handlers should be aware of which RenderViewHost sent the
679 // message, which is temporarily stored in message_source_.
680 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18681 bool handled = true;
682 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26683 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58684 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
685 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24686 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
687 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18688 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
689 OnDidLoadResourceFromMemoryCache)
690 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
691 OnDidDisplayInsecureContent)
692 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
693 OnDidRunInsecureContent)
694 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
695 OnDocumentLoadedInFrame)
696 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26697 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
698 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17699 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
700 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25701 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26702 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59703 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21704 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20705 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
706 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
707 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16708 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]59363fc92012-09-05 03:46:31709#if defined(OS_ANDROID)
710 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
711 OnFindMatchRectsReply)
712#endif
[email protected]d952a052011-09-06 18:42:45713 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10714 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20715 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
716 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
717 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
718 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29719 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50720 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50721 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
722 OnRequestPpapiBrokerPermission)
[email protected]19be7a62012-10-01 23:03:37723 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
724 OnBrowserPluginCreateGuest)
[email protected]724159a2010-12-30 01:11:18725 IPC_MESSAGE_UNHANDLED(handled = false)
726 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47727 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18728
729 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21730 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18731 GetRenderProcessHost()->ReceivedBadMessage();
732 }
733
734 return handled;
735}
736
[email protected]b172aee2012-04-10 17:05:26737void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18738 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21739 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43740 if (delegate_)
741 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18742}
743
[email protected]d1198fd2012-08-13 22:50:19744NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56745 return controller_;
746}
747
[email protected]d1198fd2012-08-13 22:50:19748const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56749 return controller_;
750}
751
[email protected]8ff00d72012-10-23 19:12:21752BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55753 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30754}
755
[email protected]b172aee2012-04-10 17:05:26756const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31757 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23758 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51759 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31760}
761
[email protected]8ff00d72012-10-23 19:12:21762WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31763 return delegate_;
764}
765
[email protected]8ff00d72012-10-23 19:12:21766void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31767 // TODO(cbentzel): remove this debugging code?
768 if (delegate == delegate_)
769 return;
770 if (delegate_)
771 delegate_->Detach(this);
772 delegate_ = delegate;
773 if (delegate_)
774 delegate_->Attach(this);
775}
776
[email protected]8ff00d72012-10-23 19:12:21777RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41778 RenderViewHostImpl* host = render_manager_.current_host();
779 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16780}
781
[email protected]b172aee2012-04-10 17:05:26782RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31783 return render_manager_.current_host();
784}
785
[email protected]6b618e62012-08-16 12:59:18786int WebContentsImpl::GetRoutingID() const {
787 if (!GetRenderViewHost())
788 return MSG_ROUTING_NONE;
789
790 return GetRenderViewHost()->GetRoutingID();
791}
792
[email protected]b172aee2012-04-10 17:05:26793RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31794 return render_manager_.GetRenderWidgetHostView();
795}
796
[email protected]8ff00d72012-10-23 19:12:21797WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31798 return view_.get();
799}
800
[email protected]8ff00d72012-10-23 19:12:21801WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50802 WebUIControllerFactory* factory =
[email protected]8ff00d72012-10-23 19:12:21803 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]863f70a2012-01-27 02:05:50804 if (!factory)
805 return NULL;
[email protected]d2353452012-01-19 19:53:56806 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22807 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50808 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22809 if (controller) {
810 web_ui->SetController(controller);
811 return web_ui;
812 }
813
814 delete web_ui;
815 return NULL;
816}
817
[email protected]8ff00d72012-10-23 19:12:21818WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31819 return render_manager_.web_ui() ? render_manager_.web_ui()
820 : render_manager_.pending_web_ui();
821}
822
[email protected]8ff00d72012-10-23 19:12:21823WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31824 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34825}
826
[email protected]86ef6a392012-05-11 22:03:11827void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22828 if (GetUserAgentOverride() == override)
829 return;
830
831 renderer_preferences_.user_agent_override = override;
832
833 // Send the new override string to the renderer.
834 RenderViewHost* host = GetRenderViewHost();
835 if (host)
836 host->SyncRendererPrefs();
837
838 // Reload the page if a load is currently in progress to avoid having
839 // different parts of the page loaded using different user agents.
840 NavigationEntry* entry = controller_.GetActiveEntry();
841 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
842 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53843
844 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
845 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11846}
847
848const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22849 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11850}
851
[email protected]b172aee2012-04-10 17:05:26852const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55853 // Transient entries take precedence. They are used for interstitial pages
854 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23855 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08856 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21857 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30858 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23859 if (entry) {
[email protected]b5cca982011-05-26 04:42:08860 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23861 }
[email protected]7ade2732011-02-10 00:13:58862 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
863 render_manager_.pending_web_ui() : render_manager_.web_ui();
864 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54865 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55866 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54867 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35868 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22869 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54870 if (!title.empty())
871 return title;
872 }
873 }
874
875 // We use the title for the last committed entry rather than a pending
876 // navigation entry. For example, when the user types in a URL, we want to
877 // keep the old page's title until the new load has committed and we get a new
878 // title.
[email protected]96d185d2009-04-24 03:28:54879 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23880 if (entry) {
[email protected]b5cca982011-05-26 04:42:08881 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23882 }
[email protected]987fc3a2011-05-26 14:18:09883
884 // |page_title_when_no_navigation_entry_| is finally used
885 // if no title cannot be retrieved.
886 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54887}
888
[email protected]b172aee2012-04-10 17:05:26889int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46890 return GetMaxPageIDForSiteInstance(GetSiteInstance());
891}
892
[email protected]b172aee2012-04-10 17:05:26893int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
894 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33895 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
896 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46897
[email protected]b6583592012-01-25 19:52:33898 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46902 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
903}
904
[email protected]b172aee2012-04-10 17:05:26905void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33906 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46907 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33908 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34909}
910
[email protected]b172aee2012-04-10 17:05:26911void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
912 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57913}
914
[email protected]b172aee2012-04-10 17:05:26915SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58916 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54917}
918
[email protected]b172aee2012-04-10 17:05:26919SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38920 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
921 render_manager_.pending_render_view_host() :
922 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58923 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38924}
925
[email protected]b172aee2012-04-10 17:05:26926bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49928}
929
[email protected]b172aee2012-04-10 17:05:26930bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31931 return waiting_for_response_;
932}
933
[email protected]b172aee2012-04-10 17:05:26934const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31935 return load_state_;
936}
937
[email protected]b172aee2012-04-10 17:05:26938const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31939 return load_state_host_;
940}
941
[email protected]b172aee2012-04-10 17:05:26942uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31943 return upload_size_;
944}
945
[email protected]b172aee2012-04-10 17:05:26946uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31947 return upload_position_;
948}
949
[email protected]b172aee2012-04-10 17:05:26950const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31951 return encoding_;
952}
953
[email protected]b172aee2012-04-10 17:05:26954bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31955 return displayed_insecure_content_;
956}
957
[email protected]b172aee2012-04-10 17:05:26958void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31959 capturing_contents_ = cap;
960}
961
[email protected]b172aee2012-04-10 17:05:26962bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31963 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
964 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
965 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49966}
967
[email protected]b172aee2012-04-10 17:05:26968void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
969 int error_code) {
[email protected]443b80e2010-12-14 00:42:23970 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34971 return;
972
[email protected]443b80e2010-12-14 00:42:23973 crashed_status_ = status;
974 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21975 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34976}
977
[email protected]b172aee2012-04-10 17:05:26978base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31979 return crashed_status_;
980}
981
[email protected]b172aee2012-04-10 17:05:26982bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31983 return is_being_destroyed_;
984}
985
[email protected]b172aee2012-04-10 17:05:26986void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34987 if (delegate_)
988 delegate_->NavigationStateChanged(this, changed_flags);
989}
990
[email protected]3e324142012-06-25 18:26:33991base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
992 return last_selected_time_;
993}
994
[email protected]9e2e4632012-07-27 16:38:41995void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54996 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04997 RenderWidgetHostViewPort* rwhv =
998 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16999 if (rwhv) {
[email protected]9e2e4632012-07-27 16:38:411000 rwhv->WasShown();
[email protected]789e9152009-08-04 21:59:431001#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161002 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431003#endif
1004 }
[email protected]96d185d2009-04-24 03:28:541005
[email protected]5ac20162010-11-24 23:33:111006 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381007
[email protected]9e2e4632012-07-27 16:38:411008 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
[email protected]b9769d82012-02-10 00:23:591009
1010 // The resize rect might have changed while this was inactive -- send the new
1011 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581012 RenderViewHostImpl* rvh =
1013 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591014 if (rvh) {
1015 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1016 }
[email protected]96d185d2009-04-24 03:28:541017
[email protected]3e324142012-06-25 18:26:331018 bool is_visible = true;
[email protected]8ff00d72012-10-23 19:12:211019 NotificationService::current()->Notify(
1020 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1021 Source<WebContents>(this),
1022 Details<bool>(&is_visible));
[email protected]be1f56ab2011-12-22 06:55:311023}
1024
[email protected]b172aee2012-04-10 17:05:261025void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:311026 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:521027 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
1028 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261029 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521030 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331031 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521032 // calls us).
[email protected]c30585c2012-02-16 15:02:041033 RenderWidgetHostViewPort* rwhv =
1034 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:161035 if (rwhv)
1036 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541037 }
1038
[email protected]375fa1b2012-05-22 22:05:371039 bool is_visible = false;
[email protected]8ff00d72012-10-23 19:12:211040 NotificationService::current()->Notify(
1041 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
1042 Source<WebContents>(this),
1043 Details<bool>(&is_visible));
[email protected]375fa1b2012-05-22 22:05:371044}
1045
[email protected]b172aee2012-04-10 17:05:261046bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311047 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271048 return WillNotifyDisconnection() &&
1049 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581050 !static_cast<RenderViewHostImpl*>(
1051 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311052}
1053
[email protected]b172aee2012-04-10 17:05:261054void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:271055 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:251056 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:271057}
1058
[email protected]b172aee2012-04-10 17:05:261059WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441060 // We use our current SiteInstance since the cloned entry will use it anyway.
1061 // We pass |this| for the |base_web_contents| to size the view correctly, and
1062 // our own opener so that the cloned page can access it if it was before.
[email protected]d1198fd2012-08-13 22:50:191063 WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
1064 GetSiteInstance(), MSG_ROUTING_NONE,
1065 this, opener_);
1066 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221067 FOR_EACH_OBSERVER(WebContentsObserver,
1068 observers_,
1069 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271070 return tc;
1071}
1072
[email protected]b172aee2012-04-10 17:05:261073gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271074 return view_->GetContentNativeView();
1075}
1076
[email protected]b172aee2012-04-10 17:05:261077gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271078 return view_->GetNativeView();
1079}
1080
[email protected]b172aee2012-04-10 17:05:261081void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271082 view_->GetContainerBounds(out);
1083}
1084
[email protected]b172aee2012-04-10 17:05:261085void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271086 view_->Focus();
1087}
1088
[email protected]14392a52012-05-02 20:28:441089void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211090 const NotificationSource& source,
1091 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441092 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211093 case NOTIFICATION_WEB_CONTENTS_DESTROYED:
1094 OnWebContentsDestroyed(Source<WebContents>(source).ptr());
[email protected]14392a52012-05-02 20:28:441095 break;
[email protected]8ff00d72012-10-23 19:12:211096 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1097 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501098 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1099 i != pending_widget_views_.end(); ++i) {
1100 if (host->GetView() == i->second) {
1101 pending_widget_views_.erase(i);
1102 break;
1103 }
1104 }
1105 break;
1106 }
[email protected]14392a52012-05-02 20:28:441107 default:
1108 NOTREACHED();
1109 }
1110}
1111
[email protected]d1198fd2012-08-13 22:50:191112void WebContentsImpl::Init(BrowserContext* browser_context,
1113 SiteInstance* site_instance,
1114 int routing_id,
1115 const WebContents* base_web_contents) {
1116 render_manager_.Init(browser_context, site_instance, routing_id);
1117
[email protected]8ff00d72012-10-23 19:12:211118 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191119 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
1120 if (view_.get()) {
1121 CHECK(render_view_host_delegate_view_);
1122 } else {
[email protected]8ff00d72012-10-23 19:12:211123 WebContentsViewDelegate* delegate =
1124 GetContentClient()->browser()->GetWebContentsViewDelegate(
[email protected]d1198fd2012-08-13 22:50:191125 this);
1126 view_.reset(CreateWebContentsView(
1127 this, delegate, &render_view_host_delegate_view_));
1128 CHECK(render_view_host_delegate_view_);
1129 }
1130 CHECK(view_.get());
1131
1132 // We have the initial size of the view be based on the size of the view of
1133 // the passed in WebContents.
1134 view_->CreateView(base_web_contents ?
1135 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
1136
1137 // Listen for whether our opener gets destroyed.
1138 if (opener_) {
[email protected]8ff00d72012-10-23 19:12:211139 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1140 Source<WebContents>(opener_));
[email protected]d1198fd2012-08-13 22:50:191141 }
1142
1143 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211144 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1145 NotificationService::AllBrowserContextsAndSources());
[email protected]d1198fd2012-08-13 22:50:191146#if defined(ENABLE_JAVA_BRIDGE)
1147 java_bridge_dispatcher_host_manager_.reset(
1148 new JavaBridgeDispatcherHostManager(this));
1149#endif
1150
[email protected]8ff00d72012-10-23 19:12:211151 old_browser_plugin_host_.reset(new old::BrowserPluginHost(this));
[email protected]d1198fd2012-08-13 22:50:191152}
1153
[email protected]14392a52012-05-02 20:28:441154void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1155 // Clear the opener if it has been closed.
1156 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211157 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1158 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441159 opener_ = NULL;
1160 }
1161}
1162
[email protected]b172aee2012-04-10 17:05:261163void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311164 observers_.AddObserver(observer);
1165}
1166
[email protected]b172aee2012-04-10 17:05:261167void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311168 observers_.RemoveObserver(observer);
1169}
1170
[email protected]b172aee2012-04-10 17:05:261171void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341172 if (delegate_)
1173 delegate_->ActivateContents(this);
1174}
1175
[email protected]b172aee2012-04-10 17:05:261176void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121177 if (delegate_)
1178 delegate_->DeactivateContents(this);
1179}
1180
[email protected]b172aee2012-04-10 17:05:261181void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481182 if (delegate_)
1183 delegate_->LostCapture();
1184}
1185
[email protected]b24b68a2012-09-24 21:57:261186void WebContentsImpl::RenderWidgetDeleted(
1187 RenderWidgetHostImpl* render_widget_host) {
1188 if (is_being_destroyed_) {
1189 // |created_widgets_| might have been destroyed.
1190 return;
1191 }
1192
1193 std::set<RenderWidgetHostImpl*>::iterator iter =
1194 created_widgets_.find(render_widget_host);
1195 if (iter != created_widgets_.end())
1196 created_widgets_.erase(iter);
1197}
1198
[email protected]b172aee2012-04-10 17:05:261199bool WebContentsImpl::PreHandleKeyboardEvent(
1200 const NativeWebKeyboardEvent& event,
1201 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481202 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131203 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481204}
1205
[email protected]b172aee2012-04-10 17:05:261206void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481207 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131208 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481209}
1210
[email protected]b172aee2012-04-10 17:05:261211void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431212 if (delegate_)
1213 delegate_->HandleMouseDown();
1214}
1215
[email protected]b172aee2012-04-10 17:05:261216void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481217 if (delegate_)
1218 delegate_->HandleMouseUp();
1219}
1220
[email protected]590a634e2012-07-19 16:38:231221void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481222 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231223 delegate_->HandlePointerActivate();
1224}
1225
1226void WebContentsImpl::HandleGestureBegin() {
1227 if (delegate_)
1228 delegate_->HandleGestureBegin();
1229}
1230
1231void WebContentsImpl::HandleGestureEnd() {
1232 if (delegate_)
1233 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481234}
1235
[email protected]b172aee2012-04-10 17:05:261236void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471237 if (delegate_)
1238 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1239}
1240
[email protected]b172aee2012-04-10 17:05:261241bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381242 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121243}
1244
[email protected]a9c81f02012-06-01 00:15:441245void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1246 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371247 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441248 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371249 } else {
1250 GotResponseToLockMouseRequest(false);
1251 }
1252}
1253
[email protected]b172aee2012-04-10 17:05:261254void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371255 if (delegate_)
1256 delegate_->LostMouseLock();
1257}
1258
[email protected]bafe6cd2012-05-23 23:09:501259void WebContentsImpl::CreateNewWindow(
1260 int route_id,
[email protected]97714c82012-06-06 10:15:131261 const ViewHostMsg_CreateWindow_Params& params,
1262 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501263 if (delegate_ && !delegate_->ShouldCreateWebContents(
1264 this, route_id, params.window_container_type, params.frame_name,
1265 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091266 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501267 return;
1268 }
1269
1270 // We usually create the new window in the same BrowsingInstance (group of
1271 // script-related windows), by passing in the current SiteInstance. However,
1272 // if the opener is being suppressed, we create a new SiteInstance in its own
1273 // BrowsingInstance.
1274 scoped_refptr<SiteInstance> site_instance =
1275 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571276 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501277 GetSiteInstance();
1278
1279 // Create the new web contents. This will automatically create the new
1280 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191281 WebContentsImpl* new_contents =
1282 new WebContentsImpl(GetBrowserContext(),
1283 params.opener_suppressed ? NULL : this);
1284
1285 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341286 //
1287 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191288 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211289 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571290 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591291 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211292 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341293 BrowserContext::GetStoragePartition(GetBrowserContext(),
1294 site_instance);
[email protected]d1198fd2012-08-13 22:50:191295 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341296 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191297 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1298 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1299 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1300 new_contents->GetController().SetSessionStorageNamespace(
1301 partition_id,
1302 session_storage_namespace);
1303 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1304
[email protected]bafe6cd2012-05-23 23:09:501305 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1306
1307 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211308 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501309
1310 // TODO(brettw): It seems bogus that we have to call this function on the
1311 // newly created object and give it one of its own member variables.
1312 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1313
1314 // Save the created window associated with the route so we can show it
1315 // later.
1316 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1317 pending_contents_[route_id] = new_contents;
1318 }
1319
1320 if (delegate_) {
1321 delegate_->WebContentsCreated(
1322 this, params.opener_frame_id, params.target_url, new_contents);
1323 }
1324
1325 if (params.opener_suppressed) {
1326 // When the opener is suppressed, the original renderer cannot access the
1327 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001328 bool was_blocked = false;
1329 if (delegate_) {
1330 gfx::Rect initial_pos;
1331 delegate_->AddNewContents(
1332 this, new_contents, params.disposition, initial_pos,
1333 params.user_gesture, &was_blocked);
1334 }
1335 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211336 OpenURLParams open_params(params.target_url,
1337 Referrer(),
1338 CURRENT_TAB,
1339 PAGE_TRANSITION_LINK,
1340 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001341 new_contents->OpenURL(open_params);
1342 }
[email protected]bafe6cd2012-05-23 23:09:501343 }
1344}
1345
1346void WebContentsImpl::CreateNewWidget(int route_id,
1347 WebKit::WebPopupType popup_type) {
1348 CreateNewWidget(route_id, false, popup_type);
1349}
1350
1351void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1352 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1353}
1354
1355void WebContentsImpl::CreateNewWidget(int route_id,
1356 bool is_fullscreen,
1357 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211358 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501359 RenderWidgetHostImpl* widget_host =
1360 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261361 created_widgets_.insert(widget_host);
1362
[email protected]bafe6cd2012-05-23 23:09:501363 RenderWidgetHostViewPort* widget_view =
1364 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1365 if (!is_fullscreen) {
1366 // Popups should not get activated.
1367 widget_view->SetPopupType(popup_type);
1368 }
1369 // Save the created widget associated with the route so we can show it later.
1370 pending_widget_views_[route_id] = widget_view;
1371
1372#if defined(OS_MACOSX)
1373 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1374 // to allow it to survive the trip without being hosted.
1375 base::mac::NSObjectRetain(widget_view->GetNativeView());
1376#endif
1377}
1378
1379void WebContentsImpl::ShowCreatedWindow(int route_id,
1380 WindowOpenDisposition disposition,
1381 const gfx::Rect& initial_pos,
1382 bool user_gesture) {
1383 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001384 if (contents) {
1385 WebContentsDelegate* delegate = GetDelegate();
1386 if (delegate) {
1387 delegate->AddNewContents(
1388 this, contents, disposition, initial_pos, user_gesture, NULL);
1389 }
1390 }
[email protected]bafe6cd2012-05-23 23:09:501391}
1392
1393void WebContentsImpl::ShowCreatedWidget(int route_id,
1394 const gfx::Rect& initial_pos) {
1395 ShowCreatedWidget(route_id, false, initial_pos);
1396}
1397
1398void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1399 ShowCreatedWidget(route_id, true, gfx::Rect());
1400}
1401
1402void WebContentsImpl::ShowCreatedWidget(int route_id,
1403 bool is_fullscreen,
1404 const gfx::Rect& initial_pos) {
1405 if (delegate_)
1406 delegate_->RenderWidgetShowing();
1407
1408 RenderWidgetHostViewPort* widget_host_view =
1409 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1410 if (!widget_host_view)
1411 return;
1412 if (is_fullscreen) {
1413 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1414 } else {
1415 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1416 }
[email protected]89054502012-06-03 10:29:241417
1418 RenderWidgetHostImpl* render_widget_host_impl =
1419 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1420 render_widget_host_impl->Init();
1421 // Only allow privileged mouse lock for fullscreen render widget, which is
1422 // used to implement Pepper Flash fullscreen.
1423 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501424
1425#if defined(OS_MACOSX)
1426 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1427 // properly embedded (or purposefully ignored) we can release the retain we
1428 // took in CreateNewWidget().
1429 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1430#endif
1431}
1432
1433WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1434 PendingContents::iterator iter = pending_contents_.find(route_id);
1435
1436 // Certain systems can block the creation of new windows. If we didn't succeed
1437 // in creating one, just return NULL.
1438 if (iter == pending_contents_.end()) {
1439 return NULL;
1440 }
1441
1442 WebContentsImpl* new_contents = iter->second;
1443 pending_contents_.erase(route_id);
1444
1445 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1446 !new_contents->GetRenderViewHost()->GetView())
1447 return NULL;
1448
1449 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1450 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1451 return new_contents;
1452}
1453
1454RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1455 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1456 if (iter == pending_widget_views_.end()) {
1457 DCHECK(false);
1458 return NULL;
1459 }
1460
1461 RenderWidgetHostView* widget_host_view = iter->second;
1462 pending_widget_views_.erase(route_id);
1463
1464 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1465 if (!widget_host->GetProcess()->HasConnection()) {
1466 // The view has gone away or the renderer crashed. Nothing to do.
1467 return NULL;
1468 }
1469
1470 return widget_host_view;
1471}
1472
1473void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211474 const ContextMenuParams& params,
1475 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501476 // Allow WebContentsDelegates to handle the context menu operation first.
1477 if (delegate_ && delegate_->HandleContextMenu(params))
1478 return;
1479
[email protected]ba16e3a2012-09-07 04:14:521480 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501481}
1482
[email protected]f13b4202012-06-12 23:53:231483void WebContentsImpl::RequestMediaAccessPermission(
[email protected]8ff00d72012-10-23 19:12:211484 const MediaStreamRequest* request,
1485 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231486 if (delegate_)
1487 delegate_->RequestMediaAccessPermission(this, request, callback);
1488 else
[email protected]8ff00d72012-10-23 19:12:211489 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231490}
1491
[email protected]16383382012-09-05 23:57:261492#if defined(OS_ANDROID)
1493void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1494 if (delegate_)
1495 delegate_->AttachLayer(this, layer);
1496}
1497
1498void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1499 if (delegate_)
1500 delegate_->RemoveLayer(this, layer);
1501}
1502#endif
1503
[email protected]b172aee2012-04-10 17:05:261504void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231505 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331506 if (delegate_)
1507 delegate_->UpdatePreferredSize(this, pref_size);
1508}
1509
[email protected]b172aee2012-04-10 17:05:261510void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341511 if (delegate_)
1512 delegate_->ResizeDueToAutoResize(this, new_size);
1513}
1514
[email protected]b172aee2012-04-10 17:05:261515WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201516 if (!delegate_)
1517 return NULL;
[email protected]00c37fc2011-08-02 00:22:501518
[email protected]e5d549d2011-12-28 01:29:201519 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1520 // Notify observers.
1521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1522 DidOpenURL(params.url, params.referrer,
1523 params.disposition, params.transition));
1524 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341525}
1526
[email protected]6b618e62012-08-16 12:59:181527bool WebContentsImpl::Send(IPC::Message* message) {
1528 if (!GetRenderViewHost()) {
1529 delete message;
1530 return false;
1531 }
1532
1533 return GetRenderViewHost()->Send(message);
1534}
1535
[email protected]b172aee2012-04-10 17:05:261536bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501537 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251538 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231539 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251540 reload_type);
[email protected]876bc832010-09-07 16:29:541541}
[email protected]96d185d2009-04-24 03:28:541542
[email protected]ba45bfd2012-05-22 21:51:441543void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211544 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441545 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1546 RenderViewForInterstitialPageCreated(render_view_host));
1547}
1548
[email protected]b172aee2012-04-10 17:05:261549bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231550 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501551 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401552 // The renderer will reject IPC messages with URLs longer than
1553 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211554 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401555 return false;
1556
[email protected]9f76c1e2012-03-05 15:15:581557 RenderViewHostImpl* dest_render_view_host =
1558 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401559 if (!dest_render_view_host)
1560 return false; // Unable to create the desired render view host.
1561
[email protected]80a8fad2011-01-29 04:02:381562 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071563 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581564 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501565 WebUIControllerFactory* factory =
[email protected]8ff00d72012-10-23 19:12:211566 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271567 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501568 bool is_allowed_in_web_ui_renderer =
1569 factory &&
[email protected]24e18252012-04-16 21:26:271570 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1571 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211572 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231573 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271574 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211575 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231576 CHECK(0);
1577 }
[email protected]54ec6472010-04-09 19:39:581578
[email protected]96d185d2009-04-24 03:28:541579 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441580 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521581 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441582 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511583 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541584
[email protected]7bb761892012-07-20 09:32:471585 // Notify observers that we will navigate in this RV.
1586 FOR_EACH_OBSERVER(WebContentsObserver,
1587 observers_,
1588 AboutToNavigateRenderView(dest_render_view_host));
1589
[email protected]96d185d2009-04-24 03:28:541590 // Used for page load time metrics.
1591 current_load_start_ = base::TimeTicks::Now();
1592
1593 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241594 std::string embedder_channel_name;
1595 int embedder_container_id;
1596 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1597 &embedder_channel_name,
1598 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341599 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271600 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241601 embedder_channel_name,
1602 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471603 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341604 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541605
[email protected]36fc0392011-12-25 03:59:511606 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541607 // HACK!! This code suppresses javascript: URLs from being added to
1608 // session history, which is what we want to do for javascript: URLs that
1609 // do not generate content. What we really need is a message from the
1610 // renderer telling us that a new page was not created. The same message
1611 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511612 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541613 return false;
1614 }
1615
[email protected]3c9e1872010-11-18 16:17:491616 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251617 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041618 observers_,
[email protected]36fc0392011-12-25 03:59:511619 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541620
[email protected]09b29342011-06-24 19:18:481621 if (delegate_)
1622 delegate_->DidNavigateToPendingEntry(this);
1623
[email protected]d5f942ba2008-09-26 19:30:341624 return true;
1625}
1626
[email protected]b172aee2012-04-10 17:05:261627void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331628 const SiteInstance* site_instance,
1629 int history_length,
1630 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411631 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1632 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191633 if (render_manager_.pending_render_view_host()) {
1634 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141635 return;
[email protected]9e1ad4b2011-08-14 16:49:191636 }
[email protected]9f76c1e2012-03-05 15:15:581637 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191638 if (!rvh) {
1639 NOTREACHED();
1640 return;
1641 }
[email protected]9f76c1e2012-03-05 15:15:581642 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191643 NOTREACHED();
1644 return;
1645 }
[email protected]6b618e62012-08-16 12:59:181646 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1647 history_length,
1648 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141649}
1650
[email protected]b172aee2012-04-10 17:05:261651void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271652 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541653 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1654 return;
1655 }
[email protected]9f76c1e2012-03-05 15:15:581656 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541657}
1658
[email protected]b172aee2012-04-10 17:05:261659bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271660 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541661}
1662
[email protected]b172aee2012-04-10 17:05:261663InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271664 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221665}
1666
[email protected]b172aee2012-04-10 17:05:261667bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161668 // WebKit creates Document object when MIME type is application/xhtml+xml,
1669 // so we also support this MIME type.
1670 return contents_mime_type_ == "text/html" ||
1671 contents_mime_type_ == "text/xml" ||
1672 contents_mime_type_ == "application/xhtml+xml" ||
1673 contents_mime_type_ == "text/plain" ||
1674 contents_mime_type_ == "text/css" ||
1675 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1676}
1677
[email protected]b172aee2012-04-10 17:05:261678void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591679 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161680 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481681 download_stats::RecordDownloadSource(
1682 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211683 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141684 return;
[email protected]c7dd2f62011-07-18 15:57:591685 }
1686
1687 Stop();
1688
1689 // Create the save package and possibly prompt the user for the name to save
1690 // the page as. The user prompt is an asynchronous operation that runs on
1691 // another thread.
1692 save_package_ = new SavePackage(this);
1693 save_package_->GetSaveInfo();
1694}
1695
1696// Used in automated testing to bypass prompting the user for file names.
1697// Instead, the names and paths are hard coded rather than running them through
1698// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261699bool WebContentsImpl::SavePage(const FilePath& main_file,
1700 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211701 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591702 // Stop the page from navigating.
1703 Stop();
1704
1705 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211706 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591707}
1708
[email protected]b172aee2012-04-10 17:05:261709void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121710 const FilePath& file,
1711 const base::Callback<void(const FilePath&, int64)>& callback) {
1712 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1713}
1714
[email protected]b172aee2012-04-10 17:05:261715bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231716 NavigationEntryImpl* active_entry =
1717 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321718 return (active_entry != NULL &&
1719 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511720 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321721}
1722
[email protected]b172aee2012-04-10 17:05:261723const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271724 return contents_mime_type_;
1725}
1726
[email protected]b172aee2012-04-10 17:05:261727bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271728 return notify_disconnection_;
1729}
1730
[email protected]b172aee2012-04-10 17:05:261731void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311732 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181733 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161734}
1735
[email protected]b172aee2012-04-10 17:05:261736void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311737 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181738 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161739}
1740
[email protected]8ff00d72012-10-23 19:12:211741RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271742 return &renderer_preferences_;
1743}
1744
[email protected]b172aee2012-04-10 17:05:261745void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271746 new_tab_start_time_ = time;
1747}
1748
[email protected]b172aee2012-04-10 17:05:261749base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271750 return new_tab_start_time_;
1751}
1752
[email protected]e35ccd52012-05-23 16:22:471753void WebContentsImpl::Close() {
1754 Close(GetRenderViewHost());
1755}
1756
[email protected]b172aee2012-04-10 17:05:261757void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151758 if (close_start_time_.is_null())
1759 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011760}
1761
[email protected]b172aee2012-04-10 17:05:261762bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191763#if defined(OS_CHROMEOS)
1764 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1765 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511766 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201767 return false;
1768 return true;
[email protected]46624bf2010-06-09 16:04:191769#else
1770 return true;
1771#endif
1772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521775 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581776 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511777 if (delegate_)
1778 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341779}
1780
[email protected]e35ccd52012-05-23 16:22:471781void WebContentsImpl::UserGestureDone() {
1782 OnUserGesture();
1783}
1784
[email protected]b172aee2012-04-10 17:05:261785void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271786 closed_by_user_gesture_ = value;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271790 return closed_by_user_gesture_;
1791}
1792
[email protected]b172aee2012-04-10 17:05:261793double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051794 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561795 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251796 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171797 return 0;
[email protected]b75b8292010-10-01 07:28:251798
1799 double zoom_level;
1800 if (temporary_zoom_settings_) {
1801 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581802 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251803 } else {
[email protected]2ae88d12011-10-14 09:11:191804 GURL url;
[email protected]10f417c52011-12-28 21:04:231805 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191806 // Since zoom map is updated using rewritten URL, use rewritten URL
1807 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511808 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191809 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251810 }
[email protected]d0b8d092010-10-25 04:05:171811 return zoom_level;
1812}
[email protected]b75b8292010-10-01 07:28:251813
[email protected]b172aee2012-04-10 17:05:261814int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591815 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171816 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011817 // Calculate the zoom percent from the factor. Round up to the nearest whole
1818 // number.
[email protected]b75b8292010-10-01 07:28:251819 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011820 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251821 *enable_decrement = percent > minimum_zoom_percent_;
1822 *enable_increment = percent < maximum_zoom_percent_;
1823 return percent;
1824}
1825
[email protected]b172aee2012-04-10 17:05:261826void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501827 if (!delegate_)
1828 return;
1829
[email protected]10f417c52011-12-28 21:04:231830 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501831 if (!active_entry)
1832 return;
1833
[email protected]36fc0392011-12-25 03:59:511834 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121835}
1836
[email protected]b172aee2012-04-10 17:05:261837void WebContentsImpl::ViewFrameSource(const GURL& url,
1838 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271839 if (!delegate_)
1840 return;
1841
1842 delegate_->ViewSourceForFrame(this, url, content_state);
1843}
1844
[email protected]b172aee2012-04-10 17:05:261845int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271846 return minimum_zoom_percent_;
1847}
1848
[email protected]b172aee2012-04-10 17:05:261849int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271850 return maximum_zoom_percent_;
1851}
1852
[email protected]b172aee2012-04-10 17:05:261853gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231854 return preferred_size_;
1855}
1856
[email protected]b172aee2012-04-10 17:05:261857int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271858 return content_restrictions_;
1859}
1860
[email protected]b172aee2012-04-10 17:05:261861WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501862 WebUIControllerFactory* factory =
[email protected]8ff00d72012-10-23 19:12:211863 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]863f70a2012-01-27 02:05:501864 if (!factory)
1865 return WebUI::kNoWebUI;
1866 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271867}
1868
[email protected]8ff00d72012-10-23 19:12:211869WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271870 // When there is a pending navigation entry, we want to use the pending WebUI
1871 // that goes along with it to control the basic flags. For example, we want to
1872 // show the pending URL in the URL bar, so we want the display_url flag to
1873 // be from the pending entry.
1874 //
1875 // The confusion comes because there are multiple possibilities for the
1876 // initial load in a tab as a side effect of the way the RenderViewHostManager
1877 // works.
1878 //
1879 // - For the very first tab the load looks "normal". The new tab Web UI is
1880 // the pending one, and we want it to apply here.
1881 //
1882 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1883 // get switched to the one previously associated with the new tab pages.
1884 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1885 // have a committed Web UI in this case.
1886 //
1887 // This condition handles all of these cases:
1888 //
1889 // - First load in first tab: no committed nav entry + pending nav entry +
1890 // pending dom ui:
1891 // -> Use pending Web UI if any.
1892 //
1893 // - First load in second tab: no committed nav entry + pending nav entry +
1894 // no pending Web UI:
1895 // -> Use the committed Web UI if any.
1896 //
1897 // - Second navigation in any tab: committed nav entry + pending nav entry:
1898 // -> Use pending Web UI if any.
1899 //
1900 // - Normal state with no load: committed nav entry + no pending nav entry:
1901 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251902 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271903 (controller_.GetLastCommittedEntry() ||
1904 render_manager_.pending_web_ui()))
1905 return render_manager_.pending_web_ui();
1906 return render_manager_.web_ui();
1907}
1908
[email protected]b172aee2012-04-10 17:05:261909bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271910 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581911 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271912}
1913
[email protected]b172aee2012-04-10 17:05:261914bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441915 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501916}
1917
[email protected]b172aee2012-04-10 17:05:261918void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321919 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181920 Send(new ViewMsg_DidChooseColorResponse(
1921 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201922}
1923
[email protected]b172aee2012-04-10 17:05:261924void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181925 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201926 if (delegate_)
1927 delegate_->DidEndColorChooser();
1928 color_chooser_ = NULL;
1929}
1930
[email protected]b172aee2012-04-10 17:05:261931bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211932 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271933 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221934 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231935 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411936 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271937}
1938
[email protected]b172aee2012-04-10 17:05:261939void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271940 if (delegate_)
1941 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211942}
1943
[email protected]3a3b75a2012-06-01 08:38:361944void WebContentsImpl::OnRegisterIntentService(
1945 const webkit_glue::WebIntentServiceData& data,
1946 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431947 if (delegate_)
1948 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301949}
1950
[email protected]b172aee2012-04-10 17:05:261951void WebContentsImpl::OnWebIntentDispatch(
1952 const webkit_glue::WebIntentData& intent,
1953 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431954 if (!delegate_)
1955 return;
1956
[email protected]0d9989d2011-12-21 20:26:001957 WebIntentsDispatcherImpl* intents_dispatcher =
1958 new WebIntentsDispatcherImpl(this, intent, intent_id);
1959 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301960}
1961
[email protected]54047eb52012-05-08 21:45:571962void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211963 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571964 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131965 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571966 bool is_main_frame,
1967 const GURL& opener_url,
1968 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211969 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181970 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451971 GURL validated_opener_url(opener_url);
[email protected]8ff00d72012-10-23 19:12:211972 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:571973 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541974 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571975 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451976 false,
[email protected]9f76c1e2012-03-05 15:15:581977 &validated_url);
[email protected]ef108e72012-06-20 14:03:541978 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571979 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451980 true,
1981 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181982
[email protected]0d60f0192011-04-14 12:40:101983 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251984 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:131985 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
1986 is_main_frame, validated_url, is_error_page,
1987 render_view_host));
[email protected]400992b2012-06-14 00:03:541988
1989 if (is_main_frame) {
1990 // Notify observers about the provisional change in the main frame URL.
1991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1992 ProvisionalChangeToMainFrameUrl(validated_url,
1993 validated_opener_url,
1994 render_view_host));
1995 }
1996}
1997
1998void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:211999 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542000 int32 page_id,
2001 const GURL& opener_url,
2002 const GURL& source_url,
2003 const GURL& target_url) {
2004 // TODO(creis): Remove this method and have the pre-rendering code listen to
2005 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
2006 // instead. See http://crbug.com/78512.
2007 GURL validated_source_url(source_url);
2008 GURL validated_target_url(target_url);
2009 GURL validated_opener_url(opener_url);
[email protected]8ff00d72012-10-23 19:12:212010 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542011 render_view_host->GetProcess();
2012 RenderViewHostImpl::FilterURL(
2013 ChildProcessSecurityPolicyImpl::GetInstance(),
2014 render_process_host->GetID(),
2015 false,
2016 &validated_source_url);
2017 RenderViewHostImpl::FilterURL(
2018 ChildProcessSecurityPolicyImpl::GetInstance(),
2019 render_process_host->GetID(),
2020 false,
2021 &validated_target_url);
2022 RenderViewHostImpl::FilterURL(
2023 ChildProcessSecurityPolicyImpl::GetInstance(),
2024 render_process_host->GetID(),
2025 true,
2026 &validated_opener_url);
2027 NavigationEntry* entry;
2028 if (page_id == -1) {
2029 entry = controller_.GetPendingEntry();
2030 } else {
2031 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2032 page_id);
2033 }
2034 if (!entry || entry->GetURL() != validated_source_url)
2035 return;
2036
2037 // Notify observers about the provisional change in the main frame URL.
2038 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2039 ProvisionalChangeToMainFrameUrl(validated_target_url,
2040 validated_opener_url,
2041 render_view_host));
[email protected]724159a2010-12-30 01:11:182042}
2043
[email protected]54047eb52012-05-08 21:45:572044void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212045 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582046 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2047 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2048 << ", error_code: " << params.error_code
2049 << ", error_description: " << params.error_description
2050 << ", is_main_frame: " << params.is_main_frame
2051 << ", showing_repost_interstitial: " <<
2052 params.showing_repost_interstitial
2053 << ", frame_id: " << params.frame_id;
2054 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212055 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572056 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542057 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572058 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452059 false,
[email protected]9f76c1e2012-03-05 15:15:582060 &validated_url);
[email protected]724159a2010-12-30 01:11:182061
[email protected]d7b175e2011-10-11 15:31:582062 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182063 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2064 // This means that the interstitial won't be torn down properly, which is
2065 // bad. But if we have an interstitial, go back to another tab type, and
2066 // then load the same interstitial again, we could end up getting the first
2067 // interstitial's "failed" message (as a result of the cancel) when we're on
2068 // the second one.
2069 //
2070 // We can't tell this apart, so we think we're tearing down the current page
2071 // which will cause a crash later one. There is also some code in
2072 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2073 // out because of this problem.
2074 //
2075 // http://code.google.com/p/chromium/issues/detail?id=2855
2076 // Because this will not tear down the interstitial properly, if "back" is
2077 // back to another tab type, the interstitial will still be somewhat alive
2078 // in the previous tab type. If you navigate somewhere that activates the
2079 // tab with the interstitial again, you'll see a flash before the new load
2080 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272081 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182082 LOG(WARNING) << "Discarding message during interstitial.";
2083 return;
2084 }
2085
[email protected]a16690732012-07-13 19:22:172086 // Do not clear the pending entry if one exists, so that the user's typed
2087 // URL is not lost when a navigation fails or is aborted. We'll allow
2088 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182089
[email protected]54047eb52012-05-08 21:45:572090 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182091 }
2092
[email protected]d8c660432011-12-22 20:51:252093 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582094 observers_,
2095 DidFailProvisionalLoad(params.frame_id,
2096 params.is_main_frame,
2097 validated_url,
2098 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462099 params.error_description,
2100 render_view_host));
[email protected]724159a2010-12-30 01:11:182101}
2102
[email protected]b172aee2012-04-10 17:05:262103void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182104 const GURL& url,
[email protected]70435962011-08-02 20:13:282105 const std::string& security_info,
2106 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182107 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282108 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192109 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182110 cache.Increment();
2111
2112 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082113 int cert_id = 0;
2114 net::CertStatus cert_status = 0;
2115 int security_bits = -1;
2116 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212117 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2118 &security_bits, &connection_status);
2119 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002120 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2121 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182122
[email protected]8ff00d72012-10-23 19:12:212123 NotificationService::current()->Notify(
2124 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2125 Source<NavigationController>(&controller_),
2126 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182127}
2128
[email protected]b172aee2012-04-10 17:05:262129void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212130 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182131 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192132 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022136 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232137 LOG(INFO) << security_origin << " ran insecure content from "
2138 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212139 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412140 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212141 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182142 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412143 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192144 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182148 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252149 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472150 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182151}
2152
[email protected]b172aee2012-04-10 17:05:262153void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312154 int64 frame_id,
2155 const GURL& validated_url,
2156 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252157 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472158 DidFinishLoad(frame_id, validated_url, is_main_frame,
2159 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312160}
2161
[email protected]b172aee2012-04-10 17:05:262162void WebContentsImpl::OnDidFailLoadWithError(
2163 int64 frame_id,
2164 const GURL& validated_url,
2165 bool is_main_frame,
2166 int error_code,
2167 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252168 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312169 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472170 error_code, error_description,
2171 message_source_));
[email protected]724159a2010-12-30 01:11:182172}
2173
[email protected]b172aee2012-04-10 17:05:262174void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272175 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432176 if (delegate_)
2177 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172178}
2179
[email protected]b172aee2012-04-10 17:05:262180void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262181 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232182 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252183 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262184 if (!entry)
2185 return;
2186 // Note that we don't call NavigationController::GotToOffset() as we don't
2187 // want to create a pending navigation entry (it might end up lingering
2188 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252189 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212190 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512191 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212192 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472193 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572194
2195 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2196 // it in now that we know. This allows us to find the entry when it commits.
2197 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232198 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332199 entry->set_site_instance(
2200 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572201 }
[email protected]216813952011-05-19 22:21:262202 }
2203}
2204
[email protected]b172aee2012-04-10 17:05:262205void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2206 int maximum_percent,
2207 bool remember) {
[email protected]216813952011-05-19 22:21:262208 minimum_zoom_percent_ = minimum_percent;
2209 maximum_zoom_percent_ = maximum_percent;
2210 temporary_zoom_settings_ = !remember;
2211}
2212
[email protected]20b433a2012-05-15 21:23:462213void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212214 const Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482215 download_stats::RecordDownloadSource(
2216 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262217 // Check if the URL to save matches the URL of the main frame. Since this
2218 // message originates from Pepper plugins, it may not be the case if the
2219 // plugin is an embedded element.
2220 GURL main_frame_url = GetURL();
2221 if (!main_frame_url.is_valid())
2222 return;
2223 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462224 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::OnEnumerateDirectory(int request_id,
2228 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432229 if (!delegate_)
2230 return;
2231
[email protected]b9535422012-02-09 01:47:592232 ChildProcessSecurityPolicyImpl* policy =
2233 ChildProcessSecurityPolicyImpl::GetInstance();
2234 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2235 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432239 if (delegate_)
2240 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2244 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362245 const string16& title,
2246 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432247 if (!delegate_)
2248 return;
2249
[email protected]b9535422012-02-09 01:47:592250 ChildProcessSecurityPolicyImpl* policy =
2251 ChildProcessSecurityPolicyImpl::GetInstance();
2252 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2253 return;
[email protected]3a3b75a2012-06-01 08:38:362254 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnFindReply(int request_id,
2258 int number_of_matches,
2259 const gfx::Rect& selection_rect,
2260 int active_match_ordinal,
2261 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432262 if (delegate_) {
2263 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2264 active_match_ordinal, final_update);
2265 }
[email protected]b888919c2011-09-02 00:32:162266}
2267
[email protected]59363fc92012-09-05 03:46:312268#if defined(OS_ANDROID)
2269void WebContentsImpl::OnFindMatchRectsReply(
2270 int version,
2271 const std::vector<gfx::RectF>& rects,
2272 const gfx::RectF& active_rect) {
2273 if (delegate_)
2274 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2275}
2276#endif
2277
[email protected]b172aee2012-04-10 17:05:262278void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442279 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2280 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452281}
2282
[email protected]b172aee2012-04-10 17:05:262283void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2284 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102285 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252286 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102287 AppCacheAccessed(manifest_url, blocked_by_policy));
2288}
2289
[email protected]b172aee2012-04-10 17:05:262290void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322291 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432292 color_chooser_ = delegate_ ?
2293 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202294}
2295
[email protected]b172aee2012-04-10 17:05:262296void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202297 if (color_chooser_ &&
2298 color_chooser_id == color_chooser_->identifier())
2299 color_chooser_->End();
2300}
2301
[email protected]b172aee2012-04-10 17:05:262302void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322303 SkColor color) {
[email protected]da8543762012-03-20 08:52:202304 if (color_chooser_ &&
2305 color_chooser_id == color_chooser_->identifier())
2306 color_chooser_->SetSelectedColor(color);
2307}
2308
[email protected]9f2a9d72012-04-16 16:02:222309void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2310 const FilePath& path,
2311 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552312 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2313
[email protected]3fc07c52012-04-20 00:27:442314 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2315 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292316}
2317
[email protected]d0759f492012-04-19 22:50:502318// This exists for render views that don't have a WebUI, but do have WebUI
2319// bindings enabled.
2320void WebContentsImpl::OnWebUISend(const GURL& source_url,
2321 const std::string& name,
2322 const base::ListValue& args) {
2323 if (delegate_)
2324 delegate_->WebUISend(this, source_url, name, args);
2325}
2326
[email protected]d8415ad92012-08-23 14:40:502327void WebContentsImpl::OnRequestPpapiBrokerPermission(
2328 int request_id,
2329 const GURL& url,
2330 const FilePath& plugin_path) {
2331 base::Callback<void(bool)> callback =
2332 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2333 base::Unretained(this), request_id);
2334 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2335 WebContentsObserver* observer;
2336 while ((observer = it.GetNext()) != NULL) {
2337 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2338 callback))
2339 return;
2340 }
2341
2342 // Fall back to allowing the request if no observer handled it.
2343 OnPpapiBrokerPermissionResult(request_id, true);
2344}
2345
2346void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2347 bool result) {
2348 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2349 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2350 request_id,
2351 result));
2352}
2353
[email protected]19be7a62012-10-01 23:03:372354void WebContentsImpl::OnBrowserPluginCreateGuest(
[email protected]92a01cc2012-09-29 14:13:592355 int instance_id,
[email protected]19be7a62012-10-01 23:03:372356 const std::string& storage_partition_id,
2357 bool persist_storage) {
2358 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
2359 // specific messages for this WebContents (through its
2360 // BrowserPluginEmbedderHelper). This means that any message from browser
2361 // plugin renderer prior to CreateGuest will be ignored.
[email protected]7a846df2012-09-20 19:17:392362 // For more info, see comment above classes BrowserPluginEmbedder and
2363 // BrowserPluginGuest.
[email protected]b6bcd8c2012-10-03 06:03:582364 // The first BrowserPluginHostMsg_CreateGuest message from this WebContents'
2365 // embedder render process is handled here. Once BrowserPluginEmbedder is
2366 // created, all subsequent BrowserPluginHostMsg_CreateGuest messages are
2367 // intercepted by the BrowserPluginEmbedderHelper and handled by the
2368 // BrowserPluginEmbedder. Thus, this code will not be executed if a
2369 // BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392370 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392371 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212372 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]19be7a62012-10-01 23:03:372373 browser_plugin_embedder_->CreateGuest(GetRenderViewHost(),
2374 instance_id,
2375 storage_partition_id,
2376 persist_storage);
2377}
2378
[email protected]96d185d2009-04-24 03:28:542379// Notifies the RenderWidgetHost instance about the fact that the page is
2380// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262381void WebContentsImpl::SetIsLoading(bool is_loading,
2382 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542383 if (is_loading == is_loading_)
2384 return;
2385
2386 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212387 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542388 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562389 upload_size_ = 0;
2390 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542391 }
2392
2393 render_manager_.SetIsLoading(is_loading);
2394
2395 is_loading_ = is_loading;
2396 waiting_for_response_ = is_loading;
2397
[email protected]6ebdc9b2010-09-27 16:55:572398 if (delegate_)
2399 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212400 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542401
[email protected]8ff00d72012-10-23 19:12:212402 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2403 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542404 if (details)
[email protected]8ff00d72012-10-23 19:12:212405 det = Details<LoadNotificationDetails>(details);
2406 NotificationService::current()->Notify(
2407 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542408}
2409
[email protected]b172aee2012-04-10 17:05:262410void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212411 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322412 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562413 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382414 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442415 // that opened the window, as long as both renderers have the same
2416 // privileges.
[email protected]1fd1a502011-03-30 16:55:562417 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562418 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582419 // web_ui might be NULL if the URL refers to a non-existent extension.
2420 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402421 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522422 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442423 }
2424 }
[email protected]1fd1a502011-03-30 16:55:562425 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442426 }
2427
[email protected]4e697b042011-07-08 06:44:562428 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322429 // Clear the status bubble. This is a workaround for a bug where WebKit
2430 // doesn't let us know that the cursor left an element during a
2431 // transition (this is also why the mouse cursor remains as a hand after
2432 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2433 // clear the bubble when a user navigates to a named anchor in the same
2434 // page.
[email protected]36fc0392011-12-25 03:59:512435 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322436 }
2437
[email protected]a6e82fc2010-02-24 22:28:142438 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472439 // Once the main frame is navigated, we're no longer considered to have
2440 // displayed insecure content.
2441 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172442 }
[email protected]ce5c4502009-05-06 16:46:112443
[email protected]3c9e1872010-11-18 16:17:492444 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252445 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042446 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322447}
2448
[email protected]b172aee2012-04-10 17:05:262449void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322450 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212451 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322452 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062453 // If we navigate off the page, reset JavaScript state. This does nothing
2454 // to prevent a malicious script from spamming messages, since the script
2455 // could just reload the page to stop blocking.
2456 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552457 dialog_creator_->ResetJavaScriptState(this);
2458 dialog_creator_ = NULL;
2459 }
[email protected]420ae012009-04-24 05:16:322460
[email protected]3c9e1872010-11-18 16:17:492461 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252462 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042463 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322464}
2465
[email protected]b172aee2012-04-10 17:05:262466void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462467 // If we are creating a RVH for a restored controller, then we need to make
2468 // sure the RenderView starts with a next_page_id_ larger than the number
2469 // of restored entries. This must be called before the RenderView starts
2470 // navigating (to avoid a race between the browser updating max_page_id and
2471 // the renderer updating next_page_id_). Because of this, we only call this
2472 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562473 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582474 if (max_restored_page_id >
2475 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2476 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2477 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322478}
2479
[email protected]b172aee2012-04-10 17:05:262480bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2481 const string16& title) {
[email protected]420ae012009-04-24 05:16:322482 // For file URLs without a title, use the pathname instead. In the case of a
2483 // synthesized title, we don't want the update to count toward the "one set
2484 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512485 string16 final_title;
[email protected]420ae012009-04-24 05:16:322486 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512487 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2488 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322489 explicit_set = false; // Don't count synthetic titles toward the set limit.
2490 } else {
[email protected]acafd272011-07-26 17:35:572491 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322492 explicit_set = true;
2493 }
2494
[email protected]987fc3a2011-05-26 14:18:092495 // If a page is created via window.open and never navigated,
2496 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552497 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092498 if (entry) {
[email protected]36fc0392011-12-25 03:59:512499 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092500 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322501
[email protected]36fc0392011-12-25 03:59:512502 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092503 } else {
2504 if (page_title_when_no_navigation_entry_ == final_title)
2505 return false; // Nothing changed, don't bother.
2506
2507 page_title_when_no_navigation_entry_ = final_title;
2508 }
[email protected]420ae012009-04-24 05:16:322509
[email protected]420ae012009-04-24 05:16:322510 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232511 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322512
[email protected]8ff00d72012-10-23 19:12:212513 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462514 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142515
[email protected]8ff00d72012-10-23 19:12:212516 NotificationService::current()->Notify(
2517 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2518 Source<WebContents>(this),
2519 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042520
[email protected]420ae012009-04-24 05:16:322521 return true;
2522}
2523
[email protected]b172aee2012-04-10 17:05:262524void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322525 // After sending out a swap notification, we need to send a disconnect
2526 // notification so that clients that pick up a pointer to |this| can NULL the
2527 // pointer. See Bug 1230284.
2528 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212529 NotificationService::current()->Notify(
2530 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2531 Source<WebContents>(this),
2532 NotificationService::NoDetails());
[email protected]7a846df2012-09-20 19:17:392533
2534 // Ensure that the associated embedder gets cleared after a RenderViewHost
2535 // gets swapped, so we don't reuse the same embedder next time a
2536 // RenderViewHost is attached to this WebContents.
2537 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322538}
2539
[email protected]b172aee2012-04-10 17:05:262540void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322541 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212542 NotificationService::current()->Notify(
2543 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2544 Source<WebContents>(this),
2545 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322546}
2547
[email protected]b172aee2012-04-10 17:05:262548void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322549 if (!notify_disconnection_)
2550 return;
2551
2552 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212553 NotificationService::current()->Notify(
2554 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2555 Source<WebContents>(this),
2556 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322557}
2558
[email protected]5a3bdf52012-05-24 15:12:572559RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2560 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322561}
2562
[email protected]8d3347f2009-07-09 22:00:212563RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262564WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212565 return &render_manager_;
2566}
2567
[email protected]8ff00d72012-10-23 19:12:212568RendererPreferences WebContentsImpl::GetRendererPrefs(
2569 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462570 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512571}
2572
[email protected]b172aee2012-04-10 17:05:262573WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172574 return this;
2575}
2576
[email protected]b172aee2012-04-10 17:05:262577gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172578 if (delegate_)
2579 return delegate_->GetRootWindowResizerRect();
2580 return gfx::Rect();
2581}
2582
[email protected]7a846df2012-09-20 19:17:392583void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2584 if (browser_plugin_embedder_.get())
2585 browser_plugin_embedder_.reset();
2586}
2587
[email protected]b172aee2012-04-10 17:05:262588void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442589 // Don't send notifications if we are just creating a swapped-out RVH for
2590 // the opener chain. These won't be used for view-source or WebUI, so it's
2591 // ok to return early.
2592 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2593 return;
2594
[email protected]8ff00d72012-10-23 19:12:212595 NotificationService::current()->Notify(
2596 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2597 Source<WebContents>(this),
2598 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232599 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322600 if (!entry)
2601 return;
2602
2603 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352604 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562605 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582606 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322607
2608 if (entry->IsViewSourceMode()) {
2609 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182610 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582611 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322612 }
[email protected]0666aef2009-05-13 19:48:082613
[email protected]d487beefe2011-12-21 05:41:212614 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262615
2616 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252617 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322618}
2619
[email protected]b172aee2012-04-10 17:05:262620void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522621 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322622 // Don't notify the world, since this came from a renderer in the
2623 // background.
2624 return;
2625 }
2626
2627 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312628 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232629 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302630
2631 // Restore the focus to the tab (otherwise the focus will be on the top
2632 // window).
[email protected]484ae5912010-09-29 19:16:142633 if (was_crashed && !FocusLocationBarByDefault() &&
2634 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302635 Focus();
[email protected]484ae5912010-09-29 19:16:142636 }
[email protected]32ded2212011-11-10 18:51:432637
[email protected]d8c660432011-12-22 20:51:252638 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322639}
2640
[email protected]b172aee2012-04-10 17:05:262641void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2642 base::TerminationStatus status,
2643 int error_code) {
[email protected]151a63d2011-12-20 22:32:522644 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322645 // The pending page's RenderViewHost is gone.
2646 return;
2647 }
2648
2649 SetIsLoading(false, NULL);
2650 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232651 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312652 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322653
[email protected]d8c660432011-12-22 20:51:252654 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272655 observers_,
[email protected]be1f56ab2011-12-22 06:55:312656 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322657}
2658
[email protected]b172aee2012-04-10 17:05:262659void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482660 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252661 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062662}
2663
[email protected]b172aee2012-04-10 17:05:262664void WebContentsImpl::DidNavigate(
2665 RenderViewHost* rvh,
2666 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8ff00d72012-10-23 19:12:212667 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322668 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372669
[email protected]434f69f2012-02-06 21:56:522670 // Update the site of the SiteInstance if it doesn't have one yet, unless
2671 // this is for about:blank. In that case, the SiteInstance can still be
2672 // considered unused until a navigation to a real page.
2673 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2674 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332675 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522676 }
[email protected]420ae012009-04-24 05:16:322677
2678 // Need to update MIME type here because it's referred to in
2679 // UpdateNavigationCommands() called by RendererDidNavigate() to
2680 // determine whether or not to enable the encoding menu.
2681 // It's updated only for the main frame. For a subframe,
2682 // RenderView::UpdateURL does not set params.contents_mime_type.
2683 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2684 // TODO(jungshik): Add a test for the encoding menu to avoid
2685 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212686 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322687 contents_mime_type_ = params.contents_mime_type;
2688
[email protected]8ff00d72012-10-23 19:12:212689 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002690 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392691
[email protected]a9c0bfe2010-09-17 08:35:222692 // Send notification about committed provisional loads. This notification is
2693 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2694 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212695 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072696 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2697 // that is not recorded in the navigation history. For the purpose of
2698 // tracking navigation events, we treat this event as a sub frame navigation
2699 // event.
2700 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212701 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222702 // Whether or not a page transition was triggered by going backward or
2703 // forward in the history is only stored in the navigation controller's
2704 // entry list.
2705 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512706 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212707 PAGE_TRANSITION_FORWARD_BACK)) {
2708 transition_type = PageTransitionFromInt(
2709 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222710 }
[email protected]0d60f0192011-04-14 12:40:102711 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252712 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102713 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462714 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222715 }
2716
[email protected]76543b92009-08-31 17:27:452717 if (!did_navigate)
2718 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322719
2720 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2721 // for the appropriate notification (best) or you can add it to
2722 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2723 // necessary, please).
2724
2725 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002726 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322727 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512728 if (delegate_)
2729 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002730 }
[email protected]420ae012009-04-24 05:16:322731 DidNavigateAnyFramePostCommit(rvh, details, params);
2732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2735 int32 page_id,
2736 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152737 // Ensure that this state update comes from either the active RVH or one of
2738 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522739 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322740
2741 // We must be prepared to handle state updates for any page, these occur
2742 // when the user is scrolling and entering form data, as well as when we're
2743 // leaving a page, in which case our state may have already been moved to
2744 // the next page. The navigation controller will look up the appropriate
2745 // NavigationEntry and update it when it is notified via the delegate.
2746
2747 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582748 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322749 if (entry_index < 0)
2750 return;
[email protected]10f417c52011-12-28 21:04:232751 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322752
[email protected]36fc0392011-12-25 03:59:512753 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322754 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512755 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322756 controller_.NotifyEntryChanged(entry, entry_index);
2757}
2758
[email protected]b172aee2012-04-10 17:05:262759void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2760 int32 page_id,
2761 const string16& title,
2762 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322763 // If we have a title, that's a pretty good indication that we've started
2764 // getting useful data.
2765 SetNotWaitingForResponse();
2766
[email protected]73eb2602012-02-09 19:50:552767 // Try to find the navigation entry, which might not be the current one.
2768 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232769 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582770 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092771
[email protected]73eb2602012-02-09 19:50:552772 // We can handle title updates when we don't have an entry in
2773 // UpdateTitleForEntry, but only if the update is from the current RVH.
2774 if (!entry && rvh != GetRenderViewHost())
2775 return;
2776
[email protected]a49e10b2011-08-01 23:57:462777 // TODO(evan): make use of title_direction.
2778 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092779 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322780 return;
2781
2782 // Broadcast notifications when the UI should be updated.
2783 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212784 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2788 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312789 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322790}
2791
[email protected]b172aee2012-04-10 17:05:262792void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512793 if (delegate_)
2794 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322795}
2796
[email protected]b172aee2012-04-10 17:05:262797void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292798 // The UI may be in an event-tracking loop, such as between the
2799 // mouse-down and mouse-up in text selection or a button click.
2800 // Defer the close until after tracking is complete, so that we
2801 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292802 // TODO(shess): This could get more fine-grained. For instance,
2803 // closing a tab in another window while selecting text in the
2804 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212805 if (GetView()->IsEventTracking()) {
2806 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292807 return;
2808 }
2809
[email protected]420ae012009-04-24 05:16:322810 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522811 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512812 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322813}
2814
[email protected]b172aee2012-04-10 17:05:262815void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522816 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512817 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572818}
2819
[email protected]b172aee2012-04-10 17:05:262820void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512821 if (delegate_ && delegate_->IsPopupOrPanel(this))
2822 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322823}
2824
[email protected]8ff00d72012-10-23 19:12:212825void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322826 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492827
[email protected]82114f52012-03-20 22:53:412828 if (delegate_ && content_restrictions_)
2829 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492830
2831 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292832 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2833 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322834}
2835
[email protected]8ff00d72012-10-23 19:12:212836void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322837 scoped_ptr<LoadNotificationDetails> details;
2838
[email protected]10f417c52011-12-28 21:04:232839 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322840 // An entry may not exist for a stop when loading an initial blank page or
2841 // if an iframe injected by script into a blank page finishes loading.
2842 if (entry) {
[email protected]420ae012009-04-24 05:16:322843 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2844
2845 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512846 entry->GetVirtualURL(),
2847 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322848 elapsed,
2849 &controller_,
2850 controller_.GetCurrentEntryIndex()));
2851 }
2852
[email protected]420ae012009-04-24 05:16:322853 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492854
2855 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292856 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2857 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322858}
2859
[email protected]b172aee2012-04-10 17:05:262860void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162861 controller_.DiscardNonCommittedEntries();
2862
2863 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212864 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162865}
2866
[email protected]b172aee2012-04-10 17:05:262867void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512868 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132869 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402870}
2871
[email protected]0720b532012-08-28 19:23:372872void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2873 render_manager_.DidUpdateFrameTree(rvh);
2874}
2875
[email protected]87717d0e2012-04-26 02:58:432876void WebContentsImpl::DocumentAvailableInMainFrame(
2877 RenderViewHost* render_view_host) {
2878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2879 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102880}
2881
[email protected]b172aee2012-04-10 17:05:262882void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082883 RenderViewHost* render_view_host,
2884 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212885 NotificationService::current()->Notify(
2886 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2887 Source<WebContents>(this),
2888 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082889}
2890
[email protected]196159d2012-05-04 17:26:542891void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2892 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212893 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262894 WindowOpenDisposition disposition,
2895 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542896 // If this came from a swapped out RenderViewHost, we only allow the request
2897 // if we are still in the same BrowsingInstance.
2898 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2899 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2900 return;
2901 }
2902
[email protected]4ad5d77d2011-12-03 02:00:482903 // Delegate to RequestTransferURL because this is just the generic
2904 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582905 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482906 GlobalRequestID());
2907}
2908
[email protected]b172aee2012-04-10 17:05:262909void WebContentsImpl::RequestTransferURL(
2910 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212911 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262912 WindowOpenDisposition disposition,
2913 int64 source_frame_id,
2914 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202915 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212916 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582917 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352918 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322919 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2920 // generated suggestions).
2921 //
[email protected]e0112912011-02-02 22:54:352922 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162923 // want web sites to see a referrer of "chrome://blah" (and some
2924 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322925 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:212926 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222927 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482928 false /* is_renderer_initiated */);
2929 params.transferred_global_request_id = old_request_id;
2930 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222931 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322932 } else {
[email protected]6bf6a6b52012-02-03 15:41:432933 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:212934 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:482935 params.transferred_global_request_id = old_request_id;
2936 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582937 }
2938 if (new_contents) {
2939 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252940 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582941 DidOpenRequestedURL(new_contents,
2942 url,
2943 referrer,
2944 disposition,
2945 transition_type,
2946 source_frame_id));
[email protected]420ae012009-04-24 05:16:322947 }
2948}
2949
[email protected]e1c3a552012-05-04 20:51:322950void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2951 // Tell the active RenderViewHost to run unload handlers and close, as long
2952 // as the request came from a RenderViewHost in the same BrowsingInstance.
2953 // In most cases, we receive this from a swapped out RenderViewHost.
2954 // It is possible to receive it from one that has just been swapped in,
2955 // in which case we might as well deliver the message anyway.
2956 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2957 GetRenderViewHost()->ClosePage();
2958}
2959
[email protected]f546640b2012-05-15 00:03:492960void WebContentsImpl::RouteMessageEvent(
2961 RenderViewHost* rvh,
2962 const ViewMsg_PostMessage_Params& params) {
2963 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:362964 // came from a RenderViewHost in the same BrowsingInstance or if this
2965 // WebContents is dedicated to a browser plugin guest.
2966 // Note: This check means that an embedder could theoretically receive a
2967 // postMessage from anyone (not just its own guests). However, this is
2968 // probably not a risk for apps since other pages won't have references
2969 // to App windows.
2970 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
2971 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:492972 return;
2973
2974 ViewMsg_PostMessage_Params new_params(params);
2975
[email protected]0720b532012-08-28 19:23:372976 // If the renderer has changed while the post message is being routed,
2977 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:192978 // TODO(nasko): Check for process ID and target frame id mismatch, once
2979 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:372980
[email protected]f546640b2012-05-15 00:03:492981 // If there is a source_routing_id, translate it to the routing ID for
2982 // the equivalent swapped out RVH in the target process. If we need
2983 // to create a swapped out RVH for the source tab, we create its opener
2984 // chain as well, since those will also be accessible to the target page.
2985 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2986 // Try to look up the WebContents for the source page.
2987 WebContentsImpl* source_contents = NULL;
2988 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2989 rvh->GetProcess()->GetID(), params.source_routing_id);
2990 if (source_rvh) {
2991 source_contents = static_cast<WebContentsImpl*>(
2992 source_rvh->GetDelegate()->GetAsWebContents());
2993 }
2994
2995 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:362996 if (GetBrowserPluginGuest()) {
2997 // We create a swapped out RenderView for the embedder in the guest's
2998 // render process but we intentionally do not expose the embedder's
2999 // opener chain to it.
3000 new_params.source_routing_id =
3001 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3002 } else {
3003 new_params.source_routing_id =
3004 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3005 }
[email protected]f546640b2012-05-15 00:03:493006 } else {
3007 // We couldn't find it, so don't pass a source frame.
3008 new_params.source_routing_id = MSG_ROUTING_NONE;
3009 }
3010 }
3011
3012 // In most cases, we receive this from a swapped out RenderViewHost.
3013 // It is possible to receive it from one that has just been swapped in,
3014 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183015 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493016}
3017
[email protected]b172aee2012-04-10 17:05:263018void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343019 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413020 const string16& message,
3021 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323022 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213023 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323024 IPC::Message* reply_msg,
3025 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073026 // Suppress JavaScript dialogs when requested. Also suppress messages when
3027 // showing an interstitial as it's shown over the previous page and we don't
3028 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503029 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583030 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273031 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073032 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523033 delegate_->ShouldSuppressDialogs() ||
3034 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323035
3036 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213037 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433038 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553039 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523040 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433041 this,
3042 frame_url.GetOrigin(),
3043 accept_lang,
3044 javascript_message_type,
3045 message,
[email protected]51da7e32012-01-30 19:24:523046 default_prompt,
[email protected]b172aee2012-04-10 17:05:263047 base::Bind(&WebContentsImpl::OnDialogClosed,
3048 base::Unretained(this),
3049 rvh,
3050 reply_msg),
[email protected]51da7e32012-01-30 19:24:523051 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323052 }
[email protected]3ab9cb82011-06-03 18:02:073053
3054 if (suppress_this_message) {
3055 // If we are suppressing messages, just reply as if the user immediately
3056 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343057 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073058 }
3059
3060 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323061}
3062
[email protected]b172aee2012-04-10 17:05:263063void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3064 const string16& message,
3065 bool is_reload,
3066 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583067 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513068 if (delegate_)
3069 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073070
3071 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583072 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073073 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523074 delegate_->ShouldSuppressDialogs() ||
3075 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153076 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343077 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583078 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503079 return;
3080 }
[email protected]3ab9cb82011-06-03 18:02:073081
[email protected]7ab1e7d62009-10-14 23:32:013082 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553083 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523084 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323085 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263086 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523087 reply_msg));
[email protected]420ae012009-04-24 05:16:323088}
3089
[email protected]a796f202012-05-30 14:14:253090bool WebContentsImpl::AddMessageToConsole(int32 level,
3091 const string16& message,
3092 int32 line_no,
3093 const string16& source_id) {
3094 if (!delegate_)
3095 return false;
3096 return delegate_->AddMessageToConsole(this, level, message, line_no,
3097 source_id);
3098}
3099
[email protected]b172aee2012-04-10 17:05:263100WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333101 // We want to base the page config off of the real URL, rather than the
3102 // display URL.
3103 GURL url = controller_.GetActiveEntry()
3104 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3105 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323106}
3107
[email protected]0eba810b2012-10-18 03:19:363108int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213109 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363110 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273114 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253115 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223116
[email protected]ea114722012-03-12 01:11:253117 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173118 if (rdh) // NULL in unittests.
3119 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253120}
3121
[email protected]b172aee2012-04-10 17:05:263122void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443123 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253124 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443125}
3126
[email protected]b172aee2012-04-10 17:05:263127void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3128 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153129 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523130 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153131 return;
3132
[email protected]9f76c1e2012-03-05 15:15:583133 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3134
[email protected]e5fc1632011-08-08 07:51:533135 // Ignore renderer unresponsive event if debugger is attached to the tab
3136 // since the event may be a result of the renderer sitting on a breakpoint.
3137 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443138 DevToolsAgentHost* agent =
[email protected]8ff00d72012-10-23 19:12:213139 DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
[email protected]0e12d7d2011-12-01 16:21:443140 if (agent &&
3141 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533142 return;
3143
[email protected]420ae012009-04-24 05:16:323144 if (is_during_unload) {
3145 // Hang occurred while firing the beforeunload/unload handler.
3146 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583147 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323148
3149 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3150 return;
3151
3152 // If the tab hangs in the beforeunload/unload handler there's really
3153 // nothing we can do to recover. Pretend the unload listeners have
3154 // all fired and close the tab. If the hang is in the beforeunload handler
3155 // then the user will not have the option of cancelling the close.
3156 Close(rvh);
3157 return;
3158 }
3159
[email protected]9f76c1e2012-03-05 15:15:583160 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473161 return;
3162
[email protected]6934a702011-12-20 00:04:513163 if (delegate_)
3164 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323165}
3166
[email protected]b172aee2012-04-10 17:05:263167void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513168 if (delegate_)
3169 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323170}
3171
[email protected]b172aee2012-04-10 17:05:263172void WebContentsImpl::LoadStateChanged(
3173 const GURL& url,
3174 const net::LoadStateWithParam& load_state,
3175 uint64 upload_position,
3176 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323177 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563178 upload_position_ = upload_position;
3179 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503180 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213181 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303182 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213183 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323184 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463185 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213186 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463187 }
[email protected]420ae012009-04-24 05:16:323188}
3189
[email protected]b172aee2012-04-10 17:05:263190void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513191 if (delegate_)
3192 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253193}
3194
[email protected]b172aee2012-04-10 17:05:263195void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553196 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323197 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553198 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513199 if (delegate_)
3200 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323201}
3202
[email protected]b172aee2012-04-10 17:05:263203void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543204 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233205 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3206 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543207}
3208
[email protected]b172aee2012-04-10 17:05:263209void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103210 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263211 gfx::Size size = view_->GetContainerSize();
3212 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3213 // here during container initialization and normal window size will be set
3214 // later. In case of tab duplication this resizing to 0x0 prevents setting
3215 // normal size later so just ignore it.
3216 if (!size.IsEmpty())
3217 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323218}
3219
[email protected]b172aee2012-04-10 17:05:263220void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543221 NotifySwapped();
3222}
3223
[email protected]14392a52012-05-02 20:28:443224int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3225 SiteInstance* instance) {
3226 if (!opener_)
3227 return MSG_ROUTING_NONE;
3228
3229 // Recursively create RenderViews for anything else in the opener chain.
3230 return opener_->CreateOpenerRenderViews(instance);
3231}
3232
3233int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3234 int opener_route_id = MSG_ROUTING_NONE;
3235
3236 // If this tab has an opener, ensure it has a RenderView in the given
3237 // SiteInstance as well.
3238 if (opener_)
3239 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3240
[email protected]0720b532012-08-28 19:23:373241 // If any of the renderers for this WebContents has the same SiteInstance,
3242 // use it.
3243 if (render_manager_.current_host()->GetSiteInstance() == instance)
3244 return render_manager_.current_host()->GetRoutingID();
3245
3246 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3247 instance);
3248 if (rvh)
3249 return rvh->GetRoutingID();
3250
[email protected]14392a52012-05-02 20:28:443251 // Create a swapped out RenderView in the given SiteInstance if none exists,
3252 // setting its opener to the given route_id. Return the new view's route_id.
3253 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3254}
3255
[email protected]b172aee2012-04-10 17:05:263256NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193257 return GetController();
[email protected]3a3d47472010-07-15 21:03:543258}
3259
[email protected]b172aee2012-04-10 17:05:263260WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563261 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323262}
3263
[email protected]10f417c52011-12-28 21:04:233264NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263265 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323266 return controller_.GetLastCommittedEntry();
3267}
3268
[email protected]b172aee2012-04-10 17:05:263269bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443270 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443271 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323272 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523273
[email protected]420ae012009-04-24 05:16:323274 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443275 if (rwh_view)
3276 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323277
[email protected]74ce1ad2011-12-16 21:51:463278 // Make sure we use the correct starting page_id in the new RenderView.
3279 UpdateMaxPageIDIfNecessary(render_view_host);
3280 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583281 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463282
[email protected]7900bfdb2012-05-24 19:31:243283 std::string embedder_channel_name;
3284 int embedder_container_id;
3285 GetBrowserPluginEmbedderInfo(render_view_host,
3286 &embedder_channel_name,
3287 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583288 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493289 render_view_host)->CreateRenderView(string16(),
3290 opener_route_id,
3291 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243292 embedder_channel_name,
3293 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523294 return false;
[email protected]14392a52012-05-02 20:28:443295 }
[email protected]a4127722011-04-27 23:13:523296
[email protected]e60c0232011-11-11 19:56:353297#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503298 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3299 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443300 if (rwh_view) {
3301 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3302 render_widget_host->WasResized();
3303 }
[email protected]f8233cc2011-05-31 20:24:503304#endif
3305
[email protected]420ae012009-04-24 05:16:323306 return true;
3307}
3308
[email protected]b172aee2012-04-10 17:05:263309void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3310 IPC::Message* reply_msg,
3311 bool success,
3312 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543313 if (is_showing_before_unload_dialog_ && !success) {
3314 // If a beforeunload dialog is canceled, we need to stop the throbber from
3315 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293316 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353317 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543318
[email protected]3bbacc5b2012-04-17 17:46:153319 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553320 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543321 }
3322 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583323 static_cast<RenderViewHostImpl*>(
3324 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543325}
3326
[email protected]b172aee2012-04-10 17:05:263327void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213328 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123329 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103330}
[email protected]f45d2a72010-03-08 23:28:353331
[email protected]b172aee2012-04-10 17:05:263332void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213333 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263334 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573335 DownloadManager* dlm =
3336 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143337 if (!dlm)
3338 return;
3339 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263340 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143341 const NavigationEntry* entry = controller_.GetActiveEntry();
3342 if (entry)
3343 post_id = entry->GetPostID();
3344 }
[email protected]8ff00d72012-10-23 19:12:213345 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo());
[email protected]c873c862012-10-17 15:32:123346 save_info->prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143347 scoped_ptr<DownloadUrlParameters> params(
[email protected]c873c862012-10-17 15:32:123348 DownloadUrlParameters::FromWebContents(this, url, save_info.Pass()));
[email protected]f859eba2012-05-30 17:22:493349 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143350 params->set_post_id(post_id);
3351 params->set_prefer_cache(true);
3352 if (post_id >= 0)
3353 params->set_method("POST");
3354 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143355}
3356
[email protected]b172aee2012-04-10 17:05:263357void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213358 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443359 // Can be NULL during tests.
3360 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213361 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363362}
[email protected]9f76c1e2012-03-05 15:15:583363
[email protected]b172aee2012-04-10 17:05:263364RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583365 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3366}
[email protected]7900bfdb2012-05-24 19:31:243367
3368void WebContentsImpl::GetBrowserPluginEmbedderInfo(
[email protected]8ff00d72012-10-23 19:12:213369 RenderViewHost* render_view_host,
[email protected]7900bfdb2012-05-24 19:31:243370 std::string* embedder_channel_name,
3371 int* embedder_container_id) {
[email protected]8ff00d72012-10-23 19:12:213372 RenderProcessHost* embedder_render_process_host =
[email protected]dd26779c2012-08-08 01:50:283373 old_browser_plugin_host()->embedder_render_process_host();
3374 *embedder_container_id = old_browser_plugin_host()->instance_id();
[email protected]7900bfdb2012-05-24 19:31:243375 int embedder_process_id =
3376 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3377 if (embedder_process_id != -1) {
3378 *embedder_channel_name =
3379 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3380 embedder_process_id);
3381 }
3382}
[email protected]7a846df2012-09-20 19:17:393383
[email protected]8ff00d72012-10-23 19:12:213384BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393385 return browser_plugin_guest_.get();
3386}
3387
[email protected]8ff00d72012-10-23 19:12:213388BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393389 return browser_plugin_embedder_.get();
3390}
[email protected]8ff00d72012-10-23 19:12:213391
3392} // namespace content