blob: 327f407e23dd7a1c03ad4dec84d92a8788d66094 [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"
31#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]ea049a02011-12-25 21:37:09115using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25116using content::WebContentsObserver;
[email protected]0e12d7d2011-12-01 16:21:44117
[email protected]420ae012009-04-24 05:16:32118namespace {
119
120// Amount of time we wait between when a key event is received and the renderer
121// is queried for its state and pushed to the NavigationEntry.
122const int kQueryStateDelay = 5000;
123
[email protected]6ebdc9b2010-09-27 16:55:57124const int kSyncWaitDelay = 40;
125
[email protected]ca406032011-07-19 21:53:05126static const char kDotGoogleDotCom[] = ".google.com";
127
[email protected]420ae012009-04-24 05:16:32128#if defined(OS_WIN)
129
130BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
131 // Note: erase is required to properly paint some widgets borders. This can
132 // be seen with textfields.
133 InvalidateRect(hwnd, NULL, TRUE);
134 return TRUE;
135}
136#endif
137
[email protected]2c5569662011-03-22 20:45:02138ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]3d7474ff2011-07-27 17:47:37139 content::BrowserContext* browser_context, const NavigationEntry& entry,
[email protected]1ccb3568d2010-02-19 10:51:16140 NavigationController::ReloadType reload_type) {
141 switch (reload_type) {
142 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02143 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16144 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02145 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16146 case NavigationController::NO_RELOAD:
147 break; // Fall through to rest of function.
148 }
[email protected]5e369672009-11-03 23:48:30149
150 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37151 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02152 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30153
[email protected]2c5569662011-03-22 20:45:02154 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30155}
156
[email protected]876bc832010-09-07 16:29:54157void MakeNavigateParams(const NavigationEntry& entry,
158 const NavigationController& controller,
[email protected]674bc592011-12-20 23:00:42159 content::WebContentsDelegate* delegate,
[email protected]1ccb3568d2010-02-19 10:51:16160 NavigationController::ReloadType reload_type,
161 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51162 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54163 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00164 params->current_history_list_offset = controller.last_committed_entry_index();
165 params->current_history_list_length = controller.entry_count();
[email protected]36fc0392011-12-25 03:59:51166 params->url = entry.GetURL();
167 params->referrer = entry.GetReferrer();
168 params->transition = entry.GetTransitionType();
169 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00170 params->navigation_type =
[email protected]3d7474ff2011-07-27 17:47:37171 GetNavigationType(controller.browser_context(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34172 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47173 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48174 params->transferred_request_child_id =
175 entry.transferred_global_request_id().child_id;
176 params->transferred_request_request_id =
177 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47178
179 if (delegate)
180 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34181}
182
[email protected]420ae012009-04-24 05:16:32183} // namespace
184
[email protected]f4f50ef2011-01-21 19:01:19185
186// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32187
[email protected]3d7474ff2011-07-27 17:47:37188TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32189 SiteInstance* site_instance,
190 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07191 const TabContents* base_tab_contents,
192 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42193 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07194 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37195 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13196 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32197 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22198 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34199 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23200 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
201 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34202 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21203 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56204 upload_size_(0),
205 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47206 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57207 capturing_contents_(false),
208 is_being_destroyed_(false),
209 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55210 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57211#if defined(OS_WIN)
212 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
213#endif
[email protected]7ab1e7d62009-10-14 23:32:01214 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56215 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38216 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25217 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01218 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25219 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01220 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00221 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43222 content_restrictions_(0),
223 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37224 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32225
[email protected]34ac70502009-09-25 17:07:23226 // We have the initial size of the view be based on the size of the passed in
227 // tab contents (normally a tab from the same window).
228 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21229 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00230
231#if defined(ENABLE_JAVA_BRIDGE)
232 java_bridge_dispatcher_host_manager_.reset(
233 new JavaBridgeDispatcherHostManager(this));
234#endif
[email protected]332af7732009-03-11 13:21:35235}
initial.commit09911bf2008-07-26 23:55:29236
237TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32238 is_being_destroyed_ = true;
239
[email protected]3ab9cb82011-06-03 18:02:07240 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55241 if (dialog_creator_)
242 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07243
[email protected]420ae012009-04-24 05:16:32244 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32245
[email protected]420ae012009-04-24 05:16:32246 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07247 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09248 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
249 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07250 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32251
252 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07253#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32254 // If we still have a window handle, destroy it. GetNativeView can return
255 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42256 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52257 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44258 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42259 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42260 }
[email protected]420ae012009-04-24 05:16:32261#endif
[email protected]7ab1e7d62009-10-14 23:32:01262
263 // OnCloseStarted isn't called in unit tests.
264 if (!tab_close_start_time_.is_null()) {
265 UMA_HISTOGRAM_TIMES("Tab.Close",
266 base::TimeTicks::Now() - tab_close_start_time_);
267 }
[email protected]b5a1d11c2011-02-17 03:09:42268
[email protected]d8c660432011-12-22 20:51:25269 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08270
[email protected]6934a702011-12-20 00:04:51271 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42272}
273
[email protected]724159a2010-12-30 01:11:18274bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]be1f56ab2011-12-22 06:55:31275 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17276 return true;
277
[email protected]d8c660432011-12-22 20:51:25278 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
279 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10280 while ((observer = it.GetNext()) != NULL)
281 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53282 return true;
[email protected]403415a2011-01-10 18:57:53283
[email protected]724159a2010-12-30 01:11:18284 bool handled = true;
285 bool message_is_ok = true;
286 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58287 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
288 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24289 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
290 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18291 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
292 OnDidStartProvisionalLoadForFrame)
293 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
294 OnDidRedirectProvisionalLoad)
295 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
296 OnDidFailProvisionalLoadWithError)
297 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
298 OnDidLoadResourceFromMemoryCache)
299 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
300 OnDidDisplayInsecureContent)
301 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
302 OnDidRunInsecureContent)
303 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
304 OnDocumentLoadedInFrame)
305 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17306 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
307 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25308 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26309 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59310 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21311 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20312 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
313 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
314 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16315 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45316 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10317 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18318 IPC_MESSAGE_UNHANDLED(handled = false)
319 IPC_END_MESSAGE_MAP_EX()
320
321 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38322 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18323 GetRenderProcessHost()->ReceivedBadMessage();
324 }
325
326 return handled;
327}
328
[email protected]6c2e472f2011-08-24 23:26:18329void TabContents::RunFileChooser(
330 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23331 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51332 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18333}
334
[email protected]f5fa20e2011-12-21 22:35:56335NavigationController& TabContents::GetController() {
336 return controller_;
337}
338
339const NavigationController& TabContents::GetController() const {
340 return controller_;
341}
342
[email protected]627e0512011-12-21 22:55:30343content::BrowserContext* TabContents::GetBrowserContext() const {
344 return controller_.browser_context();
345}
346
[email protected]f5fa20e2011-12-21 22:35:56347void TabContents::SetViewType(content::ViewType type) {
348 view_type_ = type;
349}
350
[email protected]ea049a02011-12-25 21:37:09351content::ViewType TabContents::GetViewType() const {
352 return view_type_;
353}
354
[email protected]be1f56ab2011-12-22 06:55:31355const GURL& TabContents::GetURL() const {
356 // We may not have a navigation entry yet
357 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51358 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31359}
360
361
362const base::PropertyBag* TabContents::GetPropertyBag() const {
363 return &property_bag_;
364}
365
366base::PropertyBag* TabContents::GetPropertyBag() {
367 return &property_bag_;
368}
369
370content::WebContentsDelegate* TabContents::GetDelegate() {
371 return delegate_;
372}
373
374void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
375 // TODO(cbentzel): remove this debugging code?
376 if (delegate == delegate_)
377 return;
378 if (delegate_)
379 delegate_->Detach(this);
380 delegate_ = delegate;
381 if (delegate_)
382 delegate_->Attach(this);
383}
384
[email protected]f3b1a082011-11-18 00:34:30385content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03386 if (render_manager_.current_host())
387 return render_manager_.current_host()->process();
388 else
389 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16390}
391
[email protected]be1f56ab2011-12-22 06:55:31392RenderViewHost* TabContents::GetRenderViewHost() const {
393 return render_manager_.current_host();
394}
395
396RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
397 return render_manager_.GetRenderWidgetHostView();
398}
399
400TabContentsView* TabContents::GetView() const {
401 return view_.get();
402}
403
404WebUI* TabContents::GetWebUI() const {
405 return render_manager_.web_ui() ? render_manager_.web_ui()
406 : render_manager_.pending_web_ui();
407}
408
409WebUI* TabContents::GetCommittedWebUI() const {
410 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34411}
412
[email protected]96d185d2009-04-24 03:28:54413const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55414 // Transient entries take precedence. They are used for interstitial pages
415 // that are shown on top of existing pages.
416 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08417 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20418 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30419 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23420 if (entry) {
[email protected]b5cca982011-05-26 04:42:08421 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23422 }
[email protected]7ade2732011-02-10 00:13:58423 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
424 render_manager_.pending_web_ui() : render_manager_.web_ui();
425 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54426 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55427 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54428 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35429 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58430 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54431 if (!title.empty())
432 return title;
433 }
434 }
435
436 // We use the title for the last committed entry rather than a pending
437 // navigation entry. For example, when the user types in a URL, we want to
438 // keep the old page's title until the new load has committed and we get a new
439 // title.
[email protected]96d185d2009-04-24 03:28:54440 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23441 if (entry) {
[email protected]b5cca982011-05-26 04:42:08442 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23443 }
[email protected]987fc3a2011-05-26 14:18:09444
445 // |page_title_when_no_navigation_entry_| is finally used
446 // if no title cannot be retrieved.
447 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54448}
449
[email protected]d5f942ba2008-09-26 19:30:34450int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46451 return GetMaxPageIDForSiteInstance(GetSiteInstance());
452}
453
454int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
455 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
456 max_page_ids_[site_instance->id()] = -1;
457
458 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34459}
460
461void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46462 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
463}
464
465void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
466 int32 page_id) {
467 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
468 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34469}
470
[email protected]96d185d2009-04-24 03:28:54471SiteInstance* TabContents::GetSiteInstance() const {
472 return render_manager_.current_host()->site_instance();
473}
474
[email protected]77362eb2011-08-01 17:18:38475SiteInstance* TabContents::GetPendingSiteInstance() const {
476 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
477 render_manager_.pending_render_view_host() :
478 render_manager_.current_host();
479 return dest_rvh->site_instance();
480}
481
[email protected]be1f56ab2011-12-22 06:55:31482bool TabContents::IsLoading() const {
483 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49484}
485
[email protected]be1f56ab2011-12-22 06:55:31486bool TabContents::IsWaitingForResponse() const {
487 return waiting_for_response_;
488}
489
490const net::LoadStateWithParam& TabContents::GetLoadState() const {
491 return load_state_;
492}
493
494const string16& TabContents::GetLoadStateHost() const {
495 return load_state_host_;
496}
497
498uint64 TabContents::GetUploadSize() const {
499 return upload_size_;
500}
501
502uint64 TabContents::GetUploadPosition() const {
503 return upload_position_;
504}
505
506const std::string& TabContents::GetEncoding() const {
507 return encoding_;
508}
509
510bool TabContents::DisplayedInsecureContent() const {
511 return displayed_insecure_content_;
512}
513
514void TabContents::SetCapturingContents(bool cap) {
515 capturing_contents_ = cap;
516}
517
518bool TabContents::IsCrashed() const {
519 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
520 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
521 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49522}
523
[email protected]443b80e2010-12-14 00:42:23524void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
525 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34526 return;
527
[email protected]443b80e2010-12-14 00:42:23528 crashed_status_ = status;
529 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50530 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34531}
532
[email protected]be1f56ab2011-12-22 06:55:31533base::TerminationStatus TabContents::GetCrashedStatus() const {
534 return crashed_status_;
535}
536
537bool TabContents::IsBeingDestroyed() const {
538 return is_being_destroyed_;
539}
540
[email protected]d5f942ba2008-09-26 19:30:34541void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
542 if (delegate_)
543 delegate_->NavigationStateChanged(this, changed_flags);
544}
545
[email protected]96d185d2009-04-24 03:28:54546void TabContents::DidBecomeSelected() {
547 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16548 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
549 if (rwhv) {
550 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43551#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16552 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43553#endif
554 }
[email protected]96d185d2009-04-24 03:28:54555
[email protected]5ac20162010-11-24 23:33:11556 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38557
[email protected]d8c660432011-12-22 20:51:25558 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54559}
560
[email protected]be1f56ab2011-12-22 06:55:31561
562base::TimeTicks TabContents::GetLastSelectedTime() const {
563 return last_selected_time_;
564}
565
[email protected]96d185d2009-04-24 03:28:54566void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31567 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52568 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
569 // open a tab in then background, then closes the tab before selecting it.
570 // This is because closing the tab calls TabContents::Destroy(), which
571 // removes the |GetRenderViewHost()|; then when we actually destroy the
572 // window, OnWindowPosChanged() notices and calls HideContents() (which
573 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16574 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
575 if (rwhv)
576 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54577 }
578
[email protected]ad50def52011-10-19 23:17:07579 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09580 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
581 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07582 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54583}
584
[email protected]be1f56ab2011-12-22 06:55:31585void TabContents::ShowContents() {
586 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
587 if (rwhv)
588 rwhv->DidBecomeSelected();
589}
590
591void TabContents::HideContents() {
592 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
593 // our superclass HideContents(), because some callers want to be very picky
594 // about the order in which these get called. In addition to making the code
595 // here practically impossible to understand, this also means we end up
596 // calling TabContents::WasHidden() twice if callers call both versions of
597 // HideContents() on a TabContents.
598 WasHidden();
599}
600
601bool TabContents::NeedToFireBeforeUnload() {
602 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27603 return WillNotifyDisconnection() &&
604 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31605 !GetRenderViewHost()->SuddenTerminationAllowed();
606}
607
608RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
609 return &render_manager_;
610}
611
[email protected]0bfbf882011-12-22 18:19:27612void TabContents::Stop() {
613 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25614 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27615}
616
617TabContents* TabContents::Clone() {
618 // We create a new SiteInstance so that the new tab won't share processes
619 // with the old one. This can be changed in the future if we need it to share
620 // processes for some reason.
621 TabContents* tc = new TabContents(
622 GetBrowserContext(),
623 SiteInstance::CreateSiteInstance(GetBrowserContext()),
624 MSG_ROUTING_NONE, this, NULL);
625 tc->GetController().CopyStateFrom(controller_);
626 return tc;
627}
628
629void TabContents::ShowPageInfo(const GURL& url,
630 const NavigationEntry::SSLStatus& ssl,
631 bool show_history) {
632 if (!delegate_)
633 return;
634
635 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
636}
637
638void TabContents::AddNewContents(TabContents* new_contents,
639 WindowOpenDisposition disposition,
640 const gfx::Rect& initial_pos,
641 bool user_gesture) {
642 if (!delegate_)
643 return;
644
645 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
646 user_gesture);
647}
648
649gfx::NativeView TabContents::GetContentNativeView() const {
650 return view_->GetContentNativeView();
651}
652
653gfx::NativeView TabContents::GetNativeView() const {
654 return view_->GetNativeView();
655}
656
657void TabContents::GetContainerBounds(gfx::Rect* out) const {
658 view_->GetContainerBounds(out);
659}
660
661void TabContents::Focus() {
662 view_->Focus();
663}
664
[email protected]d8c660432011-12-22 20:51:25665void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31666 observers_.AddObserver(observer);
667}
668
[email protected]d8c660432011-12-22 20:51:25669void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31670 observers_.RemoveObserver(observer);
671}
672
[email protected]d5f942ba2008-09-26 19:30:34673void TabContents::Activate() {
674 if (delegate_)
675 delegate_->ActivateContents(this);
676}
677
[email protected]ea42e7782010-08-23 23:58:12678void TabContents::Deactivate() {
679 if (delegate_)
680 delegate_->DeactivateContents(this);
681}
682
[email protected]63954792011-07-11 04:17:48683void TabContents::LostCapture() {
684 if (delegate_)
685 delegate_->LostCapture();
686}
687
688bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
689 bool* is_keyboard_shortcut) {
690 return delegate_ &&
691 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
692}
693
694void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
695 if (delegate_)
696 delegate_->HandleKeyboardEvent(event);
697}
698
[email protected]32ded2212011-11-10 18:51:43699void TabContents::HandleMouseDown() {
700 if (delegate_)
701 delegate_->HandleMouseDown();
702}
703
[email protected]63954792011-07-11 04:17:48704void TabContents::HandleMouseUp() {
705 if (delegate_)
706 delegate_->HandleMouseUp();
707}
708
709void TabContents::HandleMouseActivate() {
710 if (delegate_)
711 delegate_->HandleMouseActivate();
712}
713
[email protected]8a5e0ca2011-08-25 06:30:47714void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
715 if (delegate_)
716 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
717}
718
[email protected]5d5f7af2011-10-01 01:38:12719bool TabContents::IsFullscreenForCurrentTab() const {
720 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
721}
722
[email protected]e9621112011-10-17 05:38:37723void TabContents::RequestToLockMouse() {
724 if (delegate_) {
725 delegate_->RequestToLockMouse(this);
726 } else {
727 GotResponseToLockMouseRequest(false);
728 }
729}
730
731void TabContents::LostMouseLock() {
732 if (delegate_)
733 delegate_->LostMouseLock();
734}
735
[email protected]0548c5352011-09-07 00:33:33736void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
737 if (delegate_)
738 delegate_->UpdatePreferredSize(this, pref_size);
739}
740
[email protected]32ded2212011-11-10 18:51:43741void TabContents::WebUISend(RenderViewHost* render_view_host,
742 const GURL& source_url,
743 const std::string& name,
744 const base::ListValue& args) {
745 if (delegate_)
746 delegate_->WebUISend(this, source_url, name, args);
747}
748
[email protected]00c37fc2011-08-02 00:22:50749// TODO(adriansc): Remove this method once refactoring changed all call sites.
[email protected]992e4542011-07-20 23:09:25750TabContents* TabContents::OpenURL(const GURL& url,
751 const GURL& referrer,
752 WindowOpenDisposition disposition,
[email protected]2905f742011-10-13 03:51:58753 content::PageTransition transition) {
[email protected]39c90bb2011-12-02 15:44:10754 // For specifying a referrer, use the version of OpenURL taking OpenURLParams.
755 DCHECK(referrer.is_empty());
[email protected]bce1f1c2011-12-05 15:11:58756 return OpenURL(OpenURLParams(url, content::Referrer(), disposition,
757 transition, false));
[email protected]00c37fc2011-08-02 00:22:50758}
759
760TabContents* TabContents::OpenURL(const OpenURLParams& params) {
[email protected]1c642b52011-04-15 09:05:49761 if (delegate_) {
[email protected]00c37fc2011-08-02 00:22:50762 TabContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]1c642b52011-04-15 09:05:49763 // Notify observers.
[email protected]d8c660432011-12-22 20:51:25764 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]00c37fc2011-08-02 00:22:50765 DidOpenURL(params.url, params.referrer,
766 params.disposition, params.transition));
[email protected]992e4542011-07-20 23:09:25767 return new_contents;
[email protected]1c642b52011-04-15 09:05:49768 }
[email protected]992e4542011-07-20 23:09:25769 return NULL;
[email protected]d5f942ba2008-09-26 19:30:34770}
771
[email protected]1ccb3568d2010-02-19 10:51:16772bool TabContents::NavigateToPendingEntry(
773 NavigationController::ReloadType reload_type) {
[email protected]dd11de52011-11-03 22:54:27774 return NavigateToEntry(*controller_.pending_entry(), reload_type);
[email protected]876bc832010-09-07 16:29:54775}
[email protected]96d185d2009-04-24 03:28:54776
[email protected]876bc832010-09-07 16:29:54777bool TabContents::NavigateToEntry(
[email protected]dd11de52011-11-03 22:54:27778 const NavigationEntry& entry,
[email protected]876bc832010-09-07 16:29:54779 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40780 // The renderer will reject IPC messages with URLs longer than
781 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51782 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40783 return false;
784
[email protected]dd11de52011-11-03 22:54:27785 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40786 if (!dest_render_view_host)
787 return false; // Unable to create the desired render view host.
788
[email protected]80a8fad2011-01-29 04:02:38789 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07790 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58791 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56792 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30793 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51794 entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43795#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51796 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43797#endif
[email protected]e091df82011-10-11 18:13:21798 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55799 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58800
[email protected]96d185d2009-04-24 03:28:54801 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44802 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52803 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44804 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51805 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54806
807 // Used for page load time metrics.
808 current_load_start_ = base::TimeTicks::Now();
809
810 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34811 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27812 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47813 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34814 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54815
[email protected]36fc0392011-12-25 03:59:51816 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54817 // HACK!! This code suppresses javascript: URLs from being added to
818 // session history, which is what we want to do for javascript: URLs that
819 // do not generate content. What we really need is a message from the
820 // renderer telling us that a new page was not created. The same message
821 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51822 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54823 return false;
824 }
825
[email protected]3c9e1872010-11-18 16:17:49826 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25827 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04828 observers_,
[email protected]36fc0392011-12-25 03:59:51829 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54830
[email protected]09b29342011-06-24 19:18:48831 if (delegate_)
832 delegate_->DidNavigateToPendingEntry(this);
833
[email protected]d5f942ba2008-09-26 19:30:34834 return true;
835}
836
[email protected]9e1ad4b2011-08-14 16:49:19837void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
838 int history_length,
839 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41840 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
841 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19842 if (render_manager_.pending_render_view_host()) {
843 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14844 return;
[email protected]9e1ad4b2011-08-14 16:49:19845 }
[email protected]151a63d2011-12-20 22:32:52846 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19847 if (!rvh) {
848 NOTREACHED();
849 return;
850 }
851 if (site_instance && rvh->site_instance() != site_instance) {
852 NOTREACHED();
853 return;
854 }
855 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
856 history_length,
857 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14858}
859
[email protected]90daadb42009-06-08 21:27:28860void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27861 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54862 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
863 return;
864 }
[email protected]151a63d2011-12-20 22:32:52865 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54866}
867
[email protected]0bfbf882011-12-22 18:19:27868bool TabContents::ShowingInterstitialPage() const {
869 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54870}
871
[email protected]0bfbf882011-12-22 18:19:27872InterstitialPage* TabContents::GetInterstitialPage() const {
873 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22874}
875
[email protected]c7dd2f62011-07-18 15:57:59876void TabContents::OnSavePage() {
877 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27878 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30879 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59880 const GURL& current_page_url = GetURL();
881 if (dlm && current_page_url.is_valid()) {
882 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46883 download_stats::RecordDownloadCount(
884 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59885 return;
886 }
887 }
888
889 Stop();
890
891 // Create the save package and possibly prompt the user for the name to save
892 // the page as. The user prompt is an asynchronous operation that runs on
893 // another thread.
894 save_package_ = new SavePackage(this);
895 save_package_->GetSaveInfo();
896}
897
898// Used in automated testing to bypass prompting the user for file names.
899// Instead, the names and paths are hard coded rather than running them through
900// file name sanitation and extension / mime checking.
901bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
902 SavePackage::SavePackageType save_type) {
903 // Stop the page from navigating.
904 Stop();
905
906 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
907 return save_package_->Init();
908}
909
[email protected]420ae012009-04-24 05:16:32910bool TabContents::IsActiveEntry(int32 page_id) {
911 NavigationEntry* active_entry = controller_.GetActiveEntry();
912 return (active_entry != NULL &&
913 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51914 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32915}
916
[email protected]0bfbf882011-12-22 18:19:27917const std::string& TabContents::GetContentsMimeType() const {
918 return contents_mime_type_;
919}
920
921bool TabContents::WillNotifyDisconnection() const {
922 return notify_disconnection_;
923}
924
[email protected]b2fe07d12010-02-09 14:38:08925void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31926 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52927 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
928 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16929}
930
[email protected]b2fe07d12010-02-09 14:38:08931void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31932 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52933 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
934 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16935}
936
[email protected]0bfbf882011-12-22 18:19:27937content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
938 return &renderer_preferences_;
939}
940
941void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
942 new_tab_start_time_ = time;
943}
944
945base::TimeTicks TabContents::GetNewTabStartTime() const {
946 return new_tab_start_time_;
947}
948
[email protected]7ab1e7d62009-10-14 23:32:01949void TabContents::OnCloseStarted() {
950 if (tab_close_start_time_.is_null())
951 tab_close_start_time_ = base::TimeTicks::Now();
952}
953
[email protected]46624bf2010-06-09 16:04:19954bool TabContents::ShouldAcceptDragAndDrop() const {
955#if defined(OS_CHROMEOS)
956 // ChromeOS panels (pop-ups) do not take drag-n-drop.
957 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51958 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20959 return false;
960 return true;
[email protected]46624bf2010-06-09 16:04:19961#else
962 return true;
963#endif
964}
965
[email protected]7813bd72011-02-05 02:19:34966void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52967 if (GetRenderViewHost())
968 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51969 if (delegate_)
970 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34971}
972
[email protected]0bfbf882011-12-22 18:19:27973void TabContents::SetClosedByUserGesture(bool value) {
974 closed_by_user_gesture_ = value;
975}
976
977bool TabContents::GetClosedByUserGesture() const {
978 return closed_by_user_gesture_;
979}
980
[email protected]d0b8d092010-10-25 04:05:17981double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:30982 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25983 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17984 return 0;
[email protected]b75b8292010-10-01 07:28:25985
986 double zoom_level;
987 if (temporary_zoom_settings_) {
988 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:52989 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:25990 } else {
[email protected]2ae88d12011-10-14 09:11:19991 GURL url;
[email protected]f5fa20e2011-12-21 22:35:56992 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:19993 // Since zoom map is updated using rewritten URL, use rewritten URL
994 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:51995 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:19996 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:25997 }
[email protected]d0b8d092010-10-25 04:05:17998 return zoom_level;
999}
[email protected]b75b8292010-10-01 07:28:251000
[email protected]d0b8d092010-10-25 04:05:171001int TabContents::GetZoomPercent(bool* enable_increment,
1002 bool* enable_decrement) {
1003 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011004 // Calculate the zoom percent from the factor. Round up to the nearest whole
1005 // number.
[email protected]b75b8292010-10-01 07:28:251006 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011007 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251008 *enable_decrement = percent > minimum_zoom_percent_;
1009 *enable_increment = percent < maximum_zoom_percent_;
1010 return percent;
1011}
1012
[email protected]3c733bde2010-12-21 19:56:311013void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501014 if (!delegate_)
1015 return;
1016
[email protected]f5fa20e2011-12-21 22:35:561017 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501018 if (!active_entry)
1019 return;
1020
[email protected]36fc0392011-12-25 03:59:511021 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121022}
1023
[email protected]932b7a12011-03-09 12:50:271024void TabContents::ViewFrameSource(const GURL& url,
1025 const std::string& content_state) {
1026 if (!delegate_)
1027 return;
1028
1029 delegate_->ViewSourceForFrame(this, url, content_state);
1030}
1031
[email protected]0bfbf882011-12-22 18:19:271032int TabContents::GetMinimumZoomPercent() const {
1033 return minimum_zoom_percent_;
1034}
1035
1036int TabContents::GetMaximumZoomPercent() const {
1037 return maximum_zoom_percent_;
1038}
1039
1040int TabContents::GetContentRestrictions() const {
1041 return content_restrictions_;
1042}
1043
1044WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1045 return content::WebUIFactory::Get()->GetWebUIType(GetBrowserContext(),
1046 GetURL());
1047}
1048
1049WebUI* TabContents::GetWebUIForCurrentState() {
1050 // When there is a pending navigation entry, we want to use the pending WebUI
1051 // that goes along with it to control the basic flags. For example, we want to
1052 // show the pending URL in the URL bar, so we want the display_url flag to
1053 // be from the pending entry.
1054 //
1055 // The confusion comes because there are multiple possibilities for the
1056 // initial load in a tab as a side effect of the way the RenderViewHostManager
1057 // works.
1058 //
1059 // - For the very first tab the load looks "normal". The new tab Web UI is
1060 // the pending one, and we want it to apply here.
1061 //
1062 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1063 // get switched to the one previously associated with the new tab pages.
1064 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1065 // have a committed Web UI in this case.
1066 //
1067 // This condition handles all of these cases:
1068 //
1069 // - First load in first tab: no committed nav entry + pending nav entry +
1070 // pending dom ui:
1071 // -> Use pending Web UI if any.
1072 //
1073 // - First load in second tab: no committed nav entry + pending nav entry +
1074 // no pending Web UI:
1075 // -> Use the committed Web UI if any.
1076 //
1077 // - Second navigation in any tab: committed nav entry + pending nav entry:
1078 // -> Use pending Web UI if any.
1079 //
1080 // - Normal state with no load: committed nav entry + no pending nav entry:
1081 // -> Use committed Web UI.
1082 if (controller_.pending_entry() &&
1083 (controller_.GetLastCommittedEntry() ||
1084 render_manager_.pending_web_ui()))
1085 return render_manager_.pending_web_ui();
1086 return render_manager_.web_ui();
1087}
1088
1089bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1090 return GetRenderViewHost() ?
1091 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1092}
1093
1094bool TabContents::FocusLocationBarByDefault() {
1095 WebUI* web_ui = GetWebUIForCurrentState();
1096 if (web_ui)
1097 return web_ui->focus_location_bar_by_default();
1098 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511099 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271100 return true;
1101 return false;
1102}
1103
1104void TabContents::SetFocusToLocationBar(bool select_all) {
1105 if (delegate_)
1106 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211107}
1108
[email protected]8b5af492011-11-28 21:50:581109void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301110 const string16& type,
1111 const string16& href,
1112 const string16& title,
1113 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511114 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301115 this, action, type, href, title, disposition);
1116}
1117
[email protected]678105012011-12-09 04:01:211118void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301119 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001120 WebIntentsDispatcherImpl* intents_dispatcher =
1121 new WebIntentsDispatcherImpl(this, intent, intent_id);
1122 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301123}
1124
[email protected]724159a2010-12-30 01:11:181125void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1126 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591127 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181128 const GURL& url) {
1129 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1130 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521131 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301132 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181133
[email protected]8093a542011-05-13 07:29:321134 RenderViewHost* rvh =
1135 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521136 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101137 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251138 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101139 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321140 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101141
[email protected]724159a2010-12-30 01:11:181142 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591143 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251144 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591145 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181146 }
1147}
1148
1149void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591150 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181151 const GURL& source_url,
1152 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491153 // TODO(creis): Remove this method and have the pre-rendering code listen to
1154 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1155 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:181156 NavigationEntry* entry;
1157 if (page_id == -1)
1158 entry = controller_.pending_entry();
1159 else
1160 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511161 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181162 return;
[email protected]e7d50892011-01-19 21:47:381163
[email protected]4850a7f2011-03-08 23:36:591164 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261166 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591167 opener_url));
[email protected]724159a2010-12-30 01:11:181168}
1169
1170void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581171 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1172 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1173 << ", error_code: " << params.error_code
1174 << ", error_description: " << params.error_description
1175 << ", is_main_frame: " << params.is_main_frame
1176 << ", showing_repost_interstitial: " <<
1177 params.showing_repost_interstitial
1178 << ", frame_id: " << params.frame_id;
1179 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521180 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301181 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181182
[email protected]d7b175e2011-10-11 15:31:581183 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181184 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1185 // This means that the interstitial won't be torn down properly, which is
1186 // bad. But if we have an interstitial, go back to another tab type, and
1187 // then load the same interstitial again, we could end up getting the first
1188 // interstitial's "failed" message (as a result of the cancel) when we're on
1189 // the second one.
1190 //
1191 // We can't tell this apart, so we think we're tearing down the current page
1192 // which will cause a crash later one. There is also some code in
1193 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1194 // out because of this problem.
1195 //
1196 // http://code.google.com/p/chromium/issues/detail?id=2855
1197 // Because this will not tear down the interstitial properly, if "back" is
1198 // back to another tab type, the interstitial will still be somewhat alive
1199 // in the previous tab type. If you navigate somewhere that activates the
1200 // tab with the interstitial again, you'll see a flash before the new load
1201 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271202 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181203 LOG(WARNING) << "Discarding message during interstitial.";
1204 return;
1205 }
1206
[email protected]02102f82011-06-13 20:37:021207 // Discard our pending entry if the load canceled (e.g. if we decided to
1208 // download the file instead of load it). We do not verify that the URL
1209 // being canceled matches the pending entry's URL because they will not
1210 // match if a redirect occurred (in which case we do not want to leave a
1211 // stale redirect URL showing). This means that we also cancel the pending
1212 // entry if the user started a new navigation. As a result, the navigation
1213 // controller may not remember that a load is in progress, but the
1214 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:181215 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:021216 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:161217 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181218
[email protected]151a63d2011-12-20 22:32:521219 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181220 }
1221
1222 // Send out a notification that we failed a provisional load with an error.
1223 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581224 params.is_main_frame,
1225 controller_.IsURLInPageNavigation(validated_url),
1226 validated_url,
1227 std::string(),
1228 false,
1229 params.frame_id);
1230 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181231
[email protected]ad50def52011-10-19 23:17:071232 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271233 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]6c2381d2011-10-19 02:52:531234 content::Source<NavigationController>(&controller_),
1235 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101236
[email protected]d8c660432011-12-22 20:51:251237 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581238 observers_,
1239 DidFailProvisionalLoad(params.frame_id,
1240 params.is_main_frame,
1241 validated_url,
1242 params.error_code,
1243 params.error_description));
[email protected]724159a2010-12-30 01:11:181244}
1245
1246void TabContents::OnDidLoadResourceFromMemoryCache(
1247 const GURL& url,
[email protected]70435962011-08-02 20:13:281248 const std::string& security_info,
1249 const std::string& http_method,
1250 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191251 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181252 cache.Increment();
1253
1254 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081255 int cert_id = 0;
1256 net::CertStatus cert_status = 0;
1257 int security_bits = -1;
1258 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181259 SSLManager::DeserializeSecurityInfo(security_info,
1260 &cert_id, &cert_status,
1261 &security_bits,
1262 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301263 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161264 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181265
[email protected]ad50def52011-10-19 23:17:071266 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271267 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]6c2381d2011-10-19 02:52:531268 content::Source<NavigationController>(&controller_),
1269 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181270}
1271
1272void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381273 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181274 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561275 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181276}
1277
1278void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021279 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231280 LOG(INFO) << security_origin << " ran insecure content from "
1281 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381282 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051283 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381284 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051285 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1286 }
[email protected]724159a2010-12-30 01:11:181287 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411288 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561289 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181290}
1291
1292void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1293 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251294 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101295 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181296}
1297
[email protected]1a55c5b2011-11-29 11:36:311298void TabContents::OnDidFinishLoad(
1299 int64 frame_id,
1300 const GURL& validated_url,
1301 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251302 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311303 DidFinishLoad(frame_id, validated_url, is_main_frame));
1304}
1305
1306void TabContents::OnDidFailLoadWithError(int64 frame_id,
1307 const GURL& validated_url,
1308 bool is_main_frame,
1309 int error_code,
1310 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251311 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311312 DidFailLoad(frame_id, validated_url, is_main_frame,
1313 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181314}
1315
[email protected]c8f73ab2011-01-22 00:05:171316void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271317 content_restrictions_ = restrictions;
1318 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171319}
1320
[email protected]216813952011-05-19 22:21:261321void TabContents::OnGoToEntryAtOffset(int offset) {
1322 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1323 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1324 if (!entry)
1325 return;
1326 // Note that we don't call NavigationController::GotToOffset() as we don't
1327 // want to create a pending navigation entry (it might end up lingering
1328 // http://crbug.com/51680).
[email protected]2905f742011-10-13 03:51:581329 entry->set_transition_type(
1330 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511331 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581332 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271333 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571334
1335 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1336 // it in now that we know. This allows us to find the entry when it commits.
1337 if (!entry->site_instance() &&
1338 entry->restore_type() != NavigationEntry::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381339 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571340 }
[email protected]216813952011-05-19 22:21:261341 }
1342}
1343
1344void TabContents::OnUpdateZoomLimits(int minimum_percent,
1345 int maximum_percent,
1346 bool remember) {
1347 minimum_zoom_percent_ = minimum_percent;
1348 maximum_zoom_percent_ = maximum_percent;
1349 temporary_zoom_settings_ = !remember;
1350}
1351
[email protected]0bfbf882011-12-22 18:19:271352void TabContents::OnSaveURL(const GURL& url) {
1353 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1354 dlm->DownloadUrl(url, GetURL(), "", this);
1355}
1356
[email protected]3a29a6e2011-08-24 18:26:211357void TabContents::OnEnumerateDirectory(int request_id,
1358 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511359 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211360}
1361
[email protected]7d189022011-08-25 22:54:201362void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511363 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201364}
1365
1366void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1367 const GURL& url,
1368 const string16& title) {
[email protected]6934a702011-12-20 00:04:511369 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201370}
1371
[email protected]b888919c2011-09-02 00:32:161372void TabContents::OnFindReply(int request_id,
1373 int number_of_matches,
1374 const gfx::Rect& selection_rect,
1375 int active_match_ordinal,
1376 bool final_update) {
[email protected]6934a702011-12-20 00:04:511377 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1378 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001379 // Send a notification to the renderer that we are ready to receive more
1380 // results from the scoping effort of the Find operation. The FindInPage
1381 // scoping is asynchronous and periodically sends results back up to the
1382 // browser using IPC. In an effort to not spam the browser we have the
1383 // browser send an ACK for each FindReply message and have the renderer
1384 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521385 GetRenderViewHost()->Send(
1386 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161387}
1388
[email protected]d952a052011-09-06 18:42:451389void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511390 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451391}
1392
[email protected]7fc4bbb2011-09-08 21:23:101393void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1394 bool blocked_by_policy) {
1395 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251396 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101397 AppCacheAccessed(manifest_url, blocked_by_policy));
1398}
1399
[email protected]96d185d2009-04-24 03:28:541400// Notifies the RenderWidgetHost instance about the fact that the page is
1401// loading, or done loading and calls the base implementation.
1402void TabContents::SetIsLoading(bool is_loading,
1403 LoadNotificationDetails* details) {
1404 if (is_loading == is_loading_)
1405 return;
1406
1407 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211408 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541409 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561410 upload_size_ = 0;
1411 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541412 }
1413
1414 render_manager_.SetIsLoading(is_loading);
1415
1416 is_loading_ = is_loading;
1417 waiting_for_response_ = is_loading;
1418
[email protected]6ebdc9b2010-09-27 16:55:571419 if (delegate_)
1420 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351421 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541422
[email protected]432115822011-07-10 15:52:271423 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1424 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071425 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541426 if (details)
[email protected]6c2381d2011-10-19 02:52:531427 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071428 content::NotificationService::current()->Notify(type,
[email protected]6c2381d2011-10-19 02:52:531429 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541430 det);
1431}
1432
[email protected]420ae012009-04-24 05:16:321433void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131434 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321435 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561436 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381437 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441438 // that opened the window, as long as both renderers have the same
1439 // privileges.
[email protected]1fd1a502011-03-30 16:55:561440 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1441 WebUI* web_ui = content::GetContentClient()->browser()->
1442 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581443 // web_ui might be NULL if the URL refers to a non-existent extension.
1444 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401445 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521446 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441447 }
1448 }
[email protected]1fd1a502011-03-30 16:55:561449 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441450 }
1451
[email protected]4e697b042011-07-08 06:44:561452 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321453 // Clear the status bubble. This is a workaround for a bug where WebKit
1454 // doesn't let us know that the cursor left an element during a
1455 // transition (this is also why the mouse cursor remains as a hand after
1456 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1457 // clear the bubble when a user navigates to a named anchor in the same
1458 // page.
[email protected]36fc0392011-12-25 03:59:511459 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321460 }
1461
[email protected]a6e82fc2010-02-24 22:28:141462 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471463 // Once the main frame is navigated, we're no longer considered to have
1464 // displayed insecure content.
1465 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171466 }
[email protected]ce5c4502009-05-06 16:46:111467
[email protected]3c9e1872010-11-18 16:17:491468 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251469 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041470 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321471}
1472
1473void TabContents::DidNavigateAnyFramePostCommit(
1474 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131475 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321476 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071477 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321478 // a malicious script from spamming messages, since the script could just
1479 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551480 if (dialog_creator_) {
1481 dialog_creator_->ResetJavaScriptState(this);
1482 dialog_creator_ = NULL;
1483 }
[email protected]420ae012009-04-24 05:16:321484
[email protected]3c9e1872010-11-18 16:17:491485 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251486 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041487 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321488}
1489
[email protected]74ce1ad2011-12-16 21:51:461490void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1491 // If we are creating a RVH for a restored controller, then we need to make
1492 // sure the RenderView starts with a next_page_id_ larger than the number
1493 // of restored entries. This must be called before the RenderView starts
1494 // navigating (to avoid a race between the browser updating max_page_id and
1495 // the renderer updating next_page_id_). Because of this, we only call this
1496 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]420ae012009-04-24 05:16:321497 int max_restored_page_id = controller_.max_restored_page_id();
[email protected]74ce1ad2011-12-16 21:51:461498 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1499 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321500}
1501
[email protected]6b2f7a82011-04-25 19:30:511502bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]acafd272011-07-26 17:35:571503 const string16& title) {
[email protected]420ae012009-04-24 05:16:321504 // For file URLs without a title, use the pathname instead. In the case of a
1505 // synthesized title, we don't want the update to count toward the "one set
1506 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511507 string16 final_title;
[email protected]420ae012009-04-24 05:16:321508 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511509 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1510 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321511 explicit_set = false; // Don't count synthetic titles toward the set limit.
1512 } else {
[email protected]acafd272011-07-26 17:35:571513 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321514 explicit_set = true;
1515 }
1516
[email protected]987fc3a2011-05-26 14:18:091517 // If a page is created via window.open and never navigated,
1518 // there will be no navigation entry. In this situation,
1519 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1520 if (entry) {
[email protected]36fc0392011-12-25 03:59:511521 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091522 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321523
[email protected]36fc0392011-12-25 03:59:511524 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091525 } else {
1526 if (page_title_when_no_navigation_entry_ == final_title)
1527 return false; // Nothing changed, don't bother.
1528
1529 page_title_when_no_navigation_entry_ = final_title;
1530 }
[email protected]420ae012009-04-24 05:16:321531
[email protected]420ae012009-04-24 05:16:321532 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231533 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321534
[email protected]105bb0f2011-05-24 17:12:141535 TitleUpdatedDetails details(entry, explicit_set);
1536
[email protected]ad50def52011-10-19 23:17:071537 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271538 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531539 content::Source<TabContents>(this),
1540 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041541
[email protected]420ae012009-04-24 05:16:321542 return true;
1543}
1544
1545void TabContents::NotifySwapped() {
1546 // After sending out a swap notification, we need to send a disconnect
1547 // notification so that clients that pick up a pointer to |this| can NULL the
1548 // pointer. See Bug 1230284.
1549 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071550 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271551 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]6c2381d2011-10-19 02:52:531552 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071553 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321554}
1555
1556void TabContents::NotifyConnected() {
1557 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071558 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271559 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531560 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071561 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321562}
1563
1564void TabContents::NotifyDisconnected() {
1565 if (!notify_disconnection_)
1566 return;
1567
1568 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071569 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271570 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]6c2381d2011-10-19 02:52:531571 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071572 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321573}
1574
[email protected]8d3347f2009-07-09 22:00:211575RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321576 return view_.get();
1577}
1578
[email protected]8d3347f2009-07-09 22:00:211579RenderViewHostDelegate::RendererManagement*
1580TabContents::GetRendererManagementDelegate() {
1581 return &render_manager_;
1582}
1583
[email protected]daf82f82011-10-31 22:35:311584content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371585 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461586 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511587}
1588
[email protected]57c6a652009-05-04 07:58:341589TabContents* TabContents::GetAsTabContents() {
1590 return this;
1591}
1592
[email protected]da4dfc42011-10-12 15:53:561593content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431594 return view_type_;
[email protected]7b291f92009-08-14 05:43:531595}
1596
[email protected]420ae012009-04-24 05:16:321597void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071598 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271599 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]6c2381d2011-10-19 02:52:531600 content::Source<TabContents>(this),
1601 content::Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321602 NavigationEntry* entry = controller_.GetActiveEntry();
1603 if (!entry)
1604 return;
1605
1606 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351607 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561608 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581609 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321610
1611 if (entry->IsViewSourceMode()) {
1612 // Put the renderer in view source mode.
1613 render_view_host->Send(
1614 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1615 }
[email protected]0666aef2009-05-13 19:48:081616
[email protected]d487beefe2011-12-21 05:41:211617 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261618
1619 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251620 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321621}
1622
1623void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521624 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321625 // Don't notify the world, since this came from a renderer in the
1626 // background.
1627 return;
1628 }
1629
1630 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311631 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231632 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301633
1634 // Restore the focus to the tab (otherwise the focus will be on the top
1635 // window).
[email protected]484ae5912010-09-29 19:16:141636 if (was_crashed && !FocusLocationBarByDefault() &&
1637 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301638 Focus();
[email protected]484ae5912010-09-29 19:16:141639 }
[email protected]32ded2212011-11-10 18:51:431640
[email protected]d8c660432011-12-22 20:51:251641 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321642}
1643
[email protected]443b80e2010-12-14 00:42:231644void TabContents::RenderViewGone(RenderViewHost* rvh,
1645 base::TerminationStatus status,
1646 int error_code) {
[email protected]151a63d2011-12-20 22:32:521647 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321648 // The pending page's RenderViewHost is gone.
1649 return;
1650 }
1651
1652 SetIsLoading(false, NULL);
1653 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231654 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311655 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321656
[email protected]d8c660432011-12-22 20:51:251657 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271658 observers_,
[email protected]be1f56ab2011-12-22 06:55:311659 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321660}
1661
[email protected]2e4633c2009-07-09 16:58:061662void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481663 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251664 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061665}
1666
[email protected]420ae012009-04-24 05:16:321667void TabContents::DidNavigate(RenderViewHost* rvh,
1668 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581669 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321670 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371671
[email protected]420ae012009-04-24 05:16:321672 // Update the site of the SiteInstance if it doesn't have one yet.
1673 if (!GetSiteInstance()->has_site())
1674 GetSiteInstance()->SetSite(params.url);
1675
1676 // Need to update MIME type here because it's referred to in
1677 // UpdateNavigationCommands() called by RendererDidNavigate() to
1678 // determine whether or not to enable the encoding menu.
1679 // It's updated only for the main frame. For a subframe,
1680 // RenderView::UpdateURL does not set params.contents_mime_type.
1681 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1682 // TODO(jungshik): Add a test for the encoding menu to avoid
1683 // regressing it again.
[email protected]2905f742011-10-13 03:51:581684 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321685 contents_mime_type_ = params.contents_mime_type;
1686
[email protected]8286f51a2011-05-31 17:39:131687 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001688 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391689
[email protected]a9c0bfe2010-09-17 08:35:221690 // Send notification about committed provisional loads. This notification is
1691 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1692 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081693 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071694 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1695 // that is not recorded in the navigation history. For the purpose of
1696 // tracking navigation events, we treat this event as a sub frame navigation
1697 // event.
1698 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581699 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221700 // Whether or not a page transition was triggered by going backward or
1701 // forward in the history is only stored in the navigation controller's
1702 // entry list.
1703 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511704 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581705 content::PAGE_TRANSITION_FORWARD_BACK)) {
1706 transition_type = content::PageTransitionFromInt(
1707 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221708 }
[email protected]0d60f0192011-04-14 12:40:101709 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251710 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101711 DidCommitProvisionalLoadForFrame(params.frame_id,
1712 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221713 }
1714
[email protected]76543b92009-08-31 17:27:451715 if (!did_navigate)
1716 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321717
1718 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1719 // for the appropriate notification (best) or you can add it to
1720 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1721 // necessary, please).
1722
1723 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001724 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321725 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511726 if (delegate_)
1727 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001728 }
[email protected]420ae012009-04-24 05:16:321729 DidNavigateAnyFramePostCommit(rvh, details, params);
1730}
1731
1732void TabContents::UpdateState(RenderViewHost* rvh,
1733 int32 page_id,
1734 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151735 // Ensure that this state update comes from either the active RVH or one of
1736 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521737 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321738
1739 // We must be prepared to handle state updates for any page, these occur
1740 // when the user is scrolling and entering form data, as well as when we're
1741 // leaving a page, in which case our state may have already been moved to
1742 // the next page. The navigation controller will look up the appropriate
1743 // NavigationEntry and update it when it is notified via the delegate.
1744
1745 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151746 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321747 if (entry_index < 0)
1748 return;
1749 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1750
[email protected]36fc0392011-12-25 03:59:511751 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321752 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511753 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321754 controller_.NotifyEntryChanged(entry, entry_index);
1755}
1756
1757void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571758 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461759 const string16& title,
1760 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321761 // If we have a title, that's a pretty good indication that we've started
1762 // getting useful data.
1763 SetNotWaitingForResponse();
1764
[email protected]151a63d2011-12-20 22:32:521765 DCHECK(rvh == GetRenderViewHost());
[email protected]371cc8b2010-09-01 16:03:481766 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581767 page_id);
[email protected]987fc3a2011-05-26 14:18:091768
[email protected]a49e10b2011-08-01 23:57:461769 // TODO(evan): make use of title_direction.
1770 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091771 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321772 return;
1773
1774 // Broadcast notifications when the UI should be updated.
1775 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031776 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321777}
1778
[email protected]420ae012009-04-24 05:16:321779void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401780 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311781 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321782}
1783
1784void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511785 if (delegate_)
1786 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321787}
1788
[email protected]420ae012009-04-24 05:16:321789void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291790 // The UI may be in an event-tracking loop, such as between the
1791 // mouse-down and mouse-up in text selection or a button click.
1792 // Defer the close until after tracking is complete, so that we
1793 // don't free objects out from under the UI.
1794 // TODO(shess): This could probably be integrated with the
1795 // IsDoingDrag() test below. Punting for now because I need more
1796 // research to understand how this impacts platforms other than Mac.
1797 // TODO(shess): This could get more fine-grained. For instance,
1798 // closing a tab in another window while selecting text in the
1799 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211800 if (GetView()->IsEventTracking()) {
1801 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291802 return;
1803 }
1804
[email protected]24a4d1062009-07-10 23:10:421805 // If we close the tab while we're in the middle of a drag, we'll crash.
1806 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211807 if (GetView()->IsDoingDrag()) {
1808 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421809 return;
1810 }
1811
[email protected]420ae012009-04-24 05:16:321812 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521813 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511814 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321815}
1816
[email protected]cd9ed79d2011-11-15 19:22:571817void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521818 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511819 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571820}
1821
[email protected]420ae012009-04-24 05:16:321822void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511823 if (delegate_ && delegate_->IsPopupOrPanel(this))
1824 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321825}
1826
[email protected]7ab1e7d62009-10-14 23:32:011827void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321828 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491829
[email protected]6934a702011-12-20 00:04:511830 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211831 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511832 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001833 }
[email protected]3c9e1872010-11-18 16:17:491834
1835 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251836 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321837}
1838
[email protected]7ab1e7d62009-10-14 23:32:011839void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321840 scoped_ptr<LoadNotificationDetails> details;
1841
1842 NavigationEntry* entry = controller_.GetActiveEntry();
1843 // An entry may not exist for a stop when loading an initial blank page or
1844 // if an iframe injected by script into a blank page finishes loading.
1845 if (entry) {
[email protected]420ae012009-04-24 05:16:321846 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1847
1848 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511849 entry->GetVirtualURL(),
1850 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321851 elapsed,
1852 &controller_,
1853 controller_.GetCurrentEntryIndex()));
1854 }
1855
[email protected]420ae012009-04-24 05:16:321856 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491857
1858 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251859 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321860}
1861
[email protected]c95fa8b2011-04-28 20:26:161862void TabContents::DidCancelLoading() {
1863 controller_.DiscardNonCommittedEntries();
1864
1865 // Update the URL display.
1866 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1867}
1868
[email protected]1a3c3cb2010-12-16 21:03:401869void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511870 if (delegate_)
1871 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401872}
1873
[email protected]952a68e2011-11-17 00:36:101874void TabContents::DocumentAvailableInMainFrame(
1875 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251876 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101877 DocumentAvailableInMainFrame());
1878}
1879
[email protected]25497492010-09-11 15:15:081880void TabContents::DocumentOnLoadCompletedInMainFrame(
1881 RenderViewHost* render_view_host,
1882 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071883 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271884 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]6c2381d2011-10-19 02:52:531885 content::Source<TabContents>(this),
1886 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081887}
1888
[email protected]ae5184d62011-10-06 19:25:581889void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151890 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581891 WindowOpenDisposition disposition,
1892 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481893 // Delegate to RequestTransferURL because this is just the generic
1894 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581895 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481896 GlobalRequestID());
1897}
1898
1899void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581900 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481901 WindowOpenDisposition disposition,
1902 int64 source_frame_id,
1903 const GlobalRequestID& old_request_id) {
[email protected]ae5184d62011-10-06 19:25:581904 TabContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581905 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581906 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351907 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321908 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1909 // generated suggestions).
1910 //
[email protected]e0112912011-02-02 22:54:351911 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161912 // want web sites to see a referrer of "chrome://blah" (and some
1913 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321914 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581915 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481916 render_manager_.web_ui()->link_transition_type(),
1917 false /* is_renderer_initiated */);
1918 params.transferred_global_request_id = old_request_id;
1919 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581920 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321921 } else {
[email protected]4ad5d77d2011-12-03 02:00:481922 OpenURLParams params(url, referrer, disposition,
1923 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1924 params.transferred_global_request_id = old_request_id;
1925 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581926 }
1927 if (new_contents) {
1928 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251929 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581930 DidOpenRequestedURL(new_contents,
1931 url,
1932 referrer,
1933 disposition,
1934 transition_type,
1935 source_frame_id));
[email protected]420ae012009-04-24 05:16:321936 }
1937}
1938
[email protected]420ae012009-04-24 05:16:321939void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151940 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411941 const string16& message,
1942 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321943 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471944 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321945 IPC::Message* reply_msg,
1946 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071947 // Suppress JavaScript dialogs when requested. Also suppress messages when
1948 // showing an interstitial as it's shown over the previous page and we don't
1949 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501950 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151951 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271952 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071953 !delegate_ ||
1954 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321955
1956 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341957 content::JavaScriptDialogCreator::TitleType title_type;
1958 string16 title;
1959
1960 if (!frame_url.has_host()) {
1961 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1962 } else {
1963 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1964 title = net::FormatUrl(
1965 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201966 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301967 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341968 }
1969
[email protected]2e5b90c2011-08-16 21:11:551970 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1971 dialog_creator_->RunJavaScriptDialog(this,
1972 title_type,
1973 title,
[email protected]269f86d2011-12-07 02:43:471974 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551975 message,
1976 default_prompt,
1977 reply_msg,
1978 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321979 }
[email protected]3ab9cb82011-06-03 18:02:071980
1981 if (suppress_this_message) {
1982 // If we are suppressing messages, just reply as if the user immediately
1983 // pressed "Cancel".
1984 OnDialogClosed(reply_msg, false, string16());
1985 }
1986
1987 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321988}
1989
[email protected]992db4c2011-05-12 15:37:151990void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411991 const string16& message,
[email protected]420ae012009-04-24 05:16:321992 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:511993 if (delegate_)
1994 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071995
1996 bool suppress_this_message =
1997 rvh->is_swapped_out() ||
1998 !delegate_ ||
1999 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152000 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522001 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502002 return;
2003 }
[email protected]3ab9cb82011-06-03 18:02:072004
[email protected]7ab1e7d62009-10-14 23:32:012005 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552006 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2007 dialog_creator_->RunBeforeUnloadDialog(this,
2008 message,
2009 reply_msg);
[email protected]420ae012009-04-24 05:16:322010}
2011
[email protected]420ae012009-04-24 05:16:322012WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082013 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362014 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522015 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082016
[email protected]b8299c12011-06-03 19:52:282017 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212018 // chrome-devtools: pages (unless it's specifically allowed).
2019 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572020 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282021 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302022 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2023 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212024 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082025 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432026 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082027 }
2028
2029 return web_prefs;
[email protected]420ae012009-04-24 05:16:322030}
2031
[email protected]7d472472011-01-22 01:30:252032void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272033 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252034 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222035
2036 ResourceDispatcherHost* rdh =
2037 content::GetContentClient()->browser()->GetResourceDispatcherHost();
2038 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:302039 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252040}
2041
[email protected]fa1cf0b82010-01-15 21:49:442042void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442043 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252044 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442045}
2046
[email protected]420ae012009-04-24 05:16:322047void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2048 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152049 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522050 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152051 return;
2052
[email protected]e5fc1632011-08-08 07:51:532053 // Ignore renderer unresponsive event if debugger is attached to the tab
2054 // since the event may be a result of the renderer sitting on a breakpoint.
2055 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442056 DevToolsAgentHost* agent =
2057 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2058 if (agent &&
2059 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532060 return;
2061
[email protected]420ae012009-04-24 05:16:322062 if (is_during_unload) {
2063 // Hang occurred while firing the beforeunload/unload handler.
2064 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112065 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322066
2067 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2068 return;
2069
2070 // If the tab hangs in the beforeunload/unload handler there's really
2071 // nothing we can do to recover. Pretend the unload listeners have
2072 // all fired and close the tab. If the hang is in the beforeunload handler
2073 // then the user will not have the option of cancelling the close.
2074 Close(rvh);
2075 return;
2076 }
2077
[email protected]151a63d2011-12-20 22:32:522078 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472079 return;
2080
[email protected]6934a702011-12-20 00:04:512081 if (delegate_)
2082 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322083}
2084
2085void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512086 if (delegate_)
2087 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322088}
2089
2090void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212091 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562092 uint64 upload_position,
2093 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322094 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562095 upload_position_ = upload_position;
2096 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502097 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202098 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302099 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212100 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322101 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:512102 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:502103 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322104}
2105
[email protected]7d472472011-01-22 01:30:252106void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512107 if (delegate_)
2108 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252109}
2110
[email protected]420ae012009-04-24 05:16:322111void TabContents::BeforeUnloadFiredFromRenderManager(
2112 bool proceed,
2113 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512114 if (delegate_)
2115 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322116}
2117
[email protected]3a3d47472010-07-15 21:03:542118void TabContents::DidStartLoadingFromRenderManager(
2119 RenderViewHost* render_view_host) {
2120 DidStartLoading();
2121}
2122
2123void TabContents::RenderViewGoneFromRenderManager(
2124 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232125 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2126 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542127}
2128
[email protected]420ae012009-04-24 05:16:322129void TabContents::UpdateRenderViewSizeForRenderManager() {
2130 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262131 gfx::Size size = view_->GetContainerSize();
2132 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2133 // here during container initialization and normal window size will be set
2134 // later. In case of tab duplication this resizing to 0x0 prevents setting
2135 // normal size later so just ignore it.
2136 if (!size.IsEmpty())
2137 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322138}
2139
[email protected]3a3d47472010-07-15 21:03:542140void TabContents::NotifySwappedFromRenderManager() {
2141 NotifySwapped();
2142}
2143
2144NavigationController& TabContents::GetControllerForRenderManager() {
[email protected]f5fa20e2011-12-21 22:35:562145 return GetController();
[email protected]3a3d47472010-07-15 21:03:542146}
2147
[email protected]d0980792011-02-13 19:41:402148WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562149 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322150}
2151
2152NavigationEntry*
2153TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2154 return controller_.GetLastCommittedEntry();
2155}
2156
2157bool TabContents::CreateRenderViewForRenderManager(
2158 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442159 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322160 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522161
[email protected]420ae012009-04-24 05:16:322162 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442163 if (rwh_view)
2164 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322165
[email protected]74ce1ad2011-12-16 21:51:462166 // Make sure we use the correct starting page_id in the new RenderView.
2167 UpdateMaxPageIDIfNecessary(render_view_host);
2168 int32 max_page_id =
2169 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2170
2171 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522172 return false;
2173
[email protected]e60c0232011-11-11 19:56:352174#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502175 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2176 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442177 if (rwh_view) {
2178 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2179 render_widget_host->WasResized();
2180 }
[email protected]f8233cc2011-05-31 20:24:502181#endif
2182
[email protected]420ae012009-04-24 05:16:322183 return true;
2184}
2185
[email protected]3ab9cb82011-06-03 18:02:072186void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2187 bool success,
2188 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542189 if (is_showing_before_unload_dialog_ && !success) {
2190 // If a beforeunload dialog is canceled, we need to stop the throbber from
2191 // spinning, since we forced it to start spinning in Navigate.
2192 DidStopLoading();
2193
2194 tab_close_start_time_ = base::TimeTicks();
2195 }
2196 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522197 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542198}
2199
[email protected]0b08add2011-11-29 03:27:062200gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072201 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542202}
2203
[email protected]a1e97f02011-06-30 14:04:342204void TabContents::OnDialogShown() {
2205 Activate();
[email protected]3a3d47472010-07-15 21:03:542206}
2207
[email protected]be1f56ab2011-12-22 06:55:312208void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122209 encoding_ = content::GetContentClient()->browser()->
2210 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102211}
[email protected]f45d2a72010-03-08 23:28:352212
[email protected]33f74972010-12-08 16:40:362213void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212214 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442215 // Can be NULL during tests.
2216 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212217 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362218}