blob: fb924c8a72df9ab753e4e55276a9317ad4e2d475 [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]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]8dd709fb2012-04-06 00:49:0617#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2531#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3733#include "content/browser/web_contents/interstitial_page_impl.h"
34#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5635#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5137#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0238#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5839#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2041#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1445#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4646#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1547#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2748#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0049#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4850#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3251#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3852#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4253#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2554#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1055#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5056#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2157#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4858#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1859#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5460#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0361#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1662#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2963#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5464#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3465#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3766#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]d353541f2012-05-03 22:45:4167#include "ui/base/ui_base_switches.h"
68#include "ui/gfx/monitor.h"
69#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2470#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3171#include "webkit/glue/webpreferences.h"
72
[email protected]68b52252012-04-04 19:26:1373#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:3574#include "content/browser/web_contents/web_contents_view_aura.h"
[email protected]68b52252012-04-04 19:26:1375#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:3576#include "content/browser/web_contents/web_contents_view_win.h"
[email protected]38b098f2012-03-14 21:11:5777#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:3578#include "content/browser/web_contents/web_contents_view_gtk.h"
[email protected]38b098f2012-03-14 21:11:5779#elif defined(OS_MACOSX)
[email protected]0c4e92e62012-04-11 15:19:0080#include "content/browser/web_contents/web_contents_view_mac.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5782#elif defined(OS_ANDROID)
[email protected]0c4e92e62012-04-11 15:19:0083#include "content/browser/web_contents/web_contents_view_android.h"
[email protected]38b098f2012-03-14 21:11:5784#endif
[email protected]3e45ba92009-02-20 21:09:0085
[email protected]420ae012009-04-24 05:16:3286// Cross-Site Navigations
87//
[email protected]b172aee2012-04-10 17:05:2688// If a WebContentsImpl is told to navigate to a different web site (as
89// determined by SiteInstance), it will replace its current RenderViewHost with
90// a new RenderViewHost dedicated to the new SiteInstance. This works as
91// follows:
[email protected]420ae012009-04-24 05:16:3292//
93// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4694// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3295// - The pending RVH is "suspended," so that no navigation messages are sent to
96// its renderer until the onbeforeunload JavaScript handler has a chance to
97// run in the current RVH.
98// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
99// that it has a pending cross-site request. ResourceDispatcherHost will
100// check for this when the response arrives.
101// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46102// cancel all the pending logic. Otherwise we allow the pending RVH to send
103// the navigation request to its renderer.
104// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
105// main resource load on the pending RVH. It checks CrossSiteRequestManager
106// to see that it is a cross-site request, and installs a
107// CrossSiteResourceHandler.
108// - When RDH receives a response, the BufferedResourceHandler determines
109// whether it is a download. If so, it sends a message to the new renderer
110// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26111// pending RVH remains until the next DidNavigate event for this
112// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32113// - After RDH receives a response and determines that it is safe and not a
114// download, it pauses the response to first run the old page's onunload
115// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26116// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32117// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15118// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32119// the ResourceDispatcherHost, who unpauses the response. Data is then sent
120// to the pending RVH.
121// - The pending renderer sends a FrameNavigate message that invokes the
122// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46123// pending RVH.
[email protected]992db4c2011-05-12 15:37:15124// - The previous renderer is kept swapped out in RenderViewHostManager in case
125// the user goes back. The process only stays live if another tab is using
126// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32127
[email protected]0e12d7d2011-12-01 16:21:44128using content::DevToolsAgentHost;
129using content::DevToolsAgentHostRegistry;
130using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17131using content::DownloadItem;
132using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14133using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20134using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56135using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13136using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27137using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50138using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23139using content::NavigationEntry;
140using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20141using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11142using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57143using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27144using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11145using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58146using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04147using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25148using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14149using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43150using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33151using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38152using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09153using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25154using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56155using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22156using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50157using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25158using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44159
[email protected]420ae012009-04-24 05:16:32160namespace {
161
162// Amount of time we wait between when a key event is received and the renderer
163// is queried for its state and pushed to the NavigationEntry.
164const int kQueryStateDelay = 5000;
165
[email protected]6ebdc9b2010-09-27 16:55:57166const int kSyncWaitDelay = 40;
167
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]420ae012009-04-24 05:16:32170#if defined(OS_WIN)
171
172BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
173 // Note: erase is required to properly paint some widgets borders. This can
174 // be seen with textfields.
175 InvalidateRect(hwnd, NULL, TRUE);
176 return TRUE;
177}
178#endif
179
[email protected]2c5569662011-03-22 20:45:02180ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23181 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50182 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16183 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47184 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47186 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16189 break; // Fall through to rest of function.
190 }
[email protected]5e369672009-11-03 23:48:30191
[email protected]59246c572012-02-10 13:32:13192 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
193 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23194 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13195 browser_context->DidLastSessionExitCleanly()) {
196 if (entry.GetHasPostData())
197 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13199 }
[email protected]5e369672009-11-03 23:48:30200
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30202}
203
[email protected]10f417c52011-12-28 21:04:23204void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47205 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42206 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50207 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16208 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51209 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54210 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55211 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
212 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51213 params->url = entry.GetURL();
214 params->referrer = entry.GetReferrer();
215 params->transition = entry.GetTransitionType();
216 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00217 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55218 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34219 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47220 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48221 params->transferred_request_child_id =
222 entry.transferred_global_request_id().child_id;
223 params->transferred_request_request_id =
224 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00225 // Avoid downloading when in view-source mode.
226 params->allow_download = !entry.IsViewSourceMode();
[email protected]6c6b02d2011-09-02 03:36:47227
228 if (delegate)
229 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34230}
231
[email protected]420ae012009-04-24 05:16:32232} // namespace
233
[email protected]a81343d232011-12-27 07:39:20234namespace content {
235
236WebContents* WebContents::Create(
237 BrowserContext* browser_context,
238 SiteInstance* site_instance,
239 int routing_id,
[email protected]b172aee2012-04-10 17:05:26240 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20241 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26242 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43243 browser_context,
244 site_instance,
245 routing_id,
[email protected]b172aee2012-04-10 17:05:26246 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44247 NULL,
[email protected]adbfb8df2012-02-24 01:19:43248 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20249}
250}
[email protected]f4f50ef2011-01-21 19:01:19251
[email protected]b172aee2012-04-10 17:05:26252// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32253
[email protected]b172aee2012-04-10 17:05:26254WebContentsImpl::WebContentsImpl(
255 content::BrowserContext* browser_context,
256 SiteInstance* site_instance,
257 int routing_id,
258 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44259 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26260 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42261 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07262 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37263 this, browser_context, session_storage_namespace)),
[email protected]14392a52012-05-02 20:28:44264 opener_(opener),
[email protected]d82ed61e2009-06-16 02:46:22265 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34266 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23267 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
268 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34269 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21270 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56271 upload_size_(0),
272 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47273 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57274 capturing_contents_(false),
275 is_being_destroyed_(false),
276 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55277 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57278#if defined(OS_WIN)
279 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
280#endif
[email protected]7ab1e7d62009-10-14 23:32:01281 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56282 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38283 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25284 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01285 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25286 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01287 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00288 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43289 content_restrictions_(0),
[email protected]c8160f22012-05-14 06:44:03290 view_type_(content::VIEW_TYPE_INVALID),
[email protected]da8543762012-03-20 08:52:20291 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37292 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32293
[email protected]38b098f2012-03-14 21:11:57294 view_.reset(content::GetContentClient()->browser()->
295 OverrideCreateWebContentsView(this));
296 if (!view_.get()) {
297 content::WebContentsViewDelegate* delegate =
298 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
299 this);
[email protected]68b52252012-04-04 19:26:13300#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:35301 view_.reset(new WebContentsViewAura(this, delegate));
[email protected]68b52252012-04-04 19:26:13302#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:35303 view_.reset(new WebContentsViewWin(this, delegate));
[email protected]38b098f2012-03-14 21:11:57304#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:35305 view_.reset(new content::WebContentsViewGtk(this, delegate));
[email protected]38b098f2012-03-14 21:11:57306#elif defined(OS_MACOSX)
307 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
308#elif defined(OS_ANDROID)
309 view_.reset(new WebContentsViewAndroid(this));
310#endif
[email protected]dbd407f2012-03-14 21:30:37311 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57312 }
313 CHECK(view_.get());
314
[email protected]ca13a442012-04-17 14:00:12315 // We have the initial size of the view be based on the size of the view of
316 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26317 view_->CreateView(base_web_contents ?
318 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00319
[email protected]14392a52012-05-02 20:28:44320 // Listen for whether our opener gets destroyed.
321 if (opener_) {
322 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
323 content::Source<WebContents>(opener_));
324 }
325
[email protected]483623eb2011-10-25 09:30:00326#if defined(ENABLE_JAVA_BRIDGE)
327 java_bridge_dispatcher_host_manager_.reset(
328 new JavaBridgeDispatcherHostManager(this));
329#endif
[email protected]8dd709fb2012-04-06 00:49:06330
331 browser_plugin_web_contents_observer_.reset(
332 new content::BrowserPluginWebContentsObserver(this));
[email protected]332af7732009-03-11 13:21:35333}
initial.commit09911bf2008-07-26 23:55:29334
[email protected]b172aee2012-04-10 17:05:26335WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32336 is_being_destroyed_ = true;
337
[email protected]3ab9cb82011-06-03 18:02:07338 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55339 if (dialog_creator_)
340 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07341
[email protected]da8543762012-03-20 08:52:20342 if (color_chooser_)
343 color_chooser_->End();
344
[email protected]420ae012009-04-24 05:16:32345 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32346
[email protected]ca13a442012-04-17 14:00:12347 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07348 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09349 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
350 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07351 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32352
353 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07354#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32355 // If we still have a window handle, destroy it. GetNativeView can return
356 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42357 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52358 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58359 if (host && host->GetView())
360 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42361 }
[email protected]420ae012009-04-24 05:16:32362#endif
[email protected]7ab1e7d62009-10-14 23:32:01363
364 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15365 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01366 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15367 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01368 }
[email protected]b5a1d11c2011-02-17 03:09:42369
[email protected]2db9bd72012-04-13 20:20:56370 FOR_EACH_OBSERVER(WebContentsObserver,
371 observers_,
372 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08373
[email protected]6934a702011-12-20 00:04:51374 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42375}
376
[email protected]b172aee2012-04-10 17:05:26377WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
378 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54379 WebPreferences prefs;
380
381 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
382
383 prefs.developer_extras_enabled = true;
384 prefs.javascript_enabled =
385 !command_line.HasSwitch(switches::kDisableJavaScript);
386 prefs.web_security_enabled =
387 !command_line.HasSwitch(switches::kDisableWebSecurity);
388 prefs.plugins_enabled =
389 !command_line.HasSwitch(switches::kDisablePlugins);
390 prefs.java_enabled =
391 !command_line.HasSwitch(switches::kDisableJava);
392
393 prefs.uses_page_cache =
394 command_line.HasSwitch(switches::kEnableFastback);
395 prefs.remote_fonts_enabled =
396 !command_line.HasSwitch(switches::kDisableRemoteFonts);
397 prefs.xss_auditor_enabled =
398 !command_line.HasSwitch(switches::kDisableXSSAuditor);
399 prefs.application_cache_enabled =
400 !command_line.HasSwitch(switches::kDisableApplicationCache);
401
402 prefs.local_storage_enabled =
403 !command_line.HasSwitch(switches::kDisableLocalStorage);
404 prefs.databases_enabled =
405 !command_line.HasSwitch(switches::kDisableDatabases);
406 prefs.webaudio_enabled =
407 !command_line.HasSwitch(switches::kDisableWebAudio);
408
409 prefs.experimental_webgl_enabled =
410 GpuProcessHost::gpu_enabled() &&
411 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
412 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
413
414 prefs.gl_multisampling_enabled =
415 !command_line.HasSwitch(switches::kDisableGLMultisampling);
416 prefs.privileged_webgl_extensions_enabled =
417 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
418 prefs.site_specific_quirks_enabled =
419 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
420 prefs.allow_file_access_from_file_urls =
421 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
422 prefs.show_composited_layer_borders =
423 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
424 prefs.show_composited_layer_tree =
425 command_line.HasSwitch(switches::kShowCompositedLayerTree);
426 prefs.show_fps_counter =
427 command_line.HasSwitch(switches::kShowFPSCounter);
428 prefs.accelerated_compositing_enabled =
429 GpuProcessHost::gpu_enabled() &&
430 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54431 prefs.force_compositing_mode =
432 command_line.HasSwitch(switches::kForceCompositingMode);
433 prefs.fixed_position_compositing_enabled =
434 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
435 prefs.accelerated_2d_canvas_enabled =
436 GpuProcessHost::gpu_enabled() &&
437 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58438 prefs.deferred_2d_canvas_enabled =
439 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36440 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31441 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54442 prefs.accelerated_painting_enabled =
443 GpuProcessHost::gpu_enabled() &&
444 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
445 prefs.accelerated_filters_enabled =
446 GpuProcessHost::gpu_enabled() &&
447 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
448 prefs.accelerated_layers_enabled =
449 prefs.accelerated_animation_enabled =
450 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54451 prefs.accelerated_plugins_enabled =
452 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
453 prefs.accelerated_video_enabled =
454 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
455 prefs.partial_swap_enabled =
456 command_line.HasSwitch(switches::kEnablePartialSwap);
457 prefs.interactive_form_validation_enabled =
458 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
459 prefs.fullscreen_enabled =
460 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16461 prefs.css_regions_enabled =
462 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29463 prefs.css_shaders_enabled =
464 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54465
466#if defined(OS_MACOSX)
467 bool default_enable_scroll_animator = true;
468#else
469 // On CrOS, the launcher always passes in the --enable flag.
470 bool default_enable_scroll_animator = false;
471#endif
472 prefs.enable_scroll_animator = default_enable_scroll_animator;
473 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
474 prefs.enable_scroll_animator = true;
475 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
476 prefs.enable_scroll_animator = false;
477
478 prefs.visual_word_movement_enabled =
479 command_line.HasSwitch(switches::kEnableVisualWordMovement);
480 prefs.per_tile_painting_enabled =
481 command_line.HasSwitch(switches::kEnablePerTilePainting);
482
483 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32484 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54485 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11486 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
487 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54488 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11489 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54490 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11491 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54492 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11493 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54494 prefs.gl_multisampling_enabled = false;
495
496 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45497 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32498 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54499 prefs.accelerated_video_enabled = false;
500 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45501 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09502 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54503 }
504 }
505
[email protected]b9535422012-02-09 01:47:59506 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58507 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54508 prefs.loads_images_automatically = true;
509 prefs.javascript_enabled = true;
510 }
511
512 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
513
514 // Force accelerated compositing and 2d canvas off for chrome:, about: and
515 // chrome-devtools: pages (unless it's specifically allowed).
516 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54517 url.SchemeIs(chrome::kChromeUIScheme) ||
518 (url.SchemeIs(chrome::kAboutScheme) &&
519 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25520 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54521 prefs.accelerated_compositing_enabled = false;
522 prefs.accelerated_2d_canvas_enabled = false;
523 }
[email protected]8b3b36152012-05-01 04:55:07524#if defined(OS_MACOSX)
525 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
526 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23527 prefs.default_device_scale_factor =
528 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07529#else
530 if (rvh->GetView()) {
531 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
532 rvh->GetView()->GetNativeView());
533 prefs.default_device_scale_factor =
534 static_cast<int>(monitor.device_scale_factor());
535 } else {
[email protected]82c9a8e2012-05-02 01:07:23536 prefs.default_device_scale_factor =
537 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07538 }
539#endif
[email protected]43d9d782012-03-01 15:40:09540
[email protected]2e21fe292012-03-02 22:52:32541 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54542
543 return prefs;
544}
545
[email protected]b172aee2012-04-10 17:05:26546NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20547 return controller_;
548}
549
[email protected]b172aee2012-04-10 17:05:26550RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28551 return &render_manager_;
552}
553
[email protected]b172aee2012-04-10 17:05:26554bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56555 if (GetWebUI() &&
556 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17557 return true;
[email protected]d2353452012-01-19 19:53:56558 }
[email protected]f82d57b52011-04-27 19:13:17559
[email protected]d8c660432011-12-22 20:51:25560 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
561 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10562 while ((observer = it.GetNext()) != NULL)
563 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53564 return true;
[email protected]403415a2011-01-10 18:57:53565
[email protected]724159a2010-12-30 01:11:18566 bool handled = true;
567 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26568 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58569 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
570 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24571 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
572 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18573 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
574 OnDidLoadResourceFromMemoryCache)
575 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
576 OnDidDisplayInsecureContent)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
578 OnDidRunInsecureContent)
579 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
580 OnDocumentLoadedInFrame)
581 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26582 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
583 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17584 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
585 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25586 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26587 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59588 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21589 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20590 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
591 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
592 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16593 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45594 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10595 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20596 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
597 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
598 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
599 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29600 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50601 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18602 IPC_MESSAGE_UNHANDLED(handled = false)
603 IPC_END_MESSAGE_MAP_EX()
604
605 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38606 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18607 GetRenderProcessHost()->ReceivedBadMessage();
608 }
609
610 return handled;
611}
612
[email protected]b172aee2012-04-10 17:05:26613void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18614 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23615 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51616 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18617}
618
[email protected]b172aee2012-04-10 17:05:26619NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56620 return controller_;
621}
622
[email protected]b172aee2012-04-10 17:05:26623const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56624 return controller_;
625}
626
[email protected]b172aee2012-04-10 17:05:26627content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55628 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30629}
630
[email protected]b172aee2012-04-10 17:05:26631void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56632 view_type_ = type;
633}
634
[email protected]b172aee2012-04-10 17:05:26635content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09636 return view_type_;
637}
638
[email protected]b172aee2012-04-10 17:05:26639const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31640 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23641 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51642 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31643}
644
645
[email protected]b172aee2012-04-10 17:05:26646const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31647 return &property_bag_;
648}
649
[email protected]b172aee2012-04-10 17:05:26650base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31651 return &property_bag_;
652}
653
[email protected]b172aee2012-04-10 17:05:26654content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31655 return delegate_;
656}
657
[email protected]b172aee2012-04-10 17:05:26658void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31659 // TODO(cbentzel): remove this debugging code?
660 if (delegate == delegate_)
661 return;
662 if (delegate_)
663 delegate_->Detach(this);
664 delegate_ = delegate;
665 if (delegate_)
666 delegate_->Attach(this);
667}
668
[email protected]b172aee2012-04-10 17:05:26669content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41670 RenderViewHostImpl* host = render_manager_.current_host();
671 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16672}
673
[email protected]b172aee2012-04-10 17:05:26674RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31675 return render_manager_.current_host();
676}
677
[email protected]b172aee2012-04-10 17:05:26678RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31679 return render_manager_.GetRenderWidgetHostView();
680}
681
[email protected]b172aee2012-04-10 17:05:26682content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31683 return view_.get();
684}
685
[email protected]b172aee2012-04-10 17:05:26686content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50687 WebUIControllerFactory* factory =
688 content::GetContentClient()->browser()->GetWebUIControllerFactory();
689 if (!factory)
690 return NULL;
[email protected]d2353452012-01-19 19:53:56691 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22692 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50693 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22694 if (controller) {
695 web_ui->SetController(controller);
696 return web_ui;
697 }
698
699 delete web_ui;
700 return NULL;
701}
702
[email protected]b172aee2012-04-10 17:05:26703content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31704 return render_manager_.web_ui() ? render_manager_.web_ui()
705 : render_manager_.pending_web_ui();
706}
707
[email protected]b172aee2012-04-10 17:05:26708content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31709 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34710}
711
[email protected]86ef6a392012-05-11 22:03:11712void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
713 user_agent_override_ = override;
714}
715
716const std::string& WebContentsImpl::GetUserAgentOverride() const {
717 return user_agent_override_;
718}
719
[email protected]b172aee2012-04-10 17:05:26720const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55721 // Transient entries take precedence. They are used for interstitial pages
722 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23723 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08724 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20725 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30726 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23727 if (entry) {
[email protected]b5cca982011-05-26 04:42:08728 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23729 }
[email protected]7ade2732011-02-10 00:13:58730 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
731 render_manager_.pending_web_ui() : render_manager_.web_ui();
732 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54733 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55734 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54735 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35736 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22737 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54738 if (!title.empty())
739 return title;
740 }
741 }
742
743 // We use the title for the last committed entry rather than a pending
744 // navigation entry. For example, when the user types in a URL, we want to
745 // keep the old page's title until the new load has committed and we get a new
746 // title.
[email protected]96d185d2009-04-24 03:28:54747 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23748 if (entry) {
[email protected]b5cca982011-05-26 04:42:08749 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23750 }
[email protected]987fc3a2011-05-26 14:18:09751
752 // |page_title_when_no_navigation_entry_| is finally used
753 // if no title cannot be retrieved.
754 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54755}
756
[email protected]b172aee2012-04-10 17:05:26757int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46758 return GetMaxPageIDForSiteInstance(GetSiteInstance());
759}
760
[email protected]b172aee2012-04-10 17:05:26761int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
762 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33763 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
764 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46765
[email protected]b6583592012-01-25 19:52:33766 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34767}
768
[email protected]b172aee2012-04-10 17:05:26769void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46770 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
771}
772
[email protected]b172aee2012-04-10 17:05:26773void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33774 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46775 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33776 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34777}
778
[email protected]b172aee2012-04-10 17:05:26779void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
780 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57781}
782
[email protected]b172aee2012-04-10 17:05:26783SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58784 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54785}
786
[email protected]b172aee2012-04-10 17:05:26787SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38788 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
789 render_manager_.pending_render_view_host() :
790 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58791 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38792}
793
[email protected]b172aee2012-04-10 17:05:26794bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31795 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49796}
797
[email protected]b172aee2012-04-10 17:05:26798bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31799 return waiting_for_response_;
800}
801
[email protected]b172aee2012-04-10 17:05:26802const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return load_state_;
804}
805
[email protected]b172aee2012-04-10 17:05:26806const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31807 return load_state_host_;
808}
809
[email protected]b172aee2012-04-10 17:05:26810uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31811 return upload_size_;
812}
813
[email protected]b172aee2012-04-10 17:05:26814uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31815 return upload_position_;
816}
817
[email protected]b172aee2012-04-10 17:05:26818const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31819 return encoding_;
820}
821
[email protected]b172aee2012-04-10 17:05:26822bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31823 return displayed_insecure_content_;
824}
825
[email protected]b172aee2012-04-10 17:05:26826void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31827 capturing_contents_ = cap;
828}
829
[email protected]b172aee2012-04-10 17:05:26830bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
832 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
833 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49834}
835
[email protected]b172aee2012-04-10 17:05:26836void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
837 int error_code) {
[email protected]443b80e2010-12-14 00:42:23838 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34839 return;
840
[email protected]443b80e2010-12-14 00:42:23841 crashed_status_ = status;
842 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46843 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34844}
845
[email protected]b172aee2012-04-10 17:05:26846base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return crashed_status_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return is_being_destroyed_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34855 if (delegate_)
856 delegate_->NavigationStateChanged(this, changed_flags);
857}
858
[email protected]b172aee2012-04-10 17:05:26859void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54860 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04861 RenderWidgetHostViewPort* rwhv =
862 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16863 if (rwhv) {
864 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43865#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16866 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43867#endif
868 }
[email protected]96d185d2009-04-24 03:28:54869
[email protected]5ac20162010-11-24 23:33:11870 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38871
[email protected]d8c660432011-12-22 20:51:25872 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59873
874 // The resize rect might have changed while this was inactive -- send the new
875 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58876 RenderViewHostImpl* rvh =
877 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59878 if (rvh) {
879 rvh->ResizeRectChanged(GetRootWindowResizerRect());
880 }
[email protected]96d185d2009-04-24 03:28:54881}
882
[email protected]be1f56ab2011-12-22 06:55:31883
[email protected]b172aee2012-04-10 17:05:26884base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31885 return last_selected_time_;
886}
887
[email protected]b172aee2012-04-10 17:05:26888void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31889 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52890 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
891 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26892 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52893 // removes the |GetRenderViewHost()|; then when we actually destroy the
894 // window, OnWindowPosChanged() notices and calls HideContents() (which
895 // calls us).
[email protected]c30585c2012-02-16 15:02:04896 RenderWidgetHostViewPort* rwhv =
897 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16898 if (rwhv)
899 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54900 }
901
[email protected]ad50def52011-10-19 23:17:07902 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09903 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
904 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07905 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54906}
907
[email protected]b172aee2012-04-10 17:05:26908void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04909 RenderWidgetHostViewPort* rwhv =
910 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31911 if (rwhv)
912 rwhv->DidBecomeSelected();
913}
914
[email protected]b172aee2012-04-10 17:05:26915void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31916 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
917 // our superclass HideContents(), because some callers want to be very picky
918 // about the order in which these get called. In addition to making the code
919 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26920 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
921 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31922 WasHidden();
923}
924
[email protected]b172aee2012-04-10 17:05:26925bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31926 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27927 return WillNotifyDisconnection() &&
928 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58929 !static_cast<RenderViewHostImpl*>(
930 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31931}
932
[email protected]b172aee2012-04-10 17:05:26933void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27934 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25935 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27936}
937
[email protected]b172aee2012-04-10 17:05:26938WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44939 // We use our current SiteInstance since the cloned entry will use it anyway.
940 // We pass |this| for the |base_web_contents| to size the view correctly, and
941 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26942 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44943 GetBrowserContext(), GetSiteInstance(),
944 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20945 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27946 return tc;
947}
948
[email protected]b172aee2012-04-10 17:05:26949void WebContentsImpl::AddNewContents(WebContents* new_contents,
950 WindowOpenDisposition disposition,
951 const gfx::Rect& initial_pos,
952 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27953 if (!delegate_)
954 return;
955
956 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
957 user_gesture);
958}
959
[email protected]b172aee2012-04-10 17:05:26960gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27961 return view_->GetContentNativeView();
962}
963
[email protected]b172aee2012-04-10 17:05:26964gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27965 return view_->GetNativeView();
966}
967
[email protected]b172aee2012-04-10 17:05:26968void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27969 view_->GetContainerBounds(out);
970}
971
[email protected]b172aee2012-04-10 17:05:26972void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27973 view_->Focus();
974}
975
[email protected]14392a52012-05-02 20:28:44976void WebContentsImpl::Observe(int type,
977 const content::NotificationSource& source,
978 const content::NotificationDetails& details) {
979 switch (type) {
980 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
981 OnWebContentsDestroyed(
982 content::Source<content::WebContents>(source).ptr());
983 break;
984 default:
985 NOTREACHED();
986 }
987}
988
989void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
990 // Clear the opener if it has been closed.
991 if (web_contents == opener_) {
992 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
993 content::Source<WebContents>(opener_));
994 opener_ = NULL;
995 }
996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31999 observers_.AddObserver(observer);
1000}
1001
[email protected]b172aee2012-04-10 17:05:261002void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311003 observers_.RemoveObserver(observer);
1004}
1005
[email protected]b172aee2012-04-10 17:05:261006void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341007 if (delegate_)
1008 delegate_->ActivateContents(this);
1009}
1010
[email protected]b172aee2012-04-10 17:05:261011void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121012 if (delegate_)
1013 delegate_->DeactivateContents(this);
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481017 if (delegate_)
1018 delegate_->LostCapture();
1019}
1020
[email protected]b172aee2012-04-10 17:05:261021bool WebContentsImpl::PreHandleKeyboardEvent(
1022 const NativeWebKeyboardEvent& event,
1023 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481024 return delegate_ &&
1025 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1026}
1027
[email protected]b172aee2012-04-10 17:05:261028void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481029 if (delegate_)
1030 delegate_->HandleKeyboardEvent(event);
1031}
1032
[email protected]b172aee2012-04-10 17:05:261033void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431034 if (delegate_)
1035 delegate_->HandleMouseDown();
1036}
1037
[email protected]b172aee2012-04-10 17:05:261038void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481039 if (delegate_)
1040 delegate_->HandleMouseUp();
1041}
1042
[email protected]b172aee2012-04-10 17:05:261043void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481044 if (delegate_)
1045 delegate_->HandleMouseActivate();
1046}
1047
[email protected]b172aee2012-04-10 17:05:261048void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471049 if (delegate_)
1050 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1051}
1052
[email protected]b172aee2012-04-10 17:05:261053bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381054 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121055}
1056
[email protected]42252e02012-04-26 16:29:391057void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371058 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391059 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371060 } else {
1061 GotResponseToLockMouseRequest(false);
1062 }
1063}
1064
[email protected]b172aee2012-04-10 17:05:261065void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371066 if (delegate_)
1067 delegate_->LostMouseLock();
1068}
1069
[email protected]b172aee2012-04-10 17:05:261070void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231071 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331072 if (delegate_)
1073 delegate_->UpdatePreferredSize(this, pref_size);
1074}
1075
[email protected]b172aee2012-04-10 17:05:261076void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341077 if (delegate_)
1078 delegate_->ResizeDueToAutoResize(this, new_size);
1079}
1080
[email protected]b172aee2012-04-10 17:05:261081WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201082 if (!delegate_)
1083 return NULL;
[email protected]00c37fc2011-08-02 00:22:501084
[email protected]e5d549d2011-12-28 01:29:201085 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1086 // Notify observers.
1087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1088 DidOpenURL(params.url, params.referrer,
1089 params.disposition, params.transition));
1090 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341091}
1092
[email protected]b172aee2012-04-10 17:05:261093bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501094 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251095 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231096 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251097 reload_type);
[email protected]876bc832010-09-07 16:29:541098}
[email protected]96d185d2009-04-24 03:28:541099
[email protected]b172aee2012-04-10 17:05:261100bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231101 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501102 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401103 // The renderer will reject IPC messages with URLs longer than
1104 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511105 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401106 return false;
1107
[email protected]9f76c1e2012-03-05 15:15:581108 RenderViewHostImpl* dest_render_view_host =
1109 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401110 if (!dest_render_view_host)
1111 return false; // Unable to create the desired render view host.
1112
[email protected]80a8fad2011-01-29 04:02:381113 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071114 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581115 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501116 WebUIControllerFactory* factory =
1117 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271118 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501119 bool is_allowed_in_web_ui_renderer =
1120 factory &&
[email protected]24e18252012-04-16 21:26:271121 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1122 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231123 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1124 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271125 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231126 content::GetContentClient()->SetActiveURL(entry.GetURL());
1127 CHECK(0);
1128 }
[email protected]54ec6472010-04-09 19:39:581129
[email protected]96d185d2009-04-24 03:28:541130 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441131 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521132 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441133 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511134 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541135
1136 // Used for page load time metrics.
1137 current_load_start_ = base::TimeTicks::Now();
1138
1139 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341140 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271141 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471142 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341143 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541144
[email protected]36fc0392011-12-25 03:59:511145 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541146 // HACK!! This code suppresses javascript: URLs from being added to
1147 // session history, which is what we want to do for javascript: URLs that
1148 // do not generate content. What we really need is a message from the
1149 // renderer telling us that a new page was not created. The same message
1150 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511151 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541152 return false;
1153 }
1154
[email protected]3c9e1872010-11-18 16:17:491155 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251156 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041157 observers_,
[email protected]36fc0392011-12-25 03:59:511158 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541159
[email protected]09b29342011-06-24 19:18:481160 if (delegate_)
1161 delegate_->DidNavigateToPendingEntry(this);
1162
[email protected]d5f942ba2008-09-26 19:30:341163 return true;
1164}
1165
[email protected]b172aee2012-04-10 17:05:261166void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331167 const SiteInstance* site_instance,
1168 int history_length,
1169 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411170 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1171 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191172 if (render_manager_.pending_render_view_host()) {
1173 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141174 return;
[email protected]9e1ad4b2011-08-14 16:49:191175 }
[email protected]9f76c1e2012-03-05 15:15:581176 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191177 if (!rvh) {
1178 NOTREACHED();
1179 return;
1180 }
[email protected]9f76c1e2012-03-05 15:15:581181 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191182 NOTREACHED();
1183 return;
1184 }
[email protected]9f76c1e2012-03-05 15:15:581185 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191186 history_length,
1187 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141188}
1189
[email protected]b172aee2012-04-10 17:05:261190void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271191 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541192 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1193 return;
1194 }
[email protected]9f76c1e2012-03-05 15:15:581195 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541196}
1197
[email protected]b172aee2012-04-10 17:05:261198bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271199 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541200}
1201
[email protected]b172aee2012-04-10 17:05:261202InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271203 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221204}
1205
[email protected]b172aee2012-04-10 17:05:261206bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161207 // WebKit creates Document object when MIME type is application/xhtml+xml,
1208 // so we also support this MIME type.
1209 return contents_mime_type_ == "text/html" ||
1210 contents_mime_type_ == "text/xml" ||
1211 contents_mime_type_ == "application/xhtml+xml" ||
1212 contents_mime_type_ == "text/plain" ||
1213 contents_mime_type_ == "text/css" ||
1214 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1215}
1216
[email protected]b172aee2012-04-10 17:05:261217void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591218 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161219 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481220 download_stats::RecordDownloadSource(
1221 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461222 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141223 return;
[email protected]c7dd2f62011-07-18 15:57:591224 }
1225
1226 Stop();
1227
1228 // Create the save package and possibly prompt the user for the name to save
1229 // the page as. The user prompt is an asynchronous operation that runs on
1230 // another thread.
1231 save_package_ = new SavePackage(this);
1232 save_package_->GetSaveInfo();
1233}
1234
1235// Used in automated testing to bypass prompting the user for file names.
1236// Instead, the names and paths are hard coded rather than running them through
1237// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261238bool WebContentsImpl::SavePage(const FilePath& main_file,
1239 const FilePath& dir_path,
1240 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591241 // Stop the page from navigating.
1242 Stop();
1243
1244 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271245 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591246}
1247
[email protected]b172aee2012-04-10 17:05:261248void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121249 const FilePath& file,
1250 const base::Callback<void(const FilePath&, int64)>& callback) {
1251 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1252}
1253
[email protected]b172aee2012-04-10 17:05:261254bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231255 NavigationEntryImpl* active_entry =
1256 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321257 return (active_entry != NULL &&
1258 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511259 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321260}
1261
[email protected]b172aee2012-04-10 17:05:261262const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271263 return contents_mime_type_;
1264}
1265
[email protected]b172aee2012-04-10 17:05:261266bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271267 return notify_disconnection_;
1268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311271 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581272 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1273 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161274}
1275
[email protected]b172aee2012-04-10 17:05:261276void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311277 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581278 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1279 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161280}
1281
[email protected]b172aee2012-04-10 17:05:261282content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271283 return &renderer_preferences_;
1284}
1285
[email protected]b172aee2012-04-10 17:05:261286void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271287 new_tab_start_time_ = time;
1288}
1289
[email protected]b172aee2012-04-10 17:05:261290base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271291 return new_tab_start_time_;
1292}
1293
[email protected]b172aee2012-04-10 17:05:261294void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151295 if (close_start_time_.is_null())
1296 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011297}
1298
[email protected]b172aee2012-04-10 17:05:261299bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191300#if defined(OS_CHROMEOS)
1301 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1302 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511303 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201304 return false;
1305 return true;
[email protected]46624bf2010-06-09 16:04:191306#else
1307 return true;
1308#endif
1309}
1310
[email protected]b172aee2012-04-10 17:05:261311void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521312 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581313 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511314 if (delegate_)
1315 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341316}
1317
[email protected]b172aee2012-04-10 17:05:261318void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271319 closed_by_user_gesture_ = value;
1320}
1321
[email protected]b172aee2012-04-10 17:05:261322bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271323 return closed_by_user_gesture_;
1324}
1325
[email protected]b172aee2012-04-10 17:05:261326double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051327 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561328 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251329 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171330 return 0;
[email protected]b75b8292010-10-01 07:28:251331
1332 double zoom_level;
1333 if (temporary_zoom_settings_) {
1334 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581335 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251336 } else {
[email protected]2ae88d12011-10-14 09:11:191337 GURL url;
[email protected]10f417c52011-12-28 21:04:231338 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191339 // Since zoom map is updated using rewritten URL, use rewritten URL
1340 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511341 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191342 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251343 }
[email protected]d0b8d092010-10-25 04:05:171344 return zoom_level;
1345}
[email protected]b75b8292010-10-01 07:28:251346
[email protected]b172aee2012-04-10 17:05:261347int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1348 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171349 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011350 // Calculate the zoom percent from the factor. Round up to the nearest whole
1351 // number.
[email protected]b75b8292010-10-01 07:28:251352 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011353 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251354 *enable_decrement = percent > minimum_zoom_percent_;
1355 *enable_increment = percent < maximum_zoom_percent_;
1356 return percent;
1357}
1358
[email protected]b172aee2012-04-10 17:05:261359void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501360 if (!delegate_)
1361 return;
1362
[email protected]10f417c52011-12-28 21:04:231363 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501364 if (!active_entry)
1365 return;
1366
[email protected]36fc0392011-12-25 03:59:511367 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121368}
1369
[email protected]b172aee2012-04-10 17:05:261370void WebContentsImpl::ViewFrameSource(const GURL& url,
1371 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271372 if (!delegate_)
1373 return;
1374
1375 delegate_->ViewSourceForFrame(this, url, content_state);
1376}
1377
[email protected]b172aee2012-04-10 17:05:261378int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271379 return minimum_zoom_percent_;
1380}
1381
[email protected]b172aee2012-04-10 17:05:261382int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271383 return maximum_zoom_percent_;
1384}
1385
[email protected]b172aee2012-04-10 17:05:261386gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231387 return preferred_size_;
1388}
1389
[email protected]b172aee2012-04-10 17:05:261390int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271391 return content_restrictions_;
1392}
1393
[email protected]b172aee2012-04-10 17:05:261394WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501395 WebUIControllerFactory* factory =
1396 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1397 if (!factory)
1398 return WebUI::kNoWebUI;
1399 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271400}
1401
[email protected]b172aee2012-04-10 17:05:261402content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271403 // When there is a pending navigation entry, we want to use the pending WebUI
1404 // that goes along with it to control the basic flags. For example, we want to
1405 // show the pending URL in the URL bar, so we want the display_url flag to
1406 // be from the pending entry.
1407 //
1408 // The confusion comes because there are multiple possibilities for the
1409 // initial load in a tab as a side effect of the way the RenderViewHostManager
1410 // works.
1411 //
1412 // - For the very first tab the load looks "normal". The new tab Web UI is
1413 // the pending one, and we want it to apply here.
1414 //
1415 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1416 // get switched to the one previously associated with the new tab pages.
1417 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1418 // have a committed Web UI in this case.
1419 //
1420 // This condition handles all of these cases:
1421 //
1422 // - First load in first tab: no committed nav entry + pending nav entry +
1423 // pending dom ui:
1424 // -> Use pending Web UI if any.
1425 //
1426 // - First load in second tab: no committed nav entry + pending nav entry +
1427 // no pending Web UI:
1428 // -> Use the committed Web UI if any.
1429 //
1430 // - Second navigation in any tab: committed nav entry + pending nav entry:
1431 // -> Use pending Web UI if any.
1432 //
1433 // - Normal state with no load: committed nav entry + no pending nav entry:
1434 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251435 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271436 (controller_.GetLastCommittedEntry() ||
1437 render_manager_.pending_web_ui()))
1438 return render_manager_.pending_web_ui();
1439 return render_manager_.web_ui();
1440}
1441
[email protected]b172aee2012-04-10 17:05:261442bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271443 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581444 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271445}
1446
[email protected]b172aee2012-04-10 17:05:261447bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441448 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501449}
1450
[email protected]b172aee2012-04-10 17:05:261451void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321452 SkColor color) {
[email protected]da8543762012-03-20 08:52:201453 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1454 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1455}
1456
[email protected]b172aee2012-04-10 17:05:261457void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201458 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1459 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1460 if (delegate_)
1461 delegate_->DidEndColorChooser();
1462 color_chooser_ = NULL;
1463}
1464
[email protected]b172aee2012-04-10 17:05:261465bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471466 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271467 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221468 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231469 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411470 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271471}
1472
[email protected]b172aee2012-04-10 17:05:261473void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271474 if (delegate_)
1475 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211476}
1477
[email protected]b172aee2012-04-10 17:05:261478void WebContentsImpl::OnRegisterIntentService(const string16& action,
1479 const string16& type,
1480 const string16& href,
1481 const string16& title,
1482 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511483 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301484 this, action, type, href, title, disposition);
1485}
1486
[email protected]b172aee2012-04-10 17:05:261487void WebContentsImpl::OnWebIntentDispatch(
1488 const webkit_glue::WebIntentData& intent,
1489 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001490 WebIntentsDispatcherImpl* intents_dispatcher =
1491 new WebIntentsDispatcherImpl(this, intent, intent_id);
1492 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301493}
1494
[email protected]54047eb52012-05-08 21:45:571495void WebContentsImpl::DidStartProvisionalLoadForFrame(
1496 content::RenderViewHost* render_view_host,
1497 int64 frame_id,
1498 bool is_main_frame,
1499 const GURL& opener_url,
1500 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281501 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181502 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451503 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571504 RenderViewHostImpl* render_view_host_impl =
1505 static_cast<RenderViewHostImpl*>(render_view_host);
1506 content::RenderProcessHost* render_process_host =
1507 render_view_host->GetProcess();
1508 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581509 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571510 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451511 false,
[email protected]9f76c1e2012-03-05 15:15:581512 &validated_url);
[email protected]54047eb52012-05-08 21:45:571513 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451514 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571515 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451516 true,
1517 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181518
[email protected]0d60f0192011-04-14 12:40:101519 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251520 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101521 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571522 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101523
[email protected]724159a2010-12-30 01:11:181524 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591525 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451527 ProvisionalChangeToMainFrameUrl(validated_url,
1528 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181529 }
1530}
1531
[email protected]54047eb52012-05-08 21:45:571532void WebContentsImpl::DidRedirectProvisionalLoad(
1533 content::RenderViewHost* render_view_host,
1534 int32 page_id,
1535 const GURL& opener_url,
1536 const GURL& source_url,
1537 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491538 // TODO(creis): Remove this method and have the pre-rendering code listen to
1539 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1540 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451541 GURL validated_source_url(source_url);
1542 GURL validated_target_url(target_url);
1543 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571544 RenderViewHostImpl* render_view_host_impl =
1545 static_cast<RenderViewHostImpl*>(render_view_host);
1546 content::RenderProcessHost* render_process_host =
1547 render_view_host->GetProcess();
1548 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451549 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571550 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451551 false,
1552 &validated_source_url);
[email protected]54047eb52012-05-08 21:45:571553 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451554 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571555 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451556 false,
1557 &validated_target_url);
[email protected]54047eb52012-05-08 21:45:571558 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451559 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571560 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451561 true,
1562 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231563 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571564 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251565 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571566 } else {
1567 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1568 page_id);
1569 }
[email protected]6b7cd8f2012-03-21 21:02:451570 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181571 return;
[email protected]e7d50892011-01-19 21:47:381572
[email protected]4850a7f2011-03-08 23:36:591573 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251574 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451575 ProvisionalChangeToMainFrameUrl(validated_target_url,
1576 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181577}
1578
[email protected]54047eb52012-05-08 21:45:571579void WebContentsImpl::DidFailProvisionalLoadWithError(
1580 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581581 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1582 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1583 << ", error_code: " << params.error_code
1584 << ", error_description: " << params.error_description
1585 << ", is_main_frame: " << params.is_main_frame
1586 << ", showing_repost_interstitial: " <<
1587 params.showing_repost_interstitial
1588 << ", frame_id: " << params.frame_id;
1589 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571590 RenderViewHostImpl* render_view_host_impl =
1591 static_cast<RenderViewHostImpl*>(render_view_host);
1592 content::RenderProcessHost* render_process_host =
1593 render_view_host->GetProcess();
1594 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581595 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571596 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451597 false,
[email protected]9f76c1e2012-03-05 15:15:581598 &validated_url);
[email protected]724159a2010-12-30 01:11:181599
[email protected]d7b175e2011-10-11 15:31:581600 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181601 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1602 // This means that the interstitial won't be torn down properly, which is
1603 // bad. But if we have an interstitial, go back to another tab type, and
1604 // then load the same interstitial again, we could end up getting the first
1605 // interstitial's "failed" message (as a result of the cancel) when we're on
1606 // the second one.
1607 //
1608 // We can't tell this apart, so we think we're tearing down the current page
1609 // which will cause a crash later one. There is also some code in
1610 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1611 // out because of this problem.
1612 //
1613 // http://code.google.com/p/chromium/issues/detail?id=2855
1614 // Because this will not tear down the interstitial properly, if "back" is
1615 // back to another tab type, the interstitial will still be somewhat alive
1616 // in the previous tab type. If you navigate somewhere that activates the
1617 // tab with the interstitial again, you'll see a flash before the new load
1618 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271619 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181620 LOG(WARNING) << "Discarding message during interstitial.";
1621 return;
1622 }
1623
[email protected]02102f82011-06-13 20:37:021624 // Discard our pending entry if the load canceled (e.g. if we decided to
1625 // download the file instead of load it). We do not verify that the URL
1626 // being canceled matches the pending entry's URL because they will not
1627 // match if a redirect occurred (in which case we do not want to leave a
1628 // stale redirect URL showing). This means that we also cancel the pending
1629 // entry if the user started a new navigation. As a result, the navigation
1630 // controller may not remember that a load is in progress, but the
1631 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251632 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161633 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181634
[email protected]54047eb52012-05-08 21:45:571635 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181636 }
1637
[email protected]d8c660432011-12-22 20:51:251638 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581639 observers_,
1640 DidFailProvisionalLoad(params.frame_id,
1641 params.is_main_frame,
1642 validated_url,
1643 params.error_code,
1644 params.error_description));
[email protected]724159a2010-12-30 01:11:181645}
1646
[email protected]b172aee2012-04-10 17:05:261647void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181648 const GURL& url,
[email protected]70435962011-08-02 20:13:281649 const std::string& security_info,
1650 const std::string& http_method,
1651 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191652 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181653 cache.Increment();
1654
1655 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081656 int cert_id = 0;
1657 net::CertStatus cert_status = 0;
1658 int security_bits = -1;
1659 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511660 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1661 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301662 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161663 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181664
[email protected]ad50def52011-10-19 23:17:071665 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271666 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501667 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531668 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181669}
1670
[email protected]b172aee2012-04-10 17:05:261671void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381672 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181673 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201674 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181675}
1676
[email protected]b172aee2012-04-10 17:05:261677void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021678 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231679 LOG(INFO) << security_origin << " ran insecure content from "
1680 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381681 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411682 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1683 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181684 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411685 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201686 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181690 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251691 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101692 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181693}
1694
[email protected]b172aee2012-04-10 17:05:261695void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311696 int64 frame_id,
1697 const GURL& validated_url,
1698 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251699 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311700 DidFinishLoad(frame_id, validated_url, is_main_frame));
1701}
1702
[email protected]b172aee2012-04-10 17:05:261703void WebContentsImpl::OnDidFailLoadWithError(
1704 int64 frame_id,
1705 const GURL& validated_url,
1706 bool is_main_frame,
1707 int error_code,
1708 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311710 DidFailLoad(frame_id, validated_url, is_main_frame,
1711 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181712}
1713
[email protected]b172aee2012-04-10 17:05:261714void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271715 content_restrictions_ = restrictions;
1716 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171717}
1718
[email protected]b172aee2012-04-10 17:05:261719void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261720 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231721 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251722 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261723 if (!entry)
1724 return;
1725 // Note that we don't call NavigationController::GotToOffset() as we don't
1726 // want to create a pending navigation entry (it might end up lingering
1727 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251728 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581729 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511730 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581731 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471732 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571733
1734 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1735 // it in now that we know. This allows us to find the entry when it commits.
1736 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231737 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331738 entry->set_site_instance(
1739 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571740 }
[email protected]216813952011-05-19 22:21:261741 }
1742}
1743
[email protected]b172aee2012-04-10 17:05:261744void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1745 int maximum_percent,
1746 bool remember) {
[email protected]216813952011-05-19 22:21:261747 minimum_zoom_percent_ = minimum_percent;
1748 maximum_zoom_percent_ = maximum_percent;
1749 temporary_zoom_settings_ = !remember;
1750}
1751
[email protected]20b433a2012-05-15 21:23:461752void WebContentsImpl::OnSaveURL(const GURL& url,
1753 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:481754 download_stats::RecordDownloadSource(
1755 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261756 // Check if the URL to save matches the URL of the main frame. Since this
1757 // message originates from Pepper plugins, it may not be the case if the
1758 // plugin is an embedded element.
1759 GURL main_frame_url = GetURL();
1760 if (!main_frame_url.is_valid())
1761 return;
1762 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:461763 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271764}
1765
[email protected]b172aee2012-04-10 17:05:261766void WebContentsImpl::OnEnumerateDirectory(int request_id,
1767 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591768 ChildProcessSecurityPolicyImpl* policy =
1769 ChildProcessSecurityPolicyImpl::GetInstance();
1770 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1771 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511775 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201776}
1777
[email protected]b172aee2012-04-10 17:05:261778void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1779 const GURL& url,
1780 const string16& title) {
[email protected]b9535422012-02-09 01:47:591781 ChildProcessSecurityPolicyImpl* policy =
1782 ChildProcessSecurityPolicyImpl::GetInstance();
1783 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1784 return;
[email protected]6934a702011-12-20 00:04:511785 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201786}
1787
[email protected]b172aee2012-04-10 17:05:261788void WebContentsImpl::OnFindReply(int request_id,
1789 int number_of_matches,
1790 const gfx::Rect& selection_rect,
1791 int active_match_ordinal,
1792 bool final_update) {
[email protected]6934a702011-12-20 00:04:511793 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1794 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001795 // Send a notification to the renderer that we are ready to receive more
1796 // results from the scoping effort of the Find operation. The FindInPage
1797 // scoping is asynchronous and periodically sends results back up to the
1798 // browser using IPC. In an effort to not spam the browser we have the
1799 // browser send an ACK for each FindReply message and have the renderer
1800 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581801 GetRenderViewHostImpl()->Send(
1802 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161803}
1804
[email protected]b172aee2012-04-10 17:05:261805void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441806 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1807 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451808}
1809
[email protected]b172aee2012-04-10 17:05:261810void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1811 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101812 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251813 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101814 AppCacheAccessed(manifest_url, blocked_by_policy));
1815}
1816
[email protected]b172aee2012-04-10 17:05:261817void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321818 SkColor color) {
[email protected]da8543762012-03-20 08:52:201819 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1820}
1821
[email protected]b172aee2012-04-10 17:05:261822void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201823 if (color_chooser_ &&
1824 color_chooser_id == color_chooser_->identifier())
1825 color_chooser_->End();
1826}
1827
[email protected]b172aee2012-04-10 17:05:261828void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321829 SkColor color) {
[email protected]da8543762012-03-20 08:52:201830 if (color_chooser_ &&
1831 color_chooser_id == color_chooser_->identifier())
1832 color_chooser_->SetSelectedColor(color);
1833}
1834
[email protected]9f2a9d72012-04-16 16:02:221835void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1836 const FilePath& path,
1837 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441838 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1839 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291840}
1841
[email protected]d0759f492012-04-19 22:50:501842// This exists for render views that don't have a WebUI, but do have WebUI
1843// bindings enabled.
1844void WebContentsImpl::OnWebUISend(const GURL& source_url,
1845 const std::string& name,
1846 const base::ListValue& args) {
1847 if (delegate_)
1848 delegate_->WebUISend(this, source_url, name, args);
1849}
1850
[email protected]96d185d2009-04-24 03:28:541851// Notifies the RenderWidgetHost instance about the fact that the page is
1852// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261853void WebContentsImpl::SetIsLoading(bool is_loading,
1854 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541855 if (is_loading == is_loading_)
1856 return;
1857
1858 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211859 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541860 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561861 upload_size_ = 0;
1862 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541863 }
1864
1865 render_manager_.SetIsLoading(is_loading);
1866
1867 is_loading_ = is_loading;
1868 waiting_for_response_ = is_loading;
1869
[email protected]6ebdc9b2010-09-27 16:55:571870 if (delegate_)
1871 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461872 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541873
[email protected]432115822011-07-10 15:52:271874 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1875 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071876 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541877 if (details)
[email protected]6c2381d2011-10-19 02:52:531878 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071879 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501880 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541881 det);
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131885 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321886 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561887 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381888 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441889 // that opened the window, as long as both renderers have the same
1890 // privileges.
[email protected]1fd1a502011-03-30 16:55:561891 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561892 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581893 // web_ui might be NULL if the URL refers to a non-existent extension.
1894 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401895 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521896 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441897 }
1898 }
[email protected]1fd1a502011-03-30 16:55:561899 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441900 }
1901
[email protected]4e697b042011-07-08 06:44:561902 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321903 // Clear the status bubble. This is a workaround for a bug where WebKit
1904 // doesn't let us know that the cursor left an element during a
1905 // transition (this is also why the mouse cursor remains as a hand after
1906 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1907 // clear the bubble when a user navigates to a named anchor in the same
1908 // page.
[email protected]36fc0392011-12-25 03:59:511909 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321910 }
1911
[email protected]a6e82fc2010-02-24 22:28:141912 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471913 // Once the main frame is navigated, we're no longer considered to have
1914 // displayed insecure content.
1915 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171916 }
[email protected]ce5c4502009-05-06 16:46:111917
[email protected]3c9e1872010-11-18 16:17:491918 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251919 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041920 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321921}
1922
[email protected]b172aee2012-04-10 17:05:261923void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321924 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131925 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321926 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061927 // If we navigate off the page, reset JavaScript state. This does nothing
1928 // to prevent a malicious script from spamming messages, since the script
1929 // could just reload the page to stop blocking.
1930 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551931 dialog_creator_->ResetJavaScriptState(this);
1932 dialog_creator_ = NULL;
1933 }
[email protected]420ae012009-04-24 05:16:321934
[email protected]3c9e1872010-11-18 16:17:491935 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251936 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041937 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321938}
1939
[email protected]b172aee2012-04-10 17:05:261940void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461941 // If we are creating a RVH for a restored controller, then we need to make
1942 // sure the RenderView starts with a next_page_id_ larger than the number
1943 // of restored entries. This must be called before the RenderView starts
1944 // navigating (to avoid a race between the browser updating max_page_id and
1945 // the renderer updating next_page_id_). Because of this, we only call this
1946 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561947 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581948 if (max_restored_page_id >
1949 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1950 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1951 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321952}
1953
[email protected]b172aee2012-04-10 17:05:261954bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1955 const string16& title) {
[email protected]420ae012009-04-24 05:16:321956 // For file URLs without a title, use the pathname instead. In the case of a
1957 // synthesized title, we don't want the update to count toward the "one set
1958 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511959 string16 final_title;
[email protected]420ae012009-04-24 05:16:321960 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511961 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1962 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321963 explicit_set = false; // Don't count synthetic titles toward the set limit.
1964 } else {
[email protected]acafd272011-07-26 17:35:571965 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321966 explicit_set = true;
1967 }
1968
[email protected]987fc3a2011-05-26 14:18:091969 // If a page is created via window.open and never navigated,
1970 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551971 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091972 if (entry) {
[email protected]36fc0392011-12-25 03:59:511973 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091974 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321975
[email protected]36fc0392011-12-25 03:59:511976 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091977 } else {
1978 if (page_title_when_no_navigation_entry_ == final_title)
1979 return false; // Nothing changed, don't bother.
1980
1981 page_title_when_no_navigation_entry_ = final_title;
1982 }
[email protected]420ae012009-04-24 05:16:321983
[email protected]420ae012009-04-24 05:16:321984 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231985 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321986
[email protected]2bb171882012-03-07 02:09:461987 std::pair<content::NavigationEntry*, bool> details =
1988 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141989
[email protected]ad50def52011-10-19 23:17:071990 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441991 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1992 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461993 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041994
[email protected]420ae012009-04-24 05:16:321995 return true;
1996}
1997
[email protected]b172aee2012-04-10 17:05:261998void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321999 // After sending out a swap notification, we need to send a disconnect
2000 // notification so that clients that pick up a pointer to |this| can NULL the
2001 // pointer. See Bug 1230284.
2002 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072003 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202004 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2005 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072006 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322007}
2008
[email protected]b172aee2012-04-10 17:05:262009void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322010 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072011 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122012 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2013 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072014 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322015}
2016
[email protected]b172aee2012-04-10 17:05:262017void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322018 if (!notify_disconnection_)
2019 return;
2020
2021 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072022 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322023 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2024 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072025 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322026}
2027
[email protected]b172aee2012-04-10 17:05:262028RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322029 return view_.get();
2030}
2031
[email protected]8d3347f2009-07-09 22:00:212032RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262033WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212034 return &render_manager_;
2035}
2036
[email protected]b172aee2012-04-10 17:05:262037content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372038 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462039 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512040}
2041
[email protected]b172aee2012-04-10 17:05:262042WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172043 return this;
2044}
2045
[email protected]b172aee2012-04-10 17:05:262046content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:432047 return view_type_;
[email protected]7b291f92009-08-14 05:43:532048}
2049
[email protected]b172aee2012-04-10 17:05:262050gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172051 if (delegate_)
2052 return delegate_->GetRootWindowResizerRect();
2053 return gfx::Rect();
2054}
2055
[email protected]b172aee2012-04-10 17:05:262056void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442057 // Don't send notifications if we are just creating a swapped-out RVH for
2058 // the opener chain. These won't be used for view-source or WebUI, so it's
2059 // ok to return early.
2060 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2061 return;
2062
[email protected]ad50def52011-10-19 23:17:072063 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272064 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322065 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532066 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232067 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322068 if (!entry)
2069 return;
2070
2071 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352072 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562073 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582074 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322075
2076 if (entry->IsViewSourceMode()) {
2077 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582078 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2079 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322080 }
[email protected]0666aef2009-05-13 19:48:082081
[email protected]d487beefe2011-12-21 05:41:212082 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262083
2084 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252085 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322086}
2087
[email protected]b172aee2012-04-10 17:05:262088void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522089 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322090 // Don't notify the world, since this came from a renderer in the
2091 // background.
2092 return;
2093 }
2094
2095 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312096 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232097 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302098
2099 // Restore the focus to the tab (otherwise the focus will be on the top
2100 // window).
[email protected]484ae5912010-09-29 19:16:142101 if (was_crashed && !FocusLocationBarByDefault() &&
2102 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302103 Focus();
[email protected]484ae5912010-09-29 19:16:142104 }
[email protected]32ded2212011-11-10 18:51:432105
[email protected]d8c660432011-12-22 20:51:252106 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322107}
2108
[email protected]b172aee2012-04-10 17:05:262109void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2110 base::TerminationStatus status,
2111 int error_code) {
[email protected]151a63d2011-12-20 22:32:522112 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322113 // The pending page's RenderViewHost is gone.
2114 return;
2115 }
2116
2117 SetIsLoading(false, NULL);
2118 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232119 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312120 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322121
[email protected]d8c660432011-12-22 20:51:252122 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272123 observers_,
[email protected]be1f56ab2011-12-22 06:55:312124 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322125}
2126
[email protected]b172aee2012-04-10 17:05:262127void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482128 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252129 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062130}
2131
[email protected]b172aee2012-04-10 17:05:262132void WebContentsImpl::DidNavigate(
2133 RenderViewHost* rvh,
2134 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582135 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322136 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372137
[email protected]434f69f2012-02-06 21:56:522138 // Update the site of the SiteInstance if it doesn't have one yet, unless
2139 // this is for about:blank. In that case, the SiteInstance can still be
2140 // considered unused until a navigation to a real page.
2141 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2142 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332143 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522144 }
[email protected]420ae012009-04-24 05:16:322145
2146 // Need to update MIME type here because it's referred to in
2147 // UpdateNavigationCommands() called by RendererDidNavigate() to
2148 // determine whether or not to enable the encoding menu.
2149 // It's updated only for the main frame. For a subframe,
2150 // RenderView::UpdateURL does not set params.contents_mime_type.
2151 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2152 // TODO(jungshik): Add a test for the encoding menu to avoid
2153 // regressing it again.
[email protected]2905f742011-10-13 03:51:582154 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322155 contents_mime_type_ = params.contents_mime_type;
2156
[email protected]8286f51a2011-05-31 17:39:132157 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002158 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392159
[email protected]a9c0bfe2010-09-17 08:35:222160 // Send notification about committed provisional loads. This notification is
2161 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2162 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082163 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072164 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2165 // that is not recorded in the navigation history. For the purpose of
2166 // tracking navigation events, we treat this event as a sub frame navigation
2167 // event.
2168 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582169 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222170 // Whether or not a page transition was triggered by going backward or
2171 // forward in the history is only stored in the navigation controller's
2172 // entry list.
2173 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512174 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582175 content::PAGE_TRANSITION_FORWARD_BACK)) {
2176 transition_type = content::PageTransitionFromInt(
2177 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222178 }
[email protected]0d60f0192011-04-14 12:40:102179 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252180 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102181 DidCommitProvisionalLoadForFrame(params.frame_id,
2182 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222183 }
2184
[email protected]76543b92009-08-31 17:27:452185 if (!did_navigate)
2186 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322187
2188 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2189 // for the appropriate notification (best) or you can add it to
2190 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2191 // necessary, please).
2192
2193 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002194 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322195 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512196 if (delegate_)
2197 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002198 }
[email protected]420ae012009-04-24 05:16:322199 DidNavigateAnyFramePostCommit(rvh, details, params);
2200}
2201
[email protected]b172aee2012-04-10 17:05:262202void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2203 int32 page_id,
2204 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152205 // Ensure that this state update comes from either the active RVH or one of
2206 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522207 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322208
2209 // We must be prepared to handle state updates for any page, these occur
2210 // when the user is scrolling and entering form data, as well as when we're
2211 // leaving a page, in which case our state may have already been moved to
2212 // the next page. The navigation controller will look up the appropriate
2213 // NavigationEntry and update it when it is notified via the delegate.
2214
2215 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582216 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322217 if (entry_index < 0)
2218 return;
[email protected]10f417c52011-12-28 21:04:232219 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322220
[email protected]36fc0392011-12-25 03:59:512221 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322222 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512223 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322224 controller_.NotifyEntryChanged(entry, entry_index);
2225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2228 int32 page_id,
2229 const string16& title,
2230 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322231 // If we have a title, that's a pretty good indication that we've started
2232 // getting useful data.
2233 SetNotWaitingForResponse();
2234
[email protected]73eb2602012-02-09 19:50:552235 // Try to find the navigation entry, which might not be the current one.
2236 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232237 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582238 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092239
[email protected]73eb2602012-02-09 19:50:552240 // We can handle title updates when we don't have an entry in
2241 // UpdateTitleForEntry, but only if the update is from the current RVH.
2242 if (!entry && rvh != GetRenderViewHost())
2243 return;
2244
[email protected]a49e10b2011-08-01 23:57:462245 // TODO(evan): make use of title_direction.
2246 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092247 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322248 return;
2249
2250 // Broadcast notifications when the UI should be updated.
2251 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462252 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322253}
2254
[email protected]b172aee2012-04-10 17:05:262255void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2256 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312257 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512261 if (delegate_)
2262 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292266 // The UI may be in an event-tracking loop, such as between the
2267 // mouse-down and mouse-up in text selection or a button click.
2268 // Defer the close until after tracking is complete, so that we
2269 // don't free objects out from under the UI.
2270 // TODO(shess): This could probably be integrated with the
2271 // IsDoingDrag() test below. Punting for now because I need more
2272 // research to understand how this impacts platforms other than Mac.
2273 // TODO(shess): This could get more fine-grained. For instance,
2274 // closing a tab in another window while selecting text in the
2275 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212276 if (GetView()->IsEventTracking()) {
2277 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292278 return;
2279 }
2280
[email protected]24a4d1062009-07-10 23:10:422281 // If we close the tab while we're in the middle of a drag, we'll crash.
2282 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212283 if (GetView()->IsDoingDrag()) {
2284 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422285 return;
2286 }
2287
[email protected]420ae012009-04-24 05:16:322288 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522289 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512290 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322291}
2292
[email protected]b172aee2012-04-10 17:05:262293void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522294 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512295 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572296}
2297
[email protected]b172aee2012-04-10 17:05:262298void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512299 if (delegate_ && delegate_->IsPopupOrPanel(this))
2300 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322304 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492305
[email protected]82114f52012-03-20 22:53:412306 if (delegate_ && content_restrictions_)
2307 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492308
2309 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252310 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322314 scoped_ptr<LoadNotificationDetails> details;
2315
[email protected]10f417c52011-12-28 21:04:232316 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322317 // An entry may not exist for a stop when loading an initial blank page or
2318 // if an iframe injected by script into a blank page finishes loading.
2319 if (entry) {
[email protected]420ae012009-04-24 05:16:322320 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2321
2322 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512323 entry->GetVirtualURL(),
2324 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322325 elapsed,
2326 &controller_,
2327 controller_.GetCurrentEntryIndex()));
2328 }
2329
[email protected]420ae012009-04-24 05:16:322330 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492331
2332 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252333 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322334}
2335
[email protected]b172aee2012-04-10 17:05:262336void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162337 controller_.DiscardNonCommittedEntries();
2338
2339 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462340 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162341}
2342
[email protected]b172aee2012-04-10 17:05:262343void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512344 if (delegate_)
2345 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402346}
2347
[email protected]87717d0e2012-04-26 02:58:432348void WebContentsImpl::DocumentAvailableInMainFrame(
2349 RenderViewHost* render_view_host) {
2350 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2351 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102352}
2353
[email protected]b172aee2012-04-10 17:05:262354void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082355 RenderViewHost* render_view_host,
2356 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072357 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272358 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322359 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532360 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082361}
2362
[email protected]196159d2012-05-04 17:26:542363void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2364 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262365 const content::Referrer& referrer,
2366 WindowOpenDisposition disposition,
2367 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542368 // If this came from a swapped out RenderViewHost, we only allow the request
2369 // if we are still in the same BrowsingInstance.
2370 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2371 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2372 return;
2373 }
2374
[email protected]4ad5d77d2011-12-03 02:00:482375 // Delegate to RequestTransferURL because this is just the generic
2376 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582377 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482378 GlobalRequestID());
2379}
2380
[email protected]b172aee2012-04-10 17:05:262381void WebContentsImpl::RequestTransferURL(
2382 const GURL& url,
2383 const content::Referrer& referrer,
2384 WindowOpenDisposition disposition,
2385 int64 source_frame_id,
2386 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202387 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582388 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582389 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352390 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322391 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2392 // generated suggestions).
2393 //
[email protected]e0112912011-02-02 22:54:352394 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162395 // want web sites to see a referrer of "chrome://blah" (and some
2396 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322397 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432398 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222399 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482400 false /* is_renderer_initiated */);
2401 params.transferred_global_request_id = old_request_id;
2402 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222403 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322404 } else {
[email protected]6bf6a6b52012-02-03 15:41:432405 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482406 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2407 params.transferred_global_request_id = old_request_id;
2408 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582409 }
2410 if (new_contents) {
2411 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252412 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582413 DidOpenRequestedURL(new_contents,
2414 url,
2415 referrer,
2416 disposition,
2417 transition_type,
2418 source_frame_id));
[email protected]420ae012009-04-24 05:16:322419 }
2420}
2421
[email protected]e1c3a552012-05-04 20:51:322422void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2423 // Tell the active RenderViewHost to run unload handlers and close, as long
2424 // as the request came from a RenderViewHost in the same BrowsingInstance.
2425 // In most cases, we receive this from a swapped out RenderViewHost.
2426 // It is possible to receive it from one that has just been swapped in,
2427 // in which case we might as well deliver the message anyway.
2428 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2429 GetRenderViewHost()->ClosePage();
2430}
2431
[email protected]f546640b2012-05-15 00:03:492432void WebContentsImpl::RouteMessageEvent(
2433 RenderViewHost* rvh,
2434 const ViewMsg_PostMessage_Params& params) {
2435 // Only deliver the message to the active RenderViewHost if the request
2436 // came from a RenderViewHost in the same BrowsingInstance.
2437 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2438 return;
2439
2440 ViewMsg_PostMessage_Params new_params(params);
2441
2442 // If there is a source_routing_id, translate it to the routing ID for
2443 // the equivalent swapped out RVH in the target process. If we need
2444 // to create a swapped out RVH for the source tab, we create its opener
2445 // chain as well, since those will also be accessible to the target page.
2446 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2447 // Try to look up the WebContents for the source page.
2448 WebContentsImpl* source_contents = NULL;
2449 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2450 rvh->GetProcess()->GetID(), params.source_routing_id);
2451 if (source_rvh) {
2452 source_contents = static_cast<WebContentsImpl*>(
2453 source_rvh->GetDelegate()->GetAsWebContents());
2454 }
2455
2456 if (source_contents) {
2457 new_params.source_routing_id =
2458 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2459 } else {
2460 // We couldn't find it, so don't pass a source frame.
2461 new_params.source_routing_id = MSG_ROUTING_NONE;
2462 }
2463 }
2464
2465 // In most cases, we receive this from a swapped out RenderViewHost.
2466 // It is possible to receive it from one that has just been swapped in,
2467 // in which case we might as well deliver the message anyway.
2468 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2469 GetRenderViewHost()->GetRoutingID(), new_params));
2470}
2471
[email protected]b172aee2012-04-10 17:05:262472void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342473 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412474 const string16& message,
2475 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322476 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472477 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322478 IPC::Message* reply_msg,
2479 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072480 // Suppress JavaScript dialogs when requested. Also suppress messages when
2481 // showing an interstitial as it's shown over the previous page and we don't
2482 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502483 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582484 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272485 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072486 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522487 delegate_->ShouldSuppressDialogs() ||
2488 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322489
2490 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432491 std::string accept_lang = content::GetContentClient()->browser()->
2492 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552493 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522494 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432495 this,
2496 frame_url.GetOrigin(),
2497 accept_lang,
2498 javascript_message_type,
2499 message,
[email protected]51da7e32012-01-30 19:24:522500 default_prompt,
[email protected]b172aee2012-04-10 17:05:262501 base::Bind(&WebContentsImpl::OnDialogClosed,
2502 base::Unretained(this),
2503 rvh,
2504 reply_msg),
[email protected]51da7e32012-01-30 19:24:522505 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322506 }
[email protected]3ab9cb82011-06-03 18:02:072507
2508 if (suppress_this_message) {
2509 // If we are suppressing messages, just reply as if the user immediately
2510 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342511 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072512 }
2513
2514 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322515}
2516
[email protected]b172aee2012-04-10 17:05:262517void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2518 const string16& message,
2519 bool is_reload,
2520 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582521 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512522 if (delegate_)
2523 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072524
2525 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582526 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072527 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522528 delegate_->ShouldSuppressDialogs() ||
2529 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152530 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342531 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582532 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502533 return;
2534 }
[email protected]3ab9cb82011-06-03 18:02:072535
[email protected]7ab1e7d62009-10-14 23:32:012536 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552537 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522538 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322539 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262540 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522541 reply_msg));
[email protected]420ae012009-04-24 05:16:322542}
2543
[email protected]b172aee2012-04-10 17:05:262544WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332545 // We want to base the page config off of the real URL, rather than the
2546 // display URL.
2547 GURL url = controller_.GetActiveEntry()
2548 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2549 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322550}
2551
[email protected]b172aee2012-04-10 17:05:262552void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272553 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252554 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222555
[email protected]ea114722012-03-12 01:11:252556 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172557 if (rdh) // NULL in unittests.
2558 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252559}
2560
[email protected]b172aee2012-04-10 17:05:262561void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442562 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252563 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2567 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152568 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522569 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152570 return;
2571
[email protected]9f76c1e2012-03-05 15:15:582572 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2573
[email protected]e5fc1632011-08-08 07:51:532574 // Ignore renderer unresponsive event if debugger is attached to the tab
2575 // since the event may be a result of the renderer sitting on a breakpoint.
2576 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442577 DevToolsAgentHost* agent =
2578 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2579 if (agent &&
2580 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532581 return;
2582
[email protected]420ae012009-04-24 05:16:322583 if (is_during_unload) {
2584 // Hang occurred while firing the beforeunload/unload handler.
2585 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582586 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322587
2588 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2589 return;
2590
2591 // If the tab hangs in the beforeunload/unload handler there's really
2592 // nothing we can do to recover. Pretend the unload listeners have
2593 // all fired and close the tab. If the hang is in the beforeunload handler
2594 // then the user will not have the option of cancelling the close.
2595 Close(rvh);
2596 return;
2597 }
2598
[email protected]9f76c1e2012-03-05 15:15:582599 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472600 return;
2601
[email protected]6934a702011-12-20 00:04:512602 if (delegate_)
2603 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322604}
2605
[email protected]b172aee2012-04-10 17:05:262606void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512607 if (delegate_)
2608 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322609}
2610
[email protected]b172aee2012-04-10 17:05:262611void WebContentsImpl::LoadStateChanged(
2612 const GURL& url,
2613 const net::LoadStateWithParam& load_state,
2614 uint64 upload_position,
2615 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322616 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562617 upload_position_ = upload_position;
2618 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502619 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202620 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302621 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212622 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322623 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462624 if (IsLoading()) {
2625 NotifyNavigationStateChanged(
2626 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2627 }
[email protected]420ae012009-04-24 05:16:322628}
2629
[email protected]b172aee2012-04-10 17:05:262630void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512631 if (delegate_)
2632 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252633}
2634
[email protected]b172aee2012-04-10 17:05:262635void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322636 bool proceed,
2637 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512638 if (delegate_)
2639 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322640}
2641
[email protected]b172aee2012-04-10 17:05:262642void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542643 RenderViewHost* render_view_host) {
2644 DidStartLoading();
2645}
2646
[email protected]b172aee2012-04-10 17:05:262647void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542648 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232649 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2650 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542651}
2652
[email protected]b172aee2012-04-10 17:05:262653void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102654 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262655 gfx::Size size = view_->GetContainerSize();
2656 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2657 // here during container initialization and normal window size will be set
2658 // later. In case of tab duplication this resizing to 0x0 prevents setting
2659 // normal size later so just ignore it.
2660 if (!size.IsEmpty())
2661 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322662}
2663
[email protected]b172aee2012-04-10 17:05:262664void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542665 NotifySwapped();
2666}
2667
[email protected]14392a52012-05-02 20:28:442668int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2669 SiteInstance* instance) {
2670 if (!opener_)
2671 return MSG_ROUTING_NONE;
2672
2673 // Recursively create RenderViews for anything else in the opener chain.
2674 return opener_->CreateOpenerRenderViews(instance);
2675}
2676
2677int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2678 int opener_route_id = MSG_ROUTING_NONE;
2679
2680 // If this tab has an opener, ensure it has a RenderView in the given
2681 // SiteInstance as well.
2682 if (opener_)
2683 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2684
2685 // Create a swapped out RenderView in the given SiteInstance if none exists,
2686 // setting its opener to the given route_id. Return the new view's route_id.
2687 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2688}
2689
[email protected]b172aee2012-04-10 17:05:262690NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202691 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542692}
2693
[email protected]b172aee2012-04-10 17:05:262694WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562695 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322696}
2697
[email protected]10f417c52011-12-28 21:04:232698NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262699 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322700 return controller_.GetLastCommittedEntry();
2701}
2702
[email protected]b172aee2012-04-10 17:05:262703bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442704 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442705 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322706 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522707
[email protected]420ae012009-04-24 05:16:322708 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442709 if (rwh_view)
2710 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322711
[email protected]74ce1ad2011-12-16 21:51:462712 // Make sure we use the correct starting page_id in the new RenderView.
2713 UpdateMaxPageIDIfNecessary(render_view_host);
2714 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582715 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462716
[email protected]9f76c1e2012-03-05 15:15:582717 if (!static_cast<RenderViewHostImpl*>(
[email protected]14392a52012-05-02 20:28:442718 render_view_host)->CreateRenderView(string16(), opener_route_id,
2719 max_page_id)) {
[email protected]a4127722011-04-27 23:13:522720 return false;
[email protected]14392a52012-05-02 20:28:442721 }
[email protected]a4127722011-04-27 23:13:522722
[email protected]e60c0232011-11-11 19:56:352723#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502724 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2725 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442726 if (rwh_view) {
2727 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2728 render_widget_host->WasResized();
2729 }
[email protected]f8233cc2011-05-31 20:24:502730#endif
2731
[email protected]420ae012009-04-24 05:16:322732 return true;
2733}
2734
[email protected]b172aee2012-04-10 17:05:262735void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2736 IPC::Message* reply_msg,
2737 bool success,
2738 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542739 if (is_showing_before_unload_dialog_ && !success) {
2740 // If a beforeunload dialog is canceled, we need to stop the throbber from
2741 // spinning, since we forced it to start spinning in Navigate.
2742 DidStopLoading();
2743
[email protected]3bbacc5b2012-04-17 17:46:152744 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542745 }
2746 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582747 static_cast<RenderViewHostImpl*>(
2748 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542749}
2750
[email protected]b172aee2012-04-10 17:05:262751void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122752 encoding_ = content::GetContentClient()->browser()->
2753 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102754}
[email protected]f45d2a72010-03-08 23:28:352755
[email protected]b172aee2012-04-10 17:05:262756void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:462757 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262758 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142759 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2760 if (!dlm)
2761 return;
2762 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262763 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142764 const NavigationEntry* entry = controller_.GetActiveEntry();
2765 if (entry)
2766 post_id = entry->GetPostID();
2767 }
[email protected]29a5ffc82012-03-13 19:35:582768 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142769 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:142770 scoped_ptr<DownloadUrlParameters> params(
2771 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]20b433a2012-05-15 21:23:462772 // TODO(jochen): Pass in the referrer policy as well.
2773 params->set_referrer(referrer.url);
[email protected]c5a5c0842012-05-04 20:05:142774 params->set_post_id(post_id);
2775 params->set_prefer_cache(true);
2776 if (post_id >= 0)
2777 params->set_method("POST");
2778 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:142779}
2780
[email protected]b172aee2012-04-10 17:05:262781void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212782 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442783 // Can be NULL during tests.
2784 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212785 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362786}
[email protected]9f76c1e2012-03-05 15:15:582787
[email protected]b172aee2012-04-10 17:05:262788RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582789 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2790}