blob: 3dfb657e8519c51279bee31cba7c55bc45abe5b8 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]567812d2011-02-24 17:40:5016#include "content/browser/child_process_security_policy.h"
[email protected]0e12d7d2011-12-01 16:21:4417#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4618#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5019#include "content/browser/host_zoom_map.h"
20#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0021#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0122#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0423#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3024#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5025#include "content/browser/renderer_host/render_view_host.h"
26#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2227#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/resource_request_details.h"
29#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4430#include "content/browser/tab_contents/interstitial_page.h"
[email protected]10f417c52011-12-28 21:04:2331#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]0dd3a0ab2011-02-18 08:17:4432#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]ce9751942011-09-21 01:57:2435#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0236#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1137#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4438#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4439#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1740#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4641#include "content/public/browser/invalidate_type.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]f3f3b722012-01-07 01:29:4347#include "content/public/browser/web_ui_factory.h"
[email protected]e091df82011-10-11 18:13:2148#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4849#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1850#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0351#include "content/public/common/url_constants.h"
[email protected]d686e812009-06-03 19:10:2952#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3453#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3754#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3855#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2456#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3157#include "webkit/glue/webpreferences.h"
58
59#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1260#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3161#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0062
[email protected]420ae012009-04-24 05:16:3263// Cross-Site Navigations
64//
65// If a TabContents is told to navigate to a different web site (as determined
66// by SiteInstance), it will replace its current RenderViewHost with a new
67// RenderViewHost dedicated to the new SiteInstance. This works as follows:
68//
69// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4670// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3271// - The pending RVH is "suspended," so that no navigation messages are sent to
72// its renderer until the onbeforeunload JavaScript handler has a chance to
73// run in the current RVH.
74// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
75// that it has a pending cross-site request. ResourceDispatcherHost will
76// check for this when the response arrives.
77// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4678// cancel all the pending logic. Otherwise we allow the pending RVH to send
79// the navigation request to its renderer.
80// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
81// main resource load on the pending RVH. It checks CrossSiteRequestManager
82// to see that it is a cross-site request, and installs a
83// CrossSiteResourceHandler.
84// - When RDH receives a response, the BufferedResourceHandler determines
85// whether it is a download. If so, it sends a message to the new renderer
86// causing it to cancel the request, and the download proceeds. For now, the
87// pending RVH remains until the next DidNavigate event for this TabContents.
88// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3289// - After RDH receives a response and determines that it is safe and not a
90// download, it pauses the response to first run the old page's onunload
91// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1592// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3293// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1594// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3295// the ResourceDispatcherHost, who unpauses the response. Data is then sent
96// to the pending RVH.
97// - The pending renderer sends a FrameNavigate message that invokes the
98// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4699// pending RVH.
[email protected]992db4c2011-05-12 15:37:15100// - The previous renderer is kept swapped out in RenderViewHostManager in case
101// the user goes back. The process only stays live if another tab is using
102// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02103//
104// It is possible that we trigger a new navigation after we have received
105// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
106// In this case the old RVH has been swapped out but the new one has not
107// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
108// of the old RVH.
[email protected]420ae012009-04-24 05:16:32109
[email protected]0e12d7d2011-12-01 16:21:44110using content::DevToolsAgentHost;
111using content::DevToolsAgentHostRegistry;
112using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17113using content::DownloadItem;
114using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20115using content::GlobalRequestID;
[email protected]c5eed492012-01-04 17:07:50116using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23117using content::NavigationEntry;
118using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20119using content::OpenURLParams;
[email protected]d583e3f22011-12-27 21:38:17120using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38121using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09122using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25123using content::WebContentsObserver;
[email protected]0e12d7d2011-12-01 16:21:44124
[email protected]420ae012009-04-24 05:16:32125namespace {
126
127// Amount of time we wait between when a key event is received and the renderer
128// is queried for its state and pushed to the NavigationEntry.
129const int kQueryStateDelay = 5000;
130
[email protected]6ebdc9b2010-09-27 16:55:57131const int kSyncWaitDelay = 40;
132
[email protected]ca406032011-07-19 21:53:05133static const char kDotGoogleDotCom[] = ".google.com";
134
[email protected]420ae012009-04-24 05:16:32135#if defined(OS_WIN)
136
137BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
138 // Note: erase is required to properly paint some widgets borders. This can
139 // be seen with textfields.
140 InvalidateRect(hwnd, NULL, TRUE);
141 return TRUE;
142}
143#endif
144
[email protected]2c5569662011-03-22 20:45:02145ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23146 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50147 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16148 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47149 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02150 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47151 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02152 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47153 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16154 break; // Fall through to rest of function.
155 }
[email protected]5e369672009-11-03 23:48:30156
[email protected]10f417c52011-12-28 21:04:23157 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37158 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02159 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30160
[email protected]2c5569662011-03-22 20:45:02161 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30162}
163
[email protected]10f417c52011-12-28 21:04:23164void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47165 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42166 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50167 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16168 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51169 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54170 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55171 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
172 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51173 params->url = entry.GetURL();
174 params->referrer = entry.GetReferrer();
175 params->transition = entry.GetTransitionType();
176 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00177 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55178 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34179 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47180 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48181 params->transferred_request_child_id =
182 entry.transferred_global_request_id().child_id;
183 params->transferred_request_request_id =
184 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47185
186 if (delegate)
187 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34188}
189
[email protected]420ae012009-04-24 05:16:32190} // namespace
191
[email protected]a81343d232011-12-27 07:39:20192namespace content {
193
194WebContents* WebContents::Create(
195 BrowserContext* browser_context,
196 SiteInstance* site_instance,
197 int routing_id,
198 const WebContents* base_tab_contents,
199 SessionStorageNamespace* session_storage_namespace) {
200 return new TabContents(browser_context,
201 site_instance,
202 routing_id,
203 static_cast<const TabContents*>(base_tab_contents),
204 session_storage_namespace);
205}
206}
[email protected]f4f50ef2011-01-21 19:01:19207
208// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32209
[email protected]3d7474ff2011-07-27 17:47:37210TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32211 SiteInstance* site_instance,
212 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07213 const TabContents* base_tab_contents,
214 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42215 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07216 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37217 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13218 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32219 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22220 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34221 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23222 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
223 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34224 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21225 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56226 upload_size_(0),
227 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47228 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57229 capturing_contents_(false),
230 is_being_destroyed_(false),
231 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55232 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57233#if defined(OS_WIN)
234 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
235#endif
[email protected]7ab1e7d62009-10-14 23:32:01236 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56237 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38238 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25239 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01240 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25241 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01242 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00243 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43244 content_restrictions_(0),
245 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37246 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32247
[email protected]34ac70502009-09-25 17:07:23248 // We have the initial size of the view be based on the size of the passed in
249 // tab contents (normally a tab from the same window).
250 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21251 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00252
253#if defined(ENABLE_JAVA_BRIDGE)
254 java_bridge_dispatcher_host_manager_.reset(
255 new JavaBridgeDispatcherHostManager(this));
256#endif
[email protected]332af7732009-03-11 13:21:35257}
initial.commit09911bf2008-07-26 23:55:29258
259TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32260 is_being_destroyed_ = true;
261
[email protected]3ab9cb82011-06-03 18:02:07262 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55263 if (dialog_creator_)
264 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07265
[email protected]420ae012009-04-24 05:16:32266 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32267
[email protected]420ae012009-04-24 05:16:32268 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07269 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09270 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
271 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07272 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32273
274 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07275#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32276 // If we still have a window handle, destroy it. GetNativeView can return
277 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42278 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52279 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44280 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42281 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42282 }
[email protected]420ae012009-04-24 05:16:32283#endif
[email protected]7ab1e7d62009-10-14 23:32:01284
285 // OnCloseStarted isn't called in unit tests.
286 if (!tab_close_start_time_.is_null()) {
287 UMA_HISTOGRAM_TIMES("Tab.Close",
288 base::TimeTicks::Now() - tab_close_start_time_);
289 }
[email protected]b5a1d11c2011-02-17 03:09:42290
[email protected]d8c660432011-12-22 20:51:25291 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08292
[email protected]6934a702011-12-20 00:04:51293 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42294}
295
[email protected]d202a7c2012-01-04 07:53:47296NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20297 return controller_;
298}
299
[email protected]724159a2010-12-30 01:11:18300bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]be1f56ab2011-12-22 06:55:31301 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17302 return true;
303
[email protected]d8c660432011-12-22 20:51:25304 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
305 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10306 while ((observer = it.GetNext()) != NULL)
307 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53308 return true;
[email protected]403415a2011-01-10 18:57:53309
[email protected]724159a2010-12-30 01:11:18310 bool handled = true;
311 bool message_is_ok = true;
312 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58313 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
314 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24315 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
316 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18317 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
318 OnDidStartProvisionalLoadForFrame)
319 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
320 OnDidRedirectProvisionalLoad)
321 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
322 OnDidFailProvisionalLoadWithError)
323 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
324 OnDidLoadResourceFromMemoryCache)
325 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
326 OnDidDisplayInsecureContent)
327 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
328 OnDidRunInsecureContent)
329 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
330 OnDocumentLoadedInFrame)
331 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17332 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
333 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25334 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26335 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59336 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21337 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20338 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
339 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
340 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16341 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45342 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10343 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18344 IPC_MESSAGE_UNHANDLED(handled = false)
345 IPC_END_MESSAGE_MAP_EX()
346
347 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38348 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18349 GetRenderProcessHost()->ReceivedBadMessage();
350 }
351
352 return handled;
353}
354
[email protected]6c2e472f2011-08-24 23:26:18355void TabContents::RunFileChooser(
356 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23357 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51358 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18359}
360
[email protected]c5eed492012-01-04 17:07:50361NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56362 return controller_;
363}
364
[email protected]c5eed492012-01-04 17:07:50365const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56366 return controller_;
367}
368
[email protected]627e0512011-12-21 22:55:30369content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55370 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30371}
372
[email protected]f5fa20e2011-12-21 22:35:56373void TabContents::SetViewType(content::ViewType type) {
374 view_type_ = type;
375}
376
[email protected]ea049a02011-12-25 21:37:09377content::ViewType TabContents::GetViewType() const {
378 return view_type_;
379}
380
[email protected]be1f56ab2011-12-22 06:55:31381const GURL& TabContents::GetURL() const {
382 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23383 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51384 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31385}
386
387
388const base::PropertyBag* TabContents::GetPropertyBag() const {
389 return &property_bag_;
390}
391
392base::PropertyBag* TabContents::GetPropertyBag() {
393 return &property_bag_;
394}
395
396content::WebContentsDelegate* TabContents::GetDelegate() {
397 return delegate_;
398}
399
400void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
401 // TODO(cbentzel): remove this debugging code?
402 if (delegate == delegate_)
403 return;
404 if (delegate_)
405 delegate_->Detach(this);
406 delegate_ = delegate;
407 if (delegate_)
408 delegate_->Attach(this);
409}
410
[email protected]f3b1a082011-11-18 00:34:30411content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03412 if (render_manager_.current_host())
413 return render_manager_.current_host()->process();
414 else
415 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16416}
417
[email protected]be1f56ab2011-12-22 06:55:31418RenderViewHost* TabContents::GetRenderViewHost() const {
419 return render_manager_.current_host();
420}
421
422RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
423 return render_manager_.GetRenderWidgetHostView();
424}
425
426TabContentsView* TabContents::GetView() const {
427 return view_.get();
428}
429
430WebUI* TabContents::GetWebUI() const {
431 return render_manager_.web_ui() ? render_manager_.web_ui()
432 : render_manager_.pending_web_ui();
433}
434
435WebUI* TabContents::GetCommittedWebUI() const {
436 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34437}
438
[email protected]96d185d2009-04-24 03:28:54439const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55440 // Transient entries take precedence. They are used for interstitial pages
441 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23442 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08443 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20444 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30445 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23446 if (entry) {
[email protected]b5cca982011-05-26 04:42:08447 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23448 }
[email protected]7ade2732011-02-10 00:13:58449 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
450 render_manager_.pending_web_ui() : render_manager_.web_ui();
451 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54452 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55453 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54454 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35455 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58456 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54457 if (!title.empty())
458 return title;
459 }
460 }
461
462 // We use the title for the last committed entry rather than a pending
463 // navigation entry. For example, when the user types in a URL, we want to
464 // keep the old page's title until the new load has committed and we get a new
465 // title.
[email protected]96d185d2009-04-24 03:28:54466 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23467 if (entry) {
[email protected]b5cca982011-05-26 04:42:08468 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23469 }
[email protected]987fc3a2011-05-26 14:18:09470
471 // |page_title_when_no_navigation_entry_| is finally used
472 // if no title cannot be retrieved.
473 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54474}
475
[email protected]d5f942ba2008-09-26 19:30:34476int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46477 return GetMaxPageIDForSiteInstance(GetSiteInstance());
478}
479
480int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
481 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
482 max_page_ids_[site_instance->id()] = -1;
483
484 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34485}
486
487void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46488 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
489}
490
491void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
492 int32 page_id) {
493 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
494 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34495}
496
[email protected]91854cd2012-01-10 19:43:57497void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
498 max_page_ids_ = tab_contents->max_page_ids_;
499}
500
[email protected]96d185d2009-04-24 03:28:54501SiteInstance* TabContents::GetSiteInstance() const {
502 return render_manager_.current_host()->site_instance();
503}
504
[email protected]77362eb2011-08-01 17:18:38505SiteInstance* TabContents::GetPendingSiteInstance() const {
506 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
507 render_manager_.pending_render_view_host() :
508 render_manager_.current_host();
509 return dest_rvh->site_instance();
510}
511
[email protected]be1f56ab2011-12-22 06:55:31512bool TabContents::IsLoading() const {
513 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49514}
515
[email protected]be1f56ab2011-12-22 06:55:31516bool TabContents::IsWaitingForResponse() const {
517 return waiting_for_response_;
518}
519
520const net::LoadStateWithParam& TabContents::GetLoadState() const {
521 return load_state_;
522}
523
524const string16& TabContents::GetLoadStateHost() const {
525 return load_state_host_;
526}
527
528uint64 TabContents::GetUploadSize() const {
529 return upload_size_;
530}
531
532uint64 TabContents::GetUploadPosition() const {
533 return upload_position_;
534}
535
536const std::string& TabContents::GetEncoding() const {
537 return encoding_;
538}
539
540bool TabContents::DisplayedInsecureContent() const {
541 return displayed_insecure_content_;
542}
543
544void TabContents::SetCapturingContents(bool cap) {
545 capturing_contents_ = cap;
546}
547
548bool TabContents::IsCrashed() const {
549 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
550 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
551 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49552}
553
[email protected]443b80e2010-12-14 00:42:23554void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
555 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34556 return;
557
[email protected]443b80e2010-12-14 00:42:23558 crashed_status_ = status;
559 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46560 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34561}
562
[email protected]be1f56ab2011-12-22 06:55:31563base::TerminationStatus TabContents::GetCrashedStatus() const {
564 return crashed_status_;
565}
566
567bool TabContents::IsBeingDestroyed() const {
568 return is_being_destroyed_;
569}
570
[email protected]d5f942ba2008-09-26 19:30:34571void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
572 if (delegate_)
573 delegate_->NavigationStateChanged(this, changed_flags);
574}
575
[email protected]96d185d2009-04-24 03:28:54576void TabContents::DidBecomeSelected() {
577 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16578 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
579 if (rwhv) {
580 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43581#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16582 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43583#endif
584 }
[email protected]96d185d2009-04-24 03:28:54585
[email protected]5ac20162010-11-24 23:33:11586 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38587
[email protected]d8c660432011-12-22 20:51:25588 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54589}
590
[email protected]be1f56ab2011-12-22 06:55:31591
592base::TimeTicks TabContents::GetLastSelectedTime() const {
593 return last_selected_time_;
594}
595
[email protected]96d185d2009-04-24 03:28:54596void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31597 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52598 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
599 // open a tab in then background, then closes the tab before selecting it.
600 // This is because closing the tab calls TabContents::Destroy(), which
601 // removes the |GetRenderViewHost()|; then when we actually destroy the
602 // window, OnWindowPosChanged() notices and calls HideContents() (which
603 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16604 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
605 if (rwhv)
606 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54607 }
608
[email protected]ad50def52011-10-19 23:17:07609 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09610 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
611 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07612 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54613}
614
[email protected]be1f56ab2011-12-22 06:55:31615void TabContents::ShowContents() {
616 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
617 if (rwhv)
618 rwhv->DidBecomeSelected();
619}
620
621void TabContents::HideContents() {
622 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
623 // our superclass HideContents(), because some callers want to be very picky
624 // about the order in which these get called. In addition to making the code
625 // here practically impossible to understand, this also means we end up
626 // calling TabContents::WasHidden() twice if callers call both versions of
627 // HideContents() on a TabContents.
628 WasHidden();
629}
630
631bool TabContents::NeedToFireBeforeUnload() {
632 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27633 return WillNotifyDisconnection() &&
634 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31635 !GetRenderViewHost()->SuddenTerminationAllowed();
636}
637
638RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
639 return &render_manager_;
640}
641
[email protected]0bfbf882011-12-22 18:19:27642void TabContents::Stop() {
643 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25644 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27645}
646
[email protected]d9083482012-01-06 00:38:46647WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27648 // We create a new SiteInstance so that the new tab won't share processes
649 // with the old one. This can be changed in the future if we need it to share
650 // processes for some reason.
651 TabContents* tc = new TabContents(
652 GetBrowserContext(),
653 SiteInstance::CreateSiteInstance(GetBrowserContext()),
654 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20655 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27656 return tc;
657}
658
659void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17660 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27661 bool show_history) {
662 if (!delegate_)
663 return;
664
665 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
666}
667
[email protected]2a6bc3e2011-12-28 23:51:33668void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27669 WindowOpenDisposition disposition,
670 const gfx::Rect& initial_pos,
671 bool user_gesture) {
672 if (!delegate_)
673 return;
674
675 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
676 user_gesture);
677}
678
679gfx::NativeView TabContents::GetContentNativeView() const {
680 return view_->GetContentNativeView();
681}
682
683gfx::NativeView TabContents::GetNativeView() const {
684 return view_->GetNativeView();
685}
686
687void TabContents::GetContainerBounds(gfx::Rect* out) const {
688 view_->GetContainerBounds(out);
689}
690
691void TabContents::Focus() {
692 view_->Focus();
693}
694
[email protected]d8c660432011-12-22 20:51:25695void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31696 observers_.AddObserver(observer);
697}
698
[email protected]d8c660432011-12-22 20:51:25699void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31700 observers_.RemoveObserver(observer);
701}
702
[email protected]d5f942ba2008-09-26 19:30:34703void TabContents::Activate() {
704 if (delegate_)
705 delegate_->ActivateContents(this);
706}
707
[email protected]ea42e7782010-08-23 23:58:12708void TabContents::Deactivate() {
709 if (delegate_)
710 delegate_->DeactivateContents(this);
711}
712
[email protected]63954792011-07-11 04:17:48713void TabContents::LostCapture() {
714 if (delegate_)
715 delegate_->LostCapture();
716}
717
718bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
719 bool* is_keyboard_shortcut) {
720 return delegate_ &&
721 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
722}
723
724void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
725 if (delegate_)
726 delegate_->HandleKeyboardEvent(event);
727}
728
[email protected]32ded2212011-11-10 18:51:43729void TabContents::HandleMouseDown() {
730 if (delegate_)
731 delegate_->HandleMouseDown();
732}
733
[email protected]63954792011-07-11 04:17:48734void TabContents::HandleMouseUp() {
735 if (delegate_)
736 delegate_->HandleMouseUp();
737}
738
739void TabContents::HandleMouseActivate() {
740 if (delegate_)
741 delegate_->HandleMouseActivate();
742}
743
[email protected]8a5e0ca2011-08-25 06:30:47744void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
745 if (delegate_)
746 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
747}
748
[email protected]5d5f7af2011-10-01 01:38:12749bool TabContents::IsFullscreenForCurrentTab() const {
750 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
751}
752
[email protected]e9621112011-10-17 05:38:37753void TabContents::RequestToLockMouse() {
754 if (delegate_) {
755 delegate_->RequestToLockMouse(this);
756 } else {
757 GotResponseToLockMouseRequest(false);
758 }
759}
760
761void TabContents::LostMouseLock() {
762 if (delegate_)
763 delegate_->LostMouseLock();
764}
765
[email protected]0548c5352011-09-07 00:33:33766void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
767 if (delegate_)
768 delegate_->UpdatePreferredSize(this, pref_size);
769}
770
[email protected]32ded2212011-11-10 18:51:43771void TabContents::WebUISend(RenderViewHost* render_view_host,
772 const GURL& source_url,
773 const std::string& name,
774 const base::ListValue& args) {
775 if (delegate_)
776 delegate_->WebUISend(this, source_url, name, args);
777}
778
[email protected]e5d549d2011-12-28 01:29:20779WebContents* TabContents::OpenURL(const OpenURLParams& params) {
780 if (!delegate_)
781 return NULL;
[email protected]00c37fc2011-08-02 00:22:50782
[email protected]e5d549d2011-12-28 01:29:20783 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
784 // Notify observers.
785 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
786 DidOpenURL(params.url, params.referrer,
787 params.disposition, params.transition));
788 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34789}
790
[email protected]1ccb3568d2010-02-19 10:51:16791bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50792 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25793 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23794 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25795 reload_type);
[email protected]876bc832010-09-07 16:29:54796}
[email protected]96d185d2009-04-24 03:28:54797
[email protected]876bc832010-09-07 16:29:54798bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23799 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50800 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40801 // The renderer will reject IPC messages with URLs longer than
802 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51803 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40804 return false;
805
[email protected]dd11de52011-11-03 22:54:27806 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40807 if (!dest_render_view_host)
808 return false; // Unable to create the desired render view host.
809
[email protected]80a8fad2011-01-29 04:02:38810 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07811 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58812 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56813 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30814 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51815 entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43816#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51817 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43818#endif
[email protected]e091df82011-10-11 18:13:21819 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55820 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58821
[email protected]96d185d2009-04-24 03:28:54822 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44823 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52824 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44825 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51826 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54827
828 // Used for page load time metrics.
829 current_load_start_ = base::TimeTicks::Now();
830
831 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34832 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27833 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47834 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34835 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54836
[email protected]36fc0392011-12-25 03:59:51837 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54838 // HACK!! This code suppresses javascript: URLs from being added to
839 // session history, which is what we want to do for javascript: URLs that
840 // do not generate content. What we really need is a message from the
841 // renderer telling us that a new page was not created. The same message
842 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51843 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54844 return false;
845 }
846
[email protected]3c9e1872010-11-18 16:17:49847 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25848 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04849 observers_,
[email protected]36fc0392011-12-25 03:59:51850 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54851
[email protected]09b29342011-06-24 19:18:48852 if (delegate_)
853 delegate_->DidNavigateToPendingEntry(this);
854
[email protected]d5f942ba2008-09-26 19:30:34855 return true;
856}
857
[email protected]9e1ad4b2011-08-14 16:49:19858void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
859 int history_length,
860 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41861 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
862 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19863 if (render_manager_.pending_render_view_host()) {
864 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14865 return;
[email protected]9e1ad4b2011-08-14 16:49:19866 }
[email protected]151a63d2011-12-20 22:32:52867 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19868 if (!rvh) {
869 NOTREACHED();
870 return;
871 }
872 if (site_instance && rvh->site_instance() != site_instance) {
873 NOTREACHED();
874 return;
875 }
876 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
877 history_length,
878 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14879}
880
[email protected]90daadb42009-06-08 21:27:28881void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27882 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54883 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
884 return;
885 }
[email protected]151a63d2011-12-20 22:32:52886 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54887}
888
[email protected]0bfbf882011-12-22 18:19:27889bool TabContents::ShowingInterstitialPage() const {
890 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54891}
892
[email protected]0bfbf882011-12-22 18:19:27893InterstitialPage* TabContents::GetInterstitialPage() const {
894 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22895}
896
[email protected]c7dd2f62011-07-18 15:57:59897void TabContents::OnSavePage() {
898 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27899 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30900 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59901 const GURL& current_page_url = GetURL();
902 if (dlm && current_page_url.is_valid()) {
903 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46904 download_stats::RecordDownloadCount(
905 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59906 return;
907 }
908 }
909
910 Stop();
911
912 // Create the save package and possibly prompt the user for the name to save
913 // the page as. The user prompt is an asynchronous operation that runs on
914 // another thread.
915 save_package_ = new SavePackage(this);
916 save_package_->GetSaveInfo();
917}
918
919// Used in automated testing to bypass prompting the user for file names.
920// Instead, the names and paths are hard coded rather than running them through
921// file name sanitation and extension / mime checking.
922bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
923 SavePackage::SavePackageType save_type) {
924 // Stop the page from navigating.
925 Stop();
926
927 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
928 return save_package_->Init();
929}
930
[email protected]420ae012009-04-24 05:16:32931bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:23932 NavigationEntryImpl* active_entry =
933 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:32934 return (active_entry != NULL &&
935 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51936 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32937}
938
[email protected]0bfbf882011-12-22 18:19:27939const std::string& TabContents::GetContentsMimeType() const {
940 return contents_mime_type_;
941}
942
943bool TabContents::WillNotifyDisconnection() const {
944 return notify_disconnection_;
945}
946
[email protected]b2fe07d12010-02-09 14:38:08947void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31948 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52949 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
950 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16951}
952
[email protected]b2fe07d12010-02-09 14:38:08953void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31954 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52955 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
956 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16957}
958
[email protected]0bfbf882011-12-22 18:19:27959content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
960 return &renderer_preferences_;
961}
962
963void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
964 new_tab_start_time_ = time;
965}
966
967base::TimeTicks TabContents::GetNewTabStartTime() const {
968 return new_tab_start_time_;
969}
970
[email protected]7ab1e7d62009-10-14 23:32:01971void TabContents::OnCloseStarted() {
972 if (tab_close_start_time_.is_null())
973 tab_close_start_time_ = base::TimeTicks::Now();
974}
975
[email protected]46624bf2010-06-09 16:04:19976bool TabContents::ShouldAcceptDragAndDrop() const {
977#if defined(OS_CHROMEOS)
978 // ChromeOS panels (pop-ups) do not take drag-n-drop.
979 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51980 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20981 return false;
982 return true;
[email protected]46624bf2010-06-09 16:04:19983#else
984 return true;
985#endif
986}
987
[email protected]7813bd72011-02-05 02:19:34988void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52989 if (GetRenderViewHost())
990 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51991 if (delegate_)
992 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34993}
994
[email protected]0bfbf882011-12-22 18:19:27995void TabContents::SetClosedByUserGesture(bool value) {
996 closed_by_user_gesture_ = value;
997}
998
999bool TabContents::GetClosedByUserGesture() const {
1000 return closed_by_user_gesture_;
1001}
1002
[email protected]d0b8d092010-10-25 04:05:171003double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:301004 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:251005 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171006 return 0;
[email protected]b75b8292010-10-01 07:28:251007
1008 double zoom_level;
1009 if (temporary_zoom_settings_) {
1010 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521011 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251012 } else {
[email protected]2ae88d12011-10-14 09:11:191013 GURL url;
[email protected]10f417c52011-12-28 21:04:231014 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191015 // Since zoom map is updated using rewritten URL, use rewritten URL
1016 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511017 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191018 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251019 }
[email protected]d0b8d092010-10-25 04:05:171020 return zoom_level;
1021}
[email protected]b75b8292010-10-01 07:28:251022
[email protected]d0b8d092010-10-25 04:05:171023int TabContents::GetZoomPercent(bool* enable_increment,
1024 bool* enable_decrement) {
1025 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011026 // Calculate the zoom percent from the factor. Round up to the nearest whole
1027 // number.
[email protected]b75b8292010-10-01 07:28:251028 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011029 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251030 *enable_decrement = percent > minimum_zoom_percent_;
1031 *enable_increment = percent < maximum_zoom_percent_;
1032 return percent;
1033}
1034
[email protected]3c733bde2010-12-21 19:56:311035void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501036 if (!delegate_)
1037 return;
1038
[email protected]10f417c52011-12-28 21:04:231039 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501040 if (!active_entry)
1041 return;
1042
[email protected]36fc0392011-12-25 03:59:511043 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121044}
1045
[email protected]932b7a12011-03-09 12:50:271046void TabContents::ViewFrameSource(const GURL& url,
1047 const std::string& content_state) {
1048 if (!delegate_)
1049 return;
1050
1051 delegate_->ViewSourceForFrame(this, url, content_state);
1052}
1053
[email protected]0bfbf882011-12-22 18:19:271054int TabContents::GetMinimumZoomPercent() const {
1055 return minimum_zoom_percent_;
1056}
1057
1058int TabContents::GetMaximumZoomPercent() const {
1059 return maximum_zoom_percent_;
1060}
1061
1062int TabContents::GetContentRestrictions() const {
1063 return content_restrictions_;
1064}
1065
1066WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]f3f3b722012-01-07 01:29:431067 return content::GetContentClient()->browser()->GetWebUIFactory()->
1068 GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271069}
1070
1071WebUI* TabContents::GetWebUIForCurrentState() {
1072 // When there is a pending navigation entry, we want to use the pending WebUI
1073 // that goes along with it to control the basic flags. For example, we want to
1074 // show the pending URL in the URL bar, so we want the display_url flag to
1075 // be from the pending entry.
1076 //
1077 // The confusion comes because there are multiple possibilities for the
1078 // initial load in a tab as a side effect of the way the RenderViewHostManager
1079 // works.
1080 //
1081 // - For the very first tab the load looks "normal". The new tab Web UI is
1082 // the pending one, and we want it to apply here.
1083 //
1084 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1085 // get switched to the one previously associated with the new tab pages.
1086 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1087 // have a committed Web UI in this case.
1088 //
1089 // This condition handles all of these cases:
1090 //
1091 // - First load in first tab: no committed nav entry + pending nav entry +
1092 // pending dom ui:
1093 // -> Use pending Web UI if any.
1094 //
1095 // - First load in second tab: no committed nav entry + pending nav entry +
1096 // no pending Web UI:
1097 // -> Use the committed Web UI if any.
1098 //
1099 // - Second navigation in any tab: committed nav entry + pending nav entry:
1100 // -> Use pending Web UI if any.
1101 //
1102 // - Normal state with no load: committed nav entry + no pending nav entry:
1103 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251104 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271105 (controller_.GetLastCommittedEntry() ||
1106 render_manager_.pending_web_ui()))
1107 return render_manager_.pending_web_ui();
1108 return render_manager_.web_ui();
1109}
1110
1111bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1112 return GetRenderViewHost() ?
1113 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1114}
1115
1116bool TabContents::FocusLocationBarByDefault() {
1117 WebUI* web_ui = GetWebUIForCurrentState();
1118 if (web_ui)
1119 return web_ui->focus_location_bar_by_default();
[email protected]10f417c52011-12-28 21:04:231120 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511121 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271122 return true;
1123 return false;
1124}
1125
1126void TabContents::SetFocusToLocationBar(bool select_all) {
1127 if (delegate_)
1128 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211129}
1130
[email protected]8b5af492011-11-28 21:50:581131void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301132 const string16& type,
1133 const string16& href,
1134 const string16& title,
1135 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511136 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301137 this, action, type, href, title, disposition);
1138}
1139
[email protected]678105012011-12-09 04:01:211140void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301141 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001142 WebIntentsDispatcherImpl* intents_dispatcher =
1143 new WebIntentsDispatcherImpl(this, intent, intent_id);
1144 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301145}
1146
[email protected]724159a2010-12-30 01:11:181147void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1148 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591149 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181150 const GURL& url) {
1151 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1152 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521153 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301154 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181155
[email protected]8093a542011-05-13 07:29:321156 RenderViewHost* rvh =
1157 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521158 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101159 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251160 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101161 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321162 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101163
[email protected]724159a2010-12-30 01:11:181164 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591165 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251166 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591167 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181168 }
1169}
1170
1171void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591172 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181173 const GURL& source_url,
1174 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491175 // TODO(creis): Remove this method and have the pre-rendering code listen to
1176 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1177 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231178 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181179 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251180 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181181 else
1182 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511183 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181184 return;
[email protected]e7d50892011-01-19 21:47:381185
[email protected]4850a7f2011-03-08 23:36:591186 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251187 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261188 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591189 opener_url));
[email protected]724159a2010-12-30 01:11:181190}
1191
1192void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581193 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1194 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1195 << ", error_code: " << params.error_code
1196 << ", error_description: " << params.error_description
1197 << ", is_main_frame: " << params.is_main_frame
1198 << ", showing_repost_interstitial: " <<
1199 params.showing_repost_interstitial
1200 << ", frame_id: " << params.frame_id;
1201 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521202 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301203 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181204
[email protected]d7b175e2011-10-11 15:31:581205 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181206 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1207 // This means that the interstitial won't be torn down properly, which is
1208 // bad. But if we have an interstitial, go back to another tab type, and
1209 // then load the same interstitial again, we could end up getting the first
1210 // interstitial's "failed" message (as a result of the cancel) when we're on
1211 // the second one.
1212 //
1213 // We can't tell this apart, so we think we're tearing down the current page
1214 // which will cause a crash later one. There is also some code in
1215 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1216 // out because of this problem.
1217 //
1218 // http://code.google.com/p/chromium/issues/detail?id=2855
1219 // Because this will not tear down the interstitial properly, if "back" is
1220 // back to another tab type, the interstitial will still be somewhat alive
1221 // in the previous tab type. If you navigate somewhere that activates the
1222 // tab with the interstitial again, you'll see a flash before the new load
1223 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271224 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181225 LOG(WARNING) << "Discarding message during interstitial.";
1226 return;
1227 }
1228
[email protected]02102f82011-06-13 20:37:021229 // Discard our pending entry if the load canceled (e.g. if we decided to
1230 // download the file instead of load it). We do not verify that the URL
1231 // being canceled matches the pending entry's URL because they will not
1232 // match if a redirect occurred (in which case we do not want to leave a
1233 // stale redirect URL showing). This means that we also cancel the pending
1234 // entry if the user started a new navigation. As a result, the navigation
1235 // controller may not remember that a load is in progress, but the
1236 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251237 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161238 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181239
[email protected]151a63d2011-12-20 22:32:521240 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181241 }
1242
1243 // Send out a notification that we failed a provisional load with an error.
1244 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581245 params.is_main_frame,
1246 controller_.IsURLInPageNavigation(validated_url),
1247 validated_url,
1248 std::string(),
1249 false,
1250 params.frame_id);
1251 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181252
[email protected]ad50def52011-10-19 23:17:071253 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271254 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501255 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531256 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101257
[email protected]d8c660432011-12-22 20:51:251258 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581259 observers_,
1260 DidFailProvisionalLoad(params.frame_id,
1261 params.is_main_frame,
1262 validated_url,
1263 params.error_code,
1264 params.error_description));
[email protected]724159a2010-12-30 01:11:181265}
1266
1267void TabContents::OnDidLoadResourceFromMemoryCache(
1268 const GURL& url,
[email protected]70435962011-08-02 20:13:281269 const std::string& security_info,
1270 const std::string& http_method,
1271 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191272 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181273 cache.Increment();
1274
1275 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081276 int cert_id = 0;
1277 net::CertStatus cert_status = 0;
1278 int security_bits = -1;
1279 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181280 SSLManager::DeserializeSecurityInfo(security_info,
1281 &cert_id, &cert_status,
1282 &security_bits,
1283 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301284 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161285 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181286
[email protected]ad50def52011-10-19 23:17:071287 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271288 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501289 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531290 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181291}
1292
1293void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381294 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181295 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201296 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181297}
1298
1299void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021300 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231301 LOG(INFO) << security_origin << " ran insecure content from "
1302 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381303 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051304 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381305 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051306 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1307 }
[email protected]71fde352011-12-29 03:29:561308 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411309 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201310 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181311}
1312
1313void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1314 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251315 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101316 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181317}
1318
[email protected]1a55c5be2011-11-29 11:36:311319void TabContents::OnDidFinishLoad(
1320 int64 frame_id,
1321 const GURL& validated_url,
1322 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251323 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311324 DidFinishLoad(frame_id, validated_url, is_main_frame));
1325}
1326
1327void TabContents::OnDidFailLoadWithError(int64 frame_id,
1328 const GURL& validated_url,
1329 bool is_main_frame,
1330 int error_code,
1331 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311333 DidFailLoad(frame_id, validated_url, is_main_frame,
1334 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181335}
1336
[email protected]c8f73ab2011-01-22 00:05:171337void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271338 content_restrictions_ = restrictions;
1339 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171340}
1341
[email protected]216813952011-05-19 22:21:261342void TabContents::OnGoToEntryAtOffset(int offset) {
1343 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231344 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251345 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261346 if (!entry)
1347 return;
1348 // Note that we don't call NavigationController::GotToOffset() as we don't
1349 // want to create a pending navigation entry (it might end up lingering
1350 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251351 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581352 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511353 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581354 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471355 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571356
1357 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1358 // it in now that we know. This allows us to find the entry when it commits.
1359 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231360 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381361 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571362 }
[email protected]216813952011-05-19 22:21:261363 }
1364}
1365
1366void TabContents::OnUpdateZoomLimits(int minimum_percent,
1367 int maximum_percent,
1368 bool remember) {
1369 minimum_zoom_percent_ = minimum_percent;
1370 maximum_zoom_percent_ = maximum_percent;
1371 temporary_zoom_settings_ = !remember;
1372}
1373
[email protected]0bfbf882011-12-22 18:19:271374void TabContents::OnSaveURL(const GURL& url) {
1375 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1376 dlm->DownloadUrl(url, GetURL(), "", this);
1377}
1378
[email protected]3a29a6e2011-08-24 18:26:211379void TabContents::OnEnumerateDirectory(int request_id,
1380 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511381 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211382}
1383
[email protected]7d189022011-08-25 22:54:201384void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511385 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201386}
1387
1388void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1389 const GURL& url,
1390 const string16& title) {
[email protected]6934a702011-12-20 00:04:511391 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201392}
1393
[email protected]b888919c2011-09-02 00:32:161394void TabContents::OnFindReply(int request_id,
1395 int number_of_matches,
1396 const gfx::Rect& selection_rect,
1397 int active_match_ordinal,
1398 bool final_update) {
[email protected]6934a702011-12-20 00:04:511399 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1400 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001401 // Send a notification to the renderer that we are ready to receive more
1402 // results from the scoping effort of the Find operation. The FindInPage
1403 // scoping is asynchronous and periodically sends results back up to the
1404 // browser using IPC. In an effort to not spam the browser we have the
1405 // browser send an ACK for each FindReply message and have the renderer
1406 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521407 GetRenderViewHost()->Send(
1408 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161409}
1410
[email protected]d952a052011-09-06 18:42:451411void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511412 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451413}
1414
[email protected]7fc4bbb2011-09-08 21:23:101415void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1416 bool blocked_by_policy) {
1417 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101419 AppCacheAccessed(manifest_url, blocked_by_policy));
1420}
1421
[email protected]96d185d2009-04-24 03:28:541422// Notifies the RenderWidgetHost instance about the fact that the page is
1423// loading, or done loading and calls the base implementation.
1424void TabContents::SetIsLoading(bool is_loading,
1425 LoadNotificationDetails* details) {
1426 if (is_loading == is_loading_)
1427 return;
1428
1429 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211430 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541431 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561432 upload_size_ = 0;
1433 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541434 }
1435
1436 render_manager_.SetIsLoading(is_loading);
1437
1438 is_loading_ = is_loading;
1439 waiting_for_response_ = is_loading;
1440
[email protected]6ebdc9b2010-09-27 16:55:571441 if (delegate_)
1442 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461443 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541444
[email protected]432115822011-07-10 15:52:271445 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1446 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071447 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541448 if (details)
[email protected]6c2381d2011-10-19 02:52:531449 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071450 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501451 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541452 det);
1453}
1454
[email protected]420ae012009-04-24 05:16:321455void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131456 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321457 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561458 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381459 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441460 // that opened the window, as long as both renderers have the same
1461 // privileges.
[email protected]1fd1a502011-03-30 16:55:561462 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1463 WebUI* web_ui = content::GetContentClient()->browser()->
1464 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581465 // web_ui might be NULL if the URL refers to a non-existent extension.
1466 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401467 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521468 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441469 }
1470 }
[email protected]1fd1a502011-03-30 16:55:561471 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441472 }
1473
[email protected]4e697b042011-07-08 06:44:561474 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321475 // Clear the status bubble. This is a workaround for a bug where WebKit
1476 // doesn't let us know that the cursor left an element during a
1477 // transition (this is also why the mouse cursor remains as a hand after
1478 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1479 // clear the bubble when a user navigates to a named anchor in the same
1480 // page.
[email protected]36fc0392011-12-25 03:59:511481 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321482 }
1483
[email protected]a6e82fc2010-02-24 22:28:141484 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471485 // Once the main frame is navigated, we're no longer considered to have
1486 // displayed insecure content.
1487 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171488 }
[email protected]ce5c4502009-05-06 16:46:111489
[email protected]3c9e1872010-11-18 16:17:491490 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251491 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041492 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321493}
1494
1495void TabContents::DidNavigateAnyFramePostCommit(
1496 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131497 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321498 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071499 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321500 // a malicious script from spamming messages, since the script could just
1501 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551502 if (dialog_creator_) {
1503 dialog_creator_->ResetJavaScriptState(this);
1504 dialog_creator_ = NULL;
1505 }
[email protected]420ae012009-04-24 05:16:321506
[email protected]3c9e1872010-11-18 16:17:491507 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251508 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041509 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321510}
1511
[email protected]74ce1ad2011-12-16 21:51:461512void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1513 // If we are creating a RVH for a restored controller, then we need to make
1514 // sure the RenderView starts with a next_page_id_ larger than the number
1515 // of restored entries. This must be called before the RenderView starts
1516 // navigating (to avoid a race between the browser updating max_page_id and
1517 // the renderer updating next_page_id_). Because of this, we only call this
1518 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561519 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461520 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1521 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321522}
1523
[email protected]10f417c52011-12-28 21:04:231524bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571525 const string16& title) {
[email protected]420ae012009-04-24 05:16:321526 // For file URLs without a title, use the pathname instead. In the case of a
1527 // synthesized title, we don't want the update to count toward the "one set
1528 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511529 string16 final_title;
[email protected]420ae012009-04-24 05:16:321530 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511531 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1532 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321533 explicit_set = false; // Don't count synthetic titles toward the set limit.
1534 } else {
[email protected]acafd272011-07-26 17:35:571535 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321536 explicit_set = true;
1537 }
1538
[email protected]987fc3a2011-05-26 14:18:091539 // If a page is created via window.open and never navigated,
1540 // there will be no navigation entry. In this situation,
1541 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1542 if (entry) {
[email protected]36fc0392011-12-25 03:59:511543 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091544 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321545
[email protected]36fc0392011-12-25 03:59:511546 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091547 } else {
1548 if (page_title_when_no_navigation_entry_ == final_title)
1549 return false; // Nothing changed, don't bother.
1550
1551 page_title_when_no_navigation_entry_ = final_title;
1552 }
[email protected]420ae012009-04-24 05:16:321553
[email protected]420ae012009-04-24 05:16:321554 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231555 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321556
[email protected]105bb0f2011-05-24 17:12:141557 TitleUpdatedDetails details(entry, explicit_set);
1558
[email protected]ad50def52011-10-19 23:17:071559 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441560 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1561 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531562 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041563
[email protected]420ae012009-04-24 05:16:321564 return true;
1565}
1566
1567void TabContents::NotifySwapped() {
1568 // After sending out a swap notification, we need to send a disconnect
1569 // notification so that clients that pick up a pointer to |this| can NULL the
1570 // pointer. See Bug 1230284.
1571 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071572 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201573 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1574 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071575 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321576}
1577
1578void TabContents::NotifyConnected() {
1579 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071580 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121581 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1582 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071583 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321584}
1585
1586void TabContents::NotifyDisconnected() {
1587 if (!notify_disconnection_)
1588 return;
1589
1590 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071591 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321592 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1593 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071594 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321595}
1596
[email protected]8d3347f2009-07-09 22:00:211597RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321598 return view_.get();
1599}
1600
[email protected]8d3347f2009-07-09 22:00:211601RenderViewHostDelegate::RendererManagement*
1602TabContents::GetRendererManagementDelegate() {
1603 return &render_manager_;
1604}
1605
[email protected]daf82f82011-10-31 22:35:311606content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371607 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461608 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511609}
1610
[email protected]57c6a652009-05-04 07:58:341611TabContents* TabContents::GetAsTabContents() {
1612 return this;
1613}
1614
[email protected]768c5472011-12-26 19:06:171615WebContents* TabContents::GetAsWebContents() {
1616 return this;
1617}
1618
[email protected]da4dfc42011-10-12 15:53:561619content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431620 return view_type_;
[email protected]7b291f92009-08-14 05:43:531621}
1622
[email protected]420ae012009-04-24 05:16:321623void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071624 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271625 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321626 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531627 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231628 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321629 if (!entry)
1630 return;
1631
1632 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351633 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561634 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581635 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321636
1637 if (entry->IsViewSourceMode()) {
1638 // Put the renderer in view source mode.
1639 render_view_host->Send(
1640 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1641 }
[email protected]0666aef2009-05-13 19:48:081642
[email protected]d487beefe2011-12-21 05:41:211643 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261644
1645 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251646 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321647}
1648
1649void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521650 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321651 // Don't notify the world, since this came from a renderer in the
1652 // background.
1653 return;
1654 }
1655
1656 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311657 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231658 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301659
1660 // Restore the focus to the tab (otherwise the focus will be on the top
1661 // window).
[email protected]484ae5912010-09-29 19:16:141662 if (was_crashed && !FocusLocationBarByDefault() &&
1663 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301664 Focus();
[email protected]484ae5912010-09-29 19:16:141665 }
[email protected]32ded2212011-11-10 18:51:431666
[email protected]d8c660432011-12-22 20:51:251667 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321668}
1669
[email protected]443b80e2010-12-14 00:42:231670void TabContents::RenderViewGone(RenderViewHost* rvh,
1671 base::TerminationStatus status,
1672 int error_code) {
[email protected]151a63d2011-12-20 22:32:521673 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321674 // The pending page's RenderViewHost is gone.
1675 return;
1676 }
1677
1678 SetIsLoading(false, NULL);
1679 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231680 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311681 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321682
[email protected]d8c660432011-12-22 20:51:251683 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271684 observers_,
[email protected]be1f56ab2011-12-22 06:55:311685 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321686}
1687
[email protected]2e4633c2009-07-09 16:58:061688void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481689 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251690 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061691}
1692
[email protected]420ae012009-04-24 05:16:321693void TabContents::DidNavigate(RenderViewHost* rvh,
1694 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581695 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321696 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371697
[email protected]420ae012009-04-24 05:16:321698 // Update the site of the SiteInstance if it doesn't have one yet.
1699 if (!GetSiteInstance()->has_site())
1700 GetSiteInstance()->SetSite(params.url);
1701
1702 // Need to update MIME type here because it's referred to in
1703 // UpdateNavigationCommands() called by RendererDidNavigate() to
1704 // determine whether or not to enable the encoding menu.
1705 // It's updated only for the main frame. For a subframe,
1706 // RenderView::UpdateURL does not set params.contents_mime_type.
1707 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1708 // TODO(jungshik): Add a test for the encoding menu to avoid
1709 // regressing it again.
[email protected]2905f742011-10-13 03:51:581710 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321711 contents_mime_type_ = params.contents_mime_type;
1712
[email protected]8286f51a2011-05-31 17:39:131713 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001714 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391715
[email protected]a9c0bfe2010-09-17 08:35:221716 // Send notification about committed provisional loads. This notification is
1717 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1718 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081719 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071720 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1721 // that is not recorded in the navigation history. For the purpose of
1722 // tracking navigation events, we treat this event as a sub frame navigation
1723 // event.
1724 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581725 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221726 // Whether or not a page transition was triggered by going backward or
1727 // forward in the history is only stored in the navigation controller's
1728 // entry list.
1729 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511730 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581731 content::PAGE_TRANSITION_FORWARD_BACK)) {
1732 transition_type = content::PageTransitionFromInt(
1733 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221734 }
[email protected]0d60f0192011-04-14 12:40:101735 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251736 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101737 DidCommitProvisionalLoadForFrame(params.frame_id,
1738 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221739 }
1740
[email protected]76543b92009-08-31 17:27:451741 if (!did_navigate)
1742 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321743
1744 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1745 // for the appropriate notification (best) or you can add it to
1746 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1747 // necessary, please).
1748
1749 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001750 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321751 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511752 if (delegate_)
1753 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001754 }
[email protected]420ae012009-04-24 05:16:321755 DidNavigateAnyFramePostCommit(rvh, details, params);
1756}
1757
1758void TabContents::UpdateState(RenderViewHost* rvh,
1759 int32 page_id,
1760 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151761 // Ensure that this state update comes from either the active RVH or one of
1762 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521763 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321764
1765 // We must be prepared to handle state updates for any page, these occur
1766 // when the user is scrolling and entering form data, as well as when we're
1767 // leaving a page, in which case our state may have already been moved to
1768 // the next page. The navigation controller will look up the appropriate
1769 // NavigationEntry and update it when it is notified via the delegate.
1770
1771 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151772 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321773 if (entry_index < 0)
1774 return;
[email protected]10f417c52011-12-28 21:04:231775 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321776
[email protected]36fc0392011-12-25 03:59:511777 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321778 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511779 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321780 controller_.NotifyEntryChanged(entry, entry_index);
1781}
1782
1783void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571784 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461785 const string16& title,
1786 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321787 // If we have a title, that's a pretty good indication that we've started
1788 // getting useful data.
1789 SetNotWaitingForResponse();
1790
[email protected]151a63d2011-12-20 22:32:521791 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231792 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1793 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091794
[email protected]a49e10b2011-08-01 23:57:461795 // TODO(evan): make use of title_direction.
1796 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091797 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321798 return;
1799
1800 // Broadcast notifications when the UI should be updated.
1801 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:461802 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:321803}
1804
[email protected]420ae012009-04-24 05:16:321805void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401806 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311807 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321808}
1809
1810void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511811 if (delegate_)
1812 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321813}
1814
[email protected]420ae012009-04-24 05:16:321815void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291816 // The UI may be in an event-tracking loop, such as between the
1817 // mouse-down and mouse-up in text selection or a button click.
1818 // Defer the close until after tracking is complete, so that we
1819 // don't free objects out from under the UI.
1820 // TODO(shess): This could probably be integrated with the
1821 // IsDoingDrag() test below. Punting for now because I need more
1822 // research to understand how this impacts platforms other than Mac.
1823 // TODO(shess): This could get more fine-grained. For instance,
1824 // closing a tab in another window while selecting text in the
1825 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211826 if (GetView()->IsEventTracking()) {
1827 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291828 return;
1829 }
1830
[email protected]24a4d1062009-07-10 23:10:421831 // If we close the tab while we're in the middle of a drag, we'll crash.
1832 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211833 if (GetView()->IsDoingDrag()) {
1834 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421835 return;
1836 }
1837
[email protected]420ae012009-04-24 05:16:321838 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521839 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511840 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321841}
1842
[email protected]cd9ed79d2011-11-15 19:22:571843void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521844 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511845 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571846}
1847
[email protected]420ae012009-04-24 05:16:321848void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511849 if (delegate_ && delegate_->IsPopupOrPanel(this))
1850 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321851}
1852
[email protected]7ab1e7d62009-10-14 23:32:011853void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321854 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491855
[email protected]6934a702011-12-20 00:04:511856 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211857 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511858 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001859 }
[email protected]3c9e1872010-11-18 16:17:491860
1861 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251862 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321863}
1864
[email protected]7ab1e7d62009-10-14 23:32:011865void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321866 scoped_ptr<LoadNotificationDetails> details;
1867
[email protected]10f417c52011-12-28 21:04:231868 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321869 // An entry may not exist for a stop when loading an initial blank page or
1870 // if an iframe injected by script into a blank page finishes loading.
1871 if (entry) {
[email protected]420ae012009-04-24 05:16:321872 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1873
1874 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511875 entry->GetVirtualURL(),
1876 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321877 elapsed,
1878 &controller_,
1879 controller_.GetCurrentEntryIndex()));
1880 }
1881
[email protected]420ae012009-04-24 05:16:321882 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491883
1884 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251885 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321886}
1887
[email protected]c95fa8b2011-04-28 20:26:161888void TabContents::DidCancelLoading() {
1889 controller_.DiscardNonCommittedEntries();
1890
1891 // Update the URL display.
[email protected]d9083482012-01-06 00:38:461892 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:161893}
1894
[email protected]1a3c3cb2010-12-16 21:03:401895void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511896 if (delegate_)
1897 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401898}
1899
[email protected]952a68e2011-11-17 00:36:101900void TabContents::DocumentAvailableInMainFrame(
1901 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251902 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101903 DocumentAvailableInMainFrame());
1904}
1905
[email protected]25497492010-09-11 15:15:081906void TabContents::DocumentOnLoadCompletedInMainFrame(
1907 RenderViewHost* render_view_host,
1908 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071909 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271910 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321911 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531912 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081913}
1914
[email protected]ae5184d62011-10-06 19:25:581915void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151916 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581917 WindowOpenDisposition disposition,
1918 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481919 // Delegate to RequestTransferURL because this is just the generic
1920 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581921 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481922 GlobalRequestID());
1923}
1924
1925void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581926 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481927 WindowOpenDisposition disposition,
1928 int64 source_frame_id,
1929 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201930 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581931 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581932 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351933 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321934 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1935 // generated suggestions).
1936 //
[email protected]e0112912011-02-02 22:54:351937 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161938 // want web sites to see a referrer of "chrome://blah" (and some
1939 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321940 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581941 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481942 render_manager_.web_ui()->link_transition_type(),
1943 false /* is_renderer_initiated */);
1944 params.transferred_global_request_id = old_request_id;
1945 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581946 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321947 } else {
[email protected]4ad5d77d2011-12-03 02:00:481948 OpenURLParams params(url, referrer, disposition,
1949 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1950 params.transferred_global_request_id = old_request_id;
1951 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581952 }
1953 if (new_contents) {
1954 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251955 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581956 DidOpenRequestedURL(new_contents,
1957 url,
1958 referrer,
1959 disposition,
1960 transition_type,
1961 source_frame_id));
[email protected]420ae012009-04-24 05:16:321962 }
1963}
1964
[email protected]420ae012009-04-24 05:16:321965void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151966 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411967 const string16& message,
1968 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321969 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471970 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321971 IPC::Message* reply_msg,
1972 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071973 // Suppress JavaScript dialogs when requested. Also suppress messages when
1974 // showing an interstitial as it's shown over the previous page and we don't
1975 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501976 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151977 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271978 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071979 !delegate_ ||
1980 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321981
1982 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341983 content::JavaScriptDialogCreator::TitleType title_type;
1984 string16 title;
1985
1986 if (!frame_url.has_host()) {
1987 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1988 } else {
1989 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1990 title = net::FormatUrl(
1991 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201992 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301993 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341994 }
1995
[email protected]2e5b90c2011-08-16 21:11:551996 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1997 dialog_creator_->RunJavaScriptDialog(this,
1998 title_type,
1999 title,
[email protected]269f86d2011-12-07 02:43:472000 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:552001 message,
2002 default_prompt,
2003 reply_msg,
2004 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322005 }
[email protected]3ab9cb82011-06-03 18:02:072006
2007 if (suppress_this_message) {
2008 // If we are suppressing messages, just reply as if the user immediately
2009 // pressed "Cancel".
2010 OnDialogClosed(reply_msg, false, string16());
2011 }
2012
2013 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322014}
2015
[email protected]992db4c2011-05-12 15:37:152016void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412017 const string16& message,
[email protected]420ae012009-04-24 05:16:322018 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512019 if (delegate_)
2020 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072021
2022 bool suppress_this_message =
2023 rvh->is_swapped_out() ||
2024 !delegate_ ||
2025 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152026 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522027 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502028 return;
2029 }
[email protected]3ab9cb82011-06-03 18:02:072030
[email protected]7ab1e7d62009-10-14 23:32:012031 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552032 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2033 dialog_creator_->RunBeforeUnloadDialog(this,
2034 message,
2035 reply_msg);
[email protected]420ae012009-04-24 05:16:322036}
2037
[email protected]420ae012009-04-24 05:16:322038WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082039 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362040 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522041 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082042
[email protected]b8299c12011-06-03 19:52:282043 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212044 // chrome-devtools: pages (unless it's specifically allowed).
2045 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572046 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282047 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302048 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2049 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212050 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082051 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432052 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082053 }
2054
2055 return web_prefs;
[email protected]420ae012009-04-24 05:16:322056}
2057
[email protected]7d472472011-01-22 01:30:252058void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272059 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252060 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222061
[email protected]99907362012-01-11 05:41:402062 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172063 if (rdh) // NULL in unittests.
2064 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252065}
2066
[email protected]fa1cf0b82010-01-15 21:49:442067void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442068 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252069 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442070}
2071
[email protected]420ae012009-04-24 05:16:322072void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2073 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152074 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522075 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152076 return;
2077
[email protected]e5fc1632011-08-08 07:51:532078 // Ignore renderer unresponsive event if debugger is attached to the tab
2079 // since the event may be a result of the renderer sitting on a breakpoint.
2080 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442081 DevToolsAgentHost* agent =
2082 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2083 if (agent &&
2084 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532085 return;
2086
[email protected]420ae012009-04-24 05:16:322087 if (is_during_unload) {
2088 // Hang occurred while firing the beforeunload/unload handler.
2089 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112090 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322091
2092 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2093 return;
2094
2095 // If the tab hangs in the beforeunload/unload handler there's really
2096 // nothing we can do to recover. Pretend the unload listeners have
2097 // all fired and close the tab. If the hang is in the beforeunload handler
2098 // then the user will not have the option of cancelling the close.
2099 Close(rvh);
2100 return;
2101 }
2102
[email protected]151a63d2011-12-20 22:32:522103 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472104 return;
2105
[email protected]6934a702011-12-20 00:04:512106 if (delegate_)
2107 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322108}
2109
2110void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512111 if (delegate_)
2112 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322113}
2114
2115void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212116 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562117 uint64 upload_position,
2118 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322119 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562120 upload_position_ = upload_position;
2121 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502122 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202123 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302124 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212125 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322126 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462127 if (IsLoading()) {
2128 NotifyNavigationStateChanged(
2129 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2130 }
[email protected]420ae012009-04-24 05:16:322131}
2132
[email protected]7d472472011-01-22 01:30:252133void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512134 if (delegate_)
2135 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252136}
2137
[email protected]420ae012009-04-24 05:16:322138void TabContents::BeforeUnloadFiredFromRenderManager(
2139 bool proceed,
2140 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512141 if (delegate_)
2142 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322143}
2144
[email protected]3a3d47472010-07-15 21:03:542145void TabContents::DidStartLoadingFromRenderManager(
2146 RenderViewHost* render_view_host) {
2147 DidStartLoading();
2148}
2149
2150void TabContents::RenderViewGoneFromRenderManager(
2151 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232152 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2153 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542154}
2155
[email protected]420ae012009-04-24 05:16:322156void TabContents::UpdateRenderViewSizeForRenderManager() {
2157 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262158 gfx::Size size = view_->GetContainerSize();
2159 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2160 // here during container initialization and normal window size will be set
2161 // later. In case of tab duplication this resizing to 0x0 prevents setting
2162 // normal size later so just ignore it.
2163 if (!size.IsEmpty())
2164 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322165}
2166
[email protected]3a3d47472010-07-15 21:03:542167void TabContents::NotifySwappedFromRenderManager() {
2168 NotifySwapped();
2169}
2170
[email protected]d202a7c2012-01-04 07:53:472171NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202172 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542173}
2174
[email protected]d0980792011-02-13 19:41:402175WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]f3f3b722012-01-07 01:29:432176 return content::GetContentClient()->browser()->GetWebUIFactory()->
2177 CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322178}
2179
[email protected]10f417c52011-12-28 21:04:232180NavigationEntry*
2181 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322182 return controller_.GetLastCommittedEntry();
2183}
2184
2185bool TabContents::CreateRenderViewForRenderManager(
2186 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442187 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322188 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522189
[email protected]420ae012009-04-24 05:16:322190 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442191 if (rwh_view)
2192 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322193
[email protected]74ce1ad2011-12-16 21:51:462194 // Make sure we use the correct starting page_id in the new RenderView.
2195 UpdateMaxPageIDIfNecessary(render_view_host);
2196 int32 max_page_id =
2197 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2198
2199 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522200 return false;
2201
[email protected]e60c0232011-11-11 19:56:352202#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502203 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2204 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442205 if (rwh_view) {
2206 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2207 render_widget_host->WasResized();
2208 }
[email protected]f8233cc2011-05-31 20:24:502209#endif
2210
[email protected]420ae012009-04-24 05:16:322211 return true;
2212}
2213
[email protected]3ab9cb82011-06-03 18:02:072214void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2215 bool success,
2216 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542217 if (is_showing_before_unload_dialog_ && !success) {
2218 // If a beforeunload dialog is canceled, we need to stop the throbber from
2219 // spinning, since we forced it to start spinning in Navigate.
2220 DidStopLoading();
2221
2222 tab_close_start_time_ = base::TimeTicks();
2223 }
2224 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522225 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542226}
2227
[email protected]0b08add2011-11-29 03:27:062228gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072229 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542230}
2231
[email protected]a1e97f02011-06-30 14:04:342232void TabContents::OnDialogShown() {
2233 Activate();
[email protected]3a3d47472010-07-15 21:03:542234}
2235
[email protected]be1f56ab2011-12-22 06:55:312236void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122237 encoding_ = content::GetContentClient()->browser()->
2238 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102239}
[email protected]f45d2a72010-03-08 23:28:352240
[email protected]33f74972010-12-08 16:40:362241void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212242 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442243 // Can be NULL during tests.
2244 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212245 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362246}