blob: 390acb4f80225c0a3ab3f47c21b6cbbdb5048403 [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 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]71bf3f5e2011-08-15 21:05:2218#include "content/browser/download/download_manager.h"
[email protected]8bd9e562011-08-16 23:55:4619#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5020#include "content/browser/host_zoom_map.h"
21#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]ada02b312011-12-01 21:54:5322#include "content/browser/intents/intents_host_impl.h"
[email protected]37a72af2011-06-13 05:42:0123#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0424#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3025#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5026#include "content/browser/renderer_host/render_view_host.h"
27#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2228#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/resource_request_details.h"
30#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1332#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/navigation_entry.h"
34#include "content/browser/tab_contents/provisional_load_details.h"
35#include "content/browser/tab_contents/tab_contents_delegate.h"
36#include "content/browser/tab_contents/tab_contents_observer.h"
37#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1438#include "content/browser/tab_contents/title_updated_details.h"
[email protected]1fd1a502011-03-30 16:55:5639#include "content/browser/webui/web_ui_factory.h"
[email protected]ce9751942011-09-21 01:57:2440#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0241#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4443#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4444#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]54087fe2011-10-28 22:02:4845#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3846#include "content/public/browser/user_metrics.h"
[email protected]e091df82011-10-11 18:13:2147#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1849#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d686e812009-06-03 19:10:2951#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3452#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3854#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2455#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3156#include "webkit/glue/webpreferences.h"
57
58#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1259#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3160#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0061
[email protected]420ae012009-04-24 05:16:3262// Cross-Site Navigations
63//
64// If a TabContents is told to navigate to a different web site (as determined
65// by SiteInstance), it will replace its current RenderViewHost with a new
66// RenderViewHost dedicated to the new SiteInstance. This works as follows:
67//
68// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4669// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3270// - The pending RVH is "suspended," so that no navigation messages are sent to
71// its renderer until the onbeforeunload JavaScript handler has a chance to
72// run in the current RVH.
73// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
74// that it has a pending cross-site request. ResourceDispatcherHost will
75// check for this when the response arrives.
76// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4677// cancel all the pending logic. Otherwise we allow the pending RVH to send
78// the navigation request to its renderer.
79// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
80// main resource load on the pending RVH. It checks CrossSiteRequestManager
81// to see that it is a cross-site request, and installs a
82// CrossSiteResourceHandler.
83// - When RDH receives a response, the BufferedResourceHandler determines
84// whether it is a download. If so, it sends a message to the new renderer
85// causing it to cancel the request, and the download proceeds. For now, the
86// pending RVH remains until the next DidNavigate event for this TabContents.
87// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3288// - After RDH receives a response and determines that it is safe and not a
89// download, it pauses the response to first run the old page's onunload
90// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1591// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3292// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1593// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3294// the ResourceDispatcherHost, who unpauses the response. Data is then sent
95// to the pending RVH.
96// - The pending renderer sends a FrameNavigate message that invokes the
97// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4698// pending RVH.
[email protected]992db4c2011-05-12 15:37:1599// - The previous renderer is kept swapped out in RenderViewHostManager in case
100// the user goes back. The process only stays live if another tab is using
101// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02102//
103// It is possible that we trigger a new navigation after we have received
104// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
105// In this case the old RVH has been swapped out but the new one has not
106// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
107// of the old RVH.
[email protected]420ae012009-04-24 05:16:32108
[email protected]0e12d7d2011-12-01 16:21:44109using content::DevToolsAgentHost;
110using content::DevToolsAgentHostRegistry;
111using content::DevToolsManagerImpl;
[email protected]7f6f44c2011-12-14 13:23:38112using content::UserMetricsAction;
[email protected]0e12d7d2011-12-01 16:21:44113
[email protected]420ae012009-04-24 05:16:32114namespace {
115
116// Amount of time we wait between when a key event is received and the renderer
117// is queried for its state and pushed to the NavigationEntry.
118const int kQueryStateDelay = 5000;
119
[email protected]6ebdc9b2010-09-27 16:55:57120const int kSyncWaitDelay = 40;
121
[email protected]ca406032011-07-19 21:53:05122static const char kDotGoogleDotCom[] = ".google.com";
123
[email protected]420ae012009-04-24 05:16:32124#if defined(OS_WIN)
125
126BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
127 // Note: erase is required to properly paint some widgets borders. This can
128 // be seen with textfields.
129 InvalidateRect(hwnd, NULL, TRUE);
130 return TRUE;
131}
132#endif
133
[email protected]2c5569662011-03-22 20:45:02134ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]3d7474ff2011-07-27 17:47:37135 content::BrowserContext* browser_context, const NavigationEntry& entry,
[email protected]1ccb3568d2010-02-19 10:51:16136 NavigationController::ReloadType reload_type) {
137 switch (reload_type) {
138 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02139 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16140 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02141 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16142 case NavigationController::NO_RELOAD:
143 break; // Fall through to rest of function.
144 }
[email protected]5e369672009-11-03 23:48:30145
146 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37147 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02148 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30149
[email protected]2c5569662011-03-22 20:45:02150 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30151}
152
[email protected]876bc832010-09-07 16:29:54153void MakeNavigateParams(const NavigationEntry& entry,
154 const NavigationController& controller,
[email protected]6c6b02d2011-09-02 03:36:47155 TabContentsDelegate* delegate,
[email protected]1ccb3568d2010-02-19 10:51:16156 NavigationController::ReloadType reload_type,
157 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34158 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54159 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00160 params->current_history_list_offset = controller.last_committed_entry_index();
161 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34162 params->url = entry.url();
[email protected]cb8fb01a2011-12-05 21:01:14163 params->referrer = entry.referrer();
[email protected]056de2d2009-06-26 16:41:34164 params->transition = entry.transition_type();
165 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00166 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37167 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34168 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47169 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48170 params->transferred_request_child_id =
171 entry.transferred_global_request_id().child_id;
172 params->transferred_request_request_id =
173 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47174
175 if (delegate)
176 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34177}
178
[email protected]420ae012009-04-24 05:16:32179} // namespace
180
[email protected]f4f50ef2011-01-21 19:01:19181
182// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32183
[email protected]3d7474ff2011-07-27 17:47:37184TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32185 SiteInstance* site_instance,
186 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07187 const TabContents* base_tab_contents,
188 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42189 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07190 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37191 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13192 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32193 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22194 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34195 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23196 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
197 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34198 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21199 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56200 upload_size_(0),
201 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47202 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57203 capturing_contents_(false),
204 is_being_destroyed_(false),
205 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55206 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57207#if defined(OS_WIN)
208 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
209#endif
[email protected]7ab1e7d62009-10-14 23:32:01210 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56211 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38212 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25213 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01214 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25215 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01216 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00217 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43218 content_restrictions_(0),
219 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37220 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32221
[email protected]34ac70502009-09-25 17:07:23222 // We have the initial size of the view be based on the size of the passed in
223 // tab contents (normally a tab from the same window).
224 view_->CreateView(base_tab_contents ?
225 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00226
227#if defined(ENABLE_JAVA_BRIDGE)
228 java_bridge_dispatcher_host_manager_.reset(
229 new JavaBridgeDispatcherHostManager(this));
230#endif
[email protected]332af7732009-03-11 13:21:35231}
initial.commit09911bf2008-07-26 23:55:29232
233TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32234 is_being_destroyed_ = true;
235
[email protected]3ab9cb82011-06-03 18:02:07236 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55237 if (dialog_creator_)
238 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07239
[email protected]420ae012009-04-24 05:16:32240 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32241
[email protected]420ae012009-04-24 05:16:32242 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07243 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27244 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53245 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07246 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32247
248 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07249#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32250 // If we still have a window handle, destroy it. GetNativeView can return
251 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42252 if (GetNativeView()) {
253 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44254 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42255 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42256 }
[email protected]420ae012009-04-24 05:16:32257#endif
[email protected]7ab1e7d62009-10-14 23:32:01258
259 // OnCloseStarted isn't called in unit tests.
260 if (!tab_close_start_time_.is_null()) {
261 UMA_HISTOGRAM_TIMES("Tab.Close",
262 base::TimeTicks::Now() - tab_close_start_time_);
263 }
[email protected]b5a1d11c2011-02-17 03:09:42264
[email protected]07d490bc2011-03-07 17:05:26265 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08266
[email protected]1de2b8b2011-06-29 19:38:46267 set_delegate(NULL);
268}
269
270// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
271void TabContents::set_delegate(TabContentsDelegate* delegate) {
272 if (delegate == delegate_)
273 return;
274 if (delegate_)
275 delegate_->Detach(this);
276 delegate_ = delegate;
277 if (delegate_)
278 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42279}
280
[email protected]724159a2010-12-30 01:11:18281bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17282 if (web_ui() && web_ui()->OnMessageReceived(message))
283 return true;
284
[email protected]585b30362011-01-28 02:30:17285 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
286 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10287 while ((observer = it.GetNext()) != NULL)
288 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53289 return true;
[email protected]403415a2011-01-10 18:57:53290
[email protected]724159a2010-12-30 01:11:18291 bool handled = true;
292 bool message_is_ok = true;
293 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58294 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
295 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24296 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
297 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18298 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
299 OnDidStartProvisionalLoadForFrame)
300 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
301 OnDidRedirectProvisionalLoad)
302 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
303 OnDidFailProvisionalLoadWithError)
304 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
305 OnDidLoadResourceFromMemoryCache)
306 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
307 OnDidDisplayInsecureContent)
308 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
309 OnDidRunInsecureContent)
310 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
311 OnDocumentLoadedInFrame)
312 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17313 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
314 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25315 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26316 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59317 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21318 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20319 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
320 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
321 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16322 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45323 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10324 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18325 IPC_MESSAGE_UNHANDLED(handled = false)
326 IPC_END_MESSAGE_MAP_EX()
327
328 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38329 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18330 GetRenderProcessHost()->ReceivedBadMessage();
331 }
332
333 return handled;
334}
335
[email protected]6c2e472f2011-08-24 23:26:18336void TabContents::RunFileChooser(
337 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23338 const content::FileChooserParams& params) {
[email protected]6c2e472f2011-08-24 23:26:18339 delegate()->RunFileChooser(this, params);
340}
341
[email protected]f3b1a082011-11-18 00:34:30342content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03343 if (render_manager_.current_host())
344 return render_manager_.current_host()->process();
345 else
346 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16347}
348
[email protected]d5f942ba2008-09-26 19:30:34349const GURL& TabContents::GetURL() const {
350 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57351 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54352 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34353}
354
[email protected]96d185d2009-04-24 03:28:54355const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55356 // Transient entries take precedence. They are used for interstitial pages
357 // that are shown on top of existing pages.
358 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08359 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20360 content::GetContentClient()->browser()->GetAcceptLangs(
361 this->browser_context());
[email protected]45d0ef7f2011-01-05 13:46:23362 if (entry) {
[email protected]b5cca982011-05-26 04:42:08363 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23364 }
[email protected]7ade2732011-02-10 00:13:58365 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
366 render_manager_.pending_web_ui() : render_manager_.web_ui();
367 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54368 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55369 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54370 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35371 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58372 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54373 if (!title.empty())
374 return title;
375 }
376 }
377
378 // We use the title for the last committed entry rather than a pending
379 // navigation entry. For example, when the user types in a URL, we want to
380 // keep the old page's title until the new load has committed and we get a new
381 // title.
[email protected]96d185d2009-04-24 03:28:54382 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23383 if (entry) {
[email protected]b5cca982011-05-26 04:42:08384 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23385 }
[email protected]987fc3a2011-05-26 14:18:09386
387 // |page_title_when_no_navigation_entry_| is finally used
388 // if no title cannot be retrieved.
389 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54390}
391
[email protected]d5f942ba2008-09-26 19:30:34392int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46393 return GetMaxPageIDForSiteInstance(GetSiteInstance());
394}
395
396int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
397 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
398 max_page_ids_[site_instance->id()] = -1;
399
400 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34401}
402
403void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46404 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
405}
406
407void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
408 int32 page_id) {
409 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
410 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34411}
412
[email protected]96d185d2009-04-24 03:28:54413SiteInstance* TabContents::GetSiteInstance() const {
414 return render_manager_.current_host()->site_instance();
415}
416
[email protected]77362eb2011-08-01 17:18:38417SiteInstance* TabContents::GetPendingSiteInstance() const {
418 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
419 render_manager_.pending_render_view_host() :
420 render_manager_.current_host();
421 return dest_rvh->site_instance();
422}
423
[email protected]585b30362011-01-28 02:30:17424void TabContents::AddObserver(TabContentsObserver* observer) {
425 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49426}
427
[email protected]585b30362011-01-28 02:30:17428void TabContents::RemoveObserver(TabContentsObserver* observer) {
429 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49430}
431
[email protected]443b80e2010-12-14 00:42:23432void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
433 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34434 return;
435
[email protected]443b80e2010-12-14 00:42:23436 crashed_status_ = status;
437 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50438 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34439}
440
441void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
442 if (delegate_)
443 delegate_->NavigationStateChanged(this, changed_flags);
444}
445
[email protected]96d185d2009-04-24 03:28:54446void TabContents::DidBecomeSelected() {
447 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16448 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
449 if (rwhv) {
450 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43451#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16452 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43453#endif
454 }
[email protected]96d185d2009-04-24 03:28:54455
[email protected]5ac20162010-11-24 23:33:11456 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38457
458 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54459}
460
461void TabContents::WasHidden() {
462 if (!capturing_contents()) {
463 // |render_view_host()| can be NULL if the user middle clicks a link to open
464 // a tab in then background, then closes the tab before selecting it. This
465 // is because closing the tab calls TabContents::Destroy(), which removes
466 // the |render_view_host()|; then when we actually destroy the window,
467 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16468 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
469 if (rwhv)
470 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54471 }
472
[email protected]ad50def52011-10-19 23:17:07473 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27474 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53475 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07476 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54477}
478
[email protected]d5f942ba2008-09-26 19:30:34479void TabContents::Activate() {
480 if (delegate_)
481 delegate_->ActivateContents(this);
482}
483
[email protected]ea42e7782010-08-23 23:58:12484void TabContents::Deactivate() {
485 if (delegate_)
486 delegate_->DeactivateContents(this);
487}
488
[email protected]63954792011-07-11 04:17:48489void TabContents::LostCapture() {
490 if (delegate_)
491 delegate_->LostCapture();
492}
493
494bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
495 bool* is_keyboard_shortcut) {
496 return delegate_ &&
497 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
498}
499
500void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
501 if (delegate_)
502 delegate_->HandleKeyboardEvent(event);
503}
504
[email protected]32ded2212011-11-10 18:51:43505void TabContents::HandleMouseDown() {
506 if (delegate_)
507 delegate_->HandleMouseDown();
508}
509
[email protected]63954792011-07-11 04:17:48510void TabContents::HandleMouseUp() {
511 if (delegate_)
512 delegate_->HandleMouseUp();
513}
514
515void TabContents::HandleMouseActivate() {
516 if (delegate_)
517 delegate_->HandleMouseActivate();
518}
519
[email protected]8a5e0ca2011-08-25 06:30:47520void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
521 if (delegate_)
522 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
523}
524
[email protected]5d5f7af2011-10-01 01:38:12525bool TabContents::IsFullscreenForCurrentTab() const {
526 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
527}
528
[email protected]e9621112011-10-17 05:38:37529void TabContents::RequestToLockMouse() {
530 if (delegate_) {
531 delegate_->RequestToLockMouse(this);
532 } else {
533 GotResponseToLockMouseRequest(false);
534 }
535}
536
537void TabContents::LostMouseLock() {
538 if (delegate_)
539 delegate_->LostMouseLock();
540}
541
[email protected]0548c5352011-09-07 00:33:33542void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
543 if (delegate_)
544 delegate_->UpdatePreferredSize(this, pref_size);
545}
546
[email protected]32ded2212011-11-10 18:51:43547void TabContents::WebUISend(RenderViewHost* render_view_host,
548 const GURL& source_url,
549 const std::string& name,
550 const base::ListValue& args) {
551 if (delegate_)
552 delegate_->WebUISend(this, source_url, name, args);
553}
554
[email protected]96d185d2009-04-24 03:28:54555void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16556 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
557 if (rwhv)
558 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54559}
560
561void TabContents::HideContents() {
562 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
563 // our superclass HideContents(), because some callers want to be very picky
564 // about the order in which these get called. In addition to making the code
565 // here practically impossible to understand, this also means we end up
566 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34567 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54568 WasHidden();
569}
570
[email protected]5aab5e22010-12-08 22:13:29571bool TabContents::NeedToFireBeforeUnload() {
572 // TODO(creis): Should we fire even for interstitial pages?
573 return notify_disconnection() &&
574 !showing_interstitial_page() &&
575 !render_view_host()->SuddenTerminationAllowed();
576}
577
[email protected]00c37fc2011-08-02 00:22:50578// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25579TabContents* TabContents::OpenURL(const GURL& url,
580 const GURL& referrer,
581 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58582 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10583 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
584 DCHECK(referrer.is_empty());
[email protected]bce1f1c2011-12-05 15:11:58585 return OpenURL(OpenURLParams(url, content::Referrer(), disposition,
586 transition, false));
[email protected]00c37fc2011-08-02 00:22:50587}
588
589TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49590 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50591 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49592 // Notify observers.
593 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50594 DidOpenURL(params.url, params.referrer,
595 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25596 return new_contents;
[email protected]1c642b52011-04-15 09:05:49597 }
[email protected]992e4542011-07-20 23:09:25598 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34599}
600
[email protected]1ccb3568d2010-02-19 10:51:16601bool TabContents::NavigateToPendingEntry(
602 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27603 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54604}
[email protected]96d185d2009-04-24 03:28:54605
[email protected]876bc832010-09-07 16:29:54606bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27607 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54608 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40609 // The renderer will reject IPC messages with URLs longer than
610 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27611 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40612 return false;
613
[email protected]dd11de52011-11-03 22:54:27614 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40615 if (!dest_render_view_host)
616 return false; // Unable to create the desired render view host.
617
[email protected]80a8fad2011-01-29 04:02:38618 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07619 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58620 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56621 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37622 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]dd11de52011-11-03 22:54:27623 entry.url());
[email protected]32ded2212011-11-10 18:51:43624#if defined(OS_CHROMEOS)
625 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
626#endif
[email protected]e091df82011-10-11 18:13:21627 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55628 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58629
[email protected]96d185d2009-04-24 03:28:54630 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44631 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
632 render_view_host(),
633 dest_render_view_host,
634 entry.url());
[email protected]96d185d2009-04-24 03:28:54635
636 // Used for page load time metrics.
637 current_load_start_ = base::TimeTicks::Now();
638
639 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34640 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27641 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47642 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34643 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54644
[email protected]dd11de52011-11-03 22:54:27645 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54646 // HACK!! This code suppresses javascript: URLs from being added to
647 // session history, which is what we want to do for javascript: URLs that
648 // do not generate content. What we really need is a message from the
649 // renderer telling us that a new page was not created. The same message
650 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27651 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54652 return false;
653 }
654
[email protected]3c9e1872010-11-18 16:17:49655 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04656 FOR_EACH_OBSERVER(TabContentsObserver,
657 observers_,
[email protected]dd11de52011-11-03 22:54:27658 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54659
[email protected]09b29342011-06-24 19:18:48660 if (delegate_)
661 delegate_->DidNavigateToPendingEntry(this);
662
[email protected]d5f942ba2008-09-26 19:30:34663 return true;
664}
665
[email protected]9e1ad4b2011-08-14 16:49:19666void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
667 int history_length,
668 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41669 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
670 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19671 if (render_manager_.pending_render_view_host()) {
672 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14673 return;
[email protected]9e1ad4b2011-08-14 16:49:19674 }
675 RenderViewHost* rvh = render_view_host();
676 if (!rvh) {
677 NOTREACHED();
678 return;
679 }
680 if (site_instance && rvh->site_instance() != site_instance) {
681 NOTREACHED();
682 return;
683 }
684 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
685 history_length,
686 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14687}
688
[email protected]96d185d2009-04-24 03:28:54689void TabContents::Stop() {
690 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47691 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54692}
693
[email protected]96d185d2009-04-24 03:28:54694TabContents* TabContents::Clone() {
695 // We create a new SiteInstance so that the new tab won't share processes
696 // with the old one. This can be changed in the future if we need it to share
697 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37698 TabContents* tc = new TabContents(
699 browser_context(),
700 SiteInstance::CreateSiteInstance(browser_context()),
701 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54702 tc->controller().CopyStateFrom(controller_);
703 return tc;
704}
705
[email protected]4d677202009-07-19 07:37:12706void TabContents::ShowPageInfo(const GURL& url,
707 const NavigationEntry::SSLStatus& ssl,
708 bool show_history) {
709 if (!delegate_)
710 return;
711
[email protected]3d7474ff2011-07-27 17:47:37712 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12713}
714
[email protected]e7cfdbd2011-04-22 14:41:37715void TabContents::AddNewContents(TabContents* new_contents,
716 WindowOpenDisposition disposition,
717 const gfx::Rect& initial_pos,
718 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29719 if (!delegate_)
720 return;
721
[email protected]e7cfdbd2011-04-22 14:41:37722 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
723 user_gesture);
[email protected]96d185d2009-04-24 03:28:54724}
725
[email protected]5c9e97a2009-09-09 23:48:30726gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54727 return view_->GetContentNativeView();
728}
729
730gfx::NativeView TabContents::GetNativeView() const {
731 return view_->GetNativeView();
732}
733
734void TabContents::GetContainerBounds(gfx::Rect *out) const {
735 view_->GetContainerBounds(out);
736}
737
738void TabContents::Focus() {
739 view_->Focus();
740}
741
[email protected]90daadb42009-06-08 21:27:28742void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54743 if (showing_interstitial_page()) {
744 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
745 return;
746 }
[email protected]96d185d2009-04-24 03:28:54747 render_view_host()->SetInitialFocus(reverse);
748}
749
750bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40751 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58752 if (web_ui)
753 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43754 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25755 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43756 return true;
[email protected]96d185d2009-04-24 03:28:54757 return false;
758}
759
[email protected]a26dc362010-04-23 01:48:58760void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38761 if (delegate())
[email protected]a26dc362010-04-23 01:48:58762 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38763}
764
[email protected]686493142011-07-15 21:47:22765bool TabContents::CanDownload(int request_id) {
766 TabContentsDelegate* d = delegate();
767 if (d)
768 return d->CanDownload(this, request_id);
769 return true;
770}
771
772void TabContents::OnStartDownload(DownloadItem* download) {
773 TabContentsDelegate* d = delegate();
774 if (d)
775 d->OnStartDownload(this, download);
776}
777
[email protected]c7dd2f62011-07-18 15:57:59778void TabContents::OnSavePage() {
779 // If we can not save the page, try to download it.
780 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37781 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59782 const GURL& current_page_url = GetURL();
783 if (dlm && current_page_url.is_valid()) {
784 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46785 download_stats::RecordDownloadCount(
786 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59787 return;
788 }
789 }
790
791 Stop();
792
793 // Create the save package and possibly prompt the user for the name to save
794 // the page as. The user prompt is an asynchronous operation that runs on
795 // another thread.
796 save_package_ = new SavePackage(this);
797 save_package_->GetSaveInfo();
798}
799
800// Used in automated testing to bypass prompting the user for file names.
801// Instead, the names and paths are hard coded rather than running them through
802// file name sanitation and extension / mime checking.
803bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
804 SavePackage::SavePackageType save_type) {
805 // Stop the page from navigating.
806 Stop();
807
808 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
809 return save_package_->Init();
810}
811
812void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37813 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59814 dlm->DownloadUrl(url, GetURL(), "", this);
815}
816
[email protected]420ae012009-04-24 05:16:32817bool TabContents::IsActiveEntry(int32 page_id) {
818 NavigationEntry* active_entry = controller_.GetActiveEntry();
819 return (active_entry != NULL &&
820 active_entry->site_instance() == GetSiteInstance() &&
821 active_entry->page_id() == page_id);
822}
823
[email protected]b2fe07d12010-02-09 14:38:08824void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16825 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26826 render_view_host()->Send(new ViewMsg_SetPageEncoding(
827 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16828}
829
[email protected]b2fe07d12010-02-09 14:38:08830void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16831 reset_encoding();
[email protected]216813952011-05-19 22:21:26832 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
833 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16834}
835
[email protected]7ab1e7d62009-10-14 23:32:01836void TabContents::OnCloseStarted() {
837 if (tab_close_start_time_.is_null())
838 tab_close_start_time_ = base::TimeTicks::Now();
839}
840
[email protected]46624bf2010-06-09 16:04:19841bool TabContents::ShouldAcceptDragAndDrop() const {
842#if defined(OS_CHROMEOS)
843 // ChromeOS panels (pop-ups) do not take drag-n-drop.
844 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14845 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20846 return false;
847 return true;
[email protected]46624bf2010-06-09 16:04:19848#else
849 return true;
850#endif
851}
852
[email protected]7813bd72011-02-05 02:19:34853void TabContents::SystemDragEnded() {
854 if (render_view_host())
855 render_view_host()->DragSourceSystemDragEnded();
856 if (delegate())
857 delegate()->DragEnded();
858}
859
[email protected]d0b8d092010-10-25 04:05:17860double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37861 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25862 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17863 return 0;
[email protected]b75b8292010-10-01 07:28:25864
865 double zoom_level;
866 if (temporary_zoom_settings_) {
867 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]f3b1a082011-11-18 00:34:30868 GetRenderProcessHost()->GetID(), render_view_host()->routing_id());
[email protected]b75b8292010-10-01 07:28:25869 } else {
[email protected]2ae88d12011-10-14 09:11:19870 GURL url;
871 NavigationEntry* active_entry = controller().GetActiveEntry();
872 // Since zoom map is updated using rewritten URL, use rewritten URL
873 // to get the zoom level.
874 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
875 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25876 }
[email protected]d0b8d092010-10-25 04:05:17877 return zoom_level;
878}
[email protected]b75b8292010-10-01 07:28:25879
[email protected]d0b8d092010-10-25 04:05:17880int TabContents::GetZoomPercent(bool* enable_increment,
881 bool* enable_decrement) {
882 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01883 // Calculate the zoom percent from the factor. Round up to the nearest whole
884 // number.
[email protected]b75b8292010-10-01 07:28:25885 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:01886 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:25887 *enable_decrement = percent > minimum_zoom_percent_;
888 *enable_increment = percent < maximum_zoom_percent_;
889 return percent;
890}
891
[email protected]3c733bde2010-12-21 19:56:31892void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50893 if (!delegate_)
894 return;
895
896 NavigationEntry* active_entry = controller().GetActiveEntry();
897 if (!active_entry)
898 return;
899
900 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12901}
902
[email protected]932b7a12011-03-09 12:50:27903void TabContents::ViewFrameSource(const GURL& url,
904 const std::string& content_state) {
905 if (!delegate_)
906 return;
907
908 delegate_->ViewSourceForFrame(this, url, content_state);
909}
910
[email protected]c40d6232011-03-25 00:16:21911void TabContents::SetContentRestrictions(int restrictions) {
912 content_restrictions_ = restrictions;
913 delegate()->ContentRestrictionsChanged(this);
914}
915
[email protected]8b5af492011-11-28 21:50:58916void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30917 const string16& type,
918 const string16& href,
919 const string16& title,
920 const string16& disposition) {
921 delegate()->RegisterIntentHandler(
922 this, action, type, href, title, disposition);
923}
924
[email protected]678105012011-12-09 04:01:21925void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30926 int intent_id) {
[email protected]ada02b312011-12-01 21:54:53927 IntentsHostImpl* intents_host = new IntentsHostImpl(this, intent, intent_id);
928 delegate()->WebIntentDispatch(this, intents_host);
[email protected]63c239322011-10-31 23:56:30929}
930
[email protected]724159a2010-12-30 01:11:18931void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
932 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59933 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18934 const GURL& url) {
935 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
936 GURL validated_url(url);
937 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30938 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18939
[email protected]8093a542011-05-13 07:29:32940 RenderViewHost* rvh =
941 render_manager_.pending_render_view_host() ?
942 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10943 // Notify observers about the start of the provisional load.
944 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
945 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32946 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10947
[email protected]724159a2010-12-30 01:11:18948 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59949 // Notify observers about the provisional change in the main frame URL.
950 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59951 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18952 }
953}
954
955void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59956 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18957 const GURL& source_url,
958 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49959 // TODO(creis): Remove this method and have the pre-rendering code listen to
960 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
961 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18962 NavigationEntry* entry;
963 if (page_id == -1)
964 entry = controller_.pending_entry();
965 else
966 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
967 if (!entry || entry->url() != source_url)
968 return;
[email protected]e7d50892011-01-19 21:47:38969
[email protected]4850a7f2011-03-08 23:36:59970 // Notify observers about the provisional change in the main frame URL.
971 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26972 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59973 opener_url));
[email protected]724159a2010-12-30 01:11:18974}
975
976void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58977 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
978 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
979 << ", error_code: " << params.error_code
980 << ", error_description: " << params.error_description
981 << ", is_main_frame: " << params.is_main_frame
982 << ", showing_repost_interstitial: " <<
983 params.showing_repost_interstitial
984 << ", frame_id: " << params.frame_id;
985 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18986 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30987 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18988
[email protected]d7b175e2011-10-11 15:31:58989 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18990 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
991 // This means that the interstitial won't be torn down properly, which is
992 // bad. But if we have an interstitial, go back to another tab type, and
993 // then load the same interstitial again, we could end up getting the first
994 // interstitial's "failed" message (as a result of the cancel) when we're on
995 // the second one.
996 //
997 // We can't tell this apart, so we think we're tearing down the current page
998 // which will cause a crash later one. There is also some code in
999 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1000 // out because of this problem.
1001 //
1002 // http://code.google.com/p/chromium/issues/detail?id=2855
1003 // Because this will not tear down the interstitial properly, if "back" is
1004 // back to another tab type, the interstitial will still be somewhat alive
1005 // in the previous tab type. If you navigate somewhere that activates the
1006 // tab with the interstitial again, you'll see a flash before the new load
1007 // commits of the interstitial page.
1008 if (showing_interstitial_page()) {
1009 LOG(WARNING) << "Discarding message during interstitial.";
1010 return;
1011 }
1012
[email protected]02102f82011-06-13 20:37:021013 // Discard our pending entry if the load canceled (e.g. if we decided to
1014 // download the file instead of load it). We do not verify that the URL
1015 // being canceled matches the pending entry's URL because they will not
1016 // match if a redirect occurred (in which case we do not want to leave a
1017 // stale redirect URL showing). This means that we also cancel the pending
1018 // entry if the user started a new navigation. As a result, the navigation
1019 // controller may not remember that a load is in progress, but the
1020 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181021 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021022 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161023 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181024
1025 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1026 }
1027
1028 // Send out a notification that we failed a provisional load with an error.
1029 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581030 params.is_main_frame,
1031 controller_.IsURLInPageNavigation(validated_url),
1032 validated_url,
1033 std::string(),
1034 false,
1035 params.frame_id);
1036 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181037
[email protected]ad50def52011-10-19 23:17:071038 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271039 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531040 content::Source<NavigationController>(&controller_),
1041 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101042
[email protected]d7b175e2011-10-11 15:31:581043 FOR_EACH_OBSERVER(TabContentsObserver,
1044 observers_,
1045 DidFailProvisionalLoad(params.frame_id,
1046 params.is_main_frame,
1047 validated_url,
1048 params.error_code,
1049 params.error_description));
[email protected]724159a2010-12-30 01:11:181050}
1051
1052void TabContents::OnDidLoadResourceFromMemoryCache(
1053 const GURL& url,
[email protected]70435962011-08-02 20:13:281054 const std::string& security_info,
1055 const std::string& http_method,
1056 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191057 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181058 cache.Increment();
1059
1060 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081061 int cert_id = 0;
1062 net::CertStatus cert_status = 0;
1063 int security_bits = -1;
1064 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181065 SSLManager::DeserializeSecurityInfo(security_info,
1066 &cert_id, &cert_status,
1067 &security_bits,
1068 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301069 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161070 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181071
[email protected]ad50def52011-10-19 23:17:071072 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271073 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531074 content::Source<NavigationController>(&controller_),
1075 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181076}
1077
1078void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381079 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181080 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071081 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181082}
1083
1084void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021085 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231086 LOG(INFO) << security_origin << " ran insecure content from "
1087 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381088 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051089 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381090 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051091 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1092 }
[email protected]724159a2010-12-30 01:11:181093 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411094 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071095 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181096}
1097
1098void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1099 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101100 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1101 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181102}
1103
[email protected]1a55c5be2011-11-29 11:36:311104void TabContents::OnDidFinishLoad(
1105 int64 frame_id,
1106 const GURL& validated_url,
1107 bool is_main_frame) {
[email protected]0d60f0192011-04-14 12:40:101108 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311109 DidFinishLoad(frame_id, validated_url, is_main_frame));
1110}
1111
1112void TabContents::OnDidFailLoadWithError(int64 frame_id,
1113 const GURL& validated_url,
1114 bool is_main_frame,
1115 int error_code,
1116 const string16& error_description) {
1117 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1118 DidFailLoad(frame_id, validated_url, is_main_frame,
1119 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181120}
1121
[email protected]c8f73ab2011-01-22 00:05:171122void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211123 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171124}
1125
[email protected]216813952011-05-19 22:21:261126void TabContents::OnGoToEntryAtOffset(int offset) {
1127 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1128 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1129 if (!entry)
1130 return;
1131 // Note that we don't call NavigationController::GotToOffset() as we don't
1132 // want to create a pending navigation entry (it might end up lingering
1133 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581134 entry->set_transition_type(
1135 content::PageTransitionFromInt(
1136 entry->transition_type() |
1137 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271138 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571139
1140 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1141 // it in now that we know. This allows us to find the entry when it commits.
1142 if (!entry->site_instance() &&
1143 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381144 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571145 }
[email protected]216813952011-05-19 22:21:261146 }
1147}
1148
1149void TabContents::OnUpdateZoomLimits(int minimum_percent,
1150 int maximum_percent,
1151 bool remember) {
1152 minimum_zoom_percent_ = minimum_percent;
1153 maximum_zoom_percent_ = maximum_percent;
1154 temporary_zoom_settings_ = !remember;
1155}
1156
[email protected]3a29a6e2011-08-24 18:26:211157void TabContents::OnEnumerateDirectory(int request_id,
1158 const FilePath& path) {
1159 delegate()->EnumerateDirectory(this, request_id, path);
1160}
1161
[email protected]7d189022011-08-25 22:54:201162void TabContents::OnJSOutOfMemory() {
1163 delegate()->JSOutOfMemory(this);
1164}
1165
1166void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1167 const GURL& url,
1168 const string16& title) {
1169 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1170}
1171
[email protected]b888919c2011-09-02 00:32:161172void TabContents::OnFindReply(int request_id,
1173 int number_of_matches,
1174 const gfx::Rect& selection_rect,
1175 int active_match_ordinal,
1176 bool final_update) {
1177 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1178 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001179 // Send a notification to the renderer that we are ready to receive more
1180 // results from the scoping effort of the Find operation. The FindInPage
1181 // scoping is asynchronous and periodically sends results back up to the
1182 // browser using IPC. In an effort to not spam the browser we have the
1183 // browser send an ACK for each FindReply message and have the renderer
1184 // queue up the latest status message while waiting for this ACK.
1185 render_view_host()->Send(
1186 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161187}
1188
[email protected]d952a052011-09-06 18:42:451189void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1190 delegate()->CrashedPlugin(this, plugin_path);
1191}
1192
[email protected]7fc4bbb2011-09-08 21:23:101193void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1194 bool blocked_by_policy) {
1195 // Notify observers about navigation.
1196 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1197 AppCacheAccessed(manifest_url, blocked_by_policy));
1198}
1199
[email protected]96d185d2009-04-24 03:28:541200// Notifies the RenderWidgetHost instance about the fact that the page is
1201// loading, or done loading and calls the base implementation.
1202void TabContents::SetIsLoading(bool is_loading,
1203 LoadNotificationDetails* details) {
1204 if (is_loading == is_loading_)
1205 return;
1206
1207 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211208 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541209 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561210 upload_size_ = 0;
1211 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541212 }
1213
1214 render_manager_.SetIsLoading(is_loading);
1215
1216 is_loading_ = is_loading;
1217 waiting_for_response_ = is_loading;
1218
[email protected]6ebdc9b2010-09-27 16:55:571219 if (delegate_)
1220 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351221 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541222
[email protected]432115822011-07-10 15:52:271223 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1224 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071225 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541226 if (details)
[email protected]6c2381d2011-10-19 02:52:531227 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071228 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531229 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541230 det);
1231}
1232
[email protected]d0980792011-02-13 19:41:401233WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581234 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541235 // that goes along with it to control the basic flags. For example, we want to
1236 // show the pending URL in the URL bar, so we want the display_url flag to
1237 // be from the pending entry.
1238 //
1239 // The confusion comes because there are multiple possibilities for the
1240 // initial load in a tab as a side effect of the way the RenderViewHostManager
1241 // works.
1242 //
[email protected]e0112912011-02-02 22:54:351243 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541244 // the pending one, and we want it to apply here.
1245 //
1246 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1247 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581248 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351249 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541250 //
1251 // This condition handles all of these cases:
1252 //
1253 // - First load in first tab: no committed nav entry + pending nav entry +
1254 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351255 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541256 //
1257 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351258 // no pending Web UI:
1259 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541260 //
1261 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351262 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541263 //
1264 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351265 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541266 if (controller_.pending_entry() &&
1267 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581268 render_manager_.pending_web_ui()))
1269 return render_manager_.pending_web_ui();
1270 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541271}
[email protected]420ae012009-04-24 05:16:321272
[email protected]1fd1a502011-03-30 16:55:561273WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371274 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1275 GetURL());
[email protected]1fd1a502011-03-30 16:55:561276}
1277
[email protected]420ae012009-04-24 05:16:321278void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131279 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321280 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561281 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381282 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441283 // that opened the window, as long as both renderers have the same
1284 // privileges.
[email protected]1fd1a502011-03-30 16:55:561285 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1286 WebUI* web_ui = content::GetContentClient()->browser()->
1287 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581288 // web_ui might be NULL if the URL refers to a non-existent extension.
1289 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401290 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581291 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441292 }
1293 }
[email protected]1fd1a502011-03-30 16:55:561294 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441295 }
1296
[email protected]4e697b042011-07-08 06:44:561297 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321298 // Clear the status bubble. This is a workaround for a bug where WebKit
1299 // doesn't let us know that the cursor left an element during a
1300 // transition (this is also why the mouse cursor remains as a hand after
1301 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1302 // clear the bubble when a user navigates to a named anchor in the same
1303 // page.
1304 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321305 }
1306
[email protected]a6e82fc2010-02-24 22:28:141307 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471308 // Once the main frame is navigated, we're no longer considered to have
1309 // displayed insecure content.
1310 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171311 }
[email protected]ce5c4502009-05-06 16:46:111312
[email protected]3c9e1872010-11-18 16:17:491313 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171314 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041315 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321316}
1317
1318void TabContents::DidNavigateAnyFramePostCommit(
1319 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131320 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321321 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071322 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321323 // a malicious script from spamming messages, since the script could just
1324 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551325 if (dialog_creator_) {
1326 dialog_creator_->ResetJavaScriptState(this);
1327 dialog_creator_ = NULL;
1328 }
[email protected]420ae012009-04-24 05:16:321329
[email protected]3c9e1872010-11-18 16:17:491330 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171331 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041332 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321333}
1334
[email protected]74ce1ad2011-12-16 21:51:461335void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1336 // If we are creating a RVH for a restored controller, then we need to make
1337 // sure the RenderView starts with a next_page_id_ larger than the number
1338 // of restored entries. This must be called before the RenderView starts
1339 // navigating (to avoid a race between the browser updating max_page_id and
1340 // the renderer updating next_page_id_). Because of this, we only call this
1341 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]420ae012009-04-24 05:16:321342 int max_restored_page_id = controller_.max_restored_page_id();
[email protected]74ce1ad2011-12-16 21:51:461343 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1344 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321345}
1346
[email protected]6b2f7a82011-04-25 19:30:511347bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571348 const string16& title) {
[email protected]420ae012009-04-24 05:16:321349 // For file URLs without a title, use the pathname instead. In the case of a
1350 // synthesized title, we don't want the update to count toward the "one set
1351 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511352 string16 final_title;
[email protected]420ae012009-04-24 05:16:321353 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091354 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511355 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321356 explicit_set = false; // Don't count synthetic titles toward the set limit.
1357 } else {
[email protected]acafd272011-07-26 17:35:571358 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321359 explicit_set = true;
1360 }
1361
[email protected]987fc3a2011-05-26 14:18:091362 // If a page is created via window.open and never navigated,
1363 // there will be no navigation entry. In this situation,
1364 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1365 if (entry) {
1366 if (final_title == entry->title())
1367 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321368
[email protected]987fc3a2011-05-26 14:18:091369 entry->set_title(final_title);
1370 } else {
1371 if (page_title_when_no_navigation_entry_ == final_title)
1372 return false; // Nothing changed, don't bother.
1373
1374 page_title_when_no_navigation_entry_ = final_title;
1375 }
[email protected]420ae012009-04-24 05:16:321376
[email protected]420ae012009-04-24 05:16:321377 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231378 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321379
[email protected]105bb0f2011-05-24 17:12:141380 TitleUpdatedDetails details(entry, explicit_set);
1381
[email protected]ad50def52011-10-19 23:17:071382 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271383 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531384 content::Source<TabContents>(this),
1385 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041386
[email protected]420ae012009-04-24 05:16:321387 return true;
1388}
1389
1390void TabContents::NotifySwapped() {
1391 // After sending out a swap notification, we need to send a disconnect
1392 // notification so that clients that pick up a pointer to |this| can NULL the
1393 // pointer. See Bug 1230284.
1394 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071395 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271396 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531397 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071398 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321399}
1400
1401void TabContents::NotifyConnected() {
1402 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071403 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271404 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531405 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071406 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321407}
1408
1409void TabContents::NotifyDisconnected() {
1410 if (!notify_disconnection_)
1411 return;
1412
1413 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071414 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271415 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531416 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071417 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321418}
1419
[email protected]8d3347f2009-07-09 22:00:211420RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321421 return view_.get();
1422}
1423
[email protected]8d3347f2009-07-09 22:00:211424RenderViewHostDelegate::RendererManagement*
1425TabContents::GetRendererManagementDelegate() {
1426 return &render_manager_;
1427}
1428
[email protected]daf82f82011-10-31 22:35:311429content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371430 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461431 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511432}
1433
[email protected]57c6a652009-05-04 07:58:341434TabContents* TabContents::GetAsTabContents() {
1435 return this;
1436}
1437
[email protected]da4dfc42011-10-12 15:53:561438content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431439 return view_type_;
[email protected]7b291f92009-08-14 05:43:531440}
1441
[email protected]420ae012009-04-24 05:16:321442void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071443 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271444 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531445 content::Source<TabContents>(this),
1446 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321447 NavigationEntry* entry = controller_.GetActiveEntry();
1448 if (!entry)
1449 return;
1450
1451 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351452 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561453 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581454 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321455
1456 if (entry->IsViewSourceMode()) {
1457 // Put the renderer in view source mode.
1458 render_view_host->Send(
1459 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1460 }
[email protected]0666aef2009-05-13 19:48:081461
1462 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261463
1464 FOR_EACH_OBSERVER(
1465 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321466}
1467
1468void TabContents::RenderViewReady(RenderViewHost* rvh) {
1469 if (rvh != render_view_host()) {
1470 // Don't notify the world, since this came from a renderer in the
1471 // background.
1472 return;
1473 }
1474
1475 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301476 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231477 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301478
1479 // Restore the focus to the tab (otherwise the focus will be on the top
1480 // window).
[email protected]484ae5912010-09-29 19:16:141481 if (was_crashed && !FocusLocationBarByDefault() &&
1482 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301483 Focus();
[email protected]484ae5912010-09-29 19:16:141484 }
[email protected]32ded2212011-11-10 18:51:431485
1486 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321487}
1488
[email protected]443b80e2010-12-14 00:42:231489void TabContents::RenderViewGone(RenderViewHost* rvh,
1490 base::TerminationStatus status,
1491 int error_code) {
[email protected]420ae012009-04-24 05:16:321492 if (rvh != render_view_host()) {
1493 // The pending page's RenderViewHost is gone.
1494 return;
1495 }
1496
1497 SetIsLoading(false, NULL);
1498 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231499 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541500 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321501
[email protected]9cddb1a22011-11-15 15:04:271502 FOR_EACH_OBSERVER(TabContentsObserver,
1503 observers_,
1504 RenderViewGone(crashed_status()));
[email protected]420ae012009-04-24 05:16:321505}
1506
[email protected]2e4633c2009-07-09 16:58:061507void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481508 render_manager_.RenderViewDeleted(rvh);
[email protected]483623eb2011-10-25 09:30:001509 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061510}
1511
[email protected]420ae012009-04-24 05:16:321512void TabContents::DidNavigate(RenderViewHost* rvh,
1513 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581514 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321515 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371516
[email protected]420ae012009-04-24 05:16:321517 // Update the site of the SiteInstance if it doesn't have one yet.
1518 if (!GetSiteInstance()->has_site())
1519 GetSiteInstance()->SetSite(params.url);
1520
1521 // Need to update MIME type here because it's referred to in
1522 // UpdateNavigationCommands() called by RendererDidNavigate() to
1523 // determine whether or not to enable the encoding menu.
1524 // It's updated only for the main frame. For a subframe,
1525 // RenderView::UpdateURL does not set params.contents_mime_type.
1526 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1527 // TODO(jungshik): Add a test for the encoding menu to avoid
1528 // regressing it again.
[email protected]2905f742011-10-13 03:51:581529 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321530 contents_mime_type_ = params.contents_mime_type;
1531
[email protected]8286f51a2011-05-31 17:39:131532 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001533 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391534
[email protected]a9c0bfe2010-09-17 08:35:221535 // Send notification about committed provisional loads. This notification is
1536 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1537 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081538 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071539 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1540 // that is not recorded in the navigation history. For the purpose of
1541 // tracking navigation events, we treat this event as a sub frame navigation
1542 // event.
1543 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581544 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221545 // Whether or not a page transition was triggered by going backward or
1546 // forward in the history is only stored in the navigation controller's
1547 // entry list.
1548 if (did_navigate &&
1549 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581550 content::PAGE_TRANSITION_FORWARD_BACK)) {
1551 transition_type = content::PageTransitionFromInt(
1552 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221553 }
[email protected]0d60f0192011-04-14 12:40:101554 // Notify observers about the commit of the provisional load.
1555 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1556 DidCommitProvisionalLoadForFrame(params.frame_id,
1557 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221558 }
1559
[email protected]76543b92009-08-31 17:27:451560 if (!did_navigate)
1561 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321562
1563 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1564 // for the appropriate notification (best) or you can add it to
1565 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1566 // necessary, please).
1567
1568 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001569 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321570 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481571 if (delegate())
1572 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001573 }
[email protected]420ae012009-04-24 05:16:321574 DidNavigateAnyFramePostCommit(rvh, details, params);
1575}
1576
1577void TabContents::UpdateState(RenderViewHost* rvh,
1578 int32 page_id,
1579 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151580 // Ensure that this state update comes from either the active RVH or one of
1581 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1582 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321583
1584 // We must be prepared to handle state updates for any page, these occur
1585 // when the user is scrolling and entering form data, as well as when we're
1586 // leaving a page, in which case our state may have already been moved to
1587 // the next page. The navigation controller will look up the appropriate
1588 // NavigationEntry and update it when it is notified via the delegate.
1589
1590 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151591 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321592 if (entry_index < 0)
1593 return;
1594 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1595
1596 if (state == entry->content_state())
1597 return; // Nothing to update.
1598 entry->set_content_state(state);
1599 controller_.NotifyEntryChanged(entry, entry_index);
1600}
1601
1602void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571603 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461604 const string16& title,
1605 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321606 // If we have a title, that's a pretty good indication that we've started
1607 // getting useful data.
1608 SetNotWaitingForResponse();
1609
1610 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481611 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581612 page_id);
[email protected]987fc3a2011-05-26 14:18:091613
[email protected]a49e10b2011-08-01 23:57:461614 // TODO(evan): make use of title_direction.
1615 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091616 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321617 return;
1618
1619 // Broadcast notifications when the UI should be updated.
1620 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031621 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321622}
1623
[email protected]420ae012009-04-24 05:16:321624void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401625 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321626 set_encoding(encoding);
1627}
1628
1629void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1630 if (delegate())
[email protected]d952a052011-09-06 18:42:451631 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321632}
1633
[email protected]420ae012009-04-24 05:16:321634void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291635 // The UI may be in an event-tracking loop, such as between the
1636 // mouse-down and mouse-up in text selection or a button click.
1637 // Defer the close until after tracking is complete, so that we
1638 // don't free objects out from under the UI.
1639 // TODO(shess): This could probably be integrated with the
1640 // IsDoingDrag() test below. Punting for now because I need more
1641 // research to understand how this impacts platforms other than Mac.
1642 // TODO(shess): This could get more fine-grained. For instance,
1643 // closing a tab in another window while selecting text in the
1644 // current window's Omnibox should be just fine.
1645 if (view()->IsEventTracking()) {
1646 view()->CloseTabAfterEventTracking();
1647 return;
1648 }
1649
[email protected]24a4d1062009-07-10 23:10:421650 // If we close the tab while we're in the middle of a drag, we'll crash.
1651 // Instead, cancel the drag and close it as soon as the drag ends.
1652 if (view()->IsDoingDrag()) {
1653 view()->CancelDragAndCloseTab();
1654 return;
1655 }
1656
[email protected]420ae012009-04-24 05:16:321657 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1658 if (delegate() && rvh == render_view_host())
1659 delegate()->CloseContents(this);
1660}
1661
[email protected]cd9ed79d2011-11-15 19:22:571662void TabContents::SwappedOut(RenderViewHost* rvh) {
1663 if (delegate() && rvh == render_view_host())
1664 delegate()->SwappedOut(this);
1665}
1666
[email protected]420ae012009-04-24 05:16:321667void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141668 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321669 delegate()->MoveContents(this, new_bounds);
1670}
1671
[email protected]7ab1e7d62009-10-14 23:32:011672void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321673 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491674
[email protected]c40d6232011-03-25 00:16:211675 if (delegate() && content_restrictions_) {
1676 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211677 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001678 }
[email protected]3c9e1872010-11-18 16:17:491679
1680 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171681 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321682}
1683
[email protected]7ab1e7d62009-10-14 23:32:011684void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321685 scoped_ptr<LoadNotificationDetails> details;
1686
1687 NavigationEntry* entry = controller_.GetActiveEntry();
1688 // An entry may not exist for a stop when loading an initial blank page or
1689 // if an iframe injected by script into a blank page finishes loading.
1690 if (entry) {
[email protected]420ae012009-04-24 05:16:321691 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1692
1693 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541694 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321695 entry->transition_type(),
1696 elapsed,
1697 &controller_,
1698 controller_.GetCurrentEntryIndex()));
1699 }
1700
[email protected]420ae012009-04-24 05:16:321701 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491702
1703 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171704 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321705}
1706
[email protected]c95fa8b2011-04-28 20:26:161707void TabContents::DidCancelLoading() {
1708 controller_.DiscardNonCommittedEntries();
1709
1710 // Update the URL display.
1711 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1712}
1713
[email protected]1a3c3cb2010-12-16 21:03:401714void TabContents::DidChangeLoadProgress(double progress) {
1715 if (delegate())
1716 delegate()->LoadProgressChanged(progress);
1717}
1718
[email protected]952a68e2011-11-17 00:36:101719void TabContents::DocumentAvailableInMainFrame(
1720 RenderViewHost* render_view_host) {
1721 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1722 DocumentAvailableInMainFrame());
1723}
1724
[email protected]25497492010-09-11 15:15:081725void TabContents::DocumentOnLoadCompletedInMainFrame(
1726 RenderViewHost* render_view_host,
1727 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071728 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271729 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531730 content::Source<TabContents>(this),
1731 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081732}
1733
[email protected]ae5184d62011-10-06 19:25:581734void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151735 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581736 WindowOpenDisposition disposition,
1737 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481738 // Delegate to RequestTransferURL because this is just the generic
1739 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581740 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481741 GlobalRequestID());
1742}
1743
1744void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581745 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481746 WindowOpenDisposition disposition,
1747 int64 source_frame_id,
1748 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581749 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581750 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581751 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351752 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321753 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1754 // generated suggestions).
1755 //
[email protected]e0112912011-02-02 22:54:351756 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161757 // want web sites to see a referrer of "chrome://blah" (and some
1758 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321759 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581760 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481761 render_manager_.web_ui()->link_transition_type(),
1762 false /* is_renderer_initiated */);
1763 params.transferred_global_request_id = old_request_id;
1764 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581765 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321766 } else {
[email protected]4ad5d77d2011-12-03 02:00:481767 OpenURLParams params(url, referrer, disposition,
1768 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1769 params.transferred_global_request_id = old_request_id;
1770 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581771 }
1772 if (new_contents) {
1773 // Notify observers.
1774 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1775 DidOpenRequestedURL(new_contents,
1776 url,
1777 referrer,
1778 disposition,
1779 transition_type,
1780 source_frame_id));
[email protected]420ae012009-04-24 05:16:321781 }
1782}
1783
[email protected]420ae012009-04-24 05:16:321784void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151785 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411786 const string16& message,
1787 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321788 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471789 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321790 IPC::Message* reply_msg,
1791 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071792 // Suppress JavaScript dialogs when requested. Also suppress messages when
1793 // showing an interstitial as it's shown over the previous page and we don't
1794 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501795 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151796 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501797 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071798 !delegate_ ||
1799 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321800
1801 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341802 content::JavaScriptDialogCreator::TitleType title_type;
1803 string16 title;
1804
1805 if (!frame_url.has_host()) {
1806 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1807 } else {
1808 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1809 title = net::FormatUrl(
1810 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201811 content::GetContentClient()->browser()->GetAcceptLangs(
1812 this->browser_context()));
[email protected]b627d9a2011-06-28 14:06:341813 }
1814
[email protected]2e5b90c2011-08-16 21:11:551815 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1816 dialog_creator_->RunJavaScriptDialog(this,
1817 title_type,
1818 title,
[email protected]269f86d2011-12-07 02:43:471819 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551820 message,
1821 default_prompt,
1822 reply_msg,
1823 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321824 }
[email protected]3ab9cb82011-06-03 18:02:071825
1826 if (suppress_this_message) {
1827 // If we are suppressing messages, just reply as if the user immediately
1828 // pressed "Cancel".
1829 OnDialogClosed(reply_msg, false, string16());
1830 }
1831
1832 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321833}
1834
[email protected]992db4c2011-05-12 15:37:151835void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411836 const string16& message,
[email protected]420ae012009-04-24 05:16:321837 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291838 if (delegate())
1839 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071840
1841 bool suppress_this_message =
1842 rvh->is_swapped_out() ||
1843 !delegate_ ||
1844 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151845 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411846 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501847 return;
1848 }
[email protected]3ab9cb82011-06-03 18:02:071849
[email protected]7ab1e7d62009-10-14 23:32:011850 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551851 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1852 dialog_creator_->RunBeforeUnloadDialog(this,
1853 message,
1854 reply_msg);
[email protected]420ae012009-04-24 05:16:321855}
1856
[email protected]420ae012009-04-24 05:16:321857WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081858 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361859 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]5092c282011-10-29 21:48:371860 render_view_host());
[email protected]447021c2010-09-08 21:29:081861
[email protected]b8299c12011-06-03 19:52:281862 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211863 // chrome-devtools: pages (unless it's specifically allowed).
1864 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571865 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281866 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:301867 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1868 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211869 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081870 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431871 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081872 }
1873
1874 return web_prefs;
[email protected]420ae012009-04-24 05:16:321875}
1876
[email protected]7d472472011-01-22 01:30:251877void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271878 // Notify observers.
1879 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221880
1881 ResourceDispatcherHost* rdh =
1882 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1883 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301884 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251885}
1886
[email protected]fa1cf0b82010-01-15 21:49:441887void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441888 // Notify observers.
1889 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441890}
1891
[email protected]420ae012009-04-24 05:16:321892void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1893 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151894 // Don't show hung renderer dialog for a swapped out RVH.
1895 if (rvh != render_view_host())
1896 return;
1897
[email protected]e5fc1632011-08-08 07:51:531898 // Ignore renderer unresponsive event if debugger is attached to the tab
1899 // since the event may be a result of the renderer sitting on a breakpoint.
1900 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:441901 DevToolsAgentHost* agent =
1902 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
1903 if (agent &&
1904 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:531905 return;
1906
[email protected]420ae012009-04-24 05:16:321907 if (is_during_unload) {
1908 // Hang occurred while firing the beforeunload/unload handler.
1909 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111910 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321911
1912 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1913 return;
1914
1915 // If the tab hangs in the beforeunload/unload handler there's really
1916 // nothing we can do to recover. Pretend the unload listeners have
1917 // all fired and close the tab. If the hang is in the beforeunload handler
1918 // then the user will not have the option of cancelling the close.
1919 Close(rvh);
1920 return;
1921 }
1922
[email protected]55452902011-06-01 21:57:471923 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1924 return;
1925
1926 if (delegate())
1927 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321928}
1929
1930void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471931 if (delegate())
1932 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321933}
1934
1935void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211936 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561937 uint64 upload_position,
1938 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321939 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561940 upload_position_ = upload_position;
1941 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501942 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:201943 content::GetContentClient()->browser()->GetAcceptLangs(
1944 this->browser_context()));
[email protected]9c235f042011-08-10 22:28:211945 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321946 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511947 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501948 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321949}
1950
[email protected]7d472472011-01-22 01:30:251951void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441952 if (delegate())
[email protected]55452902011-06-01 21:57:471953 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251954}
1955
[email protected]420ae012009-04-24 05:16:321956void TabContents::BeforeUnloadFiredFromRenderManager(
1957 bool proceed,
1958 bool* proceed_to_fire_unload) {
1959 if (delegate())
1960 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1961}
1962
[email protected]3a3d47472010-07-15 21:03:541963void TabContents::DidStartLoadingFromRenderManager(
1964 RenderViewHost* render_view_host) {
1965 DidStartLoading();
1966}
1967
1968void TabContents::RenderViewGoneFromRenderManager(
1969 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231970 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1971 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541972}
1973
[email protected]420ae012009-04-24 05:16:321974void TabContents::UpdateRenderViewSizeForRenderManager() {
1975 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261976 gfx::Size size = view_->GetContainerSize();
1977 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1978 // here during container initialization and normal window size will be set
1979 // later. In case of tab duplication this resizing to 0x0 prevents setting
1980 // normal size later so just ignore it.
1981 if (!size.IsEmpty())
1982 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321983}
1984
[email protected]3a3d47472010-07-15 21:03:541985void TabContents::NotifySwappedFromRenderManager() {
1986 NotifySwapped();
1987}
1988
1989NavigationController& TabContents::GetControllerForRenderManager() {
1990 return controller();
1991}
1992
[email protected]d0980792011-02-13 19:41:401993WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561994 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321995}
1996
1997NavigationEntry*
1998TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1999 return controller_.GetLastCommittedEntry();
2000}
2001
2002bool TabContents::CreateRenderViewForRenderManager(
2003 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442004 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322005 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522006
[email protected]420ae012009-04-24 05:16:322007 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442008 if (rwh_view)
2009 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322010
[email protected]74ce1ad2011-12-16 21:51:462011 // Make sure we use the correct starting page_id in the new RenderView.
2012 UpdateMaxPageIDIfNecessary(render_view_host);
2013 int32 max_page_id =
2014 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2015
2016 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522017 return false;
2018
[email protected]e60c0232011-11-11 19:56:352019#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502020 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2021 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442022 if (rwh_view) {
2023 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2024 render_widget_host->WasResized();
2025 }
[email protected]f8233cc2011-05-31 20:24:502026#endif
2027
[email protected]420ae012009-04-24 05:16:322028 return true;
2029}
2030
[email protected]3ab9cb82011-06-03 18:02:072031void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2032 bool success,
2033 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542034 if (is_showing_before_unload_dialog_ && !success) {
2035 // If a beforeunload dialog is canceled, we need to stop the throbber from
2036 // spinning, since we forced it to start spinning in Navigate.
2037 DidStopLoading();
2038
2039 tab_close_start_time_ = base::TimeTicks();
2040 }
2041 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:412042 render_view_host()->JavaScriptDialogClosed(reply_msg,
2043 success,
[email protected]3ab9cb82011-06-03 18:02:072044 user_input);
[email protected]beb440c2009-11-06 04:08:542045}
2046
[email protected]0b08add2011-11-29 03:27:062047gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072048 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542049}
2050
[email protected]a1e97f02011-06-30 14:04:342051void TabContents::OnDialogShown() {
2052 Activate();
[email protected]3a3d47472010-07-15 21:03:542053}
2054
[email protected]41fc0322009-09-04 22:23:402055void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122056 encoding_ = content::GetContentClient()->browser()->
2057 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102058}
[email protected]f45d2a72010-03-08 23:28:352059
[email protected]33f74972010-12-08 16:40:362060void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2061 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442062 // Can be NULL during tests.
2063 if (rwh_view)
2064 rwh_view->SetSize(view()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362065}
[email protected]e9621112011-10-17 05:38:372066
2067bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
2068 return render_view_host() ?
2069 render_view_host()->GotResponseToLockMouseRequest(allowed) : false;
2070}