blob: c86b627aada0177294e2d3b7fc4524017ff98169 [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]413fcd02012-10-30 00:20:081964 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
1965 RenderViewHost::FilterURL(render_process_host, true, &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181966
[email protected]0d60f0192011-04-14 12:40:101967 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251968 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:131969 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
1970 is_main_frame, validated_url, is_error_page,
1971 render_view_host));
[email protected]400992b2012-06-14 00:03:541972
1973 if (is_main_frame) {
1974 // Notify observers about the provisional change in the main frame URL.
1975 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1976 ProvisionalChangeToMainFrameUrl(validated_url,
1977 validated_opener_url,
1978 render_view_host));
1979 }
1980}
1981
1982void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:211983 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:541984 int32 page_id,
1985 const GURL& opener_url,
1986 const GURL& source_url,
1987 const GURL& target_url) {
1988 // TODO(creis): Remove this method and have the pre-rendering code listen to
1989 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1990 // instead. See http://crbug.com/78512.
1991 GURL validated_source_url(source_url);
1992 GURL validated_target_url(target_url);
1993 GURL validated_opener_url(opener_url);
[email protected]8ff00d72012-10-23 19:12:211994 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:541995 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:081996 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
1997 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
1998 RenderViewHost::FilterURL(render_process_host, true, &validated_opener_url);
[email protected]400992b2012-06-14 00:03:541999 NavigationEntry* entry;
2000 if (page_id == -1) {
2001 entry = controller_.GetPendingEntry();
2002 } else {
2003 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2004 page_id);
2005 }
2006 if (!entry || entry->GetURL() != validated_source_url)
2007 return;
2008
2009 // Notify observers about the provisional change in the main frame URL.
2010 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2011 ProvisionalChangeToMainFrameUrl(validated_target_url,
2012 validated_opener_url,
2013 render_view_host));
[email protected]724159a2010-12-30 01:11:182014}
2015
[email protected]54047eb52012-05-08 21:45:572016void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212017 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582018 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2019 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2020 << ", error_code: " << params.error_code
2021 << ", error_description: " << params.error_description
2022 << ", is_main_frame: " << params.is_main_frame
2023 << ", showing_repost_interstitial: " <<
2024 params.showing_repost_interstitial
2025 << ", frame_id: " << params.frame_id;
2026 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212027 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572028 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082029 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182030
[email protected]d7b175e2011-10-11 15:31:582031 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182032 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2033 // This means that the interstitial won't be torn down properly, which is
2034 // bad. But if we have an interstitial, go back to another tab type, and
2035 // then load the same interstitial again, we could end up getting the first
2036 // interstitial's "failed" message (as a result of the cancel) when we're on
2037 // the second one.
2038 //
2039 // We can't tell this apart, so we think we're tearing down the current page
2040 // which will cause a crash later one. There is also some code in
2041 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2042 // out because of this problem.
2043 //
2044 // http://code.google.com/p/chromium/issues/detail?id=2855
2045 // Because this will not tear down the interstitial properly, if "back" is
2046 // back to another tab type, the interstitial will still be somewhat alive
2047 // in the previous tab type. If you navigate somewhere that activates the
2048 // tab with the interstitial again, you'll see a flash before the new load
2049 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272050 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182051 LOG(WARNING) << "Discarding message during interstitial.";
2052 return;
2053 }
2054
[email protected]a16690732012-07-13 19:22:172055 // Do not clear the pending entry if one exists, so that the user's typed
2056 // URL is not lost when a navigation fails or is aborted. We'll allow
2057 // the view to clear the pending entry and typed URL if the user requests.
[email protected]724159a2010-12-30 01:11:182058
[email protected]54047eb52012-05-08 21:45:572059 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182060 }
2061
[email protected]d8c660432011-12-22 20:51:252062 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582063 observers_,
2064 DidFailProvisionalLoad(params.frame_id,
2065 params.is_main_frame,
2066 validated_url,
2067 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462068 params.error_description,
2069 render_view_host));
[email protected]724159a2010-12-30 01:11:182070}
2071
[email protected]b172aee2012-04-10 17:05:262072void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182073 const GURL& url,
[email protected]70435962011-08-02 20:13:282074 const std::string& security_info,
2075 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182076 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282077 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192078 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182079 cache.Increment();
2080
2081 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082082 int cert_id = 0;
2083 net::CertStatus cert_status = 0;
2084 int security_bits = -1;
2085 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212086 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2087 &security_bits, &connection_status);
2088 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002089 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2090 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182091
[email protected]8ff00d72012-10-23 19:12:212092 NotificationService::current()->Notify(
2093 NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
2094 Source<NavigationController>(&controller_),
2095 Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:182096}
2097
[email protected]b172aee2012-04-10 17:05:262098void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212099 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182100 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192101 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022105 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232106 LOG(INFO) << security_origin << " ran insecure content from "
2107 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212108 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412109 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212110 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182111 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412112 displayed_insecure_content_ = true;
[email protected]d1198fd2012-08-13 22:50:192113 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:182114}
2115
[email protected]b172aee2012-04-10 17:05:262116void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:182117 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:252118 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472119 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182120}
2121
[email protected]b172aee2012-04-10 17:05:262122void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312123 int64 frame_id,
2124 const GURL& validated_url,
2125 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:252126 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472127 DidFinishLoad(frame_id, validated_url, is_main_frame,
2128 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312129}
2130
[email protected]b172aee2012-04-10 17:05:262131void WebContentsImpl::OnDidFailLoadWithError(
2132 int64 frame_id,
2133 const GURL& validated_url,
2134 bool is_main_frame,
2135 int error_code,
2136 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:252137 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312138 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472139 error_code, error_description,
2140 message_source_));
[email protected]724159a2010-12-30 01:11:182141}
2142
[email protected]b172aee2012-04-10 17:05:262143void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:272144 content_restrictions_ = restrictions;
[email protected]e5f2de02012-07-20 22:15:432145 if (delegate_)
2146 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:172147}
2148
[email protected]b172aee2012-04-10 17:05:262149void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262150 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232151 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252152 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262153 if (!entry)
2154 return;
2155 // Note that we don't call NavigationController::GotToOffset() as we don't
2156 // want to create a pending navigation entry (it might end up lingering
2157 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252158 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212159 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512160 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212161 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472162 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572163
2164 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2165 // it in now that we know. This allows us to find the entry when it commits.
2166 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232167 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332168 entry->set_site_instance(
2169 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572170 }
[email protected]216813952011-05-19 22:21:262171 }
2172}
2173
[email protected]b172aee2012-04-10 17:05:262174void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2175 int maximum_percent,
2176 bool remember) {
[email protected]216813952011-05-19 22:21:262177 minimum_zoom_percent_ = minimum_percent;
2178 maximum_zoom_percent_ = maximum_percent;
2179 temporary_zoom_settings_ = !remember;
2180}
2181
[email protected]20b433a2012-05-15 21:23:462182void WebContentsImpl::OnSaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212183 const Referrer& referrer) {
[email protected]35869622012-10-26 23:23:552184 RecordDownloadSource(INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262185 // Check if the URL to save matches the URL of the main frame. Since this
2186 // message originates from Pepper plugins, it may not be the case if the
2187 // plugin is an embedded element.
2188 GURL main_frame_url = GetURL();
2189 if (!main_frame_url.is_valid())
2190 return;
2191 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462192 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272193}
2194
[email protected]b172aee2012-04-10 17:05:262195void WebContentsImpl::OnEnumerateDirectory(int request_id,
2196 const FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432197 if (!delegate_)
2198 return;
2199
[email protected]b9535422012-02-09 01:47:592200 ChildProcessSecurityPolicyImpl* policy =
2201 ChildProcessSecurityPolicyImpl::GetInstance();
2202 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2203 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212204}
2205
[email protected]b172aee2012-04-10 17:05:262206void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432207 if (delegate_)
2208 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202209}
2210
[email protected]b172aee2012-04-10 17:05:262211void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2212 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362213 const string16& title,
2214 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432215 if (!delegate_)
2216 return;
2217
[email protected]b9535422012-02-09 01:47:592218 ChildProcessSecurityPolicyImpl* policy =
2219 ChildProcessSecurityPolicyImpl::GetInstance();
2220 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2221 return;
[email protected]3a3b75a2012-06-01 08:38:362222 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202223}
2224
[email protected]b172aee2012-04-10 17:05:262225void WebContentsImpl::OnFindReply(int request_id,
2226 int number_of_matches,
2227 const gfx::Rect& selection_rect,
2228 int active_match_ordinal,
2229 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432230 if (delegate_) {
2231 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2232 active_match_ordinal, final_update);
2233 }
[email protected]b888919c2011-09-02 00:32:162234}
2235
[email protected]59363fc92012-09-05 03:46:312236#if defined(OS_ANDROID)
2237void WebContentsImpl::OnFindMatchRectsReply(
2238 int version,
2239 const std::vector<gfx::RectF>& rects,
2240 const gfx::RectF& active_rect) {
2241 if (delegate_)
2242 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2243}
2244#endif
2245
[email protected]b172aee2012-04-10 17:05:262246void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442247 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2248 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452249}
2250
[email protected]b172aee2012-04-10 17:05:262251void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2252 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102253 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252254 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102255 AppCacheAccessed(manifest_url, blocked_by_policy));
2256}
2257
[email protected]b172aee2012-04-10 17:05:262258void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322259 SkColor color) {
[email protected]e5f2de02012-07-20 22:15:432260 color_chooser_ = delegate_ ?
2261 delegate_->OpenColorChooser(this, color_chooser_id, color) : NULL;
[email protected]da8543762012-03-20 08:52:202262}
2263
[email protected]b172aee2012-04-10 17:05:262264void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202265 if (color_chooser_ &&
2266 color_chooser_id == color_chooser_->identifier())
2267 color_chooser_->End();
2268}
2269
[email protected]b172aee2012-04-10 17:05:262270void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322271 SkColor color) {
[email protected]da8543762012-03-20 08:52:202272 if (color_chooser_ &&
2273 color_chooser_id == color_chooser_->identifier())
2274 color_chooser_->SetSelectedColor(color);
2275}
2276
[email protected]9f2a9d72012-04-16 16:02:222277void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2278 const FilePath& path,
2279 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552280 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2281
[email protected]3fc07c52012-04-20 00:27:442282 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2283 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292284}
2285
[email protected]d0759f492012-04-19 22:50:502286// This exists for render views that don't have a WebUI, but do have WebUI
2287// bindings enabled.
2288void WebContentsImpl::OnWebUISend(const GURL& source_url,
2289 const std::string& name,
2290 const base::ListValue& args) {
2291 if (delegate_)
2292 delegate_->WebUISend(this, source_url, name, args);
2293}
2294
[email protected]d8415ad92012-08-23 14:40:502295void WebContentsImpl::OnRequestPpapiBrokerPermission(
2296 int request_id,
2297 const GURL& url,
2298 const FilePath& plugin_path) {
2299 base::Callback<void(bool)> callback =
2300 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
2301 base::Unretained(this), request_id);
2302 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
2303 WebContentsObserver* observer;
2304 while ((observer = it.GetNext()) != NULL) {
2305 if (observer->RequestPpapiBrokerPermission(this, url, plugin_path,
2306 callback))
2307 return;
2308 }
2309
2310 // Fall back to allowing the request if no observer handled it.
2311 OnPpapiBrokerPermissionResult(request_id, true);
2312}
2313
2314void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id,
2315 bool result) {
2316 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
2317 rvh->Send(new ViewMsg_PpapiBrokerPermissionResult(rvh->GetRoutingID(),
2318 request_id,
2319 result));
2320}
2321
[email protected]19be7a62012-10-01 23:03:372322void WebContentsImpl::OnBrowserPluginCreateGuest(
[email protected]92a01cc2012-09-29 14:13:592323 int instance_id,
[email protected]19be7a62012-10-01 23:03:372324 const std::string& storage_partition_id,
[email protected]c88b2a562012-10-27 03:36:562325 bool persist_storage,
2326 bool visible) {
[email protected]19be7a62012-10-01 23:03:372327 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
2328 // specific messages for this WebContents (through its
2329 // BrowserPluginEmbedderHelper). This means that any message from browser
2330 // plugin renderer prior to CreateGuest will be ignored.
[email protected]7a846df2012-09-20 19:17:392331 // For more info, see comment above classes BrowserPluginEmbedder and
2332 // BrowserPluginGuest.
[email protected]b6bcd8c2012-10-03 06:03:582333 // The first BrowserPluginHostMsg_CreateGuest message from this WebContents'
2334 // embedder render process is handled here. Once BrowserPluginEmbedder is
2335 // created, all subsequent BrowserPluginHostMsg_CreateGuest messages are
2336 // intercepted by the BrowserPluginEmbedderHelper and handled by the
2337 // BrowserPluginEmbedder. Thus, this code will not be executed if a
2338 // BrowserPluginEmbedder exists for this WebContents.
[email protected]7a846df2012-09-20 19:17:392339 CHECK(!browser_plugin_embedder_.get());
[email protected]7a846df2012-09-20 19:17:392340 browser_plugin_embedder_.reset(
[email protected]8ff00d72012-10-23 19:12:212341 BrowserPluginEmbedder::Create(this, GetRenderViewHost()));
[email protected]19be7a62012-10-01 23:03:372342 browser_plugin_embedder_->CreateGuest(GetRenderViewHost(),
2343 instance_id,
2344 storage_partition_id,
[email protected]c88b2a562012-10-27 03:36:562345 persist_storage,
2346 visible);
[email protected]19be7a62012-10-01 23:03:372347}
2348
[email protected]96d185d2009-04-24 03:28:542349// Notifies the RenderWidgetHost instance about the fact that the page is
2350// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262351void WebContentsImpl::SetIsLoading(bool is_loading,
2352 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542353 if (is_loading == is_loading_)
2354 return;
2355
2356 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212357 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542358 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562359 upload_size_ = 0;
2360 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542361 }
2362
2363 render_manager_.SetIsLoading(is_loading);
2364
2365 is_loading_ = is_loading;
2366 waiting_for_response_ = is_loading;
2367
[email protected]6ebdc9b2010-09-27 16:55:572368 if (delegate_)
2369 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212370 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542371
[email protected]8ff00d72012-10-23 19:12:212372 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2373 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542374 if (details)
[email protected]8ff00d72012-10-23 19:12:212375 det = Details<LoadNotificationDetails>(details);
2376 NotificationService::current()->Notify(
2377 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542378}
2379
[email protected]b172aee2012-04-10 17:05:262380void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212381 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322382 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562383 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382384 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442385 // that opened the window, as long as both renderers have the same
2386 // privileges.
[email protected]1fd1a502011-03-30 16:55:562387 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562388 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582389 // web_ui might be NULL if the URL refers to a non-existent extension.
2390 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402391 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522392 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442393 }
2394 }
[email protected]1fd1a502011-03-30 16:55:562395 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442396 }
2397
[email protected]4e697b042011-07-08 06:44:562398 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322399 // Clear the status bubble. This is a workaround for a bug where WebKit
2400 // doesn't let us know that the cursor left an element during a
2401 // transition (this is also why the mouse cursor remains as a hand after
2402 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2403 // clear the bubble when a user navigates to a named anchor in the same
2404 // page.
[email protected]36fc0392011-12-25 03:59:512405 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322406 }
2407
[email protected]a6e82fc2010-02-24 22:28:142408 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472409 // Once the main frame is navigated, we're no longer considered to have
2410 // displayed insecure content.
2411 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172412 }
[email protected]ce5c4502009-05-06 16:46:112413
[email protected]3c9e1872010-11-18 16:17:492414 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252415 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042416 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322417}
2418
[email protected]b172aee2012-04-10 17:05:262419void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322420 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212421 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322422 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062423 // If we navigate off the page, reset JavaScript state. This does nothing
2424 // to prevent a malicious script from spamming messages, since the script
2425 // could just reload the page to stop blocking.
2426 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552427 dialog_creator_->ResetJavaScriptState(this);
2428 dialog_creator_ = NULL;
2429 }
[email protected]420ae012009-04-24 05:16:322430
[email protected]3c9e1872010-11-18 16:17:492431 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252432 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042433 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322434}
2435
[email protected]b172aee2012-04-10 17:05:262436void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462437 // If we are creating a RVH for a restored controller, then we need to make
2438 // sure the RenderView starts with a next_page_id_ larger than the number
2439 // of restored entries. This must be called before the RenderView starts
2440 // navigating (to avoid a race between the browser updating max_page_id and
2441 // the renderer updating next_page_id_). Because of this, we only call this
2442 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562443 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582444 if (max_restored_page_id >
2445 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2446 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2447 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322448}
2449
[email protected]b172aee2012-04-10 17:05:262450bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2451 const string16& title) {
[email protected]420ae012009-04-24 05:16:322452 // For file URLs without a title, use the pathname instead. In the case of a
2453 // synthesized title, we don't want the update to count toward the "one set
2454 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512455 string16 final_title;
[email protected]420ae012009-04-24 05:16:322456 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512457 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2458 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322459 explicit_set = false; // Don't count synthetic titles toward the set limit.
2460 } else {
[email protected]acafd272011-07-26 17:35:572461 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322462 explicit_set = true;
2463 }
2464
[email protected]987fc3a2011-05-26 14:18:092465 // If a page is created via window.open and never navigated,
2466 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552467 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092468 if (entry) {
[email protected]36fc0392011-12-25 03:59:512469 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092470 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322471
[email protected]36fc0392011-12-25 03:59:512472 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092473 } else {
2474 if (page_title_when_no_navigation_entry_ == final_title)
2475 return false; // Nothing changed, don't bother.
2476
2477 page_title_when_no_navigation_entry_ = final_title;
2478 }
[email protected]420ae012009-04-24 05:16:322479
[email protected]420ae012009-04-24 05:16:322480 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232481 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322482
[email protected]8ff00d72012-10-23 19:12:212483 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462484 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142485
[email protected]8ff00d72012-10-23 19:12:212486 NotificationService::current()->Notify(
2487 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2488 Source<WebContents>(this),
2489 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042490
[email protected]420ae012009-04-24 05:16:322491 return true;
2492}
2493
[email protected]b172aee2012-04-10 17:05:262494void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322495 // After sending out a swap notification, we need to send a disconnect
2496 // notification so that clients that pick up a pointer to |this| can NULL the
2497 // pointer. See Bug 1230284.
2498 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212499 NotificationService::current()->Notify(
2500 NOTIFICATION_WEB_CONTENTS_SWAPPED,
2501 Source<WebContents>(this),
2502 NotificationService::NoDetails());
[email protected]7a846df2012-09-20 19:17:392503
2504 // Ensure that the associated embedder gets cleared after a RenderViewHost
2505 // gets swapped, so we don't reuse the same embedder next time a
2506 // RenderViewHost is attached to this WebContents.
2507 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322508}
2509
[email protected]b172aee2012-04-10 17:05:262510void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322511 notify_disconnection_ = true;
[email protected]8ff00d72012-10-23 19:12:212512 NotificationService::current()->Notify(
2513 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2514 Source<WebContents>(this),
2515 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322519 if (!notify_disconnection_)
2520 return;
2521
2522 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212523 NotificationService::current()->Notify(
2524 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2525 Source<WebContents>(this),
2526 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322527}
2528
[email protected]5a3bdf52012-05-24 15:12:572529RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2530 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322531}
2532
[email protected]8d3347f2009-07-09 22:00:212533RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262534WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212535 return &render_manager_;
2536}
2537
[email protected]8ff00d72012-10-23 19:12:212538RendererPreferences WebContentsImpl::GetRendererPrefs(
2539 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462540 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512541}
2542
[email protected]b172aee2012-04-10 17:05:262543WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172544 return this;
2545}
2546
[email protected]b172aee2012-04-10 17:05:262547gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172548 if (delegate_)
2549 return delegate_->GetRootWindowResizerRect();
2550 return gfx::Rect();
2551}
2552
[email protected]7a846df2012-09-20 19:17:392553void WebContentsImpl::RemoveBrowserPluginEmbedder() {
2554 if (browser_plugin_embedder_.get())
2555 browser_plugin_embedder_.reset();
2556}
2557
[email protected]b172aee2012-04-10 17:05:262558void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442559 // Don't send notifications if we are just creating a swapped-out RVH for
2560 // the opener chain. These won't be used for view-source or WebUI, so it's
2561 // ok to return early.
2562 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2563 return;
2564
[email protected]8ff00d72012-10-23 19:12:212565 NotificationService::current()->Notify(
2566 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2567 Source<WebContents>(this),
2568 Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232569 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322570 if (!entry)
2571 return;
2572
2573 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352574 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562575 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582576 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322577
2578 if (entry->IsViewSourceMode()) {
2579 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182580 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582581 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322582 }
[email protected]0666aef2009-05-13 19:48:082583
[email protected]d487beefe2011-12-21 05:41:212584 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262585
2586 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252587 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322588}
2589
[email protected]b172aee2012-04-10 17:05:262590void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522591 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322592 // Don't notify the world, since this came from a renderer in the
2593 // background.
2594 return;
2595 }
2596
2597 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312598 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232599 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302600
2601 // Restore the focus to the tab (otherwise the focus will be on the top
2602 // window).
[email protected]484ae5912010-09-29 19:16:142603 if (was_crashed && !FocusLocationBarByDefault() &&
2604 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302605 Focus();
[email protected]484ae5912010-09-29 19:16:142606 }
[email protected]32ded2212011-11-10 18:51:432607
[email protected]d8c660432011-12-22 20:51:252608 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322609}
2610
[email protected]b172aee2012-04-10 17:05:262611void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2612 base::TerminationStatus status,
2613 int error_code) {
[email protected]151a63d2011-12-20 22:32:522614 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322615 // The pending page's RenderViewHost is gone.
2616 return;
2617 }
2618
2619 SetIsLoading(false, NULL);
2620 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232621 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312622 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322623
[email protected]d8c660432011-12-22 20:51:252624 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272625 observers_,
[email protected]be1f56ab2011-12-22 06:55:312626 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322627}
2628
[email protected]b172aee2012-04-10 17:05:262629void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482630 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252631 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062632}
2633
[email protected]b172aee2012-04-10 17:05:262634void WebContentsImpl::DidNavigate(
2635 RenderViewHost* rvh,
2636 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8ff00d72012-10-23 19:12:212637 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322638 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372639
[email protected]434f69f2012-02-06 21:56:522640 // Update the site of the SiteInstance if it doesn't have one yet, unless
2641 // this is for about:blank. In that case, the SiteInstance can still be
2642 // considered unused until a navigation to a real page.
2643 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2644 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332645 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522646 }
[email protected]420ae012009-04-24 05:16:322647
2648 // Need to update MIME type here because it's referred to in
2649 // UpdateNavigationCommands() called by RendererDidNavigate() to
2650 // determine whether or not to enable the encoding menu.
2651 // It's updated only for the main frame. For a subframe,
2652 // RenderView::UpdateURL does not set params.contents_mime_type.
2653 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2654 // TODO(jungshik): Add a test for the encoding menu to avoid
2655 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212656 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322657 contents_mime_type_ = params.contents_mime_type;
2658
[email protected]8ff00d72012-10-23 19:12:212659 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002660 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392661
[email protected]a9c0bfe2010-09-17 08:35:222662 // Send notification about committed provisional loads. This notification is
2663 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2664 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212665 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072666 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2667 // that is not recorded in the navigation history. For the purpose of
2668 // tracking navigation events, we treat this event as a sub frame navigation
2669 // event.
2670 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212671 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222672 // Whether or not a page transition was triggered by going backward or
2673 // forward in the history is only stored in the navigation controller's
2674 // entry list.
2675 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512676 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212677 PAGE_TRANSITION_FORWARD_BACK)) {
2678 transition_type = PageTransitionFromInt(
2679 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222680 }
[email protected]0d60f0192011-04-14 12:40:102681 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252682 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102683 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462684 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222685 }
2686
[email protected]76543b92009-08-31 17:27:452687 if (!did_navigate)
2688 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322689
2690 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2691 // for the appropriate notification (best) or you can add it to
2692 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2693 // necessary, please).
2694
2695 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002696 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322697 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512698 if (delegate_)
2699 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002700 }
[email protected]420ae012009-04-24 05:16:322701 DidNavigateAnyFramePostCommit(rvh, details, params);
2702}
2703
[email protected]b172aee2012-04-10 17:05:262704void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2705 int32 page_id,
2706 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152707 // Ensure that this state update comes from either the active RVH or one of
2708 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522709 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322710
2711 // We must be prepared to handle state updates for any page, these occur
2712 // when the user is scrolling and entering form data, as well as when we're
2713 // leaving a page, in which case our state may have already been moved to
2714 // the next page. The navigation controller will look up the appropriate
2715 // NavigationEntry and update it when it is notified via the delegate.
2716
2717 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582718 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322719 if (entry_index < 0)
2720 return;
[email protected]10f417c52011-12-28 21:04:232721 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322722
[email protected]36fc0392011-12-25 03:59:512723 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322724 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512725 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322726 controller_.NotifyEntryChanged(entry, entry_index);
2727}
2728
[email protected]b172aee2012-04-10 17:05:262729void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2730 int32 page_id,
2731 const string16& title,
2732 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322733 // If we have a title, that's a pretty good indication that we've started
2734 // getting useful data.
2735 SetNotWaitingForResponse();
2736
[email protected]73eb2602012-02-09 19:50:552737 // Try to find the navigation entry, which might not be the current one.
2738 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232739 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582740 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092741
[email protected]73eb2602012-02-09 19:50:552742 // We can handle title updates when we don't have an entry in
2743 // UpdateTitleForEntry, but only if the update is from the current RVH.
2744 if (!entry && rvh != GetRenderViewHost())
2745 return;
2746
[email protected]a49e10b2011-08-01 23:57:462747 // TODO(evan): make use of title_direction.
2748 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092749 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322750 return;
2751
2752 // Broadcast notifications when the UI should be updated.
2753 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212754 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322755}
2756
[email protected]b172aee2012-04-10 17:05:262757void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2758 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312759 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322760}
2761
[email protected]b172aee2012-04-10 17:05:262762void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512763 if (delegate_)
2764 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322765}
2766
[email protected]b172aee2012-04-10 17:05:262767void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292768 // The UI may be in an event-tracking loop, such as between the
2769 // mouse-down and mouse-up in text selection or a button click.
2770 // Defer the close until after tracking is complete, so that we
2771 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292772 // TODO(shess): This could get more fine-grained. For instance,
2773 // closing a tab in another window while selecting text in the
2774 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212775 if (GetView()->IsEventTracking()) {
2776 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292777 return;
2778 }
2779
[email protected]420ae012009-04-24 05:16:322780 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522781 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512782 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322783}
2784
[email protected]b172aee2012-04-10 17:05:262785void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522786 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512787 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572788}
2789
[email protected]b172aee2012-04-10 17:05:262790void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512791 if (delegate_ && delegate_->IsPopupOrPanel(this))
2792 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322793}
2794
[email protected]8ff00d72012-10-23 19:12:212795void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322796 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492797
[email protected]82114f52012-03-20 22:53:412798 if (delegate_ && content_restrictions_)
2799 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492800
2801 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2803 DidStartLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322804}
2805
[email protected]8ff00d72012-10-23 19:12:212806void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322807 scoped_ptr<LoadNotificationDetails> details;
2808
[email protected]10f417c52011-12-28 21:04:232809 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322810 // An entry may not exist for a stop when loading an initial blank page or
2811 // if an iframe injected by script into a blank page finishes loading.
2812 if (entry) {
[email protected]420ae012009-04-24 05:16:322813 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2814
2815 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512816 entry->GetVirtualURL(),
2817 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322818 elapsed,
2819 &controller_,
2820 controller_.GetCurrentEntryIndex()));
2821 }
2822
[email protected]420ae012009-04-24 05:16:322823 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492824
2825 // Notify observers about navigation.
[email protected]89793072012-07-23 22:25:292826 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2827 DidStopLoading(render_view_host));
[email protected]420ae012009-04-24 05:16:322828}
2829
[email protected]b172aee2012-04-10 17:05:262830void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162831 controller_.DiscardNonCommittedEntries();
2832
2833 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212834 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162835}
2836
[email protected]b172aee2012-04-10 17:05:262837void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]8e603cd92012-10-23 22:29:262838#if defined(OS_ANDROID)
[email protected]6934a702011-12-20 00:04:512839 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132840 delegate_->LoadProgressChanged(this, progress);
[email protected]8e603cd92012-10-23 22:29:262841#endif
[email protected]1a3c3cb2010-12-16 21:03:402842}
2843
[email protected]0720b532012-08-28 19:23:372844void WebContentsImpl::DidUpdateFrameTree(RenderViewHost* rvh) {
2845 render_manager_.DidUpdateFrameTree(rvh);
2846}
2847
[email protected]87717d0e2012-04-26 02:58:432848void WebContentsImpl::DocumentAvailableInMainFrame(
2849 RenderViewHost* render_view_host) {
2850 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2851 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102852}
2853
[email protected]b172aee2012-04-10 17:05:262854void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082855 RenderViewHost* render_view_host,
2856 int32 page_id) {
[email protected]8ff00d72012-10-23 19:12:212857 NotificationService::current()->Notify(
2858 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
2859 Source<WebContents>(this),
2860 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082861}
2862
[email protected]196159d2012-05-04 17:26:542863void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2864 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212865 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262866 WindowOpenDisposition disposition,
2867 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542868 // If this came from a swapped out RenderViewHost, we only allow the request
2869 // if we are still in the same BrowsingInstance.
2870 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2871 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2872 return;
2873 }
2874
[email protected]4ad5d77d2011-12-03 02:00:482875 // Delegate to RequestTransferURL because this is just the generic
2876 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582877 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482878 GlobalRequestID());
2879}
2880
[email protected]b172aee2012-04-10 17:05:262881void WebContentsImpl::RequestTransferURL(
2882 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:212883 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262884 WindowOpenDisposition disposition,
2885 int64 source_frame_id,
2886 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202887 WebContents* new_contents = NULL;
[email protected]8ff00d72012-10-23 19:12:212888 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582889 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352890 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322891 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2892 // generated suggestions).
2893 //
[email protected]e0112912011-02-02 22:54:352894 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162895 // want web sites to see a referrer of "chrome://blah" (and some
2896 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322897 // send to the site), so we send no referrer.
[email protected]8ff00d72012-10-23 19:12:212898 OpenURLParams params(url, Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222899 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482900 false /* is_renderer_initiated */);
2901 params.transferred_global_request_id = old_request_id;
2902 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222903 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322904 } else {
[email protected]6bf6a6b52012-02-03 15:41:432905 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]8ff00d72012-10-23 19:12:212906 PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
[email protected]4ad5d77d2011-12-03 02:00:482907 params.transferred_global_request_id = old_request_id;
2908 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582909 }
2910 if (new_contents) {
2911 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252912 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582913 DidOpenRequestedURL(new_contents,
2914 url,
2915 referrer,
2916 disposition,
2917 transition_type,
2918 source_frame_id));
[email protected]420ae012009-04-24 05:16:322919 }
2920}
2921
[email protected]e1c3a552012-05-04 20:51:322922void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2923 // Tell the active RenderViewHost to run unload handlers and close, as long
2924 // as the request came from a RenderViewHost in the same BrowsingInstance.
2925 // In most cases, we receive this from a swapped out RenderViewHost.
2926 // It is possible to receive it from one that has just been swapped in,
2927 // in which case we might as well deliver the message anyway.
2928 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2929 GetRenderViewHost()->ClosePage();
2930}
2931
[email protected]f546640b2012-05-15 00:03:492932void WebContentsImpl::RouteMessageEvent(
2933 RenderViewHost* rvh,
2934 const ViewMsg_PostMessage_Params& params) {
2935 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:362936 // came from a RenderViewHost in the same BrowsingInstance or if this
2937 // WebContents is dedicated to a browser plugin guest.
2938 // Note: This check means that an embedder could theoretically receive a
2939 // postMessage from anyone (not just its own guests). However, this is
2940 // probably not a risk for apps since other pages won't have references
2941 // to App windows.
2942 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
2943 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:492944 return;
2945
2946 ViewMsg_PostMessage_Params new_params(params);
2947
[email protected]0720b532012-08-28 19:23:372948 // If the renderer has changed while the post message is being routed,
2949 // drop the message, as it will not be delivered to the right target.
[email protected]e12dbe6f2012-10-04 22:11:192950 // TODO(nasko): Check for process ID and target frame id mismatch, once
2951 // http://crbug.com/153701 is fixed.
[email protected]0720b532012-08-28 19:23:372952
[email protected]f546640b2012-05-15 00:03:492953 // If there is a source_routing_id, translate it to the routing ID for
2954 // the equivalent swapped out RVH in the target process. If we need
2955 // to create a swapped out RVH for the source tab, we create its opener
2956 // chain as well, since those will also be accessible to the target page.
2957 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2958 // Try to look up the WebContents for the source page.
2959 WebContentsImpl* source_contents = NULL;
2960 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2961 rvh->GetProcess()->GetID(), params.source_routing_id);
2962 if (source_rvh) {
2963 source_contents = static_cast<WebContentsImpl*>(
2964 source_rvh->GetDelegate()->GetAsWebContents());
2965 }
2966
2967 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:362968 if (GetBrowserPluginGuest()) {
2969 // We create a swapped out RenderView for the embedder in the guest's
2970 // render process but we intentionally do not expose the embedder's
2971 // opener chain to it.
2972 new_params.source_routing_id =
2973 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
2974 } else {
2975 new_params.source_routing_id =
2976 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2977 }
[email protected]f546640b2012-05-15 00:03:492978 } else {
2979 // We couldn't find it, so don't pass a source frame.
2980 new_params.source_routing_id = MSG_ROUTING_NONE;
2981 }
2982 }
2983
2984 // In most cases, we receive this from a swapped out RenderViewHost.
2985 // It is possible to receive it from one that has just been swapped in,
2986 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:182987 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:492988}
2989
[email protected]b172aee2012-04-10 17:05:262990void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342991 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412992 const string16& message,
2993 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322994 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:212995 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322996 IPC::Message* reply_msg,
2997 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072998 // Suppress JavaScript dialogs when requested. Also suppress messages when
2999 // showing an interstitial as it's shown over the previous page and we don't
3000 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503001 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583002 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273003 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073004 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523005 delegate_->ShouldSuppressDialogs() ||
3006 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:323007
3008 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213009 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433010 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:553011 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523012 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433013 this,
3014 frame_url.GetOrigin(),
3015 accept_lang,
3016 javascript_message_type,
3017 message,
[email protected]51da7e32012-01-30 19:24:523018 default_prompt,
[email protected]b172aee2012-04-10 17:05:263019 base::Bind(&WebContentsImpl::OnDialogClosed,
3020 base::Unretained(this),
3021 rvh,
3022 reply_msg),
[email protected]51da7e32012-01-30 19:24:523023 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323024 }
[email protected]3ab9cb82011-06-03 18:02:073025
3026 if (suppress_this_message) {
3027 // If we are suppressing messages, just reply as if the user immediately
3028 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343029 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073030 }
3031
3032 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:323033}
3034
[email protected]b172aee2012-04-10 17:05:263035void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3036 const string16& message,
3037 bool is_reload,
3038 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583039 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513040 if (delegate_)
3041 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073042
3043 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583044 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073045 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523046 delegate_->ShouldSuppressDialogs() ||
3047 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:153048 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343049 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583050 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503051 return;
3052 }
[email protected]3ab9cb82011-06-03 18:02:073053
[email protected]7ab1e7d62009-10-14 23:32:013054 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:553055 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:523056 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323057 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263058 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523059 reply_msg));
[email protected]420ae012009-04-24 05:16:323060}
3061
[email protected]a796f202012-05-30 14:14:253062bool WebContentsImpl::AddMessageToConsole(int32 level,
3063 const string16& message,
3064 int32 line_no,
3065 const string16& source_id) {
3066 if (!delegate_)
3067 return false;
3068 return delegate_->AddMessageToConsole(this, level, message, line_no,
3069 source_id);
3070}
3071
[email protected]b172aee2012-04-10 17:05:263072WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:333073 // We want to base the page config off of the real URL, rather than the
3074 // display URL.
3075 GURL url = controller_.GetActiveEntry()
3076 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
3077 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:323078}
3079
[email protected]0eba810b2012-10-18 03:19:363080int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213081 SiteInstance* instance) {
[email protected]0eba810b2012-10-18 03:19:363082 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE, true);
3083}
3084
[email protected]b172aee2012-04-10 17:05:263085void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273086 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253087 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223088
[email protected]ea114722012-03-12 01:11:253089 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173090 if (rdh) // NULL in unittests.
3091 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253092}
3093
[email protected]b172aee2012-04-10 17:05:263094void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443095 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253096 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443097}
3098
[email protected]b172aee2012-04-10 17:05:263099void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
3100 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153101 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523102 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153103 return;
3104
[email protected]9f76c1e2012-03-05 15:15:583105 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3106
[email protected]e5fc1632011-08-08 07:51:533107 // Ignore renderer unresponsive event if debugger is attached to the tab
3108 // since the event may be a result of the renderer sitting on a breakpoint.
3109 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:443110 DevToolsAgentHost* agent =
[email protected]8ff00d72012-10-23 19:12:213111 DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
[email protected]0e12d7d2011-12-01 16:21:443112 if (agent &&
3113 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:533114 return;
3115
[email protected]420ae012009-04-24 05:16:323116 if (is_during_unload) {
3117 // Hang occurred while firing the beforeunload/unload handler.
3118 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583119 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323120
3121 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3122 return;
3123
3124 // If the tab hangs in the beforeunload/unload handler there's really
3125 // nothing we can do to recover. Pretend the unload listeners have
3126 // all fired and close the tab. If the hang is in the beforeunload handler
3127 // then the user will not have the option of cancelling the close.
3128 Close(rvh);
3129 return;
3130 }
3131
[email protected]9f76c1e2012-03-05 15:15:583132 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473133 return;
3134
[email protected]6934a702011-12-20 00:04:513135 if (delegate_)
3136 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323137}
3138
[email protected]b172aee2012-04-10 17:05:263139void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513140 if (delegate_)
3141 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323142}
3143
[email protected]b172aee2012-04-10 17:05:263144void WebContentsImpl::LoadStateChanged(
3145 const GURL& url,
3146 const net::LoadStateWithParam& load_state,
3147 uint64 upload_position,
3148 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323149 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563150 upload_position_ = upload_position;
3151 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503152 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213153 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303154 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213155 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323156 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463157 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213158 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463159 }
[email protected]420ae012009-04-24 05:16:323160}
3161
[email protected]b172aee2012-04-10 17:05:263162void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513163 if (delegate_)
3164 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253165}
3166
[email protected]b172aee2012-04-10 17:05:263167void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553168 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323169 bool* proceed_to_fire_unload) {
[email protected]feaded02012-09-25 19:12:553170 before_unload_end_time_ = proceed_time;
[email protected]6934a702011-12-20 00:04:513171 if (delegate_)
3172 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:323173}
3174
[email protected]b172aee2012-04-10 17:05:263175void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543176 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233177 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3178 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543179}
3180
[email protected]b172aee2012-04-10 17:05:263181void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103182 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263183 gfx::Size size = view_->GetContainerSize();
3184 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3185 // here during container initialization and normal window size will be set
3186 // later. In case of tab duplication this resizing to 0x0 prevents setting
3187 // normal size later so just ignore it.
3188 if (!size.IsEmpty())
3189 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323190}
3191
[email protected]b172aee2012-04-10 17:05:263192void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:543193 NotifySwapped();
3194}
3195
[email protected]14392a52012-05-02 20:28:443196int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3197 SiteInstance* instance) {
3198 if (!opener_)
3199 return MSG_ROUTING_NONE;
3200
3201 // Recursively create RenderViews for anything else in the opener chain.
3202 return opener_->CreateOpenerRenderViews(instance);
3203}
3204
3205int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3206 int opener_route_id = MSG_ROUTING_NONE;
3207
3208 // If this tab has an opener, ensure it has a RenderView in the given
3209 // SiteInstance as well.
3210 if (opener_)
3211 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3212
[email protected]0720b532012-08-28 19:23:373213 // If any of the renderers for this WebContents has the same SiteInstance,
3214 // use it.
3215 if (render_manager_.current_host()->GetSiteInstance() == instance)
3216 return render_manager_.current_host()->GetRoutingID();
3217
3218 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3219 instance);
3220 if (rvh)
3221 return rvh->GetRoutingID();
3222
[email protected]14392a52012-05-02 20:28:443223 // Create a swapped out RenderView in the given SiteInstance if none exists,
3224 // setting its opener to the given route_id. Return the new view's route_id.
3225 return render_manager_.CreateRenderView(instance, opener_route_id, true);
3226}
3227
[email protected]b172aee2012-04-10 17:05:263228NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193229 return GetController();
[email protected]3a3d47472010-07-15 21:03:543230}
3231
[email protected]b172aee2012-04-10 17:05:263232WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563233 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323234}
3235
[email protected]10f417c52011-12-28 21:04:233236NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263237 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323238 return controller_.GetLastCommittedEntry();
3239}
3240
[email protected]b172aee2012-04-10 17:05:263241bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443242 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:443243 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323244 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523245
[email protected]420ae012009-04-24 05:16:323246 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443247 if (rwh_view)
3248 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:323249
[email protected]74ce1ad2011-12-16 21:51:463250 // Make sure we use the correct starting page_id in the new RenderView.
3251 UpdateMaxPageIDIfNecessary(render_view_host);
3252 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583253 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463254
[email protected]9f76c1e2012-03-05 15:15:583255 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493256 render_view_host)->CreateRenderView(string16(),
3257 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133258 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523259 return false;
[email protected]14392a52012-05-02 20:28:443260 }
[email protected]a4127722011-04-27 23:13:523261
[email protected]e60c0232011-11-11 19:56:353262#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503263 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3264 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443265 if (rwh_view) {
3266 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3267 render_widget_host->WasResized();
3268 }
[email protected]f8233cc2011-05-31 20:24:503269#endif
3270
[email protected]420ae012009-04-24 05:16:323271 return true;
3272}
3273
[email protected]b172aee2012-04-10 17:05:263274void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3275 IPC::Message* reply_msg,
3276 bool success,
3277 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543278 if (is_showing_before_unload_dialog_ && !success) {
3279 // If a beforeunload dialog is canceled, we need to stop the throbber from
3280 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293281 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353282 controller_.DiscardNonCommittedEntries();
[email protected]beb440c2009-11-06 04:08:543283
[email protected]3bbacc5b2012-04-17 17:46:153284 close_start_time_ = base::TimeTicks();
[email protected]feaded02012-09-25 19:12:553285 before_unload_end_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543286 }
3287 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583288 static_cast<RenderViewHostImpl*>(
3289 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543290}
3291
[email protected]b172aee2012-04-10 17:05:263292void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213293 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123294 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103295}
[email protected]f45d2a72010-03-08 23:28:353296
[email protected]b172aee2012-04-10 17:05:263297void WebContentsImpl::SaveURL(const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213298 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263299 bool is_main_frame) {
[email protected]b441a8492012-06-06 14:55:573300 DownloadManager* dlm =
3301 BrowserContext::GetDownloadManager(GetBrowserContext());
[email protected]27678b2a2012-02-04 22:09:143302 if (!dlm)
3303 return;
3304 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263305 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143306 const NavigationEntry* entry = controller_.GetActiveEntry();
3307 if (entry)
3308 post_id = entry->GetPostID();
3309 }
[email protected]8ff00d72012-10-23 19:12:213310 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo());
[email protected]c873c862012-10-17 15:32:123311 save_info->prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143312 scoped_ptr<DownloadUrlParameters> params(
[email protected]c873c862012-10-17 15:32:123313 DownloadUrlParameters::FromWebContents(this, url, save_info.Pass()));
[email protected]f859eba2012-05-30 17:22:493314 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143315 params->set_post_id(post_id);
3316 params->set_prefer_cache(true);
3317 if (post_id >= 0)
3318 params->set_method("POST");
3319 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143320}
3321
[email protected]b172aee2012-04-10 17:05:263322void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213323 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443324 // Can be NULL during tests.
3325 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213326 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363327}
[email protected]9f76c1e2012-03-05 15:15:583328
[email protected]b172aee2012-04-10 17:05:263329RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583330 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3331}
[email protected]7900bfdb2012-05-24 19:31:243332
[email protected]8ff00d72012-10-23 19:12:213333BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() {
[email protected]7a846df2012-09-20 19:17:393334 return browser_plugin_guest_.get();
3335}
3336
[email protected]8ff00d72012-10-23 19:12:213337BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() {
[email protected]7a846df2012-09-20 19:17:393338 return browser_plugin_embedder_.get();
3339}
[email protected]8ff00d72012-10-23 19:12:213340
3341} // namespace content