blob: 71b14ff1d580390f83f1adac9a6efeb3b5e6dfa4 [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]64d69de42012-02-06 00:19:5420#include "content/browser/gpu/gpu_data_manager.h"
21#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"
29#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2230#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5031#include "content/browser/renderer_host/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1333#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2334#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4435#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]105bb0f2011-05-24 17:12:1436#include "content/browser/tab_contents/title_updated_details.h"
[email protected]d2353452012-01-19 19:53:5637#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2438#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5139#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0240#include "content/common/view_messages.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]cadaec52012-02-08 21:53:13119using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50120using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23121using content::NavigationEntry;
122using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20123using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57124using content::RenderViewHostDelegate;
[email protected]b6583592012-01-25 19:52:33125using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17126using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38127using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09128using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25129using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56130using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22131using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50132using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44133
[email protected]420ae012009-04-24 05:16:32134namespace {
135
136// Amount of time we wait between when a key event is received and the renderer
137// is queried for its state and pushed to the NavigationEntry.
138const int kQueryStateDelay = 5000;
139
[email protected]6ebdc9b2010-09-27 16:55:57140const int kSyncWaitDelay = 40;
141
[email protected]ca406032011-07-19 21:53:05142static const char kDotGoogleDotCom[] = ".google.com";
143
[email protected]420ae012009-04-24 05:16:32144#if defined(OS_WIN)
145
146BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
147 // Note: erase is required to properly paint some widgets borders. This can
148 // be seen with textfields.
149 InvalidateRect(hwnd, NULL, TRUE);
150 return TRUE;
151}
152#endif
153
[email protected]2c5569662011-03-22 20:45:02154ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23155 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50156 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16157 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47158 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02159 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47160 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02161 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47162 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16163 break; // Fall through to rest of function.
164 }
[email protected]5e369672009-11-03 23:48:30165
[email protected]59246c572012-02-10 13:32:13166 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
167 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23168 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13169 browser_context->DidLastSessionExitCleanly()) {
170 if (entry.GetHasPostData())
171 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02172 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13173 }
[email protected]5e369672009-11-03 23:48:30174
[email protected]2c5569662011-03-22 20:45:02175 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30176}
177
[email protected]10f417c52011-12-28 21:04:23178void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47179 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42180 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50181 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16182 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51183 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54184 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55185 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
186 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51187 params->url = entry.GetURL();
188 params->referrer = entry.GetReferrer();
189 params->transition = entry.GetTransitionType();
190 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00191 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55192 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34193 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47194 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48195 params->transferred_request_child_id =
196 entry.transferred_global_request_id().child_id;
197 params->transferred_request_request_id =
198 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47199
200 if (delegate)
201 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34202}
203
[email protected]420ae012009-04-24 05:16:32204} // namespace
205
[email protected]a81343d232011-12-27 07:39:20206namespace content {
207
208WebContents* WebContents::Create(
209 BrowserContext* browser_context,
210 SiteInstance* site_instance,
211 int routing_id,
212 const WebContents* base_tab_contents,
213 SessionStorageNamespace* session_storage_namespace) {
214 return new TabContents(browser_context,
215 site_instance,
216 routing_id,
217 static_cast<const TabContents*>(base_tab_contents),
218 session_storage_namespace);
219}
220}
[email protected]f4f50ef2011-01-21 19:01:19221
222// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32223
[email protected]3d7474ff2011-07-27 17:47:37224TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32225 SiteInstance* site_instance,
226 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07227 const TabContents* base_tab_contents,
228 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42229 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07230 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37231 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13232 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10233 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22234 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34235 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23236 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
237 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34238 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21239 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56240 upload_size_(0),
241 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47242 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57243 capturing_contents_(false),
244 is_being_destroyed_(false),
245 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55246 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57247#if defined(OS_WIN)
248 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
249#endif
[email protected]7ab1e7d62009-10-14 23:32:01250 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56251 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38252 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25253 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01254 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25255 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01256 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00257 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43258 content_restrictions_(0),
259 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37260 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32261
[email protected]34ac70502009-09-25 17:07:23262 // We have the initial size of the view be based on the size of the passed in
263 // tab contents (normally a tab from the same window).
264 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21265 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00266
267#if defined(ENABLE_JAVA_BRIDGE)
268 java_bridge_dispatcher_host_manager_.reset(
269 new JavaBridgeDispatcherHostManager(this));
270#endif
[email protected]332af7732009-03-11 13:21:35271}
initial.commit09911bf2008-07-26 23:55:29272
273TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32274 is_being_destroyed_ = true;
275
[email protected]3ab9cb82011-06-03 18:02:07276 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55277 if (dialog_creator_)
278 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07279
[email protected]420ae012009-04-24 05:16:32280 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32281
[email protected]420ae012009-04-24 05:16:32282 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07283 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09284 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
285 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07286 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32287
288 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07289#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32290 // If we still have a window handle, destroy it. GetNativeView can return
291 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42292 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52293 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44294 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42295 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42296 }
[email protected]420ae012009-04-24 05:16:32297#endif
[email protected]7ab1e7d62009-10-14 23:32:01298
299 // OnCloseStarted isn't called in unit tests.
300 if (!tab_close_start_time_.is_null()) {
301 UMA_HISTOGRAM_TIMES("Tab.Close",
302 base::TimeTicks::Now() - tab_close_start_time_);
303 }
[email protected]b5a1d11c2011-02-17 03:09:42304
[email protected]d8c660432011-12-22 20:51:25305 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08306
[email protected]6934a702011-12-20 00:04:51307 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42308}
309
[email protected]64d69de42012-02-06 00:19:54310WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
311 const GURL& url) {
312 WebPreferences prefs;
313
314 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
315
316 prefs.developer_extras_enabled = true;
317 prefs.javascript_enabled =
318 !command_line.HasSwitch(switches::kDisableJavaScript);
319 prefs.web_security_enabled =
320 !command_line.HasSwitch(switches::kDisableWebSecurity);
321 prefs.plugins_enabled =
322 !command_line.HasSwitch(switches::kDisablePlugins);
323 prefs.java_enabled =
324 !command_line.HasSwitch(switches::kDisableJava);
325
326 prefs.uses_page_cache =
327 command_line.HasSwitch(switches::kEnableFastback);
328 prefs.remote_fonts_enabled =
329 !command_line.HasSwitch(switches::kDisableRemoteFonts);
330 prefs.xss_auditor_enabled =
331 !command_line.HasSwitch(switches::kDisableXSSAuditor);
332 prefs.application_cache_enabled =
333 !command_line.HasSwitch(switches::kDisableApplicationCache);
334
335 prefs.local_storage_enabled =
336 !command_line.HasSwitch(switches::kDisableLocalStorage);
337 prefs.databases_enabled =
338 !command_line.HasSwitch(switches::kDisableDatabases);
339 prefs.webaudio_enabled =
340 !command_line.HasSwitch(switches::kDisableWebAudio);
341
342 prefs.experimental_webgl_enabled =
343 GpuProcessHost::gpu_enabled() &&
344 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
345 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
346
347 prefs.gl_multisampling_enabled =
348 !command_line.HasSwitch(switches::kDisableGLMultisampling);
349 prefs.privileged_webgl_extensions_enabled =
350 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
351 prefs.site_specific_quirks_enabled =
352 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
353 prefs.allow_file_access_from_file_urls =
354 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
355 prefs.show_composited_layer_borders =
356 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
357 prefs.show_composited_layer_tree =
358 command_line.HasSwitch(switches::kShowCompositedLayerTree);
359 prefs.show_fps_counter =
360 command_line.HasSwitch(switches::kShowFPSCounter);
361 prefs.accelerated_compositing_enabled =
362 GpuProcessHost::gpu_enabled() &&
363 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
364 prefs.threaded_compositing_enabled =
365 command_line.HasSwitch(switches::kEnableThreadedCompositing);
366 prefs.force_compositing_mode =
367 command_line.HasSwitch(switches::kForceCompositingMode);
368 prefs.fixed_position_compositing_enabled =
369 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
370 prefs.accelerated_2d_canvas_enabled =
371 GpuProcessHost::gpu_enabled() &&
372 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58373 prefs.deferred_2d_canvas_enabled =
374 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54375 prefs.accelerated_painting_enabled =
376 GpuProcessHost::gpu_enabled() &&
377 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
378 prefs.accelerated_filters_enabled =
379 GpuProcessHost::gpu_enabled() &&
380 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
381 prefs.accelerated_layers_enabled =
382 prefs.accelerated_animation_enabled =
383 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
384 prefs.composite_to_texture_enabled =
385 command_line.HasSwitch(switches::kEnableCompositeToTexture);
386 prefs.accelerated_plugins_enabled =
387 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
388 prefs.accelerated_video_enabled =
389 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
390 prefs.partial_swap_enabled =
391 command_line.HasSwitch(switches::kEnablePartialSwap);
392 prefs.interactive_form_validation_enabled =
393 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
394 prefs.fullscreen_enabled =
395 !command_line.HasSwitch(switches::kDisableFullScreen);
396
397#if defined(OS_MACOSX)
398 bool default_enable_scroll_animator = true;
399#else
400 // On CrOS, the launcher always passes in the --enable flag.
401 bool default_enable_scroll_animator = false;
402#endif
403 prefs.enable_scroll_animator = default_enable_scroll_animator;
404 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
405 prefs.enable_scroll_animator = true;
406 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
407 prefs.enable_scroll_animator = false;
408
409 prefs.visual_word_movement_enabled =
410 command_line.HasSwitch(switches::kEnableVisualWordMovement);
411 prefs.per_tile_painting_enabled =
412 command_line.HasSwitch(switches::kEnablePerTilePainting);
413
414 { // Certain GPU features might have been blacklisted.
415 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
416 DCHECK(gpu_data_manager);
417 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
418 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
419 prefs.accelerated_compositing_enabled = false;
420 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
421 prefs.experimental_webgl_enabled = false;
422 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
423 prefs.accelerated_2d_canvas_enabled = false;
424 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
425 prefs.gl_multisampling_enabled = false;
426
427 // Accelerated video and animation are slower than regular when using a
428 // software 3d rasterizer.
429 if (gpu_data_manager->software_rendering()) {
430 prefs.accelerated_video_enabled = false;
431 prefs.accelerated_animation_enabled = false;
432 }
433 }
434
[email protected]b9535422012-02-09 01:47:59435 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]64d69de42012-02-06 00:19:54436 rvh->process()->GetID())) {
437 prefs.loads_images_automatically = true;
438 prefs.javascript_enabled = true;
439 }
440
441 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
442
443 // Force accelerated compositing and 2d canvas off for chrome:, about: and
444 // chrome-devtools: pages (unless it's specifically allowed).
445 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
446 // Allow accelerated compositing for keyboard and log in screen.
447 url.SchemeIs(chrome::kChromeUIScheme) ||
448 (url.SchemeIs(chrome::kAboutScheme) &&
449 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25450 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54451 prefs.accelerated_compositing_enabled = false;
452 prefs.accelerated_2d_canvas_enabled = false;
453 }
454
455 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
456
457 return prefs;
458}
459
[email protected]d202a7c2012-01-04 07:53:47460NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20461 return controller_;
462}
463
[email protected]765187182012-01-11 23:59:28464RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
465 return &render_manager_;
466}
467
[email protected]724159a2010-12-30 01:11:18468bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56469 if (GetWebUI() &&
470 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17471 return true;
[email protected]d2353452012-01-19 19:53:56472 }
[email protected]f82d57b52011-04-27 19:13:17473
[email protected]d8c660432011-12-22 20:51:25474 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
475 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10476 while ((observer = it.GetNext()) != NULL)
477 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53478 return true;
[email protected]403415a2011-01-10 18:57:53479
[email protected]724159a2010-12-30 01:11:18480 bool handled = true;
481 bool message_is_ok = true;
482 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58483 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
484 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24485 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
486 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18487 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
488 OnDidStartProvisionalLoadForFrame)
489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
490 OnDidRedirectProvisionalLoad)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
492 OnDidFailProvisionalLoadWithError)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
494 OnDidLoadResourceFromMemoryCache)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
496 OnDidDisplayInsecureContent)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
498 OnDidRunInsecureContent)
499 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
500 OnDocumentLoadedInFrame)
501 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17502 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
503 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25504 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26505 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59506 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21507 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20508 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
509 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
510 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16511 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45512 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10513 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18514 IPC_MESSAGE_UNHANDLED(handled = false)
515 IPC_END_MESSAGE_MAP_EX()
516
517 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38518 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18519 GetRenderProcessHost()->ReceivedBadMessage();
520 }
521
522 return handled;
523}
524
[email protected]6c2e472f2011-08-24 23:26:18525void TabContents::RunFileChooser(
526 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23527 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51528 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18529}
530
[email protected]c5eed492012-01-04 17:07:50531NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56532 return controller_;
533}
534
[email protected]c5eed492012-01-04 17:07:50535const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56536 return controller_;
537}
538
[email protected]627e0512011-12-21 22:55:30539content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55540 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30541}
542
[email protected]f5fa20e2011-12-21 22:35:56543void TabContents::SetViewType(content::ViewType type) {
544 view_type_ = type;
545}
546
[email protected]ea049a02011-12-25 21:37:09547content::ViewType TabContents::GetViewType() const {
548 return view_type_;
549}
550
[email protected]be1f56ab2011-12-22 06:55:31551const GURL& TabContents::GetURL() const {
552 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23553 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51554 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31555}
556
557
558const base::PropertyBag* TabContents::GetPropertyBag() const {
559 return &property_bag_;
560}
561
562base::PropertyBag* TabContents::GetPropertyBag() {
563 return &property_bag_;
564}
565
566content::WebContentsDelegate* TabContents::GetDelegate() {
567 return delegate_;
568}
569
570void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
571 // TODO(cbentzel): remove this debugging code?
572 if (delegate == delegate_)
573 return;
574 if (delegate_)
575 delegate_->Detach(this);
576 delegate_ = delegate;
577 if (delegate_)
578 delegate_->Attach(this);
579}
580
[email protected]f3b1a082011-11-18 00:34:30581content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03582 if (render_manager_.current_host())
583 return render_manager_.current_host()->process();
584 else
585 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16586}
587
[email protected]be1f56ab2011-12-22 06:55:31588RenderViewHost* TabContents::GetRenderViewHost() const {
589 return render_manager_.current_host();
590}
591
592RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
593 return render_manager_.GetRenderWidgetHostView();
594}
595
[email protected]8643e6d2012-01-18 20:26:10596content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31597 return view_.get();
598}
599
[email protected]01ec4ec2012-01-18 04:13:47600content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50601 WebUIControllerFactory* factory =
602 content::GetContentClient()->browser()->GetWebUIControllerFactory();
603 if (!factory)
604 return NULL;
[email protected]d2353452012-01-19 19:53:56605 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22606 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50607 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22608 if (controller) {
609 web_ui->SetController(controller);
610 return web_ui;
611 }
612
613 delete web_ui;
614 return NULL;
615}
616
[email protected]01ec4ec2012-01-18 04:13:47617content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31618 return render_manager_.web_ui() ? render_manager_.web_ui()
619 : render_manager_.pending_web_ui();
620}
621
[email protected]01ec4ec2012-01-18 04:13:47622content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31623 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34624}
625
[email protected]96d185d2009-04-24 03:28:54626const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55627 // Transient entries take precedence. They are used for interstitial pages
628 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23629 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08630 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20631 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30632 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23633 if (entry) {
[email protected]b5cca982011-05-26 04:42:08634 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23635 }
[email protected]7ade2732011-02-10 00:13:58636 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
637 render_manager_.pending_web_ui() : render_manager_.web_ui();
638 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54639 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55640 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54641 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35642 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22643 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54644 if (!title.empty())
645 return title;
646 }
647 }
648
649 // We use the title for the last committed entry rather than a pending
650 // navigation entry. For example, when the user types in a URL, we want to
651 // keep the old page's title until the new load has committed and we get a new
652 // title.
[email protected]96d185d2009-04-24 03:28:54653 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23654 if (entry) {
[email protected]b5cca982011-05-26 04:42:08655 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23656 }
[email protected]987fc3a2011-05-26 14:18:09657
658 // |page_title_when_no_navigation_entry_| is finally used
659 // if no title cannot be retrieved.
660 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54661}
662
[email protected]d5f942ba2008-09-26 19:30:34663int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46664 return GetMaxPageIDForSiteInstance(GetSiteInstance());
665}
666
667int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33668 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
669 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46670
[email protected]b6583592012-01-25 19:52:33671 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34672}
673
674void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46675 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
676}
677
[email protected]b6583592012-01-25 19:52:33678void TabContents::UpdateMaxPageIDForSiteInstance(
679 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46680 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33681 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34682}
683
[email protected]91854cd2012-01-10 19:43:57684void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
685 max_page_ids_ = tab_contents->max_page_ids_;
686}
687
[email protected]96d185d2009-04-24 03:28:54688SiteInstance* TabContents::GetSiteInstance() const {
689 return render_manager_.current_host()->site_instance();
690}
691
[email protected]77362eb2011-08-01 17:18:38692SiteInstance* TabContents::GetPendingSiteInstance() const {
693 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
694 render_manager_.pending_render_view_host() :
695 render_manager_.current_host();
696 return dest_rvh->site_instance();
697}
698
[email protected]be1f56ab2011-12-22 06:55:31699bool TabContents::IsLoading() const {
700 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49701}
702
[email protected]be1f56ab2011-12-22 06:55:31703bool TabContents::IsWaitingForResponse() const {
704 return waiting_for_response_;
705}
706
707const net::LoadStateWithParam& TabContents::GetLoadState() const {
708 return load_state_;
709}
710
711const string16& TabContents::GetLoadStateHost() const {
712 return load_state_host_;
713}
714
715uint64 TabContents::GetUploadSize() const {
716 return upload_size_;
717}
718
719uint64 TabContents::GetUploadPosition() const {
720 return upload_position_;
721}
722
723const std::string& TabContents::GetEncoding() const {
724 return encoding_;
725}
726
727bool TabContents::DisplayedInsecureContent() const {
728 return displayed_insecure_content_;
729}
730
731void TabContents::SetCapturingContents(bool cap) {
732 capturing_contents_ = cap;
733}
734
735bool TabContents::IsCrashed() const {
736 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
737 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
738 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49739}
740
[email protected]443b80e2010-12-14 00:42:23741void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
742 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34743 return;
744
[email protected]443b80e2010-12-14 00:42:23745 crashed_status_ = status;
746 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46747 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34748}
749
[email protected]be1f56ab2011-12-22 06:55:31750base::TerminationStatus TabContents::GetCrashedStatus() const {
751 return crashed_status_;
752}
753
754bool TabContents::IsBeingDestroyed() const {
755 return is_being_destroyed_;
756}
757
[email protected]d5f942ba2008-09-26 19:30:34758void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
759 if (delegate_)
760 delegate_->NavigationStateChanged(this, changed_flags);
761}
762
[email protected]96d185d2009-04-24 03:28:54763void TabContents::DidBecomeSelected() {
764 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16765 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
766 if (rwhv) {
767 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43768#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16769 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43770#endif
771 }
[email protected]96d185d2009-04-24 03:28:54772
[email protected]5ac20162010-11-24 23:33:11773 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38774
[email protected]d8c660432011-12-22 20:51:25775 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59776
777 // The resize rect might have changed while this was inactive -- send the new
778 // one to make sure it's up to date.
779 RenderViewHost* rvh = GetRenderViewHost();
780 if (rvh) {
781 rvh->ResizeRectChanged(GetRootWindowResizerRect());
782 }
[email protected]96d185d2009-04-24 03:28:54783}
784
[email protected]be1f56ab2011-12-22 06:55:31785
786base::TimeTicks TabContents::GetLastSelectedTime() const {
787 return last_selected_time_;
788}
789
[email protected]96d185d2009-04-24 03:28:54790void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31791 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52792 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
793 // open a tab in then background, then closes the tab before selecting it.
794 // This is because closing the tab calls TabContents::Destroy(), which
795 // removes the |GetRenderViewHost()|; then when we actually destroy the
796 // window, OnWindowPosChanged() notices and calls HideContents() (which
797 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16798 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
799 if (rwhv)
800 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54801 }
802
[email protected]ad50def52011-10-19 23:17:07803 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09804 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
805 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07806 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54807}
808
[email protected]be1f56ab2011-12-22 06:55:31809void TabContents::ShowContents() {
810 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
811 if (rwhv)
812 rwhv->DidBecomeSelected();
813}
814
815void TabContents::HideContents() {
816 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
817 // our superclass HideContents(), because some callers want to be very picky
818 // about the order in which these get called. In addition to making the code
819 // here practically impossible to understand, this also means we end up
820 // calling TabContents::WasHidden() twice if callers call both versions of
821 // HideContents() on a TabContents.
822 WasHidden();
823}
824
825bool TabContents::NeedToFireBeforeUnload() {
826 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27827 return WillNotifyDisconnection() &&
828 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31829 !GetRenderViewHost()->SuddenTerminationAllowed();
830}
831
[email protected]0bfbf882011-12-22 18:19:27832void TabContents::Stop() {
833 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25834 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27835}
836
[email protected]d9083482012-01-06 00:38:46837WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27838 // We create a new SiteInstance so that the new tab won't share processes
839 // with the old one. This can be changed in the future if we need it to share
840 // processes for some reason.
841 TabContents* tc = new TabContents(
842 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33843 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27844 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20845 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27846 return tc;
847}
848
849void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17850 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27851 bool show_history) {
852 if (!delegate_)
853 return;
854
855 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
856}
857
[email protected]2a6bc3e2011-12-28 23:51:33858void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27859 WindowOpenDisposition disposition,
860 const gfx::Rect& initial_pos,
861 bool user_gesture) {
862 if (!delegate_)
863 return;
864
865 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
866 user_gesture);
867}
868
869gfx::NativeView TabContents::GetContentNativeView() const {
870 return view_->GetContentNativeView();
871}
872
873gfx::NativeView TabContents::GetNativeView() const {
874 return view_->GetNativeView();
875}
876
877void TabContents::GetContainerBounds(gfx::Rect* out) const {
878 view_->GetContainerBounds(out);
879}
880
881void TabContents::Focus() {
882 view_->Focus();
883}
884
[email protected]d8c660432011-12-22 20:51:25885void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31886 observers_.AddObserver(observer);
887}
888
[email protected]d8c660432011-12-22 20:51:25889void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31890 observers_.RemoveObserver(observer);
891}
892
[email protected]d5f942ba2008-09-26 19:30:34893void TabContents::Activate() {
894 if (delegate_)
895 delegate_->ActivateContents(this);
896}
897
[email protected]ea42e7782010-08-23 23:58:12898void TabContents::Deactivate() {
899 if (delegate_)
900 delegate_->DeactivateContents(this);
901}
902
[email protected]63954792011-07-11 04:17:48903void TabContents::LostCapture() {
904 if (delegate_)
905 delegate_->LostCapture();
906}
907
908bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
909 bool* is_keyboard_shortcut) {
910 return delegate_ &&
911 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
912}
913
914void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
915 if (delegate_)
916 delegate_->HandleKeyboardEvent(event);
917}
918
[email protected]32ded2212011-11-10 18:51:43919void TabContents::HandleMouseDown() {
920 if (delegate_)
921 delegate_->HandleMouseDown();
922}
923
[email protected]63954792011-07-11 04:17:48924void TabContents::HandleMouseUp() {
925 if (delegate_)
926 delegate_->HandleMouseUp();
927}
928
929void TabContents::HandleMouseActivate() {
930 if (delegate_)
931 delegate_->HandleMouseActivate();
932}
933
[email protected]8a5e0ca2011-08-25 06:30:47934void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
935 if (delegate_)
936 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
937}
938
[email protected]5d5f7af2011-10-01 01:38:12939bool TabContents::IsFullscreenForCurrentTab() const {
940 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
941}
942
[email protected]e9621112011-10-17 05:38:37943void TabContents::RequestToLockMouse() {
944 if (delegate_) {
945 delegate_->RequestToLockMouse(this);
946 } else {
947 GotResponseToLockMouseRequest(false);
948 }
949}
950
951void TabContents::LostMouseLock() {
952 if (delegate_)
953 delegate_->LostMouseLock();
954}
955
[email protected]0548c5352011-09-07 00:33:33956void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23957 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33958 if (delegate_)
959 delegate_->UpdatePreferredSize(this, pref_size);
960}
961
[email protected]32ded2212011-11-10 18:51:43962void TabContents::WebUISend(RenderViewHost* render_view_host,
963 const GURL& source_url,
964 const std::string& name,
965 const base::ListValue& args) {
966 if (delegate_)
967 delegate_->WebUISend(this, source_url, name, args);
968}
969
[email protected]e5d549d2011-12-28 01:29:20970WebContents* TabContents::OpenURL(const OpenURLParams& params) {
971 if (!delegate_)
972 return NULL;
[email protected]00c37fc2011-08-02 00:22:50973
[email protected]e5d549d2011-12-28 01:29:20974 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
975 // Notify observers.
976 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
977 DidOpenURL(params.url, params.referrer,
978 params.disposition, params.transition));
979 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34980}
981
[email protected]1ccb3568d2010-02-19 10:51:16982bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50983 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25984 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23985 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25986 reload_type);
[email protected]876bc832010-09-07 16:29:54987}
[email protected]96d185d2009-04-24 03:28:54988
[email protected]876bc832010-09-07 16:29:54989bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23990 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50991 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40992 // The renderer will reject IPC messages with URLs longer than
993 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51994 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40995 return false;
996
[email protected]dd11de52011-11-03 22:54:27997 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40998 if (!dest_render_view_host)
999 return false; // Unable to create the desired render view host.
1000
[email protected]80a8fad2011-01-29 04:02:381001 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071002 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581003 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:501004 WebUIControllerFactory* factory =
1005 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1006 bool is_allowed_in_web_ui_renderer =
1007 factory &&
1008 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431009#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511010 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431011#endif
[email protected]e091df82011-10-11 18:13:211012 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551013 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581014
[email protected]96d185d2009-04-24 03:28:541015 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441016 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521017 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441018 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511019 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541020
1021 // Used for page load time metrics.
1022 current_load_start_ = base::TimeTicks::Now();
1023
1024 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341025 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271026 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471027 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341028 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541029
[email protected]36fc0392011-12-25 03:59:511030 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541031 // HACK!! This code suppresses javascript: URLs from being added to
1032 // session history, which is what we want to do for javascript: URLs that
1033 // do not generate content. What we really need is a message from the
1034 // renderer telling us that a new page was not created. The same message
1035 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511036 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541037 return false;
1038 }
1039
[email protected]3c9e1872010-11-18 16:17:491040 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251041 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041042 observers_,
[email protected]36fc0392011-12-25 03:59:511043 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541044
[email protected]09b29342011-06-24 19:18:481045 if (delegate_)
1046 delegate_->DidNavigateToPendingEntry(this);
1047
[email protected]d5f942ba2008-09-26 19:30:341048 return true;
1049}
1050
[email protected]b6583592012-01-25 19:52:331051void TabContents::SetHistoryLengthAndPrune(
1052 const SiteInstance* site_instance,
1053 int history_length,
1054 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411055 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1056 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191057 if (render_manager_.pending_render_view_host()) {
1058 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141059 return;
[email protected]9e1ad4b2011-08-14 16:49:191060 }
[email protected]151a63d2011-12-20 22:32:521061 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191062 if (!rvh) {
1063 NOTREACHED();
1064 return;
1065 }
1066 if (site_instance && rvh->site_instance() != site_instance) {
1067 NOTREACHED();
1068 return;
1069 }
1070 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1071 history_length,
1072 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141073}
1074
[email protected]90daadb42009-06-08 21:27:281075void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271076 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541077 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1078 return;
1079 }
[email protected]151a63d2011-12-20 22:32:521080 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541081}
1082
[email protected]0bfbf882011-12-22 18:19:271083bool TabContents::ShowingInterstitialPage() const {
1084 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541085}
1086
[email protected]0bfbf882011-12-22 18:19:271087InterstitialPage* TabContents::GetInterstitialPage() const {
1088 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221089}
1090
[email protected]a53209b2012-01-20 16:48:161091bool TabContents::IsSavable() {
1092 // WebKit creates Document object when MIME type is application/xhtml+xml,
1093 // so we also support this MIME type.
1094 return contents_mime_type_ == "text/html" ||
1095 contents_mime_type_ == "text/xml" ||
1096 contents_mime_type_ == "application/xhtml+xml" ||
1097 contents_mime_type_ == "text/plain" ||
1098 contents_mime_type_ == "text/css" ||
1099 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1100}
1101
[email protected]c7dd2f62011-07-18 15:57:591102void TabContents::OnSavePage() {
1103 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161104 if (!IsSavable()) {
[email protected]e30d68d2012-02-09 00:06:261105 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141106 download_stats::RecordDownloadCount(
1107 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
1108 return;
[email protected]c7dd2f62011-07-18 15:57:591109 }
1110
1111 Stop();
1112
1113 // Create the save package and possibly prompt the user for the name to save
1114 // the page as. The user prompt is an asynchronous operation that runs on
1115 // another thread.
1116 save_package_ = new SavePackage(this);
1117 save_package_->GetSaveInfo();
1118}
1119
1120// Used in automated testing to bypass prompting the user for file names.
1121// Instead, the names and paths are hard coded rather than running them through
1122// file name sanitation and extension / mime checking.
1123bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161124 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591125 // Stop the page from navigating.
1126 Stop();
1127
1128 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1129 return save_package_->Init();
1130}
1131
[email protected]420ae012009-04-24 05:16:321132bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231133 NavigationEntryImpl* active_entry =
1134 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321135 return (active_entry != NULL &&
1136 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511137 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321138}
1139
[email protected]0bfbf882011-12-22 18:19:271140const std::string& TabContents::GetContentsMimeType() const {
1141 return contents_mime_type_;
1142}
1143
1144bool TabContents::WillNotifyDisconnection() const {
1145 return notify_disconnection_;
1146}
1147
[email protected]b2fe07d12010-02-09 14:38:081148void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311149 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521150 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1151 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161152}
1153
[email protected]b2fe07d12010-02-09 14:38:081154void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311155 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521156 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1157 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161158}
1159
[email protected]0bfbf882011-12-22 18:19:271160content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1161 return &renderer_preferences_;
1162}
1163
1164void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1165 new_tab_start_time_ = time;
1166}
1167
1168base::TimeTicks TabContents::GetNewTabStartTime() const {
1169 return new_tab_start_time_;
1170}
1171
[email protected]7ab1e7d62009-10-14 23:32:011172void TabContents::OnCloseStarted() {
1173 if (tab_close_start_time_.is_null())
1174 tab_close_start_time_ = base::TimeTicks::Now();
1175}
1176
[email protected]46624bf2010-06-09 16:04:191177bool TabContents::ShouldAcceptDragAndDrop() const {
1178#if defined(OS_CHROMEOS)
1179 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1180 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511181 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201182 return false;
1183 return true;
[email protected]46624bf2010-06-09 16:04:191184#else
1185 return true;
1186#endif
1187}
1188
[email protected]7813bd72011-02-05 02:19:341189void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521190 if (GetRenderViewHost())
1191 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511192 if (delegate_)
1193 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341194}
1195
[email protected]0bfbf882011-12-22 18:19:271196void TabContents::SetClosedByUserGesture(bool value) {
1197 closed_by_user_gesture_ = value;
1198}
1199
1200bool TabContents::GetClosedByUserGesture() const {
1201 return closed_by_user_gesture_;
1202}
1203
[email protected]d0b8d092010-10-25 04:05:171204double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051205 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
1206 GetBrowserContext()->GetHostZoomMap());
[email protected]b75b8292010-10-01 07:28:251207 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171208 return 0;
[email protected]b75b8292010-10-01 07:28:251209
1210 double zoom_level;
1211 if (temporary_zoom_settings_) {
1212 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521213 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251214 } else {
[email protected]2ae88d12011-10-14 09:11:191215 GURL url;
[email protected]10f417c52011-12-28 21:04:231216 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191217 // Since zoom map is updated using rewritten URL, use rewritten URL
1218 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511219 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191220 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251221 }
[email protected]d0b8d092010-10-25 04:05:171222 return zoom_level;
1223}
[email protected]b75b8292010-10-01 07:28:251224
[email protected]d0b8d092010-10-25 04:05:171225int TabContents::GetZoomPercent(bool* enable_increment,
1226 bool* enable_decrement) {
1227 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011228 // Calculate the zoom percent from the factor. Round up to the nearest whole
1229 // number.
[email protected]b75b8292010-10-01 07:28:251230 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011231 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251232 *enable_decrement = percent > minimum_zoom_percent_;
1233 *enable_increment = percent < maximum_zoom_percent_;
1234 return percent;
1235}
1236
[email protected]3c733bde2010-12-21 19:56:311237void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501238 if (!delegate_)
1239 return;
1240
[email protected]10f417c52011-12-28 21:04:231241 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501242 if (!active_entry)
1243 return;
1244
[email protected]36fc0392011-12-25 03:59:511245 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121246}
1247
[email protected]932b7a12011-03-09 12:50:271248void TabContents::ViewFrameSource(const GURL& url,
1249 const std::string& content_state) {
1250 if (!delegate_)
1251 return;
1252
1253 delegate_->ViewSourceForFrame(this, url, content_state);
1254}
1255
[email protected]0bfbf882011-12-22 18:19:271256int TabContents::GetMinimumZoomPercent() const {
1257 return minimum_zoom_percent_;
1258}
1259
1260int TabContents::GetMaximumZoomPercent() const {
1261 return maximum_zoom_percent_;
1262}
1263
[email protected]bcd2815602012-01-14 18:17:231264gfx::Size TabContents::GetPreferredSize() const {
1265 return preferred_size_;
1266}
1267
[email protected]0bfbf882011-12-22 18:19:271268int TabContents::GetContentRestrictions() const {
1269 return content_restrictions_;
1270}
1271
1272WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501273 WebUIControllerFactory* factory =
1274 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1275 if (!factory)
1276 return WebUI::kNoWebUI;
1277 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271278}
1279
[email protected]01ec4ec2012-01-18 04:13:471280content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271281 // When there is a pending navigation entry, we want to use the pending WebUI
1282 // that goes along with it to control the basic flags. For example, we want to
1283 // show the pending URL in the URL bar, so we want the display_url flag to
1284 // be from the pending entry.
1285 //
1286 // The confusion comes because there are multiple possibilities for the
1287 // initial load in a tab as a side effect of the way the RenderViewHostManager
1288 // works.
1289 //
1290 // - For the very first tab the load looks "normal". The new tab Web UI is
1291 // the pending one, and we want it to apply here.
1292 //
1293 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1294 // get switched to the one previously associated with the new tab pages.
1295 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1296 // have a committed Web UI in this case.
1297 //
1298 // This condition handles all of these cases:
1299 //
1300 // - First load in first tab: no committed nav entry + pending nav entry +
1301 // pending dom ui:
1302 // -> Use pending Web UI if any.
1303 //
1304 // - First load in second tab: no committed nav entry + pending nav entry +
1305 // no pending Web UI:
1306 // -> Use the committed Web UI if any.
1307 //
1308 // - Second navigation in any tab: committed nav entry + pending nav entry:
1309 // -> Use pending Web UI if any.
1310 //
1311 // - Normal state with no load: committed nav entry + no pending nav entry:
1312 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251313 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271314 (controller_.GetLastCommittedEntry() ||
1315 render_manager_.pending_web_ui()))
1316 return render_manager_.pending_web_ui();
1317 return render_manager_.web_ui();
1318}
1319
1320bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1321 return GetRenderViewHost() ?
1322 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1323}
1324
1325bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471326 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271327 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221328 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231329 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511330 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271331 return true;
1332 return false;
1333}
1334
1335void TabContents::SetFocusToLocationBar(bool select_all) {
1336 if (delegate_)
1337 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211338}
1339
[email protected]8b5af492011-11-28 21:50:581340void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301341 const string16& type,
1342 const string16& href,
1343 const string16& title,
1344 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511345 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301346 this, action, type, href, title, disposition);
1347}
1348
[email protected]678105012011-12-09 04:01:211349void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301350 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001351 WebIntentsDispatcherImpl* intents_dispatcher =
1352 new WebIntentsDispatcherImpl(this, intent, intent_id);
1353 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301354}
1355
[email protected]724159a2010-12-30 01:11:181356void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1357 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591358 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181359 const GURL& url) {
1360 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1361 GURL validated_url(url);
[email protected]b9535422012-02-09 01:47:591362 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301363 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181364
[email protected]8093a542011-05-13 07:29:321365 RenderViewHost* rvh =
1366 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521367 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101368 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251369 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101370 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321371 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101372
[email protected]724159a2010-12-30 01:11:181373 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591374 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251375 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591376 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181377 }
1378}
1379
1380void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591381 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181382 const GURL& source_url,
1383 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491384 // TODO(creis): Remove this method and have the pre-rendering code listen to
1385 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1386 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231387 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181388 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251389 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181390 else
1391 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511392 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181393 return;
[email protected]e7d50892011-01-19 21:47:381394
[email protected]4850a7f2011-03-08 23:36:591395 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251396 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261397 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591398 opener_url));
[email protected]724159a2010-12-30 01:11:181399}
1400
1401void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581402 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1403 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1404 << ", error_code: " << params.error_code
1405 << ", error_description: " << params.error_description
1406 << ", is_main_frame: " << params.is_main_frame
1407 << ", showing_repost_interstitial: " <<
1408 params.showing_repost_interstitial
1409 << ", frame_id: " << params.frame_id;
1410 GURL validated_url(params.url);
[email protected]b9535422012-02-09 01:47:591411 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301412 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181413
[email protected]d7b175e2011-10-11 15:31:581414 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181415 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1416 // This means that the interstitial won't be torn down properly, which is
1417 // bad. But if we have an interstitial, go back to another tab type, and
1418 // then load the same interstitial again, we could end up getting the first
1419 // interstitial's "failed" message (as a result of the cancel) when we're on
1420 // the second one.
1421 //
1422 // We can't tell this apart, so we think we're tearing down the current page
1423 // which will cause a crash later one. There is also some code in
1424 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1425 // out because of this problem.
1426 //
1427 // http://code.google.com/p/chromium/issues/detail?id=2855
1428 // Because this will not tear down the interstitial properly, if "back" is
1429 // back to another tab type, the interstitial will still be somewhat alive
1430 // in the previous tab type. If you navigate somewhere that activates the
1431 // tab with the interstitial again, you'll see a flash before the new load
1432 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271433 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181434 LOG(WARNING) << "Discarding message during interstitial.";
1435 return;
1436 }
1437
[email protected]02102f82011-06-13 20:37:021438 // Discard our pending entry if the load canceled (e.g. if we decided to
1439 // download the file instead of load it). We do not verify that the URL
1440 // being canceled matches the pending entry's URL because they will not
1441 // match if a redirect occurred (in which case we do not want to leave a
1442 // stale redirect URL showing). This means that we also cancel the pending
1443 // entry if the user started a new navigation. As a result, the navigation
1444 // controller may not remember that a load is in progress, but the
1445 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251446 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161447 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181448
[email protected]151a63d2011-12-20 22:32:521449 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181450 }
1451
1452 // Send out a notification that we failed a provisional load with an error.
1453 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581454 params.is_main_frame,
1455 controller_.IsURLInPageNavigation(validated_url),
1456 validated_url,
1457 std::string(),
1458 false,
1459 params.frame_id);
1460 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181461
[email protected]ad50def52011-10-19 23:17:071462 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271463 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501464 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531465 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101466
[email protected]d8c660432011-12-22 20:51:251467 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581468 observers_,
1469 DidFailProvisionalLoad(params.frame_id,
1470 params.is_main_frame,
1471 validated_url,
1472 params.error_code,
1473 params.error_description));
[email protected]724159a2010-12-30 01:11:181474}
1475
1476void TabContents::OnDidLoadResourceFromMemoryCache(
1477 const GURL& url,
[email protected]70435962011-08-02 20:13:281478 const std::string& security_info,
1479 const std::string& http_method,
1480 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191481 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181482 cache.Increment();
1483
1484 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081485 int cert_id = 0;
1486 net::CertStatus cert_status = 0;
1487 int security_bits = -1;
1488 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511489 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1490 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301491 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161492 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181493
[email protected]ad50def52011-10-19 23:17:071494 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271495 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501496 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531497 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181498}
1499
1500void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381501 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181502 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201503 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181504}
1505
1506void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021507 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231508 LOG(INFO) << security_origin << " ran insecure content from "
1509 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381510 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051511 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381512 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051513 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1514 }
[email protected]71fde352011-12-29 03:29:561515 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411516 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201517 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181518}
1519
1520void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1521 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251522 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101523 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181524}
1525
[email protected]1a55c5be2011-11-29 11:36:311526void TabContents::OnDidFinishLoad(
1527 int64 frame_id,
1528 const GURL& validated_url,
1529 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251530 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311531 DidFinishLoad(frame_id, validated_url, is_main_frame));
1532}
1533
1534void TabContents::OnDidFailLoadWithError(int64 frame_id,
1535 const GURL& validated_url,
1536 bool is_main_frame,
1537 int error_code,
1538 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251539 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311540 DidFailLoad(frame_id, validated_url, is_main_frame,
1541 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181542}
1543
[email protected]c8f73ab2011-01-22 00:05:171544void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271545 content_restrictions_ = restrictions;
1546 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171547}
1548
[email protected]216813952011-05-19 22:21:261549void TabContents::OnGoToEntryAtOffset(int offset) {
1550 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231551 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251552 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261553 if (!entry)
1554 return;
1555 // Note that we don't call NavigationController::GotToOffset() as we don't
1556 // want to create a pending navigation entry (it might end up lingering
1557 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251558 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581559 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511560 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581561 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471562 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571563
1564 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1565 // it in now that we know. This allows us to find the entry when it commits.
1566 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231567 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331568 entry->set_site_instance(
1569 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571570 }
[email protected]216813952011-05-19 22:21:261571 }
1572}
1573
1574void TabContents::OnUpdateZoomLimits(int minimum_percent,
1575 int maximum_percent,
1576 bool remember) {
1577 minimum_zoom_percent_ = minimum_percent;
1578 maximum_zoom_percent_ = maximum_percent;
1579 temporary_zoom_settings_ = !remember;
1580}
1581
[email protected]0bfbf882011-12-22 18:19:271582void TabContents::OnSaveURL(const GURL& url) {
[email protected]e30d68d2012-02-09 00:06:261583 // Check if the URL to save matches the URL of the main frame. Since this
1584 // message originates from Pepper plugins, it may not be the case if the
1585 // plugin is an embedded element.
1586 GURL main_frame_url = GetURL();
1587 if (!main_frame_url.is_valid())
1588 return;
1589 bool is_main_frame = (url == main_frame_url);
1590 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271591}
1592
[email protected]3a29a6e2011-08-24 18:26:211593void TabContents::OnEnumerateDirectory(int request_id,
1594 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591595 ChildProcessSecurityPolicyImpl* policy =
1596 ChildProcessSecurityPolicyImpl::GetInstance();
1597 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1598 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211599}
1600
[email protected]7d189022011-08-25 22:54:201601void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511602 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201603}
1604
1605void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1606 const GURL& url,
1607 const string16& title) {
[email protected]b9535422012-02-09 01:47:591608 ChildProcessSecurityPolicyImpl* policy =
1609 ChildProcessSecurityPolicyImpl::GetInstance();
1610 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1611 return;
[email protected]6934a702011-12-20 00:04:511612 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201613}
1614
[email protected]b888919c2011-09-02 00:32:161615void TabContents::OnFindReply(int request_id,
1616 int number_of_matches,
1617 const gfx::Rect& selection_rect,
1618 int active_match_ordinal,
1619 bool final_update) {
[email protected]6934a702011-12-20 00:04:511620 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1621 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001622 // Send a notification to the renderer that we are ready to receive more
1623 // results from the scoping effort of the Find operation. The FindInPage
1624 // scoping is asynchronous and periodically sends results back up to the
1625 // browser using IPC. In an effort to not spam the browser we have the
1626 // browser send an ACK for each FindReply message and have the renderer
1627 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521628 GetRenderViewHost()->Send(
1629 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161630}
1631
[email protected]d952a052011-09-06 18:42:451632void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511633 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451634}
1635
[email protected]7fc4bbb2011-09-08 21:23:101636void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1637 bool blocked_by_policy) {
1638 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251639 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101640 AppCacheAccessed(manifest_url, blocked_by_policy));
1641}
1642
[email protected]96d185d2009-04-24 03:28:541643// Notifies the RenderWidgetHost instance about the fact that the page is
1644// loading, or done loading and calls the base implementation.
1645void TabContents::SetIsLoading(bool is_loading,
1646 LoadNotificationDetails* details) {
1647 if (is_loading == is_loading_)
1648 return;
1649
1650 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211651 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541652 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561653 upload_size_ = 0;
1654 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541655 }
1656
1657 render_manager_.SetIsLoading(is_loading);
1658
1659 is_loading_ = is_loading;
1660 waiting_for_response_ = is_loading;
1661
[email protected]6ebdc9b2010-09-27 16:55:571662 if (delegate_)
1663 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461664 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541665
[email protected]432115822011-07-10 15:52:271666 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1667 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071668 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541669 if (details)
[email protected]6c2381d2011-10-19 02:52:531670 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071671 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501672 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541673 det);
1674}
1675
[email protected]420ae012009-04-24 05:16:321676void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131677 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321678 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561679 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381680 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441681 // that opened the window, as long as both renderers have the same
1682 // privileges.
[email protected]1fd1a502011-03-30 16:55:561683 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561684 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581685 // web_ui might be NULL if the URL refers to a non-existent extension.
1686 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401687 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521688 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441689 }
1690 }
[email protected]1fd1a502011-03-30 16:55:561691 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441692 }
1693
[email protected]4e697b042011-07-08 06:44:561694 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321695 // Clear the status bubble. This is a workaround for a bug where WebKit
1696 // doesn't let us know that the cursor left an element during a
1697 // transition (this is also why the mouse cursor remains as a hand after
1698 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1699 // clear the bubble when a user navigates to a named anchor in the same
1700 // page.
[email protected]36fc0392011-12-25 03:59:511701 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321702 }
1703
[email protected]a6e82fc2010-02-24 22:28:141704 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471705 // Once the main frame is navigated, we're no longer considered to have
1706 // displayed insecure content.
1707 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171708 }
[email protected]ce5c4502009-05-06 16:46:111709
[email protected]3c9e1872010-11-18 16:17:491710 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251711 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041712 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321713}
1714
1715void TabContents::DidNavigateAnyFramePostCommit(
1716 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131717 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321718 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061719 // If we navigate off the page, reset JavaScript state. This does nothing
1720 // to prevent a malicious script from spamming messages, since the script
1721 // could just reload the page to stop blocking.
1722 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551723 dialog_creator_->ResetJavaScriptState(this);
1724 dialog_creator_ = NULL;
1725 }
[email protected]420ae012009-04-24 05:16:321726
[email protected]3c9e1872010-11-18 16:17:491727 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041729 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321730}
1731
[email protected]74ce1ad2011-12-16 21:51:461732void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1733 // If we are creating a RVH for a restored controller, then we need to make
1734 // sure the RenderView starts with a next_page_id_ larger than the number
1735 // of restored entries. This must be called before the RenderView starts
1736 // navigating (to avoid a race between the browser updating max_page_id and
1737 // the renderer updating next_page_id_). Because of this, we only call this
1738 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561739 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461740 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1741 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321742}
1743
[email protected]10f417c52011-12-28 21:04:231744bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571745 const string16& title) {
[email protected]420ae012009-04-24 05:16:321746 // For file URLs without a title, use the pathname instead. In the case of a
1747 // synthesized title, we don't want the update to count toward the "one set
1748 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511749 string16 final_title;
[email protected]420ae012009-04-24 05:16:321750 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511751 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1752 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321753 explicit_set = false; // Don't count synthetic titles toward the set limit.
1754 } else {
[email protected]acafd272011-07-26 17:35:571755 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321756 explicit_set = true;
1757 }
1758
[email protected]987fc3a2011-05-26 14:18:091759 // If a page is created via window.open and never navigated,
1760 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551761 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091762 if (entry) {
[email protected]36fc0392011-12-25 03:59:511763 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091764 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321765
[email protected]36fc0392011-12-25 03:59:511766 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091767 } else {
1768 if (page_title_when_no_navigation_entry_ == final_title)
1769 return false; // Nothing changed, don't bother.
1770
1771 page_title_when_no_navigation_entry_ = final_title;
1772 }
[email protected]420ae012009-04-24 05:16:321773
[email protected]420ae012009-04-24 05:16:321774 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231775 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321776
[email protected]105bb0f2011-05-24 17:12:141777 TitleUpdatedDetails details(entry, explicit_set);
1778
[email protected]ad50def52011-10-19 23:17:071779 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441780 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1781 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531782 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041783
[email protected]420ae012009-04-24 05:16:321784 return true;
1785}
1786
1787void TabContents::NotifySwapped() {
1788 // After sending out a swap notification, we need to send a disconnect
1789 // notification so that clients that pick up a pointer to |this| can NULL the
1790 // pointer. See Bug 1230284.
1791 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071792 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201793 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1794 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071795 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321796}
1797
1798void TabContents::NotifyConnected() {
1799 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071800 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121801 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1802 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071803 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321804}
1805
1806void TabContents::NotifyDisconnected() {
1807 if (!notify_disconnection_)
1808 return;
1809
1810 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071811 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321812 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1813 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071814 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321815}
1816
[email protected]8d3347f2009-07-09 22:00:211817RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321818 return view_.get();
1819}
1820
[email protected]8d3347f2009-07-09 22:00:211821RenderViewHostDelegate::RendererManagement*
1822TabContents::GetRendererManagementDelegate() {
1823 return &render_manager_;
1824}
1825
[email protected]daf82f82011-10-31 22:35:311826content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371827 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461828 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511829}
1830
[email protected]768c5472011-12-26 19:06:171831WebContents* TabContents::GetAsWebContents() {
1832 return this;
1833}
1834
[email protected]da4dfc42011-10-12 15:53:561835content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431836 return view_type_;
[email protected]7b291f92009-08-14 05:43:531837}
1838
[email protected]b7a756d42012-01-23 18:08:171839gfx::Rect TabContents::GetRootWindowResizerRect() const {
1840 if (delegate_)
1841 return delegate_->GetRootWindowResizerRect();
1842 return gfx::Rect();
1843}
1844
[email protected]420ae012009-04-24 05:16:321845void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071846 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271847 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321848 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531849 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231850 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321851 if (!entry)
1852 return;
1853
1854 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351855 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561856 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581857 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321858
1859 if (entry->IsViewSourceMode()) {
1860 // Put the renderer in view source mode.
1861 render_view_host->Send(
1862 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1863 }
[email protected]0666aef2009-05-13 19:48:081864
[email protected]d487beefe2011-12-21 05:41:211865 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261866
1867 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251868 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321869}
1870
1871void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521872 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321873 // Don't notify the world, since this came from a renderer in the
1874 // background.
1875 return;
1876 }
1877
1878 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311879 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231880 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301881
1882 // Restore the focus to the tab (otherwise the focus will be on the top
1883 // window).
[email protected]484ae5912010-09-29 19:16:141884 if (was_crashed && !FocusLocationBarByDefault() &&
1885 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301886 Focus();
[email protected]484ae5912010-09-29 19:16:141887 }
[email protected]32ded2212011-11-10 18:51:431888
[email protected]d8c660432011-12-22 20:51:251889 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321890}
1891
[email protected]443b80e2010-12-14 00:42:231892void TabContents::RenderViewGone(RenderViewHost* rvh,
1893 base::TerminationStatus status,
1894 int error_code) {
[email protected]151a63d2011-12-20 22:32:521895 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321896 // The pending page's RenderViewHost is gone.
1897 return;
1898 }
1899
1900 SetIsLoading(false, NULL);
1901 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231902 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311903 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321904
[email protected]d8c660432011-12-22 20:51:251905 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271906 observers_,
[email protected]be1f56ab2011-12-22 06:55:311907 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321908}
1909
[email protected]2e4633c2009-07-09 16:58:061910void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481911 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251912 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061913}
1914
[email protected]420ae012009-04-24 05:16:321915void TabContents::DidNavigate(RenderViewHost* rvh,
1916 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581917 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321918 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371919
[email protected]434f69f2012-02-06 21:56:521920 // Update the site of the SiteInstance if it doesn't have one yet, unless
1921 // this is for about:blank. In that case, the SiteInstance can still be
1922 // considered unused until a navigation to a real page.
1923 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1924 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331925 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521926 }
[email protected]420ae012009-04-24 05:16:321927
1928 // Need to update MIME type here because it's referred to in
1929 // UpdateNavigationCommands() called by RendererDidNavigate() to
1930 // determine whether or not to enable the encoding menu.
1931 // It's updated only for the main frame. For a subframe,
1932 // RenderView::UpdateURL does not set params.contents_mime_type.
1933 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1934 // TODO(jungshik): Add a test for the encoding menu to avoid
1935 // regressing it again.
[email protected]2905f742011-10-13 03:51:581936 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321937 contents_mime_type_ = params.contents_mime_type;
1938
[email protected]8286f51a2011-05-31 17:39:131939 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001940 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391941
[email protected]a9c0bfe2010-09-17 08:35:221942 // Send notification about committed provisional loads. This notification is
1943 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1944 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081945 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071946 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1947 // that is not recorded in the navigation history. For the purpose of
1948 // tracking navigation events, we treat this event as a sub frame navigation
1949 // event.
1950 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581951 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221952 // Whether or not a page transition was triggered by going backward or
1953 // forward in the history is only stored in the navigation controller's
1954 // entry list.
1955 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511956 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581957 content::PAGE_TRANSITION_FORWARD_BACK)) {
1958 transition_type = content::PageTransitionFromInt(
1959 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221960 }
[email protected]0d60f0192011-04-14 12:40:101961 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251962 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101963 DidCommitProvisionalLoadForFrame(params.frame_id,
1964 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221965 }
1966
[email protected]76543b92009-08-31 17:27:451967 if (!did_navigate)
1968 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321969
1970 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1971 // for the appropriate notification (best) or you can add it to
1972 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1973 // necessary, please).
1974
1975 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001976 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321977 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511978 if (delegate_)
1979 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001980 }
[email protected]420ae012009-04-24 05:16:321981 DidNavigateAnyFramePostCommit(rvh, details, params);
1982}
1983
1984void TabContents::UpdateState(RenderViewHost* rvh,
1985 int32 page_id,
1986 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151987 // Ensure that this state update comes from either the active RVH or one of
1988 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521989 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321990
1991 // We must be prepared to handle state updates for any page, these occur
1992 // when the user is scrolling and entering form data, as well as when we're
1993 // leaving a page, in which case our state may have already been moved to
1994 // the next page. The navigation controller will look up the appropriate
1995 // NavigationEntry and update it when it is notified via the delegate.
1996
1997 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151998 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321999 if (entry_index < 0)
2000 return;
[email protected]10f417c52011-12-28 21:04:232001 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322002
[email protected]36fc0392011-12-25 03:59:512003 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322004 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512005 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322006 controller_.NotifyEntryChanged(entry, entry_index);
2007}
2008
2009void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572010 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462011 const string16& title,
2012 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322013 // If we have a title, that's a pretty good indication that we've started
2014 // getting useful data.
2015 SetNotWaitingForResponse();
2016
[email protected]73eb2602012-02-09 19:50:552017 // Try to find the navigation entry, which might not be the current one.
2018 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232019 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2020 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092021
[email protected]73eb2602012-02-09 19:50:552022 // We can handle title updates when we don't have an entry in
2023 // UpdateTitleForEntry, but only if the update is from the current RVH.
2024 if (!entry && rvh != GetRenderViewHost())
2025 return;
2026
[email protected]a49e10b2011-08-01 23:57:462027 // TODO(evan): make use of title_direction.
2028 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092029 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322030 return;
2031
2032 // Broadcast notifications when the UI should be updated.
2033 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462034 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322035}
2036
[email protected]420ae012009-04-24 05:16:322037void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402038 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312039 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322040}
2041
2042void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512043 if (delegate_)
2044 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322045}
2046
[email protected]420ae012009-04-24 05:16:322047void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292048 // The UI may be in an event-tracking loop, such as between the
2049 // mouse-down and mouse-up in text selection or a button click.
2050 // Defer the close until after tracking is complete, so that we
2051 // don't free objects out from under the UI.
2052 // TODO(shess): This could probably be integrated with the
2053 // IsDoingDrag() test below. Punting for now because I need more
2054 // research to understand how this impacts platforms other than Mac.
2055 // TODO(shess): This could get more fine-grained. For instance,
2056 // closing a tab in another window while selecting text in the
2057 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212058 if (GetView()->IsEventTracking()) {
2059 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292060 return;
2061 }
2062
[email protected]24a4d1062009-07-10 23:10:422063 // If we close the tab while we're in the middle of a drag, we'll crash.
2064 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212065 if (GetView()->IsDoingDrag()) {
2066 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422067 return;
2068 }
2069
[email protected]420ae012009-04-24 05:16:322070 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522071 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512072 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322073}
2074
[email protected]cd9ed79d2011-11-15 19:22:572075void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522076 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512077 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572078}
2079
[email protected]420ae012009-04-24 05:16:322080void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512081 if (delegate_ && delegate_->IsPopupOrPanel(this))
2082 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322083}
2084
[email protected]7ab1e7d62009-10-14 23:32:012085void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322086 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492087
[email protected]6934a702011-12-20 00:04:512088 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212089 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512090 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002091 }
[email protected]3c9e1872010-11-18 16:17:492092
2093 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252094 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322095}
2096
[email protected]7ab1e7d62009-10-14 23:32:012097void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322098 scoped_ptr<LoadNotificationDetails> details;
2099
[email protected]10f417c52011-12-28 21:04:232100 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322101 // An entry may not exist for a stop when loading an initial blank page or
2102 // if an iframe injected by script into a blank page finishes loading.
2103 if (entry) {
[email protected]420ae012009-04-24 05:16:322104 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2105
2106 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512107 entry->GetVirtualURL(),
2108 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322109 elapsed,
2110 &controller_,
2111 controller_.GetCurrentEntryIndex()));
2112 }
2113
[email protected]420ae012009-04-24 05:16:322114 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492115
2116 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252117 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322118}
2119
[email protected]c95fa8b2011-04-28 20:26:162120void TabContents::DidCancelLoading() {
2121 controller_.DiscardNonCommittedEntries();
2122
2123 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462124 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162125}
2126
[email protected]1a3c3cb2010-12-16 21:03:402127void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512128 if (delegate_)
2129 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402130}
2131
[email protected]952a68e2011-11-17 00:36:102132void TabContents::DocumentAvailableInMainFrame(
2133 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252134 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102135 DocumentAvailableInMainFrame());
2136}
2137
[email protected]25497492010-09-11 15:15:082138void TabContents::DocumentOnLoadCompletedInMainFrame(
2139 RenderViewHost* render_view_host,
2140 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072141 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272142 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322143 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532144 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082145}
2146
[email protected]ae5184d62011-10-06 19:25:582147void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152148 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582149 WindowOpenDisposition disposition,
2150 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482151 // Delegate to RequestTransferURL because this is just the generic
2152 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582153 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482154 GlobalRequestID());
2155}
2156
2157void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582158 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482159 WindowOpenDisposition disposition,
2160 int64 source_frame_id,
2161 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202162 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582163 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582164 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352165 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322166 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2167 // generated suggestions).
2168 //
[email protected]e0112912011-02-02 22:54:352169 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162170 // want web sites to see a referrer of "chrome://blah" (and some
2171 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322172 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432173 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222174 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482175 false /* is_renderer_initiated */);
2176 params.transferred_global_request_id = old_request_id;
2177 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222178 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322179 } else {
[email protected]6bf6a6b52012-02-03 15:41:432180 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482181 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2182 params.transferred_global_request_id = old_request_id;
2183 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582184 }
2185 if (new_contents) {
2186 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252187 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582188 DidOpenRequestedURL(new_contents,
2189 url,
2190 referrer,
2191 disposition,
2192 transition_type,
2193 source_frame_id));
[email protected]420ae012009-04-24 05:16:322194 }
2195}
2196
[email protected]420ae012009-04-24 05:16:322197void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342198 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412199 const string16& message,
2200 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322201 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472202 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322203 IPC::Message* reply_msg,
2204 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072205 // Suppress JavaScript dialogs when requested. Also suppress messages when
2206 // showing an interstitial as it's shown over the previous page and we don't
2207 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502208 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152209 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272210 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072211 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522212 delegate_->ShouldSuppressDialogs() ||
2213 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322214
2215 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342216 content::JavaScriptDialogCreator::TitleType title_type;
2217 string16 title;
2218
2219 if (!frame_url.has_host()) {
2220 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2221 } else {
2222 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2223 title = net::FormatUrl(
2224 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202225 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302226 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342227 }
2228
[email protected]2e5b90c2011-08-16 21:11:552229 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522230 dialog_creator_->RunJavaScriptDialog(
2231 this, title_type, title, javascript_message_type, message,
2232 default_prompt,
2233 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2234 reply_msg),
2235 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322236 }
[email protected]3ab9cb82011-06-03 18:02:072237
2238 if (suppress_this_message) {
2239 // If we are suppressing messages, just reply as if the user immediately
2240 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342241 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072242 }
2243
2244 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322245}
2246
[email protected]fedec012012-01-28 03:09:342247void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412248 const string16& message,
[email protected]420ae012009-04-24 05:16:322249 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512250 if (delegate_)
2251 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072252
2253 bool suppress_this_message =
2254 rvh->is_swapped_out() ||
2255 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522256 delegate_->ShouldSuppressDialogs() ||
2257 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152258 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342259 // The reply must be sent to the RVH that sent the request.
2260 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502261 return;
2262 }
[email protected]3ab9cb82011-06-03 18:02:072263
[email protected]7ab1e7d62009-10-14 23:32:012264 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552265 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522266 dialog_creator_->RunBeforeUnloadDialog(
2267 this, message,
2268 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2269 reply_msg));
[email protected]420ae012009-04-24 05:16:322270}
2271
[email protected]420ae012009-04-24 05:16:322272WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542273 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322274}
2275
[email protected]7d472472011-01-22 01:30:252276void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272277 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252278 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222279
[email protected]99907362012-01-11 05:41:402280 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172281 if (rdh) // NULL in unittests.
2282 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252283}
2284
[email protected]fa1cf0b82010-01-15 21:49:442285void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442286 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252287 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442288}
2289
[email protected]420ae012009-04-24 05:16:322290void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2291 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152292 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522293 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152294 return;
2295
[email protected]e5fc1632011-08-08 07:51:532296 // Ignore renderer unresponsive event if debugger is attached to the tab
2297 // since the event may be a result of the renderer sitting on a breakpoint.
2298 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442299 DevToolsAgentHost* agent =
2300 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2301 if (agent &&
2302 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532303 return;
2304
[email protected]420ae012009-04-24 05:16:322305 if (is_during_unload) {
2306 // Hang occurred while firing the beforeunload/unload handler.
2307 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112308 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322309
2310 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2311 return;
2312
2313 // If the tab hangs in the beforeunload/unload handler there's really
2314 // nothing we can do to recover. Pretend the unload listeners have
2315 // all fired and close the tab. If the hang is in the beforeunload handler
2316 // then the user will not have the option of cancelling the close.
2317 Close(rvh);
2318 return;
2319 }
2320
[email protected]151a63d2011-12-20 22:32:522321 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472322 return;
2323
[email protected]6934a702011-12-20 00:04:512324 if (delegate_)
2325 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322326}
2327
2328void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512329 if (delegate_)
2330 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322331}
2332
2333void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212334 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562335 uint64 upload_position,
2336 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322337 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562338 upload_position_ = upload_position;
2339 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502340 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202341 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302342 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212343 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322344 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462345 if (IsLoading()) {
2346 NotifyNavigationStateChanged(
2347 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2348 }
[email protected]420ae012009-04-24 05:16:322349}
2350
[email protected]7d472472011-01-22 01:30:252351void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512352 if (delegate_)
2353 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252354}
2355
[email protected]420ae012009-04-24 05:16:322356void TabContents::BeforeUnloadFiredFromRenderManager(
2357 bool proceed,
2358 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512359 if (delegate_)
2360 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322361}
2362
[email protected]3a3d47472010-07-15 21:03:542363void TabContents::DidStartLoadingFromRenderManager(
2364 RenderViewHost* render_view_host) {
2365 DidStartLoading();
2366}
2367
2368void TabContents::RenderViewGoneFromRenderManager(
2369 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232370 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2371 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542372}
2373
[email protected]420ae012009-04-24 05:16:322374void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102375 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262376 gfx::Size size = view_->GetContainerSize();
2377 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2378 // here during container initialization and normal window size will be set
2379 // later. In case of tab duplication this resizing to 0x0 prevents setting
2380 // normal size later so just ignore it.
2381 if (!size.IsEmpty())
2382 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322383}
2384
[email protected]3a3d47472010-07-15 21:03:542385void TabContents::NotifySwappedFromRenderManager() {
2386 NotifySwapped();
2387}
2388
[email protected]d202a7c2012-01-04 07:53:472389NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202390 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542391}
2392
[email protected]d2353452012-01-19 19:53:562393WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2394 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322395}
2396
[email protected]10f417c52011-12-28 21:04:232397NavigationEntry*
2398 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322399 return controller_.GetLastCommittedEntry();
2400}
2401
2402bool TabContents::CreateRenderViewForRenderManager(
2403 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442404 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322405 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522406
[email protected]420ae012009-04-24 05:16:322407 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442408 if (rwh_view)
2409 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322410
[email protected]74ce1ad2011-12-16 21:51:462411 // Make sure we use the correct starting page_id in the new RenderView.
2412 UpdateMaxPageIDIfNecessary(render_view_host);
2413 int32 max_page_id =
2414 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2415
2416 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522417 return false;
2418
[email protected]e60c0232011-11-11 19:56:352419#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502420 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2421 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442422 if (rwh_view) {
2423 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2424 render_widget_host->WasResized();
2425 }
[email protected]f8233cc2011-05-31 20:24:502426#endif
2427
[email protected]420ae012009-04-24 05:16:322428 return true;
2429}
2430
[email protected]fedec012012-01-28 03:09:342431void TabContents::OnDialogClosed(RenderViewHost* rvh,
2432 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072433 bool success,
2434 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542435 if (is_showing_before_unload_dialog_ && !success) {
2436 // If a beforeunload dialog is canceled, we need to stop the throbber from
2437 // spinning, since we forced it to start spinning in Navigate.
2438 DidStopLoading();
2439
2440 tab_close_start_time_ = base::TimeTicks();
2441 }
2442 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342443 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542444}
2445
[email protected]be1f56ab2011-12-22 06:55:312446void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122447 encoding_ = content::GetContentClient()->browser()->
2448 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102449}
[email protected]f45d2a72010-03-08 23:28:352450
[email protected]e30d68d2012-02-09 00:06:262451void TabContents::SaveURL(const GURL& url,
2452 const GURL& referrer,
2453 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142454 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2455 if (!dlm)
2456 return;
2457 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262458 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142459 const NavigationEntry* entry = controller_.GetActiveEntry();
2460 if (entry)
2461 post_id = entry->GetPostID();
2462 }
2463 DownloadSaveInfo save_info;
2464 save_info.prompt_for_save_location = true;
2465 dlm->DownloadUrl(url,
2466 referrer,
2467 "",
2468 true, // prefer_cache
2469 post_id,
2470 save_info,
2471 this);
2472}
2473
[email protected]33f74972010-12-08 16:40:362474void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212475 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442476 // Can be NULL during tests.
2477 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212478 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362479}