blob: 4324339ce563ca489757c39e17b723729abac8f1 [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]cb8fb01a2011-12-05 21:01:14163 params->referrer = entry.referrer();
[email protected]056de2d2009-06-26 16:41:34164 params->transition = entry.transition_type();
165 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00166 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37167 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34168 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47169 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48170 params->transferred_request_child_id =
171 entry.transferred_global_request_id().child_id;
172 params->transferred_request_request_id =
173 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47174
175 if (delegate)
176 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34177}
178
[email protected]420ae012009-04-24 05:16:32179} // namespace
180
[email protected]f4f50ef2011-01-21 19:01:19181
182// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32183
[email protected]3d7474ff2011-07-27 17:47:37184TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32185 SiteInstance* site_instance,
186 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07187 const TabContents* base_tab_contents,
188 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42189 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07190 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37191 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13192 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32193 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22194 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34195 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23196 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
197 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34198 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34199 max_page_id_(-1),
[email protected]9c235f042011-08-10 22:28:21200 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56201 upload_size_(0),
202 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47203 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57204 capturing_contents_(false),
205 is_being_destroyed_(false),
206 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55207 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57208#if defined(OS_WIN)
209 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
210#endif
[email protected]7ab1e7d62009-10-14 23:32:01211 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56212 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38213 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25214 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01215 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25216 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01217 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00218 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43219 content_restrictions_(0),
220 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37221 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32222
[email protected]34ac70502009-09-25 17:07:23223 // We have the initial size of the view be based on the size of the passed in
224 // tab contents (normally a tab from the same window).
225 view_->CreateView(base_tab_contents ?
226 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00227
228#if defined(ENABLE_JAVA_BRIDGE)
229 java_bridge_dispatcher_host_manager_.reset(
230 new JavaBridgeDispatcherHostManager(this));
231#endif
[email protected]332af7732009-03-11 13:21:35232}
initial.commit09911bf2008-07-26 23:55:29233
234TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32235 is_being_destroyed_ = true;
236
[email protected]3ab9cb82011-06-03 18:02:07237 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55238 if (dialog_creator_)
239 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07240
[email protected]420ae012009-04-24 05:16:32241 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32242
[email protected]420ae012009-04-24 05:16:32243 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07244 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27245 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53246 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07247 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32248
249 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07250#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32251 // If we still have a window handle, destroy it. GetNativeView can return
252 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42253 if (GetNativeView()) {
254 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44255 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42256 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42257 }
[email protected]420ae012009-04-24 05:16:32258#endif
[email protected]7ab1e7d62009-10-14 23:32:01259
260 // OnCloseStarted isn't called in unit tests.
261 if (!tab_close_start_time_.is_null()) {
262 UMA_HISTOGRAM_TIMES("Tab.Close",
263 base::TimeTicks::Now() - tab_close_start_time_);
264 }
[email protected]b5a1d11c2011-02-17 03:09:42265
[email protected]07d490bc2011-03-07 17:05:26266 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08267
[email protected]1de2b8b2011-06-29 19:38:46268 set_delegate(NULL);
269}
270
271// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
272void TabContents::set_delegate(TabContentsDelegate* delegate) {
273 if (delegate == delegate_)
274 return;
275 if (delegate_)
276 delegate_->Detach(this);
277 delegate_ = delegate;
278 if (delegate_)
279 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42280}
281
[email protected]724159a2010-12-30 01:11:18282bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17283 if (web_ui() && web_ui()->OnMessageReceived(message))
284 return true;
285
[email protected]585b30362011-01-28 02:30:17286 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
287 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10288 while ((observer = it.GetNext()) != NULL)
289 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53290 return true;
[email protected]403415a2011-01-10 18:57:53291
[email protected]724159a2010-12-30 01:11:18292 bool handled = true;
293 bool message_is_ok = true;
294 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58295 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
296 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24297 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
298 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18299 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
300 OnDidStartProvisionalLoadForFrame)
301 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
302 OnDidRedirectProvisionalLoad)
303 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
304 OnDidFailProvisionalLoadWithError)
305 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
306 OnDidLoadResourceFromMemoryCache)
307 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
308 OnDidDisplayInsecureContent)
309 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
310 OnDidRunInsecureContent)
311 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
312 OnDocumentLoadedInFrame)
313 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17314 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
315 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25316 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26317 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59318 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21319 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20320 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
321 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
322 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16323 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45324 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10325 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18326 IPC_MESSAGE_UNHANDLED(handled = false)
327 IPC_END_MESSAGE_MAP_EX()
328
329 if (!message_is_ok) {
330 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
331 GetRenderProcessHost()->ReceivedBadMessage();
332 }
333
334 return handled;
335}
336
[email protected]6c2e472f2011-08-24 23:26:18337void TabContents::RunFileChooser(
338 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23339 const content::FileChooserParams& params) {
[email protected]6c2e472f2011-08-24 23:26:18340 delegate()->RunFileChooser(this, params);
341}
342
[email protected]f3b1a082011-11-18 00:34:30343content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03344 if (render_manager_.current_host())
345 return render_manager_.current_host()->process();
346 else
347 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16348}
349
[email protected]d5f942ba2008-09-26 19:30:34350const GURL& TabContents::GetURL() const {
351 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57352 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54353 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34354}
355
[email protected]96d185d2009-04-24 03:28:54356const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55357 // Transient entries take precedence. They are used for interstitial pages
358 // that are shown on top of existing pages.
359 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08360 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20361 content::GetContentClient()->browser()->GetAcceptLangs(
362 this->browser_context());
[email protected]45d0ef7f2011-01-05 13:46:23363 if (entry) {
[email protected]b5cca982011-05-26 04:42:08364 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23365 }
[email protected]7ade2732011-02-10 00:13:58366 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
367 render_manager_.pending_web_ui() : render_manager_.web_ui();
368 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54369 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55370 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54371 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35372 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58373 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54374 if (!title.empty())
375 return title;
376 }
377 }
378
379 // We use the title for the last committed entry rather than a pending
380 // navigation entry. For example, when the user types in a URL, we want to
381 // keep the old page's title until the new load has committed and we get a new
382 // title.
[email protected]96d185d2009-04-24 03:28:54383 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23384 if (entry) {
[email protected]b5cca982011-05-26 04:42:08385 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23386 }
[email protected]987fc3a2011-05-26 14:18:09387
388 // |page_title_when_no_navigation_entry_| is finally used
389 // if no title cannot be retrieved.
390 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54391}
392
[email protected]d5f942ba2008-09-26 19:30:34393int32 TabContents::GetMaxPageID() {
394 if (GetSiteInstance())
395 return GetSiteInstance()->max_page_id();
396 else
397 return max_page_id_;
398}
399
400void TabContents::UpdateMaxPageID(int32 page_id) {
401 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34402 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34403 // testing.
404 if (GetSiteInstance())
405 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16406 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34407}
408
[email protected]96d185d2009-04-24 03:28:54409SiteInstance* TabContents::GetSiteInstance() const {
410 return render_manager_.current_host()->site_instance();
411}
412
[email protected]77362eb2011-08-01 17:18:38413SiteInstance* TabContents::GetPendingSiteInstance() const {
414 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
415 render_manager_.pending_render_view_host() :
416 render_manager_.current_host();
417 return dest_rvh->site_instance();
418}
419
[email protected]585b30362011-01-28 02:30:17420void TabContents::AddObserver(TabContentsObserver* observer) {
421 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49422}
423
[email protected]585b30362011-01-28 02:30:17424void TabContents::RemoveObserver(TabContentsObserver* observer) {
425 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49426}
427
[email protected]443b80e2010-12-14 00:42:23428void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
429 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34430 return;
431
[email protected]443b80e2010-12-14 00:42:23432 crashed_status_ = status;
433 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50434 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34435}
436
437void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
438 if (delegate_)
439 delegate_->NavigationStateChanged(this, changed_flags);
440}
441
[email protected]96d185d2009-04-24 03:28:54442void TabContents::DidBecomeSelected() {
443 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16444 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
445 if (rwhv) {
446 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43447#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16448 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43449#endif
450 }
[email protected]96d185d2009-04-24 03:28:54451
[email protected]5ac20162010-11-24 23:33:11452 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38453
454 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54455}
456
457void TabContents::WasHidden() {
458 if (!capturing_contents()) {
459 // |render_view_host()| can be NULL if the user middle clicks a link to open
460 // a tab in then background, then closes the tab before selecting it. This
461 // is because closing the tab calls TabContents::Destroy(), which removes
462 // the |render_view_host()|; then when we actually destroy the window,
463 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16464 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
465 if (rwhv)
466 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54467 }
468
[email protected]ad50def52011-10-19 23:17:07469 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27470 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53471 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07472 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54473}
474
[email protected]d5f942ba2008-09-26 19:30:34475void TabContents::Activate() {
476 if (delegate_)
477 delegate_->ActivateContents(this);
478}
479
[email protected]ea42e7782010-08-23 23:58:12480void TabContents::Deactivate() {
481 if (delegate_)
482 delegate_->DeactivateContents(this);
483}
484
[email protected]63954792011-07-11 04:17:48485void TabContents::LostCapture() {
486 if (delegate_)
487 delegate_->LostCapture();
488}
489
490bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
491 bool* is_keyboard_shortcut) {
492 return delegate_ &&
493 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
494}
495
496void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
497 if (delegate_)
498 delegate_->HandleKeyboardEvent(event);
499}
500
[email protected]32ded2212011-11-10 18:51:43501void TabContents::HandleMouseDown() {
502 if (delegate_)
503 delegate_->HandleMouseDown();
504}
505
[email protected]63954792011-07-11 04:17:48506void TabContents::HandleMouseUp() {
507 if (delegate_)
508 delegate_->HandleMouseUp();
509}
510
511void TabContents::HandleMouseActivate() {
512 if (delegate_)
513 delegate_->HandleMouseActivate();
514}
515
[email protected]8a5e0ca2011-08-25 06:30:47516void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
517 if (delegate_)
518 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
519}
520
[email protected]5d5f7af2011-10-01 01:38:12521bool TabContents::IsFullscreenForCurrentTab() const {
522 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
523}
524
[email protected]e9621112011-10-17 05:38:37525void TabContents::RequestToLockMouse() {
526 if (delegate_) {
527 delegate_->RequestToLockMouse(this);
528 } else {
529 GotResponseToLockMouseRequest(false);
530 }
531}
532
533void TabContents::LostMouseLock() {
534 if (delegate_)
535 delegate_->LostMouseLock();
536}
537
[email protected]0548c5352011-09-07 00:33:33538void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
539 if (delegate_)
540 delegate_->UpdatePreferredSize(this, pref_size);
541}
542
[email protected]32ded2212011-11-10 18:51:43543void TabContents::WebUISend(RenderViewHost* render_view_host,
544 const GURL& source_url,
545 const std::string& name,
546 const base::ListValue& args) {
547 if (delegate_)
548 delegate_->WebUISend(this, source_url, name, args);
549}
550
[email protected]96d185d2009-04-24 03:28:54551void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16552 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
553 if (rwhv)
554 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54555}
556
557void TabContents::HideContents() {
558 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
559 // our superclass HideContents(), because some callers want to be very picky
560 // about the order in which these get called. In addition to making the code
561 // here practically impossible to understand, this also means we end up
562 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34563 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54564 WasHidden();
565}
566
[email protected]5aab5e22010-12-08 22:13:29567bool TabContents::NeedToFireBeforeUnload() {
568 // TODO(creis): Should we fire even for interstitial pages?
569 return notify_disconnection() &&
570 !showing_interstitial_page() &&
571 !render_view_host()->SuddenTerminationAllowed();
572}
573
[email protected]00c37fc2011-08-02 00:22:50574// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25575TabContents* TabContents::OpenURL(const GURL& url,
576 const GURL& referrer,
577 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58578 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10579 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
580 DCHECK(referrer.is_empty());
[email protected]bce1f1c2011-12-05 15:11:58581 return OpenURL(OpenURLParams(url, content::Referrer(), disposition,
582 transition, false));
[email protected]00c37fc2011-08-02 00:22:50583}
584
585TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49586 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50587 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49588 // Notify observers.
589 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50590 DidOpenURL(params.url, params.referrer,
591 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25592 return new_contents;
[email protected]1c642b52011-04-15 09:05:49593 }
[email protected]992e4542011-07-20 23:09:25594 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34595}
596
[email protected]1ccb3568d2010-02-19 10:51:16597bool TabContents::NavigateToPendingEntry(
598 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27599 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54600}
[email protected]96d185d2009-04-24 03:28:54601
[email protected]876bc832010-09-07 16:29:54602bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27603 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54604 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40605 // The renderer will reject IPC messages with URLs longer than
606 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27607 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40608 return false;
609
[email protected]dd11de52011-11-03 22:54:27610 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40611 if (!dest_render_view_host)
612 return false; // Unable to create the desired render view host.
613
[email protected]80a8fad2011-01-29 04:02:38614 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07615 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58616 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56617 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37618 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]dd11de52011-11-03 22:54:27619 entry.url());
[email protected]32ded2212011-11-10 18:51:43620#if defined(OS_CHROMEOS)
621 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
622#endif
[email protected]e091df82011-10-11 18:13:21623 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55624 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58625
[email protected]96d185d2009-04-24 03:28:54626 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44627 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
628 render_view_host(),
629 dest_render_view_host,
630 entry.url());
[email protected]96d185d2009-04-24 03:28:54631
632 // Used for page load time metrics.
633 current_load_start_ = base::TimeTicks::Now();
634
635 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34636 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27637 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47638 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34639 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54640
[email protected]dd11de52011-11-03 22:54:27641 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54642 // HACK!! This code suppresses javascript: URLs from being added to
643 // session history, which is what we want to do for javascript: URLs that
644 // do not generate content. What we really need is a message from the
645 // renderer telling us that a new page was not created. The same message
646 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27647 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54648 return false;
649 }
650
[email protected]3c9e1872010-11-18 16:17:49651 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04652 FOR_EACH_OBSERVER(TabContentsObserver,
653 observers_,
[email protected]dd11de52011-11-03 22:54:27654 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54655
[email protected]09b29342011-06-24 19:18:48656 if (delegate_)
657 delegate_->DidNavigateToPendingEntry(this);
658
[email protected]d5f942ba2008-09-26 19:30:34659 return true;
660}
661
[email protected]9e1ad4b2011-08-14 16:49:19662void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
663 int history_length,
664 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41665 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
666 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19667 if (render_manager_.pending_render_view_host()) {
668 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14669 return;
[email protected]9e1ad4b2011-08-14 16:49:19670 }
671 RenderViewHost* rvh = render_view_host();
672 if (!rvh) {
673 NOTREACHED();
674 return;
675 }
676 if (site_instance && rvh->site_instance() != site_instance) {
677 NOTREACHED();
678 return;
679 }
680 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
681 history_length,
682 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14683}
684
[email protected]96d185d2009-04-24 03:28:54685void TabContents::Stop() {
686 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47687 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54688}
689
[email protected]96d185d2009-04-24 03:28:54690TabContents* TabContents::Clone() {
691 // We create a new SiteInstance so that the new tab won't share processes
692 // with the old one. This can be changed in the future if we need it to share
693 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37694 TabContents* tc = new TabContents(
695 browser_context(),
696 SiteInstance::CreateSiteInstance(browser_context()),
697 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54698 tc->controller().CopyStateFrom(controller_);
699 return tc;
700}
701
[email protected]4d677202009-07-19 07:37:12702void TabContents::ShowPageInfo(const GURL& url,
703 const NavigationEntry::SSLStatus& ssl,
704 bool show_history) {
705 if (!delegate_)
706 return;
707
[email protected]3d7474ff2011-07-27 17:47:37708 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12709}
710
[email protected]e7cfdbd2011-04-22 14:41:37711void TabContents::AddNewContents(TabContents* new_contents,
712 WindowOpenDisposition disposition,
713 const gfx::Rect& initial_pos,
714 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29715 if (!delegate_)
716 return;
717
[email protected]e7cfdbd2011-04-22 14:41:37718 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
719 user_gesture);
[email protected]96d185d2009-04-24 03:28:54720}
721
[email protected]5c9e97a2009-09-09 23:48:30722gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54723 return view_->GetContentNativeView();
724}
725
726gfx::NativeView TabContents::GetNativeView() const {
727 return view_->GetNativeView();
728}
729
730void TabContents::GetContainerBounds(gfx::Rect *out) const {
731 view_->GetContainerBounds(out);
732}
733
734void TabContents::Focus() {
735 view_->Focus();
736}
737
[email protected]90daadb42009-06-08 21:27:28738void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54739 if (showing_interstitial_page()) {
740 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
741 return;
742 }
[email protected]96d185d2009-04-24 03:28:54743 render_view_host()->SetInitialFocus(reverse);
744}
745
746bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40747 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58748 if (web_ui)
749 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43750 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25751 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43752 return true;
[email protected]96d185d2009-04-24 03:28:54753 return false;
754}
755
[email protected]a26dc362010-04-23 01:48:58756void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38757 if (delegate())
[email protected]a26dc362010-04-23 01:48:58758 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38759}
760
[email protected]686493142011-07-15 21:47:22761bool TabContents::CanDownload(int request_id) {
762 TabContentsDelegate* d = delegate();
763 if (d)
764 return d->CanDownload(this, request_id);
765 return true;
766}
767
768void TabContents::OnStartDownload(DownloadItem* download) {
769 TabContentsDelegate* d = delegate();
770 if (d)
771 d->OnStartDownload(this, download);
772}
773
[email protected]c7dd2f62011-07-18 15:57:59774void TabContents::OnSavePage() {
775 // If we can not save the page, try to download it.
776 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37777 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59778 const GURL& current_page_url = GetURL();
779 if (dlm && current_page_url.is_valid()) {
780 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46781 download_stats::RecordDownloadCount(
782 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59783 return;
784 }
785 }
786
787 Stop();
788
789 // Create the save package and possibly prompt the user for the name to save
790 // the page as. The user prompt is an asynchronous operation that runs on
791 // another thread.
792 save_package_ = new SavePackage(this);
793 save_package_->GetSaveInfo();
794}
795
796// Used in automated testing to bypass prompting the user for file names.
797// Instead, the names and paths are hard coded rather than running them through
798// file name sanitation and extension / mime checking.
799bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
800 SavePackage::SavePackageType save_type) {
801 // Stop the page from navigating.
802 Stop();
803
804 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
805 return save_package_->Init();
806}
807
808void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37809 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59810 dlm->DownloadUrl(url, GetURL(), "", this);
811}
812
[email protected]420ae012009-04-24 05:16:32813bool TabContents::IsActiveEntry(int32 page_id) {
814 NavigationEntry* active_entry = controller_.GetActiveEntry();
815 return (active_entry != NULL &&
816 active_entry->site_instance() == GetSiteInstance() &&
817 active_entry->page_id() == page_id);
818}
819
[email protected]b2fe07d12010-02-09 14:38:08820void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16821 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26822 render_view_host()->Send(new ViewMsg_SetPageEncoding(
823 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16824}
825
[email protected]b2fe07d12010-02-09 14:38:08826void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16827 reset_encoding();
[email protected]216813952011-05-19 22:21:26828 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
829 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16830}
831
[email protected]7ab1e7d62009-10-14 23:32:01832void TabContents::OnCloseStarted() {
833 if (tab_close_start_time_.is_null())
834 tab_close_start_time_ = base::TimeTicks::Now();
835}
836
[email protected]46624bf2010-06-09 16:04:19837bool TabContents::ShouldAcceptDragAndDrop() const {
838#if defined(OS_CHROMEOS)
839 // ChromeOS panels (pop-ups) do not take drag-n-drop.
840 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14841 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20842 return false;
843 return true;
[email protected]46624bf2010-06-09 16:04:19844#else
845 return true;
846#endif
847}
848
[email protected]7813bd72011-02-05 02:19:34849void TabContents::SystemDragEnded() {
850 if (render_view_host())
851 render_view_host()->DragSourceSystemDragEnded();
852 if (delegate())
853 delegate()->DragEnded();
854}
855
[email protected]d0b8d092010-10-25 04:05:17856double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37857 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25858 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17859 return 0;
[email protected]b75b8292010-10-01 07:28:25860
861 double zoom_level;
862 if (temporary_zoom_settings_) {
863 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]f3b1a082011-11-18 00:34:30864 GetRenderProcessHost()->GetID(), render_view_host()->routing_id());
[email protected]b75b8292010-10-01 07:28:25865 } else {
[email protected]2ae88d12011-10-14 09:11:19866 GURL url;
867 NavigationEntry* active_entry = controller().GetActiveEntry();
868 // Since zoom map is updated using rewritten URL, use rewritten URL
869 // to get the zoom level.
870 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
871 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25872 }
[email protected]d0b8d092010-10-25 04:05:17873 return zoom_level;
874}
[email protected]b75b8292010-10-01 07:28:25875
[email protected]d0b8d092010-10-25 04:05:17876int TabContents::GetZoomPercent(bool* enable_increment,
877 bool* enable_decrement) {
878 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01879 // Calculate the zoom percent from the factor. Round up to the nearest whole
880 // number.
[email protected]b75b8292010-10-01 07:28:25881 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:01882 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:25883 *enable_decrement = percent > minimum_zoom_percent_;
884 *enable_increment = percent < maximum_zoom_percent_;
885 return percent;
886}
887
[email protected]3c733bde2010-12-21 19:56:31888void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50889 if (!delegate_)
890 return;
891
892 NavigationEntry* active_entry = controller().GetActiveEntry();
893 if (!active_entry)
894 return;
895
896 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12897}
898
[email protected]932b7a12011-03-09 12:50:27899void TabContents::ViewFrameSource(const GURL& url,
900 const std::string& content_state) {
901 if (!delegate_)
902 return;
903
904 delegate_->ViewSourceForFrame(this, url, content_state);
905}
906
[email protected]c40d6232011-03-25 00:16:21907void TabContents::SetContentRestrictions(int restrictions) {
908 content_restrictions_ = restrictions;
909 delegate()->ContentRestrictionsChanged(this);
910}
911
[email protected]8b5af492011-11-28 21:50:58912void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30913 const string16& type,
914 const string16& href,
915 const string16& title,
916 const string16& disposition) {
917 delegate()->RegisterIntentHandler(
918 this, action, type, href, title, disposition);
919}
920
[email protected]678105012011-12-09 04:01:21921void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:30922 int intent_id) {
[email protected]ada02b312011-12-01 21:54:53923 IntentsHostImpl* intents_host = new IntentsHostImpl(this, intent, intent_id);
924 delegate()->WebIntentDispatch(this, intents_host);
[email protected]63c239322011-10-31 23:56:30925}
926
[email protected]724159a2010-12-30 01:11:18927void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
928 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59929 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18930 const GURL& url) {
931 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
932 GURL validated_url(url);
933 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30934 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18935
[email protected]8093a542011-05-13 07:29:32936 RenderViewHost* rvh =
937 render_manager_.pending_render_view_host() ?
938 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10939 // Notify observers about the start of the provisional load.
940 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
941 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32942 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10943
[email protected]724159a2010-12-30 01:11:18944 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59945 // Notify observers about the provisional change in the main frame URL.
946 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59947 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18948 }
949}
950
951void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59952 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18953 const GURL& source_url,
954 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49955 // TODO(creis): Remove this method and have the pre-rendering code listen to
956 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
957 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18958 NavigationEntry* entry;
959 if (page_id == -1)
960 entry = controller_.pending_entry();
961 else
962 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
963 if (!entry || entry->url() != source_url)
964 return;
[email protected]e7d50892011-01-19 21:47:38965
[email protected]4850a7f2011-03-08 23:36:59966 // Notify observers about the provisional change in the main frame URL.
967 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26968 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59969 opener_url));
[email protected]724159a2010-12-30 01:11:18970}
971
972void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58973 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
974 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
975 << ", error_code: " << params.error_code
976 << ", error_description: " << params.error_description
977 << ", is_main_frame: " << params.is_main_frame
978 << ", showing_repost_interstitial: " <<
979 params.showing_repost_interstitial
980 << ", frame_id: " << params.frame_id;
981 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18982 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30983 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18984
[email protected]d7b175e2011-10-11 15:31:58985 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18986 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
987 // This means that the interstitial won't be torn down properly, which is
988 // bad. But if we have an interstitial, go back to another tab type, and
989 // then load the same interstitial again, we could end up getting the first
990 // interstitial's "failed" message (as a result of the cancel) when we're on
991 // the second one.
992 //
993 // We can't tell this apart, so we think we're tearing down the current page
994 // which will cause a crash later one. There is also some code in
995 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
996 // out because of this problem.
997 //
998 // http://code.google.com/p/chromium/issues/detail?id=2855
999 // Because this will not tear down the interstitial properly, if "back" is
1000 // back to another tab type, the interstitial will still be somewhat alive
1001 // in the previous tab type. If you navigate somewhere that activates the
1002 // tab with the interstitial again, you'll see a flash before the new load
1003 // commits of the interstitial page.
1004 if (showing_interstitial_page()) {
1005 LOG(WARNING) << "Discarding message during interstitial.";
1006 return;
1007 }
1008
[email protected]02102f82011-06-13 20:37:021009 // Discard our pending entry if the load canceled (e.g. if we decided to
1010 // download the file instead of load it). We do not verify that the URL
1011 // being canceled matches the pending entry's URL because they will not
1012 // match if a redirect occurred (in which case we do not want to leave a
1013 // stale redirect URL showing). This means that we also cancel the pending
1014 // entry if the user started a new navigation. As a result, the navigation
1015 // controller may not remember that a load is in progress, but the
1016 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181017 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021018 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161019 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181020
1021 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1022 }
1023
1024 // Send out a notification that we failed a provisional load with an error.
1025 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581026 params.is_main_frame,
1027 controller_.IsURLInPageNavigation(validated_url),
1028 validated_url,
1029 std::string(),
1030 false,
1031 params.frame_id);
1032 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181033
[email protected]ad50def52011-10-19 23:17:071034 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271035 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531036 content::Source<NavigationController>(&controller_),
1037 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101038
[email protected]d7b175e2011-10-11 15:31:581039 FOR_EACH_OBSERVER(TabContentsObserver,
1040 observers_,
1041 DidFailProvisionalLoad(params.frame_id,
1042 params.is_main_frame,
1043 validated_url,
1044 params.error_code,
1045 params.error_description));
[email protected]724159a2010-12-30 01:11:181046}
1047
1048void TabContents::OnDidLoadResourceFromMemoryCache(
1049 const GURL& url,
[email protected]70435962011-08-02 20:13:281050 const std::string& security_info,
1051 const std::string& http_method,
1052 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191053 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181054 cache.Increment();
1055
1056 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081057 int cert_id = 0;
1058 net::CertStatus cert_status = 0;
1059 int security_bits = -1;
1060 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181061 SSLManager::DeserializeSecurityInfo(security_info,
1062 &cert_id, &cert_status,
1063 &security_bits,
1064 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301065 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161066 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181067
[email protected]ad50def52011-10-19 23:17:071068 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271069 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531070 content::Source<NavigationController>(&controller_),
1071 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181072}
1073
1074void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161075 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181076 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071077 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181078}
1079
1080void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021081 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231082 LOG(INFO) << security_origin << " ran insecure content from "
1083 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161084 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051085 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
1086 UserMetrics::RecordAction(
1087 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1088 }
[email protected]724159a2010-12-30 01:11:181089 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411090 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071091 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181092}
1093
1094void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1095 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101096 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1097 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181098}
1099
[email protected]1a55c5be2011-11-29 11:36:311100void TabContents::OnDidFinishLoad(
1101 int64 frame_id,
1102 const GURL& validated_url,
1103 bool is_main_frame) {
[email protected]0d60f0192011-04-14 12:40:101104 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311105 DidFinishLoad(frame_id, validated_url, is_main_frame));
1106}
1107
1108void TabContents::OnDidFailLoadWithError(int64 frame_id,
1109 const GURL& validated_url,
1110 bool is_main_frame,
1111 int error_code,
1112 const string16& error_description) {
1113 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1114 DidFailLoad(frame_id, validated_url, is_main_frame,
1115 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181116}
1117
[email protected]c8f73ab2011-01-22 00:05:171118void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211119 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171120}
1121
[email protected]216813952011-05-19 22:21:261122void TabContents::OnGoToEntryAtOffset(int offset) {
1123 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1124 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1125 if (!entry)
1126 return;
1127 // Note that we don't call NavigationController::GotToOffset() as we don't
1128 // want to create a pending navigation entry (it might end up lingering
1129 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581130 entry->set_transition_type(
1131 content::PageTransitionFromInt(
1132 entry->transition_type() |
1133 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271134 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571135
1136 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1137 // it in now that we know. This allows us to find the entry when it commits.
1138 if (!entry->site_instance() &&
1139 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381140 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571141 }
[email protected]216813952011-05-19 22:21:261142 }
1143}
1144
1145void TabContents::OnUpdateZoomLimits(int minimum_percent,
1146 int maximum_percent,
1147 bool remember) {
1148 minimum_zoom_percent_ = minimum_percent;
1149 maximum_zoom_percent_ = maximum_percent;
1150 temporary_zoom_settings_ = !remember;
1151}
1152
[email protected]3a29a6e2011-08-24 18:26:211153void TabContents::OnEnumerateDirectory(int request_id,
1154 const FilePath& path) {
1155 delegate()->EnumerateDirectory(this, request_id, path);
1156}
1157
[email protected]7d189022011-08-25 22:54:201158void TabContents::OnJSOutOfMemory() {
1159 delegate()->JSOutOfMemory(this);
1160}
1161
1162void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1163 const GURL& url,
1164 const string16& title) {
1165 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1166}
1167
[email protected]b888919c2011-09-02 00:32:161168void TabContents::OnFindReply(int request_id,
1169 int number_of_matches,
1170 const gfx::Rect& selection_rect,
1171 int active_match_ordinal,
1172 bool final_update) {
1173 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1174 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001175 // Send a notification to the renderer that we are ready to receive more
1176 // results from the scoping effort of the Find operation. The FindInPage
1177 // scoping is asynchronous and periodically sends results back up to the
1178 // browser using IPC. In an effort to not spam the browser we have the
1179 // browser send an ACK for each FindReply message and have the renderer
1180 // queue up the latest status message while waiting for this ACK.
1181 render_view_host()->Send(
1182 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161183}
1184
[email protected]d952a052011-09-06 18:42:451185void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1186 delegate()->CrashedPlugin(this, plugin_path);
1187}
1188
[email protected]7fc4bbb2011-09-08 21:23:101189void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1190 bool blocked_by_policy) {
1191 // Notify observers about navigation.
1192 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1193 AppCacheAccessed(manifest_url, blocked_by_policy));
1194}
1195
[email protected]96d185d2009-04-24 03:28:541196// Notifies the RenderWidgetHost instance about the fact that the page is
1197// loading, or done loading and calls the base implementation.
1198void TabContents::SetIsLoading(bool is_loading,
1199 LoadNotificationDetails* details) {
1200 if (is_loading == is_loading_)
1201 return;
1202
1203 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211204 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541205 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561206 upload_size_ = 0;
1207 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541208 }
1209
1210 render_manager_.SetIsLoading(is_loading);
1211
1212 is_loading_ = is_loading;
1213 waiting_for_response_ = is_loading;
1214
[email protected]6ebdc9b2010-09-27 16:55:571215 if (delegate_)
1216 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351217 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541218
[email protected]432115822011-07-10 15:52:271219 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1220 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071221 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541222 if (details)
[email protected]6c2381d2011-10-19 02:52:531223 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071224 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531225 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541226 det);
1227}
1228
[email protected]d0980792011-02-13 19:41:401229WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581230 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541231 // that goes along with it to control the basic flags. For example, we want to
1232 // show the pending URL in the URL bar, so we want the display_url flag to
1233 // be from the pending entry.
1234 //
1235 // The confusion comes because there are multiple possibilities for the
1236 // initial load in a tab as a side effect of the way the RenderViewHostManager
1237 // works.
1238 //
[email protected]e0112912011-02-02 22:54:351239 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541240 // the pending one, and we want it to apply here.
1241 //
1242 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1243 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581244 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351245 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541246 //
1247 // This condition handles all of these cases:
1248 //
1249 // - First load in first tab: no committed nav entry + pending nav entry +
1250 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351251 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541252 //
1253 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351254 // no pending Web UI:
1255 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541256 //
1257 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351258 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541259 //
1260 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351261 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541262 if (controller_.pending_entry() &&
1263 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581264 render_manager_.pending_web_ui()))
1265 return render_manager_.pending_web_ui();
1266 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541267}
[email protected]420ae012009-04-24 05:16:321268
[email protected]1fd1a502011-03-30 16:55:561269WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371270 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1271 GetURL());
[email protected]1fd1a502011-03-30 16:55:561272}
1273
[email protected]420ae012009-04-24 05:16:321274void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131275 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321276 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561277 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381278 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441279 // that opened the window, as long as both renderers have the same
1280 // privileges.
[email protected]1fd1a502011-03-30 16:55:561281 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1282 WebUI* web_ui = content::GetContentClient()->browser()->
1283 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581284 // web_ui might be NULL if the URL refers to a non-existent extension.
1285 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401286 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581287 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441288 }
1289 }
[email protected]1fd1a502011-03-30 16:55:561290 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441291 }
1292
[email protected]4e697b042011-07-08 06:44:561293 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321294 // Clear the status bubble. This is a workaround for a bug where WebKit
1295 // doesn't let us know that the cursor left an element during a
1296 // transition (this is also why the mouse cursor remains as a hand after
1297 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1298 // clear the bubble when a user navigates to a named anchor in the same
1299 // page.
1300 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321301 }
1302
[email protected]a6e82fc2010-02-24 22:28:141303 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471304 // Once the main frame is navigated, we're no longer considered to have
1305 // displayed insecure content.
1306 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171307 }
[email protected]ce5c4502009-05-06 16:46:111308
[email protected]3c9e1872010-11-18 16:17:491309 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171310 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041311 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321312}
1313
1314void TabContents::DidNavigateAnyFramePostCommit(
1315 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131316 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321317 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071318 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321319 // a malicious script from spamming messages, since the script could just
1320 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551321 if (dialog_creator_) {
1322 dialog_creator_->ResetJavaScriptState(this);
1323 dialog_creator_ = NULL;
1324 }
[email protected]420ae012009-04-24 05:16:321325
[email protected]3c9e1872010-11-18 16:17:491326 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171327 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041328 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321329}
1330
[email protected]420ae012009-04-24 05:16:321331void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1332 RenderViewHost* rvh) {
1333 // If we are creating a RVH for a restored controller, then we might
1334 // have more page IDs than the SiteInstance's current max page ID. We must
1335 // make sure that the max page ID is larger than any restored page ID.
1336 // Note that it is ok for conflicting page IDs to exist in another tab
1337 // (i.e., NavigationController), but if any page ID is larger than the max,
1338 // the back/forward list will get confused.
1339 int max_restored_page_id = controller_.max_restored_page_id();
1340 if (max_restored_page_id > 0) {
1341 int curr_max_page_id = site_instance->max_page_id();
1342 if (max_restored_page_id > curr_max_page_id) {
1343 // Need to update the site instance immediately.
1344 site_instance->UpdateMaxPageID(max_restored_page_id);
1345
1346 // Also tell the renderer to update its internal representation. We
1347 // need to reserve enough IDs to make all restored page IDs less than
1348 // the max.
1349 if (curr_max_page_id < 0)
1350 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261351 rvh->Send(new ViewMsg_ReservePageIDRange(
1352 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321353 }
1354 }
1355}
1356
[email protected]6b2f7a82011-04-25 19:30:511357bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571358 const string16& title) {
[email protected]420ae012009-04-24 05:16:321359 // For file URLs without a title, use the pathname instead. In the case of a
1360 // synthesized title, we don't want the update to count toward the "one set
1361 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511362 string16 final_title;
[email protected]420ae012009-04-24 05:16:321363 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091364 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511365 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321366 explicit_set = false; // Don't count synthetic titles toward the set limit.
1367 } else {
[email protected]acafd272011-07-26 17:35:571368 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321369 explicit_set = true;
1370 }
1371
[email protected]987fc3a2011-05-26 14:18:091372 // If a page is created via window.open and never navigated,
1373 // there will be no navigation entry. In this situation,
1374 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1375 if (entry) {
1376 if (final_title == entry->title())
1377 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321378
[email protected]987fc3a2011-05-26 14:18:091379 entry->set_title(final_title);
1380 } else {
1381 if (page_title_when_no_navigation_entry_ == final_title)
1382 return false; // Nothing changed, don't bother.
1383
1384 page_title_when_no_navigation_entry_ = final_title;
1385 }
[email protected]420ae012009-04-24 05:16:321386
[email protected]420ae012009-04-24 05:16:321387 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231388 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321389
[email protected]105bb0f2011-05-24 17:12:141390 TitleUpdatedDetails details(entry, explicit_set);
1391
[email protected]ad50def52011-10-19 23:17:071392 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271393 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531394 content::Source<TabContents>(this),
1395 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041396
[email protected]420ae012009-04-24 05:16:321397 return true;
1398}
1399
1400void TabContents::NotifySwapped() {
1401 // After sending out a swap notification, we need to send a disconnect
1402 // notification so that clients that pick up a pointer to |this| can NULL the
1403 // pointer. See Bug 1230284.
1404 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071405 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271406 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531407 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071408 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321409}
1410
1411void TabContents::NotifyConnected() {
1412 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071413 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271414 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531415 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071416 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321417}
1418
1419void TabContents::NotifyDisconnected() {
1420 if (!notify_disconnection_)
1421 return;
1422
1423 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071424 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271425 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531426 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071427 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321428}
1429
[email protected]8d3347f2009-07-09 22:00:211430RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321431 return view_.get();
1432}
1433
[email protected]8d3347f2009-07-09 22:00:211434RenderViewHostDelegate::RendererManagement*
1435TabContents::GetRendererManagementDelegate() {
1436 return &render_manager_;
1437}
1438
[email protected]daf82f82011-10-31 22:35:311439content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371440 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461441 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511442}
1443
[email protected]57c6a652009-05-04 07:58:341444TabContents* TabContents::GetAsTabContents() {
1445 return this;
1446}
1447
[email protected]da4dfc42011-10-12 15:53:561448content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431449 return view_type_;
[email protected]7b291f92009-08-14 05:43:531450}
1451
[email protected]420ae012009-04-24 05:16:321452void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071453 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271454 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531455 content::Source<TabContents>(this),
1456 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321457 NavigationEntry* entry = controller_.GetActiveEntry();
1458 if (!entry)
1459 return;
1460
1461 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351462 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561463 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581464 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321465
1466 if (entry->IsViewSourceMode()) {
1467 // Put the renderer in view source mode.
1468 render_view_host->Send(
1469 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1470 }
[email protected]0666aef2009-05-13 19:48:081471
1472 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261473
1474 FOR_EACH_OBSERVER(
1475 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321476}
1477
1478void TabContents::RenderViewReady(RenderViewHost* rvh) {
1479 if (rvh != render_view_host()) {
1480 // Don't notify the world, since this came from a renderer in the
1481 // background.
1482 return;
1483 }
1484
1485 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301486 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231487 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301488
1489 // Restore the focus to the tab (otherwise the focus will be on the top
1490 // window).
[email protected]484ae5912010-09-29 19:16:141491 if (was_crashed && !FocusLocationBarByDefault() &&
1492 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301493 Focus();
[email protected]484ae5912010-09-29 19:16:141494 }
[email protected]32ded2212011-11-10 18:51:431495
1496 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321497}
1498
[email protected]443b80e2010-12-14 00:42:231499void TabContents::RenderViewGone(RenderViewHost* rvh,
1500 base::TerminationStatus status,
1501 int error_code) {
[email protected]420ae012009-04-24 05:16:321502 if (rvh != render_view_host()) {
1503 // The pending page's RenderViewHost is gone.
1504 return;
1505 }
1506
1507 SetIsLoading(false, NULL);
1508 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231509 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541510 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321511
[email protected]9cddb1a22011-11-15 15:04:271512 FOR_EACH_OBSERVER(TabContentsObserver,
1513 observers_,
1514 RenderViewGone(crashed_status()));
[email protected]420ae012009-04-24 05:16:321515}
1516
[email protected]2e4633c2009-07-09 16:58:061517void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481518 render_manager_.RenderViewDeleted(rvh);
[email protected]483623eb2011-10-25 09:30:001519 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061520}
1521
[email protected]420ae012009-04-24 05:16:321522void TabContents::DidNavigate(RenderViewHost* rvh,
1523 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581524 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321525 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371526
[email protected]420ae012009-04-24 05:16:321527 // Update the site of the SiteInstance if it doesn't have one yet.
1528 if (!GetSiteInstance()->has_site())
1529 GetSiteInstance()->SetSite(params.url);
1530
1531 // Need to update MIME type here because it's referred to in
1532 // UpdateNavigationCommands() called by RendererDidNavigate() to
1533 // determine whether or not to enable the encoding menu.
1534 // It's updated only for the main frame. For a subframe,
1535 // RenderView::UpdateURL does not set params.contents_mime_type.
1536 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1537 // TODO(jungshik): Add a test for the encoding menu to avoid
1538 // regressing it again.
[email protected]2905f742011-10-13 03:51:581539 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321540 contents_mime_type_ = params.contents_mime_type;
1541
[email protected]8286f51a2011-05-31 17:39:131542 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001543 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391544
[email protected]a9c0bfe2010-09-17 08:35:221545 // Send notification about committed provisional loads. This notification is
1546 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1547 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081548 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071549 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1550 // that is not recorded in the navigation history. For the purpose of
1551 // tracking navigation events, we treat this event as a sub frame navigation
1552 // event.
1553 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581554 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221555 // Whether or not a page transition was triggered by going backward or
1556 // forward in the history is only stored in the navigation controller's
1557 // entry list.
1558 if (did_navigate &&
1559 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581560 content::PAGE_TRANSITION_FORWARD_BACK)) {
1561 transition_type = content::PageTransitionFromInt(
1562 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221563 }
[email protected]0d60f0192011-04-14 12:40:101564 // Notify observers about the commit of the provisional load.
1565 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1566 DidCommitProvisionalLoadForFrame(params.frame_id,
1567 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221568 }
1569
[email protected]76543b92009-08-31 17:27:451570 if (!did_navigate)
1571 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321572
1573 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1574 // for the appropriate notification (best) or you can add it to
1575 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1576 // necessary, please).
1577
1578 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001579 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321580 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481581 if (delegate())
1582 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001583 }
[email protected]420ae012009-04-24 05:16:321584 DidNavigateAnyFramePostCommit(rvh, details, params);
1585}
1586
1587void TabContents::UpdateState(RenderViewHost* rvh,
1588 int32 page_id,
1589 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151590 // Ensure that this state update comes from either the active RVH or one of
1591 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1592 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321593
1594 // We must be prepared to handle state updates for any page, these occur
1595 // when the user is scrolling and entering form data, as well as when we're
1596 // leaving a page, in which case our state may have already been moved to
1597 // the next page. The navigation controller will look up the appropriate
1598 // NavigationEntry and update it when it is notified via the delegate.
1599
1600 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151601 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321602 if (entry_index < 0)
1603 return;
1604 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1605
1606 if (state == entry->content_state())
1607 return; // Nothing to update.
1608 entry->set_content_state(state);
1609 controller_.NotifyEntryChanged(entry, entry_index);
1610}
1611
1612void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571613 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461614 const string16& title,
1615 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321616 // If we have a title, that's a pretty good indication that we've started
1617 // getting useful data.
1618 SetNotWaitingForResponse();
1619
1620 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481621 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581622 page_id);
[email protected]987fc3a2011-05-26 14:18:091623
[email protected]a49e10b2011-08-01 23:57:461624 // TODO(evan): make use of title_direction.
1625 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091626 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321627 return;
1628
1629 // Broadcast notifications when the UI should be updated.
1630 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031631 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321632}
1633
[email protected]420ae012009-04-24 05:16:321634void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401635 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321636 set_encoding(encoding);
1637}
1638
1639void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1640 if (delegate())
[email protected]d952a052011-09-06 18:42:451641 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321642}
1643
[email protected]420ae012009-04-24 05:16:321644void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291645 // The UI may be in an event-tracking loop, such as between the
1646 // mouse-down and mouse-up in text selection or a button click.
1647 // Defer the close until after tracking is complete, so that we
1648 // don't free objects out from under the UI.
1649 // TODO(shess): This could probably be integrated with the
1650 // IsDoingDrag() test below. Punting for now because I need more
1651 // research to understand how this impacts platforms other than Mac.
1652 // TODO(shess): This could get more fine-grained. For instance,
1653 // closing a tab in another window while selecting text in the
1654 // current window's Omnibox should be just fine.
1655 if (view()->IsEventTracking()) {
1656 view()->CloseTabAfterEventTracking();
1657 return;
1658 }
1659
[email protected]24a4d1062009-07-10 23:10:421660 // If we close the tab while we're in the middle of a drag, we'll crash.
1661 // Instead, cancel the drag and close it as soon as the drag ends.
1662 if (view()->IsDoingDrag()) {
1663 view()->CancelDragAndCloseTab();
1664 return;
1665 }
1666
[email protected]420ae012009-04-24 05:16:321667 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1668 if (delegate() && rvh == render_view_host())
1669 delegate()->CloseContents(this);
1670}
1671
[email protected]cd9ed79d2011-11-15 19:22:571672void TabContents::SwappedOut(RenderViewHost* rvh) {
1673 if (delegate() && rvh == render_view_host())
1674 delegate()->SwappedOut(this);
1675}
1676
[email protected]420ae012009-04-24 05:16:321677void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141678 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321679 delegate()->MoveContents(this, new_bounds);
1680}
1681
[email protected]7ab1e7d62009-10-14 23:32:011682void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321683 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491684
[email protected]c40d6232011-03-25 00:16:211685 if (delegate() && content_restrictions_) {
1686 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211687 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001688 }
[email protected]3c9e1872010-11-18 16:17:491689
1690 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171691 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321692}
1693
[email protected]7ab1e7d62009-10-14 23:32:011694void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321695 scoped_ptr<LoadNotificationDetails> details;
1696
1697 NavigationEntry* entry = controller_.GetActiveEntry();
1698 // An entry may not exist for a stop when loading an initial blank page or
1699 // if an iframe injected by script into a blank page finishes loading.
1700 if (entry) {
[email protected]420ae012009-04-24 05:16:321701 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1702
1703 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541704 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321705 entry->transition_type(),
1706 elapsed,
1707 &controller_,
1708 controller_.GetCurrentEntryIndex()));
1709 }
1710
[email protected]420ae012009-04-24 05:16:321711 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491712
1713 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171714 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321715}
1716
[email protected]c95fa8b2011-04-28 20:26:161717void TabContents::DidCancelLoading() {
1718 controller_.DiscardNonCommittedEntries();
1719
1720 // Update the URL display.
1721 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1722}
1723
[email protected]1a3c3cb2010-12-16 21:03:401724void TabContents::DidChangeLoadProgress(double progress) {
1725 if (delegate())
1726 delegate()->LoadProgressChanged(progress);
1727}
1728
[email protected]952a68e2011-11-17 00:36:101729void TabContents::DocumentAvailableInMainFrame(
1730 RenderViewHost* render_view_host) {
1731 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1732 DocumentAvailableInMainFrame());
1733}
1734
[email protected]25497492010-09-11 15:15:081735void TabContents::DocumentOnLoadCompletedInMainFrame(
1736 RenderViewHost* render_view_host,
1737 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071738 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271739 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531740 content::Source<TabContents>(this),
1741 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081742}
1743
[email protected]ae5184d62011-10-06 19:25:581744void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151745 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581746 WindowOpenDisposition disposition,
1747 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481748 // Delegate to RequestTransferURL because this is just the generic
1749 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581750 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481751 GlobalRequestID());
1752}
1753
1754void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581755 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481756 WindowOpenDisposition disposition,
1757 int64 source_frame_id,
1758 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581759 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581760 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581761 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351762 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321763 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1764 // generated suggestions).
1765 //
[email protected]e0112912011-02-02 22:54:351766 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161767 // want web sites to see a referrer of "chrome://blah" (and some
1768 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321769 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581770 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481771 render_manager_.web_ui()->link_transition_type(),
1772 false /* is_renderer_initiated */);
1773 params.transferred_global_request_id = old_request_id;
1774 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581775 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321776 } else {
[email protected]4ad5d77d2011-12-03 02:00:481777 OpenURLParams params(url, referrer, disposition,
1778 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1779 params.transferred_global_request_id = old_request_id;
1780 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581781 }
1782 if (new_contents) {
1783 // Notify observers.
1784 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1785 DidOpenRequestedURL(new_contents,
1786 url,
1787 referrer,
1788 disposition,
1789 transition_type,
1790 source_frame_id));
[email protected]420ae012009-04-24 05:16:321791 }
1792}
1793
[email protected]420ae012009-04-24 05:16:321794void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151795 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411796 const string16& message,
1797 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321798 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471799 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321800 IPC::Message* reply_msg,
1801 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071802 // Suppress JavaScript dialogs when requested. Also suppress messages when
1803 // showing an interstitial as it's shown over the previous page and we don't
1804 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501805 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151806 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501807 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071808 !delegate_ ||
1809 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321810
1811 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341812 content::JavaScriptDialogCreator::TitleType title_type;
1813 string16 title;
1814
1815 if (!frame_url.has_host()) {
1816 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1817 } else {
1818 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1819 title = net::FormatUrl(
1820 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201821 content::GetContentClient()->browser()->GetAcceptLangs(
1822 this->browser_context()));
[email protected]b627d9a2011-06-28 14:06:341823 }
1824
[email protected]2e5b90c2011-08-16 21:11:551825 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1826 dialog_creator_->RunJavaScriptDialog(this,
1827 title_type,
1828 title,
[email protected]269f86d2011-12-07 02:43:471829 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551830 message,
1831 default_prompt,
1832 reply_msg,
1833 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321834 }
[email protected]3ab9cb82011-06-03 18:02:071835
1836 if (suppress_this_message) {
1837 // If we are suppressing messages, just reply as if the user immediately
1838 // pressed "Cancel".
1839 OnDialogClosed(reply_msg, false, string16());
1840 }
1841
1842 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321843}
1844
[email protected]992db4c2011-05-12 15:37:151845void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411846 const string16& message,
[email protected]420ae012009-04-24 05:16:321847 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291848 if (delegate())
1849 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071850
1851 bool suppress_this_message =
1852 rvh->is_swapped_out() ||
1853 !delegate_ ||
1854 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151855 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411856 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501857 return;
1858 }
[email protected]3ab9cb82011-06-03 18:02:071859
[email protected]7ab1e7d62009-10-14 23:32:011860 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551861 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1862 dialog_creator_->RunBeforeUnloadDialog(this,
1863 message,
1864 reply_msg);
[email protected]420ae012009-04-24 05:16:321865}
1866
[email protected]420ae012009-04-24 05:16:321867WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081868 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361869 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]5092c282011-10-29 21:48:371870 render_view_host());
[email protected]447021c2010-09-08 21:29:081871
[email protected]b8299c12011-06-03 19:52:281872 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211873 // chrome-devtools: pages (unless it's specifically allowed).
1874 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571875 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281876 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:301877 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1878 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211879 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081880 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431881 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081882 }
1883
1884 return web_prefs;
[email protected]420ae012009-04-24 05:16:321885}
1886
[email protected]7d472472011-01-22 01:30:251887void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271888 // Notify observers.
1889 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221890
1891 ResourceDispatcherHost* rdh =
1892 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1893 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301894 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251895}
1896
[email protected]fa1cf0b82010-01-15 21:49:441897void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441898 // Notify observers.
1899 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441900}
1901
[email protected]420ae012009-04-24 05:16:321902void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1903 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151904 // Don't show hung renderer dialog for a swapped out RVH.
1905 if (rvh != render_view_host())
1906 return;
1907
[email protected]e5fc1632011-08-08 07:51:531908 // Ignore renderer unresponsive event if debugger is attached to the tab
1909 // since the event may be a result of the renderer sitting on a breakpoint.
1910 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:441911 DevToolsAgentHost* agent =
1912 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
1913 if (agent &&
1914 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:531915 return;
1916
[email protected]420ae012009-04-24 05:16:321917 if (is_during_unload) {
1918 // Hang occurred while firing the beforeunload/unload handler.
1919 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111920 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321921
1922 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1923 return;
1924
1925 // If the tab hangs in the beforeunload/unload handler there's really
1926 // nothing we can do to recover. Pretend the unload listeners have
1927 // all fired and close the tab. If the hang is in the beforeunload handler
1928 // then the user will not have the option of cancelling the close.
1929 Close(rvh);
1930 return;
1931 }
1932
[email protected]55452902011-06-01 21:57:471933 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1934 return;
1935
1936 if (delegate())
1937 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321938}
1939
1940void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471941 if (delegate())
1942 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321943}
1944
1945void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211946 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561947 uint64 upload_position,
1948 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321949 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561950 upload_position_ = upload_position;
1951 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501952 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:201953 content::GetContentClient()->browser()->GetAcceptLangs(
1954 this->browser_context()));
[email protected]9c235f042011-08-10 22:28:211955 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321956 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511957 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501958 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321959}
1960
[email protected]7d472472011-01-22 01:30:251961void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441962 if (delegate())
[email protected]55452902011-06-01 21:57:471963 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251964}
1965
[email protected]420ae012009-04-24 05:16:321966void TabContents::BeforeUnloadFiredFromRenderManager(
1967 bool proceed,
1968 bool* proceed_to_fire_unload) {
1969 if (delegate())
1970 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1971}
1972
[email protected]3a3d47472010-07-15 21:03:541973void TabContents::DidStartLoadingFromRenderManager(
1974 RenderViewHost* render_view_host) {
1975 DidStartLoading();
1976}
1977
1978void TabContents::RenderViewGoneFromRenderManager(
1979 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231980 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1981 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541982}
1983
[email protected]420ae012009-04-24 05:16:321984void TabContents::UpdateRenderViewSizeForRenderManager() {
1985 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261986 gfx::Size size = view_->GetContainerSize();
1987 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1988 // here during container initialization and normal window size will be set
1989 // later. In case of tab duplication this resizing to 0x0 prevents setting
1990 // normal size later so just ignore it.
1991 if (!size.IsEmpty())
1992 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321993}
1994
[email protected]3a3d47472010-07-15 21:03:541995void TabContents::NotifySwappedFromRenderManager() {
1996 NotifySwapped();
1997}
1998
1999NavigationController& TabContents::GetControllerForRenderManager() {
2000 return controller();
2001}
2002
[email protected]d0980792011-02-13 19:41:402003WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562004 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322005}
2006
2007NavigationEntry*
2008TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2009 return controller_.GetLastCommittedEntry();
2010}
2011
2012bool TabContents::CreateRenderViewForRenderManager(
2013 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442014 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322015 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522016
[email protected]420ae012009-04-24 05:16:322017 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442018 if (rwh_view)
2019 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322020
[email protected]a4127722011-04-27 23:13:522021 if (!render_view_host->CreateRenderView(string16()))
2022 return false;
2023
[email protected]e60c0232011-11-11 19:56:352024#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502025 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2026 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442027 if (rwh_view) {
2028 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2029 render_widget_host->WasResized();
2030 }
[email protected]f8233cc2011-05-31 20:24:502031#endif
2032
[email protected]420ae012009-04-24 05:16:322033 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2034 render_view_host);
2035 return true;
2036}
2037
[email protected]3ab9cb82011-06-03 18:02:072038void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2039 bool success,
2040 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542041 if (is_showing_before_unload_dialog_ && !success) {
2042 // If a beforeunload dialog is canceled, we need to stop the throbber from
2043 // spinning, since we forced it to start spinning in Navigate.
2044 DidStopLoading();
2045
2046 tab_close_start_time_ = base::TimeTicks();
2047 }
2048 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:412049 render_view_host()->JavaScriptDialogClosed(reply_msg,
2050 success,
[email protected]3ab9cb82011-06-03 18:02:072051 user_input);
[email protected]beb440c2009-11-06 04:08:542052}
2053
[email protected]0b08add2011-11-29 03:27:062054gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072055 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542056}
2057
[email protected]a1e97f02011-06-30 14:04:342058void TabContents::OnDialogShown() {
2059 Activate();
[email protected]3a3d47472010-07-15 21:03:542060}
2061
[email protected]41fc0322009-09-04 22:23:402062void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122063 encoding_ = content::GetContentClient()->browser()->
2064 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102065}
[email protected]f45d2a72010-03-08 23:28:352066
[email protected]33f74972010-12-08 16:40:362067void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2068 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442069 // Can be NULL during tests.
2070 if (rwh_view)
2071 rwh_view->SetSize(view()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362072}
[email protected]e9621112011-10-17 05:38:372073
2074bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
2075 return render_view_host() ?
2076 render_view_host()->GotResponseToLockMouseRequest(allowed) : false;
2077}