blob: 38713e03b1481295bf324ddab51afa08816cd834 [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]b9535422012-02-09 01:47:5921#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4422#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]d1198fd2012-08-13 22:50:1923#include "content/browser/dom_storage/dom_storage_context_impl.h"
[email protected]1ea3c792012-04-17 01:25:0424#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4625#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1226#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1627#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3228#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5429#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0530#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0031#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]f3b1a082011-11-18 00:34:3032#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3233#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5034#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2535#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3336#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3737#include "content/browser/web_contents/interstitial_page_impl.h"
38#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5639#include "content/browser/webui/web_ui_impl.h"
[email protected]7a846df2012-09-20 19:17:3940#include "content/common/browser_plugin_messages.h"
[email protected]ce9751942011-09-21 01:57:2441#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5142#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0243#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5744#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5845#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1146#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2047#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4448#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4449#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1750#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1451#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4652#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1553#include "content/public/browser/javascript_dialogs.h"
[email protected]a02cf4c2012-06-20 01:02:0054#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2755#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0056#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3757#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1458#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3259#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3460#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3861#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4262#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2563#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1064#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5065#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2166#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4867#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1868#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5469#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0370#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1671#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2972#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5473#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3474#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3775#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5676#include "ui/base/layout.h"
[email protected]25ee94f2012-09-11 19:16:1677#include "ui/base/touch/touch_device_win.h"
[email protected]d353541f2012-05-03 22:45:4178#include "ui/base/ui_base_switches.h"
[email protected]7da9c4c2012-06-12 14:43:0179#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5281#include "ui/gl/gl_switches.h"
[email protected]ce9751942011-09-21 01:57:2482#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3683#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3184#include "webkit/glue/webpreferences.h"
85
[email protected]f66df822012-05-18 16:52:1786#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5087#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4188#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5789#endif
[email protected]3e45ba92009-02-20 21:09:0090
[email protected]c71fe6402012-08-15 15:22:5591#if defined(USE_AURA) && defined(USE_X11)
92#include "ui/base/touch/touch_factory.h"
93#endif // defined (USE_AURA) && defined(USE_X11)
94
[email protected]420ae012009-04-24 05:16:3295// Cross-Site Navigations
96//
[email protected]b172aee2012-04-10 17:05:2697// If a WebContentsImpl is told to navigate to a different web site (as
98// determined by SiteInstance), it will replace its current RenderViewHost with
99// a new RenderViewHost dedicated to the new SiteInstance. This works as
100// follows:
[email protected]420ae012009-04-24 05:16:32101//
102// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46103// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32104// - The pending RVH is "suspended," so that no navigation messages are sent to
105// its renderer until the onbeforeunload JavaScript handler has a chance to
106// run in the current RVH.
107// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
108// that it has a pending cross-site request. ResourceDispatcherHost will
109// check for this when the response arrives.
110// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46111// cancel all the pending logic. Otherwise we allow the pending RVH to send
112// the navigation request to its renderer.
113// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
114// main resource load on the pending RVH. It checks CrossSiteRequestManager
115// to see that it is a cross-site request, and installs a
116// CrossSiteResourceHandler.
117// - When RDH receives a response, the BufferedResourceHandler determines
118// whether it is a download. If so, it sends a message to the new renderer
119// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26120// pending RVH remains until the next DidNavigate event for this
121// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32122// - After RDH receives a response and determines that it is safe and not a
123// download, it pauses the response to first run the old page's onunload
124// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26125// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32126// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15127// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32128// the ResourceDispatcherHost, who unpauses the response. Data is then sent
129// to the pending RVH.
130// - The pending renderer sends a FrameNavigate message that invokes the
131// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46132// pending RVH.
[email protected]992db4c2011-05-12 15:37:15133// - The previous renderer is kept swapped out in RenderViewHostManager in case
134// the user goes back. The process only stays live if another tab is using
135// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32136
[email protected]6717bf272012-05-11 23:31:25137using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44138
[email protected]8ff00d72012-10-23 19:12:21139namespace content {
[email protected]420ae012009-04-24 05:16:32140namespace {
141
142// Amount of time we wait between when a key event is received and the renderer
143// is queried for its state and pushed to the NavigationEntry.
144const int kQueryStateDelay = 5000;
145
[email protected]6ebdc9b2010-09-27 16:55:57146const int kSyncWaitDelay = 40;
147
[email protected]82114f52012-03-20 22:53:41148const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05149
[email protected]420ae012009-04-24 05:16:32150#if defined(OS_WIN)
151
152BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
153 // Note: erase is required to properly paint some widgets borders. This can
154 // be seen with textfields.
155 InvalidateRect(hwnd, NULL, TRUE);
156 return TRUE;
157}
158#endif
159
[email protected]2c5569662011-03-22 20:45:02160ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21161 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50162 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16163 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47164 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02165 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47166 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02167 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23168 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
169 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47170 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16171 break; // Fall through to rest of function.
172 }
[email protected]5e369672009-11-03 23:48:30173
[email protected]59246c572012-02-10 13:32:13174 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
175 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36176 if (entry.restore_type() ==
177 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13178 if (entry.GetHasPostData())
179 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13181 }
[email protected]5e369672009-11-03 23:48:30182
[email protected]2c5569662011-03-22 20:45:02183 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30184}
185
[email protected]10f417c52011-12-28 21:04:23186void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47187 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21188 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50189 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16190 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51191 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54192 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55193 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
194 params->current_history_list_length = controller.GetEntryCount();
[email protected]d1ef81d2012-07-24 11:39:36195 if (!entry.GetBaseURLForDataURL().is_empty()) {
196 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
197 params->history_url_for_data_url = entry.GetVirtualURL();
198 }
[email protected]36fc0392011-12-25 03:59:51199 params->referrer = entry.GetReferrer();
200 params->transition = entry.GetTransitionType();
201 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00202 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55203 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34204 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47205 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48206 params->transferred_request_child_id =
207 entry.transferred_global_request_id().child_id;
208 params->transferred_request_request_id =
209 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22210 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00211 // Avoid downloading when in view-source mode.
212 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44213 params->is_post = entry.GetHasPostData();
214 if(entry.GetBrowserInitiatedPostData()) {
215 params->browser_initiated_post_data.assign(
216 entry.GetBrowserInitiatedPostData()->front(),
217 entry.GetBrowserInitiatedPostData()->front() +
218 entry.GetBrowserInitiatedPostData()->size());
219
220 }
[email protected]6c6b02d2011-09-02 03:36:47221
[email protected]7c16976c2012-08-04 02:38:23222 if (reload_type == NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL &&
223 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) {
224 // We may have been redirected when navigating to the current URL.
225 // Use the URL the user originally intended to visit, if it's valid and if a
226 // POST wasn't involved; the latter case avoids issues with sending data to
227 // the wrong page.
228 params->url = entry.GetOriginalRequestURL();
229 } else {
230 params->url = entry.GetURL();
231 }
232
[email protected]951a64832012-10-11 16:26:37233 params->can_load_local_resources = entry.GetCanLoadLocalResources();
234
[email protected]6c6b02d2011-09-02 03:36:47235 if (delegate)
236 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34237}
238
[email protected]f98f5092012-05-19 00:08:14239int GetSwitchValueAsInt(
240 const CommandLine& command_line,
241 const std::string& switch_string,
242 int min_value) {
243 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
244 int int_value;
245 if (base::StringToInt(string_value, &int_value))
246 return std::max(min_value, int_value);
247 else
248 return min_value;
249}
250
[email protected]420ae012009-04-24 05:16:32251} // namespace
252
[email protected]a81343d232011-12-27 07:39:20253WebContents* WebContents::Create(
254 BrowserContext* browser_context,
255 SiteInstance* site_instance,
256 int routing_id,
[email protected]d1198fd2012-08-13 22:50:19257 const WebContents* base_web_contents) {
258 return WebContentsImpl::Create(
259 browser_context, site_instance, routing_id,
260 static_cast<const WebContentsImpl*>(base_web_contents));
261}
262
263WebContents* WebContents::CreateWithSessionStorage(
264 BrowserContext* browser_context,
265 SiteInstance* site_instance,
266 int routing_id,
[email protected]b172aee2012-04-10 17:05:26267 const WebContents* base_web_contents,
[email protected]d1198fd2012-08-13 22:50:19268 const SessionStorageNamespaceMap& session_storage_namespace_map) {
269 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
270
271 for (SessionStorageNamespaceMap::const_iterator it =
272 session_storage_namespace_map.begin();
273 it != session_storage_namespace_map.end();
274 ++it) {
275 new_contents->GetController().SetSessionStorageNamespace(it->first,
276 it->second);
277 }
278
279 new_contents->Init(browser_context, site_instance, routing_id,
280 static_cast<const WebContentsImpl*>(base_web_contents));
281 return new_contents;
[email protected]a81343d232011-12-27 07:39:20282}
[email protected]746d3052012-05-22 15:15:47283
[email protected]299d7f12012-05-23 05:31:15284WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47285 return rvh->GetDelegate()->GetAsWebContents();
286}
287
[email protected]b172aee2012-04-10 17:05:26288// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32289
[email protected]b172aee2012-04-10 17:05:26290WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21291 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19292 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42293 : delegate_(NULL),
[email protected]d1198fd2012-08-13 22:50:19294 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
[email protected]5a3bdf52012-05-24 15:12:57295 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44296 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05297 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34298 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23299 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
300 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34301 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21302 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56303 upload_size_(0),
304 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47305 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57306 capturing_contents_(false),
307 is_being_destroyed_(false),
308 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55309 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57310#if defined(OS_WIN)
311 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
312#endif
[email protected]7ab1e7d62009-10-14 23:32:01313 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56314 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38315 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21316 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
317 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00318 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43319 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20320 color_chooser_(NULL) {
[email protected]332af7732009-03-11 13:21:35321}
initial.commit09911bf2008-07-26 23:55:29322
[email protected]b172aee2012-04-10 17:05:26323WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32324 is_being_destroyed_ = true;
325
[email protected]b24b68a2012-09-24 21:57:26326 for (std::set<RenderWidgetHostImpl*>::iterator iter =
327 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
328 (*iter)->DetachDelegate();
329 }
330 created_widgets_.clear();
331
[email protected]3ab9cb82011-06-03 18:02:07332 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55333 if (dialog_creator_)
334 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07335
[email protected]da8543762012-03-20 08:52:20336 if (color_chooser_)
337 color_chooser_->End();
338
[email protected]420ae012009-04-24 05:16:32339 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32340
[email protected]ca13a442012-04-17 14:00:12341 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21342 NotificationService::current()->Notify(
343 NOTIFICATION_WEB_CONTENTS_DESTROYED,
344 Source<WebContents>(this),
345 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32346
347 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07348#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32349 // If we still have a window handle, destroy it. GetNativeView can return
350 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42351 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52352 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58353 if (host && host->GetView())
354 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42355 }
[email protected]420ae012009-04-24 05:16:32356#endif
[email protected]7ab1e7d62009-10-14 23:32:01357
358 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15359 if (!close_start_time_.is_null()) {
[email protected]feaded02012-09-25 19:12:55360 base::TimeTicks now = base::TimeTicks::Now();
361 base::TimeTicks unload_start_time = close_start_time_;
362 if (!before_unload_end_time_.is_null())
363 unload_start_time = before_unload_end_time_;
364 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
365 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
[email protected]7ab1e7d62009-10-14 23:32:01366 }
[email protected]b5a1d11c2011-02-17 03:09:42367
[email protected]2db9bd72012-04-13 20:20:56368 FOR_EACH_OBSERVER(WebContentsObserver,
369 observers_,
370 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08371
[email protected]6934a702011-12-20 00:04:51372 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42373}
374
[email protected]d1198fd2012-08-13 22:50:19375WebContentsImpl* WebContentsImpl::Create(
376 BrowserContext* browser_context,
377 SiteInstance* site_instance,
378 int routing_id,
379 const WebContentsImpl* base_web_contents) {
380 return CreateWithOpener(browser_context, site_instance, routing_id,
381 base_web_contents, NULL);
382}
383
384WebContentsImpl* WebContentsImpl::CreateWithOpener(
385 BrowserContext* browser_context,
386 SiteInstance* site_instance,
387 int routing_id,
388 const WebContentsImpl* base_web_contents,
389 WebContentsImpl* opener) {
390 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
391
392 new_contents->Init(browser_context, site_instance, routing_id,
393 static_cast<const WebContentsImpl*>(base_web_contents));
394 return new_contents;
395}
396
[email protected]7a846df2012-09-20 19:17:39397WebContentsImpl* WebContentsImpl::CreateGuest(BrowserContext* browser_context,
398 const std::string& host_url,
[email protected]c88b2a562012-10-27 03:36:56399 int guest_instance_id,
400 bool visible) {
[email protected]7a846df2012-09-20 19:17:39401 // The SiteInstance of a given guest is based on the fact that it's a guest
402 // in addition to which platform application the guest belongs to, rather
403 // than the URL that the guest is being navigated to.
404 GURL guest_site(
405 base::StringPrintf("%s://%s", chrome::kGuestScheme, host_url.c_str()));
406 SiteInstance* guest_site_instance =
407 SiteInstance::CreateForURL(browser_context, guest_site);
408 WebContentsImpl* new_contents = WebContentsImpl::Create(
409 browser_context,
410 guest_site_instance,
411 MSG_ROUTING_NONE,
412 NULL); // base WebContents
413 WebContentsImpl* new_contents_impl =
414 static_cast<WebContentsImpl*>(new_contents);
415
416 // This makes |new_contents| act as a guest.
417 // For more info, see comment above class BrowserPluginGuest.
418 new_contents_impl->browser_plugin_guest_.reset(
[email protected]8ff00d72012-10-23 19:12:21419 BrowserPluginGuest::Create(
[email protected]7a846df2012-09-20 19:17:39420 guest_instance_id,
421 new_contents_impl,
[email protected]c88b2a562012-10-27 03:36:56422 new_contents_impl->GetRenderViewHost(),
423 visible));
[email protected]7a846df2012-09-20 19:17:39424 return new_contents;
425}
426
[email protected]b172aee2012-04-10 17:05:26427WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
428 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54429 WebPreferences prefs;
430
431 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
432
433 prefs.developer_extras_enabled = true;
434 prefs.javascript_enabled =
435 !command_line.HasSwitch(switches::kDisableJavaScript);
436 prefs.web_security_enabled =
437 !command_line.HasSwitch(switches::kDisableWebSecurity);
438 prefs.plugins_enabled =
439 !command_line.HasSwitch(switches::kDisablePlugins);
440 prefs.java_enabled =
441 !command_line.HasSwitch(switches::kDisableJava);
442
443 prefs.uses_page_cache =
444 command_line.HasSwitch(switches::kEnableFastback);
445 prefs.remote_fonts_enabled =
446 !command_line.HasSwitch(switches::kDisableRemoteFonts);
447 prefs.xss_auditor_enabled =
448 !command_line.HasSwitch(switches::kDisableXSSAuditor);
449 prefs.application_cache_enabled =
450 !command_line.HasSwitch(switches::kDisableApplicationCache);
451
452 prefs.local_storage_enabled =
453 !command_line.HasSwitch(switches::kDisableLocalStorage);
454 prefs.databases_enabled =
455 !command_line.HasSwitch(switches::kDisableDatabases);
[email protected]634a3bd2012-07-26 04:49:01456#if defined(OS_ANDROID)
457 prefs.webaudio_enabled =
458 command_line.HasSwitch(switches::kEnableWebAudio);
459#else
[email protected]64d69de42012-02-06 00:19:54460 prefs.webaudio_enabled =
461 !command_line.HasSwitch(switches::kDisableWebAudio);
[email protected]634a3bd2012-07-26 04:49:01462#endif
[email protected]64d69de42012-02-06 00:19:54463
464 prefs.experimental_webgl_enabled =
465 GpuProcessHost::gpu_enabled() &&
466 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]deed0fd2012-07-25 18:20:07467#if defined(OS_ANDROID)
468 command_line.HasSwitch(switches::kEnableExperimentalWebGL);
469#else
[email protected]64d69de42012-02-06 00:19:54470 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
[email protected]deed0fd2012-07-25 18:20:07471#endif
[email protected]64d69de42012-02-06 00:19:54472
[email protected]5a073092012-06-08 00:42:51473 prefs.flash_3d_enabled =
474 GpuProcessHost::gpu_enabled() &&
475 !command_line.HasSwitch(switches::kDisableFlash3d);
476 prefs.flash_stage3d_enabled =
477 GpuProcessHost::gpu_enabled() &&
478 !command_line.HasSwitch(switches::kDisableFlashStage3d);
[email protected]e0d8c422012-06-04 22:57:19479
[email protected]64d69de42012-02-06 00:19:54480 prefs.gl_multisampling_enabled =
481 !command_line.HasSwitch(switches::kDisableGLMultisampling);
482 prefs.privileged_webgl_extensions_enabled =
483 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
484 prefs.site_specific_quirks_enabled =
485 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
486 prefs.allow_file_access_from_file_urls =
487 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
488 prefs.show_composited_layer_borders =
489 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
490 prefs.show_composited_layer_tree =
491 command_line.HasSwitch(switches::kShowCompositedLayerTree);
492 prefs.show_fps_counter =
493 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]2afdb072012-09-17 15:56:08494 prefs.accelerated_compositing_for_overflow_scroll_enabled =
495 command_line.HasSwitch(
496 switches::kEnableAcceleratedCompositingForOverflowScroll);
[email protected]8611a852012-05-23 22:11:19497 prefs.show_paint_rects =
498 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]66bd5512012-08-01 02:02:52499 prefs.render_vsync_enabled =
500 !command_line.HasSwitch(switches::kDisableGpuVsync);
[email protected]64d69de42012-02-06 00:19:54501 prefs.accelerated_compositing_enabled =
502 GpuProcessHost::gpu_enabled() &&
503 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54504 prefs.force_compositing_mode =
[email protected]9b19cf82012-06-13 06:23:23505 command_line.HasSwitch(switches::kForceCompositingMode) &&
506 !command_line.HasSwitch(switches::kDisableForceCompositingMode);
[email protected]64d69de42012-02-06 00:19:54507 prefs.fixed_position_compositing_enabled =
508 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
509 prefs.accelerated_2d_canvas_enabled =
510 GpuProcessHost::gpu_enabled() &&
511 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58512 prefs.deferred_2d_canvas_enabled =
[email protected]69cffc82012-08-10 13:27:27513 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54514 prefs.accelerated_painting_enabled =
515 GpuProcessHost::gpu_enabled() &&
516 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
517 prefs.accelerated_filters_enabled =
518 GpuProcessHost::gpu_enabled() &&
519 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
520 prefs.accelerated_layers_enabled =
521 prefs.accelerated_animation_enabled =
522 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54523 prefs.accelerated_plugins_enabled =
524 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
525 prefs.accelerated_video_enabled =
526 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
[email protected]64d69de42012-02-06 00:19:54527 prefs.fullscreen_enabled =
528 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]4e7f3e92012-09-17 20:46:43529 prefs.css_sticky_position_enabled =
530 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]37ac2a82012-03-01 05:30:16531 prefs.css_regions_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03532 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]bc199582012-03-29 09:02:29533 prefs.css_shaders_enabled =
534 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]b63b9692012-07-25 02:38:01535 prefs.css_variables_enabled =
[email protected]ff7b6dd2012-09-15 20:20:03536 command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures);
[email protected]c71fe6402012-08-15 15:22:55537#if defined(USE_AURA) && defined(USE_X11)
538 prefs.device_supports_touch |=
539 ui::TouchFactory::GetInstance()->IsTouchDevicePresent();
540#endif
[email protected]25ee94f2012-09-11 19:16:16541#if defined(OS_WIN)
542 prefs.device_supports_touch = ui::IsTouchDevicePresent();
543#endif
[email protected]d849b122012-07-18 07:35:26544#if defined(OS_ANDROID)
545 prefs.device_supports_mouse = false;
546#endif
[email protected]64d69de42012-02-06 00:19:54547
548#if defined(OS_MACOSX)
549 bool default_enable_scroll_animator = true;
550#else
551 // On CrOS, the launcher always passes in the --enable flag.
552 bool default_enable_scroll_animator = false;
553#endif
554 prefs.enable_scroll_animator = default_enable_scroll_animator;
555 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
556 prefs.enable_scroll_animator = true;
557 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
558 prefs.enable_scroll_animator = false;
559
560 prefs.visual_word_movement_enabled =
561 command_line.HasSwitch(switches::kEnableVisualWordMovement);
[email protected]64d69de42012-02-06 00:19:54562
563 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32564 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54565 DCHECK(gpu_data_manager);
[email protected]4ca18632012-08-30 21:48:39566 uint32 blacklist_type = gpu_data_manager->GetBlacklistedFeatures();
[email protected]8ff00d72012-10-23 19:12:21567 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54568 prefs.accelerated_compositing_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21569 if (blacklist_type & GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54570 prefs.experimental_webgl_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21571 if (blacklist_type & GPU_FEATURE_TYPE_FLASH3D)
[email protected]e0d8c422012-06-04 22:57:19572 prefs.flash_3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21573 if (blacklist_type & GPU_FEATURE_TYPE_FLASH_STAGE3D)
[email protected]e0d8c422012-06-04 22:57:19574 prefs.flash_stage3d_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21575 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54576 prefs.accelerated_2d_canvas_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21577 if (blacklist_type & GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54578 prefs.gl_multisampling_enabled = false;
[email protected]8ff00d72012-10-23 19:12:21579 if (blacklist_type & GPU_FEATURE_TYPE_3D_CSS) {
[email protected]c521d7462012-10-03 22:28:20580 prefs.accelerated_layers_enabled = false;
581 prefs.accelerated_animation_enabled = false;
582 }
[email protected]8ff00d72012-10-23 19:12:21583 if (blacklist_type & GPU_FEATURE_TYPE_ACCELERATED_VIDEO)
[email protected]c521d7462012-10-03 22:28:20584 prefs.accelerated_video_enabled = false;
[email protected]64d69de42012-02-06 00:19:54585
586 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45587 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32588 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54589 prefs.accelerated_video_enabled = false;
590 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45591 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09592 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54593 }
594 }
595
[email protected]b9535422012-02-09 01:47:59596 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58597 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54598 prefs.loads_images_automatically = true;
599 prefs.javascript_enabled = true;
600 }
601
602 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
603
604 // Force accelerated compositing and 2d canvas off for chrome:, about: and
605 // chrome-devtools: pages (unless it's specifically allowed).
606 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54607 url.SchemeIs(chrome::kChromeUIScheme) ||
608 (url.SchemeIs(chrome::kAboutScheme) &&
609 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25610 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54611 prefs.accelerated_compositing_enabled = false;
612 prefs.accelerated_2d_canvas_enabled = false;
613 }
[email protected]43d9d782012-03-01 15:40:09614
[email protected]f98f5092012-05-19 00:08:14615 if (command_line.HasSwitch(switches::kDefaultTileWidth))
616 prefs.default_tile_width =
617 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
618 if (command_line.HasSwitch(switches::kDefaultTileHeight))
619 prefs.default_tile_height =
620 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
621 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
622 prefs.max_untiled_layer_width =
623 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
624 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
625 prefs.max_untiled_layer_height =
626 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
627
[email protected]ffabb1e2012-10-12 19:51:17628 // TODO(scottmg): Probably Native is wrong: http://crbug.com/133312
629 if (gfx::Screen::GetNativeScreen()->IsDIPEnabled()) {
[email protected]2486dce2012-05-23 17:18:19630 // Only apply when using DIP coordinate system as this setting interferes
631 // with fixed layout mode.
632 prefs.apply_default_device_scale_factor_in_compositor = true;
633 }
634
[email protected]de023762012-07-26 17:10:17635 prefs.fixed_position_creates_stacking_context = !command_line.HasSwitch(
636 switches::kDisableFixedPositionCreatesStackingContext);
[email protected]96bcdc102012-05-24 23:42:10637
[email protected]e755a382012-09-13 17:16:35638 prefs.gesture_tap_highlight_enabled = command_line.HasSwitch(
639 switches::kEnableGestureTapHighlight);
[email protected]3f7e2062012-09-04 16:38:12640
[email protected]6b4dcb072012-06-18 22:26:51641 prefs.number_of_cpu_cores = base::SysInfo::NumberOfProcessors();
642
[email protected]1c0c9bc2012-10-08 22:41:48643 prefs.apply_page_scale_factor_in_compositor =
[email protected]65bfd9972012-10-19 03:39:37644 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:48645
[email protected]76f7d4882012-10-26 21:09:22646 prefs.deferred_image_decoding_enabled =
647 command_line.HasSwitch(switches::kEnableDeferredImageDecoding);
648
[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
[email protected]d1198fd2012-08-13 22:50:191150}
1151
[email protected]14392a52012-05-02 20:28:441152void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1153 // Clear the opener if it has been closed.
1154 if (web_contents == opener_) {
[email protected]8ff00d72012-10-23 19:12:211155 registrar_.Remove(this, NOTIFICATION_WEB_CONTENTS_DESTROYED,
1156 Source<WebContents>(opener_));
[email protected]14392a52012-05-02 20:28:441157 opener_ = NULL;
1158 }
1159}
1160
[email protected]b172aee2012-04-10 17:05:261161void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311162 observers_.AddObserver(observer);
1163}
1164
[email protected]b172aee2012-04-10 17:05:261165void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311166 observers_.RemoveObserver(observer);
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341170 if (delegate_)
1171 delegate_->ActivateContents(this);
1172}
1173
[email protected]b172aee2012-04-10 17:05:261174void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121175 if (delegate_)
1176 delegate_->DeactivateContents(this);
1177}
1178
[email protected]b172aee2012-04-10 17:05:261179void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481180 if (delegate_)
1181 delegate_->LostCapture();
1182}
1183
[email protected]b24b68a2012-09-24 21:57:261184void WebContentsImpl::RenderWidgetDeleted(
1185 RenderWidgetHostImpl* render_widget_host) {
1186 if (is_being_destroyed_) {
1187 // |created_widgets_| might have been destroyed.
1188 return;
1189 }
1190
1191 std::set<RenderWidgetHostImpl*>::iterator iter =
1192 created_widgets_.find(render_widget_host);
1193 if (iter != created_widgets_.end())
1194 created_widgets_.erase(iter);
1195}
1196
[email protected]b172aee2012-04-10 17:05:261197bool WebContentsImpl::PreHandleKeyboardEvent(
1198 const NativeWebKeyboardEvent& event,
1199 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481200 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131201 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481202}
1203
[email protected]b172aee2012-04-10 17:05:261204void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481205 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131206 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481207}
1208
[email protected]b172aee2012-04-10 17:05:261209void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431210 if (delegate_)
1211 delegate_->HandleMouseDown();
1212}
1213
[email protected]b172aee2012-04-10 17:05:261214void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481215 if (delegate_)
1216 delegate_->HandleMouseUp();
1217}
1218
[email protected]590a634e2012-07-19 16:38:231219void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481220 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231221 delegate_->HandlePointerActivate();
1222}
1223
1224void WebContentsImpl::HandleGestureBegin() {
1225 if (delegate_)
1226 delegate_->HandleGestureBegin();
1227}
1228
1229void WebContentsImpl::HandleGestureEnd() {
1230 if (delegate_)
1231 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481232}
1233
[email protected]b172aee2012-04-10 17:05:261234void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471235 if (delegate_)
1236 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1237}
1238
[email protected]b172aee2012-04-10 17:05:261239bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381240 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121241}
1242
[email protected]a9c81f02012-06-01 00:15:441243void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1244 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371245 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441246 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371247 } else {
1248 GotResponseToLockMouseRequest(false);
1249 }
1250}
1251
[email protected]b172aee2012-04-10 17:05:261252void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371253 if (delegate_)
1254 delegate_->LostMouseLock();
1255}
1256
[email protected]bafe6cd2012-05-23 23:09:501257void WebContentsImpl::CreateNewWindow(
1258 int route_id,
[email protected]97714c82012-06-06 10:15:131259 const ViewHostMsg_CreateWindow_Params& params,
1260 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501261 if (delegate_ && !delegate_->ShouldCreateWebContents(
1262 this, route_id, params.window_container_type, params.frame_name,
1263 params.target_url)) {
[email protected]aacd1d72012-07-23 17:35:091264 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
[email protected]bafe6cd2012-05-23 23:09:501265 return;
1266 }
1267
1268 // We usually create the new window in the same BrowsingInstance (group of
1269 // script-related windows), by passing in the current SiteInstance. However,
1270 // if the opener is being suppressed, we create a new SiteInstance in its own
1271 // BrowsingInstance.
1272 scoped_refptr<SiteInstance> site_instance =
1273 params.opener_suppressed ?
[email protected]e94bbcb2012-09-07 05:33:571274 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501275 GetSiteInstance();
1276
1277 // Create the new web contents. This will automatically create the new
1278 // WebContentsView. In the future, we may want to create the view separately.
[email protected]d1198fd2012-08-13 22:50:191279 WebContentsImpl* new_contents =
1280 new WebContentsImpl(GetBrowserContext(),
1281 params.opener_suppressed ? NULL : this);
1282
1283 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341284 //
1285 // http://crbug.com/142685
[email protected]d1198fd2012-08-13 22:50:191286 const std::string& partition_id =
[email protected]8ff00d72012-10-23 19:12:211287 GetContentClient()->browser()->
[email protected]e94bbcb2012-09-07 05:33:571288 GetStoragePartitionIdForSite(GetBrowserContext(),
[email protected]77ab17312012-09-28 15:34:591289 site_instance->GetSiteURL());
[email protected]8ff00d72012-10-23 19:12:211290 StoragePartition* partition =
[email protected]4c3a23582012-08-18 08:54:341291 BrowserContext::GetStoragePartition(GetBrowserContext(),
1292 site_instance);
[email protected]d1198fd2012-08-13 22:50:191293 DOMStorageContextImpl* dom_storage_context =
[email protected]4c3a23582012-08-18 08:54:341294 static_cast<DOMStorageContextImpl*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191295 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1296 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1297 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
1298 new_contents->GetController().SetSessionStorageNamespace(
1299 partition_id,
1300 session_storage_namespace);
1301 new_contents->Init(GetBrowserContext(), site_instance, route_id, this);
1302
[email protected]bafe6cd2012-05-23 23:09:501303 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1304
1305 if (!params.opener_suppressed) {
[email protected]8ff00d72012-10-23 19:12:211306 WebContentsView* new_view = new_contents->GetView();
[email protected]bafe6cd2012-05-23 23:09:501307
1308 // TODO(brettw): It seems bogus that we have to call this function on the
1309 // newly created object and give it one of its own member variables.
1310 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1311
1312 // Save the created window associated with the route so we can show it
1313 // later.
1314 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1315 pending_contents_[route_id] = new_contents;
1316 }
1317
1318 if (delegate_) {
1319 delegate_->WebContentsCreated(
1320 this, params.opener_frame_id, params.target_url, new_contents);
1321 }
1322
1323 if (params.opener_suppressed) {
1324 // When the opener is suppressed, the original renderer cannot access the
1325 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001326 bool was_blocked = false;
1327 if (delegate_) {
1328 gfx::Rect initial_pos;
1329 delegate_->AddNewContents(
1330 this, new_contents, params.disposition, initial_pos,
1331 params.user_gesture, &was_blocked);
1332 }
1333 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211334 OpenURLParams open_params(params.target_url,
1335 Referrer(),
1336 CURRENT_TAB,
1337 PAGE_TRANSITION_LINK,
1338 true /* is_renderer_initiated */);
[email protected]eda238a12012-09-07 23:44:001339 new_contents->OpenURL(open_params);
1340 }
[email protected]bafe6cd2012-05-23 23:09:501341 }
1342}
1343
1344void WebContentsImpl::CreateNewWidget(int route_id,
1345 WebKit::WebPopupType popup_type) {
1346 CreateNewWidget(route_id, false, popup_type);
1347}
1348
1349void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1350 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1351}
1352
1353void WebContentsImpl::CreateNewWidget(int route_id,
1354 bool is_fullscreen,
1355 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211356 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501357 RenderWidgetHostImpl* widget_host =
1358 new RenderWidgetHostImpl(this, process, route_id);
[email protected]b24b68a2012-09-24 21:57:261359 created_widgets_.insert(widget_host);
1360
[email protected]bafe6cd2012-05-23 23:09:501361 RenderWidgetHostViewPort* widget_view =
1362 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1363 if (!is_fullscreen) {
1364 // Popups should not get activated.
1365 widget_view->SetPopupType(popup_type);
1366 }
1367 // Save the created widget associated with the route so we can show it later.
1368 pending_widget_views_[route_id] = widget_view;
1369
1370#if defined(OS_MACOSX)
1371 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1372 // to allow it to survive the trip without being hosted.
1373 base::mac::NSObjectRetain(widget_view->GetNativeView());
1374#endif
1375}
1376
1377void WebContentsImpl::ShowCreatedWindow(int route_id,
1378 WindowOpenDisposition disposition,
1379 const gfx::Rect& initial_pos,
1380 bool user_gesture) {
1381 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001382 if (contents) {
1383 WebContentsDelegate* delegate = GetDelegate();
1384 if (delegate) {
1385 delegate->AddNewContents(
1386 this, contents, disposition, initial_pos, user_gesture, NULL);
1387 }
1388 }
[email protected]bafe6cd2012-05-23 23:09:501389}
1390
1391void WebContentsImpl::ShowCreatedWidget(int route_id,
1392 const gfx::Rect& initial_pos) {
1393 ShowCreatedWidget(route_id, false, initial_pos);
1394}
1395
1396void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1397 ShowCreatedWidget(route_id, true, gfx::Rect());
1398}
1399
1400void WebContentsImpl::ShowCreatedWidget(int route_id,
1401 bool is_fullscreen,
1402 const gfx::Rect& initial_pos) {
1403 if (delegate_)
1404 delegate_->RenderWidgetShowing();
1405
1406 RenderWidgetHostViewPort* widget_host_view =
1407 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1408 if (!widget_host_view)
1409 return;
1410 if (is_fullscreen) {
1411 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1412 } else {
1413 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1414 }
[email protected]89054502012-06-03 10:29:241415
1416 RenderWidgetHostImpl* render_widget_host_impl =
1417 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1418 render_widget_host_impl->Init();
1419 // Only allow privileged mouse lock for fullscreen render widget, which is
1420 // used to implement Pepper Flash fullscreen.
1421 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501422
1423#if defined(OS_MACOSX)
1424 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1425 // properly embedded (or purposefully ignored) we can release the retain we
1426 // took in CreateNewWidget().
1427 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1428#endif
1429}
1430
1431WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1432 PendingContents::iterator iter = pending_contents_.find(route_id);
1433
1434 // Certain systems can block the creation of new windows. If we didn't succeed
1435 // in creating one, just return NULL.
1436 if (iter == pending_contents_.end()) {
1437 return NULL;
1438 }
1439
1440 WebContentsImpl* new_contents = iter->second;
1441 pending_contents_.erase(route_id);
1442
1443 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1444 !new_contents->GetRenderViewHost()->GetView())
1445 return NULL;
1446
1447 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1448 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1449 return new_contents;
1450}
1451
1452RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1453 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1454 if (iter == pending_widget_views_.end()) {
1455 DCHECK(false);
1456 return NULL;
1457 }
1458
1459 RenderWidgetHostView* widget_host_view = iter->second;
1460 pending_widget_views_.erase(route_id);
1461
1462 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1463 if (!widget_host->GetProcess()->HasConnection()) {
1464 // The view has gone away or the renderer crashed. Nothing to do.
1465 return NULL;
1466 }
1467
1468 return widget_host_view;
1469}
1470
1471void WebContentsImpl::ShowContextMenu(
[email protected]8ff00d72012-10-23 19:12:211472 const ContextMenuParams& params,
1473 ContextMenuSourceType type) {
[email protected]bafe6cd2012-05-23 23:09:501474 // Allow WebContentsDelegates to handle the context menu operation first.
1475 if (delegate_ && delegate_->HandleContextMenu(params))
1476 return;
1477
[email protected]ba16e3a2012-09-07 04:14:521478 render_view_host_delegate_view_->ShowContextMenu(params, type);
[email protected]bafe6cd2012-05-23 23:09:501479}
1480
[email protected]f13b4202012-06-12 23:53:231481void WebContentsImpl::RequestMediaAccessPermission(
[email protected]8ff00d72012-10-23 19:12:211482 const MediaStreamRequest* request,
1483 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231484 if (delegate_)
1485 delegate_->RequestMediaAccessPermission(this, request, callback);
1486 else
[email protected]8ff00d72012-10-23 19:12:211487 callback.Run(MediaStreamDevices());
[email protected]f13b4202012-06-12 23:53:231488}
1489
[email protected]16383382012-09-05 23:57:261490#if defined(OS_ANDROID)
1491void WebContentsImpl::AttachLayer(WebKit::WebLayer* layer) {
1492 if (delegate_)
1493 delegate_->AttachLayer(this, layer);
1494}
1495
1496void WebContentsImpl::RemoveLayer(WebKit::WebLayer* layer) {
1497 if (delegate_)
1498 delegate_->RemoveLayer(this, layer);
1499}
1500#endif
1501
[email protected]b172aee2012-04-10 17:05:261502void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231503 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331504 if (delegate_)
1505 delegate_->UpdatePreferredSize(this, pref_size);
1506}
1507
[email protected]b172aee2012-04-10 17:05:261508void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341509 if (delegate_)
1510 delegate_->ResizeDueToAutoResize(this, new_size);
1511}
1512
[email protected]b172aee2012-04-10 17:05:261513WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201514 if (!delegate_)
1515 return NULL;
[email protected]00c37fc2011-08-02 00:22:501516
[email protected]e5d549d2011-12-28 01:29:201517 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1518 // Notify observers.
1519 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1520 DidOpenURL(params.url, params.referrer,
1521 params.disposition, params.transition));
1522 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341523}
1524
[email protected]6b618e62012-08-16 12:59:181525bool WebContentsImpl::Send(IPC::Message* message) {
1526 if (!GetRenderViewHost()) {
1527 delete message;
1528 return false;
1529 }
1530
1531 return GetRenderViewHost()->Send(message);
1532}
1533
[email protected]b172aee2012-04-10 17:05:261534bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501535 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251536 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231537 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251538 reload_type);
[email protected]876bc832010-09-07 16:29:541539}
[email protected]96d185d2009-04-24 03:28:541540
[email protected]ba45bfd2012-05-22 21:51:441541void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211542 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441543 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1544 RenderViewForInterstitialPageCreated(render_view_host));
1545}
1546
[email protected]b172aee2012-04-10 17:05:261547bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231548 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501549 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401550 // The renderer will reject IPC messages with URLs longer than
1551 // this limit, so don't attempt to navigate with a longer URL.
[email protected]8ff00d72012-10-23 19:12:211552 if (entry.GetURL().spec().size() > kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401553 return false;
1554
[email protected]9f76c1e2012-03-05 15:15:581555 RenderViewHostImpl* dest_render_view_host =
1556 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401557 if (!dest_render_view_host)
1558 return false; // Unable to create the desired render view host.
1559
[email protected]80a8fad2011-01-29 04:02:381560 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071561 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581562 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501563 WebUIControllerFactory* factory =
[email protected]8ff00d72012-10-23 19:12:211564 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271565 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501566 bool is_allowed_in_web_ui_renderer =
1567 factory &&
[email protected]24e18252012-04-16 21:26:271568 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1569 data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211570 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231571 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271572 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211573 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231574 CHECK(0);
1575 }
[email protected]54ec6472010-04-09 19:39:581576
[email protected]96d185d2009-04-24 03:28:541577 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441578 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521579 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441580 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511581 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541582
[email protected]7bb761892012-07-20 09:32:471583 // Notify observers that we will navigate in this RV.
1584 FOR_EACH_OBSERVER(WebContentsObserver,
1585 observers_,
1586 AboutToNavigateRenderView(dest_render_view_host));
1587
[email protected]96d185d2009-04-24 03:28:541588 // Used for page load time metrics.
1589 current_load_start_ = base::TimeTicks::Now();
1590
1591 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341592 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271593 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471594 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341595 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541596
[email protected]36fc0392011-12-25 03:59:511597 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541598 // HACK!! This code suppresses javascript: URLs from being added to
1599 // session history, which is what we want to do for javascript: URLs that
1600 // do not generate content. What we really need is a message from the
1601 // renderer telling us that a new page was not created. The same message
1602 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511603 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541604 return false;
1605 }
1606
[email protected]3c9e1872010-11-18 16:17:491607 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251608 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041609 observers_,
[email protected]36fc0392011-12-25 03:59:511610 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541611
[email protected]09b29342011-06-24 19:18:481612 if (delegate_)
1613 delegate_->DidNavigateToPendingEntry(this);
1614
[email protected]d5f942ba2008-09-26 19:30:341615 return true;
1616}
1617
[email protected]b172aee2012-04-10 17:05:261618void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331619 const SiteInstance* site_instance,
1620 int history_length,
1621 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411622 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1623 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191624 if (render_manager_.pending_render_view_host()) {
1625 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141626 return;
[email protected]9e1ad4b2011-08-14 16:49:191627 }
[email protected]9f76c1e2012-03-05 15:15:581628 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191629 if (!rvh) {
1630 NOTREACHED();
1631 return;
1632 }
[email protected]9f76c1e2012-03-05 15:15:581633 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191634 NOTREACHED();
1635 return;
1636 }
[email protected]6b618e62012-08-16 12:59:181637 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1638 history_length,
1639 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141640}
1641
[email protected]b172aee2012-04-10 17:05:261642void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271643 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541644 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1645 return;
1646 }
[email protected]9f76c1e2012-03-05 15:15:581647 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541648}
1649
[email protected]b172aee2012-04-10 17:05:261650bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271651 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541652}
1653
[email protected]b172aee2012-04-10 17:05:261654InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271655 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221656}
1657
[email protected]b172aee2012-04-10 17:05:261658bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161659 // WebKit creates Document object when MIME type is application/xhtml+xml,
1660 // so we also support this MIME type.
1661 return contents_mime_type_ == "text/html" ||
1662 contents_mime_type_ == "text/xml" ||
1663 contents_mime_type_ == "application/xhtml+xml" ||
1664 contents_mime_type_ == "text/plain" ||
1665 contents_mime_type_ == "text/css" ||
1666 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1667}
1668
[email protected]b172aee2012-04-10 17:05:261669void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591670 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161671 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551672 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]8ff00d72012-10-23 19:12:211673 SaveURL(GetURL(), Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141674 return;
[email protected]c7dd2f62011-07-18 15:57:591675 }
1676
1677 Stop();
1678
1679 // Create the save package and possibly prompt the user for the name to save
1680 // the page as. The user prompt is an asynchronous operation that runs on
1681 // another thread.
1682 save_package_ = new SavePackage(this);
1683 save_package_->GetSaveInfo();
1684}
1685
1686// Used in automated testing to bypass prompting the user for file names.
1687// Instead, the names and paths are hard coded rather than running them through
1688// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261689bool WebContentsImpl::SavePage(const FilePath& main_file,
1690 const FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211691 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591692 // Stop the page from navigating.
1693 Stop();
1694
1695 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211696 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121700 const FilePath& file,
1701 const base::Callback<void(const FilePath&, int64)>& callback) {
1702 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1703}
1704
[email protected]b172aee2012-04-10 17:05:261705bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231706 NavigationEntryImpl* active_entry =
1707 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321708 return (active_entry != NULL &&
1709 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511710 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321711}
1712
[email protected]b172aee2012-04-10 17:05:261713const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271714 return contents_mime_type_;
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271718 return notify_disconnection_;
1719}
1720
[email protected]b172aee2012-04-10 17:05:261721void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311722 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181723 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311727 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181728 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161729}
1730
[email protected]8ff00d72012-10-23 19:12:211731RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271732 return &renderer_preferences_;
1733}
1734
[email protected]b172aee2012-04-10 17:05:261735void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271736 new_tab_start_time_ = time;
1737}
1738
[email protected]b172aee2012-04-10 17:05:261739base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271740 return new_tab_start_time_;
1741}
1742
[email protected]e35ccd52012-05-23 16:22:471743void WebContentsImpl::Close() {
1744 Close(GetRenderViewHost());
1745}
1746
[email protected]b172aee2012-04-10 17:05:261747void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151748 if (close_start_time_.is_null())
1749 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011750}
1751
[email protected]b172aee2012-04-10 17:05:261752bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191753#if defined(OS_CHROMEOS)
1754 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1755 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511756 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201757 return false;
1758 return true;
[email protected]46624bf2010-06-09 16:04:191759#else
1760 return true;
1761#endif
1762}
1763
[email protected]b172aee2012-04-10 17:05:261764void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521765 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581766 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511767 if (delegate_)
1768 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341769}
1770
[email protected]e35ccd52012-05-23 16:22:471771void WebContentsImpl::UserGestureDone() {
1772 OnUserGesture();
1773}
1774
[email protected]b172aee2012-04-10 17:05:261775void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271776 closed_by_user_gesture_ = value;
1777}
1778
[email protected]b172aee2012-04-10 17:05:261779bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271780 return closed_by_user_gesture_;
1781}
1782
[email protected]b172aee2012-04-10 17:05:261783double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051784 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561785 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251786 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171787 return 0;
[email protected]b75b8292010-10-01 07:28:251788
1789 double zoom_level;
1790 if (temporary_zoom_settings_) {
1791 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581792 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251793 } else {
[email protected]2ae88d12011-10-14 09:11:191794 GURL url;
[email protected]10f417c52011-12-28 21:04:231795 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191796 // Since zoom map is updated using rewritten URL, use rewritten URL
1797 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511798 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191799 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251800 }
[email protected]d0b8d092010-10-25 04:05:171801 return zoom_level;
1802}
[email protected]b75b8292010-10-01 07:28:251803
[email protected]b172aee2012-04-10 17:05:261804int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591805 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171806 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011807 // Calculate the zoom percent from the factor. Round up to the nearest whole
1808 // number.
[email protected]b75b8292010-10-01 07:28:251809 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011810 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251811 *enable_decrement = percent > minimum_zoom_percent_;
1812 *enable_increment = percent < maximum_zoom_percent_;
1813 return percent;
1814}
1815
[email protected]b172aee2012-04-10 17:05:261816void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501817 if (!delegate_)
1818 return;
1819
[email protected]10f417c52011-12-28 21:04:231820 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501821 if (!active_entry)
1822 return;
1823
[email protected]36fc0392011-12-25 03:59:511824 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121825}
1826
[email protected]b172aee2012-04-10 17:05:261827void WebContentsImpl::ViewFrameSource(const GURL& url,
1828 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271829 if (!delegate_)
1830 return;
1831
1832 delegate_->ViewSourceForFrame(this, url, content_state);
1833}
1834
[email protected]b172aee2012-04-10 17:05:261835int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271836 return minimum_zoom_percent_;
1837}
1838
[email protected]b172aee2012-04-10 17:05:261839int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271840 return maximum_zoom_percent_;
1841}
1842
[email protected]b172aee2012-04-10 17:05:261843gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231844 return preferred_size_;
1845}
1846
[email protected]b172aee2012-04-10 17:05:261847int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271848 return content_restrictions_;
1849}
1850
[email protected]b172aee2012-04-10 17:05:261851WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501852 WebUIControllerFactory* factory =
[email protected]8ff00d72012-10-23 19:12:211853 GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]863f70a2012-01-27 02:05:501854 if (!factory)
1855 return WebUI::kNoWebUI;
1856 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271857}
1858
[email protected]8ff00d72012-10-23 19:12:211859WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271860 // When there is a pending navigation entry, we want to use the pending WebUI
1861 // that goes along with it to control the basic flags. For example, we want to
1862 // show the pending URL in the URL bar, so we want the display_url flag to
1863 // be from the pending entry.
1864 //
1865 // The confusion comes because there are multiple possibilities for the
1866 // initial load in a tab as a side effect of the way the RenderViewHostManager
1867 // works.
1868 //
1869 // - For the very first tab the load looks "normal". The new tab Web UI is
1870 // the pending one, and we want it to apply here.
1871 //
1872 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1873 // get switched to the one previously associated with the new tab pages.
1874 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1875 // have a committed Web UI in this case.
1876 //
1877 // This condition handles all of these cases:
1878 //
1879 // - First load in first tab: no committed nav entry + pending nav entry +
1880 // pending dom ui:
1881 // -> Use pending Web UI if any.
1882 //
1883 // - First load in second tab: no committed nav entry + pending nav entry +
1884 // no pending Web UI:
1885 // -> Use the committed Web UI if any.
1886 //
1887 // - Second navigation in any tab: committed nav entry + pending nav entry:
1888 // -> Use pending Web UI if any.
1889 //
1890 // - Normal state with no load: committed nav entry + no pending nav entry:
1891 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251892 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271893 (controller_.GetLastCommittedEntry() ||
1894 render_manager_.pending_web_ui()))
1895 return render_manager_.pending_web_ui();
1896 return render_manager_.web_ui();
1897}
1898
[email protected]b172aee2012-04-10 17:05:261899bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271900 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581901 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271902}
1903
[email protected]b172aee2012-04-10 17:05:261904bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441905 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501906}
1907
[email protected]b172aee2012-04-10 17:05:261908void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321909 SkColor color) {
[email protected]6b618e62012-08-16 12:59:181910 Send(new ViewMsg_DidChooseColorResponse(
1911 GetRoutingID(), color_chooser_id, color));
[email protected]da8543762012-03-20 08:52:201912}
1913
[email protected]b172aee2012-04-10 17:05:261914void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]6b618e62012-08-16 12:59:181915 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
[email protected]da8543762012-03-20 08:52:201916 if (delegate_)
1917 delegate_->DidEndColorChooser();
1918 color_chooser_ = NULL;
1919}
1920
[email protected]b172aee2012-04-10 17:05:261921bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]8ff00d72012-10-23 19:12:211922 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271923 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221924 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231925 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411926 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271927}
1928
[email protected]b172aee2012-04-10 17:05:261929void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271930 if (delegate_)
1931 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211932}
1933
[email protected]3a3b75a2012-06-01 08:38:361934void WebContentsImpl::OnRegisterIntentService(
1935 const webkit_glue::WebIntentServiceData& data,
1936 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:431937 if (delegate_)
1938 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301939}
1940
[email protected]b172aee2012-04-10 17:05:261941void WebContentsImpl::OnWebIntentDispatch(
1942 const webkit_glue::WebIntentData& intent,
1943 int intent_id) {
[email protected]e5f2de02012-07-20 22:15:431944 if (!delegate_)
1945 return;
1946
[email protected]0d9989d2011-12-21 20:26:001947 WebIntentsDispatcherImpl* intents_dispatcher =
1948 new WebIntentsDispatcherImpl(this, intent, intent_id);
1949 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301950}
1951
[email protected]54047eb52012-05-08 21:45:571952void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211953 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571954 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131955 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571956 bool is_main_frame,
1957 const GURL& opener_url,
1958 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211959 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181960 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451961 GURL validated_opener_url(opener_url);
[email protected]8ff00d72012-10-23 19:12:211962 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:571963 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:541964 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571965 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451966 false,
[email protected]9f76c1e2012-03-05 15:15:581967 &validated_url);
[email protected]ef108e72012-06-20 14:03:541968 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:571969 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451970 true,
1971 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181972
[email protected]0d60f0192011-04-14 12:40:101973 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251974 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:131975 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
1976 is_main_frame, validated_url, is_error_page,
1977 render_view_host));
[email protected]400992b2012-06-14 00:03:541978
1979 if (is_main_frame) {
1980 // Notify observers about the provisional change in the main frame URL.
1981 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1982 ProvisionalChangeToMainFrameUrl(validated_url,
1983 validated_opener_url,
1984 render_view_host));
1985 }
1986}
1987
1988void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:211989 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:541990 int32 page_id,
1991 const GURL& opener_url,
1992 const GURL& source_url,
1993 const GURL& target_url) {
1994 // TODO(creis): Remove this method and have the pre-rendering code listen to
1995 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1996 // instead. See http://crbug.com/78512.
1997 GURL validated_source_url(source_url);
1998 GURL validated_target_url(target_url);
1999 GURL validated_opener_url(opener_url);
[email protected]8ff00d72012-10-23 19:12:212000 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542001 render_view_host->GetProcess();
2002 RenderViewHostImpl::FilterURL(
2003 ChildProcessSecurityPolicyImpl::GetInstance(),
2004 render_process_host->GetID(),
2005 false,
2006 &validated_source_url);
2007 RenderViewHostImpl::FilterURL(
2008 ChildProcessSecurityPolicyImpl::GetInstance(),
2009 render_process_host->GetID(),
2010 false,
2011 &validated_target_url);
2012 RenderViewHostImpl::FilterURL(
2013 ChildProcessSecurityPolicyImpl::GetInstance(),
2014 render_process_host->GetID(),
2015 true,
2016 &validated_opener_url);
2017 NavigationEntry* entry;
2018 if (page_id == -1) {
2019 entry = controller_.GetPendingEntry();
2020 } else {
2021 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2022 page_id);
2023 }
2024 if (!entry || entry->GetURL() != validated_source_url)
2025 return;
2026
2027 // Notify observers about the provisional change in the main frame URL.
2028 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2029 ProvisionalChangeToMainFrameUrl(validated_target_url,
2030 validated_opener_url,
2031 render_view_host));
[email protected]724159a2010-12-30 01:11:182032}
2033
[email protected]54047eb52012-05-08 21:45:572034void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212035 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582036 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2037 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2038 << ", error_code: " << params.error_code
2039 << ", error_description: " << params.error_description
2040 << ", is_main_frame: " << params.is_main_frame
2041 << ", showing_repost_interstitial: " <<
2042 params.showing_repost_interstitial
2043 << ", frame_id: " << params.frame_id;
2044 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212045 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572046 render_view_host->GetProcess();
[email protected]ef108e72012-06-20 14:03:542047 RenderViewHost::FilterURL(
[email protected]54047eb52012-05-08 21:45:572048 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:452049 false,
[email protected]9f76c1e2012-03-05 15:15:582050 &validated_url);
[email protected]724159a2010-12-30 01:11:182051
[email protected]d7b175e2011-10-11 15:31:582052 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182053 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2054 // This means that the interstitial won't be torn down properly, which is
2055 // bad. But if we have an interstitial, go back to another tab type, and
2056 // then load the same interstitial again, we could end up getting the first
2057 // interstitial's "failed" message (as a result of the cancel) when we're on
2058 // the second one.
2059 //
2060 // We can't tell this apart, so we think we're tearing down the current page
2061 // which will cause a crash later one. There is also some code in
2062 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2063 // out because of this problem.
2064 //
2065 // http://code.google.com/p/chromium/issues/detail?id=2855
2066 // Because this will not tear down the interstitial properly, if "back" is
2067 // back to another tab type, the interstitial will still be somewhat alive
2068 // in the previous tab type. If you navigate somewhere that activates the
2069 // tab with the interstitial again, you'll see a flash before the new load
2070 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272071 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182072 LOG(WARNING) << "Discarding message during interstitial.";
2073 return;
2074 }
2075
[email protected]a16690732012-07-13 19:22:172076 // Do not clear the pending entry if one exists, so that the user's typed
2077 // URL is not lost when a navigation fails or is aborted. We'll allow
2078 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182079
[email protected]54047eb52012-05-08 21:45:572080 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182081 }
2082
[email protected]d8c660432011-12-22 20:51:252083 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582084 observers_,
2085 DidFailProvisionalLoad(params.frame_id,
2086 params.is_main_frame,
2087 validated_url,
2088 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462089 params.error_description,
2090 render_view_host));
[email protected]724159a2010-12-30 01:11:182091}
2092
[email protected]b172aee2012-04-10 17:05:262093void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182094 const GURL& url,
[email protected]70435962011-08-02 20:13:282095 const std::string& security_info,
2096 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182097 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282098 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192099 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182100 cache.Increment();
2101
2102 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082103 int cert_id = 0;
2104 net::CertStatus cert_status = 0;
2105 int security_bits = -1;
2106 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212107 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2108 &security_bits, &connection_status);
2109 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002110 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2111 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182112
[email protected]8ff00d72012-10-23 19:12:212113 NotificationService::current()->Notify(
2114 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2115 Source<NavigationController>(&controller_),
2116 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182117}
2118
[email protected]b172aee2012-04-10 17:05:262119void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212120 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182121 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192122 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182123}
2124
[email protected]b172aee2012-04-10 17:05:262125void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022126 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232127 LOG(INFO) << security_origin << " ran insecure content from "
2128 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212129 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412130 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212131 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182132 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412133 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192134 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182135}
2136
[email protected]b172aee2012-04-10 17:05:262137void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182138 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252139 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472140 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182141}
2142
[email protected]b172aee2012-04-10 17:05:262143void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312144 int64 frame_id,
2145 const GURL& validated_url,
2146 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252147 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472148 DidFinishLoad(frame_id, validated_url, is_main_frame,
2149 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312150}
2151
[email protected]b172aee2012-04-10 17:05:262152void WebContentsImpl::OnDidFailLoadWithError(
2153 int64 frame_id,
2154 const GURL& validated_url,
2155 bool is_main_frame,
2156 int error_code,
2157 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252158 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312159 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472160 error_code, error_description,
2161 message_source_));
[email protected]724159a2010-12-30 01:11:182162}
2163
[email protected]b172aee2012-04-10 17:05:262164void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272165 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432166 if (delegate_)
2167 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172168}
2169
[email protected]b172aee2012-04-10 17:05:262170void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262171 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232172 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252173 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262174 if (!entry)
2175 return;
2176 // Note that we don't call NavigationController::GotToOffset() as we don't
2177 // want to create a pending navigation entry (it might end up lingering
2178 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252179 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212180 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512181 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212182 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472183 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572184
2185 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2186 // it in now that we know. This allows us to find the entry when it commits.
2187 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232188 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332189 entry->set_site_instance(
2190 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572191 }
[email protected]216813952011-05-19 22:21:262192 }
2193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2196 int maximum_percent,
2197 bool remember) {
[email protected]216813952011-05-19 22:21:262198 minimum_zoom_percent_ = minimum_percent;
2199 maximum_zoom_percent_ = maximum_percent;
2200 temporary_zoom_settings_ = !remember;
2201}
2202
[email protected]20b433a2012-05-15 21:23:462203void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212204 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552205 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262206 // Check if the URL to save matches the URL of the main frame. Since this
2207 // message originates from Pepper plugins, it may not be the case if the
2208 // plugin is an embedded element.
2209 GURL main_frame_url = GetURL();
2210 if (!main_frame_url.is_valid())
2211 return;
2212 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462213 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272214}
2215
[email protected]b172aee2012-04-10 17:05:262216void WebContentsImpl::OnEnumerateDirectory(int request_id,
2217 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432218 if (!delegate_)
2219 return;
2220
[email protected]b9535422012-02-09 01:47:592221 ChildProcessSecurityPolicyImpl* policy =
2222 ChildProcessSecurityPolicyImpl::GetInstance();
2223 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2224 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432228 if (delegate_)
2229 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202230}
2231
[email protected]b172aee2012-04-10 17:05:262232void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2233 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362234 const string16& title,
2235 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432236 if (!delegate_)
2237 return;
2238
[email protected]b9535422012-02-09 01:47:592239 ChildProcessSecurityPolicyImpl* policy =
2240 ChildProcessSecurityPolicyImpl::GetInstance();
2241 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2242 return;
[email protected]3a3b75a2012-06-01 08:38:362243 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202244}
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnFindReply(int request_id,
2247 int number_of_matches,
2248 const gfx::Rect& selection_rect,
2249 int active_match_ordinal,
2250 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432251 if (delegate_) {
2252 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2253 active_match_ordinal, final_update);
2254 }
[email protected]b888919c2011-09-02 00:32:162255}
2256
[email protected]59363fc92012-09-05 03:46:312257#if defined(OS_ANDROID)
2258void WebContentsImpl::OnFindMatchRectsReply(
2259 int version,
2260 const std::vector<gfx::RectF>& rects,
2261 const gfx::RectF& active_rect) {
2262 if (delegate_)
2263 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2264}
2265#endif
2266
[email protected]b172aee2012-04-10 17:05:262267void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442268 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2269 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2273 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102274 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252275 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102276 AppCacheAccessed(manifest_url, blocked_by_policy));
2277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322280 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432281 color_chooser_ = delegate_ ?
2282 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202283}
2284
[email protected]b172aee2012-04-10 17:05:262285void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202286 if (color_chooser_ &&
2287 color_chooser_id == color_chooser_->identifier())
2288 color_chooser_->End();
2289}
2290
[email protected]b172aee2012-04-10 17:05:262291void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322292 SkColor color) {
[email protected]da8543762012-03-20 08:52:202293 if (color_chooser_ &&
2294 color_chooser_id == color_chooser_->identifier())
2295 color_chooser_->SetSelectedColor(color);
2296}
2297
[email protected]9f2a9d72012-04-16 16:02:222298void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2299 const FilePath& path,
2300 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552301 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2302
[email protected]3fc07c52012-04-20 00:27:442303 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2304 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292305}
2306
[email protected]d0759f492012-04-19 22:50:502307// This exists for render views that don't have a WebUI, but do have WebUI
2308// bindings enabled.
2309void WebContentsImpl::OnWebUISend(const GURL& source_url,
2310 const std::string& name,
2311 const base::ListValue& args) {
2312 if (delegate_)
2313 delegate_->WebUISend(this, source_url, name, args);
2314}
2315
[email protected]d8415ad92012-08-23 14:40:502316void WebContentsImpl::OnRequestPpapiBrokerPermission(
2317 int request_id,
2318 const GURL& url,
2319 const FilePath& plugin_path) {
2320 base::Callback<void(bool)> callback =
2321 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2322 base::Unretained(this), request_id);
2323 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2324 WebContentsObserver* observer;
2325 while ((observer = it.GetNext()) != NULL) {
2326 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2327 callback))
2328 return;
2329 }
2330
2331 // Fall back to allowing the request if no observer handled it.
2332 OnPpapiBrokerPermissionResult(request_id, true);
2333}
2334
2335void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2336 bool result) {
2337 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2338 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2339 request_id,
2340 result));
2341}
2342
[email protected]19be7a62012-10-01 23:03:372343void WebContentsImpl::OnBrowserPluginCreateGuest(
[email protected]92a01cc2012-09-29 14:13:592344 int instance_id,
[email protected]19be7a62012-10-01 23:03:372345 const std::string& storage_partition_id,
[email protected]c88b2a562012-10-27 03:36:562346 bool persist_storage,
2347 bool visible) {
[email protected]19be7a62012-10-01 23:03:372348 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
2349 // specific messages for this WebContents (through its
2350 // BrowserPluginEmbedderHelper). This means that any message from browser
2351 // plugin renderer prior to CreateGuest will be ignored.
[email protected]7a846df2012-09-20 19:17:392352 // For more info, see comment above classes BrowserPluginEmbedder and
2353 // BrowserPluginGuest.
[email protected]b6bcd8c2012-10-03 06:03:582354 // The first BrowserPluginHostMsg_CreateGuest message from this WebContents'
2355 // embedder render process is handled here. Once BrowserPluginEmbedder is
2356 // created, all subsequent BrowserPluginHostMsg_CreateGuest messages are
2357 // intercepted by the BrowserPluginEmbedderHelper and handled by the
2358 // BrowserPluginEmbedder. Thus, this code will not be executed if a
2359 // BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392360 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392361 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212362 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]19be7a62012-10-01 23:03:372363 browser_plugin_embedder_->CreateGuest(GetRenderViewHost(),
2364 instance_id,
2365 storage_partition_id,
[email protected]c88b2a562012-10-27 03:36:562366 persist_storage,
2367 visible);
[email protected]19be7a62012-10-01 23:03:372368}
2369
[email protected]96d185d2009-04-24 03:28:542370// Notifies the RenderWidgetHost instance about the fact that the page is
2371// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::SetIsLoading(bool is_loading,
2373 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542374 if (is_loading == is_loading_)
2375 return;
2376
2377 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212378 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542379 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562380 upload_size_ = 0;
2381 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542382 }
2383
2384 render_manager_.SetIsLoading(is_loading);
2385
2386 is_loading_ = is_loading;
2387 waiting_for_response_ = is_loading;
2388
[email protected]6ebdc9b2010-09-27 16:55:572389 if (delegate_)
2390 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212391 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542392
[email protected]8ff00d72012-10-23 19:12:212393 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2394 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542395 if (details)
[email protected]8ff00d72012-10-23 19:12:212396 det = Details<LoadNotificationDetails>(details);
2397 NotificationService::current()->Notify(
2398 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542399}
2400
[email protected]b172aee2012-04-10 17:05:262401void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212402 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322403 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562404 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382405 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442406 // that opened the window, as long as both renderers have the same
2407 // privileges.
[email protected]1fd1a502011-03-30 16:55:562408 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562409 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582410 // web_ui might be NULL if the URL refers to a non-existent extension.
2411 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402412 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522413 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442414 }
2415 }
[email protected]1fd1a502011-03-30 16:55:562416 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442417 }
2418
[email protected]4e697b042011-07-08 06:44:562419 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322420 // Clear the status bubble. This is a workaround for a bug where WebKit
2421 // doesn't let us know that the cursor left an element during a
2422 // transition (this is also why the mouse cursor remains as a hand after
2423 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2424 // clear the bubble when a user navigates to a named anchor in the same
2425 // page.
[email protected]36fc0392011-12-25 03:59:512426 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322427 }
2428
[email protected]a6e82fc2010-02-24 22:28:142429 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472430 // Once the main frame is navigated, we're no longer considered to have
2431 // displayed insecure content.
2432 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172433 }
[email protected]ce5c4502009-05-06 16:46:112434
[email protected]3c9e1872010-11-18 16:17:492435 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252436 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042437 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322438}
2439
[email protected]b172aee2012-04-10 17:05:262440void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322441 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212442 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322443 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062444 // If we navigate off the page, reset JavaScript state. This does nothing
2445 // to prevent a malicious script from spamming messages, since the script
2446 // could just reload the page to stop blocking.
2447 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552448 dialog_creator_->ResetJavaScriptState(this);
2449 dialog_creator_ = NULL;
2450 }
[email protected]420ae012009-04-24 05:16:322451
[email protected]3c9e1872010-11-18 16:17:492452 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042454 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322455}
2456
[email protected]b172aee2012-04-10 17:05:262457void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462458 // If we are creating a RVH for a restored controller, then we need to make
2459 // sure the RenderView starts with a next_page_id_ larger than the number
2460 // of restored entries. This must be called before the RenderView starts
2461 // navigating (to avoid a race between the browser updating max_page_id and
2462 // the renderer updating next_page_id_). Because of this, we only call this
2463 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562464 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582465 if (max_restored_page_id >
2466 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2467 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2468 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322469}
2470
[email protected]b172aee2012-04-10 17:05:262471bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2472 const string16& title) {
[email protected]420ae012009-04-24 05:16:322473 // For file URLs without a title, use the pathname instead. In the case of a
2474 // synthesized title, we don't want the update to count toward the "one set
2475 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512476 string16 final_title;
[email protected]420ae012009-04-24 05:16:322477 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512478 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2479 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322480 explicit_set = false; // Don't count synthetic titles toward the set limit.
2481 } else {
[email protected]acafd272011-07-26 17:35:572482 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322483 explicit_set = true;
2484 }
2485
[email protected]987fc3a2011-05-26 14:18:092486 // If a page is created via window.open and never navigated,
2487 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552488 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092489 if (entry) {
[email protected]36fc0392011-12-25 03:59:512490 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092491 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322492
[email protected]36fc0392011-12-25 03:59:512493 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092494 } else {
2495 if (page_title_when_no_navigation_entry_ == final_title)
2496 return false; // Nothing changed, don't bother.
2497
2498 page_title_when_no_navigation_entry_ = final_title;
2499 }
[email protected]420ae012009-04-24 05:16:322500
[email protected]420ae012009-04-24 05:16:322501 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232502 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322503
[email protected]8ff00d72012-10-23 19:12:212504 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462505 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142506
[email protected]8ff00d72012-10-23 19:12:212507 NotificationService::current()->Notify(
2508 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2509 Source<WebContents>(this),
2510 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042511
[email protected]420ae012009-04-24 05:16:322512 return true;
2513}
2514
[email protected]b172aee2012-04-10 17:05:262515void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322516 // After sending out a swap notification, we need to send a disconnect
2517 // notification so that clients that pick up a pointer to |this| can NULL the
2518 // pointer. See Bug 1230284.
2519 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212520 NotificationService::current()->Notify(
2521 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2522 Source<WebContents>(this),
2523 NotificationService::NoDetails());
[email protected]7a846df2012-09-20 19:17:392524
2525 // Ensure that the associated embedder gets cleared after a RenderViewHost
2526 // gets swapped, so we don't reuse the same embedder next time a
2527 // RenderViewHost is attached to this WebContents.
2528 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322532 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212533 NotificationService::current()->Notify(
2534 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2535 Source<WebContents>(this),
2536 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322537}
2538
[email protected]b172aee2012-04-10 17:05:262539void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322540 if (!notify_disconnection_)
2541 return;
2542
2543 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212544 NotificationService::current()->Notify(
2545 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2546 Source<WebContents>(this),
2547 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322548}
2549
[email protected]5a3bdf52012-05-24 15:12:572550RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2551 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322552}
2553
[email protected]8d3347f2009-07-09 22:00:212554RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262555WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212556 return &render_manager_;
2557}
2558
[email protected]8ff00d72012-10-23 19:12:212559RendererPreferences WebContentsImpl::GetRendererPrefs(
2560 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462561 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512562}
2563
[email protected]b172aee2012-04-10 17:05:262564WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172565 return this;
2566}
2567
[email protected]b172aee2012-04-10 17:05:262568gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172569 if (delegate_)
2570 return delegate_->GetRootWindowResizerRect();
2571 return gfx::Rect();
2572}
2573
[email protected]7a846df2012-09-20 19:17:392574void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2575 if (browser_plugin_embedder_.get())
2576 browser_plugin_embedder_.reset();
2577}
2578
[email protected]b172aee2012-04-10 17:05:262579void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442580 // Don't send notifications if we are just creating a swapped-out RVH for
2581 // the opener chain. These won't be used for view-source or WebUI, so it's
2582 // ok to return early.
2583 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2584 return;
2585
[email protected]8ff00d72012-10-23 19:12:212586 NotificationService::current()->Notify(
2587 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2588 Source<WebContents>(this),
2589 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232590 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322591 if (!entry)
2592 return;
2593
2594 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352595 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562596 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582597 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322598
2599 if (entry->IsViewSourceMode()) {
2600 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182601 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582602 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322603 }
[email protected]0666aef2009-05-13 19:48:082604
[email protected]d487beefe2011-12-21 05:41:212605 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262606
2607 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252608 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322609}
2610
[email protected]b172aee2012-04-10 17:05:262611void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522612 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322613 // Don't notify the world, since this came from a renderer in the
2614 // background.
2615 return;
2616 }
2617
2618 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312619 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232620 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302621
2622 // Restore the focus to the tab (otherwise the focus will be on the top
2623 // window).
[email protected]484ae5912010-09-29 19:16:142624 if (was_crashed && !FocusLocationBarByDefault() &&
2625 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302626 Focus();
[email protected]484ae5912010-09-29 19:16:142627 }
[email protected]32ded2212011-11-10 18:51:432628
[email protected]d8c660432011-12-22 20:51:252629 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]b172aee2012-04-10 17:05:262632void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2633 base::TerminationStatus status,
2634 int error_code) {
[email protected]151a63d2011-12-20 22:32:522635 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322636 // The pending page's RenderViewHost is gone.
2637 return;
2638 }
2639
2640 SetIsLoading(false, NULL);
2641 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232642 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312643 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322644
[email protected]d8c660432011-12-22 20:51:252645 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272646 observers_,
[email protected]be1f56ab2011-12-22 06:55:312647 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322648}
2649
[email protected]b172aee2012-04-10 17:05:262650void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482651 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252652 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062653}
2654
[email protected]b172aee2012-04-10 17:05:262655void WebContentsImpl::DidNavigate(
2656 RenderViewHost* rvh,
2657 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8ff00d72012-10-23 19:12:212658 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322659 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372660
[email protected]434f69f2012-02-06 21:56:522661 // Update the site of the SiteInstance if it doesn't have one yet, unless
2662 // this is for about:blank. In that case, the SiteInstance can still be
2663 // considered unused until a navigation to a real page.
2664 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2665 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332666 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522667 }
[email protected]420ae012009-04-24 05:16:322668
2669 // Need to update MIME type here because it's referred to in
2670 // UpdateNavigationCommands() called by RendererDidNavigate() to
2671 // determine whether or not to enable the encoding menu.
2672 // It's updated only for the main frame. For a subframe,
2673 // RenderView::UpdateURL does not set params.contents_mime_type.
2674 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2675 // TODO(jungshik): Add a test for the encoding menu to avoid
2676 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212677 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322678 contents_mime_type_ = params.contents_mime_type;
2679
[email protected]8ff00d72012-10-23 19:12:212680 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002681 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392682
[email protected]a9c0bfe2010-09-17 08:35:222683 // Send notification about committed provisional loads. This notification is
2684 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2685 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212686 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072687 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2688 // that is not recorded in the navigation history. For the purpose of
2689 // tracking navigation events, we treat this event as a sub frame navigation
2690 // event.
2691 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212692 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222693 // Whether or not a page transition was triggered by going backward or
2694 // forward in the history is only stored in the navigation controller's
2695 // entry list.
2696 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512697 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212698 PAGE_TRANSITION_FORWARD_BACK)) {
2699 transition_type = PageTransitionFromInt(
2700 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222701 }
[email protected]0d60f0192011-04-14 12:40:102702 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252703 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102704 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462705 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222706 }
2707
[email protected]76543b92009-08-31 17:27:452708 if (!did_navigate)
2709 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322710
2711 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2712 // for the appropriate notification (best) or you can add it to
2713 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2714 // necessary, please).
2715
2716 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002717 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322718 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512719 if (delegate_)
2720 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002721 }
[email protected]420ae012009-04-24 05:16:322722 DidNavigateAnyFramePostCommit(rvh, details, params);
2723}
2724
[email protected]b172aee2012-04-10 17:05:262725void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2726 int32 page_id,
2727 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152728 // Ensure that this state update comes from either the active RVH or one of
2729 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522730 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322731
2732 // We must be prepared to handle state updates for any page, these occur
2733 // when the user is scrolling and entering form data, as well as when we're
2734 // leaving a page, in which case our state may have already been moved to
2735 // the next page. The navigation controller will look up the appropriate
2736 // NavigationEntry and update it when it is notified via the delegate.
2737
2738 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582739 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322740 if (entry_index < 0)
2741 return;
[email protected]10f417c52011-12-28 21:04:232742 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322743
[email protected]36fc0392011-12-25 03:59:512744 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322745 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512746 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322747 controller_.NotifyEntryChanged(entry, entry_index);
2748}
2749
[email protected]b172aee2012-04-10 17:05:262750void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2751 int32 page_id,
2752 const string16& title,
2753 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322754 // If we have a title, that's a pretty good indication that we've started
2755 // getting useful data.
2756 SetNotWaitingForResponse();
2757
[email protected]73eb2602012-02-09 19:50:552758 // Try to find the navigation entry, which might not be the current one.
2759 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232760 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582761 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092762
[email protected]73eb2602012-02-09 19:50:552763 // We can handle title updates when we don't have an entry in
2764 // UpdateTitleForEntry, but only if the update is from the current RVH.
2765 if (!entry && rvh != GetRenderViewHost())
2766 return;
2767
[email protected]a49e10b2011-08-01 23:57:462768 // TODO(evan): make use of title_direction.
2769 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092770 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322771 return;
2772
2773 // Broadcast notifications when the UI should be updated.
2774 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212775 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322776}
2777
[email protected]b172aee2012-04-10 17:05:262778void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2779 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312780 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322781}
2782
[email protected]b172aee2012-04-10 17:05:262783void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512784 if (delegate_)
2785 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322786}
2787
[email protected]b172aee2012-04-10 17:05:262788void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292789 // The UI may be in an event-tracking loop, such as between the
2790 // mouse-down and mouse-up in text selection or a button click.
2791 // Defer the close until after tracking is complete, so that we
2792 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292793 // TODO(shess): This could get more fine-grained. For instance,
2794 // closing a tab in another window while selecting text in the
2795 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212796 if (GetView()->IsEventTracking()) {
2797 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292798 return;
2799 }
2800
[email protected]420ae012009-04-24 05:16:322801 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522802 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512803 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322804}
2805
[email protected]b172aee2012-04-10 17:05:262806void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522807 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512808 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512812 if (delegate_ && delegate_->IsPopupOrPanel(this))
2813 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322814}
2815
[email protected]8ff00d72012-10-23 19:12:212816void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322817 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492818
[email protected]82114f52012-03-20 22:53:412819 if (delegate_ && content_restrictions_)
2820 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492821
2822 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292823 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2824 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322825}
2826
[email protected]8ff00d72012-10-23 19:12:212827void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322828 scoped_ptr<LoadNotificationDetails> details;
2829
[email protected]10f417c52011-12-28 21:04:232830 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322831 // An entry may not exist for a stop when loading an initial blank page or
2832 // if an iframe injected by script into a blank page finishes loading.
2833 if (entry) {
[email protected]420ae012009-04-24 05:16:322834 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2835
2836 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512837 entry->GetVirtualURL(),
2838 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322839 elapsed,
2840 &controller_,
2841 controller_.GetCurrentEntryIndex()));
2842 }
2843
[email protected]420ae012009-04-24 05:16:322844 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492845
2846 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292847 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2848 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322849}
2850
[email protected]b172aee2012-04-10 17:05:262851void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162852 controller_.DiscardNonCommittedEntries();
2853
2854 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212855 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162856}
2857
[email protected]b172aee2012-04-10 17:05:262858void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262859#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512860 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132861 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262862#endif
[email protected]1a3c3cb2010-12-16 21:03:402863}
2864
[email protected]0720b532012-08-28 19:23:372865void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2866 render_manager_.DidUpdateFrameTree(rvh);
2867}
2868
[email protected]87717d0e2012-04-26 02:58:432869void WebContentsImpl::DocumentAvailableInMainFrame(
2870 RenderViewHost* render_view_host) {
2871 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2872 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102873}
2874
[email protected]b172aee2012-04-10 17:05:262875void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082876 RenderViewHost* render_view_host,
2877 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212878 NotificationService::current()->Notify(
2879 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2880 Source<WebContents>(this),
2881 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082882}
2883
[email protected]196159d2012-05-04 17:26:542884void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2885 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212886 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262887 WindowOpenDisposition disposition,
2888 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542889 // If this came from a swapped out RenderViewHost, we only allow the request
2890 // if we are still in the same BrowsingInstance.
2891 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2892 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2893 return;
2894 }
2895
[email protected]4ad5d77d2011-12-03 02:00:482896 // Delegate to RequestTransferURL because this is just the generic
2897 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582898 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482899 GlobalRequestID());
2900}
2901
[email protected]b172aee2012-04-10 17:05:262902void WebContentsImpl::RequestTransferURL(
2903 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212904 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262905 WindowOpenDisposition disposition,
2906 int64 source_frame_id,
2907 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202908 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212909 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582910 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352911 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322912 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2913 // generated suggestions).
2914 //
[email protected]e0112912011-02-02 22:54:352915 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162916 // want web sites to see a referrer of "chrome://blah" (and some
2917 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322918 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:212919 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222920 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482921 false /* is_renderer_initiated */);
2922 params.transferred_global_request_id = old_request_id;
2923 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222924 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322925 } else {
[email protected]6bf6a6b52012-02-03 15:41:432926 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:212927 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:482928 params.transferred_global_request_id = old_request_id;
2929 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582930 }
2931 if (new_contents) {
2932 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252933 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582934 DidOpenRequestedURL(new_contents,
2935 url,
2936 referrer,
2937 disposition,
2938 transition_type,
2939 source_frame_id));
[email protected]420ae012009-04-24 05:16:322940 }
2941}
2942
[email protected]e1c3a552012-05-04 20:51:322943void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2944 // Tell the active RenderViewHost to run unload handlers and close, as long
2945 // as the request came from a RenderViewHost in the same BrowsingInstance.
2946 // In most cases, we receive this from a swapped out RenderViewHost.
2947 // It is possible to receive it from one that has just been swapped in,
2948 // in which case we might as well deliver the message anyway.
2949 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2950 GetRenderViewHost()->ClosePage();
2951}
2952
[email protected]f546640b2012-05-15 00:03:492953void WebContentsImpl::RouteMessageEvent(
2954 RenderViewHost* rvh,
2955 const ViewMsg_PostMessage_Params& params) {
2956 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:362957 // came from a RenderViewHost in the same BrowsingInstance or if this
2958 // WebContents is dedicated to a browser plugin guest.
2959 // Note: This check means that an embedder could theoretically receive a
2960 // postMessage from anyone (not just its own guests). However, this is
2961 // probably not a risk for apps since other pages won't have references
2962 // to App windows.
2963 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
2964 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:492965 return;
2966
2967 ViewMsg_PostMessage_Params new_params(params);
2968
[email protected]0720b532012-08-28 19:23:372969 // If the renderer has changed while the post message is being routed,
2970 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:192971 // TODO(nasko): Check for process ID and target frame id mismatch, once
2972 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:372973
[email protected]f546640b2012-05-15 00:03:492974 // If there is a source_routing_id, translate it to the routing ID for
2975 // the equivalent swapped out RVH in the target process. If we need
2976 // to create a swapped out RVH for the source tab, we create its opener
2977 // chain as well, since those will also be accessible to the target page.
2978 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2979 // Try to look up the WebContents for the source page.
2980 WebContentsImpl* source_contents = NULL;
2981 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2982 rvh->GetProcess()->GetID(), params.source_routing_id);
2983 if (source_rvh) {
2984 source_contents = static_cast<WebContentsImpl*>(
2985 source_rvh->GetDelegate()->GetAsWebContents());
2986 }
2987
2988 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:362989 if (GetBrowserPluginGuest()) {
2990 // We create a swapped out RenderView for the embedder in the guest's
2991 // render process but we intentionally do not expose the embedder's
2992 // opener chain to it.
2993 new_params.source_routing_id =
2994 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
2995 } else {
2996 new_params.source_routing_id =
2997 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2998 }
[email protected]f546640b2012-05-15 00:03:492999 } else {
3000 // We couldn't find it, so don't pass a source frame.
3001 new_params.source_routing_id = MSG_ROUTING_NONE;
3002 }
3003 }
3004
3005 // In most cases, we receive this from a swapped out RenderViewHost.
3006 // It is possible to receive it from one that has just been swapped in,
3007 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183008 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493009}
3010
[email protected]b172aee2012-04-10 17:05:263011void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343012 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413013 const string16& message,
3014 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323015 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213016 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323017 IPC::Message* reply_msg,
3018 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073019 // Suppress JavaScript dialogs when requested. Also suppress messages when
3020 // showing an interstitial as it's shown over the previous page and we don't
3021 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503022 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583023 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273024 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073025 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523026 delegate_->ShouldSuppressDialogs() ||
3027 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323028
3029 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213030 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433031 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553032 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523033 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433034 this,
3035 frame_url.GetOrigin(),
3036 accept_lang,
3037 javascript_message_type,
3038 message,
[email protected]51da7e32012-01-30 19:24:523039 default_prompt,
[email protected]b172aee2012-04-10 17:05:263040 base::Bind(&WebContentsImpl::OnDialogClosed,
3041 base::Unretained(this),
3042 rvh,
3043 reply_msg),
[email protected]51da7e32012-01-30 19:24:523044 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323045 }
[email protected]3ab9cb82011-06-03 18:02:073046
3047 if (suppress_this_message) {
3048 // If we are suppressing messages, just reply as if the user immediately
3049 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343050 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073051 }
3052
3053 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323054}
3055
[email protected]b172aee2012-04-10 17:05:263056void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3057 const string16& message,
3058 bool is_reload,
3059 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583060 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513061 if (delegate_)
3062 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073063
3064 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583065 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073066 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523067 delegate_->ShouldSuppressDialogs() ||
3068 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153069 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343070 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583071 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503072 return;
3073 }
[email protected]3ab9cb82011-06-03 18:02:073074
[email protected]7ab1e7d62009-10-14 23:32:013075 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553076 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523077 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323078 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263079 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523080 reply_msg));
[email protected]420ae012009-04-24 05:16:323081}
3082
[email protected]a796f202012-05-30 14:14:253083bool WebContentsImpl::AddMessageToConsole(int32 level,
3084 const string16& message,
3085 int32 line_no,
3086 const string16& source_id) {
3087 if (!delegate_)
3088 return false;
3089 return delegate_->AddMessageToConsole(this, level, message, line_no,
3090 source_id);
3091}
3092
[email protected]b172aee2012-04-10 17:05:263093WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333094 // We want to base the page config off of the real URL, rather than the
3095 // display URL.
3096 GURL url = controller_.GetActiveEntry()
3097 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3098 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323099}
3100
[email protected]0eba810b2012-10-18 03:19:363101int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213102 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363103 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3104}
3105
[email protected]b172aee2012-04-10 17:05:263106void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273107 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253108 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223109
[email protected]ea114722012-03-12 01:11:253110 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173111 if (rdh) // NULL in unittests.
3112 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253113}
3114
[email protected]b172aee2012-04-10 17:05:263115void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443116 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253117 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443118}
3119
[email protected]b172aee2012-04-10 17:05:263120void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3121 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153122 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523123 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153124 return;
3125
[email protected]9f76c1e2012-03-05 15:15:583126 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3127
[email protected]e5fc1632011-08-08 07:51:533128 // Ignore renderer unresponsive event if debugger is attached to the tab
3129 // since the event may be a result of the renderer sitting on a breakpoint.
3130 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443131 DevToolsAgentHost* agent =
[email protected]8ff00d72012-10-23 19:12:213132 DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
[email protected]0e12d7d2011-12-01 16:21:443133 if (agent &&
3134 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533135 return;
3136
[email protected]420ae012009-04-24 05:16:323137 if (is_during_unload) {
3138 // Hang occurred while firing the beforeunload/unload handler.
3139 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583140 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323141
3142 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3143 return;
3144
3145 // If the tab hangs in the beforeunload/unload handler there's really
3146 // nothing we can do to recover. Pretend the unload listeners have
3147 // all fired and close the tab. If the hang is in the beforeunload handler
3148 // then the user will not have the option of cancelling the close.
3149 Close(rvh);
3150 return;
3151 }
3152
[email protected]9f76c1e2012-03-05 15:15:583153 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473154 return;
3155
[email protected]6934a702011-12-20 00:04:513156 if (delegate_)
3157 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323158}
3159
[email protected]b172aee2012-04-10 17:05:263160void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513161 if (delegate_)
3162 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323163}
3164
[email protected]b172aee2012-04-10 17:05:263165void WebContentsImpl::LoadStateChanged(
3166 const GURL& url,
3167 const net::LoadStateWithParam& load_state,
3168 uint64 upload_position,
3169 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323170 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563171 upload_position_ = upload_position;
3172 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503173 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213174 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303175 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213176 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323177 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463178 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213179 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463180 }
[email protected]420ae012009-04-24 05:16:323181}
3182
[email protected]b172aee2012-04-10 17:05:263183void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513184 if (delegate_)
3185 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253186}
3187
[email protected]b172aee2012-04-10 17:05:263188void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553189 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323190 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553191 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513192 if (delegate_)
3193 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323194}
3195
[email protected]b172aee2012-04-10 17:05:263196void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543197 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233198 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3199 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543200}
3201
[email protected]b172aee2012-04-10 17:05:263202void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103203 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263204 gfx::Size size = view_->GetContainerSize();
3205 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3206 // here during container initialization and normal window size will be set
3207 // later. In case of tab duplication this resizing to 0x0 prevents setting
3208 // normal size later so just ignore it.
3209 if (!size.IsEmpty())
3210 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323211}
3212
[email protected]b172aee2012-04-10 17:05:263213void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543214 NotifySwapped();
3215}
3216
[email protected]14392a52012-05-02 20:28:443217int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3218 SiteInstance* instance) {
3219 if (!opener_)
3220 return MSG_ROUTING_NONE;
3221
3222 // Recursively create RenderViews for anything else in the opener chain.
3223 return opener_->CreateOpenerRenderViews(instance);
3224}
3225
3226int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3227 int opener_route_id = MSG_ROUTING_NONE;
3228
3229 // If this tab has an opener, ensure it has a RenderView in the given
3230 // SiteInstance as well.
3231 if (opener_)
3232 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3233
[email protected]0720b532012-08-28 19:23:373234 // If any of the renderers for this WebContents has the same SiteInstance,
3235 // use it.
3236 if (render_manager_.current_host()->GetSiteInstance() == instance)
3237 return render_manager_.current_host()->GetRoutingID();
3238
3239 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3240 instance);
3241 if (rvh)
3242 return rvh->GetRoutingID();
3243
[email protected]14392a52012-05-02 20:28:443244 // Create a swapped out RenderView in the given SiteInstance if none exists,
3245 // setting its opener to the given route_id. Return the new view's route_id.
3246 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3247}
3248
[email protected]b172aee2012-04-10 17:05:263249NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193250 return GetController();
[email protected]3a3d47472010-07-15 21:03:543251}
3252
[email protected]b172aee2012-04-10 17:05:263253WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563254 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323255}
3256
[email protected]10f417c52011-12-28 21:04:233257NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263258 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323259 return controller_.GetLastCommittedEntry();
3260}
3261
[email protected]b172aee2012-04-10 17:05:263262bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443263 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443264 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323265 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523266
[email protected]420ae012009-04-24 05:16:323267 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443268 if (rwh_view)
3269 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323270
[email protected]74ce1ad2011-12-16 21:51:463271 // Make sure we use the correct starting page_id in the new RenderView.
3272 UpdateMaxPageIDIfNecessary(render_view_host);
3273 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583274 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463275
[email protected]9f76c1e2012-03-05 15:15:583276 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493277 render_view_host)->CreateRenderView(string16(),
3278 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133279 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523280 return false;
[email protected]14392a52012-05-02 20:28:443281 }
[email protected]a4127722011-04-27 23:13:523282
[email protected]e60c0232011-11-11 19:56:353283#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503284 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3285 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443286 if (rwh_view) {
3287 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3288 render_widget_host->WasResized();
3289 }
[email protected]f8233cc2011-05-31 20:24:503290#endif
3291
[email protected]420ae012009-04-24 05:16:323292 return true;
3293}
3294
[email protected]b172aee2012-04-10 17:05:263295void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3296 IPC::Message* reply_msg,
3297 bool success,
3298 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543299 if (is_showing_before_unload_dialog_ && !success) {
3300 // If a beforeunload dialog is canceled, we need to stop the throbber from
3301 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293302 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353303 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543304
[email protected]3bbacc5b2012-04-17 17:46:153305 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553306 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543307 }
3308 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583309 static_cast<RenderViewHostImpl*>(
3310 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543311}
3312
[email protected]b172aee2012-04-10 17:05:263313void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213314 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123315 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103316}
[email protected]f45d2a72010-03-08 23:28:353317
[email protected]b172aee2012-04-10 17:05:263318void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213319 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263320 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573321 DownloadManager* dlm =
3322 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143323 if (!dlm)
3324 return;
3325 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263326 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143327 const NavigationEntry* entry = controller_.GetActiveEntry();
3328 if (entry)
3329 post_id = entry->GetPostID();
3330 }
[email protected]8ff00d72012-10-23 19:12:213331 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo());
[email protected]c873c862012-10-17 15:32:123332 save_info->prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143333 scoped_ptr<DownloadUrlParameters> params(
[email protected]c873c862012-10-17 15:32:123334 DownloadUrlParameters::FromWebContents(this, url, save_info.Pass()));
[email protected]f859eba2012-05-30 17:22:493335 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143336 params->set_post_id(post_id);
3337 params->set_prefer_cache(true);
3338 if (post_id >= 0)
3339 params->set_method("POST");
3340 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143341}
3342
[email protected]b172aee2012-04-10 17:05:263343void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213344 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443345 // Can be NULL during tests.
3346 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213347 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363348}
[email protected]9f76c1e2012-03-05 15:15:583349
[email protected]b172aee2012-04-10 17:05:263350RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583351 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3352}
[email protected]7900bfdb2012-05-24 19:31:243353
[email protected]8ff00d72012-10-23 19:12:213354BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393355 return browser_plugin_guest_.get();
3356}
3357
[email protected]8ff00d72012-10-23 19:12:213358BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393359 return browser_plugin_embedder_.get();
3360}
[email protected]8ff00d72012-10-23 19:12:213361
3362} // namespace content