blob: bfdbd979f06ac5f70a0ab3e7d93dd50463de2015 [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]3d7474ff2011-07-27 17:47:3716#include "content/browser/browser_context.h"
[email protected]567812d2011-02-24 17:40:5017#include "content/browser/child_process_security_policy.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]71bf3f5e2011-08-15 21:05:2219#include "content/browser/download/download_manager.h"
[email protected]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5021#include "content/browser/host_zoom_map.h"
22#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]ada02b312011-12-01 21:54:5323#include "content/browser/intents/intents_host_impl.h"
[email protected]37a72af2011-06-13 05:42:0124#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0425#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3026#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5027#include "content/browser/renderer_host/render_view_host.h"
28#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2229#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5030#include "content/browser/renderer_host/resource_request_details.h"
31#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4432#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1333#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4434#include "content/browser/tab_contents/navigation_entry.h"
35#include "content/browser/tab_contents/provisional_load_details.h"
36#include "content/browser/tab_contents/tab_contents_delegate.h"
37#include "content/browser/tab_contents/tab_contents_observer.h"
38#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1439#include "content/browser/tab_contents/title_updated_details.h"
[email protected]afd1e522011-04-27 23:29:5940#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5641#include "content/browser/webui/web_ui_factory.h"
[email protected]ce9751942011-09-21 01:57:2442#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0243#include "content/common/view_messages.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]54087fe2011-10-28 22:02:4846#include "content/public/browser/notification_service.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]d5e311b2010-07-20 17:15:0355#include "webkit/glue/password_form.h"
[email protected]ce9751942011-09-21 01:57:2456#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3157#include "webkit/glue/webpreferences.h"
58
59#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1260#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3161#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0062
[email protected]420ae012009-04-24 05:16:3263// Cross-Site Navigations
64//
65// If a TabContents is told to navigate to a different web site (as determined
66// by SiteInstance), it will replace its current RenderViewHost with a new
67// RenderViewHost dedicated to the new SiteInstance. This works as follows:
68//
69// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4670// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3271// - The pending RVH is "suspended," so that no navigation messages are sent to
72// its renderer until the onbeforeunload JavaScript handler has a chance to
73// run in the current RVH.
74// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
75// that it has a pending cross-site request. ResourceDispatcherHost will
76// check for this when the response arrives.
77// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4678// cancel all the pending logic. Otherwise we allow the pending RVH to send
79// the navigation request to its renderer.
80// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
81// main resource load on the pending RVH. It checks CrossSiteRequestManager
82// to see that it is a cross-site request, and installs a
83// CrossSiteResourceHandler.
84// - When RDH receives a response, the BufferedResourceHandler determines
85// whether it is a download. If so, it sends a message to the new renderer
86// causing it to cancel the request, and the download proceeds. For now, the
87// pending RVH remains until the next DidNavigate event for this TabContents.
88// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3289// - After RDH receives a response and determines that it is safe and not a
90// download, it pauses the response to first run the old page's onunload
91// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1592// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3293// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1594// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3295// the ResourceDispatcherHost, who unpauses the response. Data is then sent
96// to the pending RVH.
97// - The pending renderer sends a FrameNavigate message that invokes the
98// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4699// pending RVH.
[email protected]992db4c2011-05-12 15:37:15100// - The previous renderer is kept swapped out in RenderViewHostManager in case
101// the user goes back. The process only stays live if another tab is using
102// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02103//
104// It is possible that we trigger a new navigation after we have received
105// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
106// In this case the old RVH has been swapped out but the new one has not
107// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
108// of the old RVH.
[email protected]420ae012009-04-24 05:16:32109
[email protected]0e12d7d2011-12-01 16:21:44110using content::DevToolsAgentHost;
111using content::DevToolsAgentHostRegistry;
112using content::DevToolsManagerImpl;
113
[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();
163 params->referrer = entry.referrer();
164 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]d5f942ba2008-09-26 19:30:34199 max_page_id_(-1),
[email protected]9c235f042011-08-10 22:28:21200 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56201 upload_size_(0),
202 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47203 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57204 capturing_contents_(false),
205 is_being_destroyed_(false),
206 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55207 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57208#if defined(OS_WIN)
209 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
210#endif
[email protected]7ab1e7d62009-10-14 23:32:01211 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56212 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38213 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25214 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01215 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25216 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01217 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00218 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43219 content_restrictions_(0),
220 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37221 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32222
[email protected]34ac70502009-09-25 17:07:23223 // We have the initial size of the view be based on the size of the passed in
224 // tab contents (normally a tab from the same window).
225 view_->CreateView(base_tab_contents ?
226 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00227
228#if defined(ENABLE_JAVA_BRIDGE)
229 java_bridge_dispatcher_host_manager_.reset(
230 new JavaBridgeDispatcherHostManager(this));
231#endif
[email protected]332af7732009-03-11 13:21:35232}
initial.commit09911bf2008-07-26 23:55:29233
234TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32235 is_being_destroyed_ = true;
236
[email protected]3ab9cb82011-06-03 18:02:07237 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55238 if (dialog_creator_)
239 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07240
[email protected]420ae012009-04-24 05:16:32241 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32242
[email protected]420ae012009-04-24 05:16:32243 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07244 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27245 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53246 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07247 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32248
249 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07250#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32251 // If we still have a window handle, destroy it. GetNativeView can return
252 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42253 if (GetNativeView()) {
254 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44255 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42256 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42257 }
[email protected]420ae012009-04-24 05:16:32258#endif
[email protected]7ab1e7d62009-10-14 23:32:01259
260 // OnCloseStarted isn't called in unit tests.
261 if (!tab_close_start_time_.is_null()) {
262 UMA_HISTOGRAM_TIMES("Tab.Close",
263 base::TimeTicks::Now() - tab_close_start_time_);
264 }
[email protected]b5a1d11c2011-02-17 03:09:42265
[email protected]07d490bc2011-03-07 17:05:26266 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08267
[email protected]1de2b8b2011-06-29 19:38:46268 set_delegate(NULL);
269}
270
271// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
272void TabContents::set_delegate(TabContentsDelegate* delegate) {
273 if (delegate == delegate_)
274 return;
275 if (delegate_)
276 delegate_->Detach(this);
277 delegate_ = delegate;
278 if (delegate_)
279 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42280}
281
[email protected]724159a2010-12-30 01:11:18282bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17283 if (web_ui() && web_ui()->OnMessageReceived(message))
284 return true;
285
[email protected]585b30362011-01-28 02:30:17286 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
287 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10288 while ((observer = it.GetNext()) != NULL)
289 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53290 return true;
[email protected]403415a2011-01-10 18:57:53291
[email protected]724159a2010-12-30 01:11:18292 bool handled = true;
293 bool message_is_ok = true;
294 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58295 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
296 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24297 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
298 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18299 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
300 OnDidStartProvisionalLoadForFrame)
301 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
302 OnDidRedirectProvisionalLoad)
303 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
304 OnDidFailProvisionalLoadWithError)
305 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
306 OnDidLoadResourceFromMemoryCache)
307 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
308 OnDidDisplayInsecureContent)
309 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
310 OnDidRunInsecureContent)
311 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
312 OnDocumentLoadedInFrame)
313 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17314 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
315 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25316 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26317 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
318 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]c7dd2f62011-07-18 15:57:59319 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21320 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20321 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
322 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
323 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16324 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45325 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10326 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18327 IPC_MESSAGE_UNHANDLED(handled = false)
328 IPC_END_MESSAGE_MAP_EX()
329
330 if (!message_is_ok) {
331 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
332 GetRenderProcessHost()->ReceivedBadMessage();
333 }
334
335 return handled;
336}
337
[email protected]6c2e472f2011-08-24 23:26:18338void TabContents::RunFileChooser(
339 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23340 const content::FileChooserParams& params) {
[email protected]6c2e472f2011-08-24 23:26:18341 delegate()->RunFileChooser(this, params);
342}
343
[email protected]f3b1a082011-11-18 00:34:30344content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03345 if (render_manager_.current_host())
346 return render_manager_.current_host()->process();
347 else
348 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16349}
350
[email protected]d5f942ba2008-09-26 19:30:34351const GURL& TabContents::GetURL() const {
352 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57353 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54354 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34355}
356
[email protected]96d185d2009-04-24 03:28:54357const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55358 // Transient entries take precedence. They are used for interstitial pages
359 // that are shown on top of existing pages.
360 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08361 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20362 content::GetContentClient()->browser()->GetAcceptLangs(
363 this->browser_context());
[email protected]45d0ef7f2011-01-05 13:46:23364 if (entry) {
[email protected]b5cca982011-05-26 04:42:08365 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23366 }
[email protected]7ade2732011-02-10 00:13:58367 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
368 render_manager_.pending_web_ui() : render_manager_.web_ui();
369 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54370 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55371 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54372 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35373 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58374 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54375 if (!title.empty())
376 return title;
377 }
378 }
379
380 // We use the title for the last committed entry rather than a pending
381 // navigation entry. For example, when the user types in a URL, we want to
382 // keep the old page's title until the new load has committed and we get a new
383 // title.
[email protected]96d185d2009-04-24 03:28:54384 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23385 if (entry) {
[email protected]b5cca982011-05-26 04:42:08386 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23387 }
[email protected]987fc3a2011-05-26 14:18:09388
389 // |page_title_when_no_navigation_entry_| is finally used
390 // if no title cannot be retrieved.
391 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54392}
393
[email protected]d5f942ba2008-09-26 19:30:34394int32 TabContents::GetMaxPageID() {
395 if (GetSiteInstance())
396 return GetSiteInstance()->max_page_id();
397 else
398 return max_page_id_;
399}
400
401void TabContents::UpdateMaxPageID(int32 page_id) {
402 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34403 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34404 // testing.
405 if (GetSiteInstance())
406 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16407 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34408}
409
[email protected]96d185d2009-04-24 03:28:54410SiteInstance* TabContents::GetSiteInstance() const {
411 return render_manager_.current_host()->site_instance();
412}
413
[email protected]77362eb2011-08-01 17:18:38414SiteInstance* TabContents::GetPendingSiteInstance() const {
415 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
416 render_manager_.pending_render_view_host() :
417 render_manager_.current_host();
418 return dest_rvh->site_instance();
419}
420
[email protected]585b30362011-01-28 02:30:17421void TabContents::AddObserver(TabContentsObserver* observer) {
422 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49423}
424
[email protected]585b30362011-01-28 02:30:17425void TabContents::RemoveObserver(TabContentsObserver* observer) {
426 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49427}
428
[email protected]443b80e2010-12-14 00:42:23429void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
430 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34431 return;
432
[email protected]443b80e2010-12-14 00:42:23433 crashed_status_ = status;
434 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50435 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34436}
437
438void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
439 if (delegate_)
440 delegate_->NavigationStateChanged(this, changed_flags);
441}
442
[email protected]96d185d2009-04-24 03:28:54443void TabContents::DidBecomeSelected() {
444 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16445 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
446 if (rwhv) {
447 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43448#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16449 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43450#endif
451 }
[email protected]96d185d2009-04-24 03:28:54452
[email protected]5ac20162010-11-24 23:33:11453 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38454
455 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54456}
457
458void TabContents::WasHidden() {
459 if (!capturing_contents()) {
460 // |render_view_host()| can be NULL if the user middle clicks a link to open
461 // a tab in then background, then closes the tab before selecting it. This
462 // is because closing the tab calls TabContents::Destroy(), which removes
463 // the |render_view_host()|; then when we actually destroy the window,
464 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16465 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
466 if (rwhv)
467 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54468 }
469
[email protected]ad50def52011-10-19 23:17:07470 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27471 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53472 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07473 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54474}
475
[email protected]d5f942ba2008-09-26 19:30:34476void TabContents::Activate() {
477 if (delegate_)
478 delegate_->ActivateContents(this);
479}
480
[email protected]ea42e7782010-08-23 23:58:12481void TabContents::Deactivate() {
482 if (delegate_)
483 delegate_->DeactivateContents(this);
484}
485
[email protected]63954792011-07-11 04:17:48486void TabContents::LostCapture() {
487 if (delegate_)
488 delegate_->LostCapture();
489}
490
491bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
492 bool* is_keyboard_shortcut) {
493 return delegate_ &&
494 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
495}
496
497void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
498 if (delegate_)
499 delegate_->HandleKeyboardEvent(event);
500}
501
[email protected]32ded2212011-11-10 18:51:43502void TabContents::HandleMouseDown() {
503 if (delegate_)
504 delegate_->HandleMouseDown();
505}
506
[email protected]63954792011-07-11 04:17:48507void TabContents::HandleMouseUp() {
508 if (delegate_)
509 delegate_->HandleMouseUp();
510}
511
512void TabContents::HandleMouseActivate() {
513 if (delegate_)
514 delegate_->HandleMouseActivate();
515}
516
[email protected]8a5e0ca2011-08-25 06:30:47517void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
518 if (delegate_)
519 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
520}
521
[email protected]5d5f7af2011-10-01 01:38:12522bool TabContents::IsFullscreenForCurrentTab() const {
523 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
524}
525
[email protected]e9621112011-10-17 05:38:37526void TabContents::RequestToLockMouse() {
527 if (delegate_) {
528 delegate_->RequestToLockMouse(this);
529 } else {
530 GotResponseToLockMouseRequest(false);
531 }
532}
533
534void TabContents::LostMouseLock() {
535 if (delegate_)
536 delegate_->LostMouseLock();
537}
538
[email protected]0548c5352011-09-07 00:33:33539void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
540 if (delegate_)
541 delegate_->UpdatePreferredSize(this, pref_size);
542}
543
[email protected]32ded2212011-11-10 18:51:43544void TabContents::WebUISend(RenderViewHost* render_view_host,
545 const GURL& source_url,
546 const std::string& name,
547 const base::ListValue& args) {
548 if (delegate_)
549 delegate_->WebUISend(this, source_url, name, args);
550}
551
[email protected]96d185d2009-04-24 03:28:54552void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16553 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
554 if (rwhv)
555 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54556}
557
558void TabContents::HideContents() {
559 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
560 // our superclass HideContents(), because some callers want to be very picky
561 // about the order in which these get called. In addition to making the code
562 // here practically impossible to understand, this also means we end up
563 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34564 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54565 WasHidden();
566}
567
[email protected]5aab5e22010-12-08 22:13:29568bool TabContents::NeedToFireBeforeUnload() {
569 // TODO(creis): Should we fire even for interstitial pages?
570 return notify_disconnection() &&
571 !showing_interstitial_page() &&
572 !render_view_host()->SuddenTerminationAllowed();
573}
574
[email protected]00c37fc2011-08-02 00:22:50575// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25576TabContents* TabContents::OpenURL(const GURL& url,
577 const GURL& referrer,
578 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58579 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10580 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
581 DCHECK(referrer.is_empty());
[email protected]e47ae9472011-10-13 19:48:34582 return OpenURL(OpenURLParams(url, referrer, disposition, transition,
583 false));
[email protected]00c37fc2011-08-02 00:22:50584}
585
586TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49587 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50588 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49589 // Notify observers.
590 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50591 DidOpenURL(params.url, params.referrer,
592 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25593 return new_contents;
[email protected]1c642b52011-04-15 09:05:49594 }
[email protected]992e4542011-07-20 23:09:25595 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34596}
597
[email protected]1ccb3568d2010-02-19 10:51:16598bool TabContents::NavigateToPendingEntry(
599 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27600 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54601}
[email protected]96d185d2009-04-24 03:28:54602
[email protected]876bc832010-09-07 16:29:54603bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27604 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54605 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40606 // The renderer will reject IPC messages with URLs longer than
607 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27608 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40609 return false;
610
[email protected]dd11de52011-11-03 22:54:27611 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40612 if (!dest_render_view_host)
613 return false; // Unable to create the desired render view host.
614
[email protected]80a8fad2011-01-29 04:02:38615 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07616 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58617 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56618 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37619 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]dd11de52011-11-03 22:54:27620 entry.url());
[email protected]32ded2212011-11-10 18:51:43621#if defined(OS_CHROMEOS)
622 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
623#endif
[email protected]e091df82011-10-11 18:13:21624 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55625 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58626
[email protected]96d185d2009-04-24 03:28:54627 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44628 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
629 render_view_host(),
630 dest_render_view_host,
631 entry.url());
[email protected]96d185d2009-04-24 03:28:54632
633 // Used for page load time metrics.
634 current_load_start_ = base::TimeTicks::Now();
635
636 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34637 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27638 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47639 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34640 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54641
[email protected]dd11de52011-11-03 22:54:27642 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54643 // HACK!! This code suppresses javascript: URLs from being added to
644 // session history, which is what we want to do for javascript: URLs that
645 // do not generate content. What we really need is a message from the
646 // renderer telling us that a new page was not created. The same message
647 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27648 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54649 return false;
650 }
651
[email protected]3c9e1872010-11-18 16:17:49652 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04653 FOR_EACH_OBSERVER(TabContentsObserver,
654 observers_,
[email protected]dd11de52011-11-03 22:54:27655 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54656
[email protected]09b29342011-06-24 19:18:48657 if (delegate_)
658 delegate_->DidNavigateToPendingEntry(this);
659
[email protected]d5f942ba2008-09-26 19:30:34660 return true;
661}
662
[email protected]9e1ad4b2011-08-14 16:49:19663void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
664 int history_length,
665 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41666 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
667 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19668 if (render_manager_.pending_render_view_host()) {
669 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14670 return;
[email protected]9e1ad4b2011-08-14 16:49:19671 }
672 RenderViewHost* rvh = render_view_host();
673 if (!rvh) {
674 NOTREACHED();
675 return;
676 }
677 if (site_instance && rvh->site_instance() != site_instance) {
678 NOTREACHED();
679 return;
680 }
681 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
682 history_length,
683 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14684}
685
[email protected]96d185d2009-04-24 03:28:54686void TabContents::Stop() {
687 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47688 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54689}
690
[email protected]96d185d2009-04-24 03:28:54691TabContents* TabContents::Clone() {
692 // We create a new SiteInstance so that the new tab won't share processes
693 // with the old one. This can be changed in the future if we need it to share
694 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37695 TabContents* tc = new TabContents(
696 browser_context(),
697 SiteInstance::CreateSiteInstance(browser_context()),
698 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54699 tc->controller().CopyStateFrom(controller_);
700 return tc;
701}
702
[email protected]4d677202009-07-19 07:37:12703void TabContents::ShowPageInfo(const GURL& url,
704 const NavigationEntry::SSLStatus& ssl,
705 bool show_history) {
706 if (!delegate_)
707 return;
708
[email protected]3d7474ff2011-07-27 17:47:37709 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12710}
711
[email protected]e7cfdbd2011-04-22 14:41:37712void TabContents::AddNewContents(TabContents* new_contents,
713 WindowOpenDisposition disposition,
714 const gfx::Rect& initial_pos,
715 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29716 if (!delegate_)
717 return;
718
[email protected]e7cfdbd2011-04-22 14:41:37719 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
720 user_gesture);
[email protected]96d185d2009-04-24 03:28:54721}
722
[email protected]5c9e97a2009-09-09 23:48:30723gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54724 return view_->GetContentNativeView();
725}
726
727gfx::NativeView TabContents::GetNativeView() const {
728 return view_->GetNativeView();
729}
730
731void TabContents::GetContainerBounds(gfx::Rect *out) const {
732 view_->GetContainerBounds(out);
733}
734
735void TabContents::Focus() {
736 view_->Focus();
737}
738
[email protected]90daadb42009-06-08 21:27:28739void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54740 if (showing_interstitial_page()) {
741 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
742 return;
743 }
[email protected]96d185d2009-04-24 03:28:54744 render_view_host()->SetInitialFocus(reverse);
745}
746
747bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40748 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58749 if (web_ui)
750 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43751 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25752 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43753 return true;
[email protected]96d185d2009-04-24 03:28:54754 return false;
755}
756
[email protected]a26dc362010-04-23 01:48:58757void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38758 if (delegate())
[email protected]a26dc362010-04-23 01:48:58759 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38760}
761
[email protected]686493142011-07-15 21:47:22762bool TabContents::CanDownload(int request_id) {
763 TabContentsDelegate* d = delegate();
764 if (d)
765 return d->CanDownload(this, request_id);
766 return true;
767}
768
769void TabContents::OnStartDownload(DownloadItem* download) {
770 TabContentsDelegate* d = delegate();
771 if (d)
772 d->OnStartDownload(this, download);
773}
774
[email protected]c7dd2f62011-07-18 15:57:59775void TabContents::OnSavePage() {
776 // If we can not save the page, try to download it.
777 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37778 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59779 const GURL& current_page_url = GetURL();
780 if (dlm && current_page_url.is_valid()) {
781 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46782 download_stats::RecordDownloadCount(
783 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59784 return;
785 }
786 }
787
788 Stop();
789
790 // Create the save package and possibly prompt the user for the name to save
791 // the page as. The user prompt is an asynchronous operation that runs on
792 // another thread.
793 save_package_ = new SavePackage(this);
794 save_package_->GetSaveInfo();
795}
796
797// Used in automated testing to bypass prompting the user for file names.
798// Instead, the names and paths are hard coded rather than running them through
799// file name sanitation and extension / mime checking.
800bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
801 SavePackage::SavePackageType save_type) {
802 // Stop the page from navigating.
803 Stop();
804
805 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
806 return save_package_->Init();
807}
808
809void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37810 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59811 dlm->DownloadUrl(url, GetURL(), "", this);
812}
813
[email protected]420ae012009-04-24 05:16:32814bool TabContents::IsActiveEntry(int32 page_id) {
815 NavigationEntry* active_entry = controller_.GetActiveEntry();
816 return (active_entry != NULL &&
817 active_entry->site_instance() == GetSiteInstance() &&
818 active_entry->page_id() == page_id);
819}
820
[email protected]b2fe07d12010-02-09 14:38:08821void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16822 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26823 render_view_host()->Send(new ViewMsg_SetPageEncoding(
824 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16825}
826
[email protected]b2fe07d12010-02-09 14:38:08827void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16828 reset_encoding();
[email protected]216813952011-05-19 22:21:26829 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
830 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16831}
832
[email protected]7ab1e7d62009-10-14 23:32:01833void TabContents::OnCloseStarted() {
834 if (tab_close_start_time_.is_null())
835 tab_close_start_time_ = base::TimeTicks::Now();
836}
837
[email protected]46624bf2010-06-09 16:04:19838bool TabContents::ShouldAcceptDragAndDrop() const {
839#if defined(OS_CHROMEOS)
840 // ChromeOS panels (pop-ups) do not take drag-n-drop.
841 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14842 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20843 return false;
844 return true;
[email protected]46624bf2010-06-09 16:04:19845#else
846 return true;
847#endif
848}
849
[email protected]7813bd72011-02-05 02:19:34850void TabContents::SystemDragEnded() {
851 if (render_view_host())
852 render_view_host()->DragSourceSystemDragEnded();
853 if (delegate())
854 delegate()->DragEnded();
855}
856
[email protected]d0b8d092010-10-25 04:05:17857double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37858 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25859 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17860 return 0;
[email protected]b75b8292010-10-01 07:28:25861
862 double zoom_level;
863 if (temporary_zoom_settings_) {
864 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]f3b1a082011-11-18 00:34:30865 GetRenderProcessHost()->GetID(), render_view_host()->routing_id());
[email protected]b75b8292010-10-01 07:28:25866 } else {
[email protected]2ae88d12011-10-14 09:11:19867 GURL url;
868 NavigationEntry* active_entry = controller().GetActiveEntry();
869 // Since zoom map is updated using rewritten URL, use rewritten URL
870 // to get the zoom level.
871 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
872 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25873 }
[email protected]d0b8d092010-10-25 04:05:17874 return zoom_level;
875}
[email protected]b75b8292010-10-01 07:28:25876
[email protected]d0b8d092010-10-25 04:05:17877int TabContents::GetZoomPercent(bool* enable_increment,
878 bool* enable_decrement) {
879 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01880 // Calculate the zoom percent from the factor. Round up to the nearest whole
881 // number.
[email protected]b75b8292010-10-01 07:28:25882 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:01883 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:25884 *enable_decrement = percent > minimum_zoom_percent_;
885 *enable_increment = percent < maximum_zoom_percent_;
886 return percent;
887}
888
[email protected]3c733bde2010-12-21 19:56:31889void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50890 if (!delegate_)
891 return;
892
893 NavigationEntry* active_entry = controller().GetActiveEntry();
894 if (!active_entry)
895 return;
896
897 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12898}
899
[email protected]932b7a12011-03-09 12:50:27900void TabContents::ViewFrameSource(const GURL& url,
901 const std::string& content_state) {
902 if (!delegate_)
903 return;
904
905 delegate_->ViewSourceForFrame(this, url, content_state);
906}
907
[email protected]c40d6232011-03-25 00:16:21908void TabContents::SetContentRestrictions(int restrictions) {
909 content_restrictions_ = restrictions;
910 delegate()->ContentRestrictionsChanged(this);
911}
912
[email protected]8b5af492011-11-28 21:50:58913void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30914 const string16& type,
915 const string16& href,
916 const string16& title,
917 const string16& disposition) {
918 delegate()->RegisterIntentHandler(
919 this, action, type, href, title, disposition);
920}
921
922void TabContents::OnWebIntentDispatch(const IPC::Message& message,
923 const webkit_glue::WebIntentData& intent,
924 int intent_id) {
[email protected]ada02b312011-12-01 21:54:53925 IntentsHostImpl* intents_host = new IntentsHostImpl(this, intent, intent_id);
926 delegate()->WebIntentDispatch(this, intents_host);
[email protected]63c239322011-10-31 23:56:30927}
928
[email protected]724159a2010-12-30 01:11:18929void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
930 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59931 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18932 const GURL& url) {
933 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
934 GURL validated_url(url);
935 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30936 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18937
[email protected]8093a542011-05-13 07:29:32938 RenderViewHost* rvh =
939 render_manager_.pending_render_view_host() ?
940 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10941 // Notify observers about the start of the provisional load.
942 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
943 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32944 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10945
[email protected]724159a2010-12-30 01:11:18946 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59947 // Notify observers about the provisional change in the main frame URL.
948 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59949 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18950 }
951}
952
953void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59954 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18955 const GURL& source_url,
956 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49957 // TODO(creis): Remove this method and have the pre-rendering code listen to
958 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
959 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18960 NavigationEntry* entry;
961 if (page_id == -1)
962 entry = controller_.pending_entry();
963 else
964 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
965 if (!entry || entry->url() != source_url)
966 return;
[email protected]e7d50892011-01-19 21:47:38967
[email protected]4850a7f2011-03-08 23:36:59968 // Notify observers about the provisional change in the main frame URL.
969 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26970 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59971 opener_url));
[email protected]724159a2010-12-30 01:11:18972}
973
974void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58975 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
976 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
977 << ", error_code: " << params.error_code
978 << ", error_description: " << params.error_description
979 << ", is_main_frame: " << params.is_main_frame
980 << ", showing_repost_interstitial: " <<
981 params.showing_repost_interstitial
982 << ", frame_id: " << params.frame_id;
983 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18984 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30985 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18986
[email protected]d7b175e2011-10-11 15:31:58987 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18988 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
989 // This means that the interstitial won't be torn down properly, which is
990 // bad. But if we have an interstitial, go back to another tab type, and
991 // then load the same interstitial again, we could end up getting the first
992 // interstitial's "failed" message (as a result of the cancel) when we're on
993 // the second one.
994 //
995 // We can't tell this apart, so we think we're tearing down the current page
996 // which will cause a crash later one. There is also some code in
997 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
998 // out because of this problem.
999 //
1000 // http://code.google.com/p/chromium/issues/detail?id=2855
1001 // Because this will not tear down the interstitial properly, if "back" is
1002 // back to another tab type, the interstitial will still be somewhat alive
1003 // in the previous tab type. If you navigate somewhere that activates the
1004 // tab with the interstitial again, you'll see a flash before the new load
1005 // commits of the interstitial page.
1006 if (showing_interstitial_page()) {
1007 LOG(WARNING) << "Discarding message during interstitial.";
1008 return;
1009 }
1010
[email protected]02102f82011-06-13 20:37:021011 // Discard our pending entry if the load canceled (e.g. if we decided to
1012 // download the file instead of load it). We do not verify that the URL
1013 // being canceled matches the pending entry's URL because they will not
1014 // match if a redirect occurred (in which case we do not want to leave a
1015 // stale redirect URL showing). This means that we also cancel the pending
1016 // entry if the user started a new navigation. As a result, the navigation
1017 // controller may not remember that a load is in progress, but the
1018 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181019 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021020 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161021 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181022
1023 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1024 }
1025
1026 // Send out a notification that we failed a provisional load with an error.
1027 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581028 params.is_main_frame,
1029 controller_.IsURLInPageNavigation(validated_url),
1030 validated_url,
1031 std::string(),
1032 false,
1033 params.frame_id);
1034 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181035
[email protected]ad50def52011-10-19 23:17:071036 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271037 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531038 content::Source<NavigationController>(&controller_),
1039 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101040
[email protected]d7b175e2011-10-11 15:31:581041 FOR_EACH_OBSERVER(TabContentsObserver,
1042 observers_,
1043 DidFailProvisionalLoad(params.frame_id,
1044 params.is_main_frame,
1045 validated_url,
1046 params.error_code,
1047 params.error_description));
[email protected]724159a2010-12-30 01:11:181048}
1049
1050void TabContents::OnDidLoadResourceFromMemoryCache(
1051 const GURL& url,
[email protected]70435962011-08-02 20:13:281052 const std::string& security_info,
1053 const std::string& http_method,
1054 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191055 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181056 cache.Increment();
1057
1058 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081059 int cert_id = 0;
1060 net::CertStatus cert_status = 0;
1061 int security_bits = -1;
1062 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181063 SSLManager::DeserializeSecurityInfo(security_info,
1064 &cert_id, &cert_status,
1065 &security_bits,
1066 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301067 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161068 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181069
[email protected]ad50def52011-10-19 23:17:071070 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271071 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531072 content::Source<NavigationController>(&controller_),
1073 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181074}
1075
1076void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161077 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181078 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071079 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181080}
1081
1082void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021083 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231084 LOG(INFO) << security_origin << " ran insecure content from "
1085 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161086 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051087 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
1088 UserMetrics::RecordAction(
1089 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1090 }
[email protected]724159a2010-12-30 01:11:181091 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411092 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071093 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181094}
1095
1096void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1097 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101098 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1099 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181100}
1101
[email protected]1a55c5be2011-11-29 11:36:311102void TabContents::OnDidFinishLoad(
1103 int64 frame_id,
1104 const GURL& validated_url,
1105 bool is_main_frame) {
[email protected]0d60f0192011-04-14 12:40:101106 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311107 DidFinishLoad(frame_id, validated_url, is_main_frame));
1108}
1109
1110void TabContents::OnDidFailLoadWithError(int64 frame_id,
1111 const GURL& validated_url,
1112 bool is_main_frame,
1113 int error_code,
1114 const string16& error_description) {
1115 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1116 DidFailLoad(frame_id, validated_url, is_main_frame,
1117 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181118}
1119
[email protected]c8f73ab2011-01-22 00:05:171120void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211121 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171122}
1123
[email protected]216813952011-05-19 22:21:261124void TabContents::OnGoToEntryAtOffset(int offset) {
1125 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1126 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1127 if (!entry)
1128 return;
1129 // Note that we don't call NavigationController::GotToOffset() as we don't
1130 // want to create a pending navigation entry (it might end up lingering
1131 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581132 entry->set_transition_type(
1133 content::PageTransitionFromInt(
1134 entry->transition_type() |
1135 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271136 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571137
1138 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1139 // it in now that we know. This allows us to find the entry when it commits.
1140 if (!entry->site_instance() &&
1141 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381142 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571143 }
[email protected]216813952011-05-19 22:21:261144 }
1145}
1146
1147void TabContents::OnUpdateZoomLimits(int minimum_percent,
1148 int maximum_percent,
1149 bool remember) {
1150 minimum_zoom_percent_ = minimum_percent;
1151 maximum_zoom_percent_ = maximum_percent;
1152 temporary_zoom_settings_ = !remember;
1153}
1154
1155void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
[email protected]ad50def52011-10-19 23:17:071156 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271157 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]6c2381d2011-10-19 02:52:531158 content::Source<TabContents>(this),
1159 content::Details<const bool>(&is_editable_node));
[email protected]216813952011-05-19 22:21:261160}
1161
[email protected]3a29a6e2011-08-24 18:26:211162void TabContents::OnEnumerateDirectory(int request_id,
1163 const FilePath& path) {
1164 delegate()->EnumerateDirectory(this, request_id, path);
1165}
1166
[email protected]7d189022011-08-25 22:54:201167void TabContents::OnJSOutOfMemory() {
1168 delegate()->JSOutOfMemory(this);
1169}
1170
1171void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1172 const GURL& url,
1173 const string16& title) {
1174 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1175}
1176
[email protected]b888919c2011-09-02 00:32:161177void TabContents::OnFindReply(int request_id,
1178 int number_of_matches,
1179 const gfx::Rect& selection_rect,
1180 int active_match_ordinal,
1181 bool final_update) {
1182 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1183 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001184 // Send a notification to the renderer that we are ready to receive more
1185 // results from the scoping effort of the Find operation. The FindInPage
1186 // scoping is asynchronous and periodically sends results back up to the
1187 // browser using IPC. In an effort to not spam the browser we have the
1188 // browser send an ACK for each FindReply message and have the renderer
1189 // queue up the latest status message while waiting for this ACK.
1190 render_view_host()->Send(
1191 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161192}
1193
[email protected]d952a052011-09-06 18:42:451194void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1195 delegate()->CrashedPlugin(this, plugin_path);
1196}
1197
[email protected]7fc4bbb2011-09-08 21:23:101198void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1199 bool blocked_by_policy) {
1200 // Notify observers about navigation.
1201 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1202 AppCacheAccessed(manifest_url, blocked_by_policy));
1203}
1204
[email protected]96d185d2009-04-24 03:28:541205// Notifies the RenderWidgetHost instance about the fact that the page is
1206// loading, or done loading and calls the base implementation.
1207void TabContents::SetIsLoading(bool is_loading,
1208 LoadNotificationDetails* details) {
1209 if (is_loading == is_loading_)
1210 return;
1211
1212 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211213 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541214 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561215 upload_size_ = 0;
1216 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541217 }
1218
1219 render_manager_.SetIsLoading(is_loading);
1220
1221 is_loading_ = is_loading;
1222 waiting_for_response_ = is_loading;
1223
[email protected]6ebdc9b2010-09-27 16:55:571224 if (delegate_)
1225 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351226 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541227
[email protected]432115822011-07-10 15:52:271228 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1229 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071230 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541231 if (details)
[email protected]6c2381d2011-10-19 02:52:531232 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071233 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531234 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541235 det);
1236}
1237
[email protected]d0980792011-02-13 19:41:401238WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581239 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541240 // that goes along with it to control the basic flags. For example, we want to
1241 // show the pending URL in the URL bar, so we want the display_url flag to
1242 // be from the pending entry.
1243 //
1244 // The confusion comes because there are multiple possibilities for the
1245 // initial load in a tab as a side effect of the way the RenderViewHostManager
1246 // works.
1247 //
[email protected]e0112912011-02-02 22:54:351248 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541249 // the pending one, and we want it to apply here.
1250 //
1251 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1252 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581253 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351254 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541255 //
1256 // This condition handles all of these cases:
1257 //
1258 // - First load in first tab: no committed nav entry + pending nav entry +
1259 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351260 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541261 //
1262 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351263 // no pending Web UI:
1264 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541265 //
1266 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351267 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541268 //
1269 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351270 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541271 if (controller_.pending_entry() &&
1272 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581273 render_manager_.pending_web_ui()))
1274 return render_manager_.pending_web_ui();
1275 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541276}
[email protected]420ae012009-04-24 05:16:321277
[email protected]1fd1a502011-03-30 16:55:561278WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371279 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1280 GetURL());
[email protected]1fd1a502011-03-30 16:55:561281}
1282
[email protected]420ae012009-04-24 05:16:321283void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131284 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321285 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561286 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381287 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441288 // that opened the window, as long as both renderers have the same
1289 // privileges.
[email protected]1fd1a502011-03-30 16:55:561290 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1291 WebUI* web_ui = content::GetContentClient()->browser()->
1292 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581293 // web_ui might be NULL if the URL refers to a non-existent extension.
1294 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401295 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581296 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441297 }
1298 }
[email protected]1fd1a502011-03-30 16:55:561299 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441300 }
1301
[email protected]4e697b042011-07-08 06:44:561302 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321303 // Clear the status bubble. This is a workaround for a bug where WebKit
1304 // doesn't let us know that the cursor left an element during a
1305 // transition (this is also why the mouse cursor remains as a hand after
1306 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1307 // clear the bubble when a user navigates to a named anchor in the same
1308 // page.
1309 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321310 }
1311
[email protected]a6e82fc2010-02-24 22:28:141312 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471313 // Once the main frame is navigated, we're no longer considered to have
1314 // displayed insecure content.
1315 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171316 }
[email protected]ce5c4502009-05-06 16:46:111317
[email protected]3c9e1872010-11-18 16:17:491318 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171319 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041320 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321321}
1322
1323void TabContents::DidNavigateAnyFramePostCommit(
1324 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131325 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321326 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071327 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321328 // a malicious script from spamming messages, since the script could just
1329 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551330 if (dialog_creator_) {
1331 dialog_creator_->ResetJavaScriptState(this);
1332 dialog_creator_ = NULL;
1333 }
[email protected]420ae012009-04-24 05:16:321334
[email protected]3c9e1872010-11-18 16:17:491335 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171336 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041337 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321338}
1339
[email protected]420ae012009-04-24 05:16:321340void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1341 RenderViewHost* rvh) {
1342 // If we are creating a RVH for a restored controller, then we might
1343 // have more page IDs than the SiteInstance's current max page ID. We must
1344 // make sure that the max page ID is larger than any restored page ID.
1345 // Note that it is ok for conflicting page IDs to exist in another tab
1346 // (i.e., NavigationController), but if any page ID is larger than the max,
1347 // the back/forward list will get confused.
1348 int max_restored_page_id = controller_.max_restored_page_id();
1349 if (max_restored_page_id > 0) {
1350 int curr_max_page_id = site_instance->max_page_id();
1351 if (max_restored_page_id > curr_max_page_id) {
1352 // Need to update the site instance immediately.
1353 site_instance->UpdateMaxPageID(max_restored_page_id);
1354
1355 // Also tell the renderer to update its internal representation. We
1356 // need to reserve enough IDs to make all restored page IDs less than
1357 // the max.
1358 if (curr_max_page_id < 0)
1359 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261360 rvh->Send(new ViewMsg_ReservePageIDRange(
1361 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321362 }
1363 }
1364}
1365
[email protected]6b2f7a82011-04-25 19:30:511366bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571367 const string16& title) {
[email protected]420ae012009-04-24 05:16:321368 // For file URLs without a title, use the pathname instead. In the case of a
1369 // synthesized title, we don't want the update to count toward the "one set
1370 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511371 string16 final_title;
[email protected]420ae012009-04-24 05:16:321372 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091373 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511374 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321375 explicit_set = false; // Don't count synthetic titles toward the set limit.
1376 } else {
[email protected]acafd272011-07-26 17:35:571377 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321378 explicit_set = true;
1379 }
1380
[email protected]987fc3a2011-05-26 14:18:091381 // If a page is created via window.open and never navigated,
1382 // there will be no navigation entry. In this situation,
1383 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1384 if (entry) {
1385 if (final_title == entry->title())
1386 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321387
[email protected]987fc3a2011-05-26 14:18:091388 entry->set_title(final_title);
1389 } else {
1390 if (page_title_when_no_navigation_entry_ == final_title)
1391 return false; // Nothing changed, don't bother.
1392
1393 page_title_when_no_navigation_entry_ = final_title;
1394 }
[email protected]420ae012009-04-24 05:16:321395
[email protected]420ae012009-04-24 05:16:321396 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231397 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321398
[email protected]105bb0f2011-05-24 17:12:141399 TitleUpdatedDetails details(entry, explicit_set);
1400
[email protected]ad50def52011-10-19 23:17:071401 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271402 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531403 content::Source<TabContents>(this),
1404 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041405
[email protected]420ae012009-04-24 05:16:321406 return true;
1407}
1408
1409void TabContents::NotifySwapped() {
1410 // After sending out a swap notification, we need to send a disconnect
1411 // notification so that clients that pick up a pointer to |this| can NULL the
1412 // pointer. See Bug 1230284.
1413 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071414 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271415 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[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
1420void TabContents::NotifyConnected() {
1421 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071422 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271423 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531424 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071425 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321426}
1427
1428void TabContents::NotifyDisconnected() {
1429 if (!notify_disconnection_)
1430 return;
1431
1432 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071433 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271434 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531435 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071436 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321437}
1438
[email protected]8d3347f2009-07-09 22:00:211439RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321440 return view_.get();
1441}
1442
[email protected]8d3347f2009-07-09 22:00:211443RenderViewHostDelegate::RendererManagement*
1444TabContents::GetRendererManagementDelegate() {
1445 return &render_manager_;
1446}
1447
[email protected]daf82f82011-10-31 22:35:311448content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371449 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461450 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511451}
1452
[email protected]57c6a652009-05-04 07:58:341453TabContents* TabContents::GetAsTabContents() {
1454 return this;
1455}
1456
[email protected]da4dfc42011-10-12 15:53:561457content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431458 return view_type_;
[email protected]7b291f92009-08-14 05:43:531459}
1460
[email protected]420ae012009-04-24 05:16:321461void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071462 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271463 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531464 content::Source<TabContents>(this),
1465 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321466 NavigationEntry* entry = controller_.GetActiveEntry();
1467 if (!entry)
1468 return;
1469
1470 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351471 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561472 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581473 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321474
1475 if (entry->IsViewSourceMode()) {
1476 // Put the renderer in view source mode.
1477 render_view_host->Send(
1478 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1479 }
[email protected]0666aef2009-05-13 19:48:081480
1481 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261482
1483 FOR_EACH_OBSERVER(
1484 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321485}
1486
1487void TabContents::RenderViewReady(RenderViewHost* rvh) {
1488 if (rvh != render_view_host()) {
1489 // Don't notify the world, since this came from a renderer in the
1490 // background.
1491 return;
1492 }
1493
1494 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301495 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231496 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301497
1498 // Restore the focus to the tab (otherwise the focus will be on the top
1499 // window).
[email protected]484ae5912010-09-29 19:16:141500 if (was_crashed && !FocusLocationBarByDefault() &&
1501 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301502 Focus();
[email protected]484ae5912010-09-29 19:16:141503 }
[email protected]32ded2212011-11-10 18:51:431504
1505 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321506}
1507
[email protected]443b80e2010-12-14 00:42:231508void TabContents::RenderViewGone(RenderViewHost* rvh,
1509 base::TerminationStatus status,
1510 int error_code) {
[email protected]420ae012009-04-24 05:16:321511 if (rvh != render_view_host()) {
1512 // The pending page's RenderViewHost is gone.
1513 return;
1514 }
1515
1516 SetIsLoading(false, NULL);
1517 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231518 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541519 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321520
[email protected]9cddb1a22011-11-15 15:04:271521 FOR_EACH_OBSERVER(TabContentsObserver,
1522 observers_,
1523 RenderViewGone(crashed_status()));
[email protected]420ae012009-04-24 05:16:321524}
1525
[email protected]2e4633c2009-07-09 16:58:061526void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481527 render_manager_.RenderViewDeleted(rvh);
[email protected]483623eb2011-10-25 09:30:001528 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061529}
1530
[email protected]420ae012009-04-24 05:16:321531void TabContents::DidNavigate(RenderViewHost* rvh,
1532 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581533 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321534 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371535
[email protected]420ae012009-04-24 05:16:321536 // Update the site of the SiteInstance if it doesn't have one yet.
1537 if (!GetSiteInstance()->has_site())
1538 GetSiteInstance()->SetSite(params.url);
1539
1540 // Need to update MIME type here because it's referred to in
1541 // UpdateNavigationCommands() called by RendererDidNavigate() to
1542 // determine whether or not to enable the encoding menu.
1543 // It's updated only for the main frame. For a subframe,
1544 // RenderView::UpdateURL does not set params.contents_mime_type.
1545 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1546 // TODO(jungshik): Add a test for the encoding menu to avoid
1547 // regressing it again.
[email protected]2905f742011-10-13 03:51:581548 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321549 contents_mime_type_ = params.contents_mime_type;
1550
[email protected]8286f51a2011-05-31 17:39:131551 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001552 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391553
[email protected]a9c0bfe2010-09-17 08:35:221554 // Send notification about committed provisional loads. This notification is
1555 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1556 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081557 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071558 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1559 // that is not recorded in the navigation history. For the purpose of
1560 // tracking navigation events, we treat this event as a sub frame navigation
1561 // event.
1562 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581563 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221564 // Whether or not a page transition was triggered by going backward or
1565 // forward in the history is only stored in the navigation controller's
1566 // entry list.
1567 if (did_navigate &&
1568 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581569 content::PAGE_TRANSITION_FORWARD_BACK)) {
1570 transition_type = content::PageTransitionFromInt(
1571 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221572 }
[email protected]0d60f0192011-04-14 12:40:101573 // Notify observers about the commit of the provisional load.
1574 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1575 DidCommitProvisionalLoadForFrame(params.frame_id,
1576 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221577 }
1578
[email protected]76543b92009-08-31 17:27:451579 if (!did_navigate)
1580 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321581
1582 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1583 // for the appropriate notification (best) or you can add it to
1584 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1585 // necessary, please).
1586
1587 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001588 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321589 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481590 if (delegate())
1591 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001592 }
[email protected]420ae012009-04-24 05:16:321593 DidNavigateAnyFramePostCommit(rvh, details, params);
1594}
1595
1596void TabContents::UpdateState(RenderViewHost* rvh,
1597 int32 page_id,
1598 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151599 // Ensure that this state update comes from either the active RVH or one of
1600 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1601 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321602
1603 // We must be prepared to handle state updates for any page, these occur
1604 // when the user is scrolling and entering form data, as well as when we're
1605 // leaving a page, in which case our state may have already been moved to
1606 // the next page. The navigation controller will look up the appropriate
1607 // NavigationEntry and update it when it is notified via the delegate.
1608
1609 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151610 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321611 if (entry_index < 0)
1612 return;
1613 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1614
1615 if (state == entry->content_state())
1616 return; // Nothing to update.
1617 entry->set_content_state(state);
1618 controller_.NotifyEntryChanged(entry, entry_index);
1619}
1620
1621void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571622 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461623 const string16& title,
1624 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321625 // If we have a title, that's a pretty good indication that we've started
1626 // getting useful data.
1627 SetNotWaitingForResponse();
1628
1629 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481630 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581631 page_id);
[email protected]987fc3a2011-05-26 14:18:091632
[email protected]a49e10b2011-08-01 23:57:461633 // TODO(evan): make use of title_direction.
1634 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091635 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321636 return;
1637
1638 // Broadcast notifications when the UI should be updated.
1639 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031640 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321641}
1642
[email protected]420ae012009-04-24 05:16:321643void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401644 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321645 set_encoding(encoding);
1646}
1647
1648void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1649 if (delegate())
[email protected]d952a052011-09-06 18:42:451650 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321651}
1652
[email protected]420ae012009-04-24 05:16:321653void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291654 // The UI may be in an event-tracking loop, such as between the
1655 // mouse-down and mouse-up in text selection or a button click.
1656 // Defer the close until after tracking is complete, so that we
1657 // don't free objects out from under the UI.
1658 // TODO(shess): This could probably be integrated with the
1659 // IsDoingDrag() test below. Punting for now because I need more
1660 // research to understand how this impacts platforms other than Mac.
1661 // TODO(shess): This could get more fine-grained. For instance,
1662 // closing a tab in another window while selecting text in the
1663 // current window's Omnibox should be just fine.
1664 if (view()->IsEventTracking()) {
1665 view()->CloseTabAfterEventTracking();
1666 return;
1667 }
1668
[email protected]24a4d1062009-07-10 23:10:421669 // If we close the tab while we're in the middle of a drag, we'll crash.
1670 // Instead, cancel the drag and close it as soon as the drag ends.
1671 if (view()->IsDoingDrag()) {
1672 view()->CancelDragAndCloseTab();
1673 return;
1674 }
1675
[email protected]420ae012009-04-24 05:16:321676 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1677 if (delegate() && rvh == render_view_host())
1678 delegate()->CloseContents(this);
1679}
1680
[email protected]cd9ed79d2011-11-15 19:22:571681void TabContents::SwappedOut(RenderViewHost* rvh) {
1682 if (delegate() && rvh == render_view_host())
1683 delegate()->SwappedOut(this);
1684}
1685
[email protected]420ae012009-04-24 05:16:321686void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141687 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321688 delegate()->MoveContents(this, new_bounds);
1689}
1690
[email protected]7ab1e7d62009-10-14 23:32:011691void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321692 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491693
[email protected]c40d6232011-03-25 00:16:211694 if (delegate() && content_restrictions_) {
1695 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211696 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001697 }
[email protected]3c9e1872010-11-18 16:17:491698
1699 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171700 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321701}
1702
[email protected]7ab1e7d62009-10-14 23:32:011703void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321704 scoped_ptr<LoadNotificationDetails> details;
1705
1706 NavigationEntry* entry = controller_.GetActiveEntry();
1707 // An entry may not exist for a stop when loading an initial blank page or
1708 // if an iframe injected by script into a blank page finishes loading.
1709 if (entry) {
[email protected]420ae012009-04-24 05:16:321710 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1711
1712 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541713 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321714 entry->transition_type(),
1715 elapsed,
1716 &controller_,
1717 controller_.GetCurrentEntryIndex()));
1718 }
1719
[email protected]420ae012009-04-24 05:16:321720 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491721
1722 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171723 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321724}
1725
[email protected]c95fa8b2011-04-28 20:26:161726void TabContents::DidCancelLoading() {
1727 controller_.DiscardNonCommittedEntries();
1728
1729 // Update the URL display.
1730 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1731}
1732
[email protected]1a3c3cb2010-12-16 21:03:401733void TabContents::DidChangeLoadProgress(double progress) {
1734 if (delegate())
1735 delegate()->LoadProgressChanged(progress);
1736}
1737
[email protected]952a68e2011-11-17 00:36:101738void TabContents::DocumentAvailableInMainFrame(
1739 RenderViewHost* render_view_host) {
1740 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1741 DocumentAvailableInMainFrame());
1742}
1743
[email protected]25497492010-09-11 15:15:081744void TabContents::DocumentOnLoadCompletedInMainFrame(
1745 RenderViewHost* render_view_host,
1746 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071747 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271748 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531749 content::Source<TabContents>(this),
1750 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081751}
1752
[email protected]ae5184d62011-10-06 19:25:581753void TabContents::RequestOpenURL(const GURL& url,
1754 const GURL& referrer,
1755 WindowOpenDisposition disposition,
1756 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481757 // Delegate to RequestTransferURL because this is just the generic
1758 // case where |old_request_id| is empty.
1759 RequestTransferURL(url, referrer, disposition, source_frame_id,
1760 GlobalRequestID());
1761}
1762
1763void TabContents::RequestTransferURL(const GURL& url,
1764 const GURL& referrer,
1765 WindowOpenDisposition disposition,
1766 int64 source_frame_id,
1767 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581768 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581769 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581770 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351771 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321772 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1773 // generated suggestions).
1774 //
[email protected]e0112912011-02-02 22:54:351775 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161776 // want web sites to see a referrer of "chrome://blah" (and some
1777 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321778 // send to the site), so we send no referrer.
[email protected]4ad5d77d2011-12-03 02:00:481779 OpenURLParams params(url, GURL(), disposition,
1780 render_manager_.web_ui()->link_transition_type(),
1781 false /* is_renderer_initiated */);
1782 params.transferred_global_request_id = old_request_id;
1783 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581784 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321785 } else {
[email protected]4ad5d77d2011-12-03 02:00:481786 OpenURLParams params(url, referrer, disposition,
1787 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1788 params.transferred_global_request_id = old_request_id;
1789 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581790 }
1791 if (new_contents) {
1792 // Notify observers.
1793 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1794 DidOpenRequestedURL(new_contents,
1795 url,
1796 referrer,
1797 disposition,
1798 transition_type,
1799 source_frame_id));
[email protected]420ae012009-04-24 05:16:321800 }
1801}
1802
[email protected]420ae012009-04-24 05:16:321803void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151804 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411805 const string16& message,
1806 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321807 const GURL& frame_url,
1808 const int flags,
1809 IPC::Message* reply_msg,
1810 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071811 // Suppress JavaScript dialogs when requested. Also suppress messages when
1812 // showing an interstitial as it's shown over the previous page and we don't
1813 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501814 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151815 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501816 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071817 !delegate_ ||
1818 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321819
1820 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341821 content::JavaScriptDialogCreator::TitleType title_type;
1822 string16 title;
1823
1824 if (!frame_url.has_host()) {
1825 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1826 } else {
1827 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1828 title = net::FormatUrl(
1829 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201830 content::GetContentClient()->browser()->GetAcceptLangs(
1831 this->browser_context()));
[email protected]b627d9a2011-06-28 14:06:341832 }
1833
[email protected]2e5b90c2011-08-16 21:11:551834 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1835 dialog_creator_->RunJavaScriptDialog(this,
1836 title_type,
1837 title,
1838 flags,
1839 message,
1840 default_prompt,
1841 reply_msg,
1842 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321843 }
[email protected]3ab9cb82011-06-03 18:02:071844
1845 if (suppress_this_message) {
1846 // If we are suppressing messages, just reply as if the user immediately
1847 // pressed "Cancel".
1848 OnDialogClosed(reply_msg, false, string16());
1849 }
1850
1851 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321852}
1853
[email protected]992db4c2011-05-12 15:37:151854void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411855 const string16& message,
[email protected]420ae012009-04-24 05:16:321856 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291857 if (delegate())
1858 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071859
1860 bool suppress_this_message =
1861 rvh->is_swapped_out() ||
1862 !delegate_ ||
1863 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151864 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411865 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501866 return;
1867 }
[email protected]3ab9cb82011-06-03 18:02:071868
[email protected]7ab1e7d62009-10-14 23:32:011869 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551870 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1871 dialog_creator_->RunBeforeUnloadDialog(this,
1872 message,
1873 reply_msg);
[email protected]420ae012009-04-24 05:16:321874}
1875
[email protected]420ae012009-04-24 05:16:321876WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081877 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361878 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]5092c282011-10-29 21:48:371879 render_view_host());
[email protected]447021c2010-09-08 21:29:081880
[email protected]b8299c12011-06-03 19:52:281881 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211882 // chrome-devtools: pages (unless it's specifically allowed).
1883 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571884 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281885 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:301886 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1887 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211888 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081889 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431890 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081891 }
1892
1893 return web_prefs;
[email protected]420ae012009-04-24 05:16:321894}
1895
[email protected]7d472472011-01-22 01:30:251896void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271897 // Notify observers.
1898 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221899
1900 ResourceDispatcherHost* rdh =
1901 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1902 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301903 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251904}
1905
[email protected]fa1cf0b82010-01-15 21:49:441906void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441907 // Notify observers.
1908 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441909}
1910
[email protected]420ae012009-04-24 05:16:321911void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1912 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151913 // Don't show hung renderer dialog for a swapped out RVH.
1914 if (rvh != render_view_host())
1915 return;
1916
[email protected]e5fc1632011-08-08 07:51:531917 // Ignore renderer unresponsive event if debugger is attached to the tab
1918 // since the event may be a result of the renderer sitting on a breakpoint.
1919 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:441920 DevToolsAgentHost* agent =
1921 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
1922 if (agent &&
1923 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:531924 return;
1925
[email protected]420ae012009-04-24 05:16:321926 if (is_during_unload) {
1927 // Hang occurred while firing the beforeunload/unload handler.
1928 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111929 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321930
1931 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1932 return;
1933
1934 // If the tab hangs in the beforeunload/unload handler there's really
1935 // nothing we can do to recover. Pretend the unload listeners have
1936 // all fired and close the tab. If the hang is in the beforeunload handler
1937 // then the user will not have the option of cancelling the close.
1938 Close(rvh);
1939 return;
1940 }
1941
[email protected]55452902011-06-01 21:57:471942 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1943 return;
1944
1945 if (delegate())
1946 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321947}
1948
1949void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471950 if (delegate())
1951 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321952}
1953
1954void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211955 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561956 uint64 upload_position,
1957 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321958 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561959 upload_position_ = upload_position;
1960 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501961 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:201962 content::GetContentClient()->browser()->GetAcceptLangs(
1963 this->browser_context()));
[email protected]9c235f042011-08-10 22:28:211964 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321965 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511966 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501967 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321968}
1969
[email protected]7d472472011-01-22 01:30:251970void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441971 if (delegate())
[email protected]55452902011-06-01 21:57:471972 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251973}
1974
[email protected]420ae012009-04-24 05:16:321975void TabContents::BeforeUnloadFiredFromRenderManager(
1976 bool proceed,
1977 bool* proceed_to_fire_unload) {
1978 if (delegate())
1979 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1980}
1981
[email protected]3a3d47472010-07-15 21:03:541982void TabContents::DidStartLoadingFromRenderManager(
1983 RenderViewHost* render_view_host) {
1984 DidStartLoading();
1985}
1986
1987void TabContents::RenderViewGoneFromRenderManager(
1988 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231989 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1990 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541991}
1992
[email protected]420ae012009-04-24 05:16:321993void TabContents::UpdateRenderViewSizeForRenderManager() {
1994 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261995 gfx::Size size = view_->GetContainerSize();
1996 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1997 // here during container initialization and normal window size will be set
1998 // later. In case of tab duplication this resizing to 0x0 prevents setting
1999 // normal size later so just ignore it.
2000 if (!size.IsEmpty())
2001 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322002}
2003
[email protected]3a3d47472010-07-15 21:03:542004void TabContents::NotifySwappedFromRenderManager() {
2005 NotifySwapped();
2006}
2007
2008NavigationController& TabContents::GetControllerForRenderManager() {
2009 return controller();
2010}
2011
[email protected]d0980792011-02-13 19:41:402012WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562013 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322014}
2015
2016NavigationEntry*
2017TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2018 return controller_.GetLastCommittedEntry();
2019}
2020
2021bool TabContents::CreateRenderViewForRenderManager(
2022 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442023 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322024 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522025
[email protected]420ae012009-04-24 05:16:322026 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442027 if (rwh_view)
2028 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322029
[email protected]a4127722011-04-27 23:13:522030 if (!render_view_host->CreateRenderView(string16()))
2031 return false;
2032
[email protected]e60c0232011-11-11 19:56:352033#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502034 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2035 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442036 if (rwh_view) {
2037 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2038 render_widget_host->WasResized();
2039 }
[email protected]f8233cc2011-05-31 20:24:502040#endif
2041
[email protected]420ae012009-04-24 05:16:322042 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2043 render_view_host);
2044 return true;
2045}
2046
[email protected]3ab9cb82011-06-03 18:02:072047void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2048 bool success,
2049 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542050 if (is_showing_before_unload_dialog_ && !success) {
2051 // If a beforeunload dialog is canceled, we need to stop the throbber from
2052 // spinning, since we forced it to start spinning in Navigate.
2053 DidStopLoading();
2054
2055 tab_close_start_time_ = base::TimeTicks();
2056 }
2057 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:412058 render_view_host()->JavaScriptDialogClosed(reply_msg,
2059 success,
[email protected]3ab9cb82011-06-03 18:02:072060 user_input);
[email protected]beb440c2009-11-06 04:08:542061}
2062
[email protected]0b08add2011-11-29 03:27:062063gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072064 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542065}
2066
[email protected]a1e97f02011-06-30 14:04:342067void TabContents::OnDialogShown() {
2068 Activate();
[email protected]3a3d47472010-07-15 21:03:542069}
2070
[email protected]41fc0322009-09-04 22:23:402071void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122072 encoding_ = content::GetContentClient()->browser()->
2073 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102074}
[email protected]f45d2a72010-03-08 23:28:352075
[email protected]33f74972010-12-08 16:40:362076void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2077 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442078 // Can be NULL during tests.
2079 if (rwh_view)
2080 rwh_view->SetSize(view()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362081}
[email protected]e9621112011-10-17 05:38:372082
2083bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
2084 return render_view_host() ?
2085 render_view_host()->GotResponseToLockMouseRequest(allowed) : false;
2086}