blob: d3eb48bf7dd9f61eee0a6e2db21127b7602a34b3 [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]567812d2011-02-24 17:40:5023#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0024#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0125#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0426#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3027#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/render_view_host.h"
[email protected]686493142011-07-15 21:47:2229#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5030#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1332#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2333#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1435#include "content/browser/tab_contents/title_updated_details.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5840#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1141#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4645#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1546#include "content/public/browser/javascript_dialogs.h"
[email protected]5b96836f2011-12-22 07:39:0047#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3849#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4250#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2551#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1052#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5053#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2154#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1856#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5457#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1659#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2960#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5461#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3462#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3763#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3864#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2465#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3166#include "webkit/glue/webpreferences.h"
67
68#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1269#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3170#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0071
[email protected]420ae012009-04-24 05:16:3272// Cross-Site Navigations
73//
74// If a TabContents is told to navigate to a different web site (as determined
75// by SiteInstance), it will replace its current RenderViewHost with a new
76// RenderViewHost dedicated to the new SiteInstance. This works as follows:
77//
78// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4679// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3280// - The pending RVH is "suspended," so that no navigation messages are sent to
81// its renderer until the onbeforeunload JavaScript handler has a chance to
82// run in the current RVH.
83// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
84// that it has a pending cross-site request. ResourceDispatcherHost will
85// check for this when the response arrives.
86// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4687// cancel all the pending logic. Otherwise we allow the pending RVH to send
88// the navigation request to its renderer.
89// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
90// main resource load on the pending RVH. It checks CrossSiteRequestManager
91// to see that it is a cross-site request, and installs a
92// CrossSiteResourceHandler.
93// - When RDH receives a response, the BufferedResourceHandler determines
94// whether it is a download. If so, it sends a message to the new renderer
95// causing it to cancel the request, and the download proceeds. For now, the
96// pending RVH remains until the next DidNavigate event for this TabContents.
97// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3298// - After RDH receives a response and determines that it is safe and not a
99// download, it pauses the response to first run the old page's onunload
100// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15101// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32102// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15103// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32104// the ResourceDispatcherHost, who unpauses the response. Data is then sent
105// to the pending RVH.
106// - The pending renderer sends a FrameNavigate message that invokes the
107// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46108// pending RVH.
[email protected]992db4c2011-05-12 15:37:15109// - The previous renderer is kept swapped out in RenderViewHostManager in case
110// the user goes back. The process only stays live if another tab is using
111// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32112
[email protected]0e12d7d2011-12-01 16:21:44113using content::DevToolsAgentHost;
114using content::DevToolsAgentHostRegistry;
115using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17116using content::DownloadItem;
117using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20118using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56119using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13120using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50121using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23122using content::NavigationEntry;
123using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20124using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57125using content::RenderViewHostDelegate;
[email protected]5626b0892012-02-20 14:46:58126using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04127using content::RenderWidgetHostViewPort;
[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) {
217 return new TabContents(browser_context,
218 site_instance,
219 routing_id,
220 static_cast<const TabContents*>(base_tab_contents),
221 session_storage_namespace);
222}
223}
[email protected]f4f50ef2011-01-21 19:01:19224
225// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32226
[email protected]3d7474ff2011-07-27 17:47:37227TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32228 SiteInstance* site_instance,
229 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07230 const TabContents* base_tab_contents,
231 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42232 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07233 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37234 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13235 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10236 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22237 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34238 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23239 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
240 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34241 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21242 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56243 upload_size_(0),
244 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47245 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57246 capturing_contents_(false),
247 is_being_destroyed_(false),
248 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55249 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57250#if defined(OS_WIN)
251 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
252#endif
[email protected]7ab1e7d62009-10-14 23:32:01253 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56254 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38255 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25256 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01257 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25258 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01259 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00260 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43261 content_restrictions_(0),
262 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37263 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32264
[email protected]34ac70502009-09-25 17:07:23265 // We have the initial size of the view be based on the size of the passed in
266 // tab contents (normally a tab from the same window).
267 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21268 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00269
270#if defined(ENABLE_JAVA_BRIDGE)
271 java_bridge_dispatcher_host_manager_.reset(
272 new JavaBridgeDispatcherHostManager(this));
273#endif
[email protected]332af7732009-03-11 13:21:35274}
initial.commit09911bf2008-07-26 23:55:29275
276TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32277 is_being_destroyed_ = true;
278
[email protected]3ab9cb82011-06-03 18:02:07279 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55280 if (dialog_creator_)
281 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07282
[email protected]420ae012009-04-24 05:16:32283 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32284
[email protected]420ae012009-04-24 05:16:32285 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07286 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09287 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
288 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07289 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32290
291 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07292#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32293 // If we still have a window handle, destroy it. GetNativeView can return
294 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42295 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52296 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44297 if (host && host->view())
[email protected]c30585c2012-02-16 15:02:04298 RenderWidgetHostViewPort::FromRWHV(host->view())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42299 }
[email protected]420ae012009-04-24 05:16:32300#endif
[email protected]7ab1e7d62009-10-14 23:32:01301
302 // OnCloseStarted isn't called in unit tests.
303 if (!tab_close_start_time_.is_null()) {
304 UMA_HISTOGRAM_TIMES("Tab.Close",
305 base::TimeTicks::Now() - tab_close_start_time_);
306 }
[email protected]b5a1d11c2011-02-17 03:09:42307
[email protected]d8c660432011-12-22 20:51:25308 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08309
[email protected]6934a702011-12-20 00:04:51310 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42311}
312
[email protected]64d69de42012-02-06 00:19:54313WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
314 const GURL& url) {
315 WebPreferences prefs;
316
317 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
318
319 prefs.developer_extras_enabled = true;
320 prefs.javascript_enabled =
321 !command_line.HasSwitch(switches::kDisableJavaScript);
322 prefs.web_security_enabled =
323 !command_line.HasSwitch(switches::kDisableWebSecurity);
324 prefs.plugins_enabled =
325 !command_line.HasSwitch(switches::kDisablePlugins);
326 prefs.java_enabled =
327 !command_line.HasSwitch(switches::kDisableJava);
328
329 prefs.uses_page_cache =
330 command_line.HasSwitch(switches::kEnableFastback);
331 prefs.remote_fonts_enabled =
332 !command_line.HasSwitch(switches::kDisableRemoteFonts);
333 prefs.xss_auditor_enabled =
334 !command_line.HasSwitch(switches::kDisableXSSAuditor);
335 prefs.application_cache_enabled =
336 !command_line.HasSwitch(switches::kDisableApplicationCache);
337
338 prefs.local_storage_enabled =
339 !command_line.HasSwitch(switches::kDisableLocalStorage);
340 prefs.databases_enabled =
341 !command_line.HasSwitch(switches::kDisableDatabases);
342 prefs.webaudio_enabled =
343 !command_line.HasSwitch(switches::kDisableWebAudio);
344
345 prefs.experimental_webgl_enabled =
346 GpuProcessHost::gpu_enabled() &&
347 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
348 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
349
350 prefs.gl_multisampling_enabled =
351 !command_line.HasSwitch(switches::kDisableGLMultisampling);
352 prefs.privileged_webgl_extensions_enabled =
353 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
354 prefs.site_specific_quirks_enabled =
355 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
356 prefs.allow_file_access_from_file_urls =
357 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
358 prefs.show_composited_layer_borders =
359 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
360 prefs.show_composited_layer_tree =
361 command_line.HasSwitch(switches::kShowCompositedLayerTree);
362 prefs.show_fps_counter =
363 command_line.HasSwitch(switches::kShowFPSCounter);
364 prefs.accelerated_compositing_enabled =
365 GpuProcessHost::gpu_enabled() &&
366 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
367 prefs.threaded_compositing_enabled =
368 command_line.HasSwitch(switches::kEnableThreadedCompositing);
369 prefs.force_compositing_mode =
370 command_line.HasSwitch(switches::kForceCompositingMode);
371 prefs.fixed_position_compositing_enabled =
372 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
373 prefs.accelerated_2d_canvas_enabled =
374 GpuProcessHost::gpu_enabled() &&
375 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58376 prefs.deferred_2d_canvas_enabled =
377 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54378 prefs.accelerated_painting_enabled =
379 GpuProcessHost::gpu_enabled() &&
380 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
381 prefs.accelerated_filters_enabled =
382 GpuProcessHost::gpu_enabled() &&
383 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
384 prefs.accelerated_layers_enabled =
385 prefs.accelerated_animation_enabled =
386 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
387 prefs.composite_to_texture_enabled =
388 command_line.HasSwitch(switches::kEnableCompositeToTexture);
389 prefs.accelerated_plugins_enabled =
390 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
391 prefs.accelerated_video_enabled =
392 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
393 prefs.partial_swap_enabled =
394 command_line.HasSwitch(switches::kEnablePartialSwap);
395 prefs.interactive_form_validation_enabled =
396 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
397 prefs.fullscreen_enabled =
398 !command_line.HasSwitch(switches::kDisableFullScreen);
399
400#if defined(OS_MACOSX)
401 bool default_enable_scroll_animator = true;
402#else
403 // On CrOS, the launcher always passes in the --enable flag.
404 bool default_enable_scroll_animator = false;
405#endif
406 prefs.enable_scroll_animator = default_enable_scroll_animator;
407 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
408 prefs.enable_scroll_animator = true;
409 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
410 prefs.enable_scroll_animator = false;
411
412 prefs.visual_word_movement_enabled =
413 command_line.HasSwitch(switches::kEnableVisualWordMovement);
414 prefs.per_tile_painting_enabled =
415 command_line.HasSwitch(switches::kEnablePerTilePainting);
416
417 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32418 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54419 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11420 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
421 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54422 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11423 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54424 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11425 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54426 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11427 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54428 prefs.gl_multisampling_enabled = false;
429
430 // Accelerated video and animation are slower than regular when using a
431 // software 3d rasterizer.
[email protected]79078df2012-02-16 01:22:32432 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54433 prefs.accelerated_video_enabled = false;
434 prefs.accelerated_animation_enabled = false;
435 }
436 }
437
[email protected]b9535422012-02-09 01:47:59438 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54439 rvh->process()->GetID())) {
440 prefs.loads_images_automatically = true;
441 prefs.javascript_enabled = true;
442 }
443
444 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
445
446 // Force accelerated compositing and 2d canvas off for chrome:, about: and
447 // chrome-devtools: pages (unless it's specifically allowed).
448 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54449 url.SchemeIs(chrome::kChromeUIScheme) ||
450 (url.SchemeIs(chrome::kAboutScheme) &&
451 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25452 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54453 prefs.accelerated_compositing_enabled = false;
454 prefs.accelerated_2d_canvas_enabled = false;
455 }
456
457 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
458
459 return prefs;
460}
461
[email protected]d202a7c2012-01-04 07:53:47462NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20463 return controller_;
464}
465
[email protected]765187182012-01-11 23:59:28466RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
467 return &render_manager_;
468}
469
[email protected]724159a2010-12-30 01:11:18470bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56471 if (GetWebUI() &&
472 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17473 return true;
[email protected]d2353452012-01-19 19:53:56474 }
[email protected]f82d57b52011-04-27 19:13:17475
[email protected]d8c660432011-12-22 20:51:25476 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
477 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10478 while ((observer = it.GetNext()) != NULL)
479 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53480 return true;
[email protected]403415a2011-01-10 18:57:53481
[email protected]724159a2010-12-30 01:11:18482 bool handled = true;
483 bool message_is_ok = true;
484 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58485 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
486 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24487 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
488 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
490 OnDidStartProvisionalLoadForFrame)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
492 OnDidRedirectProvisionalLoad)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
494 OnDidFailProvisionalLoadWithError)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
496 OnDidLoadResourceFromMemoryCache)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
498 OnDidDisplayInsecureContent)
499 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
500 OnDidRunInsecureContent)
501 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
502 OnDocumentLoadedInFrame)
503 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17504 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
505 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25506 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26507 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59508 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21509 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20510 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
512 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16513 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45514 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10515 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18516 IPC_MESSAGE_UNHANDLED(handled = false)
517 IPC_END_MESSAGE_MAP_EX()
518
519 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38520 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18521 GetRenderProcessHost()->ReceivedBadMessage();
522 }
523
524 return handled;
525}
526
[email protected]6c2e472f2011-08-24 23:26:18527void TabContents::RunFileChooser(
528 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23529 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51530 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18531}
532
[email protected]c5eed492012-01-04 17:07:50533NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56534 return controller_;
535}
536
[email protected]c5eed492012-01-04 17:07:50537const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56538 return controller_;
539}
540
[email protected]627e0512011-12-21 22:55:30541content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55542 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30543}
544
[email protected]f5fa20e2011-12-21 22:35:56545void TabContents::SetViewType(content::ViewType type) {
546 view_type_ = type;
547}
548
[email protected]ea049a02011-12-25 21:37:09549content::ViewType TabContents::GetViewType() const {
550 return view_type_;
551}
552
[email protected]be1f56ab2011-12-22 06:55:31553const GURL& TabContents::GetURL() const {
554 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23555 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51556 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31557}
558
559
560const base::PropertyBag* TabContents::GetPropertyBag() const {
561 return &property_bag_;
562}
563
564base::PropertyBag* TabContents::GetPropertyBag() {
565 return &property_bag_;
566}
567
568content::WebContentsDelegate* TabContents::GetDelegate() {
569 return delegate_;
570}
571
572void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
573 // TODO(cbentzel): remove this debugging code?
574 if (delegate == delegate_)
575 return;
576 if (delegate_)
577 delegate_->Detach(this);
578 delegate_ = delegate;
579 if (delegate_)
580 delegate_->Attach(this);
581}
582
[email protected]f3b1a082011-11-18 00:34:30583content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03584 if (render_manager_.current_host())
585 return render_manager_.current_host()->process();
586 else
587 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16588}
589
[email protected]be1f56ab2011-12-22 06:55:31590RenderViewHost* TabContents::GetRenderViewHost() const {
591 return render_manager_.current_host();
592}
593
594RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
595 return render_manager_.GetRenderWidgetHostView();
596}
597
[email protected]8643e6d2012-01-18 20:26:10598content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31599 return view_.get();
600}
601
[email protected]01ec4ec2012-01-18 04:13:47602content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50603 WebUIControllerFactory* factory =
604 content::GetContentClient()->browser()->GetWebUIControllerFactory();
605 if (!factory)
606 return NULL;
[email protected]d2353452012-01-19 19:53:56607 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22608 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50609 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22610 if (controller) {
611 web_ui->SetController(controller);
612 return web_ui;
613 }
614
615 delete web_ui;
616 return NULL;
617}
618
[email protected]01ec4ec2012-01-18 04:13:47619content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31620 return render_manager_.web_ui() ? render_manager_.web_ui()
621 : render_manager_.pending_web_ui();
622}
623
[email protected]01ec4ec2012-01-18 04:13:47624content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31625 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34626}
627
[email protected]96d185d2009-04-24 03:28:54628const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55629 // Transient entries take precedence. They are used for interstitial pages
630 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23631 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08632 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20633 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30634 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23635 if (entry) {
[email protected]b5cca982011-05-26 04:42:08636 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23637 }
[email protected]7ade2732011-02-10 00:13:58638 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
639 render_manager_.pending_web_ui() : render_manager_.web_ui();
640 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54641 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55642 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54643 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35644 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22645 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54646 if (!title.empty())
647 return title;
648 }
649 }
650
651 // We use the title for the last committed entry rather than a pending
652 // navigation entry. For example, when the user types in a URL, we want to
653 // keep the old page's title until the new load has committed and we get a new
654 // title.
[email protected]96d185d2009-04-24 03:28:54655 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23656 if (entry) {
[email protected]b5cca982011-05-26 04:42:08657 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23658 }
[email protected]987fc3a2011-05-26 14:18:09659
660 // |page_title_when_no_navigation_entry_| is finally used
661 // if no title cannot be retrieved.
662 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54663}
664
[email protected]d5f942ba2008-09-26 19:30:34665int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46666 return GetMaxPageIDForSiteInstance(GetSiteInstance());
667}
668
669int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33670 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
671 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46672
[email protected]b6583592012-01-25 19:52:33673 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34674}
675
676void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46677 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
678}
679
[email protected]b6583592012-01-25 19:52:33680void TabContents::UpdateMaxPageIDForSiteInstance(
681 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46682 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33683 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34684}
685
[email protected]91854cd2012-01-10 19:43:57686void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
687 max_page_ids_ = tab_contents->max_page_ids_;
688}
689
[email protected]96d185d2009-04-24 03:28:54690SiteInstance* TabContents::GetSiteInstance() const {
691 return render_manager_.current_host()->site_instance();
692}
693
[email protected]77362eb2011-08-01 17:18:38694SiteInstance* TabContents::GetPendingSiteInstance() const {
695 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
696 render_manager_.pending_render_view_host() :
697 render_manager_.current_host();
698 return dest_rvh->site_instance();
699}
700
[email protected]be1f56ab2011-12-22 06:55:31701bool TabContents::IsLoading() const {
702 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49703}
704
[email protected]be1f56ab2011-12-22 06:55:31705bool TabContents::IsWaitingForResponse() const {
706 return waiting_for_response_;
707}
708
709const net::LoadStateWithParam& TabContents::GetLoadState() const {
710 return load_state_;
711}
712
713const string16& TabContents::GetLoadStateHost() const {
714 return load_state_host_;
715}
716
717uint64 TabContents::GetUploadSize() const {
718 return upload_size_;
719}
720
721uint64 TabContents::GetUploadPosition() const {
722 return upload_position_;
723}
724
725const std::string& TabContents::GetEncoding() const {
726 return encoding_;
727}
728
729bool TabContents::DisplayedInsecureContent() const {
730 return displayed_insecure_content_;
731}
732
733void TabContents::SetCapturingContents(bool cap) {
734 capturing_contents_ = cap;
735}
736
737bool TabContents::IsCrashed() const {
738 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
739 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
740 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49741}
742
[email protected]443b80e2010-12-14 00:42:23743void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
744 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34745 return;
746
[email protected]443b80e2010-12-14 00:42:23747 crashed_status_ = status;
748 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46749 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34750}
751
[email protected]be1f56ab2011-12-22 06:55:31752base::TerminationStatus TabContents::GetCrashedStatus() const {
753 return crashed_status_;
754}
755
756bool TabContents::IsBeingDestroyed() const {
757 return is_being_destroyed_;
758}
759
[email protected]d5f942ba2008-09-26 19:30:34760void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
761 if (delegate_)
762 delegate_->NavigationStateChanged(this, changed_flags);
763}
764
[email protected]96d185d2009-04-24 03:28:54765void TabContents::DidBecomeSelected() {
766 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04767 RenderWidgetHostViewPort* rwhv =
768 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16769 if (rwhv) {
770 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43771#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16772 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43773#endif
774 }
[email protected]96d185d2009-04-24 03:28:54775
[email protected]5ac20162010-11-24 23:33:11776 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38777
[email protected]d8c660432011-12-22 20:51:25778 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59779
780 // The resize rect might have changed while this was inactive -- send the new
781 // one to make sure it's up to date.
782 RenderViewHost* rvh = GetRenderViewHost();
783 if (rvh) {
784 rvh->ResizeRectChanged(GetRootWindowResizerRect());
785 }
[email protected]96d185d2009-04-24 03:28:54786}
787
[email protected]be1f56ab2011-12-22 06:55:31788
789base::TimeTicks TabContents::GetLastSelectedTime() const {
790 return last_selected_time_;
791}
792
[email protected]96d185d2009-04-24 03:28:54793void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31794 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52795 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
796 // open a tab in then background, then closes the tab before selecting it.
797 // This is because closing the tab calls TabContents::Destroy(), which
798 // removes the |GetRenderViewHost()|; then when we actually destroy the
799 // window, OnWindowPosChanged() notices and calls HideContents() (which
800 // calls us).
[email protected]c30585c2012-02-16 15:02:04801 RenderWidgetHostViewPort* rwhv =
802 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16803 if (rwhv)
804 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54805 }
806
[email protected]ad50def52011-10-19 23:17:07807 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09808 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
809 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07810 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54811}
812
[email protected]be1f56ab2011-12-22 06:55:31813void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04814 RenderWidgetHostViewPort* rwhv =
815 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31816 if (rwhv)
817 rwhv->DidBecomeSelected();
818}
819
820void TabContents::HideContents() {
821 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
822 // our superclass HideContents(), because some callers want to be very picky
823 // about the order in which these get called. In addition to making the code
824 // here practically impossible to understand, this also means we end up
825 // calling TabContents::WasHidden() twice if callers call both versions of
826 // HideContents() on a TabContents.
827 WasHidden();
828}
829
830bool TabContents::NeedToFireBeforeUnload() {
831 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27832 return WillNotifyDisconnection() &&
833 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31834 !GetRenderViewHost()->SuddenTerminationAllowed();
835}
836
[email protected]0bfbf882011-12-22 18:19:27837void TabContents::Stop() {
838 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25839 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27840}
841
[email protected]d9083482012-01-06 00:38:46842WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27843 // We create a new SiteInstance so that the new tab won't share processes
844 // with the old one. This can be changed in the future if we need it to share
845 // processes for some reason.
846 TabContents* tc = new TabContents(
847 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33848 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27849 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20850 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27851 return tc;
852}
853
[email protected]2a6bc3e2011-12-28 23:51:33854void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27855 WindowOpenDisposition disposition,
856 const gfx::Rect& initial_pos,
857 bool user_gesture) {
858 if (!delegate_)
859 return;
860
861 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
862 user_gesture);
863}
864
865gfx::NativeView TabContents::GetContentNativeView() const {
866 return view_->GetContentNativeView();
867}
868
869gfx::NativeView TabContents::GetNativeView() const {
870 return view_->GetNativeView();
871}
872
873void TabContents::GetContainerBounds(gfx::Rect* out) const {
874 view_->GetContainerBounds(out);
875}
876
877void TabContents::Focus() {
878 view_->Focus();
879}
880
[email protected]d8c660432011-12-22 20:51:25881void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31882 observers_.AddObserver(observer);
883}
884
[email protected]d8c660432011-12-22 20:51:25885void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31886 observers_.RemoveObserver(observer);
887}
888
[email protected]d5f942ba2008-09-26 19:30:34889void TabContents::Activate() {
890 if (delegate_)
891 delegate_->ActivateContents(this);
892}
893
[email protected]ea42e7782010-08-23 23:58:12894void TabContents::Deactivate() {
895 if (delegate_)
896 delegate_->DeactivateContents(this);
897}
898
[email protected]63954792011-07-11 04:17:48899void TabContents::LostCapture() {
900 if (delegate_)
901 delegate_->LostCapture();
902}
903
904bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
905 bool* is_keyboard_shortcut) {
906 return delegate_ &&
907 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
908}
909
910void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
911 if (delegate_)
912 delegate_->HandleKeyboardEvent(event);
913}
914
[email protected]32ded2212011-11-10 18:51:43915void TabContents::HandleMouseDown() {
916 if (delegate_)
917 delegate_->HandleMouseDown();
918}
919
[email protected]63954792011-07-11 04:17:48920void TabContents::HandleMouseUp() {
921 if (delegate_)
922 delegate_->HandleMouseUp();
923}
924
925void TabContents::HandleMouseActivate() {
926 if (delegate_)
927 delegate_->HandleMouseActivate();
928}
929
[email protected]8a5e0ca2011-08-25 06:30:47930void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
931 if (delegate_)
932 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
933}
934
[email protected]5d5f7af2011-10-01 01:38:12935bool TabContents::IsFullscreenForCurrentTab() const {
936 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
937}
938
[email protected]e9621112011-10-17 05:38:37939void TabContents::RequestToLockMouse() {
940 if (delegate_) {
941 delegate_->RequestToLockMouse(this);
942 } else {
943 GotResponseToLockMouseRequest(false);
944 }
945}
946
947void TabContents::LostMouseLock() {
948 if (delegate_)
949 delegate_->LostMouseLock();
950}
951
[email protected]0548c5352011-09-07 00:33:33952void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23953 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33954 if (delegate_)
955 delegate_->UpdatePreferredSize(this, pref_size);
956}
957
[email protected]32ded2212011-11-10 18:51:43958void TabContents::WebUISend(RenderViewHost* render_view_host,
959 const GURL& source_url,
960 const std::string& name,
961 const base::ListValue& args) {
962 if (delegate_)
963 delegate_->WebUISend(this, source_url, name, args);
964}
965
[email protected]e5d549d2011-12-28 01:29:20966WebContents* TabContents::OpenURL(const OpenURLParams& params) {
967 if (!delegate_)
968 return NULL;
[email protected]00c37fc2011-08-02 00:22:50969
[email protected]e5d549d2011-12-28 01:29:20970 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
971 // Notify observers.
972 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
973 DidOpenURL(params.url, params.referrer,
974 params.disposition, params.transition));
975 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34976}
977
[email protected]1ccb3568d2010-02-19 10:51:16978bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50979 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25980 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23981 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25982 reload_type);
[email protected]876bc832010-09-07 16:29:54983}
[email protected]96d185d2009-04-24 03:28:54984
[email protected]876bc832010-09-07 16:29:54985bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23986 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50987 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40988 // The renderer will reject IPC messages with URLs longer than
989 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51990 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40991 return false;
992
[email protected]dd11de52011-11-03 22:54:27993 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40994 if (!dest_render_view_host)
995 return false; // Unable to create the desired render view host.
996
[email protected]80a8fad2011-01-29 04:02:38997 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07998 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58999 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501000 WebUIControllerFactory* factory =
1001 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1002 bool is_allowed_in_web_ui_renderer =
1003 factory &&
1004 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431005#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511006 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431007#endif
[email protected]e091df82011-10-11 18:13:211008 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551009 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581010
[email protected]96d185d2009-04-24 03:28:541011 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441012 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521013 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441014 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511015 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541016
1017 // Used for page load time metrics.
1018 current_load_start_ = base::TimeTicks::Now();
1019
1020 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341021 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271022 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471023 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341024 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541025
[email protected]36fc0392011-12-25 03:59:511026 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541027 // HACK!! This code suppresses javascript: URLs from being added to
1028 // session history, which is what we want to do for javascript: URLs that
1029 // do not generate content. What we really need is a message from the
1030 // renderer telling us that a new page was not created. The same message
1031 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511032 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541033 return false;
1034 }
1035
[email protected]3c9e1872010-11-18 16:17:491036 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251037 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041038 observers_,
[email protected]36fc0392011-12-25 03:59:511039 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541040
[email protected]09b29342011-06-24 19:18:481041 if (delegate_)
1042 delegate_->DidNavigateToPendingEntry(this);
1043
[email protected]d5f942ba2008-09-26 19:30:341044 return true;
1045}
1046
[email protected]b6583592012-01-25 19:52:331047void TabContents::SetHistoryLengthAndPrune(
1048 const SiteInstance* site_instance,
1049 int history_length,
1050 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411051 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1052 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191053 if (render_manager_.pending_render_view_host()) {
1054 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141055 return;
[email protected]9e1ad4b2011-08-14 16:49:191056 }
[email protected]151a63d2011-12-20 22:32:521057 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191058 if (!rvh) {
1059 NOTREACHED();
1060 return;
1061 }
1062 if (site_instance && rvh->site_instance() != site_instance) {
1063 NOTREACHED();
1064 return;
1065 }
1066 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1067 history_length,
1068 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141069}
1070
[email protected]90daadb42009-06-08 21:27:281071void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271072 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541073 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1074 return;
1075 }
[email protected]151a63d2011-12-20 22:32:521076 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541077}
1078
[email protected]0bfbf882011-12-22 18:19:271079bool TabContents::ShowingInterstitialPage() const {
1080 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541081}
1082
[email protected]0bfbf882011-12-22 18:19:271083InterstitialPage* TabContents::GetInterstitialPage() const {
1084 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221085}
1086
[email protected]a53209b2012-01-20 16:48:161087bool TabContents::IsSavable() {
1088 // WebKit creates Document object when MIME type is application/xhtml+xml,
1089 // so we also support this MIME type.
1090 return contents_mime_type_ == "text/html" ||
1091 contents_mime_type_ == "text/xml" ||
1092 contents_mime_type_ == "application/xhtml+xml" ||
1093 contents_mime_type_ == "text/plain" ||
1094 contents_mime_type_ == "text/css" ||
1095 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1096}
1097
[email protected]c7dd2f62011-07-18 15:57:591098void TabContents::OnSavePage() {
1099 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161100 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481101 download_stats::RecordDownloadSource(
1102 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261103 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141104 return;
[email protected]c7dd2f62011-07-18 15:57:591105 }
1106
1107 Stop();
1108
1109 // Create the save package and possibly prompt the user for the name to save
1110 // the page as. The user prompt is an asynchronous operation that runs on
1111 // another thread.
1112 save_package_ = new SavePackage(this);
1113 save_package_->GetSaveInfo();
1114}
1115
1116// Used in automated testing to bypass prompting the user for file names.
1117// Instead, the names and paths are hard coded rather than running them through
1118// file name sanitation and extension / mime checking.
1119bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161120 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591121 // Stop the page from navigating.
1122 Stop();
1123
1124 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1125 return save_package_->Init();
1126}
1127
[email protected]420ae012009-04-24 05:16:321128bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231129 NavigationEntryImpl* active_entry =
1130 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321131 return (active_entry != NULL &&
1132 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511133 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321134}
1135
[email protected]0bfbf882011-12-22 18:19:271136const std::string& TabContents::GetContentsMimeType() const {
1137 return contents_mime_type_;
1138}
1139
1140bool TabContents::WillNotifyDisconnection() const {
1141 return notify_disconnection_;
1142}
1143
[email protected]b2fe07d12010-02-09 14:38:081144void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311145 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521146 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1147 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161148}
1149
[email protected]b2fe07d12010-02-09 14:38:081150void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311151 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521152 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1153 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161154}
1155
[email protected]0bfbf882011-12-22 18:19:271156content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1157 return &renderer_preferences_;
1158}
1159
1160void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1161 new_tab_start_time_ = time;
1162}
1163
1164base::TimeTicks TabContents::GetNewTabStartTime() const {
1165 return new_tab_start_time_;
1166}
1167
[email protected]7ab1e7d62009-10-14 23:32:011168void TabContents::OnCloseStarted() {
1169 if (tab_close_start_time_.is_null())
1170 tab_close_start_time_ = base::TimeTicks::Now();
1171}
1172
[email protected]46624bf2010-06-09 16:04:191173bool TabContents::ShouldAcceptDragAndDrop() const {
1174#if defined(OS_CHROMEOS)
1175 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1176 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511177 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201178 return false;
1179 return true;
[email protected]46624bf2010-06-09 16:04:191180#else
1181 return true;
1182#endif
1183}
1184
[email protected]7813bd72011-02-05 02:19:341185void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521186 if (GetRenderViewHost())
1187 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511188 if (delegate_)
1189 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341190}
1191
[email protected]0bfbf882011-12-22 18:19:271192void TabContents::SetClosedByUserGesture(bool value) {
1193 closed_by_user_gesture_ = value;
1194}
1195
1196bool TabContents::GetClosedByUserGesture() const {
1197 return closed_by_user_gesture_;
1198}
1199
[email protected]d0b8d092010-10-25 04:05:171200double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051201 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561202 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251203 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171204 return 0;
[email protected]b75b8292010-10-01 07:28:251205
1206 double zoom_level;
1207 if (temporary_zoom_settings_) {
1208 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521209 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251210 } else {
[email protected]2ae88d12011-10-14 09:11:191211 GURL url;
[email protected]10f417c52011-12-28 21:04:231212 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191213 // Since zoom map is updated using rewritten URL, use rewritten URL
1214 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511215 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191216 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251217 }
[email protected]d0b8d092010-10-25 04:05:171218 return zoom_level;
1219}
[email protected]b75b8292010-10-01 07:28:251220
[email protected]d0b8d092010-10-25 04:05:171221int TabContents::GetZoomPercent(bool* enable_increment,
1222 bool* enable_decrement) {
1223 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011224 // Calculate the zoom percent from the factor. Round up to the nearest whole
1225 // number.
[email protected]b75b8292010-10-01 07:28:251226 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011227 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251228 *enable_decrement = percent > minimum_zoom_percent_;
1229 *enable_increment = percent < maximum_zoom_percent_;
1230 return percent;
1231}
1232
[email protected]3c733bde2010-12-21 19:56:311233void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501234 if (!delegate_)
1235 return;
1236
[email protected]10f417c52011-12-28 21:04:231237 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501238 if (!active_entry)
1239 return;
1240
[email protected]36fc0392011-12-25 03:59:511241 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121242}
1243
[email protected]932b7a12011-03-09 12:50:271244void TabContents::ViewFrameSource(const GURL& url,
1245 const std::string& content_state) {
1246 if (!delegate_)
1247 return;
1248
1249 delegate_->ViewSourceForFrame(this, url, content_state);
1250}
1251
[email protected]0bfbf882011-12-22 18:19:271252int TabContents::GetMinimumZoomPercent() const {
1253 return minimum_zoom_percent_;
1254}
1255
1256int TabContents::GetMaximumZoomPercent() const {
1257 return maximum_zoom_percent_;
1258}
1259
[email protected]bcd2815602012-01-14 18:17:231260gfx::Size TabContents::GetPreferredSize() const {
1261 return preferred_size_;
1262}
1263
[email protected]0bfbf882011-12-22 18:19:271264int TabContents::GetContentRestrictions() const {
1265 return content_restrictions_;
1266}
1267
1268WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501269 WebUIControllerFactory* factory =
1270 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1271 if (!factory)
1272 return WebUI::kNoWebUI;
1273 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271274}
1275
[email protected]01ec4ec2012-01-18 04:13:471276content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271277 // When there is a pending navigation entry, we want to use the pending WebUI
1278 // that goes along with it to control the basic flags. For example, we want to
1279 // show the pending URL in the URL bar, so we want the display_url flag to
1280 // be from the pending entry.
1281 //
1282 // The confusion comes because there are multiple possibilities for the
1283 // initial load in a tab as a side effect of the way the RenderViewHostManager
1284 // works.
1285 //
1286 // - For the very first tab the load looks "normal". The new tab Web UI is
1287 // the pending one, and we want it to apply here.
1288 //
1289 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1290 // get switched to the one previously associated with the new tab pages.
1291 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1292 // have a committed Web UI in this case.
1293 //
1294 // This condition handles all of these cases:
1295 //
1296 // - First load in first tab: no committed nav entry + pending nav entry +
1297 // pending dom ui:
1298 // -> Use pending Web UI if any.
1299 //
1300 // - First load in second tab: no committed nav entry + pending nav entry +
1301 // no pending Web UI:
1302 // -> Use the committed Web UI if any.
1303 //
1304 // - Second navigation in any tab: committed nav entry + pending nav entry:
1305 // -> Use pending Web UI if any.
1306 //
1307 // - Normal state with no load: committed nav entry + no pending nav entry:
1308 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251309 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271310 (controller_.GetLastCommittedEntry() ||
1311 render_manager_.pending_web_ui()))
1312 return render_manager_.pending_web_ui();
1313 return render_manager_.web_ui();
1314}
1315
1316bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1317 return GetRenderViewHost() ?
1318 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1319}
1320
1321bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471322 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271323 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221324 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231325 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511326 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271327 return true;
1328 return false;
1329}
1330
1331void TabContents::SetFocusToLocationBar(bool select_all) {
1332 if (delegate_)
1333 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211334}
1335
[email protected]8b5af492011-11-28 21:50:581336void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301337 const string16& type,
1338 const string16& href,
1339 const string16& title,
1340 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511341 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301342 this, action, type, href, title, disposition);
1343}
1344
[email protected]678105012011-12-09 04:01:211345void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301346 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001347 WebIntentsDispatcherImpl* intents_dispatcher =
1348 new WebIntentsDispatcherImpl(this, intent, intent_id);
1349 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301350}
1351
[email protected]724159a2010-12-30 01:11:181352void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1353 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591354 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181355 const GURL& url) {
1356 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1357 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591358 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301359 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181360
[email protected]8093a542011-05-13 07:29:321361 RenderViewHost* rvh =
1362 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521363 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101364 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251365 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101366 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321367 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101368
[email protected]724159a2010-12-30 01:11:181369 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591370 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251371 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591372 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181373 }
1374}
1375
1376void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591377 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181378 const GURL& source_url,
1379 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491380 // TODO(creis): Remove this method and have the pre-rendering code listen to
1381 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1382 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231383 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181384 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251385 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181386 else
1387 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511388 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181389 return;
[email protected]e7d50892011-01-19 21:47:381390
[email protected]4850a7f2011-03-08 23:36:591391 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251392 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261393 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591394 opener_url));
[email protected]724159a2010-12-30 01:11:181395}
1396
1397void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581398 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1399 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1400 << ", error_code: " << params.error_code
1401 << ", error_description: " << params.error_description
1402 << ", is_main_frame: " << params.is_main_frame
1403 << ", showing_repost_interstitial: " <<
1404 params.showing_repost_interstitial
1405 << ", frame_id: " << params.frame_id;
1406 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591407 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301408 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181409
[email protected]d7b175e2011-10-11 15:31:581410 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181411 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1412 // This means that the interstitial won't be torn down properly, which is
1413 // bad. But if we have an interstitial, go back to another tab type, and
1414 // then load the same interstitial again, we could end up getting the first
1415 // interstitial's "failed" message (as a result of the cancel) when we're on
1416 // the second one.
1417 //
1418 // We can't tell this apart, so we think we're tearing down the current page
1419 // which will cause a crash later one. There is also some code in
1420 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1421 // out because of this problem.
1422 //
1423 // http://code.google.com/p/chromium/issues/detail?id=2855
1424 // Because this will not tear down the interstitial properly, if "back" is
1425 // back to another tab type, the interstitial will still be somewhat alive
1426 // in the previous tab type. If you navigate somewhere that activates the
1427 // tab with the interstitial again, you'll see a flash before the new load
1428 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271429 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181430 LOG(WARNING) << "Discarding message during interstitial.";
1431 return;
1432 }
1433
[email protected]02102f82011-06-13 20:37:021434 // Discard our pending entry if the load canceled (e.g. if we decided to
1435 // download the file instead of load it). We do not verify that the URL
1436 // being canceled matches the pending entry's URL because they will not
1437 // match if a redirect occurred (in which case we do not want to leave a
1438 // stale redirect URL showing). This means that we also cancel the pending
1439 // entry if the user started a new navigation. As a result, the navigation
1440 // controller may not remember that a load is in progress, but the
1441 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251442 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161443 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181444
[email protected]151a63d2011-12-20 22:32:521445 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181446 }
1447
1448 // Send out a notification that we failed a provisional load with an error.
1449 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581450 params.is_main_frame,
1451 controller_.IsURLInPageNavigation(validated_url),
1452 validated_url,
1453 std::string(),
1454 false,
1455 params.frame_id);
1456 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181457
[email protected]ad50def52011-10-19 23:17:071458 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271459 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501460 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531461 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101462
[email protected]d8c660432011-12-22 20:51:251463 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581464 observers_,
1465 DidFailProvisionalLoad(params.frame_id,
1466 params.is_main_frame,
1467 validated_url,
1468 params.error_code,
1469 params.error_description));
[email protected]724159a2010-12-30 01:11:181470}
1471
1472void TabContents::OnDidLoadResourceFromMemoryCache(
1473 const GURL& url,
[email protected]70435962011-08-02 20:13:281474 const std::string& security_info,
1475 const std::string& http_method,
1476 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191477 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181478 cache.Increment();
1479
1480 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081481 int cert_id = 0;
1482 net::CertStatus cert_status = 0;
1483 int security_bits = -1;
1484 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511485 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1486 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301487 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161488 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181489
[email protected]ad50def52011-10-19 23:17:071490 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271491 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501492 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531493 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181494}
1495
1496void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381497 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181498 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201499 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181500}
1501
1502void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021503 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231504 LOG(INFO) << security_origin << " ran insecure content from "
1505 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381506 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051507 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381508 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051509 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1510 }
[email protected]330614de2012-02-13 17:07:181511 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411512 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201513 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181514}
1515
1516void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1517 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251518 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101519 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181520}
1521
[email protected]1a55c5be2011-11-29 11:36:311522void TabContents::OnDidFinishLoad(
1523 int64 frame_id,
1524 const GURL& validated_url,
1525 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311527 DidFinishLoad(frame_id, validated_url, is_main_frame));
1528}
1529
1530void TabContents::OnDidFailLoadWithError(int64 frame_id,
1531 const GURL& validated_url,
1532 bool is_main_frame,
1533 int error_code,
1534 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251535 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311536 DidFailLoad(frame_id, validated_url, is_main_frame,
1537 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181538}
1539
[email protected]c8f73ab2011-01-22 00:05:171540void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271541 content_restrictions_ = restrictions;
1542 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171543}
1544
[email protected]216813952011-05-19 22:21:261545void TabContents::OnGoToEntryAtOffset(int offset) {
1546 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231547 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251548 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261549 if (!entry)
1550 return;
1551 // Note that we don't call NavigationController::GotToOffset() as we don't
1552 // want to create a pending navigation entry (it might end up lingering
1553 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251554 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581555 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511556 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581557 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471558 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571559
1560 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1561 // it in now that we know. This allows us to find the entry when it commits.
1562 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231563 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331564 entry->set_site_instance(
1565 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571566 }
[email protected]216813952011-05-19 22:21:261567 }
1568}
1569
1570void TabContents::OnUpdateZoomLimits(int minimum_percent,
1571 int maximum_percent,
1572 bool remember) {
1573 minimum_zoom_percent_ = minimum_percent;
1574 maximum_zoom_percent_ = maximum_percent;
1575 temporary_zoom_settings_ = !remember;
1576}
1577
[email protected]0bfbf882011-12-22 18:19:271578void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481579 download_stats::RecordDownloadSource(
1580 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261581 // Check if the URL to save matches the URL of the main frame. Since this
1582 // message originates from Pepper plugins, it may not be the case if the
1583 // plugin is an embedded element.
1584 GURL main_frame_url = GetURL();
1585 if (!main_frame_url.is_valid())
1586 return;
1587 bool is_main_frame = (url == main_frame_url);
1588 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271589}
1590
[email protected]3a29a6e2011-08-24 18:26:211591void TabContents::OnEnumerateDirectory(int request_id,
1592 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591593 ChildProcessSecurityPolicyImpl* policy =
1594 ChildProcessSecurityPolicyImpl::GetInstance();
1595 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1596 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211597}
1598
[email protected]7d189022011-08-25 22:54:201599void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511600 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201601}
1602
1603void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1604 const GURL& url,
1605 const string16& title) {
[email protected]b9535422012-02-09 01:47:591606 ChildProcessSecurityPolicyImpl* policy =
1607 ChildProcessSecurityPolicyImpl::GetInstance();
1608 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1609 return;
[email protected]6934a702011-12-20 00:04:511610 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201611}
1612
[email protected]b888919c2011-09-02 00:32:161613void TabContents::OnFindReply(int request_id,
1614 int number_of_matches,
1615 const gfx::Rect& selection_rect,
1616 int active_match_ordinal,
1617 bool final_update) {
[email protected]6934a702011-12-20 00:04:511618 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1619 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001620 // Send a notification to the renderer that we are ready to receive more
1621 // results from the scoping effort of the Find operation. The FindInPage
1622 // scoping is asynchronous and periodically sends results back up to the
1623 // browser using IPC. In an effort to not spam the browser we have the
1624 // browser send an ACK for each FindReply message and have the renderer
1625 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521626 GetRenderViewHost()->Send(
1627 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161628}
1629
[email protected]d952a052011-09-06 18:42:451630void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511631 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451632}
1633
[email protected]7fc4bbb2011-09-08 21:23:101634void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1635 bool blocked_by_policy) {
1636 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251637 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101638 AppCacheAccessed(manifest_url, blocked_by_policy));
1639}
1640
[email protected]96d185d2009-04-24 03:28:541641// Notifies the RenderWidgetHost instance about the fact that the page is
1642// loading, or done loading and calls the base implementation.
1643void TabContents::SetIsLoading(bool is_loading,
1644 LoadNotificationDetails* details) {
1645 if (is_loading == is_loading_)
1646 return;
1647
1648 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211649 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541650 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561651 upload_size_ = 0;
1652 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541653 }
1654
1655 render_manager_.SetIsLoading(is_loading);
1656
1657 is_loading_ = is_loading;
1658 waiting_for_response_ = is_loading;
1659
[email protected]6ebdc9b2010-09-27 16:55:571660 if (delegate_)
1661 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461662 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541663
[email protected]432115822011-07-10 15:52:271664 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1665 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071666 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541667 if (details)
[email protected]6c2381d2011-10-19 02:52:531668 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071669 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501670 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541671 det);
1672}
1673
[email protected]420ae012009-04-24 05:16:321674void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131675 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321676 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561677 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381678 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441679 // that opened the window, as long as both renderers have the same
1680 // privileges.
[email protected]1fd1a502011-03-30 16:55:561681 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561682 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581683 // web_ui might be NULL if the URL refers to a non-existent extension.
1684 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401685 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521686 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441687 }
1688 }
[email protected]1fd1a502011-03-30 16:55:561689 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441690 }
1691
[email protected]4e697b042011-07-08 06:44:561692 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321693 // Clear the status bubble. This is a workaround for a bug where WebKit
1694 // doesn't let us know that the cursor left an element during a
1695 // transition (this is also why the mouse cursor remains as a hand after
1696 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1697 // clear the bubble when a user navigates to a named anchor in the same
1698 // page.
[email protected]36fc0392011-12-25 03:59:511699 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321700 }
1701
[email protected]a6e82fc2010-02-24 22:28:141702 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471703 // Once the main frame is navigated, we're no longer considered to have
1704 // displayed insecure content.
1705 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171706 }
[email protected]ce5c4502009-05-06 16:46:111707
[email protected]3c9e1872010-11-18 16:17:491708 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041710 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321711}
1712
1713void TabContents::DidNavigateAnyFramePostCommit(
1714 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131715 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321716 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061717 // If we navigate off the page, reset JavaScript state. This does nothing
1718 // to prevent a malicious script from spamming messages, since the script
1719 // could just reload the page to stop blocking.
1720 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551721 dialog_creator_->ResetJavaScriptState(this);
1722 dialog_creator_ = NULL;
1723 }
[email protected]420ae012009-04-24 05:16:321724
[email protected]3c9e1872010-11-18 16:17:491725 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251726 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041727 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321728}
1729
[email protected]74ce1ad2011-12-16 21:51:461730void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1731 // If we are creating a RVH for a restored controller, then we need to make
1732 // sure the RenderView starts with a next_page_id_ larger than the number
1733 // of restored entries. This must be called before the RenderView starts
1734 // navigating (to avoid a race between the browser updating max_page_id and
1735 // the renderer updating next_page_id_). Because of this, we only call this
1736 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561737 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461738 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1739 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321740}
1741
[email protected]10f417c52011-12-28 21:04:231742bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571743 const string16& title) {
[email protected]420ae012009-04-24 05:16:321744 // For file URLs without a title, use the pathname instead. In the case of a
1745 // synthesized title, we don't want the update to count toward the "one set
1746 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511747 string16 final_title;
[email protected]420ae012009-04-24 05:16:321748 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511749 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1750 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321751 explicit_set = false; // Don't count synthetic titles toward the set limit.
1752 } else {
[email protected]acafd272011-07-26 17:35:571753 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321754 explicit_set = true;
1755 }
1756
[email protected]987fc3a2011-05-26 14:18:091757 // If a page is created via window.open and never navigated,
1758 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551759 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091760 if (entry) {
[email protected]36fc0392011-12-25 03:59:511761 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091762 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321763
[email protected]36fc0392011-12-25 03:59:511764 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091765 } else {
1766 if (page_title_when_no_navigation_entry_ == final_title)
1767 return false; // Nothing changed, don't bother.
1768
1769 page_title_when_no_navigation_entry_ = final_title;
1770 }
[email protected]420ae012009-04-24 05:16:321771
[email protected]420ae012009-04-24 05:16:321772 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231773 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321774
[email protected]105bb0f2011-05-24 17:12:141775 TitleUpdatedDetails details(entry, explicit_set);
1776
[email protected]ad50def52011-10-19 23:17:071777 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441778 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1779 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531780 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041781
[email protected]420ae012009-04-24 05:16:321782 return true;
1783}
1784
1785void TabContents::NotifySwapped() {
1786 // After sending out a swap notification, we need to send a disconnect
1787 // notification so that clients that pick up a pointer to |this| can NULL the
1788 // pointer. See Bug 1230284.
1789 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071790 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201791 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1792 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071793 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321794}
1795
1796void TabContents::NotifyConnected() {
1797 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071798 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121799 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1800 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071801 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321802}
1803
1804void TabContents::NotifyDisconnected() {
1805 if (!notify_disconnection_)
1806 return;
1807
1808 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071809 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321810 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1811 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071812 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321813}
1814
[email protected]8d3347f2009-07-09 22:00:211815RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321816 return view_.get();
1817}
1818
[email protected]8d3347f2009-07-09 22:00:211819RenderViewHostDelegate::RendererManagement*
1820TabContents::GetRendererManagementDelegate() {
1821 return &render_manager_;
1822}
1823
[email protected]daf82f82011-10-31 22:35:311824content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371825 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461826 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511827}
1828
[email protected]768c5472011-12-26 19:06:171829WebContents* TabContents::GetAsWebContents() {
1830 return this;
1831}
1832
[email protected]da4dfc42011-10-12 15:53:561833content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431834 return view_type_;
[email protected]7b291f92009-08-14 05:43:531835}
1836
[email protected]b7a756d42012-01-23 18:08:171837gfx::Rect TabContents::GetRootWindowResizerRect() const {
1838 if (delegate_)
1839 return delegate_->GetRootWindowResizerRect();
1840 return gfx::Rect();
1841}
1842
[email protected]420ae012009-04-24 05:16:321843void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071844 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271845 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321846 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531847 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231848 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321849 if (!entry)
1850 return;
1851
1852 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351853 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561854 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581855 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321856
1857 if (entry->IsViewSourceMode()) {
1858 // Put the renderer in view source mode.
1859 render_view_host->Send(
1860 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1861 }
[email protected]0666aef2009-05-13 19:48:081862
[email protected]d487beefe2011-12-21 05:41:211863 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261864
1865 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251866 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321867}
1868
1869void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521870 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321871 // Don't notify the world, since this came from a renderer in the
1872 // background.
1873 return;
1874 }
1875
1876 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311877 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231878 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301879
1880 // Restore the focus to the tab (otherwise the focus will be on the top
1881 // window).
[email protected]484ae5912010-09-29 19:16:141882 if (was_crashed && !FocusLocationBarByDefault() &&
1883 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301884 Focus();
[email protected]484ae5912010-09-29 19:16:141885 }
[email protected]32ded2212011-11-10 18:51:431886
[email protected]d8c660432011-12-22 20:51:251887 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321888}
1889
[email protected]443b80e2010-12-14 00:42:231890void TabContents::RenderViewGone(RenderViewHost* rvh,
1891 base::TerminationStatus status,
1892 int error_code) {
[email protected]151a63d2011-12-20 22:32:521893 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321894 // The pending page's RenderViewHost is gone.
1895 return;
1896 }
1897
1898 SetIsLoading(false, NULL);
1899 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231900 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311901 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321902
[email protected]d8c660432011-12-22 20:51:251903 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271904 observers_,
[email protected]be1f56ab2011-12-22 06:55:311905 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321906}
1907
[email protected]2e4633c2009-07-09 16:58:061908void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481909 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251910 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061911}
1912
[email protected]420ae012009-04-24 05:16:321913void TabContents::DidNavigate(RenderViewHost* rvh,
1914 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581915 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321916 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371917
[email protected]434f69f2012-02-06 21:56:521918 // Update the site of the SiteInstance if it doesn't have one yet, unless
1919 // this is for about:blank. In that case, the SiteInstance can still be
1920 // considered unused until a navigation to a real page.
1921 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1922 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331923 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521924 }
[email protected]420ae012009-04-24 05:16:321925
1926 // Need to update MIME type here because it's referred to in
1927 // UpdateNavigationCommands() called by RendererDidNavigate() to
1928 // determine whether or not to enable the encoding menu.
1929 // It's updated only for the main frame. For a subframe,
1930 // RenderView::UpdateURL does not set params.contents_mime_type.
1931 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1932 // TODO(jungshik): Add a test for the encoding menu to avoid
1933 // regressing it again.
[email protected]2905f742011-10-13 03:51:581934 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321935 contents_mime_type_ = params.contents_mime_type;
1936
[email protected]8286f51a2011-05-31 17:39:131937 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001938 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391939
[email protected]a9c0bfe2010-09-17 08:35:221940 // Send notification about committed provisional loads. This notification is
1941 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1942 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081943 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071944 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1945 // that is not recorded in the navigation history. For the purpose of
1946 // tracking navigation events, we treat this event as a sub frame navigation
1947 // event.
1948 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581949 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221950 // Whether or not a page transition was triggered by going backward or
1951 // forward in the history is only stored in the navigation controller's
1952 // entry list.
1953 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511954 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581955 content::PAGE_TRANSITION_FORWARD_BACK)) {
1956 transition_type = content::PageTransitionFromInt(
1957 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221958 }
[email protected]0d60f0192011-04-14 12:40:101959 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251960 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101961 DidCommitProvisionalLoadForFrame(params.frame_id,
1962 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221963 }
1964
[email protected]76543b92009-08-31 17:27:451965 if (!did_navigate)
1966 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321967
1968 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1969 // for the appropriate notification (best) or you can add it to
1970 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1971 // necessary, please).
1972
1973 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001974 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321975 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511976 if (delegate_)
1977 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001978 }
[email protected]420ae012009-04-24 05:16:321979 DidNavigateAnyFramePostCommit(rvh, details, params);
1980}
1981
1982void TabContents::UpdateState(RenderViewHost* rvh,
1983 int32 page_id,
1984 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151985 // Ensure that this state update comes from either the active RVH or one of
1986 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521987 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321988
1989 // We must be prepared to handle state updates for any page, these occur
1990 // when the user is scrolling and entering form data, as well as when we're
1991 // leaving a page, in which case our state may have already been moved to
1992 // the next page. The navigation controller will look up the appropriate
1993 // NavigationEntry and update it when it is notified via the delegate.
1994
1995 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151996 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321997 if (entry_index < 0)
1998 return;
[email protected]10f417c52011-12-28 21:04:231999 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322000
[email protected]36fc0392011-12-25 03:59:512001 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322002 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512003 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322004 controller_.NotifyEntryChanged(entry, entry_index);
2005}
2006
2007void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572008 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462009 const string16& title,
2010 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322011 // If we have a title, that's a pretty good indication that we've started
2012 // getting useful data.
2013 SetNotWaitingForResponse();
2014
[email protected]73eb2602012-02-09 19:50:552015 // Try to find the navigation entry, which might not be the current one.
2016 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232017 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2018 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092019
[email protected]73eb2602012-02-09 19:50:552020 // We can handle title updates when we don't have an entry in
2021 // UpdateTitleForEntry, but only if the update is from the current RVH.
2022 if (!entry && rvh != GetRenderViewHost())
2023 return;
2024
[email protected]a49e10b2011-08-01 23:57:462025 // TODO(evan): make use of title_direction.
2026 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092027 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322028 return;
2029
2030 // Broadcast notifications when the UI should be updated.
2031 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462032 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322033}
2034
[email protected]420ae012009-04-24 05:16:322035void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402036 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312037 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322038}
2039
2040void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512041 if (delegate_)
2042 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322043}
2044
[email protected]420ae012009-04-24 05:16:322045void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292046 // The UI may be in an event-tracking loop, such as between the
2047 // mouse-down and mouse-up in text selection or a button click.
2048 // Defer the close until after tracking is complete, so that we
2049 // don't free objects out from under the UI.
2050 // TODO(shess): This could probably be integrated with the
2051 // IsDoingDrag() test below. Punting for now because I need more
2052 // research to understand how this impacts platforms other than Mac.
2053 // TODO(shess): This could get more fine-grained. For instance,
2054 // closing a tab in another window while selecting text in the
2055 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212056 if (GetView()->IsEventTracking()) {
2057 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292058 return;
2059 }
2060
[email protected]24a4d1062009-07-10 23:10:422061 // If we close the tab while we're in the middle of a drag, we'll crash.
2062 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212063 if (GetView()->IsDoingDrag()) {
2064 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422065 return;
2066 }
2067
[email protected]420ae012009-04-24 05:16:322068 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522069 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512070 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322071}
2072
[email protected]cd9ed79d2011-11-15 19:22:572073void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522074 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512075 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572076}
2077
[email protected]420ae012009-04-24 05:16:322078void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512079 if (delegate_ && delegate_->IsPopupOrPanel(this))
2080 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322081}
2082
[email protected]7ab1e7d62009-10-14 23:32:012083void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322084 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492085
[email protected]6934a702011-12-20 00:04:512086 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212087 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512088 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002089 }
[email protected]3c9e1872010-11-18 16:17:492090
2091 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252092 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322093}
2094
[email protected]7ab1e7d62009-10-14 23:32:012095void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322096 scoped_ptr<LoadNotificationDetails> details;
2097
[email protected]10f417c52011-12-28 21:04:232098 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322099 // An entry may not exist for a stop when loading an initial blank page or
2100 // if an iframe injected by script into a blank page finishes loading.
2101 if (entry) {
[email protected]420ae012009-04-24 05:16:322102 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2103
2104 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512105 entry->GetVirtualURL(),
2106 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322107 elapsed,
2108 &controller_,
2109 controller_.GetCurrentEntryIndex()));
2110 }
2111
[email protected]420ae012009-04-24 05:16:322112 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492113
2114 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252115 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322116}
2117
[email protected]c95fa8b2011-04-28 20:26:162118void TabContents::DidCancelLoading() {
2119 controller_.DiscardNonCommittedEntries();
2120
2121 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462122 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162123}
2124
[email protected]1a3c3cb2010-12-16 21:03:402125void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512126 if (delegate_)
2127 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402128}
2129
[email protected]952a68e2011-11-17 00:36:102130void TabContents::DocumentAvailableInMainFrame(
2131 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252132 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102133 DocumentAvailableInMainFrame());
2134}
2135
[email protected]25497492010-09-11 15:15:082136void TabContents::DocumentOnLoadCompletedInMainFrame(
2137 RenderViewHost* render_view_host,
2138 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072139 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272140 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322141 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532142 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082143}
2144
[email protected]ae5184d62011-10-06 19:25:582145void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152146 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582147 WindowOpenDisposition disposition,
2148 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482149 // Delegate to RequestTransferURL because this is just the generic
2150 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582151 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482152 GlobalRequestID());
2153}
2154
2155void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582156 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482157 WindowOpenDisposition disposition,
2158 int64 source_frame_id,
2159 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202160 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582161 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582162 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352163 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322164 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2165 // generated suggestions).
2166 //
[email protected]e0112912011-02-02 22:54:352167 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162168 // want web sites to see a referrer of "chrome://blah" (and some
2169 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322170 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432171 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222172 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482173 false /* is_renderer_initiated */);
2174 params.transferred_global_request_id = old_request_id;
2175 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222176 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322177 } else {
[email protected]6bf6a6b52012-02-03 15:41:432178 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482179 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2180 params.transferred_global_request_id = old_request_id;
2181 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582182 }
2183 if (new_contents) {
2184 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252185 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582186 DidOpenRequestedURL(new_contents,
2187 url,
2188 referrer,
2189 disposition,
2190 transition_type,
2191 source_frame_id));
[email protected]420ae012009-04-24 05:16:322192 }
2193}
2194
[email protected]420ae012009-04-24 05:16:322195void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342196 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412197 const string16& message,
2198 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322199 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472200 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322201 IPC::Message* reply_msg,
2202 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072203 // Suppress JavaScript dialogs when requested. Also suppress messages when
2204 // showing an interstitial as it's shown over the previous page and we don't
2205 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502206 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152207 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272208 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072209 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522210 delegate_->ShouldSuppressDialogs() ||
2211 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322212
2213 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342214 content::JavaScriptDialogCreator::TitleType title_type;
2215 string16 title;
2216
2217 if (!frame_url.has_host()) {
2218 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2219 } else {
2220 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2221 title = net::FormatUrl(
2222 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202223 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302224 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342225 }
2226
[email protected]2e5b90c2011-08-16 21:11:552227 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522228 dialog_creator_->RunJavaScriptDialog(
2229 this, title_type, title, javascript_message_type, message,
2230 default_prompt,
2231 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2232 reply_msg),
2233 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322234 }
[email protected]3ab9cb82011-06-03 18:02:072235
2236 if (suppress_this_message) {
2237 // If we are suppressing messages, just reply as if the user immediately
2238 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342239 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072240 }
2241
2242 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322243}
2244
[email protected]fedec012012-01-28 03:09:342245void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412246 const string16& message,
[email protected]420ae012009-04-24 05:16:322247 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512248 if (delegate_)
2249 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072250
2251 bool suppress_this_message =
2252 rvh->is_swapped_out() ||
2253 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522254 delegate_->ShouldSuppressDialogs() ||
2255 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152256 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342257 // The reply must be sent to the RVH that sent the request.
2258 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502259 return;
2260 }
[email protected]3ab9cb82011-06-03 18:02:072261
[email protected]7ab1e7d62009-10-14 23:32:012262 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552263 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522264 dialog_creator_->RunBeforeUnloadDialog(
2265 this, message,
2266 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2267 reply_msg));
[email protected]420ae012009-04-24 05:16:322268}
2269
[email protected]420ae012009-04-24 05:16:322270WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542271 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322272}
2273
[email protected]7d472472011-01-22 01:30:252274void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272275 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252276 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222277
[email protected]99907362012-01-11 05:41:402278 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172279 if (rdh) // NULL in unittests.
2280 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252281}
2282
[email protected]fa1cf0b82010-01-15 21:49:442283void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442284 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252285 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442286}
2287
[email protected]420ae012009-04-24 05:16:322288void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2289 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152290 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522291 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152292 return;
2293
[email protected]e5fc1632011-08-08 07:51:532294 // Ignore renderer unresponsive event if debugger is attached to the tab
2295 // since the event may be a result of the renderer sitting on a breakpoint.
2296 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442297 DevToolsAgentHost* agent =
2298 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2299 if (agent &&
2300 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532301 return;
2302
[email protected]420ae012009-04-24 05:16:322303 if (is_during_unload) {
2304 // Hang occurred while firing the beforeunload/unload handler.
2305 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112306 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322307
2308 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2309 return;
2310
2311 // If the tab hangs in the beforeunload/unload handler there's really
2312 // nothing we can do to recover. Pretend the unload listeners have
2313 // all fired and close the tab. If the hang is in the beforeunload handler
2314 // then the user will not have the option of cancelling the close.
2315 Close(rvh);
2316 return;
2317 }
2318
[email protected]151a63d2011-12-20 22:32:522319 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472320 return;
2321
[email protected]6934a702011-12-20 00:04:512322 if (delegate_)
2323 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322324}
2325
2326void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512327 if (delegate_)
2328 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322329}
2330
2331void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212332 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562333 uint64 upload_position,
2334 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322335 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562336 upload_position_ = upload_position;
2337 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502338 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202339 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302340 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212341 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322342 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462343 if (IsLoading()) {
2344 NotifyNavigationStateChanged(
2345 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2346 }
[email protected]420ae012009-04-24 05:16:322347}
2348
[email protected]7d472472011-01-22 01:30:252349void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512350 if (delegate_)
2351 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252352}
2353
[email protected]420ae012009-04-24 05:16:322354void TabContents::BeforeUnloadFiredFromRenderManager(
2355 bool proceed,
2356 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512357 if (delegate_)
2358 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]3a3d47472010-07-15 21:03:542361void TabContents::DidStartLoadingFromRenderManager(
2362 RenderViewHost* render_view_host) {
2363 DidStartLoading();
2364}
2365
2366void TabContents::RenderViewGoneFromRenderManager(
2367 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232368 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2369 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542370}
2371
[email protected]420ae012009-04-24 05:16:322372void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102373 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262374 gfx::Size size = view_->GetContainerSize();
2375 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2376 // here during container initialization and normal window size will be set
2377 // later. In case of tab duplication this resizing to 0x0 prevents setting
2378 // normal size later so just ignore it.
2379 if (!size.IsEmpty())
2380 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322381}
2382
[email protected]3a3d47472010-07-15 21:03:542383void TabContents::NotifySwappedFromRenderManager() {
2384 NotifySwapped();
2385}
2386
[email protected]d202a7c2012-01-04 07:53:472387NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202388 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542389}
2390
[email protected]d2353452012-01-19 19:53:562391WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2392 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322393}
2394
[email protected]10f417c52011-12-28 21:04:232395NavigationEntry*
2396 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322397 return controller_.GetLastCommittedEntry();
2398}
2399
2400bool TabContents::CreateRenderViewForRenderManager(
2401 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442402 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322403 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522404
[email protected]420ae012009-04-24 05:16:322405 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442406 if (rwh_view)
2407 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322408
[email protected]74ce1ad2011-12-16 21:51:462409 // Make sure we use the correct starting page_id in the new RenderView.
2410 UpdateMaxPageIDIfNecessary(render_view_host);
2411 int32 max_page_id =
2412 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2413
2414 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522415 return false;
2416
[email protected]e60c0232011-11-11 19:56:352417#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502418 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2419 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442420 if (rwh_view) {
2421 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2422 render_widget_host->WasResized();
2423 }
[email protected]f8233cc2011-05-31 20:24:502424#endif
2425
[email protected]420ae012009-04-24 05:16:322426 return true;
2427}
2428
[email protected]fedec012012-01-28 03:09:342429void TabContents::OnDialogClosed(RenderViewHost* rvh,
2430 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072431 bool success,
2432 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542433 if (is_showing_before_unload_dialog_ && !success) {
2434 // If a beforeunload dialog is canceled, we need to stop the throbber from
2435 // spinning, since we forced it to start spinning in Navigate.
2436 DidStopLoading();
2437
2438 tab_close_start_time_ = base::TimeTicks();
2439 }
2440 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342441 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542442}
2443
[email protected]be1f56ab2011-12-22 06:55:312444void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122445 encoding_ = content::GetContentClient()->browser()->
2446 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102447}
[email protected]f45d2a72010-03-08 23:28:352448
[email protected]e30d68d2012-02-09 00:06:262449void TabContents::SaveURL(const GURL& url,
2450 const GURL& referrer,
2451 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142452 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2453 if (!dlm)
2454 return;
2455 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262456 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142457 const NavigationEntry* entry = controller_.GetActiveEntry();
2458 if (entry)
2459 post_id = entry->GetPostID();
2460 }
2461 DownloadSaveInfo save_info;
2462 save_info.prompt_for_save_location = true;
2463 dlm->DownloadUrl(url,
2464 referrer,
2465 "",
2466 true, // prefer_cache
2467 post_id,
2468 save_info,
2469 this);
2470}
2471
[email protected]33f74972010-12-08 16:40:362472void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212473 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442474 // Can be NULL during tests.
2475 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212476 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362477}