blob: 0cb1762bb0f84b0e81e914d56b4bec3c34bc450d [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]567812d2011-02-24 17:40:5016#include "content/browser/child_process_security_policy.h"
[email protected]0e12d7d2011-12-01 16:21:4417#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4618#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5019#include "content/browser/host_zoom_map.h"
20#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0021#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0122#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0423#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3024#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5025#include "content/browser/renderer_host/render_view_host.h"
26#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2227#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/resource_request_details.h"
29#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4430#include "content/browser/tab_contents/interstitial_page.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/navigation_entry.h"
32#include "content/browser/tab_contents/provisional_load_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1434#include "content/browser/tab_contents/title_updated_details.h"
[email protected]1fd1a502011-03-30 16:55:5635#include "content/browser/webui/web_ui_factory.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1138#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4439#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4440#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1741#include "content/public/browser/download_manager.h"
[email protected]5b96836f2011-12-22 07:39:0042#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4843#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3844#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4245#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2546#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2147#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1849#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d686e812009-06-03 19:10:2951#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3452#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3854#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2455#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3156#include "webkit/glue/webpreferences.h"
57
58#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1259#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3160#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0061
[email protected]420ae012009-04-24 05:16:3262// Cross-Site Navigations
63//
64// If a TabContents is told to navigate to a different web site (as determined
65// by SiteInstance), it will replace its current RenderViewHost with a new
66// RenderViewHost dedicated to the new SiteInstance. This works as follows:
67//
68// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4669// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3270// - The pending RVH is "suspended," so that no navigation messages are sent to
71// its renderer until the onbeforeunload JavaScript handler has a chance to
72// run in the current RVH.
73// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
74// that it has a pending cross-site request. ResourceDispatcherHost will
75// check for this when the response arrives.
76// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4677// cancel all the pending logic. Otherwise we allow the pending RVH to send
78// the navigation request to its renderer.
79// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
80// main resource load on the pending RVH. It checks CrossSiteRequestManager
81// to see that it is a cross-site request, and installs a
82// CrossSiteResourceHandler.
83// - When RDH receives a response, the BufferedResourceHandler determines
84// whether it is a download. If so, it sends a message to the new renderer
85// causing it to cancel the request, and the download proceeds. For now, the
86// pending RVH remains until the next DidNavigate event for this TabContents.
87// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3288// - After RDH receives a response and determines that it is safe and not a
89// download, it pauses the response to first run the old page's onunload
90// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1591// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3292// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1593// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3294// the ResourceDispatcherHost, who unpauses the response. Data is then sent
95// to the pending RVH.
96// - The pending renderer sends a FrameNavigate message that invokes the
97// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4698// pending RVH.
[email protected]992db4c2011-05-12 15:37:1599// - The previous renderer is kept swapped out in RenderViewHostManager in case
100// the user goes back. The process only stays live if another tab is using
101// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02102//
103// It is possible that we trigger a new navigation after we have received
104// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
105// In this case the old RVH has been swapped out but the new one has not
106// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
107// of the old RVH.
[email protected]420ae012009-04-24 05:16:32108
[email protected]0e12d7d2011-12-01 16:21:44109using content::DevToolsAgentHost;
110using content::DevToolsAgentHostRegistry;
111using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17112using content::DownloadItem;
113using content::DownloadManager;
[email protected]7f6f44c2011-12-14 13:23:38114using content::UserMetricsAction;
[email protected]d8c660432011-12-22 20:51:25115using content::WebContentsObserver;
[email protected]0e12d7d2011-12-01 16:21:44116
[email protected]420ae012009-04-24 05:16:32117namespace {
118
119// Amount of time we wait between when a key event is received and the renderer
120// is queried for its state and pushed to the NavigationEntry.
121const int kQueryStateDelay = 5000;
122
[email protected]6ebdc9b2010-09-27 16:55:57123const int kSyncWaitDelay = 40;
124
[email protected]ca406032011-07-19 21:53:05125static const char kDotGoogleDotCom[] = ".google.com";
126
[email protected]420ae012009-04-24 05:16:32127#if defined(OS_WIN)
128
129BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
130 // Note: erase is required to properly paint some widgets borders. This can
131 // be seen with textfields.
132 InvalidateRect(hwnd, NULL, TRUE);
133 return TRUE;
134}
135#endif
136
[email protected]2c5569662011-03-22 20:45:02137ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]3d7474ff2011-07-27 17:47:37138 content::BrowserContext* browser_context, const NavigationEntry& entry,
[email protected]1ccb3568d2010-02-19 10:51:16139 NavigationController::ReloadType reload_type) {
140 switch (reload_type) {
141 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02142 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16143 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02144 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16145 case NavigationController::NO_RELOAD:
146 break; // Fall through to rest of function.
147 }
[email protected]5e369672009-11-03 23:48:30148
149 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37150 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02151 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30152
[email protected]2c5569662011-03-22 20:45:02153 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30154}
155
[email protected]876bc832010-09-07 16:29:54156void MakeNavigateParams(const NavigationEntry& entry,
157 const NavigationController& controller,
[email protected]674bc592011-12-20 23:00:42158 content::WebContentsDelegate* delegate,
[email protected]1ccb3568d2010-02-19 10:51:16159 NavigationController::ReloadType reload_type,
160 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34161 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54162 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00163 params->current_history_list_offset = controller.last_committed_entry_index();
164 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34165 params->url = entry.url();
[email protected]cb8fb01a2011-12-05 21:01:14166 params->referrer = entry.referrer();
[email protected]056de2d2009-06-26 16:41:34167 params->transition = entry.transition_type();
168 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00169 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37170 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34171 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47172 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48173 params->transferred_request_child_id =
174 entry.transferred_global_request_id().child_id;
175 params->transferred_request_request_id =
176 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47177
178 if (delegate)
179 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34180}
181
[email protected]420ae012009-04-24 05:16:32182} // namespace
183
[email protected]f4f50ef2011-01-21 19:01:19184
185// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32186
[email protected]3d7474ff2011-07-27 17:47:37187TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32188 SiteInstance* site_instance,
189 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07190 const TabContents* base_tab_contents,
191 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42192 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07193 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37194 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13195 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32196 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22197 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34198 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23199 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
200 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34201 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21202 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56203 upload_size_(0),
204 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47205 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57206 capturing_contents_(false),
207 is_being_destroyed_(false),
208 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55209 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57210#if defined(OS_WIN)
211 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
212#endif
[email protected]7ab1e7d62009-10-14 23:32:01213 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56214 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38215 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25216 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01217 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25218 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01219 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00220 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43221 content_restrictions_(0),
222 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37223 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32224
[email protected]34ac70502009-09-25 17:07:23225 // We have the initial size of the view be based on the size of the passed in
226 // tab contents (normally a tab from the same window).
227 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21228 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00229
230#if defined(ENABLE_JAVA_BRIDGE)
231 java_bridge_dispatcher_host_manager_.reset(
232 new JavaBridgeDispatcherHostManager(this));
233#endif
[email protected]332af7732009-03-11 13:21:35234}
initial.commit09911bf2008-07-26 23:55:29235
236TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32237 is_being_destroyed_ = true;
238
[email protected]3ab9cb82011-06-03 18:02:07239 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55240 if (dialog_creator_)
241 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07242
[email protected]420ae012009-04-24 05:16:32243 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32244
[email protected]420ae012009-04-24 05:16:32245 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07246 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27247 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53248 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07249 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32250
251 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07252#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32253 // If we still have a window handle, destroy it. GetNativeView can return
254 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42255 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52256 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44257 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42258 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42259 }
[email protected]420ae012009-04-24 05:16:32260#endif
[email protected]7ab1e7d62009-10-14 23:32:01261
262 // OnCloseStarted isn't called in unit tests.
263 if (!tab_close_start_time_.is_null()) {
264 UMA_HISTOGRAM_TIMES("Tab.Close",
265 base::TimeTicks::Now() - tab_close_start_time_);
266 }
[email protected]b5a1d11c2011-02-17 03:09:42267
[email protected]d8c660432011-12-22 20:51:25268 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08269
[email protected]6934a702011-12-20 00:04:51270 SetDelegate(NULL);
[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]be1f56ab2011-12-22 06:55:31274 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17275 return true;
276
[email protected]d8c660432011-12-22 20:51:25277 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
278 WebContentsObserver* 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)
[email protected]c7dd2f62011-07-18 15:57:59309 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21310 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20311 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
312 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
313 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16314 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45315 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10316 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18317 IPC_MESSAGE_UNHANDLED(handled = false)
318 IPC_END_MESSAGE_MAP_EX()
319
320 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38321 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18322 GetRenderProcessHost()->ReceivedBadMessage();
323 }
324
325 return handled;
326}
327
[email protected]6c2e472f2011-08-24 23:26:18328void TabContents::RunFileChooser(
329 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23330 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51331 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18332}
333
[email protected]f5fa20e2011-12-21 22:35:56334NavigationController& TabContents::GetController() {
335 return controller_;
336}
337
338const NavigationController& TabContents::GetController() const {
339 return controller_;
340}
341
[email protected]627e0512011-12-21 22:55:30342content::BrowserContext* TabContents::GetBrowserContext() const {
343 return controller_.browser_context();
344}
345
[email protected]f5fa20e2011-12-21 22:35:56346void TabContents::SetViewType(content::ViewType type) {
347 view_type_ = type;
348}
349
[email protected]be1f56ab2011-12-22 06:55:31350const GURL& TabContents::GetURL() const {
351 // We may not have a navigation entry yet
352 NavigationEntry* entry = controller_.GetActiveEntry();
353 return entry ? entry->virtual_url() : GURL::EmptyGURL();
354}
355
356
357const base::PropertyBag* TabContents::GetPropertyBag() const {
358 return &property_bag_;
359}
360
361base::PropertyBag* TabContents::GetPropertyBag() {
362 return &property_bag_;
363}
364
365content::WebContentsDelegate* TabContents::GetDelegate() {
366 return delegate_;
367}
368
369void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
370 // TODO(cbentzel): remove this debugging code?
371 if (delegate == delegate_)
372 return;
373 if (delegate_)
374 delegate_->Detach(this);
375 delegate_ = delegate;
376 if (delegate_)
377 delegate_->Attach(this);
378}
379
[email protected]f3b1a082011-11-18 00:34:30380content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03381 if (render_manager_.current_host())
382 return render_manager_.current_host()->process();
383 else
384 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16385}
386
[email protected]be1f56ab2011-12-22 06:55:31387RenderViewHost* TabContents::GetRenderViewHost() const {
388 return render_manager_.current_host();
389}
390
391RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
392 return render_manager_.GetRenderWidgetHostView();
393}
394
395TabContentsView* TabContents::GetView() const {
396 return view_.get();
397}
398
399WebUI* TabContents::GetWebUI() const {
400 return render_manager_.web_ui() ? render_manager_.web_ui()
401 : render_manager_.pending_web_ui();
402}
403
404WebUI* TabContents::GetCommittedWebUI() const {
405 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34406}
407
[email protected]96d185d2009-04-24 03:28:54408const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55409 // Transient entries take precedence. They are used for interstitial pages
410 // that are shown on top of existing pages.
411 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08412 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20413 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30414 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23415 if (entry) {
[email protected]b5cca982011-05-26 04:42:08416 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23417 }
[email protected]7ade2732011-02-10 00:13:58418 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
419 render_manager_.pending_web_ui() : render_manager_.web_ui();
420 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54421 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55422 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54423 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35424 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58425 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54426 if (!title.empty())
427 return title;
428 }
429 }
430
431 // We use the title for the last committed entry rather than a pending
432 // navigation entry. For example, when the user types in a URL, we want to
433 // keep the old page's title until the new load has committed and we get a new
434 // title.
[email protected]96d185d2009-04-24 03:28:54435 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23436 if (entry) {
[email protected]b5cca982011-05-26 04:42:08437 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23438 }
[email protected]987fc3a2011-05-26 14:18:09439
440 // |page_title_when_no_navigation_entry_| is finally used
441 // if no title cannot be retrieved.
442 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54443}
444
[email protected]d5f942ba2008-09-26 19:30:34445int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46446 return GetMaxPageIDForSiteInstance(GetSiteInstance());
447}
448
449int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
450 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
451 max_page_ids_[site_instance->id()] = -1;
452
453 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34454}
455
456void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46457 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
458}
459
460void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
461 int32 page_id) {
462 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
463 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34464}
465
[email protected]96d185d2009-04-24 03:28:54466SiteInstance* TabContents::GetSiteInstance() const {
467 return render_manager_.current_host()->site_instance();
468}
469
[email protected]77362eb2011-08-01 17:18:38470SiteInstance* TabContents::GetPendingSiteInstance() const {
471 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
472 render_manager_.pending_render_view_host() :
473 render_manager_.current_host();
474 return dest_rvh->site_instance();
475}
476
[email protected]be1f56ab2011-12-22 06:55:31477bool TabContents::IsLoading() const {
478 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49479}
480
[email protected]be1f56ab2011-12-22 06:55:31481bool TabContents::IsWaitingForResponse() const {
482 return waiting_for_response_;
483}
484
485const net::LoadStateWithParam& TabContents::GetLoadState() const {
486 return load_state_;
487}
488
489const string16& TabContents::GetLoadStateHost() const {
490 return load_state_host_;
491}
492
493uint64 TabContents::GetUploadSize() const {
494 return upload_size_;
495}
496
497uint64 TabContents::GetUploadPosition() const {
498 return upload_position_;
499}
500
501const std::string& TabContents::GetEncoding() const {
502 return encoding_;
503}
504
505bool TabContents::DisplayedInsecureContent() const {
506 return displayed_insecure_content_;
507}
508
509void TabContents::SetCapturingContents(bool cap) {
510 capturing_contents_ = cap;
511}
512
513bool TabContents::IsCrashed() const {
514 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
515 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
516 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49517}
518
[email protected]443b80e2010-12-14 00:42:23519void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
520 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34521 return;
522
[email protected]443b80e2010-12-14 00:42:23523 crashed_status_ = status;
524 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50525 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34526}
527
[email protected]be1f56ab2011-12-22 06:55:31528base::TerminationStatus TabContents::GetCrashedStatus() const {
529 return crashed_status_;
530}
531
532bool TabContents::IsBeingDestroyed() const {
533 return is_being_destroyed_;
534}
535
[email protected]d5f942ba2008-09-26 19:30:34536void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
537 if (delegate_)
538 delegate_->NavigationStateChanged(this, changed_flags);
539}
540
[email protected]96d185d2009-04-24 03:28:54541void TabContents::DidBecomeSelected() {
542 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16543 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
544 if (rwhv) {
545 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43546#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16547 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43548#endif
549 }
[email protected]96d185d2009-04-24 03:28:54550
[email protected]5ac20162010-11-24 23:33:11551 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38552
[email protected]d8c660432011-12-22 20:51:25553 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54554}
555
[email protected]be1f56ab2011-12-22 06:55:31556
557base::TimeTicks TabContents::GetLastSelectedTime() const {
558 return last_selected_time_;
559}
560
[email protected]96d185d2009-04-24 03:28:54561void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31562 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52563 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
564 // open a tab in then background, then closes the tab before selecting it.
565 // This is because closing the tab calls TabContents::Destroy(), which
566 // removes the |GetRenderViewHost()|; then when we actually destroy the
567 // window, OnWindowPosChanged() notices and calls HideContents() (which
568 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16569 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
570 if (rwhv)
571 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54572 }
573
[email protected]ad50def52011-10-19 23:17:07574 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27575 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]6c2381d2011-10-19 02:52:53576 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:07577 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54578}
579
[email protected]be1f56ab2011-12-22 06:55:31580void TabContents::ShowContents() {
581 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
582 if (rwhv)
583 rwhv->DidBecomeSelected();
584}
585
586void TabContents::HideContents() {
587 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
588 // our superclass HideContents(), because some callers want to be very picky
589 // about the order in which these get called. In addition to making the code
590 // here practically impossible to understand, this also means we end up
591 // calling TabContents::WasHidden() twice if callers call both versions of
592 // HideContents() on a TabContents.
593 WasHidden();
594}
595
596bool TabContents::NeedToFireBeforeUnload() {
597 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27598 return WillNotifyDisconnection() &&
599 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31600 !GetRenderViewHost()->SuddenTerminationAllowed();
601}
602
603RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
604 return &render_manager_;
605}
606
[email protected]0bfbf882011-12-22 18:19:27607void TabContents::Stop() {
608 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25609 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27610}
611
612TabContents* TabContents::Clone() {
613 // We create a new SiteInstance so that the new tab won't share processes
614 // with the old one. This can be changed in the future if we need it to share
615 // processes for some reason.
616 TabContents* tc = new TabContents(
617 GetBrowserContext(),
618 SiteInstance::CreateSiteInstance(GetBrowserContext()),
619 MSG_ROUTING_NONE, this, NULL);
620 tc->GetController().CopyStateFrom(controller_);
621 return tc;
622}
623
624void TabContents::ShowPageInfo(const GURL& url,
625 const NavigationEntry::SSLStatus& ssl,
626 bool show_history) {
627 if (!delegate_)
628 return;
629
630 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
631}
632
633void TabContents::AddNewContents(TabContents* new_contents,
634 WindowOpenDisposition disposition,
635 const gfx::Rect& initial_pos,
636 bool user_gesture) {
637 if (!delegate_)
638 return;
639
640 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
641 user_gesture);
642}
643
644gfx::NativeView TabContents::GetContentNativeView() const {
645 return view_->GetContentNativeView();
646}
647
648gfx::NativeView TabContents::GetNativeView() const {
649 return view_->GetNativeView();
650}
651
652void TabContents::GetContainerBounds(gfx::Rect* out) const {
653 view_->GetContainerBounds(out);
654}
655
656void TabContents::Focus() {
657 view_->Focus();
658}
659
[email protected]d8c660432011-12-22 20:51:25660void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31661 observers_.AddObserver(observer);
662}
663
[email protected]d8c660432011-12-22 20:51:25664void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31665 observers_.RemoveObserver(observer);
666}
667
[email protected]d5f942ba2008-09-26 19:30:34668void TabContents::Activate() {
669 if (delegate_)
670 delegate_->ActivateContents(this);
671}
672
[email protected]ea42e7782010-08-23 23:58:12673void TabContents::Deactivate() {
674 if (delegate_)
675 delegate_->DeactivateContents(this);
676}
677
[email protected]63954792011-07-11 04:17:48678void TabContents::LostCapture() {
679 if (delegate_)
680 delegate_->LostCapture();
681}
682
683bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
684 bool* is_keyboard_shortcut) {
685 return delegate_ &&
686 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
687}
688
689void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
690 if (delegate_)
691 delegate_->HandleKeyboardEvent(event);
692}
693
[email protected]32ded2212011-11-10 18:51:43694void TabContents::HandleMouseDown() {
695 if (delegate_)
696 delegate_->HandleMouseDown();
697}
698
[email protected]63954792011-07-11 04:17:48699void TabContents::HandleMouseUp() {
700 if (delegate_)
701 delegate_->HandleMouseUp();
702}
703
704void TabContents::HandleMouseActivate() {
705 if (delegate_)
706 delegate_->HandleMouseActivate();
707}
708
[email protected]8a5e0ca2011-08-25 06:30:47709void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
710 if (delegate_)
711 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
712}
713
[email protected]5d5f7af2011-10-01 01:38:12714bool TabContents::IsFullscreenForCurrentTab() const {
715 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
716}
717
[email protected]e9621112011-10-17 05:38:37718void TabContents::RequestToLockMouse() {
719 if (delegate_) {
720 delegate_->RequestToLockMouse(this);
721 } else {
722 GotResponseToLockMouseRequest(false);
723 }
724}
725
726void TabContents::LostMouseLock() {
727 if (delegate_)
728 delegate_->LostMouseLock();
729}
730
[email protected]0548c5352011-09-07 00:33:33731void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
732 if (delegate_)
733 delegate_->UpdatePreferredSize(this, pref_size);
734}
735
[email protected]32ded2212011-11-10 18:51:43736void TabContents::WebUISend(RenderViewHost* render_view_host,
737 const GURL& source_url,
738 const std::string& name,
739 const base::ListValue& args) {
740 if (delegate_)
741 delegate_->WebUISend(this, source_url, name, args);
742}
743
[email protected]00c37fc2011-08-02 00:22:50744// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25745TabContents* TabContents::OpenURL(const GURL& url,
746 const GURL& referrer,
747 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58748 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10749 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
750 DCHECK(referrer.is_empty());
[email protected]bce1f1c2011-12-05 15:11:58751 return OpenURL(OpenURLParams(url, content::Referrer(), disposition,
752 transition, false));
[email protected]00c37fc2011-08-02 00:22:50753}
754
755TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49756 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50757 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49758 // Notify observers.
[email protected]d8c660432011-12-22 20:51:25759 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50760 DidOpenURL(params.url, params.referrer,
761 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25762 return new_contents;
[email protected]1c642b52011-04-15 09:05:49763 }
[email protected]992e4542011-07-20 23:09:25764 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34765}
766
[email protected]1ccb3568d2010-02-19 10:51:16767bool TabContents::NavigateToPendingEntry(
768 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27769 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54770}
[email protected]96d185d2009-04-24 03:28:54771
[email protected]876bc832010-09-07 16:29:54772bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27773 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54774 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40775 // The renderer will reject IPC messages with URLs longer than
776 // this limit, so don't attempt to navigate with a longer URL.
[email protected]dd11de52011-11-03 22:54:27777 if (entry.url().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40778 return false;
779
[email protected]dd11de52011-11-03 22:54:27780 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40781 if (!dest_render_view_host)
782 return false; // Unable to create the desired render view host.
783
[email protected]80a8fad2011-01-29 04:02:38784 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07785 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58786 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56787 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30788 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]dd11de52011-11-03 22:54:27789 entry.url());
[email protected]32ded2212011-11-10 18:51:43790#if defined(OS_CHROMEOS)
791 is_allowed_in_web_ui_renderer |= entry.url().SchemeIs(chrome::kDataScheme);
792#endif
[email protected]e091df82011-10-11 18:13:21793 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55794 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58795
[email protected]96d185d2009-04-24 03:28:54796 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44797 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52798 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44799 dest_render_view_host,
800 entry.url());
[email protected]96d185d2009-04-24 03:28:54801
802 // Used for page load time metrics.
803 current_load_start_ = base::TimeTicks::Now();
804
805 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34806 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27807 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47808 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34809 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54810
[email protected]dd11de52011-11-03 22:54:27811 if (entry.page_id() == -1) {
[email protected]96d185d2009-04-24 03:28:54812 // HACK!! This code suppresses javascript: URLs from being added to
813 // session history, which is what we want to do for javascript: URLs that
814 // do not generate content. What we really need is a message from the
815 // renderer telling us that a new page was not created. The same message
816 // could be used for mailto: URLs and the like.
[email protected]dd11de52011-11-03 22:54:27817 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54818 return false;
819 }
820
[email protected]3c9e1872010-11-18 16:17:49821 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25822 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04823 observers_,
[email protected]dd11de52011-11-03 22:54:27824 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54825
[email protected]09b29342011-06-24 19:18:48826 if (delegate_)
827 delegate_->DidNavigateToPendingEntry(this);
828
[email protected]d5f942ba2008-09-26 19:30:34829 return true;
830}
831
[email protected]9e1ad4b2011-08-14 16:49:19832void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
833 int history_length,
834 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41835 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
836 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19837 if (render_manager_.pending_render_view_host()) {
838 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14839 return;
[email protected]9e1ad4b2011-08-14 16:49:19840 }
[email protected]151a63d2011-12-20 22:32:52841 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19842 if (!rvh) {
843 NOTREACHED();
844 return;
845 }
846 if (site_instance && rvh->site_instance() != site_instance) {
847 NOTREACHED();
848 return;
849 }
850 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
851 history_length,
852 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14853}
854
[email protected]90daadb42009-06-08 21:27:28855void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27856 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54857 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
858 return;
859 }
[email protected]151a63d2011-12-20 22:32:52860 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54861}
862
[email protected]0bfbf882011-12-22 18:19:27863bool TabContents::ShowingInterstitialPage() const {
864 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54865}
866
[email protected]0bfbf882011-12-22 18:19:27867InterstitialPage* TabContents::GetInterstitialPage() const {
868 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22869}
870
[email protected]c7dd2f62011-07-18 15:57:59871void TabContents::OnSavePage() {
872 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27873 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30874 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59875 const GURL& current_page_url = GetURL();
876 if (dlm && current_page_url.is_valid()) {
877 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46878 download_stats::RecordDownloadCount(
879 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59880 return;
881 }
882 }
883
884 Stop();
885
886 // Create the save package and possibly prompt the user for the name to save
887 // the page as. The user prompt is an asynchronous operation that runs on
888 // another thread.
889 save_package_ = new SavePackage(this);
890 save_package_->GetSaveInfo();
891}
892
893// Used in automated testing to bypass prompting the user for file names.
894// Instead, the names and paths are hard coded rather than running them through
895// file name sanitation and extension / mime checking.
896bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
897 SavePackage::SavePackageType save_type) {
898 // Stop the page from navigating.
899 Stop();
900
901 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
902 return save_package_->Init();
903}
904
[email protected]420ae012009-04-24 05:16:32905bool TabContents::IsActiveEntry(int32 page_id) {
906 NavigationEntry* active_entry = controller_.GetActiveEntry();
907 return (active_entry != NULL &&
908 active_entry->site_instance() == GetSiteInstance() &&
909 active_entry->page_id() == page_id);
910}
911
[email protected]0bfbf882011-12-22 18:19:27912const std::string& TabContents::GetContentsMimeType() const {
913 return contents_mime_type_;
914}
915
916bool TabContents::WillNotifyDisconnection() const {
917 return notify_disconnection_;
918}
919
[email protected]b2fe07d12010-02-09 14:38:08920void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31921 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52922 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
923 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16924}
925
[email protected]b2fe07d12010-02-09 14:38:08926void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31927 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52928 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
929 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16930}
931
[email protected]0bfbf882011-12-22 18:19:27932content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
933 return &renderer_preferences_;
934}
935
936void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
937 new_tab_start_time_ = time;
938}
939
940base::TimeTicks TabContents::GetNewTabStartTime() const {
941 return new_tab_start_time_;
942}
943
[email protected]7ab1e7d62009-10-14 23:32:01944void TabContents::OnCloseStarted() {
945 if (tab_close_start_time_.is_null())
946 tab_close_start_time_ = base::TimeTicks::Now();
947}
948
[email protected]46624bf2010-06-09 16:04:19949bool TabContents::ShouldAcceptDragAndDrop() const {
950#if defined(OS_CHROMEOS)
951 // ChromeOS panels (pop-ups) do not take drag-n-drop.
952 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51953 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20954 return false;
955 return true;
[email protected]46624bf2010-06-09 16:04:19956#else
957 return true;
958#endif
959}
960
[email protected]7813bd72011-02-05 02:19:34961void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52962 if (GetRenderViewHost())
963 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51964 if (delegate_)
965 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34966}
967
[email protected]0bfbf882011-12-22 18:19:27968void TabContents::SetClosedByUserGesture(bool value) {
969 closed_by_user_gesture_ = value;
970}
971
972bool TabContents::GetClosedByUserGesture() const {
973 return closed_by_user_gesture_;
974}
975
[email protected]d0b8d092010-10-25 04:05:17976double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:30977 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25978 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17979 return 0;
[email protected]b75b8292010-10-01 07:28:25980
981 double zoom_level;
982 if (temporary_zoom_settings_) {
983 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:52984 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:25985 } else {
[email protected]2ae88d12011-10-14 09:11:19986 GURL url;
[email protected]f5fa20e2011-12-21 22:35:56987 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:19988 // Since zoom map is updated using rewritten URL, use rewritten URL
989 // to get the zoom level.
990 url = active_entry ? active_entry->url() : GURL::EmptyGURL();
991 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25992 }
[email protected]d0b8d092010-10-25 04:05:17993 return zoom_level;
994}
[email protected]b75b8292010-10-01 07:28:25995
[email protected]d0b8d092010-10-25 04:05:17996int TabContents::GetZoomPercent(bool* enable_increment,
997 bool* enable_decrement) {
998 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:01999 // Calculate the zoom percent from the factor. Round up to the nearest whole
1000 // number.
[email protected]b75b8292010-10-01 07:28:251001 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011002 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251003 *enable_decrement = percent > minimum_zoom_percent_;
1004 *enable_increment = percent < maximum_zoom_percent_;
1005 return percent;
1006}
1007
[email protected]3c733bde2010-12-21 19:56:311008void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501009 if (!delegate_)
1010 return;
1011
[email protected]f5fa20e2011-12-21 22:35:561012 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501013 if (!active_entry)
1014 return;
1015
1016 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121017}
1018
[email protected]932b7a12011-03-09 12:50:271019void TabContents::ViewFrameSource(const GURL& url,
1020 const std::string& content_state) {
1021 if (!delegate_)
1022 return;
1023
1024 delegate_->ViewSourceForFrame(this, url, content_state);
1025}
1026
[email protected]0bfbf882011-12-22 18:19:271027int TabContents::GetMinimumZoomPercent() const {
1028 return minimum_zoom_percent_;
1029}
1030
1031int TabContents::GetMaximumZoomPercent() const {
1032 return maximum_zoom_percent_;
1033}
1034
1035int TabContents::GetContentRestrictions() const {
1036 return content_restrictions_;
1037}
1038
1039WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1040 return content::WebUIFactory::Get()->GetWebUIType(GetBrowserContext(),
1041 GetURL());
1042}
1043
1044WebUI* TabContents::GetWebUIForCurrentState() {
1045 // When there is a pending navigation entry, we want to use the pending WebUI
1046 // that goes along with it to control the basic flags. For example, we want to
1047 // show the pending URL in the URL bar, so we want the display_url flag to
1048 // be from the pending entry.
1049 //
1050 // The confusion comes because there are multiple possibilities for the
1051 // initial load in a tab as a side effect of the way the RenderViewHostManager
1052 // works.
1053 //
1054 // - For the very first tab the load looks "normal". The new tab Web UI is
1055 // the pending one, and we want it to apply here.
1056 //
1057 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1058 // get switched to the one previously associated with the new tab pages.
1059 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1060 // have a committed Web UI in this case.
1061 //
1062 // This condition handles all of these cases:
1063 //
1064 // - First load in first tab: no committed nav entry + pending nav entry +
1065 // pending dom ui:
1066 // -> Use pending Web UI if any.
1067 //
1068 // - First load in second tab: no committed nav entry + pending nav entry +
1069 // no pending Web UI:
1070 // -> Use the committed Web UI if any.
1071 //
1072 // - Second navigation in any tab: committed nav entry + pending nav entry:
1073 // -> Use pending Web UI if any.
1074 //
1075 // - Normal state with no load: committed nav entry + no pending nav entry:
1076 // -> Use committed Web UI.
1077 if (controller_.pending_entry() &&
1078 (controller_.GetLastCommittedEntry() ||
1079 render_manager_.pending_web_ui()))
1080 return render_manager_.pending_web_ui();
1081 return render_manager_.web_ui();
1082}
1083
1084bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1085 return GetRenderViewHost() ?
1086 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1087}
1088
1089bool TabContents::FocusLocationBarByDefault() {
1090 WebUI* web_ui = GetWebUIForCurrentState();
1091 if (web_ui)
1092 return web_ui->focus_location_bar_by_default();
1093 NavigationEntry* entry = controller_.GetActiveEntry();
1094 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
1095 return true;
1096 return false;
1097}
1098
1099void TabContents::SetFocusToLocationBar(bool select_all) {
1100 if (delegate_)
1101 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211102}
1103
[email protected]8b5af492011-11-28 21:50:581104void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301105 const string16& type,
1106 const string16& href,
1107 const string16& title,
1108 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511109 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301110 this, action, type, href, title, disposition);
1111}
1112
[email protected]678105012011-12-09 04:01:211113void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301114 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001115 WebIntentsDispatcherImpl* intents_dispatcher =
1116 new WebIntentsDispatcherImpl(this, intent, intent_id);
1117 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301118}
1119
[email protected]724159a2010-12-30 01:11:181120void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1121 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591122 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181123 const GURL& url) {
1124 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1125 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521126 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301127 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181128
[email protected]8093a542011-05-13 07:29:321129 RenderViewHost* rvh =
1130 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521131 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101132 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251133 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101134 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321135 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101136
[email protected]724159a2010-12-30 01:11:181137 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591138 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251139 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591140 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181141 }
1142}
1143
1144void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591145 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181146 const GURL& source_url,
1147 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491148 // TODO(creis): Remove this method and have the pre-rendering code listen to
1149 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1150 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:181151 NavigationEntry* entry;
1152 if (page_id == -1)
1153 entry = controller_.pending_entry();
1154 else
1155 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1156 if (!entry || entry->url() != source_url)
1157 return;
[email protected]e7d50892011-01-19 21:47:381158
[email protected]4850a7f2011-03-08 23:36:591159 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251160 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261161 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591162 opener_url));
[email protected]724159a2010-12-30 01:11:181163}
1164
1165void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581166 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1167 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1168 << ", error_code: " << params.error_code
1169 << ", error_description: " << params.error_description
1170 << ", is_main_frame: " << params.is_main_frame
1171 << ", showing_repost_interstitial: " <<
1172 params.showing_repost_interstitial
1173 << ", frame_id: " << params.frame_id;
1174 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521175 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301176 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181177
[email protected]d7b175e2011-10-11 15:31:581178 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181179 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1180 // This means that the interstitial won't be torn down properly, which is
1181 // bad. But if we have an interstitial, go back to another tab type, and
1182 // then load the same interstitial again, we could end up getting the first
1183 // interstitial's "failed" message (as a result of the cancel) when we're on
1184 // the second one.
1185 //
1186 // We can't tell this apart, so we think we're tearing down the current page
1187 // which will cause a crash later one. There is also some code in
1188 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1189 // out because of this problem.
1190 //
1191 // http://code.google.com/p/chromium/issues/detail?id=2855
1192 // Because this will not tear down the interstitial properly, if "back" is
1193 // back to another tab type, the interstitial will still be somewhat alive
1194 // in the previous tab type. If you navigate somewhere that activates the
1195 // tab with the interstitial again, you'll see a flash before the new load
1196 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271197 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181198 LOG(WARNING) << "Discarding message during interstitial.";
1199 return;
1200 }
1201
[email protected]02102f82011-06-13 20:37:021202 // Discard our pending entry if the load canceled (e.g. if we decided to
1203 // download the file instead of load it). We do not verify that the URL
1204 // being canceled matches the pending entry's URL because they will not
1205 // match if a redirect occurred (in which case we do not want to leave a
1206 // stale redirect URL showing). This means that we also cancel the pending
1207 // entry if the user started a new navigation. As a result, the navigation
1208 // controller may not remember that a load is in progress, but the
1209 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181210 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021211 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161212 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181213
[email protected]151a63d2011-12-20 22:32:521214 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181215 }
1216
1217 // Send out a notification that we failed a provisional load with an error.
1218 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581219 params.is_main_frame,
1220 controller_.IsURLInPageNavigation(validated_url),
1221 validated_url,
1222 std::string(),
1223 false,
1224 params.frame_id);
1225 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181226
[email protected]ad50def52011-10-19 23:17:071227 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271228 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531229 content::Source<NavigationController>(&controller_),
1230 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101231
[email protected]d8c660432011-12-22 20:51:251232 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581233 observers_,
1234 DidFailProvisionalLoad(params.frame_id,
1235 params.is_main_frame,
1236 validated_url,
1237 params.error_code,
1238 params.error_description));
[email protected]724159a2010-12-30 01:11:181239}
1240
1241void TabContents::OnDidLoadResourceFromMemoryCache(
1242 const GURL& url,
[email protected]70435962011-08-02 20:13:281243 const std::string& security_info,
1244 const std::string& http_method,
1245 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191246 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181247 cache.Increment();
1248
1249 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081250 int cert_id = 0;
1251 net::CertStatus cert_status = 0;
1252 int security_bits = -1;
1253 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181254 SSLManager::DeserializeSecurityInfo(security_info,
1255 &cert_id, &cert_status,
1256 &security_bits,
1257 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301258 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161259 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181260
[email protected]ad50def52011-10-19 23:17:071261 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271262 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531263 content::Source<NavigationController>(&controller_),
1264 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181265}
1266
1267void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381268 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181269 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561270 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181271}
1272
1273void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021274 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231275 LOG(INFO) << security_origin << " ran insecure content from "
1276 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381277 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051278 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381279 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051280 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1281 }
[email protected]724159a2010-12-30 01:11:181282 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411283 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561284 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181285}
1286
1287void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1288 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251289 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101290 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181291}
1292
[email protected]1a55c5be2011-11-29 11:36:311293void TabContents::OnDidFinishLoad(
1294 int64 frame_id,
1295 const GURL& validated_url,
1296 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251297 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311298 DidFinishLoad(frame_id, validated_url, is_main_frame));
1299}
1300
1301void TabContents::OnDidFailLoadWithError(int64 frame_id,
1302 const GURL& validated_url,
1303 bool is_main_frame,
1304 int error_code,
1305 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251306 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311307 DidFailLoad(frame_id, validated_url, is_main_frame,
1308 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181309}
1310
[email protected]c8f73ab2011-01-22 00:05:171311void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271312 content_restrictions_ = restrictions;
1313 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171314}
1315
[email protected]216813952011-05-19 22:21:261316void TabContents::OnGoToEntryAtOffset(int offset) {
1317 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1318 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1319 if (!entry)
1320 return;
1321 // Note that we don't call NavigationController::GotToOffset() as we don't
1322 // want to create a pending navigation entry (it might end up lingering
1323 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581324 entry->set_transition_type(
1325 content::PageTransitionFromInt(
1326 entry->transition_type() |
1327 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271328 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571329
1330 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1331 // it in now that we know. This allows us to find the entry when it commits.
1332 if (!entry->site_instance() &&
1333 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381334 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571335 }
[email protected]216813952011-05-19 22:21:261336 }
1337}
1338
1339void TabContents::OnUpdateZoomLimits(int minimum_percent,
1340 int maximum_percent,
1341 bool remember) {
1342 minimum_zoom_percent_ = minimum_percent;
1343 maximum_zoom_percent_ = maximum_percent;
1344 temporary_zoom_settings_ = !remember;
1345}
1346
[email protected]0bfbf882011-12-22 18:19:271347void TabContents::OnSaveURL(const GURL& url) {
1348 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1349 dlm->DownloadUrl(url, GetURL(), "", this);
1350}
1351
[email protected]3a29a6e2011-08-24 18:26:211352void TabContents::OnEnumerateDirectory(int request_id,
1353 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511354 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211355}
1356
[email protected]7d189022011-08-25 22:54:201357void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511358 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201359}
1360
1361void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1362 const GURL& url,
1363 const string16& title) {
[email protected]6934a702011-12-20 00:04:511364 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201365}
1366
[email protected]b888919c2011-09-02 00:32:161367void TabContents::OnFindReply(int request_id,
1368 int number_of_matches,
1369 const gfx::Rect& selection_rect,
1370 int active_match_ordinal,
1371 bool final_update) {
[email protected]6934a702011-12-20 00:04:511372 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1373 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001374 // Send a notification to the renderer that we are ready to receive more
1375 // results from the scoping effort of the Find operation. The FindInPage
1376 // scoping is asynchronous and periodically sends results back up to the
1377 // browser using IPC. In an effort to not spam the browser we have the
1378 // browser send an ACK for each FindReply message and have the renderer
1379 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521380 GetRenderViewHost()->Send(
1381 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161382}
1383
[email protected]d952a052011-09-06 18:42:451384void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511385 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451386}
1387
[email protected]7fc4bbb2011-09-08 21:23:101388void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1389 bool blocked_by_policy) {
1390 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251391 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101392 AppCacheAccessed(manifest_url, blocked_by_policy));
1393}
1394
[email protected]96d185d2009-04-24 03:28:541395// Notifies the RenderWidgetHost instance about the fact that the page is
1396// loading, or done loading and calls the base implementation.
1397void TabContents::SetIsLoading(bool is_loading,
1398 LoadNotificationDetails* details) {
1399 if (is_loading == is_loading_)
1400 return;
1401
1402 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211403 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541404 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561405 upload_size_ = 0;
1406 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541407 }
1408
1409 render_manager_.SetIsLoading(is_loading);
1410
1411 is_loading_ = is_loading;
1412 waiting_for_response_ = is_loading;
1413
[email protected]6ebdc9b2010-09-27 16:55:571414 if (delegate_)
1415 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351416 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541417
[email protected]432115822011-07-10 15:52:271418 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1419 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071420 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541421 if (details)
[email protected]6c2381d2011-10-19 02:52:531422 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071423 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531424 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541425 det);
1426}
1427
[email protected]420ae012009-04-24 05:16:321428void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131429 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321430 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561431 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381432 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441433 // that opened the window, as long as both renderers have the same
1434 // privileges.
[email protected]1fd1a502011-03-30 16:55:561435 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1436 WebUI* web_ui = content::GetContentClient()->browser()->
1437 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581438 // web_ui might be NULL if the URL refers to a non-existent extension.
1439 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401440 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521441 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441442 }
1443 }
[email protected]1fd1a502011-03-30 16:55:561444 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441445 }
1446
[email protected]4e697b042011-07-08 06:44:561447 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321448 // Clear the status bubble. This is a workaround for a bug where WebKit
1449 // doesn't let us know that the cursor left an element during a
1450 // transition (this is also why the mouse cursor remains as a hand after
1451 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1452 // clear the bubble when a user navigates to a named anchor in the same
1453 // page.
1454 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321455 }
1456
[email protected]a6e82fc2010-02-24 22:28:141457 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471458 // Once the main frame is navigated, we're no longer considered to have
1459 // displayed insecure content.
1460 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171461 }
[email protected]ce5c4502009-05-06 16:46:111462
[email protected]3c9e1872010-11-18 16:17:491463 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251464 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041465 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321466}
1467
1468void TabContents::DidNavigateAnyFramePostCommit(
1469 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131470 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321471 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071472 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321473 // a malicious script from spamming messages, since the script could just
1474 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551475 if (dialog_creator_) {
1476 dialog_creator_->ResetJavaScriptState(this);
1477 dialog_creator_ = NULL;
1478 }
[email protected]420ae012009-04-24 05:16:321479
[email protected]3c9e1872010-11-18 16:17:491480 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251481 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041482 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321483}
1484
[email protected]74ce1ad2011-12-16 21:51:461485void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1486 // If we are creating a RVH for a restored controller, then we need to make
1487 // sure the RenderView starts with a next_page_id_ larger than the number
1488 // of restored entries. This must be called before the RenderView starts
1489 // navigating (to avoid a race between the browser updating max_page_id and
1490 // the renderer updating next_page_id_). Because of this, we only call this
1491 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]420ae012009-04-24 05:16:321492 int max_restored_page_id = controller_.max_restored_page_id();
[email protected]74ce1ad2011-12-16 21:51:461493 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1494 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321495}
1496
[email protected]6b2f7a82011-04-25 19:30:511497bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571498 const string16& title) {
[email protected]420ae012009-04-24 05:16:321499 // For file URLs without a title, use the pathname instead. In the case of a
1500 // synthesized title, we don't want the update to count toward the "one set
1501 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511502 string16 final_title;
[email protected]420ae012009-04-24 05:16:321503 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091504 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511505 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321506 explicit_set = false; // Don't count synthetic titles toward the set limit.
1507 } else {
[email protected]acafd272011-07-26 17:35:571508 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321509 explicit_set = true;
1510 }
1511
[email protected]987fc3a2011-05-26 14:18:091512 // If a page is created via window.open and never navigated,
1513 // there will be no navigation entry. In this situation,
1514 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1515 if (entry) {
1516 if (final_title == entry->title())
1517 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321518
[email protected]987fc3a2011-05-26 14:18:091519 entry->set_title(final_title);
1520 } else {
1521 if (page_title_when_no_navigation_entry_ == final_title)
1522 return false; // Nothing changed, don't bother.
1523
1524 page_title_when_no_navigation_entry_ = final_title;
1525 }
[email protected]420ae012009-04-24 05:16:321526
[email protected]420ae012009-04-24 05:16:321527 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231528 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321529
[email protected]105bb0f2011-05-24 17:12:141530 TitleUpdatedDetails details(entry, explicit_set);
1531
[email protected]ad50def52011-10-19 23:17:071532 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271533 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531534 content::Source<TabContents>(this),
1535 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041536
[email protected]420ae012009-04-24 05:16:321537 return true;
1538}
1539
1540void TabContents::NotifySwapped() {
1541 // After sending out a swap notification, we need to send a disconnect
1542 // notification so that clients that pick up a pointer to |this| can NULL the
1543 // pointer. See Bug 1230284.
1544 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071545 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271546 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531547 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071548 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321549}
1550
1551void TabContents::NotifyConnected() {
1552 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071553 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271554 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531555 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071556 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321557}
1558
1559void TabContents::NotifyDisconnected() {
1560 if (!notify_disconnection_)
1561 return;
1562
1563 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071564 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271565 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531566 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071567 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321568}
1569
[email protected]8d3347f2009-07-09 22:00:211570RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321571 return view_.get();
1572}
1573
[email protected]8d3347f2009-07-09 22:00:211574RenderViewHostDelegate::RendererManagement*
1575TabContents::GetRendererManagementDelegate() {
1576 return &render_manager_;
1577}
1578
[email protected]daf82f82011-10-31 22:35:311579content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371580 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461581 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511582}
1583
[email protected]57c6a652009-05-04 07:58:341584TabContents* TabContents::GetAsTabContents() {
1585 return this;
1586}
1587
[email protected]da4dfc42011-10-12 15:53:561588content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431589 return view_type_;
[email protected]7b291f92009-08-14 05:43:531590}
1591
[email protected]420ae012009-04-24 05:16:321592void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071593 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271594 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531595 content::Source<TabContents>(this),
1596 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321597 NavigationEntry* entry = controller_.GetActiveEntry();
1598 if (!entry)
1599 return;
1600
1601 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351602 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561603 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581604 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321605
1606 if (entry->IsViewSourceMode()) {
1607 // Put the renderer in view source mode.
1608 render_view_host->Send(
1609 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1610 }
[email protected]0666aef2009-05-13 19:48:081611
[email protected]d487beefe2011-12-21 05:41:211612 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261613
1614 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251615 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321616}
1617
1618void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521619 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321620 // Don't notify the world, since this came from a renderer in the
1621 // background.
1622 return;
1623 }
1624
1625 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311626 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231627 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301628
1629 // Restore the focus to the tab (otherwise the focus will be on the top
1630 // window).
[email protected]484ae5912010-09-29 19:16:141631 if (was_crashed && !FocusLocationBarByDefault() &&
1632 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301633 Focus();
[email protected]484ae5912010-09-29 19:16:141634 }
[email protected]32ded2212011-11-10 18:51:431635
[email protected]d8c660432011-12-22 20:51:251636 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321637}
1638
[email protected]443b80e2010-12-14 00:42:231639void TabContents::RenderViewGone(RenderViewHost* rvh,
1640 base::TerminationStatus status,
1641 int error_code) {
[email protected]151a63d2011-12-20 22:32:521642 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321643 // The pending page's RenderViewHost is gone.
1644 return;
1645 }
1646
1647 SetIsLoading(false, NULL);
1648 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231649 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311650 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321651
[email protected]d8c660432011-12-22 20:51:251652 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271653 observers_,
[email protected]be1f56ab2011-12-22 06:55:311654 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321655}
1656
[email protected]2e4633c2009-07-09 16:58:061657void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481658 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251659 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061660}
1661
[email protected]420ae012009-04-24 05:16:321662void TabContents::DidNavigate(RenderViewHost* rvh,
1663 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581664 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321665 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371666
[email protected]420ae012009-04-24 05:16:321667 // Update the site of the SiteInstance if it doesn't have one yet.
1668 if (!GetSiteInstance()->has_site())
1669 GetSiteInstance()->SetSite(params.url);
1670
1671 // Need to update MIME type here because it's referred to in
1672 // UpdateNavigationCommands() called by RendererDidNavigate() to
1673 // determine whether or not to enable the encoding menu.
1674 // It's updated only for the main frame. For a subframe,
1675 // RenderView::UpdateURL does not set params.contents_mime_type.
1676 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1677 // TODO(jungshik): Add a test for the encoding menu to avoid
1678 // regressing it again.
[email protected]2905f742011-10-13 03:51:581679 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321680 contents_mime_type_ = params.contents_mime_type;
1681
[email protected]8286f51a2011-05-31 17:39:131682 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001683 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391684
[email protected]a9c0bfe2010-09-17 08:35:221685 // Send notification about committed provisional loads. This notification is
1686 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1687 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081688 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071689 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1690 // that is not recorded in the navigation history. For the purpose of
1691 // tracking navigation events, we treat this event as a sub frame navigation
1692 // event.
1693 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581694 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221695 // Whether or not a page transition was triggered by going backward or
1696 // forward in the history is only stored in the navigation controller's
1697 // entry list.
1698 if (did_navigate &&
1699 (controller_.GetActiveEntry()->transition_type() &
[email protected]2905f742011-10-13 03:51:581700 content::PAGE_TRANSITION_FORWARD_BACK)) {
1701 transition_type = content::PageTransitionFromInt(
1702 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221703 }
[email protected]0d60f0192011-04-14 12:40:101704 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251705 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101706 DidCommitProvisionalLoadForFrame(params.frame_id,
1707 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221708 }
1709
[email protected]76543b92009-08-31 17:27:451710 if (!did_navigate)
1711 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321712
1713 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1714 // for the appropriate notification (best) or you can add it to
1715 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1716 // necessary, please).
1717
1718 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001719 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321720 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511721 if (delegate_)
1722 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001723 }
[email protected]420ae012009-04-24 05:16:321724 DidNavigateAnyFramePostCommit(rvh, details, params);
1725}
1726
1727void TabContents::UpdateState(RenderViewHost* rvh,
1728 int32 page_id,
1729 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151730 // Ensure that this state update comes from either the active RVH or one of
1731 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521732 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321733
1734 // We must be prepared to handle state updates for any page, these occur
1735 // when the user is scrolling and entering form data, as well as when we're
1736 // leaving a page, in which case our state may have already been moved to
1737 // the next page. The navigation controller will look up the appropriate
1738 // NavigationEntry and update it when it is notified via the delegate.
1739
1740 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151741 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321742 if (entry_index < 0)
1743 return;
1744 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1745
1746 if (state == entry->content_state())
1747 return; // Nothing to update.
1748 entry->set_content_state(state);
1749 controller_.NotifyEntryChanged(entry, entry_index);
1750}
1751
1752void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571753 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461754 const string16& title,
1755 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321756 // If we have a title, that's a pretty good indication that we've started
1757 // getting useful data.
1758 SetNotWaitingForResponse();
1759
[email protected]151a63d2011-12-20 22:32:521760 DCHECK(rvh == GetRenderViewHost());
[email protected]371cc8b2010-09-01 16:03:481761 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581762 page_id);
[email protected]987fc3a2011-05-26 14:18:091763
[email protected]a49e10b2011-08-01 23:57:461764 // TODO(evan): make use of title_direction.
1765 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091766 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321767 return;
1768
1769 // Broadcast notifications when the UI should be updated.
1770 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031771 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321772}
1773
[email protected]420ae012009-04-24 05:16:321774void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401775 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311776 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321777}
1778
1779void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511780 if (delegate_)
1781 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321782}
1783
[email protected]420ae012009-04-24 05:16:321784void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291785 // The UI may be in an event-tracking loop, such as between the
1786 // mouse-down and mouse-up in text selection or a button click.
1787 // Defer the close until after tracking is complete, so that we
1788 // don't free objects out from under the UI.
1789 // TODO(shess): This could probably be integrated with the
1790 // IsDoingDrag() test below. Punting for now because I need more
1791 // research to understand how this impacts platforms other than Mac.
1792 // TODO(shess): This could get more fine-grained. For instance,
1793 // closing a tab in another window while selecting text in the
1794 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211795 if (GetView()->IsEventTracking()) {
1796 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291797 return;
1798 }
1799
[email protected]24a4d1062009-07-10 23:10:421800 // If we close the tab while we're in the middle of a drag, we'll crash.
1801 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211802 if (GetView()->IsDoingDrag()) {
1803 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421804 return;
1805 }
1806
[email protected]420ae012009-04-24 05:16:321807 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521808 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511809 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321810}
1811
[email protected]cd9ed79d2011-11-15 19:22:571812void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521813 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511814 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571815}
1816
[email protected]420ae012009-04-24 05:16:321817void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511818 if (delegate_ && delegate_->IsPopupOrPanel(this))
1819 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321820}
1821
[email protected]7ab1e7d62009-10-14 23:32:011822void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321823 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491824
[email protected]6934a702011-12-20 00:04:511825 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211826 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511827 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001828 }
[email protected]3c9e1872010-11-18 16:17:491829
1830 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251831 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321832}
1833
[email protected]7ab1e7d62009-10-14 23:32:011834void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321835 scoped_ptr<LoadNotificationDetails> details;
1836
1837 NavigationEntry* entry = controller_.GetActiveEntry();
1838 // An entry may not exist for a stop when loading an initial blank page or
1839 // if an iframe injected by script into a blank page finishes loading.
1840 if (entry) {
[email protected]420ae012009-04-24 05:16:321841 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1842
1843 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541844 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321845 entry->transition_type(),
1846 elapsed,
1847 &controller_,
1848 controller_.GetCurrentEntryIndex()));
1849 }
1850
[email protected]420ae012009-04-24 05:16:321851 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491852
1853 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251854 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321855}
1856
[email protected]c95fa8b2011-04-28 20:26:161857void TabContents::DidCancelLoading() {
1858 controller_.DiscardNonCommittedEntries();
1859
1860 // Update the URL display.
1861 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1862}
1863
[email protected]1a3c3cb2010-12-16 21:03:401864void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511865 if (delegate_)
1866 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401867}
1868
[email protected]952a68e2011-11-17 00:36:101869void TabContents::DocumentAvailableInMainFrame(
1870 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251871 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101872 DocumentAvailableInMainFrame());
1873}
1874
[email protected]25497492010-09-11 15:15:081875void TabContents::DocumentOnLoadCompletedInMainFrame(
1876 RenderViewHost* render_view_host,
1877 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071878 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271879 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531880 content::Source<TabContents>(this),
1881 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081882}
1883
[email protected]ae5184d62011-10-06 19:25:581884void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151885 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581886 WindowOpenDisposition disposition,
1887 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481888 // Delegate to RequestTransferURL because this is just the generic
1889 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581890 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481891 GlobalRequestID());
1892}
1893
1894void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581895 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481896 WindowOpenDisposition disposition,
1897 int64 source_frame_id,
1898 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581899 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581900 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581901 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351902 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321903 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1904 // generated suggestions).
1905 //
[email protected]e0112912011-02-02 22:54:351906 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161907 // want web sites to see a referrer of "chrome://blah" (and some
1908 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321909 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581910 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481911 render_manager_.web_ui()->link_transition_type(),
1912 false /* is_renderer_initiated */);
1913 params.transferred_global_request_id = old_request_id;
1914 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581915 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321916 } else {
[email protected]4ad5d77d2011-12-03 02:00:481917 OpenURLParams params(url, referrer, disposition,
1918 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1919 params.transferred_global_request_id = old_request_id;
1920 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581921 }
1922 if (new_contents) {
1923 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251924 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581925 DidOpenRequestedURL(new_contents,
1926 url,
1927 referrer,
1928 disposition,
1929 transition_type,
1930 source_frame_id));
[email protected]420ae012009-04-24 05:16:321931 }
1932}
1933
[email protected]420ae012009-04-24 05:16:321934void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151935 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411936 const string16& message,
1937 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321938 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471939 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321940 IPC::Message* reply_msg,
1941 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071942 // Suppress JavaScript dialogs when requested. Also suppress messages when
1943 // showing an interstitial as it's shown over the previous page and we don't
1944 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501945 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151946 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271947 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071948 !delegate_ ||
1949 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321950
1951 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341952 content::JavaScriptDialogCreator::TitleType title_type;
1953 string16 title;
1954
1955 if (!frame_url.has_host()) {
1956 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1957 } else {
1958 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1959 title = net::FormatUrl(
1960 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201961 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301962 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341963 }
1964
[email protected]2e5b90c2011-08-16 21:11:551965 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1966 dialog_creator_->RunJavaScriptDialog(this,
1967 title_type,
1968 title,
[email protected]269f86d2011-12-07 02:43:471969 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551970 message,
1971 default_prompt,
1972 reply_msg,
1973 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321974 }
[email protected]3ab9cb82011-06-03 18:02:071975
1976 if (suppress_this_message) {
1977 // If we are suppressing messages, just reply as if the user immediately
1978 // pressed "Cancel".
1979 OnDialogClosed(reply_msg, false, string16());
1980 }
1981
1982 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321983}
1984
[email protected]992db4c2011-05-12 15:37:151985void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411986 const string16& message,
[email protected]420ae012009-04-24 05:16:321987 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:511988 if (delegate_)
1989 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071990
1991 bool suppress_this_message =
1992 rvh->is_swapped_out() ||
1993 !delegate_ ||
1994 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151995 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:521996 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501997 return;
1998 }
[email protected]3ab9cb82011-06-03 18:02:071999
[email protected]7ab1e7d62009-10-14 23:32:012000 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552001 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2002 dialog_creator_->RunBeforeUnloadDialog(this,
2003 message,
2004 reply_msg);
[email protected]420ae012009-04-24 05:16:322005}
2006
[email protected]420ae012009-04-24 05:16:322007WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082008 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362009 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522010 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082011
[email protected]b8299c12011-06-03 19:52:282012 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212013 // chrome-devtools: pages (unless it's specifically allowed).
2014 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572015 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282016 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302017 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2018 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212019 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082020 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432021 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082022 }
2023
2024 return web_prefs;
[email protected]420ae012009-04-24 05:16:322025}
2026
[email protected]7d472472011-01-22 01:30:252027void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272028 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252029 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222030
2031 ResourceDispatcherHost* rdh =
2032 content::GetContentClient()->browser()->GetResourceDispatcherHost();
2033 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:302034 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252035}
2036
[email protected]fa1cf0b82010-01-15 21:49:442037void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442038 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252039 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442040}
2041
[email protected]420ae012009-04-24 05:16:322042void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2043 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152044 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522045 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152046 return;
2047
[email protected]e5fc1632011-08-08 07:51:532048 // Ignore renderer unresponsive event if debugger is attached to the tab
2049 // since the event may be a result of the renderer sitting on a breakpoint.
2050 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442051 DevToolsAgentHost* agent =
2052 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2053 if (agent &&
2054 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532055 return;
2056
[email protected]420ae012009-04-24 05:16:322057 if (is_during_unload) {
2058 // Hang occurred while firing the beforeunload/unload handler.
2059 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112060 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322061
2062 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2063 return;
2064
2065 // If the tab hangs in the beforeunload/unload handler there's really
2066 // nothing we can do to recover. Pretend the unload listeners have
2067 // all fired and close the tab. If the hang is in the beforeunload handler
2068 // then the user will not have the option of cancelling the close.
2069 Close(rvh);
2070 return;
2071 }
2072
[email protected]151a63d2011-12-20 22:32:522073 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472074 return;
2075
[email protected]6934a702011-12-20 00:04:512076 if (delegate_)
2077 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322078}
2079
2080void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512081 if (delegate_)
2082 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322083}
2084
2085void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212086 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562087 uint64 upload_position,
2088 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322089 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562090 upload_position_ = upload_position;
2091 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502092 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202093 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302094 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212095 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322096 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:512097 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:502098 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322099}
2100
[email protected]7d472472011-01-22 01:30:252101void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512102 if (delegate_)
2103 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252104}
2105
[email protected]420ae012009-04-24 05:16:322106void TabContents::BeforeUnloadFiredFromRenderManager(
2107 bool proceed,
2108 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512109 if (delegate_)
2110 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322111}
2112
[email protected]3a3d47472010-07-15 21:03:542113void TabContents::DidStartLoadingFromRenderManager(
2114 RenderViewHost* render_view_host) {
2115 DidStartLoading();
2116}
2117
2118void TabContents::RenderViewGoneFromRenderManager(
2119 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232120 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2121 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542122}
2123
[email protected]420ae012009-04-24 05:16:322124void TabContents::UpdateRenderViewSizeForRenderManager() {
2125 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262126 gfx::Size size = view_->GetContainerSize();
2127 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2128 // here during container initialization and normal window size will be set
2129 // later. In case of tab duplication this resizing to 0x0 prevents setting
2130 // normal size later so just ignore it.
2131 if (!size.IsEmpty())
2132 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322133}
2134
[email protected]3a3d47472010-07-15 21:03:542135void TabContents::NotifySwappedFromRenderManager() {
2136 NotifySwapped();
2137}
2138
2139NavigationController& TabContents::GetControllerForRenderManager() {
[email protected]f5fa20e2011-12-21 22:35:562140 return GetController();
[email protected]3a3d47472010-07-15 21:03:542141}
2142
[email protected]d0980792011-02-13 19:41:402143WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562144 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322145}
2146
2147NavigationEntry*
2148TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2149 return controller_.GetLastCommittedEntry();
2150}
2151
2152bool TabContents::CreateRenderViewForRenderManager(
2153 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442154 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322155 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522156
[email protected]420ae012009-04-24 05:16:322157 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442158 if (rwh_view)
2159 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322160
[email protected]74ce1ad2011-12-16 21:51:462161 // Make sure we use the correct starting page_id in the new RenderView.
2162 UpdateMaxPageIDIfNecessary(render_view_host);
2163 int32 max_page_id =
2164 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2165
2166 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522167 return false;
2168
[email protected]e60c0232011-11-11 19:56:352169#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502170 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2171 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442172 if (rwh_view) {
2173 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2174 render_widget_host->WasResized();
2175 }
[email protected]f8233cc2011-05-31 20:24:502176#endif
2177
[email protected]420ae012009-04-24 05:16:322178 return true;
2179}
2180
[email protected]3ab9cb82011-06-03 18:02:072181void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2182 bool success,
2183 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542184 if (is_showing_before_unload_dialog_ && !success) {
2185 // If a beforeunload dialog is canceled, we need to stop the throbber from
2186 // spinning, since we forced it to start spinning in Navigate.
2187 DidStopLoading();
2188
2189 tab_close_start_time_ = base::TimeTicks();
2190 }
2191 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522192 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542193}
2194
[email protected]0b08add2011-11-29 03:27:062195gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072196 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542197}
2198
[email protected]a1e97f02011-06-30 14:04:342199void TabContents::OnDialogShown() {
2200 Activate();
[email protected]3a3d47472010-07-15 21:03:542201}
2202
[email protected]be1f56ab2011-12-22 06:55:312203void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122204 encoding_ = content::GetContentClient()->browser()->
2205 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102206}
[email protected]f45d2a72010-03-08 23:28:352207
[email protected]33f74972010-12-08 16:40:362208void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212209 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442210 // Can be NULL during tests.
2211 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212212 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362213}