blob: 04401495f831631627436fe0faf10027d85e715b [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]567812d2011-02-24 17:40:5016#include "content/browser/child_process_security_policy.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]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4644#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1545#include "content/public/browser/javascript_dialogs.h"
[email protected]5b96836f2011-12-22 07:39:0046#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4847#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3848#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4249#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2550#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1051#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5052#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2153#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1855#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5456#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0357#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1658#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2959#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5460#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3461#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3762#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3863#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2464#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3165#include "webkit/glue/webpreferences.h"
66
67#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1268#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3169#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0070
[email protected]420ae012009-04-24 05:16:3271// Cross-Site Navigations
72//
73// If a TabContents is told to navigate to a different web site (as determined
74// by SiteInstance), it will replace its current RenderViewHost with a new
75// RenderViewHost dedicated to the new SiteInstance. This works as follows:
76//
77// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4678// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3279// - The pending RVH is "suspended," so that no navigation messages are sent to
80// its renderer until the onbeforeunload JavaScript handler has a chance to
81// run in the current RVH.
82// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
83// that it has a pending cross-site request. ResourceDispatcherHost will
84// check for this when the response arrives.
85// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4686// cancel all the pending logic. Otherwise we allow the pending RVH to send
87// the navigation request to its renderer.
88// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
89// main resource load on the pending RVH. It checks CrossSiteRequestManager
90// to see that it is a cross-site request, and installs a
91// CrossSiteResourceHandler.
92// - When RDH receives a response, the BufferedResourceHandler determines
93// whether it is a download. If so, it sends a message to the new renderer
94// causing it to cancel the request, and the download proceeds. For now, the
95// pending RVH remains until the next DidNavigate event for this TabContents.
96// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3297// - After RDH receives a response and determines that it is safe and not a
98// download, it pauses the response to first run the old page's onunload
99// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15100// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32101// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15102// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32103// the ResourceDispatcherHost, who unpauses the response. Data is then sent
104// to the pending RVH.
105// - The pending renderer sends a FrameNavigate message that invokes the
106// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46107// pending RVH.
[email protected]992db4c2011-05-12 15:37:15108// - The previous renderer is kept swapped out in RenderViewHostManager in case
109// the user goes back. The process only stays live if another tab is using
110// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32111
[email protected]0e12d7d2011-12-01 16:21:44112using content::DevToolsAgentHost;
113using content::DevToolsAgentHostRegistry;
114using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17115using content::DownloadItem;
116using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20117using content::GlobalRequestID;
[email protected]cadaec52012-02-08 21:53:13118using content::InterstitialPage;
[email protected]c5eed492012-01-04 17:07:50119using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23120using content::NavigationEntry;
121using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20122using content::OpenURLParams;
[email protected]b0b67cf2012-01-18 21:59:57123using content::RenderViewHostDelegate;
[email protected]b6583592012-01-25 19:52:33124using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17125using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38126using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09127using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25128using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56129using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22130using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50131using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44132
[email protected]420ae012009-04-24 05:16:32133namespace {
134
135// Amount of time we wait between when a key event is received and the renderer
136// is queried for its state and pushed to the NavigationEntry.
137const int kQueryStateDelay = 5000;
138
[email protected]6ebdc9b2010-09-27 16:55:57139const int kSyncWaitDelay = 40;
140
[email protected]ca406032011-07-19 21:53:05141static const char kDotGoogleDotCom[] = ".google.com";
142
[email protected]420ae012009-04-24 05:16:32143#if defined(OS_WIN)
144
145BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
146 // Note: erase is required to properly paint some widgets borders. This can
147 // be seen with textfields.
148 InvalidateRect(hwnd, NULL, TRUE);
149 return TRUE;
150}
151#endif
152
[email protected]2c5569662011-03-22 20:45:02153ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23154 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50155 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16156 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47157 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02158 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47159 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02160 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47161 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16162 break; // Fall through to rest of function.
163 }
[email protected]5e369672009-11-03 23:48:30164
[email protected]10f417c52011-12-28 21:04:23165 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37166 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02167 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30168
[email protected]2c5569662011-03-22 20:45:02169 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30170}
171
[email protected]10f417c52011-12-28 21:04:23172void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47173 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42174 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50175 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16176 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51177 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54178 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55179 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
180 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51181 params->url = entry.GetURL();
182 params->referrer = entry.GetReferrer();
183 params->transition = entry.GetTransitionType();
184 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00185 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55186 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34187 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47188 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48189 params->transferred_request_child_id =
190 entry.transferred_global_request_id().child_id;
191 params->transferred_request_request_id =
192 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47193
194 if (delegate)
195 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34196}
197
[email protected]420ae012009-04-24 05:16:32198} // namespace
199
[email protected]a81343d232011-12-27 07:39:20200namespace content {
201
202WebContents* WebContents::Create(
203 BrowserContext* browser_context,
204 SiteInstance* site_instance,
205 int routing_id,
206 const WebContents* base_tab_contents,
207 SessionStorageNamespace* session_storage_namespace) {
208 return new TabContents(browser_context,
209 site_instance,
210 routing_id,
211 static_cast<const TabContents*>(base_tab_contents),
212 session_storage_namespace);
213}
214}
[email protected]f4f50ef2011-01-21 19:01:19215
216// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32217
[email protected]3d7474ff2011-07-27 17:47:37218TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32219 SiteInstance* site_instance,
220 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07221 const TabContents* base_tab_contents,
222 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42223 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07224 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37225 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13226 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]8643e6d2012-01-18 20:26:10227 content::GetContentClient()->browser()->CreateWebContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22228 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34229 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23230 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
231 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34232 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21233 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56234 upload_size_(0),
235 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47236 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57237 capturing_contents_(false),
238 is_being_destroyed_(false),
239 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55240 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57241#if defined(OS_WIN)
242 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
243#endif
[email protected]7ab1e7d62009-10-14 23:32:01244 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56245 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38246 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25247 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01248 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25249 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01250 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00251 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43252 content_restrictions_(0),
253 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37254 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32255
[email protected]34ac70502009-09-25 17:07:23256 // We have the initial size of the view be based on the size of the passed in
257 // tab contents (normally a tab from the same window).
258 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21259 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00260
261#if defined(ENABLE_JAVA_BRIDGE)
262 java_bridge_dispatcher_host_manager_.reset(
263 new JavaBridgeDispatcherHostManager(this));
264#endif
[email protected]332af7732009-03-11 13:21:35265}
initial.commit09911bf2008-07-26 23:55:29266
267TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32268 is_being_destroyed_ = true;
269
[email protected]3ab9cb82011-06-03 18:02:07270 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55271 if (dialog_creator_)
272 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07273
[email protected]420ae012009-04-24 05:16:32274 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32275
[email protected]420ae012009-04-24 05:16:32276 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07277 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09278 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
279 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07280 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32281
282 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07283#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32284 // If we still have a window handle, destroy it. GetNativeView can return
285 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42286 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52287 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44288 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42289 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42290 }
[email protected]420ae012009-04-24 05:16:32291#endif
[email protected]7ab1e7d62009-10-14 23:32:01292
293 // OnCloseStarted isn't called in unit tests.
294 if (!tab_close_start_time_.is_null()) {
295 UMA_HISTOGRAM_TIMES("Tab.Close",
296 base::TimeTicks::Now() - tab_close_start_time_);
297 }
[email protected]b5a1d11c2011-02-17 03:09:42298
[email protected]d8c660432011-12-22 20:51:25299 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08300
[email protected]6934a702011-12-20 00:04:51301 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42302}
303
[email protected]64d69de42012-02-06 00:19:54304WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
305 const GURL& url) {
306 WebPreferences prefs;
307
308 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
309
310 prefs.developer_extras_enabled = true;
311 prefs.javascript_enabled =
312 !command_line.HasSwitch(switches::kDisableJavaScript);
313 prefs.web_security_enabled =
314 !command_line.HasSwitch(switches::kDisableWebSecurity);
315 prefs.plugins_enabled =
316 !command_line.HasSwitch(switches::kDisablePlugins);
317 prefs.java_enabled =
318 !command_line.HasSwitch(switches::kDisableJava);
319
320 prefs.uses_page_cache =
321 command_line.HasSwitch(switches::kEnableFastback);
322 prefs.remote_fonts_enabled =
323 !command_line.HasSwitch(switches::kDisableRemoteFonts);
324 prefs.xss_auditor_enabled =
325 !command_line.HasSwitch(switches::kDisableXSSAuditor);
326 prefs.application_cache_enabled =
327 !command_line.HasSwitch(switches::kDisableApplicationCache);
328
329 prefs.local_storage_enabled =
330 !command_line.HasSwitch(switches::kDisableLocalStorage);
331 prefs.databases_enabled =
332 !command_line.HasSwitch(switches::kDisableDatabases);
333 prefs.webaudio_enabled =
334 !command_line.HasSwitch(switches::kDisableWebAudio);
335
336 prefs.experimental_webgl_enabled =
337 GpuProcessHost::gpu_enabled() &&
338 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
339 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
340
341 prefs.gl_multisampling_enabled =
342 !command_line.HasSwitch(switches::kDisableGLMultisampling);
343 prefs.privileged_webgl_extensions_enabled =
344 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
345 prefs.site_specific_quirks_enabled =
346 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
347 prefs.allow_file_access_from_file_urls =
348 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
349 prefs.show_composited_layer_borders =
350 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
351 prefs.show_composited_layer_tree =
352 command_line.HasSwitch(switches::kShowCompositedLayerTree);
353 prefs.show_fps_counter =
354 command_line.HasSwitch(switches::kShowFPSCounter);
355 prefs.accelerated_compositing_enabled =
356 GpuProcessHost::gpu_enabled() &&
357 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
358 prefs.threaded_compositing_enabled =
359 command_line.HasSwitch(switches::kEnableThreadedCompositing);
360 prefs.force_compositing_mode =
361 command_line.HasSwitch(switches::kForceCompositingMode);
362 prefs.fixed_position_compositing_enabled =
363 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
364 prefs.accelerated_2d_canvas_enabled =
365 GpuProcessHost::gpu_enabled() &&
366 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58367 prefs.deferred_2d_canvas_enabled =
368 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]64d69de42012-02-06 00:19:54369 prefs.accelerated_painting_enabled =
370 GpuProcessHost::gpu_enabled() &&
371 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
372 prefs.accelerated_filters_enabled =
373 GpuProcessHost::gpu_enabled() &&
374 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
375 prefs.accelerated_layers_enabled =
376 prefs.accelerated_animation_enabled =
377 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
378 prefs.composite_to_texture_enabled =
379 command_line.HasSwitch(switches::kEnableCompositeToTexture);
380 prefs.accelerated_plugins_enabled =
381 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
382 prefs.accelerated_video_enabled =
383 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
384 prefs.partial_swap_enabled =
385 command_line.HasSwitch(switches::kEnablePartialSwap);
386 prefs.interactive_form_validation_enabled =
387 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
388 prefs.fullscreen_enabled =
389 !command_line.HasSwitch(switches::kDisableFullScreen);
390
391#if defined(OS_MACOSX)
392 bool default_enable_scroll_animator = true;
393#else
394 // On CrOS, the launcher always passes in the --enable flag.
395 bool default_enable_scroll_animator = false;
396#endif
397 prefs.enable_scroll_animator = default_enable_scroll_animator;
398 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
399 prefs.enable_scroll_animator = true;
400 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
401 prefs.enable_scroll_animator = false;
402
403 prefs.visual_word_movement_enabled =
404 command_line.HasSwitch(switches::kEnableVisualWordMovement);
405 prefs.per_tile_painting_enabled =
406 command_line.HasSwitch(switches::kEnablePerTilePainting);
407
408 { // Certain GPU features might have been blacklisted.
409 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
410 DCHECK(gpu_data_manager);
411 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
412 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
413 prefs.accelerated_compositing_enabled = false;
414 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
415 prefs.experimental_webgl_enabled = false;
416 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
417 prefs.accelerated_2d_canvas_enabled = false;
418 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
419 prefs.gl_multisampling_enabled = false;
420
421 // Accelerated video and animation are slower than regular when using a
422 // software 3d rasterizer.
423 if (gpu_data_manager->software_rendering()) {
424 prefs.accelerated_video_enabled = false;
425 prefs.accelerated_animation_enabled = false;
426 }
427 }
428
429 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
430 rvh->process()->GetID())) {
431 prefs.loads_images_automatically = true;
432 prefs.javascript_enabled = true;
433 }
434
435 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
436
437 // Force accelerated compositing and 2d canvas off for chrome:, about: and
438 // chrome-devtools: pages (unless it's specifically allowed).
439 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
440 // Allow accelerated compositing for keyboard and log in screen.
441 url.SchemeIs(chrome::kChromeUIScheme) ||
442 (url.SchemeIs(chrome::kAboutScheme) &&
443 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25444 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54445 prefs.accelerated_compositing_enabled = false;
446 prefs.accelerated_2d_canvas_enabled = false;
447 }
448
449 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, &prefs);
450
451 return prefs;
452}
453
[email protected]d202a7c2012-01-04 07:53:47454NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20455 return controller_;
456}
457
[email protected]765187182012-01-11 23:59:28458RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
459 return &render_manager_;
460}
461
[email protected]724159a2010-12-30 01:11:18462bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56463 if (GetWebUI() &&
464 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17465 return true;
[email protected]d2353452012-01-19 19:53:56466 }
[email protected]f82d57b52011-04-27 19:13:17467
[email protected]d8c660432011-12-22 20:51:25468 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
469 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10470 while ((observer = it.GetNext()) != NULL)
471 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53472 return true;
[email protected]403415a2011-01-10 18:57:53473
[email protected]724159a2010-12-30 01:11:18474 bool handled = true;
475 bool message_is_ok = true;
476 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58477 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
478 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24479 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
480 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18481 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
482 OnDidStartProvisionalLoadForFrame)
483 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
484 OnDidRedirectProvisionalLoad)
485 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
486 OnDidFailProvisionalLoadWithError)
487 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
488 OnDidLoadResourceFromMemoryCache)
489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
490 OnDidDisplayInsecureContent)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
492 OnDidRunInsecureContent)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
494 OnDocumentLoadedInFrame)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17496 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
497 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25498 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26499 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59500 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21501 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20502 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
503 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
504 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16505 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45506 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10507 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18508 IPC_MESSAGE_UNHANDLED(handled = false)
509 IPC_END_MESSAGE_MAP_EX()
510
511 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38512 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18513 GetRenderProcessHost()->ReceivedBadMessage();
514 }
515
516 return handled;
517}
518
[email protected]6c2e472f2011-08-24 23:26:18519void TabContents::RunFileChooser(
520 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23521 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51522 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18523}
524
[email protected]c5eed492012-01-04 17:07:50525NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56526 return controller_;
527}
528
[email protected]c5eed492012-01-04 17:07:50529const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56530 return controller_;
531}
532
[email protected]627e0512011-12-21 22:55:30533content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55534 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30535}
536
[email protected]f5fa20e2011-12-21 22:35:56537void TabContents::SetViewType(content::ViewType type) {
538 view_type_ = type;
539}
540
[email protected]ea049a02011-12-25 21:37:09541content::ViewType TabContents::GetViewType() const {
542 return view_type_;
543}
544
[email protected]be1f56ab2011-12-22 06:55:31545const GURL& TabContents::GetURL() const {
546 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23547 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51548 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31549}
550
551
552const base::PropertyBag* TabContents::GetPropertyBag() const {
553 return &property_bag_;
554}
555
556base::PropertyBag* TabContents::GetPropertyBag() {
557 return &property_bag_;
558}
559
560content::WebContentsDelegate* TabContents::GetDelegate() {
561 return delegate_;
562}
563
564void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
565 // TODO(cbentzel): remove this debugging code?
566 if (delegate == delegate_)
567 return;
568 if (delegate_)
569 delegate_->Detach(this);
570 delegate_ = delegate;
571 if (delegate_)
572 delegate_->Attach(this);
573}
574
[email protected]f3b1a082011-11-18 00:34:30575content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03576 if (render_manager_.current_host())
577 return render_manager_.current_host()->process();
578 else
579 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16580}
581
[email protected]be1f56ab2011-12-22 06:55:31582RenderViewHost* TabContents::GetRenderViewHost() const {
583 return render_manager_.current_host();
584}
585
586RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
587 return render_manager_.GetRenderWidgetHostView();
588}
589
[email protected]8643e6d2012-01-18 20:26:10590content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31591 return view_.get();
592}
593
[email protected]01ec4ec2012-01-18 04:13:47594content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50595 WebUIControllerFactory* factory =
596 content::GetContentClient()->browser()->GetWebUIControllerFactory();
597 if (!factory)
598 return NULL;
[email protected]d2353452012-01-19 19:53:56599 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22600 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50601 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22602 if (controller) {
603 web_ui->SetController(controller);
604 return web_ui;
605 }
606
607 delete web_ui;
608 return NULL;
609}
610
[email protected]01ec4ec2012-01-18 04:13:47611content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31612 return render_manager_.web_ui() ? render_manager_.web_ui()
613 : render_manager_.pending_web_ui();
614}
615
[email protected]01ec4ec2012-01-18 04:13:47616content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31617 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34618}
619
[email protected]96d185d2009-04-24 03:28:54620const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55621 // Transient entries take precedence. They are used for interstitial pages
622 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23623 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08624 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20625 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30626 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23627 if (entry) {
[email protected]b5cca982011-05-26 04:42:08628 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23629 }
[email protected]7ade2732011-02-10 00:13:58630 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
631 render_manager_.pending_web_ui() : render_manager_.web_ui();
632 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54633 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55634 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54635 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35636 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22637 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54638 if (!title.empty())
639 return title;
640 }
641 }
642
643 // We use the title for the last committed entry rather than a pending
644 // navigation entry. For example, when the user types in a URL, we want to
645 // keep the old page's title until the new load has committed and we get a new
646 // title.
[email protected]96d185d2009-04-24 03:28:54647 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23648 if (entry) {
[email protected]b5cca982011-05-26 04:42:08649 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23650 }
[email protected]987fc3a2011-05-26 14:18:09651
652 // |page_title_when_no_navigation_entry_| is finally used
653 // if no title cannot be retrieved.
654 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54655}
656
[email protected]d5f942ba2008-09-26 19:30:34657int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46658 return GetMaxPageIDForSiteInstance(GetSiteInstance());
659}
660
661int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33662 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
663 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46664
[email protected]b6583592012-01-25 19:52:33665 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34666}
667
668void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46669 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
670}
671
[email protected]b6583592012-01-25 19:52:33672void TabContents::UpdateMaxPageIDForSiteInstance(
673 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46674 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33675 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34676}
677
[email protected]91854cd2012-01-10 19:43:57678void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
679 max_page_ids_ = tab_contents->max_page_ids_;
680}
681
[email protected]96d185d2009-04-24 03:28:54682SiteInstance* TabContents::GetSiteInstance() const {
683 return render_manager_.current_host()->site_instance();
684}
685
[email protected]77362eb2011-08-01 17:18:38686SiteInstance* TabContents::GetPendingSiteInstance() const {
687 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
688 render_manager_.pending_render_view_host() :
689 render_manager_.current_host();
690 return dest_rvh->site_instance();
691}
692
[email protected]be1f56ab2011-12-22 06:55:31693bool TabContents::IsLoading() const {
694 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49695}
696
[email protected]be1f56ab2011-12-22 06:55:31697bool TabContents::IsWaitingForResponse() const {
698 return waiting_for_response_;
699}
700
701const net::LoadStateWithParam& TabContents::GetLoadState() const {
702 return load_state_;
703}
704
705const string16& TabContents::GetLoadStateHost() const {
706 return load_state_host_;
707}
708
709uint64 TabContents::GetUploadSize() const {
710 return upload_size_;
711}
712
713uint64 TabContents::GetUploadPosition() const {
714 return upload_position_;
715}
716
717const std::string& TabContents::GetEncoding() const {
718 return encoding_;
719}
720
721bool TabContents::DisplayedInsecureContent() const {
722 return displayed_insecure_content_;
723}
724
725void TabContents::SetCapturingContents(bool cap) {
726 capturing_contents_ = cap;
727}
728
729bool TabContents::IsCrashed() const {
730 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
731 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
732 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49733}
734
[email protected]443b80e2010-12-14 00:42:23735void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
736 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34737 return;
738
[email protected]443b80e2010-12-14 00:42:23739 crashed_status_ = status;
740 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46741 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34742}
743
[email protected]be1f56ab2011-12-22 06:55:31744base::TerminationStatus TabContents::GetCrashedStatus() const {
745 return crashed_status_;
746}
747
748bool TabContents::IsBeingDestroyed() const {
749 return is_being_destroyed_;
750}
751
[email protected]d5f942ba2008-09-26 19:30:34752void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
753 if (delegate_)
754 delegate_->NavigationStateChanged(this, changed_flags);
755}
756
[email protected]96d185d2009-04-24 03:28:54757void TabContents::DidBecomeSelected() {
758 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16759 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
760 if (rwhv) {
761 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43762#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16763 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43764#endif
765 }
[email protected]96d185d2009-04-24 03:28:54766
[email protected]5ac20162010-11-24 23:33:11767 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38768
[email protected]d8c660432011-12-22 20:51:25769 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54770}
771
[email protected]be1f56ab2011-12-22 06:55:31772
773base::TimeTicks TabContents::GetLastSelectedTime() const {
774 return last_selected_time_;
775}
776
[email protected]96d185d2009-04-24 03:28:54777void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31778 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52779 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
780 // open a tab in then background, then closes the tab before selecting it.
781 // This is because closing the tab calls TabContents::Destroy(), which
782 // removes the |GetRenderViewHost()|; then when we actually destroy the
783 // window, OnWindowPosChanged() notices and calls HideContents() (which
784 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16785 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
786 if (rwhv)
787 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54788 }
789
[email protected]ad50def52011-10-19 23:17:07790 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09791 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
792 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07793 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54794}
795
[email protected]be1f56ab2011-12-22 06:55:31796void TabContents::ShowContents() {
797 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
798 if (rwhv)
799 rwhv->DidBecomeSelected();
800}
801
802void TabContents::HideContents() {
803 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
804 // our superclass HideContents(), because some callers want to be very picky
805 // about the order in which these get called. In addition to making the code
806 // here practically impossible to understand, this also means we end up
807 // calling TabContents::WasHidden() twice if callers call both versions of
808 // HideContents() on a TabContents.
809 WasHidden();
810}
811
812bool TabContents::NeedToFireBeforeUnload() {
813 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27814 return WillNotifyDisconnection() &&
815 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31816 !GetRenderViewHost()->SuddenTerminationAllowed();
817}
818
[email protected]0bfbf882011-12-22 18:19:27819void TabContents::Stop() {
820 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25821 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27822}
823
[email protected]d9083482012-01-06 00:38:46824WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27825 // We create a new SiteInstance so that the new tab won't share processes
826 // with the old one. This can be changed in the future if we need it to share
827 // processes for some reason.
828 TabContents* tc = new TabContents(
829 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33830 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27831 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20832 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27833 return tc;
834}
835
836void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17837 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27838 bool show_history) {
839 if (!delegate_)
840 return;
841
842 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
843}
844
[email protected]2a6bc3e2011-12-28 23:51:33845void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27846 WindowOpenDisposition disposition,
847 const gfx::Rect& initial_pos,
848 bool user_gesture) {
849 if (!delegate_)
850 return;
851
852 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
853 user_gesture);
854}
855
856gfx::NativeView TabContents::GetContentNativeView() const {
857 return view_->GetContentNativeView();
858}
859
860gfx::NativeView TabContents::GetNativeView() const {
861 return view_->GetNativeView();
862}
863
864void TabContents::GetContainerBounds(gfx::Rect* out) const {
865 view_->GetContainerBounds(out);
866}
867
868void TabContents::Focus() {
869 view_->Focus();
870}
871
[email protected]d8c660432011-12-22 20:51:25872void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31873 observers_.AddObserver(observer);
874}
875
[email protected]d8c660432011-12-22 20:51:25876void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31877 observers_.RemoveObserver(observer);
878}
879
[email protected]d5f942ba2008-09-26 19:30:34880void TabContents::Activate() {
881 if (delegate_)
882 delegate_->ActivateContents(this);
883}
884
[email protected]ea42e7782010-08-23 23:58:12885void TabContents::Deactivate() {
886 if (delegate_)
887 delegate_->DeactivateContents(this);
888}
889
[email protected]63954792011-07-11 04:17:48890void TabContents::LostCapture() {
891 if (delegate_)
892 delegate_->LostCapture();
893}
894
895bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
896 bool* is_keyboard_shortcut) {
897 return delegate_ &&
898 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
899}
900
901void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
902 if (delegate_)
903 delegate_->HandleKeyboardEvent(event);
904}
905
[email protected]32ded2212011-11-10 18:51:43906void TabContents::HandleMouseDown() {
907 if (delegate_)
908 delegate_->HandleMouseDown();
909}
910
[email protected]63954792011-07-11 04:17:48911void TabContents::HandleMouseUp() {
912 if (delegate_)
913 delegate_->HandleMouseUp();
914}
915
916void TabContents::HandleMouseActivate() {
917 if (delegate_)
918 delegate_->HandleMouseActivate();
919}
920
[email protected]8a5e0ca2011-08-25 06:30:47921void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
922 if (delegate_)
923 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
924}
925
[email protected]5d5f7af2011-10-01 01:38:12926bool TabContents::IsFullscreenForCurrentTab() const {
927 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
928}
929
[email protected]e9621112011-10-17 05:38:37930void TabContents::RequestToLockMouse() {
931 if (delegate_) {
932 delegate_->RequestToLockMouse(this);
933 } else {
934 GotResponseToLockMouseRequest(false);
935 }
936}
937
938void TabContents::LostMouseLock() {
939 if (delegate_)
940 delegate_->LostMouseLock();
941}
942
[email protected]0548c5352011-09-07 00:33:33943void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:23944 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33945 if (delegate_)
946 delegate_->UpdatePreferredSize(this, pref_size);
947}
948
[email protected]32ded2212011-11-10 18:51:43949void TabContents::WebUISend(RenderViewHost* render_view_host,
950 const GURL& source_url,
951 const std::string& name,
952 const base::ListValue& args) {
953 if (delegate_)
954 delegate_->WebUISend(this, source_url, name, args);
955}
956
[email protected]e5d549d2011-12-28 01:29:20957WebContents* TabContents::OpenURL(const OpenURLParams& params) {
958 if (!delegate_)
959 return NULL;
[email protected]00c37fc2011-08-02 00:22:50960
[email protected]e5d549d2011-12-28 01:29:20961 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
962 // Notify observers.
963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
964 DidOpenURL(params.url, params.referrer,
965 params.disposition, params.transition));
966 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34967}
968
[email protected]1ccb3568d2010-02-19 10:51:16969bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50970 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25971 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23972 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25973 reload_type);
[email protected]876bc832010-09-07 16:29:54974}
[email protected]96d185d2009-04-24 03:28:54975
[email protected]876bc832010-09-07 16:29:54976bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23977 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50978 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40979 // The renderer will reject IPC messages with URLs longer than
980 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51981 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40982 return false;
983
[email protected]dd11de52011-11-03 22:54:27984 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40985 if (!dest_render_view_host)
986 return false; // Unable to create the desired render view host.
987
[email protected]80a8fad2011-01-29 04:02:38988 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07989 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58990 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]863f70a2012-01-27 02:05:50991 WebUIControllerFactory* factory =
992 content::GetContentClient()->browser()->GetWebUIControllerFactory();
993 bool is_allowed_in_web_ui_renderer =
994 factory &&
995 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43996#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51997 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43998#endif
[email protected]e091df82011-10-11 18:13:21999 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551000 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581001
[email protected]96d185d2009-04-24 03:28:541002 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441003 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521004 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441005 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511006 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541007
1008 // Used for page load time metrics.
1009 current_load_start_ = base::TimeTicks::Now();
1010
1011 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341012 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271013 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471014 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341015 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541016
[email protected]36fc0392011-12-25 03:59:511017 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541018 // HACK!! This code suppresses javascript: URLs from being added to
1019 // session history, which is what we want to do for javascript: URLs that
1020 // do not generate content. What we really need is a message from the
1021 // renderer telling us that a new page was not created. The same message
1022 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511023 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541024 return false;
1025 }
1026
[email protected]3c9e1872010-11-18 16:17:491027 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251028 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041029 observers_,
[email protected]36fc0392011-12-25 03:59:511030 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541031
[email protected]09b29342011-06-24 19:18:481032 if (delegate_)
1033 delegate_->DidNavigateToPendingEntry(this);
1034
[email protected]d5f942ba2008-09-26 19:30:341035 return true;
1036}
1037
[email protected]b6583592012-01-25 19:52:331038void TabContents::SetHistoryLengthAndPrune(
1039 const SiteInstance* site_instance,
1040 int history_length,
1041 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411042 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1043 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191044 if (render_manager_.pending_render_view_host()) {
1045 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141046 return;
[email protected]9e1ad4b2011-08-14 16:49:191047 }
[email protected]151a63d2011-12-20 22:32:521048 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:191049 if (!rvh) {
1050 NOTREACHED();
1051 return;
1052 }
1053 if (site_instance && rvh->site_instance() != site_instance) {
1054 NOTREACHED();
1055 return;
1056 }
1057 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
1058 history_length,
1059 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141060}
1061
[email protected]90daadb42009-06-08 21:27:281062void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271063 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541064 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1065 return;
1066 }
[email protected]151a63d2011-12-20 22:32:521067 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541068}
1069
[email protected]0bfbf882011-12-22 18:19:271070bool TabContents::ShowingInterstitialPage() const {
1071 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541072}
1073
[email protected]0bfbf882011-12-22 18:19:271074InterstitialPage* TabContents::GetInterstitialPage() const {
1075 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221076}
1077
[email protected]a53209b2012-01-20 16:48:161078bool TabContents::IsSavable() {
1079 // WebKit creates Document object when MIME type is application/xhtml+xml,
1080 // so we also support this MIME type.
1081 return contents_mime_type_ == "text/html" ||
1082 contents_mime_type_ == "text/xml" ||
1083 contents_mime_type_ == "application/xhtml+xml" ||
1084 contents_mime_type_ == "text/plain" ||
1085 contents_mime_type_ == "text/css" ||
1086 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1087}
1088
[email protected]c7dd2f62011-07-18 15:57:591089void TabContents::OnSavePage() {
1090 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161091 if (!IsSavable()) {
[email protected]e30d68d2012-02-09 00:06:261092 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141093 download_stats::RecordDownloadCount(
1094 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
1095 return;
[email protected]c7dd2f62011-07-18 15:57:591096 }
1097
1098 Stop();
1099
1100 // Create the save package and possibly prompt the user for the name to save
1101 // the page as. The user prompt is an asynchronous operation that runs on
1102 // another thread.
1103 save_package_ = new SavePackage(this);
1104 save_package_->GetSaveInfo();
1105}
1106
1107// Used in automated testing to bypass prompting the user for file names.
1108// Instead, the names and paths are hard coded rather than running them through
1109// file name sanitation and extension / mime checking.
1110bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161111 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591112 // Stop the page from navigating.
1113 Stop();
1114
1115 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1116 return save_package_->Init();
1117}
1118
[email protected]420ae012009-04-24 05:16:321119bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231120 NavigationEntryImpl* active_entry =
1121 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321122 return (active_entry != NULL &&
1123 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511124 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321125}
1126
[email protected]0bfbf882011-12-22 18:19:271127const std::string& TabContents::GetContentsMimeType() const {
1128 return contents_mime_type_;
1129}
1130
1131bool TabContents::WillNotifyDisconnection() const {
1132 return notify_disconnection_;
1133}
1134
[email protected]b2fe07d12010-02-09 14:38:081135void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311136 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:521137 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
1138 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161139}
1140
[email protected]b2fe07d12010-02-09 14:38:081141void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311142 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:521143 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
1144 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:161145}
1146
[email protected]0bfbf882011-12-22 18:19:271147content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1148 return &renderer_preferences_;
1149}
1150
1151void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1152 new_tab_start_time_ = time;
1153}
1154
1155base::TimeTicks TabContents::GetNewTabStartTime() const {
1156 return new_tab_start_time_;
1157}
1158
[email protected]7ab1e7d62009-10-14 23:32:011159void TabContents::OnCloseStarted() {
1160 if (tab_close_start_time_.is_null())
1161 tab_close_start_time_ = base::TimeTicks::Now();
1162}
1163
[email protected]46624bf2010-06-09 16:04:191164bool TabContents::ShouldAcceptDragAndDrop() const {
1165#if defined(OS_CHROMEOS)
1166 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1167 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511168 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201169 return false;
1170 return true;
[email protected]46624bf2010-06-09 16:04:191171#else
1172 return true;
1173#endif
1174}
1175
[email protected]7813bd72011-02-05 02:19:341176void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521177 if (GetRenderViewHost())
1178 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511179 if (delegate_)
1180 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341181}
1182
[email protected]0bfbf882011-12-22 18:19:271183void TabContents::SetClosedByUserGesture(bool value) {
1184 closed_by_user_gesture_ = value;
1185}
1186
1187bool TabContents::GetClosedByUserGesture() const {
1188 return closed_by_user_gesture_;
1189}
1190
[email protected]d0b8d092010-10-25 04:05:171191double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051192 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
1193 GetBrowserContext()->GetHostZoomMap());
[email protected]b75b8292010-10-01 07:28:251194 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171195 return 0;
[email protected]b75b8292010-10-01 07:28:251196
1197 double zoom_level;
1198 if (temporary_zoom_settings_) {
1199 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521200 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251201 } else {
[email protected]2ae88d12011-10-14 09:11:191202 GURL url;
[email protected]10f417c52011-12-28 21:04:231203 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191204 // Since zoom map is updated using rewritten URL, use rewritten URL
1205 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511206 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191207 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251208 }
[email protected]d0b8d092010-10-25 04:05:171209 return zoom_level;
1210}
[email protected]b75b8292010-10-01 07:28:251211
[email protected]d0b8d092010-10-25 04:05:171212int TabContents::GetZoomPercent(bool* enable_increment,
1213 bool* enable_decrement) {
1214 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011215 // Calculate the zoom percent from the factor. Round up to the nearest whole
1216 // number.
[email protected]b75b8292010-10-01 07:28:251217 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011218 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251219 *enable_decrement = percent > minimum_zoom_percent_;
1220 *enable_increment = percent < maximum_zoom_percent_;
1221 return percent;
1222}
1223
[email protected]3c733bde2010-12-21 19:56:311224void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501225 if (!delegate_)
1226 return;
1227
[email protected]10f417c52011-12-28 21:04:231228 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501229 if (!active_entry)
1230 return;
1231
[email protected]36fc0392011-12-25 03:59:511232 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121233}
1234
[email protected]932b7a12011-03-09 12:50:271235void TabContents::ViewFrameSource(const GURL& url,
1236 const std::string& content_state) {
1237 if (!delegate_)
1238 return;
1239
1240 delegate_->ViewSourceForFrame(this, url, content_state);
1241}
1242
[email protected]0bfbf882011-12-22 18:19:271243int TabContents::GetMinimumZoomPercent() const {
1244 return minimum_zoom_percent_;
1245}
1246
1247int TabContents::GetMaximumZoomPercent() const {
1248 return maximum_zoom_percent_;
1249}
1250
[email protected]bcd2815602012-01-14 18:17:231251gfx::Size TabContents::GetPreferredSize() const {
1252 return preferred_size_;
1253}
1254
[email protected]0bfbf882011-12-22 18:19:271255int TabContents::GetContentRestrictions() const {
1256 return content_restrictions_;
1257}
1258
1259WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501260 WebUIControllerFactory* factory =
1261 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1262 if (!factory)
1263 return WebUI::kNoWebUI;
1264 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271265}
1266
[email protected]01ec4ec2012-01-18 04:13:471267content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271268 // When there is a pending navigation entry, we want to use the pending WebUI
1269 // that goes along with it to control the basic flags. For example, we want to
1270 // show the pending URL in the URL bar, so we want the display_url flag to
1271 // be from the pending entry.
1272 //
1273 // The confusion comes because there are multiple possibilities for the
1274 // initial load in a tab as a side effect of the way the RenderViewHostManager
1275 // works.
1276 //
1277 // - For the very first tab the load looks "normal". The new tab Web UI is
1278 // the pending one, and we want it to apply here.
1279 //
1280 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1281 // get switched to the one previously associated with the new tab pages.
1282 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1283 // have a committed Web UI in this case.
1284 //
1285 // This condition handles all of these cases:
1286 //
1287 // - First load in first tab: no committed nav entry + pending nav entry +
1288 // pending dom ui:
1289 // -> Use pending Web UI if any.
1290 //
1291 // - First load in second tab: no committed nav entry + pending nav entry +
1292 // no pending Web UI:
1293 // -> Use the committed Web UI if any.
1294 //
1295 // - Second navigation in any tab: committed nav entry + pending nav entry:
1296 // -> Use pending Web UI if any.
1297 //
1298 // - Normal state with no load: committed nav entry + no pending nav entry:
1299 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251300 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271301 (controller_.GetLastCommittedEntry() ||
1302 render_manager_.pending_web_ui()))
1303 return render_manager_.pending_web_ui();
1304 return render_manager_.web_ui();
1305}
1306
1307bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1308 return GetRenderViewHost() ?
1309 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1310}
1311
1312bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471313 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271314 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221315 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231316 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511317 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271318 return true;
1319 return false;
1320}
1321
1322void TabContents::SetFocusToLocationBar(bool select_all) {
1323 if (delegate_)
1324 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211325}
1326
[email protected]8b5af492011-11-28 21:50:581327void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301328 const string16& type,
1329 const string16& href,
1330 const string16& title,
1331 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511332 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301333 this, action, type, href, title, disposition);
1334}
1335
[email protected]678105012011-12-09 04:01:211336void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301337 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001338 WebIntentsDispatcherImpl* intents_dispatcher =
1339 new WebIntentsDispatcherImpl(this, intent, intent_id);
1340 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301341}
1342
[email protected]724159a2010-12-30 01:11:181343void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1344 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591345 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181346 const GURL& url) {
1347 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1348 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521349 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301350 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181351
[email protected]8093a542011-05-13 07:29:321352 RenderViewHost* rvh =
1353 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521354 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101355 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251356 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101357 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321358 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101359
[email protected]724159a2010-12-30 01:11:181360 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591361 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251362 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591363 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181364 }
1365}
1366
1367void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591368 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181369 const GURL& source_url,
1370 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491371 // TODO(creis): Remove this method and have the pre-rendering code listen to
1372 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1373 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231374 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181375 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251376 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181377 else
1378 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511379 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181380 return;
[email protected]e7d50892011-01-19 21:47:381381
[email protected]4850a7f2011-03-08 23:36:591382 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251383 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261384 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591385 opener_url));
[email protected]724159a2010-12-30 01:11:181386}
1387
1388void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581389 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1390 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1391 << ", error_code: " << params.error_code
1392 << ", error_description: " << params.error_description
1393 << ", is_main_frame: " << params.is_main_frame
1394 << ", showing_repost_interstitial: " <<
1395 params.showing_repost_interstitial
1396 << ", frame_id: " << params.frame_id;
1397 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521398 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301399 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181400
[email protected]d7b175e2011-10-11 15:31:581401 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181402 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1403 // This means that the interstitial won't be torn down properly, which is
1404 // bad. But if we have an interstitial, go back to another tab type, and
1405 // then load the same interstitial again, we could end up getting the first
1406 // interstitial's "failed" message (as a result of the cancel) when we're on
1407 // the second one.
1408 //
1409 // We can't tell this apart, so we think we're tearing down the current page
1410 // which will cause a crash later one. There is also some code in
1411 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1412 // out because of this problem.
1413 //
1414 // http://code.google.com/p/chromium/issues/detail?id=2855
1415 // Because this will not tear down the interstitial properly, if "back" is
1416 // back to another tab type, the interstitial will still be somewhat alive
1417 // in the previous tab type. If you navigate somewhere that activates the
1418 // tab with the interstitial again, you'll see a flash before the new load
1419 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271420 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181421 LOG(WARNING) << "Discarding message during interstitial.";
1422 return;
1423 }
1424
[email protected]02102f82011-06-13 20:37:021425 // Discard our pending entry if the load canceled (e.g. if we decided to
1426 // download the file instead of load it). We do not verify that the URL
1427 // being canceled matches the pending entry's URL because they will not
1428 // match if a redirect occurred (in which case we do not want to leave a
1429 // stale redirect URL showing). This means that we also cancel the pending
1430 // entry if the user started a new navigation. As a result, the navigation
1431 // controller may not remember that a load is in progress, but the
1432 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251433 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161434 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181435
[email protected]151a63d2011-12-20 22:32:521436 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181437 }
1438
1439 // Send out a notification that we failed a provisional load with an error.
1440 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581441 params.is_main_frame,
1442 controller_.IsURLInPageNavigation(validated_url),
1443 validated_url,
1444 std::string(),
1445 false,
1446 params.frame_id);
1447 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181448
[email protected]ad50def52011-10-19 23:17:071449 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271450 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501451 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531452 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101453
[email protected]d8c660432011-12-22 20:51:251454 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581455 observers_,
1456 DidFailProvisionalLoad(params.frame_id,
1457 params.is_main_frame,
1458 validated_url,
1459 params.error_code,
1460 params.error_description));
[email protected]724159a2010-12-30 01:11:181461}
1462
1463void TabContents::OnDidLoadResourceFromMemoryCache(
1464 const GURL& url,
[email protected]70435962011-08-02 20:13:281465 const std::string& security_info,
1466 const std::string& http_method,
1467 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191468 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181469 cache.Increment();
1470
1471 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081472 int cert_id = 0;
1473 net::CertStatus cert_status = 0;
1474 int security_bits = -1;
1475 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181476 SSLManager::DeserializeSecurityInfo(security_info,
1477 &cert_id, &cert_status,
1478 &security_bits,
1479 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301480 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161481 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181482
[email protected]ad50def52011-10-19 23:17:071483 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271484 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501485 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531486 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181487}
1488
1489void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381490 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181491 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201492 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181493}
1494
1495void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021496 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231497 LOG(INFO) << security_origin << " ran insecure content from "
1498 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381499 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051500 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381501 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051502 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1503 }
[email protected]71fde352011-12-29 03:29:561504 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411505 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201506 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181507}
1508
1509void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1510 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101512 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181513}
1514
[email protected]1a55c5be2011-11-29 11:36:311515void TabContents::OnDidFinishLoad(
1516 int64 frame_id,
1517 const GURL& validated_url,
1518 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251519 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311520 DidFinishLoad(frame_id, validated_url, is_main_frame));
1521}
1522
1523void TabContents::OnDidFailLoadWithError(int64 frame_id,
1524 const GURL& validated_url,
1525 bool is_main_frame,
1526 int error_code,
1527 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251528 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311529 DidFailLoad(frame_id, validated_url, is_main_frame,
1530 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181531}
1532
[email protected]c8f73ab2011-01-22 00:05:171533void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271534 content_restrictions_ = restrictions;
1535 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171536}
1537
[email protected]216813952011-05-19 22:21:261538void TabContents::OnGoToEntryAtOffset(int offset) {
1539 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231540 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251541 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261542 if (!entry)
1543 return;
1544 // Note that we don't call NavigationController::GotToOffset() as we don't
1545 // want to create a pending navigation entry (it might end up lingering
1546 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251547 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581548 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511549 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581550 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471551 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571552
1553 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1554 // it in now that we know. This allows us to find the entry when it commits.
1555 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231556 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331557 entry->set_site_instance(
1558 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571559 }
[email protected]216813952011-05-19 22:21:261560 }
1561}
1562
1563void TabContents::OnUpdateZoomLimits(int minimum_percent,
1564 int maximum_percent,
1565 bool remember) {
1566 minimum_zoom_percent_ = minimum_percent;
1567 maximum_zoom_percent_ = maximum_percent;
1568 temporary_zoom_settings_ = !remember;
1569}
1570
[email protected]0bfbf882011-12-22 18:19:271571void TabContents::OnSaveURL(const GURL& url) {
[email protected]e30d68d2012-02-09 00:06:261572 // Check if the URL to save matches the URL of the main frame. Since this
1573 // message originates from Pepper plugins, it may not be the case if the
1574 // plugin is an embedded element.
1575 GURL main_frame_url = GetURL();
1576 if (!main_frame_url.is_valid())
1577 return;
1578 bool is_main_frame = (url == main_frame_url);
1579 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271580}
1581
[email protected]3a29a6e2011-08-24 18:26:211582void TabContents::OnEnumerateDirectory(int request_id,
1583 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511584 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211585}
1586
[email protected]7d189022011-08-25 22:54:201587void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511588 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201589}
1590
1591void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1592 const GURL& url,
1593 const string16& title) {
[email protected]6934a702011-12-20 00:04:511594 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201595}
1596
[email protected]b888919c2011-09-02 00:32:161597void TabContents::OnFindReply(int request_id,
1598 int number_of_matches,
1599 const gfx::Rect& selection_rect,
1600 int active_match_ordinal,
1601 bool final_update) {
[email protected]6934a702011-12-20 00:04:511602 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1603 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001604 // Send a notification to the renderer that we are ready to receive more
1605 // results from the scoping effort of the Find operation. The FindInPage
1606 // scoping is asynchronous and periodically sends results back up to the
1607 // browser using IPC. In an effort to not spam the browser we have the
1608 // browser send an ACK for each FindReply message and have the renderer
1609 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521610 GetRenderViewHost()->Send(
1611 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161612}
1613
[email protected]d952a052011-09-06 18:42:451614void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511615 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451616}
1617
[email protected]7fc4bbb2011-09-08 21:23:101618void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1619 bool blocked_by_policy) {
1620 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251621 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101622 AppCacheAccessed(manifest_url, blocked_by_policy));
1623}
1624
[email protected]96d185d2009-04-24 03:28:541625// Notifies the RenderWidgetHost instance about the fact that the page is
1626// loading, or done loading and calls the base implementation.
1627void TabContents::SetIsLoading(bool is_loading,
1628 LoadNotificationDetails* details) {
1629 if (is_loading == is_loading_)
1630 return;
1631
1632 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211633 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541634 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561635 upload_size_ = 0;
1636 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541637 }
1638
1639 render_manager_.SetIsLoading(is_loading);
1640
1641 is_loading_ = is_loading;
1642 waiting_for_response_ = is_loading;
1643
[email protected]6ebdc9b2010-09-27 16:55:571644 if (delegate_)
1645 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461646 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541647
[email protected]432115822011-07-10 15:52:271648 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1649 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071650 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541651 if (details)
[email protected]6c2381d2011-10-19 02:52:531652 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071653 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501654 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541655 det);
1656}
1657
[email protected]420ae012009-04-24 05:16:321658void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131659 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321660 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561661 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381662 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441663 // that opened the window, as long as both renderers have the same
1664 // privileges.
[email protected]1fd1a502011-03-30 16:55:561665 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561666 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581667 // web_ui might be NULL if the URL refers to a non-existent extension.
1668 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401669 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521670 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441671 }
1672 }
[email protected]1fd1a502011-03-30 16:55:561673 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441674 }
1675
[email protected]4e697b042011-07-08 06:44:561676 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321677 // Clear the status bubble. This is a workaround for a bug where WebKit
1678 // doesn't let us know that the cursor left an element during a
1679 // transition (this is also why the mouse cursor remains as a hand after
1680 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1681 // clear the bubble when a user navigates to a named anchor in the same
1682 // page.
[email protected]36fc0392011-12-25 03:59:511683 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321684 }
1685
[email protected]a6e82fc2010-02-24 22:28:141686 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471687 // Once the main frame is navigated, we're no longer considered to have
1688 // displayed insecure content.
1689 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171690 }
[email protected]ce5c4502009-05-06 16:46:111691
[email protected]3c9e1872010-11-18 16:17:491692 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251693 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041694 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321695}
1696
1697void TabContents::DidNavigateAnyFramePostCommit(
1698 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131699 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321700 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061701 // If we navigate off the page, reset JavaScript state. This does nothing
1702 // to prevent a malicious script from spamming messages, since the script
1703 // could just reload the page to stop blocking.
1704 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551705 dialog_creator_->ResetJavaScriptState(this);
1706 dialog_creator_ = NULL;
1707 }
[email protected]420ae012009-04-24 05:16:321708
[email protected]3c9e1872010-11-18 16:17:491709 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251710 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041711 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321712}
1713
[email protected]74ce1ad2011-12-16 21:51:461714void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1715 // If we are creating a RVH for a restored controller, then we need to make
1716 // sure the RenderView starts with a next_page_id_ larger than the number
1717 // of restored entries. This must be called before the RenderView starts
1718 // navigating (to avoid a race between the browser updating max_page_id and
1719 // the renderer updating next_page_id_). Because of this, we only call this
1720 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561721 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461722 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1723 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321724}
1725
[email protected]10f417c52011-12-28 21:04:231726bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571727 const string16& title) {
[email protected]420ae012009-04-24 05:16:321728 // For file URLs without a title, use the pathname instead. In the case of a
1729 // synthesized title, we don't want the update to count toward the "one set
1730 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511731 string16 final_title;
[email protected]420ae012009-04-24 05:16:321732 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511733 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1734 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321735 explicit_set = false; // Don't count synthetic titles toward the set limit.
1736 } else {
[email protected]acafd272011-07-26 17:35:571737 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321738 explicit_set = true;
1739 }
1740
[email protected]987fc3a2011-05-26 14:18:091741 // If a page is created via window.open and never navigated,
1742 // there will be no navigation entry. In this situation,
1743 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1744 if (entry) {
[email protected]36fc0392011-12-25 03:59:511745 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091746 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321747
[email protected]36fc0392011-12-25 03:59:511748 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091749 } else {
1750 if (page_title_when_no_navigation_entry_ == final_title)
1751 return false; // Nothing changed, don't bother.
1752
1753 page_title_when_no_navigation_entry_ = final_title;
1754 }
[email protected]420ae012009-04-24 05:16:321755
[email protected]420ae012009-04-24 05:16:321756 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231757 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321758
[email protected]105bb0f2011-05-24 17:12:141759 TitleUpdatedDetails details(entry, explicit_set);
1760
[email protected]ad50def52011-10-19 23:17:071761 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441762 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1763 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531764 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041765
[email protected]420ae012009-04-24 05:16:321766 return true;
1767}
1768
1769void TabContents::NotifySwapped() {
1770 // After sending out a swap notification, we need to send a disconnect
1771 // notification so that clients that pick up a pointer to |this| can NULL the
1772 // pointer. See Bug 1230284.
1773 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071774 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201775 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1776 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071777 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321778}
1779
1780void TabContents::NotifyConnected() {
1781 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071782 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121783 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1784 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071785 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321786}
1787
1788void TabContents::NotifyDisconnected() {
1789 if (!notify_disconnection_)
1790 return;
1791
1792 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071793 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321794 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1795 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071796 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321797}
1798
[email protected]8d3347f2009-07-09 22:00:211799RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321800 return view_.get();
1801}
1802
[email protected]8d3347f2009-07-09 22:00:211803RenderViewHostDelegate::RendererManagement*
1804TabContents::GetRendererManagementDelegate() {
1805 return &render_manager_;
1806}
1807
[email protected]daf82f82011-10-31 22:35:311808content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371809 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461810 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511811}
1812
[email protected]768c5472011-12-26 19:06:171813WebContents* TabContents::GetAsWebContents() {
1814 return this;
1815}
1816
[email protected]da4dfc42011-10-12 15:53:561817content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431818 return view_type_;
[email protected]7b291f92009-08-14 05:43:531819}
1820
[email protected]b7a756d42012-01-23 18:08:171821gfx::Rect TabContents::GetRootWindowResizerRect() const {
1822 if (delegate_)
1823 return delegate_->GetRootWindowResizerRect();
1824 return gfx::Rect();
1825}
1826
[email protected]420ae012009-04-24 05:16:321827void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071828 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271829 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321830 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531831 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231832 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321833 if (!entry)
1834 return;
1835
1836 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351837 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561838 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581839 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321840
1841 if (entry->IsViewSourceMode()) {
1842 // Put the renderer in view source mode.
1843 render_view_host->Send(
1844 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1845 }
[email protected]0666aef2009-05-13 19:48:081846
[email protected]d487beefe2011-12-21 05:41:211847 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261848
1849 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251850 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321851}
1852
1853void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521854 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321855 // Don't notify the world, since this came from a renderer in the
1856 // background.
1857 return;
1858 }
1859
1860 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311861 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231862 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301863
1864 // Restore the focus to the tab (otherwise the focus will be on the top
1865 // window).
[email protected]484ae5912010-09-29 19:16:141866 if (was_crashed && !FocusLocationBarByDefault() &&
1867 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301868 Focus();
[email protected]484ae5912010-09-29 19:16:141869 }
[email protected]32ded2212011-11-10 18:51:431870
[email protected]d8c660432011-12-22 20:51:251871 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321872}
1873
[email protected]443b80e2010-12-14 00:42:231874void TabContents::RenderViewGone(RenderViewHost* rvh,
1875 base::TerminationStatus status,
1876 int error_code) {
[email protected]151a63d2011-12-20 22:32:521877 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321878 // The pending page's RenderViewHost is gone.
1879 return;
1880 }
1881
1882 SetIsLoading(false, NULL);
1883 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231884 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311885 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321886
[email protected]d8c660432011-12-22 20:51:251887 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271888 observers_,
[email protected]be1f56ab2011-12-22 06:55:311889 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321890}
1891
[email protected]2e4633c2009-07-09 16:58:061892void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481893 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251894 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061895}
1896
[email protected]420ae012009-04-24 05:16:321897void TabContents::DidNavigate(RenderViewHost* rvh,
1898 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581899 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321900 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371901
[email protected]434f69f2012-02-06 21:56:521902 // Update the site of the SiteInstance if it doesn't have one yet, unless
1903 // this is for about:blank. In that case, the SiteInstance can still be
1904 // considered unused until a navigation to a real page.
1905 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
1906 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:331907 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:521908 }
[email protected]420ae012009-04-24 05:16:321909
1910 // Need to update MIME type here because it's referred to in
1911 // UpdateNavigationCommands() called by RendererDidNavigate() to
1912 // determine whether or not to enable the encoding menu.
1913 // It's updated only for the main frame. For a subframe,
1914 // RenderView::UpdateURL does not set params.contents_mime_type.
1915 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1916 // TODO(jungshik): Add a test for the encoding menu to avoid
1917 // regressing it again.
[email protected]2905f742011-10-13 03:51:581918 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321919 contents_mime_type_ = params.contents_mime_type;
1920
[email protected]8286f51a2011-05-31 17:39:131921 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001922 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391923
[email protected]a9c0bfe2010-09-17 08:35:221924 // Send notification about committed provisional loads. This notification is
1925 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1926 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081927 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071928 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1929 // that is not recorded in the navigation history. For the purpose of
1930 // tracking navigation events, we treat this event as a sub frame navigation
1931 // event.
1932 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581933 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221934 // Whether or not a page transition was triggered by going backward or
1935 // forward in the history is only stored in the navigation controller's
1936 // entry list.
1937 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511938 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581939 content::PAGE_TRANSITION_FORWARD_BACK)) {
1940 transition_type = content::PageTransitionFromInt(
1941 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221942 }
[email protected]0d60f0192011-04-14 12:40:101943 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251944 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101945 DidCommitProvisionalLoadForFrame(params.frame_id,
1946 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221947 }
1948
[email protected]76543b92009-08-31 17:27:451949 if (!did_navigate)
1950 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321951
1952 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1953 // for the appropriate notification (best) or you can add it to
1954 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1955 // necessary, please).
1956
1957 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001958 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321959 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511960 if (delegate_)
1961 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001962 }
[email protected]420ae012009-04-24 05:16:321963 DidNavigateAnyFramePostCommit(rvh, details, params);
1964}
1965
1966void TabContents::UpdateState(RenderViewHost* rvh,
1967 int32 page_id,
1968 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151969 // Ensure that this state update comes from either the active RVH or one of
1970 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521971 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321972
1973 // We must be prepared to handle state updates for any page, these occur
1974 // when the user is scrolling and entering form data, as well as when we're
1975 // leaving a page, in which case our state may have already been moved to
1976 // the next page. The navigation controller will look up the appropriate
1977 // NavigationEntry and update it when it is notified via the delegate.
1978
1979 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151980 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321981 if (entry_index < 0)
1982 return;
[email protected]10f417c52011-12-28 21:04:231983 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321984
[email protected]36fc0392011-12-25 03:59:511985 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321986 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511987 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321988 controller_.NotifyEntryChanged(entry, entry_index);
1989}
1990
1991void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571992 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461993 const string16& title,
1994 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321995 // If we have a title, that's a pretty good indication that we've started
1996 // getting useful data.
1997 SetNotWaitingForResponse();
1998
[email protected]151a63d2011-12-20 22:32:521999 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:232000 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
2001 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092002
[email protected]a49e10b2011-08-01 23:57:462003 // TODO(evan): make use of title_direction.
2004 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092005 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322006 return;
2007
2008 // Broadcast notifications when the UI should be updated.
2009 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462010 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322011}
2012
[email protected]420ae012009-04-24 05:16:322013void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402014 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312015 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322016}
2017
2018void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512019 if (delegate_)
2020 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322021}
2022
[email protected]420ae012009-04-24 05:16:322023void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292024 // The UI may be in an event-tracking loop, such as between the
2025 // mouse-down and mouse-up in text selection or a button click.
2026 // Defer the close until after tracking is complete, so that we
2027 // don't free objects out from under the UI.
2028 // TODO(shess): This could probably be integrated with the
2029 // IsDoingDrag() test below. Punting for now because I need more
2030 // research to understand how this impacts platforms other than Mac.
2031 // TODO(shess): This could get more fine-grained. For instance,
2032 // closing a tab in another window while selecting text in the
2033 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212034 if (GetView()->IsEventTracking()) {
2035 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292036 return;
2037 }
2038
[email protected]24a4d1062009-07-10 23:10:422039 // If we close the tab while we're in the middle of a drag, we'll crash.
2040 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212041 if (GetView()->IsDoingDrag()) {
2042 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422043 return;
2044 }
2045
[email protected]420ae012009-04-24 05:16:322046 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522047 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512048 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322049}
2050
[email protected]cd9ed79d2011-11-15 19:22:572051void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522052 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512053 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572054}
2055
[email protected]420ae012009-04-24 05:16:322056void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512057 if (delegate_ && delegate_->IsPopupOrPanel(this))
2058 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322059}
2060
[email protected]7ab1e7d62009-10-14 23:32:012061void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322062 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492063
[email protected]6934a702011-12-20 00:04:512064 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:212065 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:512066 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002067 }
[email protected]3c9e1872010-11-18 16:17:492068
2069 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252070 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322071}
2072
[email protected]7ab1e7d62009-10-14 23:32:012073void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322074 scoped_ptr<LoadNotificationDetails> details;
2075
[email protected]10f417c52011-12-28 21:04:232076 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322077 // An entry may not exist for a stop when loading an initial blank page or
2078 // if an iframe injected by script into a blank page finishes loading.
2079 if (entry) {
[email protected]420ae012009-04-24 05:16:322080 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2081
2082 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512083 entry->GetVirtualURL(),
2084 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322085 elapsed,
2086 &controller_,
2087 controller_.GetCurrentEntryIndex()));
2088 }
2089
[email protected]420ae012009-04-24 05:16:322090 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492091
2092 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252093 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322094}
2095
[email protected]c95fa8b2011-04-28 20:26:162096void TabContents::DidCancelLoading() {
2097 controller_.DiscardNonCommittedEntries();
2098
2099 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462100 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162101}
2102
[email protected]1a3c3cb2010-12-16 21:03:402103void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512104 if (delegate_)
2105 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402106}
2107
[email protected]952a68e2011-11-17 00:36:102108void TabContents::DocumentAvailableInMainFrame(
2109 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252110 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102111 DocumentAvailableInMainFrame());
2112}
2113
[email protected]25497492010-09-11 15:15:082114void TabContents::DocumentOnLoadCompletedInMainFrame(
2115 RenderViewHost* render_view_host,
2116 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072117 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272118 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322119 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532120 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082121}
2122
[email protected]ae5184d62011-10-06 19:25:582123void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152124 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582125 WindowOpenDisposition disposition,
2126 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482127 // Delegate to RequestTransferURL because this is just the generic
2128 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582129 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482130 GlobalRequestID());
2131}
2132
2133void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582134 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482135 WindowOpenDisposition disposition,
2136 int64 source_frame_id,
2137 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202138 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582139 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582140 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352141 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322142 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2143 // generated suggestions).
2144 //
[email protected]e0112912011-02-02 22:54:352145 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162146 // want web sites to see a referrer of "chrome://blah" (and some
2147 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322148 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432149 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222150 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482151 false /* is_renderer_initiated */);
2152 params.transferred_global_request_id = old_request_id;
2153 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222154 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322155 } else {
[email protected]6bf6a6b52012-02-03 15:41:432156 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482157 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2158 params.transferred_global_request_id = old_request_id;
2159 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582160 }
2161 if (new_contents) {
2162 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252163 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582164 DidOpenRequestedURL(new_contents,
2165 url,
2166 referrer,
2167 disposition,
2168 transition_type,
2169 source_frame_id));
[email protected]420ae012009-04-24 05:16:322170 }
2171}
2172
[email protected]420ae012009-04-24 05:16:322173void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342174 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412175 const string16& message,
2176 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322177 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472178 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322179 IPC::Message* reply_msg,
2180 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072181 // Suppress JavaScript dialogs when requested. Also suppress messages when
2182 // showing an interstitial as it's shown over the previous page and we don't
2183 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502184 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:152185 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272186 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072187 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522188 delegate_->ShouldSuppressDialogs() ||
2189 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322190
2191 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:342192 content::JavaScriptDialogCreator::TitleType title_type;
2193 string16 title;
2194
2195 if (!frame_url.has_host()) {
2196 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
2197 } else {
2198 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
2199 title = net::FormatUrl(
2200 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:202201 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302202 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:342203 }
2204
[email protected]2e5b90c2011-08-16 21:11:552205 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522206 dialog_creator_->RunJavaScriptDialog(
2207 this, title_type, title, javascript_message_type, message,
2208 default_prompt,
2209 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2210 reply_msg),
2211 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322212 }
[email protected]3ab9cb82011-06-03 18:02:072213
2214 if (suppress_this_message) {
2215 // If we are suppressing messages, just reply as if the user immediately
2216 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342217 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072218 }
2219
2220 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322221}
2222
[email protected]fedec012012-01-28 03:09:342223void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412224 const string16& message,
[email protected]420ae012009-04-24 05:16:322225 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512226 if (delegate_)
2227 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072228
2229 bool suppress_this_message =
2230 rvh->is_swapped_out() ||
2231 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522232 delegate_->ShouldSuppressDialogs() ||
2233 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152234 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342235 // The reply must be sent to the RVH that sent the request.
2236 rvh->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502237 return;
2238 }
[email protected]3ab9cb82011-06-03 18:02:072239
[email protected]7ab1e7d62009-10-14 23:32:012240 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552241 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522242 dialog_creator_->RunBeforeUnloadDialog(
2243 this, message,
2244 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2245 reply_msg));
[email protected]420ae012009-04-24 05:16:322246}
2247
[email protected]420ae012009-04-24 05:16:322248WebPreferences TabContents::GetWebkitPrefs() {
[email protected]64d69de42012-02-06 00:19:542249 return GetWebkitPrefs(GetRenderViewHost(), GetURL());
[email protected]420ae012009-04-24 05:16:322250}
2251
[email protected]7d472472011-01-22 01:30:252252void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272253 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252254 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222255
[email protected]99907362012-01-11 05:41:402256 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172257 if (rdh) // NULL in unittests.
2258 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252259}
2260
[email protected]fa1cf0b82010-01-15 21:49:442261void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442262 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252263 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442264}
2265
[email protected]420ae012009-04-24 05:16:322266void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2267 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152268 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522269 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152270 return;
2271
[email protected]e5fc1632011-08-08 07:51:532272 // Ignore renderer unresponsive event if debugger is attached to the tab
2273 // since the event may be a result of the renderer sitting on a breakpoint.
2274 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442275 DevToolsAgentHost* agent =
2276 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2277 if (agent &&
2278 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532279 return;
2280
[email protected]420ae012009-04-24 05:16:322281 if (is_during_unload) {
2282 // Hang occurred while firing the beforeunload/unload handler.
2283 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112284 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322285
2286 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2287 return;
2288
2289 // If the tab hangs in the beforeunload/unload handler there's really
2290 // nothing we can do to recover. Pretend the unload listeners have
2291 // all fired and close the tab. If the hang is in the beforeunload handler
2292 // then the user will not have the option of cancelling the close.
2293 Close(rvh);
2294 return;
2295 }
2296
[email protected]151a63d2011-12-20 22:32:522297 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472298 return;
2299
[email protected]6934a702011-12-20 00:04:512300 if (delegate_)
2301 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322302}
2303
2304void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512305 if (delegate_)
2306 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322307}
2308
2309void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212310 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562311 uint64 upload_position,
2312 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322313 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562314 upload_position_ = upload_position;
2315 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502316 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202317 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302318 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212319 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322320 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462321 if (IsLoading()) {
2322 NotifyNavigationStateChanged(
2323 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2324 }
[email protected]420ae012009-04-24 05:16:322325}
2326
[email protected]7d472472011-01-22 01:30:252327void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512328 if (delegate_)
2329 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252330}
2331
[email protected]420ae012009-04-24 05:16:322332void TabContents::BeforeUnloadFiredFromRenderManager(
2333 bool proceed,
2334 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512335 if (delegate_)
2336 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322337}
2338
[email protected]3a3d47472010-07-15 21:03:542339void TabContents::DidStartLoadingFromRenderManager(
2340 RenderViewHost* render_view_host) {
2341 DidStartLoading();
2342}
2343
2344void TabContents::RenderViewGoneFromRenderManager(
2345 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232346 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2347 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542348}
2349
[email protected]420ae012009-04-24 05:16:322350void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102351 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262352 gfx::Size size = view_->GetContainerSize();
2353 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2354 // here during container initialization and normal window size will be set
2355 // later. In case of tab duplication this resizing to 0x0 prevents setting
2356 // normal size later so just ignore it.
2357 if (!size.IsEmpty())
2358 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]3a3d47472010-07-15 21:03:542361void TabContents::NotifySwappedFromRenderManager() {
2362 NotifySwapped();
2363}
2364
[email protected]d202a7c2012-01-04 07:53:472365NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202366 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542367}
2368
[email protected]d2353452012-01-19 19:53:562369WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2370 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322371}
2372
[email protected]10f417c52011-12-28 21:04:232373NavigationEntry*
2374 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322375 return controller_.GetLastCommittedEntry();
2376}
2377
2378bool TabContents::CreateRenderViewForRenderManager(
2379 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442380 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322381 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522382
[email protected]420ae012009-04-24 05:16:322383 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442384 if (rwh_view)
2385 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322386
[email protected]74ce1ad2011-12-16 21:51:462387 // Make sure we use the correct starting page_id in the new RenderView.
2388 UpdateMaxPageIDIfNecessary(render_view_host);
2389 int32 max_page_id =
2390 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2391
2392 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522393 return false;
2394
[email protected]e60c0232011-11-11 19:56:352395#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502396 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2397 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442398 if (rwh_view) {
2399 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2400 render_widget_host->WasResized();
2401 }
[email protected]f8233cc2011-05-31 20:24:502402#endif
2403
[email protected]420ae012009-04-24 05:16:322404 return true;
2405}
2406
[email protected]fedec012012-01-28 03:09:342407void TabContents::OnDialogClosed(RenderViewHost* rvh,
2408 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072409 bool success,
2410 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542411 if (is_showing_before_unload_dialog_ && !success) {
2412 // If a beforeunload dialog is canceled, we need to stop the throbber from
2413 // spinning, since we forced it to start spinning in Navigate.
2414 DidStopLoading();
2415
2416 tab_close_start_time_ = base::TimeTicks();
2417 }
2418 is_showing_before_unload_dialog_ = false;
[email protected]fedec012012-01-28 03:09:342419 rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542420}
2421
[email protected]be1f56ab2011-12-22 06:55:312422void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122423 encoding_ = content::GetContentClient()->browser()->
2424 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102425}
[email protected]f45d2a72010-03-08 23:28:352426
[email protected]e30d68d2012-02-09 00:06:262427void TabContents::SaveURL(const GURL& url,
2428 const GURL& referrer,
2429 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142430 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2431 if (!dlm)
2432 return;
2433 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262434 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142435 const NavigationEntry* entry = controller_.GetActiveEntry();
2436 if (entry)
2437 post_id = entry->GetPostID();
2438 }
2439 DownloadSaveInfo save_info;
2440 save_info.prompt_for_save_location = true;
2441 dlm->DownloadUrl(url,
2442 referrer,
2443 "",
2444 true, // prefer_cache
2445 post_id,
2446 save_info,
2447 this);
2448}
2449
[email protected]33f74972010-12-08 16:40:362450void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212451 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442452 // Can be NULL during tests.
2453 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212454 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362455}