blob: a7c8b81ebd72b92b3155ddd73d7eb664a9a09205 [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>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5916#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4417#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4618#include "content/browser/download/download_stats.h"
[email protected]a53209b2012-01-20 16:48:1619#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3220#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5421#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0522#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0023#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0124#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0425#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3026#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5027#include "content/browser/renderer_host/render_view_host.h"
[email protected]686493142011-07-15 21:47:2228#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3330#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1331#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2332#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1434#include "content/browser/tab_contents/title_updated_details.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]5b96836f2011-12-22 07:39:0046#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4847#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3848#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4249#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2550#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1051#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5052#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2153#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1855#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5456#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0357#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1658#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2959#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5460#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3461#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3863#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2464#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3165#include "webkit/glue/webpreferences.h"
66
67#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1268#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3169#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0070
[email protected]420ae012009-04-24 05:16:3271// Cross-Site Navigations
72//
73// If a TabContents is told to navigate to a different web site (as determined
74// by SiteInstance), it will replace its current RenderViewHost with a new
75// RenderViewHost dedicated to the new SiteInstance. This works as follows:
76//
77// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4678// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3279// - The pending RVH is "suspended," so that no navigation messages are sent to
80// its renderer until the onbeforeunload JavaScript handler has a chance to
81// run in the current RVH.
82// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
83// that it has a pending cross-site request. ResourceDispatcherHost will
84// check for this when the response arrives.
85// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4686// cancel all the pending logic. Otherwise we allow the pending RVH to send
87// the navigation request to its renderer.
88// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
89// main resource load on the pending RVH. It checks CrossSiteRequestManager
90// to see that it is a cross-site request, and installs a
91// CrossSiteResourceHandler.
92// - When RDH receives a response, the BufferedResourceHandler determines
93// whether it is a download. If so, it sends a message to the new renderer
94// causing it to cancel the request, and the download proceeds. For now, the
95// pending RVH remains until the next DidNavigate event for this TabContents.
96// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3297// - After RDH receives a response and determines that it is safe and not a
98// download, it pauses the response to first run the old page's onunload
99// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15100// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32101// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15102// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32103// the ResourceDispatcherHost, who unpauses the response. Data is then sent
104// to the pending RVH.
105// - The pending renderer sends a FrameNavigate message that invokes the
106// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46107// pending RVH.
[email protected]992db4c2011-05-12 15:37:15108// - The previous renderer is kept swapped out in RenderViewHostManager in case
109// the user goes back. The process only stays live if another tab is using
110// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32111
[email protected]0e12d7d2011-12-01 16:21:44112using content::DevToolsAgentHost;
113using content::DevToolsAgentHostRegistry;
114using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17115using content::DownloadItem;
116using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20117using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56118using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13119using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50120using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23121using content::NavigationEntry;
122using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20123using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57124using content::RenderViewHostDelegate;
[email protected]5626b0892012-02-20 14:46:58125using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04126using content::RenderWidgetHostViewPort;
[email protected]adbfb8df2012-02-24 01:19:43127using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33128using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17129using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38130using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09131using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25132using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56133using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22134using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50135using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44136
[email protected]420ae012009-04-24 05:16:32137namespace {
138
139// Amount of time we wait between when a key event is received and the renderer
140// is queried for its state and pushed to the NavigationEntry.
141const int kQueryStateDelay = 5000;
142
[email protected]6ebdc9b2010-09-27 16:55:57143const int kSyncWaitDelay = 40;
144
[email protected]ca406032011-07-19 21:53:05145static const char kDotGoogleDotCom[] = ".google.com";
146
[email protected]420ae012009-04-24 05:16:32147#if defined(OS_WIN)
148
149BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
150 // Note: erase is required to properly paint some widgets borders. This can
151 // be seen with textfields.
152 InvalidateRect(hwnd, NULL, TRUE);
153 return TRUE;
154}
155#endif
156
[email protected]2c5569662011-03-22 20:45:02157ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23158 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50159 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16160 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47161 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02162 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47163 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02164 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47165 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16166 break; // Fall through to rest of function.
167 }
[email protected]5e369672009-11-03 23:48:30168
[email protected]59246c572012-02-10 13:32:13169 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
170 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23171 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13172 browser_context->DidLastSessionExitCleanly()) {
173 if (entry.GetHasPostData())
174 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02175 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13176 }
[email protected]5e369672009-11-03 23:48:30177
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30179}
180
[email protected]10f417c52011-12-28 21:04:23181void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47182 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42183 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50184 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16185 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51186 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54187 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55188 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
189 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51190 params->url = entry.GetURL();
191 params->referrer = entry.GetReferrer();
192 params->transition = entry.GetTransitionType();
193 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00194 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55195 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34196 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47197 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48198 params->transferred_request_child_id =
199 entry.transferred_global_request_id().child_id;
200 params->transferred_request_request_id =
201 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47202
203 if (delegate)
204 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34205}
206
[email protected]420ae012009-04-24 05:16:32207} // namespace
208
[email protected]a81343d232011-12-27 07:39:20209namespace content {
210
211WebContents* WebContents::Create(
212 BrowserContext* browser_context,
213 SiteInstance* site_instance,
214 int routing_id,
215 const WebContents* base_tab_contents,
216 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43217 return new TabContents(
218 browser_context,
219 site_instance,
220 routing_id,
221 static_cast<const TabContents*>(base_tab_contents),
222 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20223}
224}
[email protected]f4f50ef2011-01-21 19:01:19225
226// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32227
[email protected]3d7474ff2011-07-27 17:47:37228TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32229 SiteInstance* site_instance,
230 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07231 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43232 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42233 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07234 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37235 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13236 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10237 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22238 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34239 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23240 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
241 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34242 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21243 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56244 upload_size_(0),
245 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47246 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57247 capturing_contents_(false),
248 is_being_destroyed_(false),
249 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55250 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57251#if defined(OS_WIN)
252 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
253#endif
[email protected]7ab1e7d62009-10-14 23:32:01254 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56255 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38256 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25257 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01258 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25259 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01260 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00261 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43262 content_restrictions_(0),
263 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37264 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32265
[email protected]34ac70502009-09-25 17:07:23266 // We have the initial size of the view be based on the size of the passed in
267 // tab contents (normally a tab from the same window).
268 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21269 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00270
271#if defined(ENABLE_JAVA_BRIDGE)
272 java_bridge_dispatcher_host_manager_.reset(
273 new JavaBridgeDispatcherHostManager(this));
274#endif
[email protected]332af7732009-03-11 13:21:35275}
initial.commit09911bf2008-07-26 23:55:29276
277TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32278 is_being_destroyed_ = true;
279
[email protected]3ab9cb82011-06-03 18:02:07280 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55281 if (dialog_creator_)
282 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07283
[email protected]420ae012009-04-24 05:16:32284 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32285
[email protected]420ae012009-04-24 05:16:32286 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07287 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09288 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
289 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07290 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32291
292 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07293#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32294 // If we still have a window handle, destroy it. GetNativeView can return
295 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42296 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52297 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44298 if (host && host->view())
[email protected]c30585c2012-02-16 15:02:04299 RenderWidgetHostViewPort::FromRWHV(host->view())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42300 }
[email protected]420ae012009-04-24 05:16:32301#endif
[email protected]7ab1e7d62009-10-14 23:32:01302
303 // OnCloseStarted isn't called in unit tests.
304 if (!tab_close_start_time_.is_null()) {
305 UMA_HISTOGRAM_TIMES("Tab.Close",
306 base::TimeTicks::Now() - tab_close_start_time_);
307 }
[email protected]b5a1d11c2011-02-17 03:09:42308
[email protected]d8c660432011-12-22 20:51:25309 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08310
[email protected]6934a702011-12-20 00:04:51311 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42312}
313
[email protected]64d69de42012-02-06 00:19:54314WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
315 const GURL& url) {
316 WebPreferences prefs;
317
318 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
319
320 prefs.developer_extras_enabled = true;
321 prefs.javascript_enabled =
322 !command_line.HasSwitch(switches::kDisableJavaScript);
323 prefs.web_security_enabled =
324 !command_line.HasSwitch(switches::kDisableWebSecurity);
325 prefs.plugins_enabled =
326 !command_line.HasSwitch(switches::kDisablePlugins);
327 prefs.java_enabled =
328 !command_line.HasSwitch(switches::kDisableJava);
329
330 prefs.uses_page_cache =
331 command_line.HasSwitch(switches::kEnableFastback);
332 prefs.remote_fonts_enabled =
333 !command_line.HasSwitch(switches::kDisableRemoteFonts);
334 prefs.xss_auditor_enabled =
335 !command_line.HasSwitch(switches::kDisableXSSAuditor);
336 prefs.application_cache_enabled =
337 !command_line.HasSwitch(switches::kDisableApplicationCache);
338
339 prefs.local_storage_enabled =
340 !command_line.HasSwitch(switches::kDisableLocalStorage);
341 prefs.databases_enabled =
342 !command_line.HasSwitch(switches::kDisableDatabases);
343 prefs.webaudio_enabled =
344 !command_line.HasSwitch(switches::kDisableWebAudio);
345
346 prefs.experimental_webgl_enabled =
347 GpuProcessHost::gpu_enabled() &&
348 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
349 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
350
351 prefs.gl_multisampling_enabled =
352 !command_line.HasSwitch(switches::kDisableGLMultisampling);
353 prefs.privileged_webgl_extensions_enabled =
354 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
355 prefs.site_specific_quirks_enabled =
356 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
357 prefs.allow_file_access_from_file_urls =
358 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
359 prefs.show_composited_layer_borders =
360 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
361 prefs.show_composited_layer_tree =
362 command_line.HasSwitch(switches::kShowCompositedLayerTree);
363 prefs.show_fps_counter =
364 command_line.HasSwitch(switches::kShowFPSCounter);
365 prefs.accelerated_compositing_enabled =
366 GpuProcessHost::gpu_enabled() &&
367 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
368 prefs.threaded_compositing_enabled =
369 command_line.HasSwitch(switches::kEnableThreadedCompositing);
370 prefs.force_compositing_mode =
371 command_line.HasSwitch(switches::kForceCompositingMode);
372 prefs.fixed_position_compositing_enabled =
373 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
374 prefs.accelerated_2d_canvas_enabled =
375 GpuProcessHost::gpu_enabled() &&
376 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58377 prefs.deferred_2d_canvas_enabled =
378 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36379 prefs.threaded_animation_enabled =
380 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54381 prefs.accelerated_painting_enabled =
382 GpuProcessHost::gpu_enabled() &&
383 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
384 prefs.accelerated_filters_enabled =
385 GpuProcessHost::gpu_enabled() &&
386 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
387 prefs.accelerated_layers_enabled =
388 prefs.accelerated_animation_enabled =
389 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
390 prefs.composite_to_texture_enabled =
391 command_line.HasSwitch(switches::kEnableCompositeToTexture);
392 prefs.accelerated_plugins_enabled =
393 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
394 prefs.accelerated_video_enabled =
395 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
396 prefs.partial_swap_enabled =
397 command_line.HasSwitch(switches::kEnablePartialSwap);
398 prefs.interactive_form_validation_enabled =
399 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
400 prefs.fullscreen_enabled =
401 !command_line.HasSwitch(switches::kDisableFullScreen);
402
403#if defined(OS_MACOSX)
404 bool default_enable_scroll_animator = true;
405#else
406 // On CrOS, the launcher always passes in the --enable flag.
407 bool default_enable_scroll_animator = false;
408#endif
409 prefs.enable_scroll_animator = default_enable_scroll_animator;
410 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
411 prefs.enable_scroll_animator = true;
412 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
413 prefs.enable_scroll_animator = false;
414
415 prefs.visual_word_movement_enabled =
416 command_line.HasSwitch(switches::kEnableVisualWordMovement);
417 prefs.per_tile_painting_enabled =
418 command_line.HasSwitch(switches::kEnablePerTilePainting);
419
420 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32421 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54422 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11423 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
424 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54425 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11426 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54427 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11428 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54429 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11430 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54431 prefs.gl_multisampling_enabled = false;
432
433 // Accelerated video and animation are slower than regular when using a
434 // software 3d rasterizer.
[email protected]79078df2012-02-16 01:22:32435 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54436 prefs.accelerated_video_enabled = false;
437 prefs.accelerated_animation_enabled = false;
438 }
439 }
440
[email protected]b9535422012-02-09 01:47:59441 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54442 rvh->process()->GetID())) {
443 prefs.loads_images_automatically = true;
444 prefs.javascript_enabled = true;
445 }
446
447 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
448
449 // Force accelerated compositing and 2d canvas off for chrome:, about: and
450 // chrome-devtools: pages (unless it's specifically allowed).
451 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54452 url.SchemeIs(chrome::kChromeUIScheme) ||
453 (url.SchemeIs(chrome::kAboutScheme) &&
454 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25455 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54456 prefs.accelerated_compositing_enabled = false;
457 prefs.accelerated_2d_canvas_enabled = false;
458 }
459
460 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
461
462 return prefs;
463}
464
[email protected]d202a7c2012-01-04 07:53:47465NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20466 return controller_;
467}
468
[email protected]765187182012-01-11 23:59:28469RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
470 return &render_manager_;
471}
472
[email protected]724159a2010-12-30 01:11:18473bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56474 if (GetWebUI() &&
475 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17476 return true;
[email protected]d2353452012-01-19 19:53:56477 }
[email protected]f82d57b52011-04-27 19:13:17478
[email protected]d8c660432011-12-22 20:51:25479 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
480 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10481 while ((observer = it.GetNext()) != NULL)
482 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53483 return true;
[email protected]403415a2011-01-10 18:57:53484
[email protected]724159a2010-12-30 01:11:18485 bool handled = true;
486 bool message_is_ok = true;
487 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58488 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
489 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24490 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
491 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18492 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
493 OnDidStartProvisionalLoadForFrame)
494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
495 OnDidRedirectProvisionalLoad)
496 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
497 OnDidFailProvisionalLoadWithError)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
499 OnDidLoadResourceFromMemoryCache)
500 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
501 OnDidDisplayInsecureContent)
502 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
503 OnDidRunInsecureContent)
504 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
505 OnDocumentLoadedInFrame)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17507 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
508 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25509 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26510 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59511 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21512 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20513 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
515 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16516 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45517 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10518 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18519 IPC_MESSAGE_UNHANDLED(handled = false)
520 IPC_END_MESSAGE_MAP_EX()
521
522 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38523 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18524 GetRenderProcessHost()->ReceivedBadMessage();
525 }
526
527 return handled;
528}
529
[email protected]6c2e472f2011-08-24 23:26:18530void TabContents::RunFileChooser(
531 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23532 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51533 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18534}
535
[email protected]c5eed492012-01-04 17:07:50536NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56537 return controller_;
538}
539
[email protected]c5eed492012-01-04 17:07:50540const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56541 return controller_;
542}
543
[email protected]627e0512011-12-21 22:55:30544content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55545 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30546}
547
[email protected]f5fa20e2011-12-21 22:35:56548void TabContents::SetViewType(content::ViewType type) {
549 view_type_ = type;
550}
551
[email protected]ea049a02011-12-25 21:37:09552content::ViewType TabContents::GetViewType() const {
553 return view_type_;
554}
555
[email protected]be1f56ab2011-12-22 06:55:31556const GURL& TabContents::GetURL() const {
557 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23558 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51559 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31560}
561
562
563const base::PropertyBag* TabContents::GetPropertyBag() const {
564 return &property_bag_;
565}
566
567base::PropertyBag* TabContents::GetPropertyBag() {
568 return &property_bag_;
569}
570
571content::WebContentsDelegate* TabContents::GetDelegate() {
572 return delegate_;
573}
574
575void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
576 // TODO(cbentzel): remove this debugging code?
577 if (delegate == delegate_)
578 return;
579 if (delegate_)
580 delegate_->Detach(this);
581 delegate_ = delegate;
582 if (delegate_)
583 delegate_->Attach(this);
584}
585
[email protected]f3b1a082011-11-18 00:34:30586content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03587 if (render_manager_.current_host())
588 return render_manager_.current_host()->process();
589 else
590 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16591}
592
[email protected]be1f56ab2011-12-22 06:55:31593RenderViewHost* TabContents::GetRenderViewHost() const {
594 return render_manager_.current_host();
595}
596
597RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
598 return render_manager_.GetRenderWidgetHostView();
599}
600
[email protected]8643e6d2012-01-18 20:26:10601content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31602 return view_.get();
603}
604
[email protected]01ec4ec2012-01-18 04:13:47605content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50606 WebUIControllerFactory* factory =
607 content::GetContentClient()->browser()->GetWebUIControllerFactory();
608 if (!factory)
609 return NULL;
[email protected]d2353452012-01-19 19:53:56610 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22611 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50612 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22613 if (controller) {
614 web_ui->SetController(controller);
615 return web_ui;
616 }
617
618 delete web_ui;
619 return NULL;
620}
621
[email protected]01ec4ec2012-01-18 04:13:47622content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31623 return render_manager_.web_ui() ? render_manager_.web_ui()
624 : render_manager_.pending_web_ui();
625}
626
[email protected]01ec4ec2012-01-18 04:13:47627content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31628 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34629}
630
[email protected]96d185d2009-04-24 03:28:54631const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55632 // Transient entries take precedence. They are used for interstitial pages
633 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23634 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08635 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20636 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30637 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23638 if (entry) {
[email protected]b5cca982011-05-26 04:42:08639 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23640 }
[email protected]7ade2732011-02-10 00:13:58641 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
642 render_manager_.pending_web_ui() : render_manager_.web_ui();
643 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54644 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55645 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54646 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35647 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22648 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54649 if (!title.empty())
650 return title;
651 }
652 }
653
654 // We use the title for the last committed entry rather than a pending
655 // navigation entry. For example, when the user types in a URL, we want to
656 // keep the old page's title until the new load has committed and we get a new
657 // title.
[email protected]96d185d2009-04-24 03:28:54658 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23659 if (entry) {
[email protected]b5cca982011-05-26 04:42:08660 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23661 }
[email protected]987fc3a2011-05-26 14:18:09662
663 // |page_title_when_no_navigation_entry_| is finally used
664 // if no title cannot be retrieved.
665 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54666}
667
[email protected]d5f942ba2008-09-26 19:30:34668int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46669 return GetMaxPageIDForSiteInstance(GetSiteInstance());
670}
671
672int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33673 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
674 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46675
[email protected]b6583592012-01-25 19:52:33676 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34677}
678
679void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46680 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
681}
682
[email protected]b6583592012-01-25 19:52:33683void TabContents::UpdateMaxPageIDForSiteInstance(
684 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46685 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33686 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34687}
688
[email protected]91854cd2012-01-10 19:43:57689void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
690 max_page_ids_ = tab_contents->max_page_ids_;
691}
692
[email protected]96d185d2009-04-24 03:28:54693SiteInstance* TabContents::GetSiteInstance() const {
694 return render_manager_.current_host()->site_instance();
695}
696
[email protected]77362eb2011-08-01 17:18:38697SiteInstance* TabContents::GetPendingSiteInstance() const {
698 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
699 render_manager_.pending_render_view_host() :
700 render_manager_.current_host();
701 return dest_rvh->site_instance();
702}
703
[email protected]be1f56ab2011-12-22 06:55:31704bool TabContents::IsLoading() const {
705 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49706}
707
[email protected]be1f56ab2011-12-22 06:55:31708bool TabContents::IsWaitingForResponse() const {
709 return waiting_for_response_;
710}
711
712const net::LoadStateWithParam& TabContents::GetLoadState() const {
713 return load_state_;
714}
715
716const string16& TabContents::GetLoadStateHost() const {
717 return load_state_host_;
718}
719
720uint64 TabContents::GetUploadSize() const {
721 return upload_size_;
722}
723
724uint64 TabContents::GetUploadPosition() const {
725 return upload_position_;
726}
727
728const std::string& TabContents::GetEncoding() const {
729 return encoding_;
730}
731
732bool TabContents::DisplayedInsecureContent() const {
733 return displayed_insecure_content_;
734}
735
736void TabContents::SetCapturingContents(bool cap) {
737 capturing_contents_ = cap;
738}
739
740bool TabContents::IsCrashed() const {
741 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
742 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
743 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49744}
745
[email protected]443b80e2010-12-14 00:42:23746void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
747 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34748 return;
749
[email protected]443b80e2010-12-14 00:42:23750 crashed_status_ = status;
751 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46752 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34753}
754
[email protected]be1f56ab2011-12-22 06:55:31755base::TerminationStatus TabContents::GetCrashedStatus() const {
756 return crashed_status_;
757}
758
759bool TabContents::IsBeingDestroyed() const {
760 return is_being_destroyed_;
761}
762
[email protected]d5f942ba2008-09-26 19:30:34763void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
764 if (delegate_)
765 delegate_->NavigationStateChanged(this, changed_flags);
766}
767
[email protected]96d185d2009-04-24 03:28:54768void TabContents::DidBecomeSelected() {
769 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04770 RenderWidgetHostViewPort* rwhv =
771 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16772 if (rwhv) {
773 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43774#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16775 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43776#endif
777 }
[email protected]96d185d2009-04-24 03:28:54778
[email protected]5ac20162010-11-24 23:33:11779 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38780
[email protected]d8c660432011-12-22 20:51:25781 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59782
783 // The resize rect might have changed while this was inactive -- send the new
784 // one to make sure it's up to date.
785 RenderViewHost* rvh = GetRenderViewHost();
786 if (rvh) {
787 rvh->ResizeRectChanged(GetRootWindowResizerRect());
788 }
[email protected]96d185d2009-04-24 03:28:54789}
790
[email protected]be1f56ab2011-12-22 06:55:31791
792base::TimeTicks TabContents::GetLastSelectedTime() const {
793 return last_selected_time_;
794}
795
[email protected]96d185d2009-04-24 03:28:54796void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31797 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52798 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
799 // open a tab in then background, then closes the tab before selecting it.
800 // This is because closing the tab calls TabContents::Destroy(), which
801 // removes the |GetRenderViewHost()|; then when we actually destroy the
802 // window, OnWindowPosChanged() notices and calls HideContents() (which
803 // calls us).
[email protected]c30585c2012-02-16 15:02:04804 RenderWidgetHostViewPort* rwhv =
805 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16806 if (rwhv)
807 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54808 }
809
[email protected]ad50def52011-10-19 23:17:07810 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09811 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
812 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07813 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54814}
815
[email protected]be1f56ab2011-12-22 06:55:31816void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04817 RenderWidgetHostViewPort* rwhv =
818 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31819 if (rwhv)
820 rwhv->DidBecomeSelected();
821}
822
823void TabContents::HideContents() {
824 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
825 // our superclass HideContents(), because some callers want to be very picky
826 // about the order in which these get called. In addition to making the code
827 // here practically impossible to understand, this also means we end up
828 // calling TabContents::WasHidden() twice if callers call both versions of
829 // HideContents() on a TabContents.
830 WasHidden();
831}
832
833bool TabContents::NeedToFireBeforeUnload() {
834 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27835 return WillNotifyDisconnection() &&
836 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31837 !GetRenderViewHost()->SuddenTerminationAllowed();
838}
839
[email protected]0bfbf882011-12-22 18:19:27840void TabContents::Stop() {
841 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25842 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27843}
844
[email protected]d9083482012-01-06 00:38:46845WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27846 // We create a new SiteInstance so that the new tab won't share processes
847 // with the old one. This can be changed in the future if we need it to share
848 // processes for some reason.
849 TabContents* tc = new TabContents(
850 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33851 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27852 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20853 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27854 return tc;
855}
856
[email protected]2a6bc3e2011-12-28 23:51:33857void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27858 WindowOpenDisposition disposition,
859 const gfx::Rect& initial_pos,
860 bool user_gesture) {
861 if (!delegate_)
862 return;
863
864 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
865 user_gesture);
866}
867
868gfx::NativeView TabContents::GetContentNativeView() const {
869 return view_->GetContentNativeView();
870}
871
872gfx::NativeView TabContents::GetNativeView() const {
873 return view_->GetNativeView();
874}
875
876void TabContents::GetContainerBounds(gfx::Rect* out) const {
877 view_->GetContainerBounds(out);
878}
879
880void TabContents::Focus() {
881 view_->Focus();
882}
883
[email protected]d8c660432011-12-22 20:51:25884void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31885 observers_.AddObserver(observer);
886}
887
[email protected]d8c660432011-12-22 20:51:25888void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31889 observers_.RemoveObserver(observer);
890}
891
[email protected]d5f942ba2008-09-26 19:30:34892void TabContents::Activate() {
893 if (delegate_)
894 delegate_->ActivateContents(this);
895}
896
[email protected]ea42e7782010-08-23 23:58:12897void TabContents::Deactivate() {
898 if (delegate_)
899 delegate_->DeactivateContents(this);
900}
901
[email protected]63954792011-07-11 04:17:48902void TabContents::LostCapture() {
903 if (delegate_)
904 delegate_->LostCapture();
905}
906
907bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
908 bool* is_keyboard_shortcut) {
909 return delegate_ &&
910 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
911}
912
913void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
914 if (delegate_)
915 delegate_->HandleKeyboardEvent(event);
916}
917
[email protected]32ded2212011-11-10 18:51:43918void TabContents::HandleMouseDown() {
919 if (delegate_)
920 delegate_->HandleMouseDown();
921}
922
[email protected]63954792011-07-11 04:17:48923void TabContents::HandleMouseUp() {
924 if (delegate_)
925 delegate_->HandleMouseUp();
926}
927
928void TabContents::HandleMouseActivate() {
929 if (delegate_)
930 delegate_->HandleMouseActivate();
931}
932
[email protected]8a5e0ca2011-08-25 06:30:47933void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
934 if (delegate_)
935 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
936}
937
[email protected]5d5f7af2011-10-01 01:38:12938bool TabContents::IsFullscreenForCurrentTab() const {
939 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
940}
941
[email protected]e9621112011-10-17 05:38:37942void TabContents::RequestToLockMouse() {
943 if (delegate_) {
944 delegate_->RequestToLockMouse(this);
945 } else {
946 GotResponseToLockMouseRequest(false);
947 }
948}
949
950void TabContents::LostMouseLock() {
951 if (delegate_)
952 delegate_->LostMouseLock();
953}
954
[email protected]0548c5352011-09-07 00:33:33955void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23956 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33957 if (delegate_)
958 delegate_->UpdatePreferredSize(this, pref_size);
959}
960
[email protected]32ded2212011-11-10 18:51:43961void TabContents::WebUISend(RenderViewHost* render_view_host,
962 const GURL& source_url,
963 const std::string& name,
964 const base::ListValue& args) {
965 if (delegate_)
966 delegate_->WebUISend(this, source_url, name, args);
967}
968
[email protected]e5d549d2011-12-28 01:29:20969WebContents* TabContents::OpenURL(const OpenURLParams& params) {
970 if (!delegate_)
971 return NULL;
[email protected]00c37fc2011-08-02 00:22:50972
[email protected]e5d549d2011-12-28 01:29:20973 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
974 // Notify observers.
975 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
976 DidOpenURL(params.url, params.referrer,
977 params.disposition, params.transition));
978 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34979}
980
[email protected]1ccb3568d2010-02-19 10:51:16981bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50982 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25983 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23984 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25985 reload_type);
[email protected]876bc832010-09-07 16:29:54986}
[email protected]96d185d2009-04-24 03:28:54987
[email protected]876bc832010-09-07 16:29:54988bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23989 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50990 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40991 // The renderer will reject IPC messages with URLs longer than
992 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51993 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40994 return false;
995
[email protected]dd11de52011-11-03 22:54:27996 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40997 if (!dest_render_view_host)
998 return false; // Unable to create the desired render view host.
999
[email protected]80a8fad2011-01-29 04:02:381000 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071001 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581002 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501003 WebUIControllerFactory* factory =
1004 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1005 bool is_allowed_in_web_ui_renderer =
1006 factory &&
1007 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431008#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511009 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431010#endif
[email protected]e091df82011-10-11 18:13:211011 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551012 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581013
[email protected]96d185d2009-04-24 03:28:541014 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441015 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521016 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441017 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511018 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541019
1020 // Used for page load time metrics.
1021 current_load_start_ = base::TimeTicks::Now();
1022
1023 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341024 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271025 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471026 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341027 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541028
[email protected]36fc0392011-12-25 03:59:511029 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541030 // HACK!! This code suppresses javascript: URLs from being added to
1031 // session history, which is what we want to do for javascript: URLs that
1032 // do not generate content. What we really need is a message from the
1033 // renderer telling us that a new page was not created. The same message
1034 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511035 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541036 return false;
1037 }
1038
[email protected]3c9e1872010-11-18 16:17:491039 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251040 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041041 observers_,
[email protected]36fc0392011-12-25 03:59:511042 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541043
[email protected]09b29342011-06-24 19:18:481044 if (delegate_)
1045 delegate_->DidNavigateToPendingEntry(this);
1046
[email protected]d5f942ba2008-09-26 19:30:341047 return true;
1048}
1049
[email protected]b6583592012-01-25 19:52:331050void TabContents::SetHistoryLengthAndPrune(
1051 const SiteInstance* site_instance,
1052 int history_length,
1053 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411054 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1055 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191056 if (render_manager_.pending_render_view_host()) {
1057 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141058 return;
[email protected]9e1ad4b2011-08-14 16:49:191059 }
[email protected]151a63d2011-12-20 22:32:521060 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191061 if (!rvh) {
1062 NOTREACHED();
1063 return;
1064 }
1065 if (site_instance && rvh->site_instance() != site_instance) {
1066 NOTREACHED();
1067 return;
1068 }
1069 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1070 history_length,
1071 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141072}
1073
[email protected]90daadb42009-06-08 21:27:281074void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271075 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541076 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1077 return;
1078 }
[email protected]151a63d2011-12-20 22:32:521079 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541080}
1081
[email protected]0bfbf882011-12-22 18:19:271082bool TabContents::ShowingInterstitialPage() const {
1083 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541084}
1085
[email protected]0bfbf882011-12-22 18:19:271086InterstitialPage* TabContents::GetInterstitialPage() const {
1087 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221088}
1089
[email protected]a53209b2012-01-20 16:48:161090bool TabContents::IsSavable() {
1091 // WebKit creates Document object when MIME type is application/xhtml+xml,
1092 // so we also support this MIME type.
1093 return contents_mime_type_ == "text/html" ||
1094 contents_mime_type_ == "text/xml" ||
1095 contents_mime_type_ == "application/xhtml+xml" ||
1096 contents_mime_type_ == "text/plain" ||
1097 contents_mime_type_ == "text/css" ||
1098 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1099}
1100
[email protected]c7dd2f62011-07-18 15:57:591101void TabContents::OnSavePage() {
1102 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161103 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481104 download_stats::RecordDownloadSource(
1105 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261106 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141107 return;
[email protected]c7dd2f62011-07-18 15:57:591108 }
1109
1110 Stop();
1111
1112 // Create the save package and possibly prompt the user for the name to save
1113 // the page as. The user prompt is an asynchronous operation that runs on
1114 // another thread.
1115 save_package_ = new SavePackage(this);
1116 save_package_->GetSaveInfo();
1117}
1118
1119// Used in automated testing to bypass prompting the user for file names.
1120// Instead, the names and paths are hard coded rather than running them through
1121// file name sanitation and extension / mime checking.
1122bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161123 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591124 // Stop the page from navigating.
1125 Stop();
1126
1127 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1128 return save_package_->Init();
1129}
1130
[email protected]420ae012009-04-24 05:16:321131bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231132 NavigationEntryImpl* active_entry =
1133 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321134 return (active_entry != NULL &&
1135 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511136 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321137}
1138
[email protected]0bfbf882011-12-22 18:19:271139const std::string& TabContents::GetContentsMimeType() const {
1140 return contents_mime_type_;
1141}
1142
1143bool TabContents::WillNotifyDisconnection() const {
1144 return notify_disconnection_;
1145}
1146
[email protected]b2fe07d12010-02-09 14:38:081147void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311148 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521149 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1150 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161151}
1152
[email protected]b2fe07d12010-02-09 14:38:081153void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311154 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521155 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1156 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161157}
1158
[email protected]0bfbf882011-12-22 18:19:271159content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1160 return &renderer_preferences_;
1161}
1162
1163void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1164 new_tab_start_time_ = time;
1165}
1166
1167base::TimeTicks TabContents::GetNewTabStartTime() const {
1168 return new_tab_start_time_;
1169}
1170
[email protected]7ab1e7d62009-10-14 23:32:011171void TabContents::OnCloseStarted() {
1172 if (tab_close_start_time_.is_null())
1173 tab_close_start_time_ = base::TimeTicks::Now();
1174}
1175
[email protected]46624bf2010-06-09 16:04:191176bool TabContents::ShouldAcceptDragAndDrop() const {
1177#if defined(OS_CHROMEOS)
1178 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1179 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511180 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201181 return false;
1182 return true;
[email protected]46624bf2010-06-09 16:04:191183#else
1184 return true;
1185#endif
1186}
1187
[email protected]7813bd72011-02-05 02:19:341188void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521189 if (GetRenderViewHost())
1190 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511191 if (delegate_)
1192 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341193}
1194
[email protected]0bfbf882011-12-22 18:19:271195void TabContents::SetClosedByUserGesture(bool value) {
1196 closed_by_user_gesture_ = value;
1197}
1198
1199bool TabContents::GetClosedByUserGesture() const {
1200 return closed_by_user_gesture_;
1201}
1202
[email protected]d0b8d092010-10-25 04:05:171203double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051204 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561205 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251206 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171207 return 0;
[email protected]b75b8292010-10-01 07:28:251208
1209 double zoom_level;
1210 if (temporary_zoom_settings_) {
1211 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521212 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251213 } else {
[email protected]2ae88d12011-10-14 09:11:191214 GURL url;
[email protected]10f417c52011-12-28 21:04:231215 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191216 // Since zoom map is updated using rewritten URL, use rewritten URL
1217 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511218 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191219 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251220 }
[email protected]d0b8d092010-10-25 04:05:171221 return zoom_level;
1222}
[email protected]b75b8292010-10-01 07:28:251223
[email protected]d0b8d092010-10-25 04:05:171224int TabContents::GetZoomPercent(bool* enable_increment,
1225 bool* enable_decrement) {
1226 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011227 // Calculate the zoom percent from the factor. Round up to the nearest whole
1228 // number.
[email protected]b75b8292010-10-01 07:28:251229 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011230 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251231 *enable_decrement = percent > minimum_zoom_percent_;
1232 *enable_increment = percent < maximum_zoom_percent_;
1233 return percent;
1234}
1235
[email protected]3c733bde2010-12-21 19:56:311236void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501237 if (!delegate_)
1238 return;
1239
[email protected]10f417c52011-12-28 21:04:231240 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501241 if (!active_entry)
1242 return;
1243
[email protected]36fc0392011-12-25 03:59:511244 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121245}
1246
[email protected]932b7a12011-03-09 12:50:271247void TabContents::ViewFrameSource(const GURL& url,
1248 const std::string& content_state) {
1249 if (!delegate_)
1250 return;
1251
1252 delegate_->ViewSourceForFrame(this, url, content_state);
1253}
1254
[email protected]0bfbf882011-12-22 18:19:271255int TabContents::GetMinimumZoomPercent() const {
1256 return minimum_zoom_percent_;
1257}
1258
1259int TabContents::GetMaximumZoomPercent() const {
1260 return maximum_zoom_percent_;
1261}
1262
[email protected]bcd2815602012-01-14 18:17:231263gfx::Size TabContents::GetPreferredSize() const {
1264 return preferred_size_;
1265}
1266
[email protected]0bfbf882011-12-22 18:19:271267int TabContents::GetContentRestrictions() const {
1268 return content_restrictions_;
1269}
1270
1271WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501272 WebUIControllerFactory* factory =
1273 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1274 if (!factory)
1275 return WebUI::kNoWebUI;
1276 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271277}
1278
[email protected]01ec4ec2012-01-18 04:13:471279content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271280 // When there is a pending navigation entry, we want to use the pending WebUI
1281 // that goes along with it to control the basic flags. For example, we want to
1282 // show the pending URL in the URL bar, so we want the display_url flag to
1283 // be from the pending entry.
1284 //
1285 // The confusion comes because there are multiple possibilities for the
1286 // initial load in a tab as a side effect of the way the RenderViewHostManager
1287 // works.
1288 //
1289 // - For the very first tab the load looks "normal". The new tab Web UI is
1290 // the pending one, and we want it to apply here.
1291 //
1292 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1293 // get switched to the one previously associated with the new tab pages.
1294 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1295 // have a committed Web UI in this case.
1296 //
1297 // This condition handles all of these cases:
1298 //
1299 // - First load in first tab: no committed nav entry + pending nav entry +
1300 // pending dom ui:
1301 // -> Use pending Web UI if any.
1302 //
1303 // - First load in second tab: no committed nav entry + pending nav entry +
1304 // no pending Web UI:
1305 // -> Use the committed Web UI if any.
1306 //
1307 // - Second navigation in any tab: committed nav entry + pending nav entry:
1308 // -> Use pending Web UI if any.
1309 //
1310 // - Normal state with no load: committed nav entry + no pending nav entry:
1311 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251312 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271313 (controller_.GetLastCommittedEntry() ||
1314 render_manager_.pending_web_ui()))
1315 return render_manager_.pending_web_ui();
1316 return render_manager_.web_ui();
1317}
1318
1319bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1320 return GetRenderViewHost() ?
1321 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1322}
1323
1324bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471325 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271326 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221327 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231328 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511329 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271330 return true;
1331 return false;
1332}
1333
1334void TabContents::SetFocusToLocationBar(bool select_all) {
1335 if (delegate_)
1336 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211337}
1338
[email protected]8b5af492011-11-28 21:50:581339void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301340 const string16& type,
1341 const string16& href,
1342 const string16& title,
1343 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511344 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301345 this, action, type, href, title, disposition);
1346}
1347
[email protected]678105012011-12-09 04:01:211348void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301349 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001350 WebIntentsDispatcherImpl* intents_dispatcher =
1351 new WebIntentsDispatcherImpl(this, intent, intent_id);
1352 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301353}
1354
[email protected]724159a2010-12-30 01:11:181355void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1356 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591357 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181358 const GURL& url) {
1359 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1360 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591361 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301362 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181363
[email protected]8093a542011-05-13 07:29:321364 RenderViewHost* rvh =
1365 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521366 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101367 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251368 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101369 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321370 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101371
[email protected]724159a2010-12-30 01:11:181372 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591373 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251374 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591375 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181376 }
1377}
1378
1379void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591380 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181381 const GURL& source_url,
1382 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491383 // TODO(creis): Remove this method and have the pre-rendering code listen to
1384 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1385 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231386 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181387 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251388 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181389 else
1390 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511391 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181392 return;
[email protected]e7d50892011-01-19 21:47:381393
[email protected]4850a7f2011-03-08 23:36:591394 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251395 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261396 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591397 opener_url));
[email protected]724159a2010-12-30 01:11:181398}
1399
1400void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581401 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1402 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1403 << ", error_code: " << params.error_code
1404 << ", error_description: " << params.error_description
1405 << ", is_main_frame: " << params.is_main_frame
1406 << ", showing_repost_interstitial: " <<
1407 params.showing_repost_interstitial
1408 << ", frame_id: " << params.frame_id;
1409 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591410 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301411 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181412
[email protected]d7b175e2011-10-11 15:31:581413 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181414 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1415 // This means that the interstitial won't be torn down properly, which is
1416 // bad. But if we have an interstitial, go back to another tab type, and
1417 // then load the same interstitial again, we could end up getting the first
1418 // interstitial's "failed" message (as a result of the cancel) when we're on
1419 // the second one.
1420 //
1421 // We can't tell this apart, so we think we're tearing down the current page
1422 // which will cause a crash later one. There is also some code in
1423 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1424 // out because of this problem.
1425 //
1426 // http://code.google.com/p/chromium/issues/detail?id=2855
1427 // Because this will not tear down the interstitial properly, if "back" is
1428 // back to another tab type, the interstitial will still be somewhat alive
1429 // in the previous tab type. If you navigate somewhere that activates the
1430 // tab with the interstitial again, you'll see a flash before the new load
1431 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271432 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181433 LOG(WARNING) << "Discarding message during interstitial.";
1434 return;
1435 }
1436
[email protected]02102f82011-06-13 20:37:021437 // Discard our pending entry if the load canceled (e.g. if we decided to
1438 // download the file instead of load it). We do not verify that the URL
1439 // being canceled matches the pending entry's URL because they will not
1440 // match if a redirect occurred (in which case we do not want to leave a
1441 // stale redirect URL showing). This means that we also cancel the pending
1442 // entry if the user started a new navigation. As a result, the navigation
1443 // controller may not remember that a load is in progress, but the
1444 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251445 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161446 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181447
[email protected]151a63d2011-12-20 22:32:521448 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181449 }
1450
1451 // Send out a notification that we failed a provisional load with an error.
1452 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581453 params.is_main_frame,
1454 controller_.IsURLInPageNavigation(validated_url),
1455 validated_url,
1456 std::string(),
1457 false,
1458 params.frame_id);
1459 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181460
[email protected]ad50def52011-10-19 23:17:071461 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271462 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501463 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531464 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101465
[email protected]d8c660432011-12-22 20:51:251466 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581467 observers_,
1468 DidFailProvisionalLoad(params.frame_id,
1469 params.is_main_frame,
1470 validated_url,
1471 params.error_code,
1472 params.error_description));
[email protected]724159a2010-12-30 01:11:181473}
1474
1475void TabContents::OnDidLoadResourceFromMemoryCache(
1476 const GURL& url,
[email protected]70435962011-08-02 20:13:281477 const std::string& security_info,
1478 const std::string& http_method,
1479 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191480 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181481 cache.Increment();
1482
1483 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081484 int cert_id = 0;
1485 net::CertStatus cert_status = 0;
1486 int security_bits = -1;
1487 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511488 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1489 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301490 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161491 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181492
[email protected]ad50def52011-10-19 23:17:071493 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271494 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501495 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531496 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181497}
1498
1499void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381500 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181501 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201502 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181503}
1504
1505void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021506 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231507 LOG(INFO) << security_origin << " ran insecure content from "
1508 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381509 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051510 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381511 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051512 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1513 }
[email protected]330614de2012-02-13 17:07:181514 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411515 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201516 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181517}
1518
1519void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1520 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101522 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181523}
1524
[email protected]1a55c5be2011-11-29 11:36:311525void TabContents::OnDidFinishLoad(
1526 int64 frame_id,
1527 const GURL& validated_url,
1528 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251529 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311530 DidFinishLoad(frame_id, validated_url, is_main_frame));
1531}
1532
1533void TabContents::OnDidFailLoadWithError(int64 frame_id,
1534 const GURL& validated_url,
1535 bool is_main_frame,
1536 int error_code,
1537 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251538 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311539 DidFailLoad(frame_id, validated_url, is_main_frame,
1540 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181541}
1542
[email protected]c8f73ab2011-01-22 00:05:171543void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271544 content_restrictions_ = restrictions;
1545 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171546}
1547
[email protected]216813952011-05-19 22:21:261548void TabContents::OnGoToEntryAtOffset(int offset) {
1549 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231550 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251551 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261552 if (!entry)
1553 return;
1554 // Note that we don't call NavigationController::GotToOffset() as we don't
1555 // want to create a pending navigation entry (it might end up lingering
1556 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251557 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581558 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511559 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581560 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471561 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571562
1563 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1564 // it in now that we know. This allows us to find the entry when it commits.
1565 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231566 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331567 entry->set_site_instance(
1568 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571569 }
[email protected]216813952011-05-19 22:21:261570 }
1571}
1572
1573void TabContents::OnUpdateZoomLimits(int minimum_percent,
1574 int maximum_percent,
1575 bool remember) {
1576 minimum_zoom_percent_ = minimum_percent;
1577 maximum_zoom_percent_ = maximum_percent;
1578 temporary_zoom_settings_ = !remember;
1579}
1580
[email protected]0bfbf882011-12-22 18:19:271581void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481582 download_stats::RecordDownloadSource(
1583 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261584 // Check if the URL to save matches the URL of the main frame. Since this
1585 // message originates from Pepper plugins, it may not be the case if the
1586 // plugin is an embedded element.
1587 GURL main_frame_url = GetURL();
1588 if (!main_frame_url.is_valid())
1589 return;
1590 bool is_main_frame = (url == main_frame_url);
1591 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271592}
1593
[email protected]3a29a6e2011-08-24 18:26:211594void TabContents::OnEnumerateDirectory(int request_id,
1595 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591596 ChildProcessSecurityPolicyImpl* policy =
1597 ChildProcessSecurityPolicyImpl::GetInstance();
1598 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1599 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211600}
1601
[email protected]7d189022011-08-25 22:54:201602void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511603 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201604}
1605
1606void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1607 const GURL& url,
1608 const string16& title) {
[email protected]b9535422012-02-09 01:47:591609 ChildProcessSecurityPolicyImpl* policy =
1610 ChildProcessSecurityPolicyImpl::GetInstance();
1611 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1612 return;
[email protected]6934a702011-12-20 00:04:511613 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201614}
1615
[email protected]b888919c2011-09-02 00:32:161616void TabContents::OnFindReply(int request_id,
1617 int number_of_matches,
1618 const gfx::Rect& selection_rect,
1619 int active_match_ordinal,
1620 bool final_update) {
[email protected]6934a702011-12-20 00:04:511621 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1622 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001623 // Send a notification to the renderer that we are ready to receive more
1624 // results from the scoping effort of the Find operation. The FindInPage
1625 // scoping is asynchronous and periodically sends results back up to the
1626 // browser using IPC. In an effort to not spam the browser we have the
1627 // browser send an ACK for each FindReply message and have the renderer
1628 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521629 GetRenderViewHost()->Send(
1630 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161631}
1632
[email protected]d952a052011-09-06 18:42:451633void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511634 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451635}
1636
[email protected]7fc4bbb2011-09-08 21:23:101637void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1638 bool blocked_by_policy) {
1639 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101641 AppCacheAccessed(manifest_url, blocked_by_policy));
1642}
1643
[email protected]96d185d2009-04-24 03:28:541644// Notifies the RenderWidgetHost instance about the fact that the page is
1645// loading, or done loading and calls the base implementation.
1646void TabContents::SetIsLoading(bool is_loading,
1647 LoadNotificationDetails* details) {
1648 if (is_loading == is_loading_)
1649 return;
1650
1651 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211652 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541653 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561654 upload_size_ = 0;
1655 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541656 }
1657
1658 render_manager_.SetIsLoading(is_loading);
1659
1660 is_loading_ = is_loading;
1661 waiting_for_response_ = is_loading;
1662
[email protected]6ebdc9b2010-09-27 16:55:571663 if (delegate_)
1664 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461665 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541666
[email protected]432115822011-07-10 15:52:271667 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1668 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071669 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541670 if (details)
[email protected]6c2381d2011-10-19 02:52:531671 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071672 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501673 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541674 det);
1675}
1676
[email protected]420ae012009-04-24 05:16:321677void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131678 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321679 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561680 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381681 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441682 // that opened the window, as long as both renderers have the same
1683 // privileges.
[email protected]1fd1a502011-03-30 16:55:561684 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561685 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581686 // web_ui might be NULL if the URL refers to a non-existent extension.
1687 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401688 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521689 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441690 }
1691 }
[email protected]1fd1a502011-03-30 16:55:561692 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441693 }
1694
[email protected]4e697b042011-07-08 06:44:561695 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321696 // Clear the status bubble. This is a workaround for a bug where WebKit
1697 // doesn't let us know that the cursor left an element during a
1698 // transition (this is also why the mouse cursor remains as a hand after
1699 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1700 // clear the bubble when a user navigates to a named anchor in the same
1701 // page.
[email protected]36fc0392011-12-25 03:59:511702 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321703 }
1704
[email protected]a6e82fc2010-02-24 22:28:141705 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471706 // Once the main frame is navigated, we're no longer considered to have
1707 // displayed insecure content.
1708 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171709 }
[email protected]ce5c4502009-05-06 16:46:111710
[email protected]3c9e1872010-11-18 16:17:491711 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251712 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041713 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321714}
1715
1716void TabContents::DidNavigateAnyFramePostCommit(
1717 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131718 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321719 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061720 // If we navigate off the page, reset JavaScript state. This does nothing
1721 // to prevent a malicious script from spamming messages, since the script
1722 // could just reload the page to stop blocking.
1723 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551724 dialog_creator_->ResetJavaScriptState(this);
1725 dialog_creator_ = NULL;
1726 }
[email protected]420ae012009-04-24 05:16:321727
[email protected]3c9e1872010-11-18 16:17:491728 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041730 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]74ce1ad2011-12-16 21:51:461733void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1734 // If we are creating a RVH for a restored controller, then we need to make
1735 // sure the RenderView starts with a next_page_id_ larger than the number
1736 // of restored entries. This must be called before the RenderView starts
1737 // navigating (to avoid a race between the browser updating max_page_id and
1738 // the renderer updating next_page_id_). Because of this, we only call this
1739 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561740 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461741 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1742 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321743}
1744
[email protected]10f417c52011-12-28 21:04:231745bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571746 const string16& title) {
[email protected]420ae012009-04-24 05:16:321747 // For file URLs without a title, use the pathname instead. In the case of a
1748 // synthesized title, we don't want the update to count toward the "one set
1749 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511750 string16 final_title;
[email protected]420ae012009-04-24 05:16:321751 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511752 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1753 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321754 explicit_set = false; // Don't count synthetic titles toward the set limit.
1755 } else {
[email protected]acafd272011-07-26 17:35:571756 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321757 explicit_set = true;
1758 }
1759
[email protected]987fc3a2011-05-26 14:18:091760 // If a page is created via window.open and never navigated,
1761 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551762 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091763 if (entry) {
[email protected]36fc0392011-12-25 03:59:511764 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091765 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321766
[email protected]36fc0392011-12-25 03:59:511767 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091768 } else {
1769 if (page_title_when_no_navigation_entry_ == final_title)
1770 return false; // Nothing changed, don't bother.
1771
1772 page_title_when_no_navigation_entry_ = final_title;
1773 }
[email protected]420ae012009-04-24 05:16:321774
[email protected]420ae012009-04-24 05:16:321775 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231776 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321777
[email protected]105bb0f2011-05-24 17:12:141778 TitleUpdatedDetails details(entry, explicit_set);
1779
[email protected]ad50def52011-10-19 23:17:071780 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441781 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1782 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531783 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041784
[email protected]420ae012009-04-24 05:16:321785 return true;
1786}
1787
1788void TabContents::NotifySwapped() {
1789 // After sending out a swap notification, we need to send a disconnect
1790 // notification so that clients that pick up a pointer to |this| can NULL the
1791 // pointer. See Bug 1230284.
1792 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071793 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201794 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1795 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071796 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321797}
1798
1799void TabContents::NotifyConnected() {
1800 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071801 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121802 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1803 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071804 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321805}
1806
1807void TabContents::NotifyDisconnected() {
1808 if (!notify_disconnection_)
1809 return;
1810
1811 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071812 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321813 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1814 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071815 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321816}
1817
[email protected]8d3347f2009-07-09 22:00:211818RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321819 return view_.get();
1820}
1821
[email protected]8d3347f2009-07-09 22:00:211822RenderViewHostDelegate::RendererManagement*
1823TabContents::GetRendererManagementDelegate() {
1824 return &render_manager_;
1825}
1826
[email protected]daf82f82011-10-31 22:35:311827content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371828 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461829 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511830}
1831
[email protected]768c5472011-12-26 19:06:171832WebContents* TabContents::GetAsWebContents() {
1833 return this;
1834}
1835
[email protected]da4dfc42011-10-12 15:53:561836content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431837 return view_type_;
[email protected]7b291f92009-08-14 05:43:531838}
1839
[email protected]b7a756d42012-01-23 18:08:171840gfx::Rect TabContents::GetRootWindowResizerRect() const {
1841 if (delegate_)
1842 return delegate_->GetRootWindowResizerRect();
1843 return gfx::Rect();
1844}
1845
[email protected]420ae012009-04-24 05:16:321846void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071847 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271848 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321849 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531850 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231851 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321852 if (!entry)
1853 return;
1854
1855 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351856 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561857 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581858 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321859
1860 if (entry->IsViewSourceMode()) {
1861 // Put the renderer in view source mode.
1862 render_view_host->Send(
1863 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1864 }
[email protected]0666aef2009-05-13 19:48:081865
[email protected]d487beefe2011-12-21 05:41:211866 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261867
1868 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251869 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321870}
1871
1872void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521873 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321874 // Don't notify the world, since this came from a renderer in the
1875 // background.
1876 return;
1877 }
1878
1879 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311880 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231881 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301882
1883 // Restore the focus to the tab (otherwise the focus will be on the top
1884 // window).
[email protected]484ae5912010-09-29 19:16:141885 if (was_crashed && !FocusLocationBarByDefault() &&
1886 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301887 Focus();
[email protected]484ae5912010-09-29 19:16:141888 }
[email protected]32ded2212011-11-10 18:51:431889
[email protected]d8c660432011-12-22 20:51:251890 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321891}
1892
[email protected]443b80e2010-12-14 00:42:231893void TabContents::RenderViewGone(RenderViewHost* rvh,
1894 base::TerminationStatus status,
1895 int error_code) {
[email protected]151a63d2011-12-20 22:32:521896 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321897 // The pending page's RenderViewHost is gone.
1898 return;
1899 }
1900
1901 SetIsLoading(false, NULL);
1902 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231903 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311904 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321905
[email protected]d8c660432011-12-22 20:51:251906 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271907 observers_,
[email protected]be1f56ab2011-12-22 06:55:311908 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321909}
1910
[email protected]2e4633c2009-07-09 16:58:061911void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481912 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251913 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061914}
1915
[email protected]420ae012009-04-24 05:16:321916void TabContents::DidNavigate(RenderViewHost* rvh,
1917 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581918 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321919 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371920
[email protected]434f69f2012-02-06 21:56:521921 // Update the site of the SiteInstance if it doesn't have one yet, unless
1922 // this is for about:blank. In that case, the SiteInstance can still be
1923 // considered unused until a navigation to a real page.
1924 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1925 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331926 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521927 }
[email protected]420ae012009-04-24 05:16:321928
1929 // Need to update MIME type here because it's referred to in
1930 // UpdateNavigationCommands() called by RendererDidNavigate() to
1931 // determine whether or not to enable the encoding menu.
1932 // It's updated only for the main frame. For a subframe,
1933 // RenderView::UpdateURL does not set params.contents_mime_type.
1934 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1935 // TODO(jungshik): Add a test for the encoding menu to avoid
1936 // regressing it again.
[email protected]2905f742011-10-13 03:51:581937 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321938 contents_mime_type_ = params.contents_mime_type;
1939
[email protected]8286f51a2011-05-31 17:39:131940 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001941 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391942
[email protected]a9c0bfe2010-09-17 08:35:221943 // Send notification about committed provisional loads. This notification is
1944 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1945 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081946 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071947 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1948 // that is not recorded in the navigation history. For the purpose of
1949 // tracking navigation events, we treat this event as a sub frame navigation
1950 // event.
1951 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581952 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221953 // Whether or not a page transition was triggered by going backward or
1954 // forward in the history is only stored in the navigation controller's
1955 // entry list.
1956 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511957 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581958 content::PAGE_TRANSITION_FORWARD_BACK)) {
1959 transition_type = content::PageTransitionFromInt(
1960 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221961 }
[email protected]0d60f0192011-04-14 12:40:101962 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101964 DidCommitProvisionalLoadForFrame(params.frame_id,
1965 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221966 }
1967
[email protected]76543b92009-08-31 17:27:451968 if (!did_navigate)
1969 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321970
1971 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1972 // for the appropriate notification (best) or you can add it to
1973 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1974 // necessary, please).
1975
1976 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001977 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321978 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511979 if (delegate_)
1980 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001981 }
[email protected]420ae012009-04-24 05:16:321982 DidNavigateAnyFramePostCommit(rvh, details, params);
1983}
1984
1985void TabContents::UpdateState(RenderViewHost* rvh,
1986 int32 page_id,
1987 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151988 // Ensure that this state update comes from either the active RVH or one of
1989 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521990 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321991
1992 // We must be prepared to handle state updates for any page, these occur
1993 // when the user is scrolling and entering form data, as well as when we're
1994 // leaving a page, in which case our state may have already been moved to
1995 // the next page. The navigation controller will look up the appropriate
1996 // NavigationEntry and update it when it is notified via the delegate.
1997
1998 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151999 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:322000 if (entry_index < 0)
2001 return;
[email protected]10f417c52011-12-28 21:04:232002 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322003
[email protected]36fc0392011-12-25 03:59:512004 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322005 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512006 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322007 controller_.NotifyEntryChanged(entry, entry_index);
2008}
2009
2010void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572011 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462012 const string16& title,
2013 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322014 // If we have a title, that's a pretty good indication that we've started
2015 // getting useful data.
2016 SetNotWaitingForResponse();
2017
[email protected]73eb2602012-02-09 19:50:552018 // Try to find the navigation entry, which might not be the current one.
2019 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232020 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2021 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092022
[email protected]73eb2602012-02-09 19:50:552023 // We can handle title updates when we don't have an entry in
2024 // UpdateTitleForEntry, but only if the update is from the current RVH.
2025 if (!entry && rvh != GetRenderViewHost())
2026 return;
2027
[email protected]a49e10b2011-08-01 23:57:462028 // TODO(evan): make use of title_direction.
2029 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092030 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322031 return;
2032
2033 // Broadcast notifications when the UI should be updated.
2034 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462035 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322036}
2037
[email protected]420ae012009-04-24 05:16:322038void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402039 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312040 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322041}
2042
2043void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512044 if (delegate_)
2045 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322046}
2047
[email protected]420ae012009-04-24 05:16:322048void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292049 // The UI may be in an event-tracking loop, such as between the
2050 // mouse-down and mouse-up in text selection or a button click.
2051 // Defer the close until after tracking is complete, so that we
2052 // don't free objects out from under the UI.
2053 // TODO(shess): This could probably be integrated with the
2054 // IsDoingDrag() test below. Punting for now because I need more
2055 // research to understand how this impacts platforms other than Mac.
2056 // TODO(shess): This could get more fine-grained. For instance,
2057 // closing a tab in another window while selecting text in the
2058 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212059 if (GetView()->IsEventTracking()) {
2060 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292061 return;
2062 }
2063
[email protected]24a4d1062009-07-10 23:10:422064 // If we close the tab while we're in the middle of a drag, we'll crash.
2065 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212066 if (GetView()->IsDoingDrag()) {
2067 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422068 return;
2069 }
2070
[email protected]420ae012009-04-24 05:16:322071 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522072 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512073 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322074}
2075
[email protected]cd9ed79d2011-11-15 19:22:572076void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522077 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512078 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572079}
2080
[email protected]420ae012009-04-24 05:16:322081void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512082 if (delegate_ && delegate_->IsPopupOrPanel(this))
2083 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322084}
2085
[email protected]7ab1e7d62009-10-14 23:32:012086void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322087 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492088
[email protected]6934a702011-12-20 00:04:512089 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212090 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512091 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002092 }
[email protected]3c9e1872010-11-18 16:17:492093
2094 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252095 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322096}
2097
[email protected]7ab1e7d62009-10-14 23:32:012098void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322099 scoped_ptr<LoadNotificationDetails> details;
2100
[email protected]10f417c52011-12-28 21:04:232101 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322102 // An entry may not exist for a stop when loading an initial blank page or
2103 // if an iframe injected by script into a blank page finishes loading.
2104 if (entry) {
[email protected]420ae012009-04-24 05:16:322105 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2106
2107 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512108 entry->GetVirtualURL(),
2109 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322110 elapsed,
2111 &controller_,
2112 controller_.GetCurrentEntryIndex()));
2113 }
2114
[email protected]420ae012009-04-24 05:16:322115 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492116
2117 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252118 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322119}
2120
[email protected]c95fa8b2011-04-28 20:26:162121void TabContents::DidCancelLoading() {
2122 controller_.DiscardNonCommittedEntries();
2123
2124 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462125 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162126}
2127
[email protected]1a3c3cb2010-12-16 21:03:402128void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512129 if (delegate_)
2130 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402131}
2132
[email protected]952a68e2011-11-17 00:36:102133void TabContents::DocumentAvailableInMainFrame(
2134 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252135 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102136 DocumentAvailableInMainFrame());
2137}
2138
[email protected]25497492010-09-11 15:15:082139void TabContents::DocumentOnLoadCompletedInMainFrame(
2140 RenderViewHost* render_view_host,
2141 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072142 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272143 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322144 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532145 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082146}
2147
[email protected]ae5184d62011-10-06 19:25:582148void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152149 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582150 WindowOpenDisposition disposition,
2151 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482152 // Delegate to RequestTransferURL because this is just the generic
2153 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582154 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482155 GlobalRequestID());
2156}
2157
2158void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582159 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482160 WindowOpenDisposition disposition,
2161 int64 source_frame_id,
2162 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202163 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582164 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582165 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352166 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322167 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2168 // generated suggestions).
2169 //
[email protected]e0112912011-02-02 22:54:352170 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162171 // want web sites to see a referrer of "chrome://blah" (and some
2172 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322173 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432174 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222175 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482176 false /* is_renderer_initiated */);
2177 params.transferred_global_request_id = old_request_id;
2178 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222179 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322180 } else {
[email protected]6bf6a6b52012-02-03 15:41:432181 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482182 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2183 params.transferred_global_request_id = old_request_id;
2184 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582185 }
2186 if (new_contents) {
2187 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252188 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582189 DidOpenRequestedURL(new_contents,
2190 url,
2191 referrer,
2192 disposition,
2193 transition_type,
2194 source_frame_id));
[email protected]420ae012009-04-24 05:16:322195 }
2196}
2197
[email protected]420ae012009-04-24 05:16:322198void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342199 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412200 const string16& message,
2201 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322202 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472203 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322204 IPC::Message* reply_msg,
2205 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072206 // Suppress JavaScript dialogs when requested. Also suppress messages when
2207 // showing an interstitial as it's shown over the previous page and we don't
2208 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502209 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152210 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272211 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072212 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522213 delegate_->ShouldSuppressDialogs() ||
2214 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322215
2216 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342217 content::JavaScriptDialogCreator::TitleType title_type;
2218 string16 title;
2219
2220 if (!frame_url.has_host()) {
2221 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2222 } else {
2223 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2224 title = net::FormatUrl(
2225 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202226 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302227 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342228 }
2229
[email protected]2e5b90c2011-08-16 21:11:552230 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522231 dialog_creator_->RunJavaScriptDialog(
2232 this, title_type, title, javascript_message_type, message,
2233 default_prompt,
2234 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2235 reply_msg),
2236 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322237 }
[email protected]3ab9cb82011-06-03 18:02:072238
2239 if (suppress_this_message) {
2240 // If we are suppressing messages, just reply as if the user immediately
2241 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342242 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072243 }
2244
2245 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322246}
2247
[email protected]fedec012012-01-28 03:09:342248void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412249 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322250 bool is_reload,
[email protected]420ae012009-04-24 05:16:322251 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512252 if (delegate_)
2253 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072254
2255 bool suppress_this_message =
2256 rvh->is_swapped_out() ||
2257 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522258 delegate_->ShouldSuppressDialogs() ||
2259 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152260 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342261 // The reply must be sent to the RVH that sent the request.
2262 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502263 return;
2264 }
[email protected]3ab9cb82011-06-03 18:02:072265
[email protected]7ab1e7d62009-10-14 23:32:012266 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552267 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522268 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322269 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522270 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2271 reply_msg));
[email protected]420ae012009-04-24 05:16:322272}
2273
[email protected]420ae012009-04-24 05:16:322274WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542275 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322276}
2277
[email protected]7d472472011-01-22 01:30:252278void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272279 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252280 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222281
[email protected]99907362012-01-11 05:41:402282 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172283 if (rdh) // NULL in unittests.
2284 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252285}
2286
[email protected]fa1cf0b82010-01-15 21:49:442287void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442288 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252289 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442290}
2291
[email protected]420ae012009-04-24 05:16:322292void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2293 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152294 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522295 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152296 return;
2297
[email protected]e5fc1632011-08-08 07:51:532298 // Ignore renderer unresponsive event if debugger is attached to the tab
2299 // since the event may be a result of the renderer sitting on a breakpoint.
2300 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442301 DevToolsAgentHost* agent =
2302 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2303 if (agent &&
2304 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532305 return;
2306
[email protected]420ae012009-04-24 05:16:322307 if (is_during_unload) {
2308 // Hang occurred while firing the beforeunload/unload handler.
2309 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112310 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322311
2312 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2313 return;
2314
2315 // If the tab hangs in the beforeunload/unload handler there's really
2316 // nothing we can do to recover. Pretend the unload listeners have
2317 // all fired and close the tab. If the hang is in the beforeunload handler
2318 // then the user will not have the option of cancelling the close.
2319 Close(rvh);
2320 return;
2321 }
2322
[email protected]151a63d2011-12-20 22:32:522323 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472324 return;
2325
[email protected]6934a702011-12-20 00:04:512326 if (delegate_)
2327 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322328}
2329
2330void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512331 if (delegate_)
2332 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322333}
2334
2335void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212336 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562337 uint64 upload_position,
2338 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322339 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562340 upload_position_ = upload_position;
2341 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502342 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202343 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302344 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212345 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322346 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462347 if (IsLoading()) {
2348 NotifyNavigationStateChanged(
2349 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2350 }
[email protected]420ae012009-04-24 05:16:322351}
2352
[email protected]7d472472011-01-22 01:30:252353void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512354 if (delegate_)
2355 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252356}
2357
[email protected]420ae012009-04-24 05:16:322358void TabContents::BeforeUnloadFiredFromRenderManager(
2359 bool proceed,
2360 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512361 if (delegate_)
2362 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322363}
2364
[email protected]3a3d47472010-07-15 21:03:542365void TabContents::DidStartLoadingFromRenderManager(
2366 RenderViewHost* render_view_host) {
2367 DidStartLoading();
2368}
2369
2370void TabContents::RenderViewGoneFromRenderManager(
2371 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232372 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2373 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542374}
2375
[email protected]420ae012009-04-24 05:16:322376void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102377 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262378 gfx::Size size = view_->GetContainerSize();
2379 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2380 // here during container initialization and normal window size will be set
2381 // later. In case of tab duplication this resizing to 0x0 prevents setting
2382 // normal size later so just ignore it.
2383 if (!size.IsEmpty())
2384 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322385}
2386
[email protected]3a3d47472010-07-15 21:03:542387void TabContents::NotifySwappedFromRenderManager() {
2388 NotifySwapped();
2389}
2390
[email protected]d202a7c2012-01-04 07:53:472391NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202392 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542393}
2394
[email protected]d2353452012-01-19 19:53:562395WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2396 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322397}
2398
[email protected]10f417c52011-12-28 21:04:232399NavigationEntry*
2400 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322401 return controller_.GetLastCommittedEntry();
2402}
2403
2404bool TabContents::CreateRenderViewForRenderManager(
2405 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442406 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322407 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522408
[email protected]420ae012009-04-24 05:16:322409 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442410 if (rwh_view)
2411 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322412
[email protected]74ce1ad2011-12-16 21:51:462413 // Make sure we use the correct starting page_id in the new RenderView.
2414 UpdateMaxPageIDIfNecessary(render_view_host);
2415 int32 max_page_id =
2416 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2417
2418 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522419 return false;
2420
[email protected]e60c0232011-11-11 19:56:352421#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502422 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2423 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442424 if (rwh_view) {
2425 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2426 render_widget_host->WasResized();
2427 }
[email protected]f8233cc2011-05-31 20:24:502428#endif
2429
[email protected]420ae012009-04-24 05:16:322430 return true;
2431}
2432
[email protected]fedec012012-01-28 03:09:342433void TabContents::OnDialogClosed(RenderViewHost* rvh,
2434 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072435 bool success,
2436 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542437 if (is_showing_before_unload_dialog_ && !success) {
2438 // If a beforeunload dialog is canceled, we need to stop the throbber from
2439 // spinning, since we forced it to start spinning in Navigate.
2440 DidStopLoading();
2441
2442 tab_close_start_time_ = base::TimeTicks();
2443 }
2444 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342445 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542446}
2447
[email protected]be1f56ab2011-12-22 06:55:312448void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122449 encoding_ = content::GetContentClient()->browser()->
2450 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102451}
[email protected]f45d2a72010-03-08 23:28:352452
[email protected]e30d68d2012-02-09 00:06:262453void TabContents::SaveURL(const GURL& url,
2454 const GURL& referrer,
2455 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142456 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2457 if (!dlm)
2458 return;
2459 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262460 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142461 const NavigationEntry* entry = controller_.GetActiveEntry();
2462 if (entry)
2463 post_id = entry->GetPostID();
2464 }
2465 DownloadSaveInfo save_info;
2466 save_info.prompt_for_save_location = true;
2467 dlm->DownloadUrl(url,
2468 referrer,
2469 "",
2470 true, // prefer_cache
2471 post_id,
2472 save_info,
2473 this);
2474}
2475
[email protected]33f74972010-12-08 16:40:362476void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212477 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442478 // Can be NULL during tests.
2479 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212480 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362481}