blob: 489e38d72da7789e4ee84d51e12de8178972aeca [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();
[email protected]445e1042011-12-03 21:03:15163 params->referrer = content::Referrer(entry.referrer(),
164 WebKit::WebReferrerPolicyDefault);
[email protected]056de2d2009-06-26 16:41:34165 params->transition = entry.transition_type();
166 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00167 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37168 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34169 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47170 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48171 params->transferred_request_child_id =
172 entry.transferred_global_request_id().child_id;
173 params->transferred_request_request_id =
174 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47175
176 if (delegate)
177 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34178}
179
[email protected]420ae012009-04-24 05:16:32180} // namespace
181
[email protected]f4f50ef2011-01-21 19:01:19182
183// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32184
[email protected]3d7474ff2011-07-27 17:47:37185TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32186 SiteInstance* site_instance,
187 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07188 const TabContents* base_tab_contents,
189 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42190 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07191 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37192 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13193 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32194 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22195 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34196 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23197 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
198 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34199 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34200 max_page_id_(-1),
[email protected]9c235f042011-08-10 22:28:21201 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56202 upload_size_(0),
203 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47204 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57205 capturing_contents_(false),
206 is_being_destroyed_(false),
207 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55208 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57209#if defined(OS_WIN)
210 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
211#endif
[email protected]7ab1e7d62009-10-14 23:32:01212 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56213 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38214 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25215 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01216 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25217 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01218 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00219 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43220 content_restrictions_(0),
221 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37222 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32223
[email protected]34ac70502009-09-25 17:07:23224 // We have the initial size of the view be based on the size of the passed in
225 // tab contents (normally a tab from the same window).
226 view_->CreateView(base_tab_contents ?
227 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00228
229#if defined(ENABLE_JAVA_BRIDGE)
230 java_bridge_dispatcher_host_manager_.reset(
231 new JavaBridgeDispatcherHostManager(this));
232#endif
[email protected]332af7732009-03-11 13:21:35233}
initial.commit09911bf2008-07-26 23:55:29234
235TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32236 is_being_destroyed_ = true;
237
[email protected]3ab9cb82011-06-03 18:02:07238 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55239 if (dialog_creator_)
240 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07241
[email protected]420ae012009-04-24 05:16:32242 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32243
[email protected]420ae012009-04-24 05:16:32244 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07245 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27246 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53247 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07248 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32249
250 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07251#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32252 // If we still have a window handle, destroy it. GetNativeView can return
253 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42254 if (GetNativeView()) {
255 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44256 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42257 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42258 }
[email protected]420ae012009-04-24 05:16:32259#endif
[email protected]7ab1e7d62009-10-14 23:32:01260
261 // OnCloseStarted isn't called in unit tests.
262 if (!tab_close_start_time_.is_null()) {
263 UMA_HISTOGRAM_TIMES("Tab.Close",
264 base::TimeTicks::Now() - tab_close_start_time_);
265 }
[email protected]b5a1d11c2011-02-17 03:09:42266
[email protected]07d490bc2011-03-07 17:05:26267 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08268
[email protected]1de2b8b2011-06-29 19:38:46269 set_delegate(NULL);
270}
271
272// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
273void TabContents::set_delegate(TabContentsDelegate* delegate) {
274 if (delegate == delegate_)
275 return;
276 if (delegate_)
277 delegate_->Detach(this);
278 delegate_ = delegate;
279 if (delegate_)
280 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42281}
282
[email protected]724159a2010-12-30 01:11:18283bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17284 if (web_ui() && web_ui()->OnMessageReceived(message))
285 return true;
286
[email protected]585b30362011-01-28 02:30:17287 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
288 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10289 while ((observer = it.GetNext()) != NULL)
290 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53291 return true;
[email protected]403415a2011-01-10 18:57:53292
[email protected]724159a2010-12-30 01:11:18293 bool handled = true;
294 bool message_is_ok = true;
295 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58296 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
297 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24298 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
299 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18300 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
301 OnDidStartProvisionalLoadForFrame)
302 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
303 OnDidRedirectProvisionalLoad)
304 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
305 OnDidFailProvisionalLoadWithError)
306 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
307 OnDidLoadResourceFromMemoryCache)
308 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
309 OnDidDisplayInsecureContent)
310 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
311 OnDidRunInsecureContent)
312 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
313 OnDocumentLoadedInFrame)
314 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17315 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
316 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25317 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26318 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
319 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]c7dd2f62011-07-18 15:57:59320 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21321 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20322 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
323 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
324 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16325 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45326 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10327 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18328 IPC_MESSAGE_UNHANDLED(handled = false)
329 IPC_END_MESSAGE_MAP_EX()
330
331 if (!message_is_ok) {
332 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
333 GetRenderProcessHost()->ReceivedBadMessage();
334 }
335
336 return handled;
337}
338
[email protected]6c2e472f2011-08-24 23:26:18339void TabContents::RunFileChooser(
340 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23341 const content::FileChooserParams& params) {
[email protected]6c2e472f2011-08-24 23:26:18342 delegate()->RunFileChooser(this, params);
343}
344
[email protected]f3b1a082011-11-18 00:34:30345content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03346 if (render_manager_.current_host())
347 return render_manager_.current_host()->process();
348 else
349 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16350}
351
[email protected]d5f942ba2008-09-26 19:30:34352const GURL& TabContents::GetURL() const {
353 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57354 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54355 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34356}
357
[email protected]96d185d2009-04-24 03:28:54358const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55359 // Transient entries take precedence. They are used for interstitial pages
360 // that are shown on top of existing pages.
361 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08362 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20363 content::GetContentClient()->browser()->GetAcceptLangs(
364 this->browser_context());
[email protected]45d0ef7f2011-01-05 13:46:23365 if (entry) {
[email protected]b5cca982011-05-26 04:42:08366 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23367 }
[email protected]7ade2732011-02-10 00:13:58368 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
369 render_manager_.pending_web_ui() : render_manager_.web_ui();
370 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54371 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55372 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54373 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35374 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58375 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54376 if (!title.empty())
377 return title;
378 }
379 }
380
381 // We use the title for the last committed entry rather than a pending
382 // navigation entry. For example, when the user types in a URL, we want to
383 // keep the old page's title until the new load has committed and we get a new
384 // title.
[email protected]96d185d2009-04-24 03:28:54385 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23386 if (entry) {
[email protected]b5cca982011-05-26 04:42:08387 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23388 }
[email protected]987fc3a2011-05-26 14:18:09389
390 // |page_title_when_no_navigation_entry_| is finally used
391 // if no title cannot be retrieved.
392 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54393}
394
[email protected]d5f942ba2008-09-26 19:30:34395int32 TabContents::GetMaxPageID() {
396 if (GetSiteInstance())
397 return GetSiteInstance()->max_page_id();
398 else
399 return max_page_id_;
400}
401
402void TabContents::UpdateMaxPageID(int32 page_id) {
403 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34404 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34405 // testing.
406 if (GetSiteInstance())
407 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16408 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34409}
410
[email protected]96d185d2009-04-24 03:28:54411SiteInstance* TabContents::GetSiteInstance() const {
412 return render_manager_.current_host()->site_instance();
413}
414
[email protected]77362eb2011-08-01 17:18:38415SiteInstance* TabContents::GetPendingSiteInstance() const {
416 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
417 render_manager_.pending_render_view_host() :
418 render_manager_.current_host();
419 return dest_rvh->site_instance();
420}
421
[email protected]585b30362011-01-28 02:30:17422void TabContents::AddObserver(TabContentsObserver* observer) {
423 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49424}
425
[email protected]585b30362011-01-28 02:30:17426void TabContents::RemoveObserver(TabContentsObserver* observer) {
427 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49428}
429
[email protected]443b80e2010-12-14 00:42:23430void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
431 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34432 return;
433
[email protected]443b80e2010-12-14 00:42:23434 crashed_status_ = status;
435 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50436 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34437}
438
439void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
440 if (delegate_)
441 delegate_->NavigationStateChanged(this, changed_flags);
442}
443
[email protected]96d185d2009-04-24 03:28:54444void TabContents::DidBecomeSelected() {
445 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16446 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
447 if (rwhv) {
448 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43449#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16450 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43451#endif
452 }
[email protected]96d185d2009-04-24 03:28:54453
[email protected]5ac20162010-11-24 23:33:11454 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38455
456 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54457}
458
459void TabContents::WasHidden() {
460 if (!capturing_contents()) {
461 // |render_view_host()| can be NULL if the user middle clicks a link to open
462 // a tab in then background, then closes the tab before selecting it. This
463 // is because closing the tab calls TabContents::Destroy(), which removes
464 // the |render_view_host()|; then when we actually destroy the window,
465 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16466 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
467 if (rwhv)
468 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54469 }
470
[email protected]ad50def52011-10-19 23:17:07471 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27472 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53473 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07474 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54475}
476
[email protected]d5f942ba2008-09-26 19:30:34477void TabContents::Activate() {
478 if (delegate_)
479 delegate_->ActivateContents(this);
480}
481
[email protected]ea42e7782010-08-23 23:58:12482void TabContents::Deactivate() {
483 if (delegate_)
484 delegate_->DeactivateContents(this);
485}
486
[email protected]63954792011-07-11 04:17:48487void TabContents::LostCapture() {
488 if (delegate_)
489 delegate_->LostCapture();
490}
491
492bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
493 bool* is_keyboard_shortcut) {
494 return delegate_ &&
495 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
496}
497
498void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
499 if (delegate_)
500 delegate_->HandleKeyboardEvent(event);
501}
502
[email protected]32ded2212011-11-10 18:51:43503void TabContents::HandleMouseDown() {
504 if (delegate_)
505 delegate_->HandleMouseDown();
506}
507
[email protected]63954792011-07-11 04:17:48508void TabContents::HandleMouseUp() {
509 if (delegate_)
510 delegate_->HandleMouseUp();
511}
512
513void TabContents::HandleMouseActivate() {
514 if (delegate_)
515 delegate_->HandleMouseActivate();
516}
517
[email protected]8a5e0ca2011-08-25 06:30:47518void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
519 if (delegate_)
520 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
521}
522
[email protected]5d5f7af2011-10-01 01:38:12523bool TabContents::IsFullscreenForCurrentTab() const {
524 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
525}
526
[email protected]e9621112011-10-17 05:38:37527void TabContents::RequestToLockMouse() {
528 if (delegate_) {
529 delegate_->RequestToLockMouse(this);
530 } else {
531 GotResponseToLockMouseRequest(false);
532 }
533}
534
535void TabContents::LostMouseLock() {
536 if (delegate_)
537 delegate_->LostMouseLock();
538}
539
[email protected]0548c5352011-09-07 00:33:33540void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
541 if (delegate_)
542 delegate_->UpdatePreferredSize(this, pref_size);
543}
544
[email protected]32ded2212011-11-10 18:51:43545void TabContents::WebUISend(RenderViewHost* render_view_host,
546 const GURL& source_url,
547 const std::string& name,
548 const base::ListValue& args) {
549 if (delegate_)
550 delegate_->WebUISend(this, source_url, name, args);
551}
552
[email protected]96d185d2009-04-24 03:28:54553void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16554 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
555 if (rwhv)
556 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54557}
558
559void TabContents::HideContents() {
560 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
561 // our superclass HideContents(), because some callers want to be very picky
562 // about the order in which these get called. In addition to making the code
563 // here practically impossible to understand, this also means we end up
564 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34565 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54566 WasHidden();
567}
568
[email protected]5aab5e22010-12-08 22:13:29569bool TabContents::NeedToFireBeforeUnload() {
570 // TODO(creis): Should we fire even for interstitial pages?
571 return notify_disconnection() &&
572 !showing_interstitial_page() &&
573 !render_view_host()->SuddenTerminationAllowed();
574}
575
[email protected]00c37fc2011-08-02 00:22:50576// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25577TabContents* TabContents::OpenURL(const GURL& url,
578 const GURL& referrer,
579 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58580 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10581 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
582 DCHECK(referrer.is_empty());
[email protected]bce1f1c2011-12-05 15:11:58583 return OpenURL(OpenURLParams(url, content::Referrer(), disposition,
584 transition, false));
[email protected]00c37fc2011-08-02 00:22:50585}
586
587TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49588 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50589 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49590 // Notify observers.
591 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50592 DidOpenURL(params.url, params.referrer,
593 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25594 return new_contents;
[email protected]1c642b52011-04-15 09:05:49595 }
[email protected]992e4542011-07-20 23:09:25596 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34597}
598
[email protected]1ccb3568d2010-02-19 10:51:16599bool TabContents::NavigateToPendingEntry(
600 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27601 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54602}
[email protected]96d185d2009-04-24 03:28:54603
[email protected]876bc832010-09-07 16:29:54604bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27605 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54606 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40607 // The renderer will reject IPC messages with URLs longer than
608 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27609 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40610 return false;
611
[email protected]dd11de52011-11-03 22:54:27612 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40613 if (!dest_render_view_host)
614 return false; // Unable to create the desired render view host.
615
[email protected]80a8fad2011-01-29 04:02:38616 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07617 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58618 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56619 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37620 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]dd11de52011-11-03 22:54:27621 entry.url());
[email protected]32ded2212011-11-10 18:51:43622#if defined(OS_CHROMEOS)
623 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
624#endif
[email protected]e091df82011-10-11 18:13:21625 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55626 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58627
[email protected]96d185d2009-04-24 03:28:54628 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44629 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
630 render_view_host(),
631 dest_render_view_host,
632 entry.url());
[email protected]96d185d2009-04-24 03:28:54633
634 // Used for page load time metrics.
635 current_load_start_ = base::TimeTicks::Now();
636
637 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34638 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27639 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47640 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34641 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54642
[email protected]dd11de52011-11-03 22:54:27643 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54644 // HACK!! This code suppresses javascript: URLs from being added to
645 // session history, which is what we want to do for javascript: URLs that
646 // do not generate content. What we really need is a message from the
647 // renderer telling us that a new page was not created. The same message
648 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27649 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54650 return false;
651 }
652
[email protected]3c9e1872010-11-18 16:17:49653 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04654 FOR_EACH_OBSERVER(TabContentsObserver,
655 observers_,
[email protected]dd11de52011-11-03 22:54:27656 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54657
[email protected]09b29342011-06-24 19:18:48658 if (delegate_)
659 delegate_->DidNavigateToPendingEntry(this);
660
[email protected]d5f942ba2008-09-26 19:30:34661 return true;
662}
663
[email protected]9e1ad4b2011-08-14 16:49:19664void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
665 int history_length,
666 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41667 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
668 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19669 if (render_manager_.pending_render_view_host()) {
670 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14671 return;
[email protected]9e1ad4b2011-08-14 16:49:19672 }
673 RenderViewHost* rvh = render_view_host();
674 if (!rvh) {
675 NOTREACHED();
676 return;
677 }
678 if (site_instance && rvh->site_instance() != site_instance) {
679 NOTREACHED();
680 return;
681 }
682 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
683 history_length,
684 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14685}
686
[email protected]96d185d2009-04-24 03:28:54687void TabContents::Stop() {
688 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47689 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54690}
691
[email protected]96d185d2009-04-24 03:28:54692TabContents* TabContents::Clone() {
693 // We create a new SiteInstance so that the new tab won't share processes
694 // with the old one. This can be changed in the future if we need it to share
695 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37696 TabContents* tc = new TabContents(
697 browser_context(),
698 SiteInstance::CreateSiteInstance(browser_context()),
699 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54700 tc->controller().CopyStateFrom(controller_);
701 return tc;
702}
703
[email protected]4d677202009-07-19 07:37:12704void TabContents::ShowPageInfo(const GURL& url,
705 const NavigationEntry::SSLStatus& ssl,
706 bool show_history) {
707 if (!delegate_)
708 return;
709
[email protected]3d7474ff2011-07-27 17:47:37710 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12711}
712
[email protected]e7cfdbd2011-04-22 14:41:37713void TabContents::AddNewContents(TabContents* new_contents,
714 WindowOpenDisposition disposition,
715 const gfx::Rect& initial_pos,
716 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29717 if (!delegate_)
718 return;
719
[email protected]e7cfdbd2011-04-22 14:41:37720 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
721 user_gesture);
[email protected]96d185d2009-04-24 03:28:54722}
723
[email protected]5c9e97a2009-09-09 23:48:30724gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54725 return view_->GetContentNativeView();
726}
727
728gfx::NativeView TabContents::GetNativeView() const {
729 return view_->GetNativeView();
730}
731
732void TabContents::GetContainerBounds(gfx::Rect *out) const {
733 view_->GetContainerBounds(out);
734}
735
736void TabContents::Focus() {
737 view_->Focus();
738}
739
[email protected]90daadb42009-06-08 21:27:28740void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54741 if (showing_interstitial_page()) {
742 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
743 return;
744 }
[email protected]96d185d2009-04-24 03:28:54745 render_view_host()->SetInitialFocus(reverse);
746}
747
748bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40749 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58750 if (web_ui)
751 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43752 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25753 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43754 return true;
[email protected]96d185d2009-04-24 03:28:54755 return false;
756}
757
[email protected]a26dc362010-04-23 01:48:58758void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38759 if (delegate())
[email protected]a26dc362010-04-23 01:48:58760 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38761}
762
[email protected]686493142011-07-15 21:47:22763bool TabContents::CanDownload(int request_id) {
764 TabContentsDelegate* d = delegate();
765 if (d)
766 return d->CanDownload(this, request_id);
767 return true;
768}
769
770void TabContents::OnStartDownload(DownloadItem* download) {
771 TabContentsDelegate* d = delegate();
772 if (d)
773 d->OnStartDownload(this, download);
774}
775
[email protected]c7dd2f62011-07-18 15:57:59776void TabContents::OnSavePage() {
777 // If we can not save the page, try to download it.
778 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37779 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59780 const GURL& current_page_url = GetURL();
781 if (dlm && current_page_url.is_valid()) {
782 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46783 download_stats::RecordDownloadCount(
784 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59785 return;
786 }
787 }
788
789 Stop();
790
791 // Create the save package and possibly prompt the user for the name to save
792 // the page as. The user prompt is an asynchronous operation that runs on
793 // another thread.
794 save_package_ = new SavePackage(this);
795 save_package_->GetSaveInfo();
796}
797
798// Used in automated testing to bypass prompting the user for file names.
799// Instead, the names and paths are hard coded rather than running them through
800// file name sanitation and extension / mime checking.
801bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
802 SavePackage::SavePackageType save_type) {
803 // Stop the page from navigating.
804 Stop();
805
806 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
807 return save_package_->Init();
808}
809
810void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37811 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59812 dlm->DownloadUrl(url, GetURL(), "", this);
813}
814
[email protected]420ae012009-04-24 05:16:32815bool TabContents::IsActiveEntry(int32 page_id) {
816 NavigationEntry* active_entry = controller_.GetActiveEntry();
817 return (active_entry != NULL &&
818 active_entry->site_instance() == GetSiteInstance() &&
819 active_entry->page_id() == page_id);
820}
821
[email protected]b2fe07d12010-02-09 14:38:08822void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16823 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26824 render_view_host()->Send(new ViewMsg_SetPageEncoding(
825 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16826}
827
[email protected]b2fe07d12010-02-09 14:38:08828void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16829 reset_encoding();
[email protected]216813952011-05-19 22:21:26830 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
831 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16832}
833
[email protected]7ab1e7d62009-10-14 23:32:01834void TabContents::OnCloseStarted() {
835 if (tab_close_start_time_.is_null())
836 tab_close_start_time_ = base::TimeTicks::Now();
837}
838
[email protected]46624bf2010-06-09 16:04:19839bool TabContents::ShouldAcceptDragAndDrop() const {
840#if defined(OS_CHROMEOS)
841 // ChromeOS panels (pop-ups) do not take drag-n-drop.
842 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14843 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20844 return false;
845 return true;
[email protected]46624bf2010-06-09 16:04:19846#else
847 return true;
848#endif
849}
850
[email protected]7813bd72011-02-05 02:19:34851void TabContents::SystemDragEnded() {
852 if (render_view_host())
853 render_view_host()->DragSourceSystemDragEnded();
854 if (delegate())
855 delegate()->DragEnded();
856}
857
[email protected]d0b8d092010-10-25 04:05:17858double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37859 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25860 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17861 return 0;
[email protected]b75b8292010-10-01 07:28:25862
863 double zoom_level;
864 if (temporary_zoom_settings_) {
865 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]f3b1a082011-11-18 00:34:30866 GetRenderProcessHost()->GetID(), render_view_host()->routing_id());
[email protected]b75b8292010-10-01 07:28:25867 } else {
[email protected]2ae88d12011-10-14 09:11:19868 GURL url;
869 NavigationEntry* active_entry = controller().GetActiveEntry();
870 // Since zoom map is updated using rewritten URL, use rewritten URL
871 // to get the zoom level.
872 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
873 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25874 }
[email protected]d0b8d092010-10-25 04:05:17875 return zoom_level;
876}
[email protected]b75b8292010-10-01 07:28:25877
[email protected]d0b8d092010-10-25 04:05:17878int TabContents::GetZoomPercent(bool* enable_increment,
879 bool* enable_decrement) {
880 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01881 // Calculate the zoom percent from the factor. Round up to the nearest whole
882 // number.
[email protected]b75b8292010-10-01 07:28:25883 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:01884 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:25885 *enable_decrement = percent > minimum_zoom_percent_;
886 *enable_increment = percent < maximum_zoom_percent_;
887 return percent;
888}
889
[email protected]3c733bde2010-12-21 19:56:31890void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50891 if (!delegate_)
892 return;
893
894 NavigationEntry* active_entry = controller().GetActiveEntry();
895 if (!active_entry)
896 return;
897
898 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12899}
900
[email protected]932b7a12011-03-09 12:50:27901void TabContents::ViewFrameSource(const GURL& url,
902 const std::string& content_state) {
903 if (!delegate_)
904 return;
905
906 delegate_->ViewSourceForFrame(this, url, content_state);
907}
908
[email protected]c40d6232011-03-25 00:16:21909void TabContents::SetContentRestrictions(int restrictions) {
910 content_restrictions_ = restrictions;
911 delegate()->ContentRestrictionsChanged(this);
912}
913
[email protected]8b5af492011-11-28 21:50:58914void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30915 const string16& type,
916 const string16& href,
917 const string16& title,
918 const string16& disposition) {
919 delegate()->RegisterIntentHandler(
920 this, action, type, href, title, disposition);
921}
922
923void TabContents::OnWebIntentDispatch(const IPC::Message& message,
924 const webkit_glue::WebIntentData& intent,
925 int intent_id) {
[email protected]ada02b312011-12-01 21:54:53926 IntentsHostImpl* intents_host = new IntentsHostImpl(this, intent, intent_id);
927 delegate()->WebIntentDispatch(this, intents_host);
[email protected]63c239322011-10-31 23:56:30928}
929
[email protected]724159a2010-12-30 01:11:18930void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
931 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59932 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18933 const GURL& url) {
934 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
935 GURL validated_url(url);
936 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30937 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18938
[email protected]8093a542011-05-13 07:29:32939 RenderViewHost* rvh =
940 render_manager_.pending_render_view_host() ?
941 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10942 // Notify observers about the start of the provisional load.
943 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
944 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32945 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10946
[email protected]724159a2010-12-30 01:11:18947 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59948 // Notify observers about the provisional change in the main frame URL.
949 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59950 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18951 }
952}
953
954void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59955 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18956 const GURL& source_url,
957 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49958 // TODO(creis): Remove this method and have the pre-rendering code listen to
959 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
960 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18961 NavigationEntry* entry;
962 if (page_id == -1)
963 entry = controller_.pending_entry();
964 else
965 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
966 if (!entry || entry->url() != source_url)
967 return;
[email protected]e7d50892011-01-19 21:47:38968
[email protected]4850a7f2011-03-08 23:36:59969 // Notify observers about the provisional change in the main frame URL.
970 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26971 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59972 opener_url));
[email protected]724159a2010-12-30 01:11:18973}
974
975void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58976 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
977 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
978 << ", error_code: " << params.error_code
979 << ", error_description: " << params.error_description
980 << ", is_main_frame: " << params.is_main_frame
981 << ", showing_repost_interstitial: " <<
982 params.showing_repost_interstitial
983 << ", frame_id: " << params.frame_id;
984 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18985 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30986 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18987
[email protected]d7b175e2011-10-11 15:31:58988 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18989 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
990 // This means that the interstitial won't be torn down properly, which is
991 // bad. But if we have an interstitial, go back to another tab type, and
992 // then load the same interstitial again, we could end up getting the first
993 // interstitial's "failed" message (as a result of the cancel) when we're on
994 // the second one.
995 //
996 // We can't tell this apart, so we think we're tearing down the current page
997 // which will cause a crash later one. There is also some code in
998 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
999 // out because of this problem.
1000 //
1001 // http://code.google.com/p/chromium/issues/detail?id=2855
1002 // Because this will not tear down the interstitial properly, if "back" is
1003 // back to another tab type, the interstitial will still be somewhat alive
1004 // in the previous tab type. If you navigate somewhere that activates the
1005 // tab with the interstitial again, you'll see a flash before the new load
1006 // commits of the interstitial page.
1007 if (showing_interstitial_page()) {
1008 LOG(WARNING) << "Discarding message during interstitial.";
1009 return;
1010 }
1011
[email protected]02102f82011-06-13 20:37:021012 // Discard our pending entry if the load canceled (e.g. if we decided to
1013 // download the file instead of load it). We do not verify that the URL
1014 // being canceled matches the pending entry's URL because they will not
1015 // match if a redirect occurred (in which case we do not want to leave a
1016 // stale redirect URL showing). This means that we also cancel the pending
1017 // entry if the user started a new navigation. As a result, the navigation
1018 // controller may not remember that a load is in progress, but the
1019 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181020 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021021 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161022 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181023
1024 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1025 }
1026
1027 // Send out a notification that we failed a provisional load with an error.
1028 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581029 params.is_main_frame,
1030 controller_.IsURLInPageNavigation(validated_url),
1031 validated_url,
1032 std::string(),
1033 false,
1034 params.frame_id);
1035 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181036
[email protected]ad50def52011-10-19 23:17:071037 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271038 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531039 content::Source<NavigationController>(&controller_),
1040 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101041
[email protected]d7b175e2011-10-11 15:31:581042 FOR_EACH_OBSERVER(TabContentsObserver,
1043 observers_,
1044 DidFailProvisionalLoad(params.frame_id,
1045 params.is_main_frame,
1046 validated_url,
1047 params.error_code,
1048 params.error_description));
[email protected]724159a2010-12-30 01:11:181049}
1050
1051void TabContents::OnDidLoadResourceFromMemoryCache(
1052 const GURL& url,
[email protected]70435962011-08-02 20:13:281053 const std::string& security_info,
1054 const std::string& http_method,
1055 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191056 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181057 cache.Increment();
1058
1059 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081060 int cert_id = 0;
1061 net::CertStatus cert_status = 0;
1062 int security_bits = -1;
1063 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181064 SSLManager::DeserializeSecurityInfo(security_info,
1065 &cert_id, &cert_status,
1066 &security_bits,
1067 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301068 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161069 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181070
[email protected]ad50def52011-10-19 23:17:071071 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271072 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531073 content::Source<NavigationController>(&controller_),
1074 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181075}
1076
1077void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161078 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181079 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071080 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181081}
1082
1083void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021084 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231085 LOG(INFO) << security_origin << " ran insecure content from "
1086 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161087 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051088 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
1089 UserMetrics::RecordAction(
1090 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1091 }
[email protected]724159a2010-12-30 01:11:181092 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411093 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071094 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181095}
1096
1097void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1098 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101099 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1100 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181101}
1102
[email protected]1a55c5be2011-11-29 11:36:311103void TabContents::OnDidFinishLoad(
1104 int64 frame_id,
1105 const GURL& validated_url,
1106 bool is_main_frame) {
[email protected]0d60f0192011-04-14 12:40:101107 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311108 DidFinishLoad(frame_id, validated_url, is_main_frame));
1109}
1110
1111void TabContents::OnDidFailLoadWithError(int64 frame_id,
1112 const GURL& validated_url,
1113 bool is_main_frame,
1114 int error_code,
1115 const string16& error_description) {
1116 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1117 DidFailLoad(frame_id, validated_url, is_main_frame,
1118 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181119}
1120
[email protected]c8f73ab2011-01-22 00:05:171121void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211122 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171123}
1124
[email protected]216813952011-05-19 22:21:261125void TabContents::OnGoToEntryAtOffset(int offset) {
1126 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1127 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1128 if (!entry)
1129 return;
1130 // Note that we don't call NavigationController::GotToOffset() as we don't
1131 // want to create a pending navigation entry (it might end up lingering
1132 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581133 entry->set_transition_type(
1134 content::PageTransitionFromInt(
1135 entry->transition_type() |
1136 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271137 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571138
1139 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1140 // it in now that we know. This allows us to find the entry when it commits.
1141 if (!entry->site_instance() &&
1142 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381143 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571144 }
[email protected]216813952011-05-19 22:21:261145 }
1146}
1147
1148void TabContents::OnUpdateZoomLimits(int minimum_percent,
1149 int maximum_percent,
1150 bool remember) {
1151 minimum_zoom_percent_ = minimum_percent;
1152 maximum_zoom_percent_ = maximum_percent;
1153 temporary_zoom_settings_ = !remember;
1154}
1155
1156void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
[email protected]ad50def52011-10-19 23:17:071157 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271158 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]6c2381d2011-10-19 02:52:531159 content::Source<TabContents>(this),
1160 content::Details<const bool>(&is_editable_node));
[email protected]216813952011-05-19 22:21:261161}
1162
[email protected]3a29a6e2011-08-24 18:26:211163void TabContents::OnEnumerateDirectory(int request_id,
1164 const FilePath& path) {
1165 delegate()->EnumerateDirectory(this, request_id, path);
1166}
1167
[email protected]7d189022011-08-25 22:54:201168void TabContents::OnJSOutOfMemory() {
1169 delegate()->JSOutOfMemory(this);
1170}
1171
1172void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1173 const GURL& url,
1174 const string16& title) {
1175 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1176}
1177
[email protected]b888919c2011-09-02 00:32:161178void TabContents::OnFindReply(int request_id,
1179 int number_of_matches,
1180 const gfx::Rect& selection_rect,
1181 int active_match_ordinal,
1182 bool final_update) {
1183 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1184 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001185 // Send a notification to the renderer that we are ready to receive more
1186 // results from the scoping effort of the Find operation. The FindInPage
1187 // scoping is asynchronous and periodically sends results back up to the
1188 // browser using IPC. In an effort to not spam the browser we have the
1189 // browser send an ACK for each FindReply message and have the renderer
1190 // queue up the latest status message while waiting for this ACK.
1191 render_view_host()->Send(
1192 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161193}
1194
[email protected]d952a052011-09-06 18:42:451195void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1196 delegate()->CrashedPlugin(this, plugin_path);
1197}
1198
[email protected]7fc4bbb2011-09-08 21:23:101199void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1200 bool blocked_by_policy) {
1201 // Notify observers about navigation.
1202 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1203 AppCacheAccessed(manifest_url, blocked_by_policy));
1204}
1205
[email protected]96d185d2009-04-24 03:28:541206// Notifies the RenderWidgetHost instance about the fact that the page is
1207// loading, or done loading and calls the base implementation.
1208void TabContents::SetIsLoading(bool is_loading,
1209 LoadNotificationDetails* details) {
1210 if (is_loading == is_loading_)
1211 return;
1212
1213 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211214 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541215 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561216 upload_size_ = 0;
1217 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541218 }
1219
1220 render_manager_.SetIsLoading(is_loading);
1221
1222 is_loading_ = is_loading;
1223 waiting_for_response_ = is_loading;
1224
[email protected]6ebdc9b2010-09-27 16:55:571225 if (delegate_)
1226 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351227 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541228
[email protected]432115822011-07-10 15:52:271229 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1230 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071231 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541232 if (details)
[email protected]6c2381d2011-10-19 02:52:531233 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071234 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531235 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541236 det);
1237}
1238
[email protected]d0980792011-02-13 19:41:401239WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581240 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541241 // that goes along with it to control the basic flags. For example, we want to
1242 // show the pending URL in the URL bar, so we want the display_url flag to
1243 // be from the pending entry.
1244 //
1245 // The confusion comes because there are multiple possibilities for the
1246 // initial load in a tab as a side effect of the way the RenderViewHostManager
1247 // works.
1248 //
[email protected]e0112912011-02-02 22:54:351249 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541250 // the pending one, and we want it to apply here.
1251 //
1252 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1253 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581254 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351255 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541256 //
1257 // This condition handles all of these cases:
1258 //
1259 // - First load in first tab: no committed nav entry + pending nav entry +
1260 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351261 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541262 //
1263 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351264 // no pending Web UI:
1265 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541266 //
1267 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351268 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541269 //
1270 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351271 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541272 if (controller_.pending_entry() &&
1273 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581274 render_manager_.pending_web_ui()))
1275 return render_manager_.pending_web_ui();
1276 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541277}
[email protected]420ae012009-04-24 05:16:321278
[email protected]1fd1a502011-03-30 16:55:561279WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371280 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1281 GetURL());
[email protected]1fd1a502011-03-30 16:55:561282}
1283
[email protected]420ae012009-04-24 05:16:321284void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131285 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321286 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561287 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381288 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441289 // that opened the window, as long as both renderers have the same
1290 // privileges.
[email protected]1fd1a502011-03-30 16:55:561291 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1292 WebUI* web_ui = content::GetContentClient()->browser()->
1293 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581294 // web_ui might be NULL if the URL refers to a non-existent extension.
1295 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401296 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581297 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441298 }
1299 }
[email protected]1fd1a502011-03-30 16:55:561300 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441301 }
1302
[email protected]4e697b042011-07-08 06:44:561303 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321304 // Clear the status bubble. This is a workaround for a bug where WebKit
1305 // doesn't let us know that the cursor left an element during a
1306 // transition (this is also why the mouse cursor remains as a hand after
1307 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1308 // clear the bubble when a user navigates to a named anchor in the same
1309 // page.
1310 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321311 }
1312
[email protected]a6e82fc2010-02-24 22:28:141313 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471314 // Once the main frame is navigated, we're no longer considered to have
1315 // displayed insecure content.
1316 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171317 }
[email protected]ce5c4502009-05-06 16:46:111318
[email protected]3c9e1872010-11-18 16:17:491319 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171320 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041321 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321322}
1323
1324void TabContents::DidNavigateAnyFramePostCommit(
1325 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131326 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321327 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071328 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321329 // a malicious script from spamming messages, since the script could just
1330 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551331 if (dialog_creator_) {
1332 dialog_creator_->ResetJavaScriptState(this);
1333 dialog_creator_ = NULL;
1334 }
[email protected]420ae012009-04-24 05:16:321335
[email protected]3c9e1872010-11-18 16:17:491336 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171337 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041338 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321339}
1340
[email protected]420ae012009-04-24 05:16:321341void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1342 RenderViewHost* rvh) {
1343 // If we are creating a RVH for a restored controller, then we might
1344 // have more page IDs than the SiteInstance's current max page ID. We must
1345 // make sure that the max page ID is larger than any restored page ID.
1346 // Note that it is ok for conflicting page IDs to exist in another tab
1347 // (i.e., NavigationController), but if any page ID is larger than the max,
1348 // the back/forward list will get confused.
1349 int max_restored_page_id = controller_.max_restored_page_id();
1350 if (max_restored_page_id > 0) {
1351 int curr_max_page_id = site_instance->max_page_id();
1352 if (max_restored_page_id > curr_max_page_id) {
1353 // Need to update the site instance immediately.
1354 site_instance->UpdateMaxPageID(max_restored_page_id);
1355
1356 // Also tell the renderer to update its internal representation. We
1357 // need to reserve enough IDs to make all restored page IDs less than
1358 // the max.
1359 if (curr_max_page_id < 0)
1360 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261361 rvh->Send(new ViewMsg_ReservePageIDRange(
1362 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321363 }
1364 }
1365}
1366
[email protected]6b2f7a82011-04-25 19:30:511367bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571368 const string16& title) {
[email protected]420ae012009-04-24 05:16:321369 // For file URLs without a title, use the pathname instead. In the case of a
1370 // synthesized title, we don't want the update to count toward the "one set
1371 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511372 string16 final_title;
[email protected]420ae012009-04-24 05:16:321373 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091374 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511375 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321376 explicit_set = false; // Don't count synthetic titles toward the set limit.
1377 } else {
[email protected]acafd272011-07-26 17:35:571378 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321379 explicit_set = true;
1380 }
1381
[email protected]987fc3a2011-05-26 14:18:091382 // If a page is created via window.open and never navigated,
1383 // there will be no navigation entry. In this situation,
1384 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1385 if (entry) {
1386 if (final_title == entry->title())
1387 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321388
[email protected]987fc3a2011-05-26 14:18:091389 entry->set_title(final_title);
1390 } else {
1391 if (page_title_when_no_navigation_entry_ == final_title)
1392 return false; // Nothing changed, don't bother.
1393
1394 page_title_when_no_navigation_entry_ = final_title;
1395 }
[email protected]420ae012009-04-24 05:16:321396
[email protected]420ae012009-04-24 05:16:321397 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231398 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321399
[email protected]105bb0f2011-05-24 17:12:141400 TitleUpdatedDetails details(entry, explicit_set);
1401
[email protected]ad50def52011-10-19 23:17:071402 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271403 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531404 content::Source<TabContents>(this),
1405 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041406
[email protected]420ae012009-04-24 05:16:321407 return true;
1408}
1409
1410void TabContents::NotifySwapped() {
1411 // After sending out a swap notification, we need to send a disconnect
1412 // notification so that clients that pick up a pointer to |this| can NULL the
1413 // pointer. See Bug 1230284.
1414 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071415 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271416 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531417 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071418 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321419}
1420
1421void TabContents::NotifyConnected() {
1422 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071423 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271424 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531425 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071426 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321427}
1428
1429void TabContents::NotifyDisconnected() {
1430 if (!notify_disconnection_)
1431 return;
1432
1433 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071434 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271435 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531436 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071437 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321438}
1439
[email protected]8d3347f2009-07-09 22:00:211440RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321441 return view_.get();
1442}
1443
[email protected]8d3347f2009-07-09 22:00:211444RenderViewHostDelegate::RendererManagement*
1445TabContents::GetRendererManagementDelegate() {
1446 return &render_manager_;
1447}
1448
[email protected]daf82f82011-10-31 22:35:311449content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371450 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461451 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511452}
1453
[email protected]57c6a652009-05-04 07:58:341454TabContents* TabContents::GetAsTabContents() {
1455 return this;
1456}
1457
[email protected]da4dfc42011-10-12 15:53:561458content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431459 return view_type_;
[email protected]7b291f92009-08-14 05:43:531460}
1461
[email protected]420ae012009-04-24 05:16:321462void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071463 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271464 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531465 content::Source<TabContents>(this),
1466 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321467 NavigationEntry* entry = controller_.GetActiveEntry();
1468 if (!entry)
1469 return;
1470
1471 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351472 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561473 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581474 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321475
1476 if (entry->IsViewSourceMode()) {
1477 // Put the renderer in view source mode.
1478 render_view_host->Send(
1479 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1480 }
[email protected]0666aef2009-05-13 19:48:081481
1482 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261483
1484 FOR_EACH_OBSERVER(
1485 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321486}
1487
1488void TabContents::RenderViewReady(RenderViewHost* rvh) {
1489 if (rvh != render_view_host()) {
1490 // Don't notify the world, since this came from a renderer in the
1491 // background.
1492 return;
1493 }
1494
1495 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301496 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231497 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301498
1499 // Restore the focus to the tab (otherwise the focus will be on the top
1500 // window).
[email protected]484ae5912010-09-29 19:16:141501 if (was_crashed && !FocusLocationBarByDefault() &&
1502 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301503 Focus();
[email protected]484ae5912010-09-29 19:16:141504 }
[email protected]32ded2212011-11-10 18:51:431505
1506 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321507}
1508
[email protected]443b80e2010-12-14 00:42:231509void TabContents::RenderViewGone(RenderViewHost* rvh,
1510 base::TerminationStatus status,
1511 int error_code) {
[email protected]420ae012009-04-24 05:16:321512 if (rvh != render_view_host()) {
1513 // The pending page's RenderViewHost is gone.
1514 return;
1515 }
1516
1517 SetIsLoading(false, NULL);
1518 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231519 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541520 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321521
[email protected]9cddb1a22011-11-15 15:04:271522 FOR_EACH_OBSERVER(TabContentsObserver,
1523 observers_,
1524 RenderViewGone(crashed_status()));
[email protected]420ae012009-04-24 05:16:321525}
1526
[email protected]2e4633c2009-07-09 16:58:061527void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481528 render_manager_.RenderViewDeleted(rvh);
[email protected]483623eb2011-10-25 09:30:001529 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061530}
1531
[email protected]420ae012009-04-24 05:16:321532void TabContents::DidNavigate(RenderViewHost* rvh,
1533 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581534 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321535 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371536
[email protected]420ae012009-04-24 05:16:321537 // Update the site of the SiteInstance if it doesn't have one yet.
1538 if (!GetSiteInstance()->has_site())
1539 GetSiteInstance()->SetSite(params.url);
1540
1541 // Need to update MIME type here because it's referred to in
1542 // UpdateNavigationCommands() called by RendererDidNavigate() to
1543 // determine whether or not to enable the encoding menu.
1544 // It's updated only for the main frame. For a subframe,
1545 // RenderView::UpdateURL does not set params.contents_mime_type.
1546 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1547 // TODO(jungshik): Add a test for the encoding menu to avoid
1548 // regressing it again.
[email protected]2905f742011-10-13 03:51:581549 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321550 contents_mime_type_ = params.contents_mime_type;
1551
[email protected]8286f51a2011-05-31 17:39:131552 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001553 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391554
[email protected]a9c0bfe2010-09-17 08:35:221555 // Send notification about committed provisional loads. This notification is
1556 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1557 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081558 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071559 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1560 // that is not recorded in the navigation history. For the purpose of
1561 // tracking navigation events, we treat this event as a sub frame navigation
1562 // event.
1563 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581564 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221565 // Whether or not a page transition was triggered by going backward or
1566 // forward in the history is only stored in the navigation controller's
1567 // entry list.
1568 if (did_navigate &&
1569 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581570 content::PAGE_TRANSITION_FORWARD_BACK)) {
1571 transition_type = content::PageTransitionFromInt(
1572 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221573 }
[email protected]0d60f0192011-04-14 12:40:101574 // Notify observers about the commit of the provisional load.
1575 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1576 DidCommitProvisionalLoadForFrame(params.frame_id,
1577 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221578 }
1579
[email protected]76543b92009-08-31 17:27:451580 if (!did_navigate)
1581 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321582
1583 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1584 // for the appropriate notification (best) or you can add it to
1585 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1586 // necessary, please).
1587
1588 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001589 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321590 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481591 if (delegate())
1592 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001593 }
[email protected]420ae012009-04-24 05:16:321594 DidNavigateAnyFramePostCommit(rvh, details, params);
1595}
1596
1597void TabContents::UpdateState(RenderViewHost* rvh,
1598 int32 page_id,
1599 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151600 // Ensure that this state update comes from either the active RVH or one of
1601 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1602 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321603
1604 // We must be prepared to handle state updates for any page, these occur
1605 // when the user is scrolling and entering form data, as well as when we're
1606 // leaving a page, in which case our state may have already been moved to
1607 // the next page. The navigation controller will look up the appropriate
1608 // NavigationEntry and update it when it is notified via the delegate.
1609
1610 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151611 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321612 if (entry_index < 0)
1613 return;
1614 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1615
1616 if (state == entry->content_state())
1617 return; // Nothing to update.
1618 entry->set_content_state(state);
1619 controller_.NotifyEntryChanged(entry, entry_index);
1620}
1621
1622void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571623 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461624 const string16& title,
1625 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321626 // If we have a title, that's a pretty good indication that we've started
1627 // getting useful data.
1628 SetNotWaitingForResponse();
1629
1630 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481631 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581632 page_id);
[email protected]987fc3a2011-05-26 14:18:091633
[email protected]a49e10b2011-08-01 23:57:461634 // TODO(evan): make use of title_direction.
1635 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091636 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321637 return;
1638
1639 // Broadcast notifications when the UI should be updated.
1640 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031641 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321642}
1643
[email protected]420ae012009-04-24 05:16:321644void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401645 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321646 set_encoding(encoding);
1647}
1648
1649void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1650 if (delegate())
[email protected]d952a052011-09-06 18:42:451651 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321652}
1653
[email protected]420ae012009-04-24 05:16:321654void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291655 // The UI may be in an event-tracking loop, such as between the
1656 // mouse-down and mouse-up in text selection or a button click.
1657 // Defer the close until after tracking is complete, so that we
1658 // don't free objects out from under the UI.
1659 // TODO(shess): This could probably be integrated with the
1660 // IsDoingDrag() test below. Punting for now because I need more
1661 // research to understand how this impacts platforms other than Mac.
1662 // TODO(shess): This could get more fine-grained. For instance,
1663 // closing a tab in another window while selecting text in the
1664 // current window's Omnibox should be just fine.
1665 if (view()->IsEventTracking()) {
1666 view()->CloseTabAfterEventTracking();
1667 return;
1668 }
1669
[email protected]24a4d1062009-07-10 23:10:421670 // If we close the tab while we're in the middle of a drag, we'll crash.
1671 // Instead, cancel the drag and close it as soon as the drag ends.
1672 if (view()->IsDoingDrag()) {
1673 view()->CancelDragAndCloseTab();
1674 return;
1675 }
1676
[email protected]420ae012009-04-24 05:16:321677 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1678 if (delegate() && rvh == render_view_host())
1679 delegate()->CloseContents(this);
1680}
1681
[email protected]cd9ed79d2011-11-15 19:22:571682void TabContents::SwappedOut(RenderViewHost* rvh) {
1683 if (delegate() && rvh == render_view_host())
1684 delegate()->SwappedOut(this);
1685}
1686
[email protected]420ae012009-04-24 05:16:321687void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141688 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321689 delegate()->MoveContents(this, new_bounds);
1690}
1691
[email protected]7ab1e7d62009-10-14 23:32:011692void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321693 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491694
[email protected]c40d6232011-03-25 00:16:211695 if (delegate() && content_restrictions_) {
1696 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211697 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001698 }
[email protected]3c9e1872010-11-18 16:17:491699
1700 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171701 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321702}
1703
[email protected]7ab1e7d62009-10-14 23:32:011704void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321705 scoped_ptr<LoadNotificationDetails> details;
1706
1707 NavigationEntry* entry = controller_.GetActiveEntry();
1708 // An entry may not exist for a stop when loading an initial blank page or
1709 // if an iframe injected by script into a blank page finishes loading.
1710 if (entry) {
[email protected]420ae012009-04-24 05:16:321711 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1712
1713 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541714 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321715 entry->transition_type(),
1716 elapsed,
1717 &controller_,
1718 controller_.GetCurrentEntryIndex()));
1719 }
1720
[email protected]420ae012009-04-24 05:16:321721 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491722
1723 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171724 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321725}
1726
[email protected]c95fa8b2011-04-28 20:26:161727void TabContents::DidCancelLoading() {
1728 controller_.DiscardNonCommittedEntries();
1729
1730 // Update the URL display.
1731 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1732}
1733
[email protected]1a3c3cb2010-12-16 21:03:401734void TabContents::DidChangeLoadProgress(double progress) {
1735 if (delegate())
1736 delegate()->LoadProgressChanged(progress);
1737}
1738
[email protected]952a68e2011-11-17 00:36:101739void TabContents::DocumentAvailableInMainFrame(
1740 RenderViewHost* render_view_host) {
1741 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1742 DocumentAvailableInMainFrame());
1743}
1744
[email protected]25497492010-09-11 15:15:081745void TabContents::DocumentOnLoadCompletedInMainFrame(
1746 RenderViewHost* render_view_host,
1747 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071748 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271749 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531750 content::Source<TabContents>(this),
1751 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081752}
1753
[email protected]ae5184d62011-10-06 19:25:581754void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151755 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581756 WindowOpenDisposition disposition,
1757 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481758 // Delegate to RequestTransferURL because this is just the generic
1759 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581760 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481761 GlobalRequestID());
1762}
1763
1764void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581765 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481766 WindowOpenDisposition disposition,
1767 int64 source_frame_id,
1768 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581769 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581770 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581771 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351772 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321773 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1774 // generated suggestions).
1775 //
[email protected]e0112912011-02-02 22:54:351776 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161777 // want web sites to see a referrer of "chrome://blah" (and some
1778 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321779 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581780 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481781 render_manager_.web_ui()->link_transition_type(),
1782 false /* is_renderer_initiated */);
1783 params.transferred_global_request_id = old_request_id;
1784 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581785 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321786 } else {
[email protected]4ad5d77d2011-12-03 02:00:481787 OpenURLParams params(url, referrer, disposition,
1788 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1789 params.transferred_global_request_id = old_request_id;
1790 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581791 }
1792 if (new_contents) {
1793 // Notify observers.
1794 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1795 DidOpenRequestedURL(new_contents,
1796 url,
1797 referrer,
1798 disposition,
1799 transition_type,
1800 source_frame_id));
[email protected]420ae012009-04-24 05:16:321801 }
1802}
1803
[email protected]420ae012009-04-24 05:16:321804void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151805 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411806 const string16& message,
1807 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321808 const GURL& frame_url,
1809 const int flags,
1810 IPC::Message* reply_msg,
1811 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071812 // Suppress JavaScript dialogs when requested. Also suppress messages when
1813 // showing an interstitial as it's shown over the previous page and we don't
1814 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501815 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151816 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501817 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071818 !delegate_ ||
1819 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321820
1821 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341822 content::JavaScriptDialogCreator::TitleType title_type;
1823 string16 title;
1824
1825 if (!frame_url.has_host()) {
1826 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1827 } else {
1828 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1829 title = net::FormatUrl(
1830 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201831 content::GetContentClient()->browser()->GetAcceptLangs(
1832 this->browser_context()));
[email protected]b627d9a2011-06-28 14:06:341833 }
1834
[email protected]2e5b90c2011-08-16 21:11:551835 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1836 dialog_creator_->RunJavaScriptDialog(this,
1837 title_type,
1838 title,
1839 flags,
1840 message,
1841 default_prompt,
1842 reply_msg,
1843 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321844 }
[email protected]3ab9cb82011-06-03 18:02:071845
1846 if (suppress_this_message) {
1847 // If we are suppressing messages, just reply as if the user immediately
1848 // pressed "Cancel".
1849 OnDialogClosed(reply_msg, false, string16());
1850 }
1851
1852 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321853}
1854
[email protected]992db4c2011-05-12 15:37:151855void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411856 const string16& message,
[email protected]420ae012009-04-24 05:16:321857 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291858 if (delegate())
1859 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071860
1861 bool suppress_this_message =
1862 rvh->is_swapped_out() ||
1863 !delegate_ ||
1864 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151865 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411866 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501867 return;
1868 }
[email protected]3ab9cb82011-06-03 18:02:071869
[email protected]7ab1e7d62009-10-14 23:32:011870 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551871 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1872 dialog_creator_->RunBeforeUnloadDialog(this,
1873 message,
1874 reply_msg);
[email protected]420ae012009-04-24 05:16:321875}
1876
[email protected]420ae012009-04-24 05:16:321877WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081878 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361879 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]5092c282011-10-29 21:48:371880 render_view_host());
[email protected]447021c2010-09-08 21:29:081881
[email protected]b8299c12011-06-03 19:52:281882 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211883 // chrome-devtools: pages (unless it's specifically allowed).
1884 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571885 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281886 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:301887 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1888 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211889 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081890 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431891 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081892 }
1893
1894 return web_prefs;
[email protected]420ae012009-04-24 05:16:321895}
1896
[email protected]7d472472011-01-22 01:30:251897void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271898 // Notify observers.
1899 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221900
1901 ResourceDispatcherHost* rdh =
1902 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1903 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301904 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251905}
1906
[email protected]fa1cf0b82010-01-15 21:49:441907void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441908 // Notify observers.
1909 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441910}
1911
[email protected]420ae012009-04-24 05:16:321912void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1913 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151914 // Don't show hung renderer dialog for a swapped out RVH.
1915 if (rvh != render_view_host())
1916 return;
1917
[email protected]e5fc1632011-08-08 07:51:531918 // Ignore renderer unresponsive event if debugger is attached to the tab
1919 // since the event may be a result of the renderer sitting on a breakpoint.
1920 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:441921 DevToolsAgentHost* agent =
1922 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
1923 if (agent &&
1924 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:531925 return;
1926
[email protected]420ae012009-04-24 05:16:321927 if (is_during_unload) {
1928 // Hang occurred while firing the beforeunload/unload handler.
1929 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111930 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321931
1932 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1933 return;
1934
1935 // If the tab hangs in the beforeunload/unload handler there's really
1936 // nothing we can do to recover. Pretend the unload listeners have
1937 // all fired and close the tab. If the hang is in the beforeunload handler
1938 // then the user will not have the option of cancelling the close.
1939 Close(rvh);
1940 return;
1941 }
1942
[email protected]55452902011-06-01 21:57:471943 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1944 return;
1945
1946 if (delegate())
1947 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321948}
1949
1950void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471951 if (delegate())
1952 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321953}
1954
1955void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211956 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561957 uint64 upload_position,
1958 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321959 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561960 upload_position_ = upload_position;
1961 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501962 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:201963 content::GetContentClient()->browser()->GetAcceptLangs(
1964 this->browser_context()));
[email protected]9c235f042011-08-10 22:28:211965 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321966 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511967 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501968 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321969}
1970
[email protected]7d472472011-01-22 01:30:251971void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441972 if (delegate())
[email protected]55452902011-06-01 21:57:471973 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251974}
1975
[email protected]420ae012009-04-24 05:16:321976void TabContents::BeforeUnloadFiredFromRenderManager(
1977 bool proceed,
1978 bool* proceed_to_fire_unload) {
1979 if (delegate())
1980 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1981}
1982
[email protected]3a3d47472010-07-15 21:03:541983void TabContents::DidStartLoadingFromRenderManager(
1984 RenderViewHost* render_view_host) {
1985 DidStartLoading();
1986}
1987
1988void TabContents::RenderViewGoneFromRenderManager(
1989 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231990 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1991 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541992}
1993
[email protected]420ae012009-04-24 05:16:321994void TabContents::UpdateRenderViewSizeForRenderManager() {
1995 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261996 gfx::Size size = view_->GetContainerSize();
1997 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1998 // here during container initialization and normal window size will be set
1999 // later. In case of tab duplication this resizing to 0x0 prevents setting
2000 // normal size later so just ignore it.
2001 if (!size.IsEmpty())
2002 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322003}
2004
[email protected]3a3d47472010-07-15 21:03:542005void TabContents::NotifySwappedFromRenderManager() {
2006 NotifySwapped();
2007}
2008
2009NavigationController& TabContents::GetControllerForRenderManager() {
2010 return controller();
2011}
2012
[email protected]d0980792011-02-13 19:41:402013WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562014 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322015}
2016
2017NavigationEntry*
2018TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2019 return controller_.GetLastCommittedEntry();
2020}
2021
2022bool TabContents::CreateRenderViewForRenderManager(
2023 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442024 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322025 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522026
[email protected]420ae012009-04-24 05:16:322027 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442028 if (rwh_view)
2029 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322030
[email protected]a4127722011-04-27 23:13:522031 if (!render_view_host->CreateRenderView(string16()))
2032 return false;
2033
[email protected]e60c0232011-11-11 19:56:352034#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502035 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2036 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442037 if (rwh_view) {
2038 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2039 render_widget_host->WasResized();
2040 }
[email protected]f8233cc2011-05-31 20:24:502041#endif
2042
[email protected]420ae012009-04-24 05:16:322043 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2044 render_view_host);
2045 return true;
2046}
2047
[email protected]3ab9cb82011-06-03 18:02:072048void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2049 bool success,
2050 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542051 if (is_showing_before_unload_dialog_ && !success) {
2052 // If a beforeunload dialog is canceled, we need to stop the throbber from
2053 // spinning, since we forced it to start spinning in Navigate.
2054 DidStopLoading();
2055
2056 tab_close_start_time_ = base::TimeTicks();
2057 }
2058 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:412059 render_view_host()->JavaScriptDialogClosed(reply_msg,
2060 success,
[email protected]3ab9cb82011-06-03 18:02:072061 user_input);
[email protected]beb440c2009-11-06 04:08:542062}
2063
[email protected]0b08add2011-11-29 03:27:062064gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072065 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542066}
2067
[email protected]a1e97f02011-06-30 14:04:342068void TabContents::OnDialogShown() {
2069 Activate();
[email protected]3a3d47472010-07-15 21:03:542070}
2071
[email protected]41fc0322009-09-04 22:23:402072void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122073 encoding_ = content::GetContentClient()->browser()->
2074 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102075}
[email protected]f45d2a72010-03-08 23:28:352076
[email protected]33f74972010-12-08 16:40:362077void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2078 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442079 // Can be NULL during tests.
2080 if (rwh_view)
2081 rwh_view->SetSize(view()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362082}
[email protected]e9621112011-10-17 05:38:372083
2084bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
2085 return render_view_host() ?
2086 render_view_host()->GotResponseToLockMouseRequest(allowed) : false;
2087}