blob: d52c3fd6054de63c70759196c3faad7bd2988afe [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]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
[email protected]2bb171882012-03-07 02:09:468#include <utility>
[email protected]b75b8292010-10-01 07:28:259
[email protected]36fb2c7c2011-04-04 15:49:0810#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1812#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5413#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0914#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3715#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5416#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3117#include "base/utf_string_conversions.h"
[email protected]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]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1221#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1622#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3223#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5424#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0525#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0026#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0127#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3229#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2530#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]567812d2011-02-24 17:40:5031#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1333#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2334#include "content/browser/tab_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]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4644#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1545#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2746#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0047#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3849#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4250#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2551#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1052#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5053#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2154#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1856#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5457#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1659#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2960#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5461#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3462#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3763#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3864#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2465#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3166#include "webkit/glue/webpreferences.h"
67
[email protected]38b098f2012-03-14 21:11:5768#if defined(OS_WIN) && !defined(USE_AURA)
69#include "content/browser/tab_contents/tab_contents_view_win.h"
70#elif defined(TOOLKIT_GTK)
71#include "content/browser/tab_contents/tab_contents_view_gtk.h"
72#elif defined(OS_MACOSX)
73#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]b9b751f22011-03-25 14:04:1274#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5775#elif defined(OS_ANDROID)
76#include "content/browser/tab_contents/web_contents_view_android.h"
77#endif
[email protected]3e45ba92009-02-20 21:09:0078
[email protected]420ae012009-04-24 05:16:3279// Cross-Site Navigations
80//
81// If a TabContents is told to navigate to a different web site (as determined
82// by SiteInstance), it will replace its current RenderViewHost with a new
83// RenderViewHost dedicated to the new SiteInstance. This works as follows:
84//
85// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4686// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3287// - The pending RVH is "suspended," so that no navigation messages are sent to
88// its renderer until the onbeforeunload JavaScript handler has a chance to
89// run in the current RVH.
90// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
91// that it has a pending cross-site request. ResourceDispatcherHost will
92// check for this when the response arrives.
93// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4694// cancel all the pending logic. Otherwise we allow the pending RVH to send
95// the navigation request to its renderer.
96// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
97// main resource load on the pending RVH. It checks CrossSiteRequestManager
98// to see that it is a cross-site request, and installs a
99// CrossSiteResourceHandler.
100// - When RDH receives a response, the BufferedResourceHandler determines
101// whether it is a download. If so, it sends a message to the new renderer
102// causing it to cancel the request, and the download proceeds. For now, the
103// pending RVH remains until the next DidNavigate event for this TabContents.
104// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32105// - After RDH receives a response and determines that it is safe and not a
106// download, it pauses the response to first run the old page's onunload
107// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15108// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32109// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15110// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32111// the ResourceDispatcherHost, who unpauses the response. Data is then sent
112// to the pending RVH.
113// - The pending renderer sends a FrameNavigate message that invokes the
114// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46115// pending RVH.
[email protected]992db4c2011-05-12 15:37:15116// - The previous renderer is kept swapped out in RenderViewHostManager in case
117// the user goes back. The process only stays live if another tab is using
118// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32119
[email protected]0e12d7d2011-12-01 16:21:44120using content::DevToolsAgentHost;
121using content::DevToolsAgentHostRegistry;
122using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17123using content::DownloadItem;
124using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20125using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56126using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13127using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27128using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50129using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23130using content::NavigationEntry;
131using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20132using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11133using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57134using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27135using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11136using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58137using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04138using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25139using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43140using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33141using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17142using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38143using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09144using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25145using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56146using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22147using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50148using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44149
[email protected]420ae012009-04-24 05:16:32150namespace {
151
152// Amount of time we wait between when a key event is received and the renderer
153// is queried for its state and pushed to the NavigationEntry.
154const int kQueryStateDelay = 5000;
155
[email protected]6ebdc9b2010-09-27 16:55:57156const int kSyncWaitDelay = 40;
157
[email protected]ca406032011-07-19 21:53:05158static const char kDotGoogleDotCom[] = ".google.com";
159
[email protected]420ae012009-04-24 05:16:32160#if defined(OS_WIN)
161
162BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
163 // Note: erase is required to properly paint some widgets borders. This can
164 // be seen with textfields.
165 InvalidateRect(hwnd, NULL, TRUE);
166 return TRUE;
167}
168#endif
169
[email protected]2c5569662011-03-22 20:45:02170ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23171 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50172 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16173 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47174 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02175 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47176 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02177 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16179 break; // Fall through to rest of function.
180 }
[email protected]5e369672009-11-03 23:48:30181
[email protected]59246c572012-02-10 13:32:13182 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
183 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23184 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13185 browser_context->DidLastSessionExitCleanly()) {
186 if (entry.GetHasPostData())
187 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13189 }
[email protected]5e369672009-11-03 23:48:30190
[email protected]2c5569662011-03-22 20:45:02191 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30192}
193
[email protected]10f417c52011-12-28 21:04:23194void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47195 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42196 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50197 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16198 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51199 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54200 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55201 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
202 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51203 params->url = entry.GetURL();
204 params->referrer = entry.GetReferrer();
205 params->transition = entry.GetTransitionType();
206 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00207 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55208 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34209 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47210 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48211 params->transferred_request_child_id =
212 entry.transferred_global_request_id().child_id;
213 params->transferred_request_request_id =
214 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47215
216 if (delegate)
217 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34218}
219
[email protected]420ae012009-04-24 05:16:32220} // namespace
221
[email protected]a81343d232011-12-27 07:39:20222namespace content {
223
224WebContents* WebContents::Create(
225 BrowserContext* browser_context,
226 SiteInstance* site_instance,
227 int routing_id,
228 const WebContents* base_tab_contents,
229 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43230 return new TabContents(
231 browser_context,
232 site_instance,
233 routing_id,
234 static_cast<const TabContents*>(base_tab_contents),
235 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20236}
237}
[email protected]f4f50ef2011-01-21 19:01:19238
239// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32240
[email protected]3d7474ff2011-07-27 17:47:37241TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32242 SiteInstance* site_instance,
243 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07244 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43245 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42246 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07247 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37248 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22249 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34250 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23251 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
252 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34253 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21254 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56255 upload_size_(0),
256 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47257 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57258 capturing_contents_(false),
259 is_being_destroyed_(false),
260 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55261 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57262#if defined(OS_WIN)
263 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
264#endif
[email protected]7ab1e7d62009-10-14 23:32:01265 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56266 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38267 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25268 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01269 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25270 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01271 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00272 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43273 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50274 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
[email protected]dd8678f2012-03-15 13:14:03275 has_opener_(false) {
[email protected]3d7474ff2011-07-27 17:47:37276 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32277
[email protected]38b098f2012-03-14 21:11:57278 view_.reset(content::GetContentClient()->browser()->
279 OverrideCreateWebContentsView(this));
280 if (!view_.get()) {
281 content::WebContentsViewDelegate* delegate =
282 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
283 this);
284#if defined(OS_WIN) && !defined(USE_AURA)
285 view_.reset(new TabContentsViewWin(this, delegate));
286#elif defined(TOOLKIT_GTK)
287 view_.reset(new content::TabContentsViewGtk(this, delegate));
288#elif defined(OS_MACOSX)
289 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
290#elif defined(OS_ANDROID)
291 view_.reset(new WebContentsViewAndroid(this));
292#endif
[email protected]dbd407f2012-03-14 21:30:37293 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57294 }
295 CHECK(view_.get());
296
[email protected]34ac70502009-09-25 17:07:23297 // We have the initial size of the view be based on the size of the passed in
298 // tab contents (normally a tab from the same window).
299 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21300 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00301
302#if defined(ENABLE_JAVA_BRIDGE)
303 java_bridge_dispatcher_host_manager_.reset(
304 new JavaBridgeDispatcherHostManager(this));
305#endif
[email protected]332af7732009-03-11 13:21:35306}
initial.commit09911bf2008-07-26 23:55:29307
308TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32309 is_being_destroyed_ = true;
310
[email protected]3ab9cb82011-06-03 18:02:07311 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55312 if (dialog_creator_)
313 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07314
[email protected]420ae012009-04-24 05:16:32315 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32316
[email protected]420ae012009-04-24 05:16:32317 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07318 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09319 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
320 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07321 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32322
323 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07324#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32325 // If we still have a window handle, destroy it. GetNativeView can return
326 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42327 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52328 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58329 if (host && host->GetView())
330 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42331 }
[email protected]420ae012009-04-24 05:16:32332#endif
[email protected]7ab1e7d62009-10-14 23:32:01333
334 // OnCloseStarted isn't called in unit tests.
335 if (!tab_close_start_time_.is_null()) {
336 UMA_HISTOGRAM_TIMES("Tab.Close",
337 base::TimeTicks::Now() - tab_close_start_time_);
338 }
[email protected]b5a1d11c2011-02-17 03:09:42339
[email protected]d8c660432011-12-22 20:51:25340 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08341
[email protected]6934a702011-12-20 00:04:51342 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42343}
344
[email protected]64d69de42012-02-06 00:19:54345WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
346 const GURL& url) {
347 WebPreferences prefs;
348
349 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
350
351 prefs.developer_extras_enabled = true;
352 prefs.javascript_enabled =
353 !command_line.HasSwitch(switches::kDisableJavaScript);
354 prefs.web_security_enabled =
355 !command_line.HasSwitch(switches::kDisableWebSecurity);
356 prefs.plugins_enabled =
357 !command_line.HasSwitch(switches::kDisablePlugins);
358 prefs.java_enabled =
359 !command_line.HasSwitch(switches::kDisableJava);
360
361 prefs.uses_page_cache =
362 command_line.HasSwitch(switches::kEnableFastback);
363 prefs.remote_fonts_enabled =
364 !command_line.HasSwitch(switches::kDisableRemoteFonts);
365 prefs.xss_auditor_enabled =
366 !command_line.HasSwitch(switches::kDisableXSSAuditor);
367 prefs.application_cache_enabled =
368 !command_line.HasSwitch(switches::kDisableApplicationCache);
369
370 prefs.local_storage_enabled =
371 !command_line.HasSwitch(switches::kDisableLocalStorage);
372 prefs.databases_enabled =
373 !command_line.HasSwitch(switches::kDisableDatabases);
374 prefs.webaudio_enabled =
375 !command_line.HasSwitch(switches::kDisableWebAudio);
376
377 prefs.experimental_webgl_enabled =
378 GpuProcessHost::gpu_enabled() &&
379 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
380 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
381
382 prefs.gl_multisampling_enabled =
383 !command_line.HasSwitch(switches::kDisableGLMultisampling);
384 prefs.privileged_webgl_extensions_enabled =
385 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
386 prefs.site_specific_quirks_enabled =
387 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
388 prefs.allow_file_access_from_file_urls =
389 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
390 prefs.show_composited_layer_borders =
391 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
392 prefs.show_composited_layer_tree =
393 command_line.HasSwitch(switches::kShowCompositedLayerTree);
394 prefs.show_fps_counter =
395 command_line.HasSwitch(switches::kShowFPSCounter);
396 prefs.accelerated_compositing_enabled =
397 GpuProcessHost::gpu_enabled() &&
398 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
399 prefs.threaded_compositing_enabled =
400 command_line.HasSwitch(switches::kEnableThreadedCompositing);
401 prefs.force_compositing_mode =
402 command_line.HasSwitch(switches::kForceCompositingMode);
403 prefs.fixed_position_compositing_enabled =
404 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
405 prefs.accelerated_2d_canvas_enabled =
406 GpuProcessHost::gpu_enabled() &&
407 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58408 prefs.deferred_2d_canvas_enabled =
409 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36410 prefs.threaded_animation_enabled =
411 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54412 prefs.accelerated_painting_enabled =
413 GpuProcessHost::gpu_enabled() &&
414 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
415 prefs.accelerated_filters_enabled =
416 GpuProcessHost::gpu_enabled() &&
417 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
418 prefs.accelerated_layers_enabled =
419 prefs.accelerated_animation_enabled =
420 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
421 prefs.composite_to_texture_enabled =
422 command_line.HasSwitch(switches::kEnableCompositeToTexture);
423 prefs.accelerated_plugins_enabled =
424 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
425 prefs.accelerated_video_enabled =
426 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
427 prefs.partial_swap_enabled =
428 command_line.HasSwitch(switches::kEnablePartialSwap);
429 prefs.interactive_form_validation_enabled =
430 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
431 prefs.fullscreen_enabled =
432 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16433 prefs.css_regions_enabled =
434 command_line.HasSwitch(switches::kEnableCssRegions);
435
[email protected]64d69de42012-02-06 00:19:54436
437#if defined(OS_MACOSX)
438 bool default_enable_scroll_animator = true;
439#else
440 // On CrOS, the launcher always passes in the --enable flag.
441 bool default_enable_scroll_animator = false;
442#endif
443 prefs.enable_scroll_animator = default_enable_scroll_animator;
444 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
445 prefs.enable_scroll_animator = true;
446 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
447 prefs.enable_scroll_animator = false;
448
449 prefs.visual_word_movement_enabled =
450 command_line.HasSwitch(switches::kEnableVisualWordMovement);
451 prefs.per_tile_painting_enabled =
452 command_line.HasSwitch(switches::kEnablePerTilePainting);
453
454 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32455 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54456 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11457 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
458 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54459 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11460 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54461 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11462 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54463 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11464 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54465 prefs.gl_multisampling_enabled = false;
466
467 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45468 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32469 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54470 prefs.accelerated_video_enabled = false;
471 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45472 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54473 }
474 }
475
[email protected]b9535422012-02-09 01:47:59476 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58477 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54478 prefs.loads_images_automatically = true;
479 prefs.javascript_enabled = true;
480 }
481
482 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
483
484 // Force accelerated compositing and 2d canvas off for chrome:, about: and
485 // chrome-devtools: pages (unless it's specifically allowed).
486 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54487 url.SchemeIs(chrome::kChromeUIScheme) ||
488 (url.SchemeIs(chrome::kAboutScheme) &&
489 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25490 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54491 prefs.accelerated_compositing_enabled = false;
492 prefs.accelerated_2d_canvas_enabled = false;
493 }
494
[email protected]43d9d782012-03-01 15:40:09495 int default_device_scale_factor;
496 base::StringToInt(command_line.GetSwitchValueASCII(
497 switches::kDefaultDeviceScaleFactor),
498 &default_device_scale_factor);
499
500 prefs.default_device_scale_factor = default_device_scale_factor;
501
[email protected]2e21fe292012-03-02 22:52:32502 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54503
504 return prefs;
505}
506
[email protected]d202a7c2012-01-04 07:53:47507NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20508 return controller_;
509}
510
[email protected]765187182012-01-11 23:59:28511RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
512 return &render_manager_;
513}
514
[email protected]724159a2010-12-30 01:11:18515bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56516 if (GetWebUI() &&
517 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17518 return true;
[email protected]d2353452012-01-19 19:53:56519 }
[email protected]f82d57b52011-04-27 19:13:17520
[email protected]d8c660432011-12-22 20:51:25521 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
522 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10523 while ((observer = it.GetNext()) != NULL)
524 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53525 return true;
[email protected]403415a2011-01-10 18:57:53526
[email protected]724159a2010-12-30 01:11:18527 bool handled = true;
528 bool message_is_ok = true;
529 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58530 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
531 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24532 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
533 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
535 OnDidStartProvisionalLoadForFrame)
536 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
537 OnDidRedirectProvisionalLoad)
538 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
539 OnDidFailProvisionalLoadWithError)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
541 OnDidLoadResourceFromMemoryCache)
542 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
543 OnDidDisplayInsecureContent)
544 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
545 OnDidRunInsecureContent)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
547 OnDocumentLoadedInFrame)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17549 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
550 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25551 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26552 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59553 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21554 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20555 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
557 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16558 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45559 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10560 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18561 IPC_MESSAGE_UNHANDLED(handled = false)
562 IPC_END_MESSAGE_MAP_EX()
563
564 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38565 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18566 GetRenderProcessHost()->ReceivedBadMessage();
567 }
568
569 return handled;
570}
571
[email protected]6c2e472f2011-08-24 23:26:18572void TabContents::RunFileChooser(
573 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23574 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51575 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18576}
577
[email protected]c5eed492012-01-04 17:07:50578NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56579 return controller_;
580}
581
[email protected]c5eed492012-01-04 17:07:50582const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56583 return controller_;
584}
585
[email protected]627e0512011-12-21 22:55:30586content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55587 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30588}
589
[email protected]f5fa20e2011-12-21 22:35:56590void TabContents::SetViewType(content::ViewType type) {
591 view_type_ = type;
592}
593
[email protected]ea049a02011-12-25 21:37:09594content::ViewType TabContents::GetViewType() const {
595 return view_type_;
596}
597
[email protected]be1f56ab2011-12-22 06:55:31598const GURL& TabContents::GetURL() const {
599 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23600 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51601 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31602}
603
604
605const base::PropertyBag* TabContents::GetPropertyBag() const {
606 return &property_bag_;
607}
608
609base::PropertyBag* TabContents::GetPropertyBag() {
610 return &property_bag_;
611}
612
613content::WebContentsDelegate* TabContents::GetDelegate() {
614 return delegate_;
615}
616
617void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
618 // TODO(cbentzel): remove this debugging code?
619 if (delegate == delegate_)
620 return;
621 if (delegate_)
622 delegate_->Detach(this);
623 delegate_ = delegate;
624 if (delegate_)
625 delegate_->Attach(this);
626}
627
[email protected]f3b1a082011-11-18 00:34:30628content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03629 if (render_manager_.current_host())
[email protected]9f76c1e2012-03-05 15:15:58630 return render_manager_.current_host()->GetProcess();
[email protected]4d0df262011-10-03 20:05:03631 else
632 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16633}
634
[email protected]be1f56ab2011-12-22 06:55:31635RenderViewHost* TabContents::GetRenderViewHost() const {
636 return render_manager_.current_host();
637}
638
639RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
640 return render_manager_.GetRenderWidgetHostView();
641}
642
[email protected]8643e6d2012-01-18 20:26:10643content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31644 return view_.get();
645}
646
[email protected]01ec4ec2012-01-18 04:13:47647content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50648 WebUIControllerFactory* factory =
649 content::GetContentClient()->browser()->GetWebUIControllerFactory();
650 if (!factory)
651 return NULL;
[email protected]d2353452012-01-19 19:53:56652 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22653 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50654 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22655 if (controller) {
656 web_ui->SetController(controller);
657 return web_ui;
658 }
659
660 delete web_ui;
661 return NULL;
662}
663
[email protected]01ec4ec2012-01-18 04:13:47664content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31665 return render_manager_.web_ui() ? render_manager_.web_ui()
666 : render_manager_.pending_web_ui();
667}
668
[email protected]01ec4ec2012-01-18 04:13:47669content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31670 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34671}
672
[email protected]96d185d2009-04-24 03:28:54673const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55674 // Transient entries take precedence. They are used for interstitial pages
675 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23676 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08677 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20678 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30679 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23680 if (entry) {
[email protected]b5cca982011-05-26 04:42:08681 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23682 }
[email protected]7ade2732011-02-10 00:13:58683 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
684 render_manager_.pending_web_ui() : render_manager_.web_ui();
685 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54686 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55687 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54688 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35689 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22690 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54691 if (!title.empty())
692 return title;
693 }
694 }
695
696 // We use the title for the last committed entry rather than a pending
697 // navigation entry. For example, when the user types in a URL, we want to
698 // keep the old page's title until the new load has committed and we get a new
699 // title.
[email protected]96d185d2009-04-24 03:28:54700 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23701 if (entry) {
[email protected]b5cca982011-05-26 04:42:08702 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23703 }
[email protected]987fc3a2011-05-26 14:18:09704
705 // |page_title_when_no_navigation_entry_| is finally used
706 // if no title cannot be retrieved.
707 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54708}
709
[email protected]d5f942ba2008-09-26 19:30:34710int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46711 return GetMaxPageIDForSiteInstance(GetSiteInstance());
712}
713
714int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33715 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
716 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46717
[email protected]b6583592012-01-25 19:52:33718 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34719}
720
721void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46722 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
723}
724
[email protected]b6583592012-01-25 19:52:33725void TabContents::UpdateMaxPageIDForSiteInstance(
726 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46727 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33728 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34729}
730
[email protected]91854cd2012-01-10 19:43:57731void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
732 max_page_ids_ = tab_contents->max_page_ids_;
733}
734
[email protected]96d185d2009-04-24 03:28:54735SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58736 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54737}
738
[email protected]77362eb2011-08-01 17:18:38739SiteInstance* TabContents::GetPendingSiteInstance() const {
740 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
741 render_manager_.pending_render_view_host() :
742 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58743 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38744}
745
[email protected]be1f56ab2011-12-22 06:55:31746bool TabContents::IsLoading() const {
747 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49748}
749
[email protected]be1f56ab2011-12-22 06:55:31750bool TabContents::IsWaitingForResponse() const {
751 return waiting_for_response_;
752}
753
754const net::LoadStateWithParam& TabContents::GetLoadState() const {
755 return load_state_;
756}
757
758const string16& TabContents::GetLoadStateHost() const {
759 return load_state_host_;
760}
761
762uint64 TabContents::GetUploadSize() const {
763 return upload_size_;
764}
765
766uint64 TabContents::GetUploadPosition() const {
767 return upload_position_;
768}
769
770const std::string& TabContents::GetEncoding() const {
771 return encoding_;
772}
773
774bool TabContents::DisplayedInsecureContent() const {
775 return displayed_insecure_content_;
776}
777
778void TabContents::SetCapturingContents(bool cap) {
779 capturing_contents_ = cap;
780}
781
782bool TabContents::IsCrashed() const {
783 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
784 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
785 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49786}
787
[email protected]443b80e2010-12-14 00:42:23788void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
789 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34790 return;
791
[email protected]443b80e2010-12-14 00:42:23792 crashed_status_ = status;
793 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46794 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34795}
796
[email protected]be1f56ab2011-12-22 06:55:31797base::TerminationStatus TabContents::GetCrashedStatus() const {
798 return crashed_status_;
799}
800
801bool TabContents::IsBeingDestroyed() const {
802 return is_being_destroyed_;
803}
804
[email protected]d5f942ba2008-09-26 19:30:34805void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
806 if (delegate_)
807 delegate_->NavigationStateChanged(this, changed_flags);
808}
809
[email protected]96d185d2009-04-24 03:28:54810void TabContents::DidBecomeSelected() {
811 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04812 RenderWidgetHostViewPort* rwhv =
813 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16814 if (rwhv) {
815 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43816#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16817 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43818#endif
819 }
[email protected]96d185d2009-04-24 03:28:54820
[email protected]5ac20162010-11-24 23:33:11821 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38822
[email protected]d8c660432011-12-22 20:51:25823 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59824
825 // The resize rect might have changed while this was inactive -- send the new
826 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58827 RenderViewHostImpl* rvh =
828 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59829 if (rvh) {
830 rvh->ResizeRectChanged(GetRootWindowResizerRect());
831 }
[email protected]96d185d2009-04-24 03:28:54832}
833
[email protected]be1f56ab2011-12-22 06:55:31834
835base::TimeTicks TabContents::GetLastSelectedTime() const {
836 return last_selected_time_;
837}
838
[email protected]96d185d2009-04-24 03:28:54839void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31840 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52841 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
842 // open a tab in then background, then closes the tab before selecting it.
843 // This is because closing the tab calls TabContents::Destroy(), which
844 // removes the |GetRenderViewHost()|; then when we actually destroy the
845 // window, OnWindowPosChanged() notices and calls HideContents() (which
846 // calls us).
[email protected]c30585c2012-02-16 15:02:04847 RenderWidgetHostViewPort* rwhv =
848 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16849 if (rwhv)
850 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54851 }
852
[email protected]ad50def52011-10-19 23:17:07853 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09854 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
855 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07856 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54857}
858
[email protected]be1f56ab2011-12-22 06:55:31859void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04860 RenderWidgetHostViewPort* rwhv =
861 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31862 if (rwhv)
863 rwhv->DidBecomeSelected();
864}
865
866void TabContents::HideContents() {
867 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
868 // our superclass HideContents(), because some callers want to be very picky
869 // about the order in which these get called. In addition to making the code
870 // here practically impossible to understand, this also means we end up
871 // calling TabContents::WasHidden() twice if callers call both versions of
872 // HideContents() on a TabContents.
873 WasHidden();
874}
875
876bool TabContents::NeedToFireBeforeUnload() {
877 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27878 return WillNotifyDisconnection() &&
879 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58880 !static_cast<RenderViewHostImpl*>(
881 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31882}
883
[email protected]0bfbf882011-12-22 18:19:27884void TabContents::Stop() {
885 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25886 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27887}
888
[email protected]d9083482012-01-06 00:38:46889WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27890 // We create a new SiteInstance so that the new tab won't share processes
891 // with the old one. This can be changed in the future if we need it to share
892 // processes for some reason.
893 TabContents* tc = new TabContents(
894 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33895 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27896 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20897 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27898 return tc;
899}
900
[email protected]2a6bc3e2011-12-28 23:51:33901void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27902 WindowOpenDisposition disposition,
903 const gfx::Rect& initial_pos,
904 bool user_gesture) {
905 if (!delegate_)
906 return;
907
908 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
909 user_gesture);
910}
911
912gfx::NativeView TabContents::GetContentNativeView() const {
913 return view_->GetContentNativeView();
914}
915
916gfx::NativeView TabContents::GetNativeView() const {
917 return view_->GetNativeView();
918}
919
920void TabContents::GetContainerBounds(gfx::Rect* out) const {
921 view_->GetContainerBounds(out);
922}
923
924void TabContents::Focus() {
925 view_->Focus();
926}
927
[email protected]d8c660432011-12-22 20:51:25928void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31929 observers_.AddObserver(observer);
930}
931
[email protected]d8c660432011-12-22 20:51:25932void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31933 observers_.RemoveObserver(observer);
934}
935
[email protected]d5f942ba2008-09-26 19:30:34936void TabContents::Activate() {
937 if (delegate_)
938 delegate_->ActivateContents(this);
939}
940
[email protected]ea42e7782010-08-23 23:58:12941void TabContents::Deactivate() {
942 if (delegate_)
943 delegate_->DeactivateContents(this);
944}
945
[email protected]63954792011-07-11 04:17:48946void TabContents::LostCapture() {
947 if (delegate_)
948 delegate_->LostCapture();
949}
950
951bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
952 bool* is_keyboard_shortcut) {
953 return delegate_ &&
954 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
955}
956
957void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
958 if (delegate_)
959 delegate_->HandleKeyboardEvent(event);
960}
961
[email protected]32ded2212011-11-10 18:51:43962void TabContents::HandleMouseDown() {
963 if (delegate_)
964 delegate_->HandleMouseDown();
965}
966
[email protected]63954792011-07-11 04:17:48967void TabContents::HandleMouseUp() {
968 if (delegate_)
969 delegate_->HandleMouseUp();
970}
971
972void TabContents::HandleMouseActivate() {
973 if (delegate_)
974 delegate_->HandleMouseActivate();
975}
976
[email protected]8a5e0ca2011-08-25 06:30:47977void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
978 if (delegate_)
979 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
980}
981
[email protected]5d5f7af2011-10-01 01:38:12982bool TabContents::IsFullscreenForCurrentTab() const {
983 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
984}
985
[email protected]e9621112011-10-17 05:38:37986void TabContents::RequestToLockMouse() {
987 if (delegate_) {
988 delegate_->RequestToLockMouse(this);
989 } else {
990 GotResponseToLockMouseRequest(false);
991 }
992}
993
994void TabContents::LostMouseLock() {
995 if (delegate_)
996 delegate_->LostMouseLock();
997}
998
[email protected]0548c5352011-09-07 00:33:33999void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231000 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331001 if (delegate_)
1002 delegate_->UpdatePreferredSize(this, pref_size);
1003}
1004
[email protected]61e2b3cc2012-03-02 16:13:341005void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
1006 if (delegate_)
1007 delegate_->ResizeDueToAutoResize(this, new_size);
1008}
1009
[email protected]32ded2212011-11-10 18:51:431010void TabContents::WebUISend(RenderViewHost* render_view_host,
1011 const GURL& source_url,
1012 const std::string& name,
1013 const base::ListValue& args) {
1014 if (delegate_)
1015 delegate_->WebUISend(this, source_url, name, args);
1016}
1017
[email protected]e5d549d2011-12-28 01:29:201018WebContents* TabContents::OpenURL(const OpenURLParams& params) {
1019 if (!delegate_)
1020 return NULL;
[email protected]00c37fc2011-08-02 00:22:501021
[email protected]e5d549d2011-12-28 01:29:201022 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1023 // Notify observers.
1024 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1025 DidOpenURL(params.url, params.referrer,
1026 params.disposition, params.transition));
1027 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341028}
1029
[email protected]1ccb3568d2010-02-19 10:51:161030bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501031 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251032 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231033 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251034 reload_type);
[email protected]876bc832010-09-07 16:29:541035}
[email protected]96d185d2009-04-24 03:28:541036
[email protected]876bc832010-09-07 16:29:541037bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231038 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501039 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401040 // The renderer will reject IPC messages with URLs longer than
1041 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511042 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401043 return false;
1044
[email protected]9f76c1e2012-03-05 15:15:581045 RenderViewHostImpl* dest_render_view_host =
1046 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401047 if (!dest_render_view_host)
1048 return false; // Unable to create the desired render view host.
1049
[email protected]80a8fad2011-01-29 04:02:381050 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071051 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581052 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501053 WebUIControllerFactory* factory =
1054 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1055 bool is_allowed_in_web_ui_renderer =
1056 factory &&
1057 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431058#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511059 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431060#endif
[email protected]e091df82011-10-11 18:13:211061 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551062 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581063
[email protected]96d185d2009-04-24 03:28:541064 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441065 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521066 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441067 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511068 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541069
1070 // Used for page load time metrics.
1071 current_load_start_ = base::TimeTicks::Now();
1072
1073 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341074 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271075 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471076 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341077 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541078
[email protected]36fc0392011-12-25 03:59:511079 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541080 // HACK!! This code suppresses javascript: URLs from being added to
1081 // session history, which is what we want to do for javascript: URLs that
1082 // do not generate content. What we really need is a message from the
1083 // renderer telling us that a new page was not created. The same message
1084 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511085 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541086 return false;
1087 }
1088
[email protected]3c9e1872010-11-18 16:17:491089 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251090 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041091 observers_,
[email protected]36fc0392011-12-25 03:59:511092 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541093
[email protected]09b29342011-06-24 19:18:481094 if (delegate_)
1095 delegate_->DidNavigateToPendingEntry(this);
1096
[email protected]d5f942ba2008-09-26 19:30:341097 return true;
1098}
1099
[email protected]b6583592012-01-25 19:52:331100void TabContents::SetHistoryLengthAndPrune(
1101 const SiteInstance* site_instance,
1102 int history_length,
1103 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411104 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1105 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191106 if (render_manager_.pending_render_view_host()) {
1107 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141108 return;
[email protected]9e1ad4b2011-08-14 16:49:191109 }
[email protected]9f76c1e2012-03-05 15:15:581110 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191111 if (!rvh) {
1112 NOTREACHED();
1113 return;
1114 }
[email protected]9f76c1e2012-03-05 15:15:581115 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191116 NOTREACHED();
1117 return;
1118 }
[email protected]9f76c1e2012-03-05 15:15:581119 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191120 history_length,
1121 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141122}
1123
[email protected]90daadb42009-06-08 21:27:281124void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271125 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541126 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1127 return;
1128 }
[email protected]9f76c1e2012-03-05 15:15:581129 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541130}
1131
[email protected]0bfbf882011-12-22 18:19:271132bool TabContents::ShowingInterstitialPage() const {
1133 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541134}
1135
[email protected]0bfbf882011-12-22 18:19:271136InterstitialPage* TabContents::GetInterstitialPage() const {
1137 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221138}
1139
[email protected]a53209b2012-01-20 16:48:161140bool TabContents::IsSavable() {
1141 // WebKit creates Document object when MIME type is application/xhtml+xml,
1142 // so we also support this MIME type.
1143 return contents_mime_type_ == "text/html" ||
1144 contents_mime_type_ == "text/xml" ||
1145 contents_mime_type_ == "application/xhtml+xml" ||
1146 contents_mime_type_ == "text/plain" ||
1147 contents_mime_type_ == "text/css" ||
1148 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1149}
1150
[email protected]c7dd2f62011-07-18 15:57:591151void TabContents::OnSavePage() {
1152 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161153 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481154 download_stats::RecordDownloadSource(
1155 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261156 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141157 return;
[email protected]c7dd2f62011-07-18 15:57:591158 }
1159
1160 Stop();
1161
1162 // Create the save package and possibly prompt the user for the name to save
1163 // the page as. The user prompt is an asynchronous operation that runs on
1164 // another thread.
1165 save_package_ = new SavePackage(this);
1166 save_package_->GetSaveInfo();
1167}
1168
1169// Used in automated testing to bypass prompting the user for file names.
1170// Instead, the names and paths are hard coded rather than running them through
1171// file name sanitation and extension / mime checking.
1172bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161173 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591174 // Stop the page from navigating.
1175 Stop();
1176
1177 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1178 return save_package_->Init();
1179}
1180
[email protected]aa4f3972012-03-01 18:12:121181void TabContents::GenerateMHTML(
1182 const FilePath& file,
1183 const base::Callback<void(const FilePath&, int64)>& callback) {
1184 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1185}
1186
[email protected]420ae012009-04-24 05:16:321187bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231188 NavigationEntryImpl* active_entry =
1189 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321190 return (active_entry != NULL &&
1191 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511192 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321193}
1194
[email protected]0bfbf882011-12-22 18:19:271195const std::string& TabContents::GetContentsMimeType() const {
1196 return contents_mime_type_;
1197}
1198
1199bool TabContents::WillNotifyDisconnection() const {
1200 return notify_disconnection_;
1201}
1202
[email protected]b2fe07d12010-02-09 14:38:081203void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311204 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581205 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1206 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161207}
1208
[email protected]b2fe07d12010-02-09 14:38:081209void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311210 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581211 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1212 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161213}
1214
[email protected]0bfbf882011-12-22 18:19:271215content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1216 return &renderer_preferences_;
1217}
1218
1219void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1220 new_tab_start_time_ = time;
1221}
1222
1223base::TimeTicks TabContents::GetNewTabStartTime() const {
1224 return new_tab_start_time_;
1225}
1226
[email protected]7ab1e7d62009-10-14 23:32:011227void TabContents::OnCloseStarted() {
1228 if (tab_close_start_time_.is_null())
1229 tab_close_start_time_ = base::TimeTicks::Now();
1230}
1231
[email protected]46624bf2010-06-09 16:04:191232bool TabContents::ShouldAcceptDragAndDrop() const {
1233#if defined(OS_CHROMEOS)
1234 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1235 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511236 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201237 return false;
1238 return true;
[email protected]46624bf2010-06-09 16:04:191239#else
1240 return true;
1241#endif
1242}
1243
[email protected]7813bd72011-02-05 02:19:341244void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521245 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581246 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511247 if (delegate_)
1248 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341249}
1250
[email protected]0bfbf882011-12-22 18:19:271251void TabContents::SetClosedByUserGesture(bool value) {
1252 closed_by_user_gesture_ = value;
1253}
1254
1255bool TabContents::GetClosedByUserGesture() const {
1256 return closed_by_user_gesture_;
1257}
1258
[email protected]d0b8d092010-10-25 04:05:171259double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051260 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561261 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251262 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171263 return 0;
[email protected]b75b8292010-10-01 07:28:251264
1265 double zoom_level;
1266 if (temporary_zoom_settings_) {
1267 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581268 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251269 } else {
[email protected]2ae88d12011-10-14 09:11:191270 GURL url;
[email protected]10f417c52011-12-28 21:04:231271 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191272 // Since zoom map is updated using rewritten URL, use rewritten URL
1273 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511274 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191275 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251276 }
[email protected]d0b8d092010-10-25 04:05:171277 return zoom_level;
1278}
[email protected]b75b8292010-10-01 07:28:251279
[email protected]d0b8d092010-10-25 04:05:171280int TabContents::GetZoomPercent(bool* enable_increment,
1281 bool* enable_decrement) {
1282 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011283 // Calculate the zoom percent from the factor. Round up to the nearest whole
1284 // number.
[email protected]b75b8292010-10-01 07:28:251285 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011286 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251287 *enable_decrement = percent > minimum_zoom_percent_;
1288 *enable_increment = percent < maximum_zoom_percent_;
1289 return percent;
1290}
1291
[email protected]3c733bde2010-12-21 19:56:311292void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501293 if (!delegate_)
1294 return;
1295
[email protected]10f417c52011-12-28 21:04:231296 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501297 if (!active_entry)
1298 return;
1299
[email protected]36fc0392011-12-25 03:59:511300 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121301}
1302
[email protected]932b7a12011-03-09 12:50:271303void TabContents::ViewFrameSource(const GURL& url,
1304 const std::string& content_state) {
1305 if (!delegate_)
1306 return;
1307
1308 delegate_->ViewSourceForFrame(this, url, content_state);
1309}
1310
[email protected]0bfbf882011-12-22 18:19:271311int TabContents::GetMinimumZoomPercent() const {
1312 return minimum_zoom_percent_;
1313}
1314
1315int TabContents::GetMaximumZoomPercent() const {
1316 return maximum_zoom_percent_;
1317}
1318
[email protected]bcd2815602012-01-14 18:17:231319gfx::Size TabContents::GetPreferredSize() const {
1320 return preferred_size_;
1321}
1322
[email protected]0bfbf882011-12-22 18:19:271323int TabContents::GetContentRestrictions() const {
1324 return content_restrictions_;
1325}
1326
1327WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501328 WebUIControllerFactory* factory =
1329 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1330 if (!factory)
1331 return WebUI::kNoWebUI;
1332 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271333}
1334
[email protected]01ec4ec2012-01-18 04:13:471335content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271336 // When there is a pending navigation entry, we want to use the pending WebUI
1337 // that goes along with it to control the basic flags. For example, we want to
1338 // show the pending URL in the URL bar, so we want the display_url flag to
1339 // be from the pending entry.
1340 //
1341 // The confusion comes because there are multiple possibilities for the
1342 // initial load in a tab as a side effect of the way the RenderViewHostManager
1343 // works.
1344 //
1345 // - For the very first tab the load looks "normal". The new tab Web UI is
1346 // the pending one, and we want it to apply here.
1347 //
1348 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1349 // get switched to the one previously associated with the new tab pages.
1350 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1351 // have a committed Web UI in this case.
1352 //
1353 // This condition handles all of these cases:
1354 //
1355 // - First load in first tab: no committed nav entry + pending nav entry +
1356 // pending dom ui:
1357 // -> Use pending Web UI if any.
1358 //
1359 // - First load in second tab: no committed nav entry + pending nav entry +
1360 // no pending Web UI:
1361 // -> Use the committed Web UI if any.
1362 //
1363 // - Second navigation in any tab: committed nav entry + pending nav entry:
1364 // -> Use pending Web UI if any.
1365 //
1366 // - Normal state with no load: committed nav entry + no pending nav entry:
1367 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251368 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271369 (controller_.GetLastCommittedEntry() ||
1370 render_manager_.pending_web_ui()))
1371 return render_manager_.pending_web_ui();
1372 return render_manager_.web_ui();
1373}
1374
1375bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1376 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581377 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271378}
1379
[email protected]a0358d72012-03-09 14:06:501380bool TabContents::HasOpener() const {
1381 return has_opener_;
1382}
1383
[email protected]0bfbf882011-12-22 18:19:271384bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471385 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271386 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221387 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231388 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511389 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271390 return true;
1391 return false;
1392}
1393
1394void TabContents::SetFocusToLocationBar(bool select_all) {
1395 if (delegate_)
1396 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211397}
1398
[email protected]8b5af492011-11-28 21:50:581399void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301400 const string16& type,
1401 const string16& href,
1402 const string16& title,
1403 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511404 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301405 this, action, type, href, title, disposition);
1406}
1407
[email protected]678105012011-12-09 04:01:211408void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301409 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001410 WebIntentsDispatcherImpl* intents_dispatcher =
1411 new WebIntentsDispatcherImpl(this, intent, intent_id);
1412 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301413}
1414
[email protected]724159a2010-12-30 01:11:181415void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1416 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591417 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181418 const GURL& url) {
1419 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1420 GURL validated_url(url);
[email protected]9f76c1e2012-03-05 15:15:581421 GetRenderViewHostImpl()->FilterURL(
1422 ChildProcessSecurityPolicyImpl::GetInstance(),
1423 GetRenderProcessHost()->GetID(),
1424 &validated_url);
[email protected]724159a2010-12-30 01:11:181425
[email protected]8093a542011-05-13 07:29:321426 RenderViewHost* rvh =
1427 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521428 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101429 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251430 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101431 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321432 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101433
[email protected]724159a2010-12-30 01:11:181434 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591435 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251436 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591437 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181438 }
1439}
1440
1441void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591442 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181443 const GURL& source_url,
1444 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491445 // TODO(creis): Remove this method and have the pre-rendering code listen to
1446 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1447 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231448 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181449 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251450 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181451 else
1452 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511453 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181454 return;
[email protected]e7d50892011-01-19 21:47:381455
[email protected]4850a7f2011-03-08 23:36:591456 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251457 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261458 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591459 opener_url));
[email protected]724159a2010-12-30 01:11:181460}
1461
1462void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581463 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1464 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1465 << ", error_code: " << params.error_code
1466 << ", error_description: " << params.error_description
1467 << ", is_main_frame: " << params.is_main_frame
1468 << ", showing_repost_interstitial: " <<
1469 params.showing_repost_interstitial
1470 << ", frame_id: " << params.frame_id;
1471 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581472 GetRenderViewHostImpl()->FilterURL(
1473 ChildProcessSecurityPolicyImpl::GetInstance(),
1474 GetRenderProcessHost()->GetID(),
1475 &validated_url);
[email protected]724159a2010-12-30 01:11:181476
[email protected]d7b175e2011-10-11 15:31:581477 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181478 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1479 // This means that the interstitial won't be torn down properly, which is
1480 // bad. But if we have an interstitial, go back to another tab type, and
1481 // then load the same interstitial again, we could end up getting the first
1482 // interstitial's "failed" message (as a result of the cancel) when we're on
1483 // the second one.
1484 //
1485 // We can't tell this apart, so we think we're tearing down the current page
1486 // which will cause a crash later one. There is also some code in
1487 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1488 // out because of this problem.
1489 //
1490 // http://code.google.com/p/chromium/issues/detail?id=2855
1491 // Because this will not tear down the interstitial properly, if "back" is
1492 // back to another tab type, the interstitial will still be somewhat alive
1493 // in the previous tab type. If you navigate somewhere that activates the
1494 // tab with the interstitial again, you'll see a flash before the new load
1495 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271496 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181497 LOG(WARNING) << "Discarding message during interstitial.";
1498 return;
1499 }
1500
[email protected]02102f82011-06-13 20:37:021501 // Discard our pending entry if the load canceled (e.g. if we decided to
1502 // download the file instead of load it). We do not verify that the URL
1503 // being canceled matches the pending entry's URL because they will not
1504 // match if a redirect occurred (in which case we do not want to leave a
1505 // stale redirect URL showing). This means that we also cancel the pending
1506 // entry if the user started a new navigation. As a result, the navigation
1507 // controller may not remember that a load is in progress, but the
1508 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251509 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161510 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181511
[email protected]151a63d2011-12-20 22:32:521512 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181513 }
1514
[email protected]d8c660432011-12-22 20:51:251515 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581516 observers_,
1517 DidFailProvisionalLoad(params.frame_id,
1518 params.is_main_frame,
1519 validated_url,
1520 params.error_code,
1521 params.error_description));
[email protected]724159a2010-12-30 01:11:181522}
1523
1524void TabContents::OnDidLoadResourceFromMemoryCache(
1525 const GURL& url,
[email protected]70435962011-08-02 20:13:281526 const std::string& security_info,
1527 const std::string& http_method,
1528 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191529 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181530 cache.Increment();
1531
1532 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081533 int cert_id = 0;
1534 net::CertStatus cert_status = 0;
1535 int security_bits = -1;
1536 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511537 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1538 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301539 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161540 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181541
[email protected]ad50def52011-10-19 23:17:071542 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271543 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501544 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531545 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181546}
1547
1548void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381549 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181550 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201551 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181552}
1553
1554void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021555 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231556 LOG(INFO) << security_origin << " ran insecure content from "
1557 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381558 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051559 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381560 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051561 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1562 }
[email protected]330614de2012-02-13 17:07:181563 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411564 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201565 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181566}
1567
1568void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1569 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101571 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181572}
1573
[email protected]1a55c5be2011-11-29 11:36:311574void TabContents::OnDidFinishLoad(
1575 int64 frame_id,
1576 const GURL& validated_url,
1577 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251578 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311579 DidFinishLoad(frame_id, validated_url, is_main_frame));
1580}
1581
1582void TabContents::OnDidFailLoadWithError(int64 frame_id,
1583 const GURL& validated_url,
1584 bool is_main_frame,
1585 int error_code,
1586 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311588 DidFailLoad(frame_id, validated_url, is_main_frame,
1589 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181590}
1591
[email protected]c8f73ab2011-01-22 00:05:171592void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271593 content_restrictions_ = restrictions;
1594 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171595}
1596
[email protected]216813952011-05-19 22:21:261597void TabContents::OnGoToEntryAtOffset(int offset) {
1598 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231599 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251600 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261601 if (!entry)
1602 return;
1603 // Note that we don't call NavigationController::GotToOffset() as we don't
1604 // want to create a pending navigation entry (it might end up lingering
1605 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251606 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581607 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511608 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581609 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471610 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571611
1612 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1613 // it in now that we know. This allows us to find the entry when it commits.
1614 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231615 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331616 entry->set_site_instance(
1617 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571618 }
[email protected]216813952011-05-19 22:21:261619 }
1620}
1621
1622void TabContents::OnUpdateZoomLimits(int minimum_percent,
1623 int maximum_percent,
1624 bool remember) {
1625 minimum_zoom_percent_ = minimum_percent;
1626 maximum_zoom_percent_ = maximum_percent;
1627 temporary_zoom_settings_ = !remember;
1628}
1629
[email protected]0bfbf882011-12-22 18:19:271630void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481631 download_stats::RecordDownloadSource(
1632 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261633 // Check if the URL to save matches the URL of the main frame. Since this
1634 // message originates from Pepper plugins, it may not be the case if the
1635 // plugin is an embedded element.
1636 GURL main_frame_url = GetURL();
1637 if (!main_frame_url.is_valid())
1638 return;
1639 bool is_main_frame = (url == main_frame_url);
1640 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271641}
1642
[email protected]3a29a6e2011-08-24 18:26:211643void TabContents::OnEnumerateDirectory(int request_id,
1644 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591645 ChildProcessSecurityPolicyImpl* policy =
1646 ChildProcessSecurityPolicyImpl::GetInstance();
1647 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1648 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211649}
1650
[email protected]7d189022011-08-25 22:54:201651void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511652 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201653}
1654
1655void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1656 const GURL& url,
1657 const string16& title) {
[email protected]b9535422012-02-09 01:47:591658 ChildProcessSecurityPolicyImpl* policy =
1659 ChildProcessSecurityPolicyImpl::GetInstance();
1660 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1661 return;
[email protected]6934a702011-12-20 00:04:511662 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201663}
1664
[email protected]b888919c2011-09-02 00:32:161665void TabContents::OnFindReply(int request_id,
1666 int number_of_matches,
1667 const gfx::Rect& selection_rect,
1668 int active_match_ordinal,
1669 bool final_update) {
[email protected]6934a702011-12-20 00:04:511670 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1671 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001672 // Send a notification to the renderer that we are ready to receive more
1673 // results from the scoping effort of the Find operation. The FindInPage
1674 // scoping is asynchronous and periodically sends results back up to the
1675 // browser using IPC. In an effort to not spam the browser we have the
1676 // browser send an ACK for each FindReply message and have the renderer
1677 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581678 GetRenderViewHostImpl()->Send(
1679 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161680}
1681
[email protected]d952a052011-09-06 18:42:451682void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511683 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451684}
1685
[email protected]7fc4bbb2011-09-08 21:23:101686void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1687 bool blocked_by_policy) {
1688 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251689 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101690 AppCacheAccessed(manifest_url, blocked_by_policy));
1691}
1692
[email protected]96d185d2009-04-24 03:28:541693// Notifies the RenderWidgetHost instance about the fact that the page is
1694// loading, or done loading and calls the base implementation.
1695void TabContents::SetIsLoading(bool is_loading,
1696 LoadNotificationDetails* details) {
1697 if (is_loading == is_loading_)
1698 return;
1699
1700 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211701 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541702 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561703 upload_size_ = 0;
1704 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541705 }
1706
1707 render_manager_.SetIsLoading(is_loading);
1708
1709 is_loading_ = is_loading;
1710 waiting_for_response_ = is_loading;
1711
[email protected]6ebdc9b2010-09-27 16:55:571712 if (delegate_)
1713 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461714 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541715
[email protected]432115822011-07-10 15:52:271716 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1717 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071718 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541719 if (details)
[email protected]6c2381d2011-10-19 02:52:531720 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071721 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501722 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541723 det);
1724}
1725
[email protected]420ae012009-04-24 05:16:321726void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131727 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321728 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561729 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381730 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441731 // that opened the window, as long as both renderers have the same
1732 // privileges.
[email protected]1fd1a502011-03-30 16:55:561733 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561734 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581735 // web_ui might be NULL if the URL refers to a non-existent extension.
1736 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401737 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521738 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441739 }
1740 }
[email protected]1fd1a502011-03-30 16:55:561741 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441742 }
1743
[email protected]4e697b042011-07-08 06:44:561744 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321745 // Clear the status bubble. This is a workaround for a bug where WebKit
1746 // doesn't let us know that the cursor left an element during a
1747 // transition (this is also why the mouse cursor remains as a hand after
1748 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1749 // clear the bubble when a user navigates to a named anchor in the same
1750 // page.
[email protected]36fc0392011-12-25 03:59:511751 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321752 }
1753
[email protected]a6e82fc2010-02-24 22:28:141754 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471755 // Once the main frame is navigated, we're no longer considered to have
1756 // displayed insecure content.
1757 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171758 }
[email protected]ce5c4502009-05-06 16:46:111759
[email protected]3c9e1872010-11-18 16:17:491760 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041762 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321763}
1764
1765void TabContents::DidNavigateAnyFramePostCommit(
1766 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131767 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321768 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061769 // If we navigate off the page, reset JavaScript state. This does nothing
1770 // to prevent a malicious script from spamming messages, since the script
1771 // could just reload the page to stop blocking.
1772 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551773 dialog_creator_->ResetJavaScriptState(this);
1774 dialog_creator_ = NULL;
1775 }
[email protected]420ae012009-04-24 05:16:321776
[email protected]3c9e1872010-11-18 16:17:491777 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251778 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041779 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321780}
1781
[email protected]74ce1ad2011-12-16 21:51:461782void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1783 // If we are creating a RVH for a restored controller, then we need to make
1784 // sure the RenderView starts with a next_page_id_ larger than the number
1785 // of restored entries. This must be called before the RenderView starts
1786 // navigating (to avoid a race between the browser updating max_page_id and
1787 // the renderer updating next_page_id_). Because of this, we only call this
1788 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561789 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581790 if (max_restored_page_id >
1791 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1792 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1793 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321794}
1795
[email protected]10f417c52011-12-28 21:04:231796bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571797 const string16& title) {
[email protected]420ae012009-04-24 05:16:321798 // For file URLs without a title, use the pathname instead. In the case of a
1799 // synthesized title, we don't want the update to count toward the "one set
1800 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511801 string16 final_title;
[email protected]420ae012009-04-24 05:16:321802 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511803 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1804 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321805 explicit_set = false; // Don't count synthetic titles toward the set limit.
1806 } else {
[email protected]acafd272011-07-26 17:35:571807 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321808 explicit_set = true;
1809 }
1810
[email protected]987fc3a2011-05-26 14:18:091811 // If a page is created via window.open and never navigated,
1812 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551813 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091814 if (entry) {
[email protected]36fc0392011-12-25 03:59:511815 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091816 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321817
[email protected]36fc0392011-12-25 03:59:511818 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091819 } else {
1820 if (page_title_when_no_navigation_entry_ == final_title)
1821 return false; // Nothing changed, don't bother.
1822
1823 page_title_when_no_navigation_entry_ = final_title;
1824 }
[email protected]420ae012009-04-24 05:16:321825
[email protected]420ae012009-04-24 05:16:321826 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231827 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321828
[email protected]2bb171882012-03-07 02:09:461829 std::pair<content::NavigationEntry*, bool> details =
1830 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141831
[email protected]ad50def52011-10-19 23:17:071832 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441833 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1834 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461835 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041836
[email protected]420ae012009-04-24 05:16:321837 return true;
1838}
1839
1840void TabContents::NotifySwapped() {
1841 // After sending out a swap notification, we need to send a disconnect
1842 // notification so that clients that pick up a pointer to |this| can NULL the
1843 // pointer. See Bug 1230284.
1844 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071845 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201846 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1847 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071848 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321849}
1850
1851void TabContents::NotifyConnected() {
1852 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071853 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121854 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1855 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071856 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321857}
1858
1859void TabContents::NotifyDisconnected() {
1860 if (!notify_disconnection_)
1861 return;
1862
1863 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071864 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321865 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1866 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071867 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321868}
1869
[email protected]8d3347f2009-07-09 22:00:211870RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321871 return view_.get();
1872}
1873
[email protected]8d3347f2009-07-09 22:00:211874RenderViewHostDelegate::RendererManagement*
1875TabContents::GetRendererManagementDelegate() {
1876 return &render_manager_;
1877}
1878
[email protected]daf82f82011-10-31 22:35:311879content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371880 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461881 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511882}
1883
[email protected]768c5472011-12-26 19:06:171884WebContents* TabContents::GetAsWebContents() {
1885 return this;
1886}
1887
[email protected]da4dfc42011-10-12 15:53:561888content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431889 return view_type_;
[email protected]7b291f92009-08-14 05:43:531890}
1891
[email protected]b7a756d42012-01-23 18:08:171892gfx::Rect TabContents::GetRootWindowResizerRect() const {
1893 if (delegate_)
1894 return delegate_->GetRootWindowResizerRect();
1895 return gfx::Rect();
1896}
1897
[email protected]420ae012009-04-24 05:16:321898void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071899 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271900 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321901 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531902 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231903 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321904 if (!entry)
1905 return;
1906
1907 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351908 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561909 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581910 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321911
1912 if (entry->IsViewSourceMode()) {
1913 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581914 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1915 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321916 }
[email protected]0666aef2009-05-13 19:48:081917
[email protected]d487beefe2011-12-21 05:41:211918 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261919
1920 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251921 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321922}
1923
1924void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521925 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321926 // Don't notify the world, since this came from a renderer in the
1927 // background.
1928 return;
1929 }
1930
1931 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311932 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231933 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301934
1935 // Restore the focus to the tab (otherwise the focus will be on the top
1936 // window).
[email protected]484ae5912010-09-29 19:16:141937 if (was_crashed && !FocusLocationBarByDefault() &&
1938 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301939 Focus();
[email protected]484ae5912010-09-29 19:16:141940 }
[email protected]32ded2212011-11-10 18:51:431941
[email protected]d8c660432011-12-22 20:51:251942 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321943}
1944
[email protected]443b80e2010-12-14 00:42:231945void TabContents::RenderViewGone(RenderViewHost* rvh,
1946 base::TerminationStatus status,
1947 int error_code) {
[email protected]151a63d2011-12-20 22:32:521948 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321949 // The pending page's RenderViewHost is gone.
1950 return;
1951 }
1952
1953 SetIsLoading(false, NULL);
1954 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231955 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311956 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321957
[email protected]d8c660432011-12-22 20:51:251958 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271959 observers_,
[email protected]be1f56ab2011-12-22 06:55:311960 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321961}
1962
[email protected]2e4633c2009-07-09 16:58:061963void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481964 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251965 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061966}
1967
[email protected]420ae012009-04-24 05:16:321968void TabContents::DidNavigate(RenderViewHost* rvh,
1969 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581970 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321971 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371972
[email protected]434f69f2012-02-06 21:56:521973 // Update the site of the SiteInstance if it doesn't have one yet, unless
1974 // this is for about:blank. In that case, the SiteInstance can still be
1975 // considered unused until a navigation to a real page.
1976 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1977 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331978 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521979 }
[email protected]420ae012009-04-24 05:16:321980
1981 // Need to update MIME type here because it's referred to in
1982 // UpdateNavigationCommands() called by RendererDidNavigate() to
1983 // determine whether or not to enable the encoding menu.
1984 // It's updated only for the main frame. For a subframe,
1985 // RenderView::UpdateURL does not set params.contents_mime_type.
1986 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1987 // TODO(jungshik): Add a test for the encoding menu to avoid
1988 // regressing it again.
[email protected]2905f742011-10-13 03:51:581989 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321990 contents_mime_type_ = params.contents_mime_type;
1991
[email protected]8286f51a2011-05-31 17:39:131992 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001993 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391994
[email protected]a9c0bfe2010-09-17 08:35:221995 // Send notification about committed provisional loads. This notification is
1996 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1997 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081998 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071999 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2000 // that is not recorded in the navigation history. For the purpose of
2001 // tracking navigation events, we treat this event as a sub frame navigation
2002 // event.
2003 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582004 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222005 // Whether or not a page transition was triggered by going backward or
2006 // forward in the history is only stored in the navigation controller's
2007 // entry list.
2008 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512009 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582010 content::PAGE_TRANSITION_FORWARD_BACK)) {
2011 transition_type = content::PageTransitionFromInt(
2012 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222013 }
[email protected]0d60f0192011-04-14 12:40:102014 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102016 DidCommitProvisionalLoadForFrame(params.frame_id,
2017 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222018 }
2019
[email protected]76543b92009-08-31 17:27:452020 if (!did_navigate)
2021 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322022
2023 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2024 // for the appropriate notification (best) or you can add it to
2025 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2026 // necessary, please).
2027
2028 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002029 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322030 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512031 if (delegate_)
2032 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002033 }
[email protected]420ae012009-04-24 05:16:322034 DidNavigateAnyFramePostCommit(rvh, details, params);
2035}
2036
2037void TabContents::UpdateState(RenderViewHost* rvh,
2038 int32 page_id,
2039 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152040 // Ensure that this state update comes from either the active RVH or one of
2041 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522042 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322043
2044 // We must be prepared to handle state updates for any page, these occur
2045 // when the user is scrolling and entering form data, as well as when we're
2046 // leaving a page, in which case our state may have already been moved to
2047 // the next page. The navigation controller will look up the appropriate
2048 // NavigationEntry and update it when it is notified via the delegate.
2049
2050 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582051 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322052 if (entry_index < 0)
2053 return;
[email protected]10f417c52011-12-28 21:04:232054 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322055
[email protected]36fc0392011-12-25 03:59:512056 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322057 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512058 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322059 controller_.NotifyEntryChanged(entry, entry_index);
2060}
2061
2062void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572063 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462064 const string16& title,
2065 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322066 // If we have a title, that's a pretty good indication that we've started
2067 // getting useful data.
2068 SetNotWaitingForResponse();
2069
[email protected]73eb2602012-02-09 19:50:552070 // Try to find the navigation entry, which might not be the current one.
2071 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232072 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582073 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092074
[email protected]73eb2602012-02-09 19:50:552075 // We can handle title updates when we don't have an entry in
2076 // UpdateTitleForEntry, but only if the update is from the current RVH.
2077 if (!entry && rvh != GetRenderViewHost())
2078 return;
2079
[email protected]a49e10b2011-08-01 23:57:462080 // TODO(evan): make use of title_direction.
2081 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092082 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322083 return;
2084
2085 // Broadcast notifications when the UI should be updated.
2086 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462087 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322088}
2089
[email protected]420ae012009-04-24 05:16:322090void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402091 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312092 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322093}
2094
2095void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512096 if (delegate_)
2097 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322098}
2099
[email protected]420ae012009-04-24 05:16:322100void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292101 // The UI may be in an event-tracking loop, such as between the
2102 // mouse-down and mouse-up in text selection or a button click.
2103 // Defer the close until after tracking is complete, so that we
2104 // don't free objects out from under the UI.
2105 // TODO(shess): This could probably be integrated with the
2106 // IsDoingDrag() test below. Punting for now because I need more
2107 // research to understand how this impacts platforms other than Mac.
2108 // TODO(shess): This could get more fine-grained. For instance,
2109 // closing a tab in another window while selecting text in the
2110 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212111 if (GetView()->IsEventTracking()) {
2112 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292113 return;
2114 }
2115
[email protected]24a4d1062009-07-10 23:10:422116 // If we close the tab while we're in the middle of a drag, we'll crash.
2117 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212118 if (GetView()->IsDoingDrag()) {
2119 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422120 return;
2121 }
2122
[email protected]420ae012009-04-24 05:16:322123 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522124 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512125 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322126}
2127
[email protected]cd9ed79d2011-11-15 19:22:572128void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522129 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512130 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572131}
2132
[email protected]420ae012009-04-24 05:16:322133void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512134 if (delegate_ && delegate_->IsPopupOrPanel(this))
2135 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322136}
2137
[email protected]7ab1e7d62009-10-14 23:32:012138void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322139 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492140
[email protected]6934a702011-12-20 00:04:512141 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212142 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512143 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002144 }
[email protected]3c9e1872010-11-18 16:17:492145
2146 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252147 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322148}
2149
[email protected]7ab1e7d62009-10-14 23:32:012150void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322151 scoped_ptr<LoadNotificationDetails> details;
2152
[email protected]10f417c52011-12-28 21:04:232153 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322154 // An entry may not exist for a stop when loading an initial blank page or
2155 // if an iframe injected by script into a blank page finishes loading.
2156 if (entry) {
[email protected]420ae012009-04-24 05:16:322157 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2158
2159 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512160 entry->GetVirtualURL(),
2161 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322162 elapsed,
2163 &controller_,
2164 controller_.GetCurrentEntryIndex()));
2165 }
2166
[email protected]420ae012009-04-24 05:16:322167 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492168
2169 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252170 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322171}
2172
[email protected]c95fa8b2011-04-28 20:26:162173void TabContents::DidCancelLoading() {
2174 controller_.DiscardNonCommittedEntries();
2175
2176 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462177 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162178}
2179
[email protected]1a3c3cb2010-12-16 21:03:402180void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512181 if (delegate_)
2182 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402183}
2184
[email protected]952a68e2011-11-17 00:36:102185void TabContents::DocumentAvailableInMainFrame(
2186 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252187 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102188 DocumentAvailableInMainFrame());
2189}
2190
[email protected]25497492010-09-11 15:15:082191void TabContents::DocumentOnLoadCompletedInMainFrame(
2192 RenderViewHost* render_view_host,
2193 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072194 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272195 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322196 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532197 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082198}
2199
[email protected]ae5184d62011-10-06 19:25:582200void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152201 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582202 WindowOpenDisposition disposition,
2203 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482204 // Delegate to RequestTransferURL because this is just the generic
2205 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582206 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482207 GlobalRequestID());
2208}
2209
2210void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582211 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482212 WindowOpenDisposition disposition,
2213 int64 source_frame_id,
2214 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202215 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582216 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582217 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352218 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322219 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2220 // generated suggestions).
2221 //
[email protected]e0112912011-02-02 22:54:352222 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162223 // want web sites to see a referrer of "chrome://blah" (and some
2224 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322225 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432226 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222227 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482228 false /* is_renderer_initiated */);
2229 params.transferred_global_request_id = old_request_id;
2230 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222231 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322232 } else {
[email protected]6bf6a6b52012-02-03 15:41:432233 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482234 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2235 params.transferred_global_request_id = old_request_id;
2236 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582237 }
2238 if (new_contents) {
2239 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252240 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582241 DidOpenRequestedURL(new_contents,
2242 url,
2243 referrer,
2244 disposition,
2245 transition_type,
2246 source_frame_id));
[email protected]420ae012009-04-24 05:16:322247 }
2248}
2249
[email protected]420ae012009-04-24 05:16:322250void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342251 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412252 const string16& message,
2253 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322254 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472255 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322256 IPC::Message* reply_msg,
2257 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072258 // Suppress JavaScript dialogs when requested. Also suppress messages when
2259 // showing an interstitial as it's shown over the previous page and we don't
2260 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502261 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582262 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272263 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072264 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522265 delegate_->ShouldSuppressDialogs() ||
2266 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322267
2268 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432269 std::string accept_lang = content::GetContentClient()->browser()->
2270 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552271 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522272 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432273 this,
2274 frame_url.GetOrigin(),
2275 accept_lang,
2276 javascript_message_type,
2277 message,
[email protected]51da7e32012-01-30 19:24:522278 default_prompt,
2279 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432280 reply_msg),
[email protected]51da7e32012-01-30 19:24:522281 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322282 }
[email protected]3ab9cb82011-06-03 18:02:072283
2284 if (suppress_this_message) {
2285 // If we are suppressing messages, just reply as if the user immediately
2286 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342287 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072288 }
2289
2290 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322291}
2292
[email protected]fedec012012-01-28 03:09:342293void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412294 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322295 bool is_reload,
[email protected]420ae012009-04-24 05:16:322296 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582297 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512298 if (delegate_)
2299 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072300
2301 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582302 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072303 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522304 delegate_->ShouldSuppressDialogs() ||
2305 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152306 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342307 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582308 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502309 return;
2310 }
[email protected]3ab9cb82011-06-03 18:02:072311
[email protected]7ab1e7d62009-10-14 23:32:012312 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552313 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522314 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322315 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522316 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2317 reply_msg));
[email protected]420ae012009-04-24 05:16:322318}
2319
[email protected]420ae012009-04-24 05:16:322320WebPreferences TabContents::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332321 // We want to base the page config off of the real URL, rather than the
2322 // display URL.
2323 GURL url = controller_.GetActiveEntry()
2324 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2325 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322326}
2327
[email protected]7d472472011-01-22 01:30:252328void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272329 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252330 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222331
[email protected]ea114722012-03-12 01:11:252332 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172333 if (rdh) // NULL in unittests.
2334 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252335}
2336
[email protected]fa1cf0b82010-01-15 21:49:442337void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442338 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252339 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442340}
2341
[email protected]420ae012009-04-24 05:16:322342void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2343 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152344 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522345 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152346 return;
2347
[email protected]9f76c1e2012-03-05 15:15:582348 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2349
[email protected]e5fc1632011-08-08 07:51:532350 // Ignore renderer unresponsive event if debugger is attached to the tab
2351 // since the event may be a result of the renderer sitting on a breakpoint.
2352 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442353 DevToolsAgentHost* agent =
2354 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2355 if (agent &&
2356 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532357 return;
2358
[email protected]420ae012009-04-24 05:16:322359 if (is_during_unload) {
2360 // Hang occurred while firing the beforeunload/unload handler.
2361 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582362 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322363
2364 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2365 return;
2366
2367 // If the tab hangs in the beforeunload/unload handler there's really
2368 // nothing we can do to recover. Pretend the unload listeners have
2369 // all fired and close the tab. If the hang is in the beforeunload handler
2370 // then the user will not have the option of cancelling the close.
2371 Close(rvh);
2372 return;
2373 }
2374
[email protected]9f76c1e2012-03-05 15:15:582375 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472376 return;
2377
[email protected]6934a702011-12-20 00:04:512378 if (delegate_)
2379 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322380}
2381
2382void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512383 if (delegate_)
2384 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322385}
2386
2387void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212388 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562389 uint64 upload_position,
2390 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322391 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562392 upload_position_ = upload_position;
2393 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502394 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202395 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302396 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212397 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322398 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462399 if (IsLoading()) {
2400 NotifyNavigationStateChanged(
2401 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2402 }
[email protected]420ae012009-04-24 05:16:322403}
2404
[email protected]7d472472011-01-22 01:30:252405void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512406 if (delegate_)
2407 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252408}
2409
[email protected]420ae012009-04-24 05:16:322410void TabContents::BeforeUnloadFiredFromRenderManager(
2411 bool proceed,
2412 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512413 if (delegate_)
2414 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322415}
2416
[email protected]3a3d47472010-07-15 21:03:542417void TabContents::DidStartLoadingFromRenderManager(
2418 RenderViewHost* render_view_host) {
2419 DidStartLoading();
2420}
2421
2422void TabContents::RenderViewGoneFromRenderManager(
2423 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232424 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2425 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542426}
2427
[email protected]420ae012009-04-24 05:16:322428void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102429 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262430 gfx::Size size = view_->GetContainerSize();
2431 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2432 // here during container initialization and normal window size will be set
2433 // later. In case of tab duplication this resizing to 0x0 prevents setting
2434 // normal size later so just ignore it.
2435 if (!size.IsEmpty())
2436 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322437}
2438
[email protected]3a3d47472010-07-15 21:03:542439void TabContents::NotifySwappedFromRenderManager() {
2440 NotifySwapped();
2441}
2442
[email protected]d202a7c2012-01-04 07:53:472443NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202444 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542445}
2446
[email protected]d2353452012-01-19 19:53:562447WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2448 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322449}
2450
[email protected]10f417c52011-12-28 21:04:232451NavigationEntry*
2452 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322453 return controller_.GetLastCommittedEntry();
2454}
2455
2456bool TabContents::CreateRenderViewForRenderManager(
2457 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442458 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322459 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522460
[email protected]420ae012009-04-24 05:16:322461 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442462 if (rwh_view)
2463 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322464
[email protected]74ce1ad2011-12-16 21:51:462465 // Make sure we use the correct starting page_id in the new RenderView.
2466 UpdateMaxPageIDIfNecessary(render_view_host);
2467 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582468 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462469
[email protected]9f76c1e2012-03-05 15:15:582470 if (!static_cast<RenderViewHostImpl*>(
2471 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522472 return false;
2473
[email protected]e60c0232011-11-11 19:56:352474#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502475 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2476 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442477 if (rwh_view) {
2478 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2479 render_widget_host->WasResized();
2480 }
[email protected]f8233cc2011-05-31 20:24:502481#endif
2482
[email protected]420ae012009-04-24 05:16:322483 return true;
2484}
2485
[email protected]fedec012012-01-28 03:09:342486void TabContents::OnDialogClosed(RenderViewHost* rvh,
2487 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072488 bool success,
2489 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542490 if (is_showing_before_unload_dialog_ && !success) {
2491 // If a beforeunload dialog is canceled, we need to stop the throbber from
2492 // spinning, since we forced it to start spinning in Navigate.
2493 DidStopLoading();
2494
2495 tab_close_start_time_ = base::TimeTicks();
2496 }
2497 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582498 static_cast<RenderViewHostImpl*>(
2499 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542500}
2501
[email protected]be1f56ab2011-12-22 06:55:312502void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122503 encoding_ = content::GetContentClient()->browser()->
2504 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102505}
[email protected]f45d2a72010-03-08 23:28:352506
[email protected]e30d68d2012-02-09 00:06:262507void TabContents::SaveURL(const GURL& url,
2508 const GURL& referrer,
2509 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142510 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2511 if (!dlm)
2512 return;
2513 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262514 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142515 const NavigationEntry* entry = controller_.GetActiveEntry();
2516 if (entry)
2517 post_id = entry->GetPostID();
2518 }
[email protected]29a5ffc82012-03-13 19:35:582519 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142520 save_info.prompt_for_save_location = true;
2521 dlm->DownloadUrl(url,
2522 referrer,
2523 "",
2524 true, // prefer_cache
2525 post_id,
2526 save_info,
[email protected]89e6aa72012-03-12 22:51:332527 this,
2528 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142529}
2530
[email protected]33f74972010-12-08 16:40:362531void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212532 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442533 // Can be NULL during tests.
2534 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212535 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362536}
[email protected]9f76c1e2012-03-05 15:15:582537
2538RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2539 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2540}