blob: 13e8ff42c0b0c65104e8183f57031dc1f0a28747 [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]b46442d7e2011-06-29 02:16:0618#include "content/browser/debugger/devtools_manager.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]37a72af2011-06-13 05:42:0123#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0424#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3025#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5026#include "content/browser/renderer_host/render_view_host.h"
27#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2228#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/resource_request_details.h"
30#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1332#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/navigation_entry.h"
34#include "content/browser/tab_contents/provisional_load_details.h"
35#include "content/browser/tab_contents/tab_contents_delegate.h"
36#include "content/browser/tab_contents/tab_contents_observer.h"
37#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1438#include "content/browser/tab_contents/title_updated_details.h"
[email protected]afd1e522011-04-27 23:29:5939#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5640#include "content/browser/webui/web_ui_factory.h"
[email protected]ce9751942011-09-21 01:57:2441#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0242#include "content/common/view_messages.h"
[email protected]87f3c082011-10-19 18:07:4443#include "content/public/browser/content_browser_client.h"
[email protected]610cbb82011-10-18 16:35:0844#include "content/public/browser/navigation_types.h"
[email protected]54087fe2011-10-28 22:02:4845#include "content/public/browser/notification_service.h"
[email protected]e091df82011-10-11 18:13:2146#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4847#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1848#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0349#include "content/public/common/url_constants.h"
[email protected]d686e812009-06-03 19:10:2950#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3451#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3752#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3853#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0354#include "webkit/glue/password_form.h"
[email protected]ce9751942011-09-21 01:57:2455#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3156#include "webkit/glue/webpreferences.h"
57
58#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1259#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3160#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0061
[email protected]420ae012009-04-24 05:16:3262// Cross-Site Navigations
63//
64// If a TabContents is told to navigate to a different web site (as determined
65// by SiteInstance), it will replace its current RenderViewHost with a new
66// RenderViewHost dedicated to the new SiteInstance. This works as follows:
67//
68// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4669// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3270// - The pending RVH is "suspended," so that no navigation messages are sent to
71// its renderer until the onbeforeunload JavaScript handler has a chance to
72// run in the current RVH.
73// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
74// that it has a pending cross-site request. ResourceDispatcherHost will
75// check for this when the response arrives.
76// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4677// cancel all the pending logic. Otherwise we allow the pending RVH to send
78// the navigation request to its renderer.
79// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
80// main resource load on the pending RVH. It checks CrossSiteRequestManager
81// to see that it is a cross-site request, and installs a
82// CrossSiteResourceHandler.
83// - When RDH receives a response, the BufferedResourceHandler determines
84// whether it is a download. If so, it sends a message to the new renderer
85// causing it to cancel the request, and the download proceeds. For now, the
86// pending RVH remains until the next DidNavigate event for this TabContents.
87// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3288// - After RDH receives a response and determines that it is safe and not a
89// download, it pauses the response to first run the old page's onunload
90// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1591// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3292// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1593// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3294// the ResourceDispatcherHost, who unpauses the response. Data is then sent
95// to the pending RVH.
96// - The pending renderer sends a FrameNavigate message that invokes the
97// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4698// pending RVH.
[email protected]992db4c2011-05-12 15:37:1599// - The previous renderer is kept swapped out in RenderViewHostManager in case
100// the user goes back. The process only stays live if another tab is using
101// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02102//
103// It is possible that we trigger a new navigation after we have received
104// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
105// In this case the old RVH has been swapped out but the new one has not
106// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
107// of the old RVH.
[email protected]420ae012009-04-24 05:16:32108
109namespace {
110
111// Amount of time we wait between when a key event is received and the renderer
112// is queried for its state and pushed to the NavigationEntry.
113const int kQueryStateDelay = 5000;
114
[email protected]6ebdc9b2010-09-27 16:55:57115const int kSyncWaitDelay = 40;
116
[email protected]ca406032011-07-19 21:53:05117static const char kDotGoogleDotCom[] = ".google.com";
118
[email protected]420ae012009-04-24 05:16:32119#if defined(OS_WIN)
120
121BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
122 // Note: erase is required to properly paint some widgets borders. This can
123 // be seen with textfields.
124 InvalidateRect(hwnd, NULL, TRUE);
125 return TRUE;
126}
127#endif
128
[email protected]2c5569662011-03-22 20:45:02129ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]3d7474ff2011-07-27 17:47:37130 content::BrowserContext* browser_context, const NavigationEntry& entry,
[email protected]1ccb3568d2010-02-19 10:51:16131 NavigationController::ReloadType reload_type) {
132 switch (reload_type) {
133 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02134 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16135 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02136 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16137 case NavigationController::NO_RELOAD:
138 break; // Fall through to rest of function.
139 }
[email protected]5e369672009-11-03 23:48:30140
141 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37142 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02143 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30144
[email protected]2c5569662011-03-22 20:45:02145 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30146}
147
[email protected]876bc832010-09-07 16:29:54148void MakeNavigateParams(const NavigationEntry& entry,
149 const NavigationController& controller,
[email protected]6c6b02d2011-09-02 03:36:47150 TabContentsDelegate* delegate,
[email protected]1ccb3568d2010-02-19 10:51:16151 NavigationController::ReloadType reload_type,
152 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34153 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54154 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00155 params->current_history_list_offset = controller.last_committed_entry_index();
156 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34157 params->url = entry.url();
158 params->referrer = entry.referrer();
159 params->transition = entry.transition_type();
160 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00161 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37162 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34163 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47164 params->extra_headers = entry.extra_headers();
165
166 if (delegate)
167 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34168}
169
[email protected]420ae012009-04-24 05:16:32170} // namespace
171
[email protected]f4f50ef2011-01-21 19:01:19172
173// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32174
[email protected]3d7474ff2011-07-27 17:47:37175TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32176 SiteInstance* site_instance,
177 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07178 const TabContents* base_tab_contents,
179 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42180 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07181 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37182 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13183 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32184 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22185 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34186 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23187 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
188 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34189 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34190 max_page_id_(-1),
[email protected]9c235f042011-08-10 22:28:21191 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56192 upload_size_(0),
193 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47194 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57195 capturing_contents_(false),
196 is_being_destroyed_(false),
197 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55198 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57199#if defined(OS_WIN)
200 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
201#endif
[email protected]7ab1e7d62009-10-14 23:32:01202 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56203 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38204 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25205 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01206 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25207 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01208 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00209 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43210 content_restrictions_(0),
211 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37212 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32213
[email protected]34ac70502009-09-25 17:07:23214 // We have the initial size of the view be based on the size of the passed in
215 // tab contents (normally a tab from the same window).
216 view_->CreateView(base_tab_contents ?
217 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00218
219#if defined(ENABLE_JAVA_BRIDGE)
220 java_bridge_dispatcher_host_manager_.reset(
221 new JavaBridgeDispatcherHostManager(this));
222#endif
[email protected]332af7732009-03-11 13:21:35223}
initial.commit09911bf2008-07-26 23:55:29224
225TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32226 is_being_destroyed_ = true;
227
[email protected]3ab9cb82011-06-03 18:02:07228 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55229 if (dialog_creator_)
230 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07231
[email protected]420ae012009-04-24 05:16:32232 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32233
[email protected]420ae012009-04-24 05:16:32234 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07235 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27236 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53237 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07238 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32239
240 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07241#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32242 // If we still have a window handle, destroy it. GetNativeView can return
243 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42244 if (GetNativeView()) {
245 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44246 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42247 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42248 }
[email protected]420ae012009-04-24 05:16:32249#endif
[email protected]7ab1e7d62009-10-14 23:32:01250
251 // OnCloseStarted isn't called in unit tests.
252 if (!tab_close_start_time_.is_null()) {
253 UMA_HISTOGRAM_TIMES("Tab.Close",
254 base::TimeTicks::Now() - tab_close_start_time_);
255 }
[email protected]b5a1d11c2011-02-17 03:09:42256
[email protected]07d490bc2011-03-07 17:05:26257 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08258
[email protected]1de2b8b2011-06-29 19:38:46259 set_delegate(NULL);
260}
261
262// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
263void TabContents::set_delegate(TabContentsDelegate* delegate) {
264 if (delegate == delegate_)
265 return;
266 if (delegate_)
267 delegate_->Detach(this);
268 delegate_ = delegate;
269 if (delegate_)
270 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42271}
272
[email protected]724159a2010-12-30 01:11:18273bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17274 if (web_ui() && web_ui()->OnMessageReceived(message))
275 return true;
276
[email protected]585b30362011-01-28 02:30:17277 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
278 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10279 while ((observer = it.GetNext()) != NULL)
280 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53281 return true;
[email protected]403415a2011-01-10 18:57:53282
[email protected]724159a2010-12-30 01:11:18283 bool handled = true;
284 bool message_is_ok = true;
285 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58286 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
287 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24288 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
289 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18290 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
291 OnDidStartProvisionalLoadForFrame)
292 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
293 OnDidRedirectProvisionalLoad)
294 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
295 OnDidFailProvisionalLoadWithError)
296 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
297 OnDidLoadResourceFromMemoryCache)
298 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
299 OnDidDisplayInsecureContent)
300 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
301 OnDidRunInsecureContent)
302 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
303 OnDocumentLoadedInFrame)
304 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17305 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
306 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25307 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26308 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
309 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]c7dd2f62011-07-18 15:57:59310 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21311 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20312 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
313 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
314 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16315 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45316 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10317 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18318 IPC_MESSAGE_UNHANDLED(handled = false)
319 IPC_END_MESSAGE_MAP_EX()
320
321 if (!message_is_ok) {
322 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
323 GetRenderProcessHost()->ReceivedBadMessage();
324 }
325
326 return handled;
327}
328
[email protected]6c2e472f2011-08-24 23:26:18329void TabContents::RunFileChooser(
330 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23331 const content::FileChooserParams& params) {
[email protected]6c2e472f2011-08-24 23:26:18332 delegate()->RunFileChooser(this, params);
333}
334
[email protected]f3b1a082011-11-18 00:34:30335content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03336 if (render_manager_.current_host())
337 return render_manager_.current_host()->process();
338 else
339 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16340}
341
[email protected]d5f942ba2008-09-26 19:30:34342const GURL& TabContents::GetURL() const {
343 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57344 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54345 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34346}
347
[email protected]96d185d2009-04-24 03:28:54348const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55349 // Transient entries take precedence. They are used for interstitial pages
350 // that are shown on top of existing pages.
351 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08352 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20353 content::GetContentClient()->browser()->GetAcceptLangs(
354 this->browser_context());
[email protected]45d0ef7f2011-01-05 13:46:23355 if (entry) {
[email protected]b5cca982011-05-26 04:42:08356 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23357 }
[email protected]7ade2732011-02-10 00:13:58358 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
359 render_manager_.pending_web_ui() : render_manager_.web_ui();
360 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54361 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55362 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54363 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35364 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58365 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54366 if (!title.empty())
367 return title;
368 }
369 }
370
371 // We use the title for the last committed entry rather than a pending
372 // navigation entry. For example, when the user types in a URL, we want to
373 // keep the old page's title until the new load has committed and we get a new
374 // title.
[email protected]96d185d2009-04-24 03:28:54375 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23376 if (entry) {
[email protected]b5cca982011-05-26 04:42:08377 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23378 }
[email protected]987fc3a2011-05-26 14:18:09379
380 // |page_title_when_no_navigation_entry_| is finally used
381 // if no title cannot be retrieved.
382 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54383}
384
[email protected]d5f942ba2008-09-26 19:30:34385int32 TabContents::GetMaxPageID() {
386 if (GetSiteInstance())
387 return GetSiteInstance()->max_page_id();
388 else
389 return max_page_id_;
390}
391
392void TabContents::UpdateMaxPageID(int32 page_id) {
393 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34394 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34395 // testing.
396 if (GetSiteInstance())
397 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16398 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34399}
400
[email protected]96d185d2009-04-24 03:28:54401SiteInstance* TabContents::GetSiteInstance() const {
402 return render_manager_.current_host()->site_instance();
403}
404
[email protected]77362eb2011-08-01 17:18:38405SiteInstance* TabContents::GetPendingSiteInstance() const {
406 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
407 render_manager_.pending_render_view_host() :
408 render_manager_.current_host();
409 return dest_rvh->site_instance();
410}
411
[email protected]585b30362011-01-28 02:30:17412void TabContents::AddObserver(TabContentsObserver* observer) {
413 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49414}
415
[email protected]585b30362011-01-28 02:30:17416void TabContents::RemoveObserver(TabContentsObserver* observer) {
417 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49418}
419
[email protected]443b80e2010-12-14 00:42:23420void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
421 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34422 return;
423
[email protected]443b80e2010-12-14 00:42:23424 crashed_status_ = status;
425 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50426 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34427}
428
429void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
430 if (delegate_)
431 delegate_->NavigationStateChanged(this, changed_flags);
432}
433
[email protected]96d185d2009-04-24 03:28:54434void TabContents::DidBecomeSelected() {
435 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16436 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
437 if (rwhv) {
438 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43439#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16440 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43441#endif
442 }
[email protected]96d185d2009-04-24 03:28:54443
[email protected]5ac20162010-11-24 23:33:11444 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38445
446 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54447}
448
449void TabContents::WasHidden() {
450 if (!capturing_contents()) {
451 // |render_view_host()| can be NULL if the user middle clicks a link to open
452 // a tab in then background, then closes the tab before selecting it. This
453 // is because closing the tab calls TabContents::Destroy(), which removes
454 // the |render_view_host()|; then when we actually destroy the window,
455 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16456 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
457 if (rwhv)
458 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54459 }
460
[email protected]ad50def52011-10-19 23:17:07461 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27462 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53463 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07464 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54465}
466
[email protected]d5f942ba2008-09-26 19:30:34467void TabContents::Activate() {
468 if (delegate_)
469 delegate_->ActivateContents(this);
470}
471
[email protected]ea42e7782010-08-23 23:58:12472void TabContents::Deactivate() {
473 if (delegate_)
474 delegate_->DeactivateContents(this);
475}
476
[email protected]63954792011-07-11 04:17:48477void TabContents::LostCapture() {
478 if (delegate_)
479 delegate_->LostCapture();
480}
481
482bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
483 bool* is_keyboard_shortcut) {
484 return delegate_ &&
485 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
486}
487
488void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
489 if (delegate_)
490 delegate_->HandleKeyboardEvent(event);
491}
492
[email protected]32ded2212011-11-10 18:51:43493void TabContents::HandleMouseDown() {
494 if (delegate_)
495 delegate_->HandleMouseDown();
496}
497
[email protected]63954792011-07-11 04:17:48498void TabContents::HandleMouseUp() {
499 if (delegate_)
500 delegate_->HandleMouseUp();
501}
502
503void TabContents::HandleMouseActivate() {
504 if (delegate_)
505 delegate_->HandleMouseActivate();
506}
507
[email protected]8a5e0ca2011-08-25 06:30:47508void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
509 if (delegate_)
510 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
511}
512
[email protected]5d5f7af2011-10-01 01:38:12513bool TabContents::IsFullscreenForCurrentTab() const {
514 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
515}
516
[email protected]e9621112011-10-17 05:38:37517void TabContents::RequestToLockMouse() {
518 if (delegate_) {
519 delegate_->RequestToLockMouse(this);
520 } else {
521 GotResponseToLockMouseRequest(false);
522 }
523}
524
525void TabContents::LostMouseLock() {
526 if (delegate_)
527 delegate_->LostMouseLock();
528}
529
[email protected]0548c5352011-09-07 00:33:33530void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
531 if (delegate_)
532 delegate_->UpdatePreferredSize(this, pref_size);
533}
534
[email protected]32ded2212011-11-10 18:51:43535void TabContents::WebUISend(RenderViewHost* render_view_host,
536 const GURL& source_url,
537 const std::string& name,
538 const base::ListValue& args) {
539 if (delegate_)
540 delegate_->WebUISend(this, source_url, name, args);
541}
542
[email protected]96d185d2009-04-24 03:28:54543void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16544 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
545 if (rwhv)
546 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54547}
548
549void TabContents::HideContents() {
550 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
551 // our superclass HideContents(), because some callers want to be very picky
552 // about the order in which these get called. In addition to making the code
553 // here practically impossible to understand, this also means we end up
554 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34555 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54556 WasHidden();
557}
558
[email protected]5aab5e22010-12-08 22:13:29559bool TabContents::NeedToFireBeforeUnload() {
560 // TODO(creis): Should we fire even for interstitial pages?
561 return notify_disconnection() &&
562 !showing_interstitial_page() &&
563 !render_view_host()->SuddenTerminationAllowed();
564}
565
[email protected]00c37fc2011-08-02 00:22:50566// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25567TabContents* TabContents::OpenURL(const GURL& url,
568 const GURL& referrer,
569 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58570 content::PageTransition transition) {
[email protected]e47ae9472011-10-13 19:48:34571 return OpenURL(OpenURLParams(url, referrer, disposition, transition,
572 false));
[email protected]00c37fc2011-08-02 00:22:50573}
574
575TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49576 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50577 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49578 // Notify observers.
579 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50580 DidOpenURL(params.url, params.referrer,
581 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25582 return new_contents;
[email protected]1c642b52011-04-15 09:05:49583 }
[email protected]992e4542011-07-20 23:09:25584 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34585}
586
[email protected]1ccb3568d2010-02-19 10:51:16587bool TabContents::NavigateToPendingEntry(
588 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27589 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54590}
[email protected]96d185d2009-04-24 03:28:54591
[email protected]876bc832010-09-07 16:29:54592bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27593 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54594 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40595 // The renderer will reject IPC messages with URLs longer than
596 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27597 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40598 return false;
599
[email protected]dd11de52011-11-03 22:54:27600 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40601 if (!dest_render_view_host)
602 return false; // Unable to create the desired render view host.
603
[email protected]80a8fad2011-01-29 04:02:38604 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07605 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58606 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56607 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]3d7474ff2011-07-27 17:47:37608 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(browser_context(),
[email protected]dd11de52011-11-03 22:54:27609 entry.url());
[email protected]32ded2212011-11-10 18:51:43610#if defined(OS_CHROMEOS)
611 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
612#endif
[email protected]e091df82011-10-11 18:13:21613 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55614 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58615
[email protected]96d185d2009-04-24 03:28:54616 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12617 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32618 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00619 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
620 dest_render_view_host,
[email protected]dd11de52011-11-03 22:54:27621 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32622 }
[email protected]96d185d2009-04-24 03:28:54623
624 // Used for page load time metrics.
625 current_load_start_ = base::TimeTicks::Now();
626
627 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34628 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27629 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47630 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34631 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54632
[email protected]dd11de52011-11-03 22:54:27633 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54634 // HACK!! This code suppresses javascript: URLs from being added to
635 // session history, which is what we want to do for javascript: URLs that
636 // do not generate content. What we really need is a message from the
637 // renderer telling us that a new page was not created. The same message
638 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27639 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54640 return false;
641 }
642
[email protected]3c9e1872010-11-18 16:17:49643 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04644 FOR_EACH_OBSERVER(TabContentsObserver,
645 observers_,
[email protected]dd11de52011-11-03 22:54:27646 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54647
[email protected]09b29342011-06-24 19:18:48648 if (delegate_)
649 delegate_->DidNavigateToPendingEntry(this);
650
[email protected]d5f942ba2008-09-26 19:30:34651 return true;
652}
653
[email protected]9e1ad4b2011-08-14 16:49:19654void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
655 int history_length,
656 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41657 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
658 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19659 if (render_manager_.pending_render_view_host()) {
660 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14661 return;
[email protected]9e1ad4b2011-08-14 16:49:19662 }
663 RenderViewHost* rvh = render_view_host();
664 if (!rvh) {
665 NOTREACHED();
666 return;
667 }
668 if (site_instance && rvh->site_instance() != site_instance) {
669 NOTREACHED();
670 return;
671 }
672 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
673 history_length,
674 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14675}
676
[email protected]96d185d2009-04-24 03:28:54677void TabContents::Stop() {
678 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47679 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54680}
681
[email protected]96d185d2009-04-24 03:28:54682TabContents* TabContents::Clone() {
683 // We create a new SiteInstance so that the new tab won't share processes
684 // with the old one. This can be changed in the future if we need it to share
685 // processes for some reason.
[email protected]3d7474ff2011-07-27 17:47:37686 TabContents* tc = new TabContents(
687 browser_context(),
688 SiteInstance::CreateSiteInstance(browser_context()),
689 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54690 tc->controller().CopyStateFrom(controller_);
691 return tc;
692}
693
[email protected]4d677202009-07-19 07:37:12694void TabContents::ShowPageInfo(const GURL& url,
695 const NavigationEntry::SSLStatus& ssl,
696 bool show_history) {
697 if (!delegate_)
698 return;
699
[email protected]3d7474ff2011-07-27 17:47:37700 delegate_->ShowPageInfo(browser_context(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12701}
702
[email protected]e7cfdbd2011-04-22 14:41:37703void TabContents::AddNewContents(TabContents* new_contents,
704 WindowOpenDisposition disposition,
705 const gfx::Rect& initial_pos,
706 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29707 if (!delegate_)
708 return;
709
[email protected]e7cfdbd2011-04-22 14:41:37710 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
711 user_gesture);
[email protected]96d185d2009-04-24 03:28:54712}
713
[email protected]5c9e97a2009-09-09 23:48:30714gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54715 return view_->GetContentNativeView();
716}
717
718gfx::NativeView TabContents::GetNativeView() const {
719 return view_->GetNativeView();
720}
721
722void TabContents::GetContainerBounds(gfx::Rect *out) const {
723 view_->GetContainerBounds(out);
724}
725
726void TabContents::Focus() {
727 view_->Focus();
728}
729
[email protected]90daadb42009-06-08 21:27:28730void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54731 if (showing_interstitial_page()) {
732 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
733 return;
734 }
[email protected]96d185d2009-04-24 03:28:54735 render_view_host()->SetInitialFocus(reverse);
736}
737
738bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40739 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58740 if (web_ui)
741 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43742 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25743 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43744 return true;
[email protected]96d185d2009-04-24 03:28:54745 return false;
746}
747
[email protected]a26dc362010-04-23 01:48:58748void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38749 if (delegate())
[email protected]a26dc362010-04-23 01:48:58750 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38751}
752
[email protected]686493142011-07-15 21:47:22753bool TabContents::CanDownload(int request_id) {
754 TabContentsDelegate* d = delegate();
755 if (d)
756 return d->CanDownload(this, request_id);
757 return true;
758}
759
760void TabContents::OnStartDownload(DownloadItem* download) {
761 TabContentsDelegate* d = delegate();
762 if (d)
763 d->OnStartDownload(this, download);
764}
765
[email protected]c7dd2f62011-07-18 15:57:59766void TabContents::OnSavePage() {
767 // If we can not save the page, try to download it.
768 if (!SavePackage::IsSavableContents(contents_mime_type())) {
[email protected]3d7474ff2011-07-27 17:47:37769 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59770 const GURL& current_page_url = GetURL();
771 if (dlm && current_page_url.is_valid()) {
772 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46773 download_stats::RecordDownloadCount(
774 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59775 return;
776 }
777 }
778
779 Stop();
780
781 // Create the save package and possibly prompt the user for the name to save
782 // the page as. The user prompt is an asynchronous operation that runs on
783 // another thread.
784 save_package_ = new SavePackage(this);
785 save_package_->GetSaveInfo();
786}
787
788// Used in automated testing to bypass prompting the user for file names.
789// Instead, the names and paths are hard coded rather than running them through
790// file name sanitation and extension / mime checking.
791bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
792 SavePackage::SavePackageType save_type) {
793 // Stop the page from navigating.
794 Stop();
795
796 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
797 return save_package_->Init();
798}
799
800void TabContents::OnSaveURL(const GURL& url) {
[email protected]3d7474ff2011-07-27 17:47:37801 DownloadManager* dlm = browser_context()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59802 dlm->DownloadUrl(url, GetURL(), "", this);
803}
804
[email protected]420ae012009-04-24 05:16:32805bool TabContents::IsActiveEntry(int32 page_id) {
806 NavigationEntry* active_entry = controller_.GetActiveEntry();
807 return (active_entry != NULL &&
808 active_entry->site_instance() == GetSiteInstance() &&
809 active_entry->page_id() == page_id);
810}
811
[email protected]b2fe07d12010-02-09 14:38:08812void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16813 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26814 render_view_host()->Send(new ViewMsg_SetPageEncoding(
815 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16816}
817
[email protected]b2fe07d12010-02-09 14:38:08818void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16819 reset_encoding();
[email protected]216813952011-05-19 22:21:26820 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
821 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16822}
823
[email protected]7ab1e7d62009-10-14 23:32:01824void TabContents::OnCloseStarted() {
825 if (tab_close_start_time_.is_null())
826 tab_close_start_time_ = base::TimeTicks::Now();
827}
828
[email protected]46624bf2010-06-09 16:04:19829bool TabContents::ShouldAcceptDragAndDrop() const {
830#if defined(OS_CHROMEOS)
831 // ChromeOS panels (pop-ups) do not take drag-n-drop.
832 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14833 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20834 return false;
835 return true;
[email protected]46624bf2010-06-09 16:04:19836#else
837 return true;
838#endif
839}
840
[email protected]7813bd72011-02-05 02:19:34841void TabContents::SystemDragEnded() {
842 if (render_view_host())
843 render_view_host()->DragSourceSystemDragEnded();
844 if (delegate())
845 delegate()->DragEnded();
846}
847
[email protected]d0b8d092010-10-25 04:05:17848double TabContents::GetZoomLevel() const {
[email protected]3d7474ff2011-07-27 17:47:37849 HostZoomMap* zoom_map = browser_context()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25850 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17851 return 0;
[email protected]b75b8292010-10-01 07:28:25852
853 double zoom_level;
854 if (temporary_zoom_settings_) {
855 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]f3b1a082011-11-18 00:34:30856 GetRenderProcessHost()->GetID(), render_view_host()->routing_id());
[email protected]b75b8292010-10-01 07:28:25857 } else {
[email protected]2ae88d12011-10-14 09:11:19858 GURL url;
859 NavigationEntry* active_entry = controller().GetActiveEntry();
860 // Since zoom map is updated using rewritten URL, use rewritten URL
861 // to get the zoom level.
862 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
863 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25864 }
[email protected]d0b8d092010-10-25 04:05:17865 return zoom_level;
866}
[email protected]b75b8292010-10-01 07:28:25867
[email protected]d0b8d092010-10-25 04:05:17868int TabContents::GetZoomPercent(bool* enable_increment,
869 bool* enable_decrement) {
870 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01871 // Calculate the zoom percent from the factor. Round up to the nearest whole
872 // number.
[email protected]b75b8292010-10-01 07:28:25873 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:01874 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:25875 *enable_decrement = percent > minimum_zoom_percent_;
876 *enable_increment = percent < maximum_zoom_percent_;
877 return percent;
878}
879
[email protected]3c733bde2010-12-21 19:56:31880void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50881 if (!delegate_)
882 return;
883
884 NavigationEntry* active_entry = controller().GetActiveEntry();
885 if (!active_entry)
886 return;
887
888 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12889}
890
[email protected]932b7a12011-03-09 12:50:27891void TabContents::ViewFrameSource(const GURL& url,
892 const std::string& content_state) {
893 if (!delegate_)
894 return;
895
896 delegate_->ViewSourceForFrame(this, url, content_state);
897}
898
[email protected]c40d6232011-03-25 00:16:21899void TabContents::SetContentRestrictions(int restrictions) {
900 content_restrictions_ = restrictions;
901 delegate()->ContentRestrictionsChanged(this);
902}
903
[email protected]8b5af492011-11-28 21:50:58904void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:30905 const string16& type,
906 const string16& href,
907 const string16& title,
908 const string16& disposition) {
909 delegate()->RegisterIntentHandler(
910 this, action, type, href, title, disposition);
911}
912
913void TabContents::OnWebIntentDispatch(const IPC::Message& message,
914 const webkit_glue::WebIntentData& intent,
915 int intent_id) {
916 delegate()->WebIntentDispatch(this, message.routing_id(), intent, intent_id);
917}
918
[email protected]724159a2010-12-30 01:11:18919void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
920 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:59921 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18922 const GURL& url) {
923 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
924 GURL validated_url(url);
925 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30926 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18927
[email protected]8093a542011-05-13 07:29:32928 RenderViewHost* rvh =
929 render_manager_.pending_render_view_host() ?
930 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10931 // Notify observers about the start of the provisional load.
932 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
933 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32934 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10935
[email protected]724159a2010-12-30 01:11:18936 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59937 // Notify observers about the provisional change in the main frame URL.
938 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:59939 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:18940 }
941}
942
943void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:59944 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:18945 const GURL& source_url,
946 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49947 // TODO(creis): Remove this method and have the pre-rendering code listen to
948 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
949 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18950 NavigationEntry* entry;
951 if (page_id == -1)
952 entry = controller_.pending_entry();
953 else
954 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
955 if (!entry || entry->url() != source_url)
956 return;
[email protected]e7d50892011-01-19 21:47:38957
[email protected]4850a7f2011-03-08 23:36:59958 // Notify observers about the provisional change in the main frame URL.
959 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26960 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:59961 opener_url));
[email protected]724159a2010-12-30 01:11:18962}
963
964void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:58965 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
966 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
967 << ", error_code: " << params.error_code
968 << ", error_description: " << params.error_description
969 << ", is_main_frame: " << params.is_main_frame
970 << ", showing_repost_interstitial: " <<
971 params.showing_repost_interstitial
972 << ", frame_id: " << params.frame_id;
973 GURL validated_url(params.url);
[email protected]724159a2010-12-30 01:11:18974 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:30975 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:18976
[email protected]d7b175e2011-10-11 15:31:58977 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:18978 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
979 // This means that the interstitial won't be torn down properly, which is
980 // bad. But if we have an interstitial, go back to another tab type, and
981 // then load the same interstitial again, we could end up getting the first
982 // interstitial's "failed" message (as a result of the cancel) when we're on
983 // the second one.
984 //
985 // We can't tell this apart, so we think we're tearing down the current page
986 // which will cause a crash later one. There is also some code in
987 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
988 // out because of this problem.
989 //
990 // http://code.google.com/p/chromium/issues/detail?id=2855
991 // Because this will not tear down the interstitial properly, if "back" is
992 // back to another tab type, the interstitial will still be somewhat alive
993 // in the previous tab type. If you navigate somewhere that activates the
994 // tab with the interstitial again, you'll see a flash before the new load
995 // commits of the interstitial page.
996 if (showing_interstitial_page()) {
997 LOG(WARNING) << "Discarding message during interstitial.";
998 return;
999 }
1000
[email protected]02102f82011-06-13 20:37:021001 // Discard our pending entry if the load canceled (e.g. if we decided to
1002 // download the file instead of load it). We do not verify that the URL
1003 // being canceled matches the pending entry's URL because they will not
1004 // match if a redirect occurred (in which case we do not want to leave a
1005 // stale redirect URL showing). This means that we also cancel the pending
1006 // entry if the user started a new navigation. As a result, the navigation
1007 // controller may not remember that a load is in progress, but the
1008 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181009 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021010 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161011 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181012
1013 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1014 }
1015
1016 // Send out a notification that we failed a provisional load with an error.
1017 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581018 params.is_main_frame,
1019 controller_.IsURLInPageNavigation(validated_url),
1020 validated_url,
1021 std::string(),
1022 false,
1023 params.frame_id);
1024 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181025
[email protected]ad50def52011-10-19 23:17:071026 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271027 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531028 content::Source<NavigationController>(&controller_),
1029 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101030
[email protected]d7b175e2011-10-11 15:31:581031 FOR_EACH_OBSERVER(TabContentsObserver,
1032 observers_,
1033 DidFailProvisionalLoad(params.frame_id,
1034 params.is_main_frame,
1035 validated_url,
1036 params.error_code,
1037 params.error_description));
[email protected]724159a2010-12-30 01:11:181038}
1039
1040void TabContents::OnDidLoadResourceFromMemoryCache(
1041 const GURL& url,
[email protected]70435962011-08-02 20:13:281042 const std::string& security_info,
1043 const std::string& http_method,
1044 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191045 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181046 cache.Increment();
1047
1048 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081049 int cert_id = 0;
1050 net::CertStatus cert_status = 0;
1051 int security_bits = -1;
1052 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181053 SSLManager::DeserializeSecurityInfo(security_info,
1054 &cert_id, &cert_status,
1055 &security_bits,
1056 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301057 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161058 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181059
[email protected]ad50def52011-10-19 23:17:071060 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271061 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531062 content::Source<NavigationController>(&controller_),
1063 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181064}
1065
1066void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:161067 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181068 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071069 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181070}
1071
1072void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021073 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231074 LOG(INFO) << security_origin << " ran insecure content from "
1075 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:161076 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051077 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
1078 UserMetrics::RecordAction(
1079 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1080 }
[email protected]724159a2010-12-30 01:11:181081 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411082 displayed_insecure_content_ = true;
[email protected]9678d8f2011-08-05 04:05:071083 SSLManager::NotifySSLInternalStateChanged(&controller());
[email protected]724159a2010-12-30 01:11:181084}
1085
1086void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1087 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101088 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1089 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181090}
1091
1092void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:101093 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1094 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:181095}
1096
[email protected]c8f73ab2011-01-22 00:05:171097void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211098 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171099}
1100
[email protected]216813952011-05-19 22:21:261101void TabContents::OnGoToEntryAtOffset(int offset) {
1102 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1103 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1104 if (!entry)
1105 return;
1106 // Note that we don't call NavigationController::GotToOffset() as we don't
1107 // want to create a pending navigation entry (it might end up lingering
1108 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581109 entry->set_transition_type(
1110 content::PageTransitionFromInt(
1111 entry->transition_type() |
1112 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271113 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571114
1115 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1116 // it in now that we know. This allows us to find the entry when it commits.
1117 if (!entry->site_instance() &&
1118 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381119 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571120 }
[email protected]216813952011-05-19 22:21:261121 }
1122}
1123
1124void TabContents::OnUpdateZoomLimits(int minimum_percent,
1125 int maximum_percent,
1126 bool remember) {
1127 minimum_zoom_percent_ = minimum_percent;
1128 maximum_zoom_percent_ = maximum_percent;
1129 temporary_zoom_settings_ = !remember;
1130}
1131
1132void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
[email protected]ad50def52011-10-19 23:17:071133 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271134 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]6c2381d2011-10-19 02:52:531135 content::Source<TabContents>(this),
1136 content::Details<const bool>(&is_editable_node));
[email protected]216813952011-05-19 22:21:261137}
1138
[email protected]3a29a6e2011-08-24 18:26:211139void TabContents::OnEnumerateDirectory(int request_id,
1140 const FilePath& path) {
1141 delegate()->EnumerateDirectory(this, request_id, path);
1142}
1143
[email protected]7d189022011-08-25 22:54:201144void TabContents::OnJSOutOfMemory() {
1145 delegate()->JSOutOfMemory(this);
1146}
1147
1148void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1149 const GURL& url,
1150 const string16& title) {
1151 delegate()->RegisterProtocolHandler(this, protocol, url, title);
1152}
1153
[email protected]b888919c2011-09-02 00:32:161154void TabContents::OnFindReply(int request_id,
1155 int number_of_matches,
1156 const gfx::Rect& selection_rect,
1157 int active_match_ordinal,
1158 bool final_update) {
1159 delegate()->FindReply(this, request_id, number_of_matches, selection_rect,
1160 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001161 // Send a notification to the renderer that we are ready to receive more
1162 // results from the scoping effort of the Find operation. The FindInPage
1163 // scoping is asynchronous and periodically sends results back up to the
1164 // browser using IPC. In an effort to not spam the browser we have the
1165 // browser send an ACK for each FindReply message and have the renderer
1166 // queue up the latest status message while waiting for this ACK.
1167 render_view_host()->Send(
1168 new ViewMsg_FindReplyACK(render_view_host()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161169}
1170
[email protected]d952a052011-09-06 18:42:451171void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
1172 delegate()->CrashedPlugin(this, plugin_path);
1173}
1174
[email protected]7fc4bbb2011-09-08 21:23:101175void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1176 bool blocked_by_policy) {
1177 // Notify observers about navigation.
1178 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1179 AppCacheAccessed(manifest_url, blocked_by_policy));
1180}
1181
[email protected]96d185d2009-04-24 03:28:541182// Notifies the RenderWidgetHost instance about the fact that the page is
1183// loading, or done loading and calls the base implementation.
1184void TabContents::SetIsLoading(bool is_loading,
1185 LoadNotificationDetails* details) {
1186 if (is_loading == is_loading_)
1187 return;
1188
1189 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211190 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541191 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561192 upload_size_ = 0;
1193 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541194 }
1195
1196 render_manager_.SetIsLoading(is_loading);
1197
1198 is_loading_ = is_loading;
1199 waiting_for_response_ = is_loading;
1200
[email protected]6ebdc9b2010-09-27 16:55:571201 if (delegate_)
1202 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351203 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541204
[email protected]432115822011-07-10 15:52:271205 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1206 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071207 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541208 if (details)
[email protected]6c2381d2011-10-19 02:52:531209 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071210 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531211 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541212 det);
1213}
1214
[email protected]d0980792011-02-13 19:41:401215WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581216 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541217 // that goes along with it to control the basic flags. For example, we want to
1218 // show the pending URL in the URL bar, so we want the display_url flag to
1219 // be from the pending entry.
1220 //
1221 // The confusion comes because there are multiple possibilities for the
1222 // initial load in a tab as a side effect of the way the RenderViewHostManager
1223 // works.
1224 //
[email protected]e0112912011-02-02 22:54:351225 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541226 // the pending one, and we want it to apply here.
1227 //
1228 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1229 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581230 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351231 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541232 //
1233 // This condition handles all of these cases:
1234 //
1235 // - First load in first tab: no committed nav entry + pending nav entry +
1236 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351237 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541238 //
1239 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351240 // no pending Web UI:
1241 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541242 //
1243 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351244 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541245 //
1246 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351247 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541248 if (controller_.pending_entry() &&
1249 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581250 render_manager_.pending_web_ui()))
1251 return render_manager_.pending_web_ui();
1252 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541253}
[email protected]420ae012009-04-24 05:16:321254
[email protected]1fd1a502011-03-30 16:55:561255WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]3d7474ff2011-07-27 17:47:371256 return content::WebUIFactory::Get()->GetWebUIType(browser_context(),
1257 GetURL());
[email protected]1fd1a502011-03-30 16:55:561258}
1259
[email protected]420ae012009-04-24 05:16:321260void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131261 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321262 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561263 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381264 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441265 // that opened the window, as long as both renderers have the same
1266 // privileges.
[email protected]1fd1a502011-03-30 16:55:561267 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1268 WebUI* web_ui = content::GetContentClient()->browser()->
1269 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581270 // web_ui might be NULL if the URL refers to a non-existent extension.
1271 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401272 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581273 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441274 }
1275 }
[email protected]1fd1a502011-03-30 16:55:561276 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441277 }
1278
[email protected]4e697b042011-07-08 06:44:561279 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321280 // Clear the status bubble. This is a workaround for a bug where WebKit
1281 // doesn't let us know that the cursor left an element during a
1282 // transition (this is also why the mouse cursor remains as a hand after
1283 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1284 // clear the bubble when a user navigates to a named anchor in the same
1285 // page.
1286 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321287 }
1288
[email protected]a6e82fc2010-02-24 22:28:141289 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471290 // Once the main frame is navigated, we're no longer considered to have
1291 // displayed insecure content.
1292 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171293 }
[email protected]ce5c4502009-05-06 16:46:111294
[email protected]3c9e1872010-11-18 16:17:491295 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171296 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041297 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321298}
1299
1300void TabContents::DidNavigateAnyFramePostCommit(
1301 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131302 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321303 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071304 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321305 // a malicious script from spamming messages, since the script could just
1306 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551307 if (dialog_creator_) {
1308 dialog_creator_->ResetJavaScriptState(this);
1309 dialog_creator_ = NULL;
1310 }
[email protected]420ae012009-04-24 05:16:321311
[email protected]3c9e1872010-11-18 16:17:491312 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171313 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041314 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321315}
1316
[email protected]420ae012009-04-24 05:16:321317void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1318 RenderViewHost* rvh) {
1319 // If we are creating a RVH for a restored controller, then we might
1320 // have more page IDs than the SiteInstance's current max page ID. We must
1321 // make sure that the max page ID is larger than any restored page ID.
1322 // Note that it is ok for conflicting page IDs to exist in another tab
1323 // (i.e., NavigationController), but if any page ID is larger than the max,
1324 // the back/forward list will get confused.
1325 int max_restored_page_id = controller_.max_restored_page_id();
1326 if (max_restored_page_id > 0) {
1327 int curr_max_page_id = site_instance->max_page_id();
1328 if (max_restored_page_id > curr_max_page_id) {
1329 // Need to update the site instance immediately.
1330 site_instance->UpdateMaxPageID(max_restored_page_id);
1331
1332 // Also tell the renderer to update its internal representation. We
1333 // need to reserve enough IDs to make all restored page IDs less than
1334 // the max.
1335 if (curr_max_page_id < 0)
1336 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261337 rvh->Send(new ViewMsg_ReservePageIDRange(
1338 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321339 }
1340 }
1341}
1342
[email protected]6b2f7a82011-04-25 19:30:511343bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571344 const string16& title) {
[email protected]420ae012009-04-24 05:16:321345 // For file URLs without a title, use the pathname instead. In the case of a
1346 // synthesized title, we don't want the update to count toward the "one set
1347 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511348 string16 final_title;
[email protected]420ae012009-04-24 05:16:321349 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091350 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511351 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321352 explicit_set = false; // Don't count synthetic titles toward the set limit.
1353 } else {
[email protected]acafd272011-07-26 17:35:571354 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321355 explicit_set = true;
1356 }
1357
[email protected]987fc3a2011-05-26 14:18:091358 // If a page is created via window.open and never navigated,
1359 // there will be no navigation entry. In this situation,
1360 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1361 if (entry) {
1362 if (final_title == entry->title())
1363 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321364
[email protected]987fc3a2011-05-26 14:18:091365 entry->set_title(final_title);
1366 } else {
1367 if (page_title_when_no_navigation_entry_ == final_title)
1368 return false; // Nothing changed, don't bother.
1369
1370 page_title_when_no_navigation_entry_ = final_title;
1371 }
[email protected]420ae012009-04-24 05:16:321372
[email protected]420ae012009-04-24 05:16:321373 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231374 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321375
[email protected]105bb0f2011-05-24 17:12:141376 TitleUpdatedDetails details(entry, explicit_set);
1377
[email protected]ad50def52011-10-19 23:17:071378 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271379 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531380 content::Source<TabContents>(this),
1381 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041382
[email protected]420ae012009-04-24 05:16:321383 return true;
1384}
1385
1386void TabContents::NotifySwapped() {
1387 // After sending out a swap notification, we need to send a disconnect
1388 // notification so that clients that pick up a pointer to |this| can NULL the
1389 // pointer. See Bug 1230284.
1390 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071391 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271392 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531393 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071394 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321395}
1396
1397void TabContents::NotifyConnected() {
1398 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071399 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271400 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531401 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071402 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321403}
1404
1405void TabContents::NotifyDisconnected() {
1406 if (!notify_disconnection_)
1407 return;
1408
1409 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071410 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271411 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531412 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071413 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321414}
1415
[email protected]8d3347f2009-07-09 22:00:211416RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321417 return view_.get();
1418}
1419
[email protected]8d3347f2009-07-09 22:00:211420RenderViewHostDelegate::RendererManagement*
1421TabContents::GetRendererManagementDelegate() {
1422 return &render_manager_;
1423}
1424
[email protected]daf82f82011-10-31 22:35:311425content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371426 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461427 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511428}
1429
[email protected]57c6a652009-05-04 07:58:341430TabContents* TabContents::GetAsTabContents() {
1431 return this;
1432}
1433
[email protected]da4dfc42011-10-12 15:53:561434content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431435 return view_type_;
[email protected]7b291f92009-08-14 05:43:531436}
1437
[email protected]420ae012009-04-24 05:16:321438void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071439 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271440 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531441 content::Source<TabContents>(this),
1442 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321443 NavigationEntry* entry = controller_.GetActiveEntry();
1444 if (!entry)
1445 return;
1446
1447 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351448 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561449 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581450 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321451
1452 if (entry->IsViewSourceMode()) {
1453 // Put the renderer in view source mode.
1454 render_view_host->Send(
1455 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1456 }
[email protected]0666aef2009-05-13 19:48:081457
1458 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261459
1460 FOR_EACH_OBSERVER(
1461 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321462}
1463
1464void TabContents::RenderViewReady(RenderViewHost* rvh) {
1465 if (rvh != render_view_host()) {
1466 // Don't notify the world, since this came from a renderer in the
1467 // background.
1468 return;
1469 }
1470
1471 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301472 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231473 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301474
1475 // Restore the focus to the tab (otherwise the focus will be on the top
1476 // window).
[email protected]484ae5912010-09-29 19:16:141477 if (was_crashed && !FocusLocationBarByDefault() &&
1478 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301479 Focus();
[email protected]484ae5912010-09-29 19:16:141480 }
[email protected]32ded2212011-11-10 18:51:431481
1482 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321483}
1484
[email protected]443b80e2010-12-14 00:42:231485void TabContents::RenderViewGone(RenderViewHost* rvh,
1486 base::TerminationStatus status,
1487 int error_code) {
[email protected]420ae012009-04-24 05:16:321488 if (rvh != render_view_host()) {
1489 // The pending page's RenderViewHost is gone.
1490 return;
1491 }
1492
1493 SetIsLoading(false, NULL);
1494 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231495 SetIsCrashed(status, error_code);
[email protected]b3e3f87a2011-10-01 23:37:541496 view()->OnTabCrashed(crashed_status(), crashed_error_code());
[email protected]420ae012009-04-24 05:16:321497
[email protected]9cddb1a22011-11-15 15:04:271498 FOR_EACH_OBSERVER(TabContentsObserver,
1499 observers_,
1500 RenderViewGone(crashed_status()));
[email protected]420ae012009-04-24 05:16:321501}
1502
[email protected]2e4633c2009-07-09 16:58:061503void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481504 render_manager_.RenderViewDeleted(rvh);
[email protected]483623eb2011-10-25 09:30:001505 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061506}
1507
[email protected]420ae012009-04-24 05:16:321508void TabContents::DidNavigate(RenderViewHost* rvh,
1509 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581510 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321511 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371512
[email protected]420ae012009-04-24 05:16:321513 // Update the site of the SiteInstance if it doesn't have one yet.
1514 if (!GetSiteInstance()->has_site())
1515 GetSiteInstance()->SetSite(params.url);
1516
1517 // Need to update MIME type here because it's referred to in
1518 // UpdateNavigationCommands() called by RendererDidNavigate() to
1519 // determine whether or not to enable the encoding menu.
1520 // It's updated only for the main frame. For a subframe,
1521 // RenderView::UpdateURL does not set params.contents_mime_type.
1522 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1523 // TODO(jungshik): Add a test for the encoding menu to avoid
1524 // regressing it again.
[email protected]2905f742011-10-13 03:51:581525 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321526 contents_mime_type_ = params.contents_mime_type;
1527
[email protected]8286f51a2011-05-31 17:39:131528 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001529 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391530
[email protected]a9c0bfe2010-09-17 08:35:221531 // Send notification about committed provisional loads. This notification is
1532 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1533 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081534 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071535 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1536 // that is not recorded in the navigation history. For the purpose of
1537 // tracking navigation events, we treat this event as a sub frame navigation
1538 // event.
1539 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581540 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221541 // Whether or not a page transition was triggered by going backward or
1542 // forward in the history is only stored in the navigation controller's
1543 // entry list.
1544 if (did_navigate &&
1545 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581546 content::PAGE_TRANSITION_FORWARD_BACK)) {
1547 transition_type = content::PageTransitionFromInt(
1548 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221549 }
[email protected]0d60f0192011-04-14 12:40:101550 // Notify observers about the commit of the provisional load.
1551 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1552 DidCommitProvisionalLoadForFrame(params.frame_id,
1553 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221554 }
1555
[email protected]76543b92009-08-31 17:27:451556 if (!did_navigate)
1557 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321558
1559 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1560 // for the appropriate notification (best) or you can add it to
1561 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1562 // necessary, please).
1563
1564 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001565 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321566 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481567 if (delegate())
1568 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001569 }
[email protected]420ae012009-04-24 05:16:321570 DidNavigateAnyFramePostCommit(rvh, details, params);
1571}
1572
1573void TabContents::UpdateState(RenderViewHost* rvh,
1574 int32 page_id,
1575 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151576 // Ensure that this state update comes from either the active RVH or one of
1577 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1578 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321579
1580 // We must be prepared to handle state updates for any page, these occur
1581 // when the user is scrolling and entering form data, as well as when we're
1582 // leaving a page, in which case our state may have already been moved to
1583 // the next page. The navigation controller will look up the appropriate
1584 // NavigationEntry and update it when it is notified via the delegate.
1585
1586 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151587 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321588 if (entry_index < 0)
1589 return;
1590 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1591
1592 if (state == entry->content_state())
1593 return; // Nothing to update.
1594 entry->set_content_state(state);
1595 controller_.NotifyEntryChanged(entry, entry_index);
1596}
1597
1598void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571599 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461600 const string16& title,
1601 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321602 // If we have a title, that's a pretty good indication that we've started
1603 // getting useful data.
1604 SetNotWaitingForResponse();
1605
1606 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481607 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581608 page_id);
[email protected]987fc3a2011-05-26 14:18:091609
[email protected]a49e10b2011-08-01 23:57:461610 // TODO(evan): make use of title_direction.
1611 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091612 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321613 return;
1614
1615 // Broadcast notifications when the UI should be updated.
1616 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031617 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321618}
1619
[email protected]420ae012009-04-24 05:16:321620void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401621 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321622 set_encoding(encoding);
1623}
1624
1625void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1626 if (delegate())
[email protected]d952a052011-09-06 18:42:451627 delegate()->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321628}
1629
[email protected]420ae012009-04-24 05:16:321630void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291631 // The UI may be in an event-tracking loop, such as between the
1632 // mouse-down and mouse-up in text selection or a button click.
1633 // Defer the close until after tracking is complete, so that we
1634 // don't free objects out from under the UI.
1635 // TODO(shess): This could probably be integrated with the
1636 // IsDoingDrag() test below. Punting for now because I need more
1637 // research to understand how this impacts platforms other than Mac.
1638 // TODO(shess): This could get more fine-grained. For instance,
1639 // closing a tab in another window while selecting text in the
1640 // current window's Omnibox should be just fine.
1641 if (view()->IsEventTracking()) {
1642 view()->CloseTabAfterEventTracking();
1643 return;
1644 }
1645
[email protected]24a4d1062009-07-10 23:10:421646 // If we close the tab while we're in the middle of a drag, we'll crash.
1647 // Instead, cancel the drag and close it as soon as the drag ends.
1648 if (view()->IsDoingDrag()) {
1649 view()->CancelDragAndCloseTab();
1650 return;
1651 }
1652
[email protected]420ae012009-04-24 05:16:321653 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1654 if (delegate() && rvh == render_view_host())
1655 delegate()->CloseContents(this);
1656}
1657
[email protected]cd9ed79d2011-11-15 19:22:571658void TabContents::SwappedOut(RenderViewHost* rvh) {
1659 if (delegate() && rvh == render_view_host())
1660 delegate()->SwappedOut(this);
1661}
1662
[email protected]420ae012009-04-24 05:16:321663void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141664 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321665 delegate()->MoveContents(this, new_bounds);
1666}
1667
[email protected]7ab1e7d62009-10-14 23:32:011668void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321669 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491670
[email protected]c40d6232011-03-25 00:16:211671 if (delegate() && content_restrictions_) {
1672 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211673 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001674 }
[email protected]3c9e1872010-11-18 16:17:491675
1676 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171677 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321678}
1679
[email protected]7ab1e7d62009-10-14 23:32:011680void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321681 scoped_ptr<LoadNotificationDetails> details;
1682
1683 NavigationEntry* entry = controller_.GetActiveEntry();
1684 // An entry may not exist for a stop when loading an initial blank page or
1685 // if an iframe injected by script into a blank page finishes loading.
1686 if (entry) {
[email protected]420ae012009-04-24 05:16:321687 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1688
1689 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541690 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321691 entry->transition_type(),
1692 elapsed,
1693 &controller_,
1694 controller_.GetCurrentEntryIndex()));
1695 }
1696
[email protected]420ae012009-04-24 05:16:321697 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491698
1699 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171700 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321701}
1702
[email protected]c95fa8b2011-04-28 20:26:161703void TabContents::DidCancelLoading() {
1704 controller_.DiscardNonCommittedEntries();
1705
1706 // Update the URL display.
1707 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1708}
1709
[email protected]1a3c3cb2010-12-16 21:03:401710void TabContents::DidChangeLoadProgress(double progress) {
1711 if (delegate())
1712 delegate()->LoadProgressChanged(progress);
1713}
1714
[email protected]952a68e2011-11-17 00:36:101715void TabContents::DocumentAvailableInMainFrame(
1716 RenderViewHost* render_view_host) {
1717 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1718 DocumentAvailableInMainFrame());
1719}
1720
[email protected]25497492010-09-11 15:15:081721void TabContents::DocumentOnLoadCompletedInMainFrame(
1722 RenderViewHost* render_view_host,
1723 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071724 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271725 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531726 content::Source<TabContents>(this),
1727 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081728}
1729
[email protected]ae5184d62011-10-06 19:25:581730void TabContents::RequestOpenURL(const GURL& url,
1731 const GURL& referrer,
1732 WindowOpenDisposition disposition,
1733 int64 source_frame_id) {
1734 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581735 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581736 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351737 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321738 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1739 // generated suggestions).
1740 //
[email protected]e0112912011-02-02 22:54:351741 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161742 // want web sites to see a referrer of "chrome://blah" (and some
1743 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321744 // send to the site), so we send no referrer.
[email protected]ae5184d62011-10-06 19:25:581745 new_contents = OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:581746 render_manager_.web_ui()->link_transition_type());
[email protected]ae5184d62011-10-06 19:25:581747 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321748 } else {
[email protected]e47ae9472011-10-13 19:48:341749 new_contents = OpenURL(OpenURLParams(
1750 url, referrer, disposition, content::PAGE_TRANSITION_LINK,
1751 true /* is_renderer_initiated */));
[email protected]ae5184d62011-10-06 19:25:581752 }
1753 if (new_contents) {
1754 // Notify observers.
1755 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1756 DidOpenRequestedURL(new_contents,
1757 url,
1758 referrer,
1759 disposition,
1760 transition_type,
1761 source_frame_id));
[email protected]420ae012009-04-24 05:16:321762 }
1763}
1764
[email protected]420ae012009-04-24 05:16:321765void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151766 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411767 const string16& message,
1768 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321769 const GURL& frame_url,
1770 const int flags,
1771 IPC::Message* reply_msg,
1772 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071773 // Suppress JavaScript dialogs when requested. Also suppress messages when
1774 // showing an interstitial as it's shown over the previous page and we don't
1775 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501776 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151777 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501778 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071779 !delegate_ ||
1780 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321781
1782 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341783 content::JavaScriptDialogCreator::TitleType title_type;
1784 string16 title;
1785
1786 if (!frame_url.has_host()) {
1787 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1788 } else {
1789 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1790 title = net::FormatUrl(
1791 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201792 content::GetContentClient()->browser()->GetAcceptLangs(
1793 this->browser_context()));
[email protected]b627d9a2011-06-28 14:06:341794 }
1795
[email protected]2e5b90c2011-08-16 21:11:551796 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1797 dialog_creator_->RunJavaScriptDialog(this,
1798 title_type,
1799 title,
1800 flags,
1801 message,
1802 default_prompt,
1803 reply_msg,
1804 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321805 }
[email protected]3ab9cb82011-06-03 18:02:071806
1807 if (suppress_this_message) {
1808 // If we are suppressing messages, just reply as if the user immediately
1809 // pressed "Cancel".
1810 OnDialogClosed(reply_msg, false, string16());
1811 }
1812
1813 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321814}
1815
[email protected]992db4c2011-05-12 15:37:151816void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411817 const string16& message,
[email protected]420ae012009-04-24 05:16:321818 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291819 if (delegate())
1820 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071821
1822 bool suppress_this_message =
1823 rvh->is_swapped_out() ||
1824 !delegate_ ||
1825 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151826 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411827 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501828 return;
1829 }
[email protected]3ab9cb82011-06-03 18:02:071830
[email protected]7ab1e7d62009-10-14 23:32:011831 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:551832 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1833 dialog_creator_->RunBeforeUnloadDialog(this,
1834 message,
1835 reply_msg);
[email protected]420ae012009-04-24 05:16:321836}
1837
[email protected]420ae012009-04-24 05:16:321838WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081839 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361840 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]5092c282011-10-29 21:48:371841 render_view_host());
[email protected]447021c2010-09-08 21:29:081842
[email protected]b8299c12011-06-03 19:52:281843 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:211844 // chrome-devtools: pages (unless it's specifically allowed).
1845 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:571846 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:281847 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:301848 (GetURL().SchemeIs(chrome::kAboutScheme) &&
1849 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:211850 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:081851 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431852 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081853 }
1854
1855 return web_prefs;
[email protected]420ae012009-04-24 05:16:321856}
1857
[email protected]7d472472011-01-22 01:30:251858void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271859 // Notify observers.
1860 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221861
1862 ResourceDispatcherHost* rdh =
1863 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1864 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:301865 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251866}
1867
[email protected]fa1cf0b82010-01-15 21:49:441868void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:441869 // Notify observers.
1870 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:441871}
1872
[email protected]420ae012009-04-24 05:16:321873void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1874 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151875 // Don't show hung renderer dialog for a swapped out RVH.
1876 if (rvh != render_view_host())
1877 return;
1878
[email protected]e5fc1632011-08-08 07:51:531879 // Ignore renderer unresponsive event if debugger is attached to the tab
1880 // since the event may be a result of the renderer sitting on a breakpoint.
1881 // See http://crbug.com/65458
1882 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
1883 if (devtools_manager &&
1884 devtools_manager->GetDevToolsClientHostFor(rvh) != NULL)
1885 return;
1886
[email protected]420ae012009-04-24 05:16:321887 if (is_during_unload) {
1888 // Hang occurred while firing the beforeunload/unload handler.
1889 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111890 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321891
1892 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1893 return;
1894
1895 // If the tab hangs in the beforeunload/unload handler there's really
1896 // nothing we can do to recover. Pretend the unload listeners have
1897 // all fired and close the tab. If the hang is in the beforeunload handler
1898 // then the user will not have the option of cancelling the close.
1899 Close(rvh);
1900 return;
1901 }
1902
[email protected]55452902011-06-01 21:57:471903 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1904 return;
1905
1906 if (delegate())
1907 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321908}
1909
1910void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471911 if (delegate())
1912 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321913}
1914
1915void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:211916 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:561917 uint64 upload_position,
1918 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321919 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561920 upload_position_ = upload_position;
1921 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501922 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:201923 content::GetContentClient()->browser()->GetAcceptLangs(
1924 this->browser_context()));
[email protected]9c235f042011-08-10 22:28:211925 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:321926 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:511927 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:501928 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321929}
1930
[email protected]7d472472011-01-22 01:30:251931void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441932 if (delegate())
[email protected]55452902011-06-01 21:57:471933 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251934}
1935
[email protected]420ae012009-04-24 05:16:321936void TabContents::BeforeUnloadFiredFromRenderManager(
1937 bool proceed,
1938 bool* proceed_to_fire_unload) {
1939 if (delegate())
1940 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1941}
1942
[email protected]3a3d47472010-07-15 21:03:541943void TabContents::DidStartLoadingFromRenderManager(
1944 RenderViewHost* render_view_host) {
1945 DidStartLoading();
1946}
1947
1948void TabContents::RenderViewGoneFromRenderManager(
1949 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231950 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1951 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541952}
1953
[email protected]420ae012009-04-24 05:16:321954void TabContents::UpdateRenderViewSizeForRenderManager() {
1955 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261956 gfx::Size size = view_->GetContainerSize();
1957 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1958 // here during container initialization and normal window size will be set
1959 // later. In case of tab duplication this resizing to 0x0 prevents setting
1960 // normal size later so just ignore it.
1961 if (!size.IsEmpty())
1962 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321963}
1964
[email protected]3a3d47472010-07-15 21:03:541965void TabContents::NotifySwappedFromRenderManager() {
1966 NotifySwapped();
1967}
1968
1969NavigationController& TabContents::GetControllerForRenderManager() {
1970 return controller();
1971}
1972
[email protected]d0980792011-02-13 19:41:401973WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561974 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321975}
1976
1977NavigationEntry*
1978TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1979 return controller_.GetLastCommittedEntry();
1980}
1981
1982bool TabContents::CreateRenderViewForRenderManager(
1983 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:441984 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:321985 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:521986
[email protected]420ae012009-04-24 05:16:321987 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:441988 if (rwh_view)
1989 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:321990
[email protected]a4127722011-04-27 23:13:521991 if (!render_view_host->CreateRenderView(string16()))
1992 return false;
1993
[email protected]e60c0232011-11-11 19:56:351994#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:501995 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
1996 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:441997 if (rwh_view) {
1998 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1999 render_widget_host->WasResized();
2000 }
[email protected]f8233cc2011-05-31 20:24:502001#endif
2002
[email protected]420ae012009-04-24 05:16:322003 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2004 render_view_host);
2005 return true;
2006}
2007
[email protected]3ab9cb82011-06-03 18:02:072008void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2009 bool success,
2010 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542011 if (is_showing_before_unload_dialog_ && !success) {
2012 // If a beforeunload dialog is canceled, we need to stop the throbber from
2013 // spinning, since we forced it to start spinning in Navigate.
2014 DidStopLoading();
2015
2016 tab_close_start_time_ = base::TimeTicks();
2017 }
2018 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:412019 render_view_host()->JavaScriptDialogClosed(reply_msg,
2020 success,
[email protected]3ab9cb82011-06-03 18:02:072021 user_input);
[email protected]beb440c2009-11-06 04:08:542022}
2023
[email protected]3ab9cb82011-06-03 18:02:072024gfx::NativeWindow TabContents::GetDialogRootWindow() {
2025 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542026}
2027
[email protected]a1e97f02011-06-30 14:04:342028void TabContents::OnDialogShown() {
2029 Activate();
[email protected]3a3d47472010-07-15 21:03:542030}
2031
[email protected]41fc0322009-09-04 22:23:402032void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122033 encoding_ = content::GetContentClient()->browser()->
2034 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102035}
[email protected]f45d2a72010-03-08 23:28:352036
[email protected]33f74972010-12-08 16:40:362037void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2038 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442039 // Can be NULL during tests.
2040 if (rwh_view)
2041 rwh_view->SetSize(view()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362042}
[email protected]e9621112011-10-17 05:38:372043
2044bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
2045 return render_view_host() ?
2046 render_view_host()->GotResponseToLockMouseRequest(allowed) : false;
2047}