blob: 8ea6a1facb30cb548397c06dbc1b69311fcef063 [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]765187182012-01-11 23:59:28300RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
301 return &render_manager_;
302}
303
[email protected]724159a2010-12-30 01:11:18304bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]be1f56ab2011-12-22 06:55:31305 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17306 return true;
307
[email protected]d8c660432011-12-22 20:51:25308 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
309 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10310 while ((observer = it.GetNext()) != NULL)
311 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53312 return true;
[email protected]403415a2011-01-10 18:57:53313
[email protected]724159a2010-12-30 01:11:18314 bool handled = true;
315 bool message_is_ok = true;
316 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58317 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
318 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24319 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
320 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18321 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
322 OnDidStartProvisionalLoadForFrame)
323 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
324 OnDidRedirectProvisionalLoad)
325 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
326 OnDidFailProvisionalLoadWithError)
327 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
328 OnDidLoadResourceFromMemoryCache)
329 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
330 OnDidDisplayInsecureContent)
331 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
332 OnDidRunInsecureContent)
333 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
334 OnDocumentLoadedInFrame)
335 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17336 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
337 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25338 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26339 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59340 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21341 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20342 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
343 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
344 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16345 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45346 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10347 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18348 IPC_MESSAGE_UNHANDLED(handled = false)
349 IPC_END_MESSAGE_MAP_EX()
350
351 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38352 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18353 GetRenderProcessHost()->ReceivedBadMessage();
354 }
355
356 return handled;
357}
358
[email protected]6c2e472f2011-08-24 23:26:18359void TabContents::RunFileChooser(
360 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23361 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51362 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18363}
364
[email protected]c5eed492012-01-04 17:07:50365NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56366 return controller_;
367}
368
[email protected]c5eed492012-01-04 17:07:50369const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56370 return controller_;
371}
372
[email protected]627e0512011-12-21 22:55:30373content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55374 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30375}
376
[email protected]f5fa20e2011-12-21 22:35:56377void TabContents::SetViewType(content::ViewType type) {
378 view_type_ = type;
379}
380
[email protected]ea049a02011-12-25 21:37:09381content::ViewType TabContents::GetViewType() const {
382 return view_type_;
383}
384
[email protected]be1f56ab2011-12-22 06:55:31385const GURL& TabContents::GetURL() const {
386 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23387 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51388 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31389}
390
391
392const base::PropertyBag* TabContents::GetPropertyBag() const {
393 return &property_bag_;
394}
395
396base::PropertyBag* TabContents::GetPropertyBag() {
397 return &property_bag_;
398}
399
400content::WebContentsDelegate* TabContents::GetDelegate() {
401 return delegate_;
402}
403
404void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
405 // TODO(cbentzel): remove this debugging code?
406 if (delegate == delegate_)
407 return;
408 if (delegate_)
409 delegate_->Detach(this);
410 delegate_ = delegate;
411 if (delegate_)
412 delegate_->Attach(this);
413}
414
[email protected]f3b1a082011-11-18 00:34:30415content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03416 if (render_manager_.current_host())
417 return render_manager_.current_host()->process();
418 else
419 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16420}
421
[email protected]be1f56ab2011-12-22 06:55:31422RenderViewHost* TabContents::GetRenderViewHost() const {
423 return render_manager_.current_host();
424}
425
426RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
427 return render_manager_.GetRenderWidgetHostView();
428}
429
430TabContentsView* TabContents::GetView() const {
431 return view_.get();
432}
433
434WebUI* TabContents::GetWebUI() const {
435 return render_manager_.web_ui() ? render_manager_.web_ui()
436 : render_manager_.pending_web_ui();
437}
438
439WebUI* TabContents::GetCommittedWebUI() const {
440 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34441}
442
[email protected]96d185d2009-04-24 03:28:54443const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55444 // Transient entries take precedence. They are used for interstitial pages
445 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23446 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08447 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20448 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30449 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23450 if (entry) {
[email protected]b5cca982011-05-26 04:42:08451 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23452 }
[email protected]7ade2732011-02-10 00:13:58453 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
454 render_manager_.pending_web_ui() : render_manager_.web_ui();
455 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54456 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55457 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54458 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35459 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58460 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54461 if (!title.empty())
462 return title;
463 }
464 }
465
466 // We use the title for the last committed entry rather than a pending
467 // navigation entry. For example, when the user types in a URL, we want to
468 // keep the old page's title until the new load has committed and we get a new
469 // title.
[email protected]96d185d2009-04-24 03:28:54470 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23471 if (entry) {
[email protected]b5cca982011-05-26 04:42:08472 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23473 }
[email protected]987fc3a2011-05-26 14:18:09474
475 // |page_title_when_no_navigation_entry_| is finally used
476 // if no title cannot be retrieved.
477 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54478}
479
[email protected]d5f942ba2008-09-26 19:30:34480int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46481 return GetMaxPageIDForSiteInstance(GetSiteInstance());
482}
483
484int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
485 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
486 max_page_ids_[site_instance->id()] = -1;
487
488 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34489}
490
491void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46492 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
493}
494
495void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
496 int32 page_id) {
497 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
498 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34499}
500
[email protected]91854cd2012-01-10 19:43:57501void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
502 max_page_ids_ = tab_contents->max_page_ids_;
503}
504
[email protected]96d185d2009-04-24 03:28:54505SiteInstance* TabContents::GetSiteInstance() const {
506 return render_manager_.current_host()->site_instance();
507}
508
[email protected]77362eb2011-08-01 17:18:38509SiteInstance* TabContents::GetPendingSiteInstance() const {
510 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
511 render_manager_.pending_render_view_host() :
512 render_manager_.current_host();
513 return dest_rvh->site_instance();
514}
515
[email protected]be1f56ab2011-12-22 06:55:31516bool TabContents::IsLoading() const {
517 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49518}
519
[email protected]be1f56ab2011-12-22 06:55:31520bool TabContents::IsWaitingForResponse() const {
521 return waiting_for_response_;
522}
523
524const net::LoadStateWithParam& TabContents::GetLoadState() const {
525 return load_state_;
526}
527
528const string16& TabContents::GetLoadStateHost() const {
529 return load_state_host_;
530}
531
532uint64 TabContents::GetUploadSize() const {
533 return upload_size_;
534}
535
536uint64 TabContents::GetUploadPosition() const {
537 return upload_position_;
538}
539
540const std::string& TabContents::GetEncoding() const {
541 return encoding_;
542}
543
544bool TabContents::DisplayedInsecureContent() const {
545 return displayed_insecure_content_;
546}
547
548void TabContents::SetCapturingContents(bool cap) {
549 capturing_contents_ = cap;
550}
551
552bool TabContents::IsCrashed() const {
553 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
554 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
555 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49556}
557
[email protected]443b80e2010-12-14 00:42:23558void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
559 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34560 return;
561
[email protected]443b80e2010-12-14 00:42:23562 crashed_status_ = status;
563 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46564 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34565}
566
[email protected]be1f56ab2011-12-22 06:55:31567base::TerminationStatus TabContents::GetCrashedStatus() const {
568 return crashed_status_;
569}
570
571bool TabContents::IsBeingDestroyed() const {
572 return is_being_destroyed_;
573}
574
[email protected]d5f942ba2008-09-26 19:30:34575void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
576 if (delegate_)
577 delegate_->NavigationStateChanged(this, changed_flags);
578}
579
[email protected]96d185d2009-04-24 03:28:54580void TabContents::DidBecomeSelected() {
581 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16582 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
583 if (rwhv) {
584 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43585#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16586 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43587#endif
588 }
[email protected]96d185d2009-04-24 03:28:54589
[email protected]5ac20162010-11-24 23:33:11590 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38591
[email protected]d8c660432011-12-22 20:51:25592 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54593}
594
[email protected]be1f56ab2011-12-22 06:55:31595
596base::TimeTicks TabContents::GetLastSelectedTime() const {
597 return last_selected_time_;
598}
599
[email protected]96d185d2009-04-24 03:28:54600void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31601 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52602 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
603 // open a tab in then background, then closes the tab before selecting it.
604 // This is because closing the tab calls TabContents::Destroy(), which
605 // removes the |GetRenderViewHost()|; then when we actually destroy the
606 // window, OnWindowPosChanged() notices and calls HideContents() (which
607 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16608 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
609 if (rwhv)
610 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54611 }
612
[email protected]ad50def52011-10-19 23:17:07613 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09614 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
615 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07616 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54617}
618
[email protected]be1f56ab2011-12-22 06:55:31619void TabContents::ShowContents() {
620 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
621 if (rwhv)
622 rwhv->DidBecomeSelected();
623}
624
625void TabContents::HideContents() {
626 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
627 // our superclass HideContents(), because some callers want to be very picky
628 // about the order in which these get called. In addition to making the code
629 // here practically impossible to understand, this also means we end up
630 // calling TabContents::WasHidden() twice if callers call both versions of
631 // HideContents() on a TabContents.
632 WasHidden();
633}
634
635bool TabContents::NeedToFireBeforeUnload() {
636 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27637 return WillNotifyDisconnection() &&
638 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31639 !GetRenderViewHost()->SuddenTerminationAllowed();
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) {
[email protected]bcd2815602012-01-14 18:17:23767 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:33768 if (delegate_)
769 delegate_->UpdatePreferredSize(this, pref_size);
770}
771
[email protected]32ded2212011-11-10 18:51:43772void TabContents::WebUISend(RenderViewHost* render_view_host,
773 const GURL& source_url,
774 const std::string& name,
775 const base::ListValue& args) {
776 if (delegate_)
777 delegate_->WebUISend(this, source_url, name, args);
778}
779
[email protected]e5d549d2011-12-28 01:29:20780WebContents* TabContents::OpenURL(const OpenURLParams& params) {
781 if (!delegate_)
782 return NULL;
[email protected]00c37fc2011-08-02 00:22:50783
[email protected]e5d549d2011-12-28 01:29:20784 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
785 // Notify observers.
786 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
787 DidOpenURL(params.url, params.referrer,
788 params.disposition, params.transition));
789 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34790}
791
[email protected]1ccb3568d2010-02-19 10:51:16792bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:50793 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25794 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23795 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25796 reload_type);
[email protected]876bc832010-09-07 16:29:54797}
[email protected]96d185d2009-04-24 03:28:54798
[email protected]876bc832010-09-07 16:29:54799bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23800 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50801 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40802 // The renderer will reject IPC messages with URLs longer than
803 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51804 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40805 return false;
806
[email protected]dd11de52011-11-03 22:54:27807 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40808 if (!dest_render_view_host)
809 return false; // Unable to create the desired render view host.
810
[email protected]80a8fad2011-01-29 04:02:38811 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07812 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58813 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56814 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30815 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51816 entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43817#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51818 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43819#endif
[email protected]e091df82011-10-11 18:13:21820 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55821 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58822
[email protected]96d185d2009-04-24 03:28:54823 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44824 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52825 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44826 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51827 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54828
829 // Used for page load time metrics.
830 current_load_start_ = base::TimeTicks::Now();
831
832 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34833 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27834 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47835 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34836 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54837
[email protected]36fc0392011-12-25 03:59:51838 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54839 // HACK!! This code suppresses javascript: URLs from being added to
840 // session history, which is what we want to do for javascript: URLs that
841 // do not generate content. What we really need is a message from the
842 // renderer telling us that a new page was not created. The same message
843 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51844 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54845 return false;
846 }
847
[email protected]3c9e1872010-11-18 16:17:49848 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25849 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04850 observers_,
[email protected]36fc0392011-12-25 03:59:51851 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54852
[email protected]09b29342011-06-24 19:18:48853 if (delegate_)
854 delegate_->DidNavigateToPendingEntry(this);
855
[email protected]d5f942ba2008-09-26 19:30:34856 return true;
857}
858
[email protected]9e1ad4b2011-08-14 16:49:19859void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
860 int history_length,
861 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41862 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
863 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19864 if (render_manager_.pending_render_view_host()) {
865 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14866 return;
[email protected]9e1ad4b2011-08-14 16:49:19867 }
[email protected]151a63d2011-12-20 22:32:52868 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19869 if (!rvh) {
870 NOTREACHED();
871 return;
872 }
873 if (site_instance && rvh->site_instance() != site_instance) {
874 NOTREACHED();
875 return;
876 }
877 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
878 history_length,
879 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14880}
881
[email protected]90daadb42009-06-08 21:27:28882void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27883 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54884 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
885 return;
886 }
[email protected]151a63d2011-12-20 22:32:52887 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54888}
889
[email protected]0bfbf882011-12-22 18:19:27890bool TabContents::ShowingInterstitialPage() const {
891 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54892}
893
[email protected]0bfbf882011-12-22 18:19:27894InterstitialPage* TabContents::GetInterstitialPage() const {
895 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22896}
897
[email protected]c7dd2f62011-07-18 15:57:59898void TabContents::OnSavePage() {
899 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27900 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30901 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59902 const GURL& current_page_url = GetURL();
903 if (dlm && current_page_url.is_valid()) {
904 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46905 download_stats::RecordDownloadCount(
906 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59907 return;
908 }
909 }
910
911 Stop();
912
913 // Create the save package and possibly prompt the user for the name to save
914 // the page as. The user prompt is an asynchronous operation that runs on
915 // another thread.
916 save_package_ = new SavePackage(this);
917 save_package_->GetSaveInfo();
918}
919
920// Used in automated testing to bypass prompting the user for file names.
921// Instead, the names and paths are hard coded rather than running them through
922// file name sanitation and extension / mime checking.
923bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
924 SavePackage::SavePackageType save_type) {
925 // Stop the page from navigating.
926 Stop();
927
928 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
929 return save_package_->Init();
930}
931
[email protected]420ae012009-04-24 05:16:32932bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:23933 NavigationEntryImpl* active_entry =
934 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:32935 return (active_entry != NULL &&
936 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51937 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32938}
939
[email protected]0bfbf882011-12-22 18:19:27940const std::string& TabContents::GetContentsMimeType() const {
941 return contents_mime_type_;
942}
943
944bool TabContents::WillNotifyDisconnection() const {
945 return notify_disconnection_;
946}
947
[email protected]b2fe07d12010-02-09 14:38:08948void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31949 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52950 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
951 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16952}
953
[email protected]b2fe07d12010-02-09 14:38:08954void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31955 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52956 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
957 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16958}
959
[email protected]0bfbf882011-12-22 18:19:27960content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
961 return &renderer_preferences_;
962}
963
964void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
965 new_tab_start_time_ = time;
966}
967
968base::TimeTicks TabContents::GetNewTabStartTime() const {
969 return new_tab_start_time_;
970}
971
[email protected]7ab1e7d62009-10-14 23:32:01972void TabContents::OnCloseStarted() {
973 if (tab_close_start_time_.is_null())
974 tab_close_start_time_ = base::TimeTicks::Now();
975}
976
[email protected]46624bf2010-06-09 16:04:19977bool TabContents::ShouldAcceptDragAndDrop() const {
978#if defined(OS_CHROMEOS)
979 // ChromeOS panels (pop-ups) do not take drag-n-drop.
980 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51981 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20982 return false;
983 return true;
[email protected]46624bf2010-06-09 16:04:19984#else
985 return true;
986#endif
987}
988
[email protected]7813bd72011-02-05 02:19:34989void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52990 if (GetRenderViewHost())
991 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51992 if (delegate_)
993 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34994}
995
[email protected]0bfbf882011-12-22 18:19:27996void TabContents::SetClosedByUserGesture(bool value) {
997 closed_by_user_gesture_ = value;
998}
999
1000bool TabContents::GetClosedByUserGesture() const {
1001 return closed_by_user_gesture_;
1002}
1003
[email protected]d0b8d092010-10-25 04:05:171004double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:301005 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:251006 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171007 return 0;
[email protected]b75b8292010-10-01 07:28:251008
1009 double zoom_level;
1010 if (temporary_zoom_settings_) {
1011 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521012 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251013 } else {
[email protected]2ae88d12011-10-14 09:11:191014 GURL url;
[email protected]10f417c52011-12-28 21:04:231015 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191016 // Since zoom map is updated using rewritten URL, use rewritten URL
1017 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511018 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191019 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251020 }
[email protected]d0b8d092010-10-25 04:05:171021 return zoom_level;
1022}
[email protected]b75b8292010-10-01 07:28:251023
[email protected]d0b8d092010-10-25 04:05:171024int TabContents::GetZoomPercent(bool* enable_increment,
1025 bool* enable_decrement) {
1026 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011027 // Calculate the zoom percent from the factor. Round up to the nearest whole
1028 // number.
[email protected]b75b8292010-10-01 07:28:251029 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011030 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251031 *enable_decrement = percent > minimum_zoom_percent_;
1032 *enable_increment = percent < maximum_zoom_percent_;
1033 return percent;
1034}
1035
[email protected]3c733bde2010-12-21 19:56:311036void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501037 if (!delegate_)
1038 return;
1039
[email protected]10f417c52011-12-28 21:04:231040 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501041 if (!active_entry)
1042 return;
1043
[email protected]36fc0392011-12-25 03:59:511044 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121045}
1046
[email protected]932b7a12011-03-09 12:50:271047void TabContents::ViewFrameSource(const GURL& url,
1048 const std::string& content_state) {
1049 if (!delegate_)
1050 return;
1051
1052 delegate_->ViewSourceForFrame(this, url, content_state);
1053}
1054
[email protected]0bfbf882011-12-22 18:19:271055int TabContents::GetMinimumZoomPercent() const {
1056 return minimum_zoom_percent_;
1057}
1058
1059int TabContents::GetMaximumZoomPercent() const {
1060 return maximum_zoom_percent_;
1061}
1062
[email protected]bcd2815602012-01-14 18:17:231063gfx::Size TabContents::GetPreferredSize() const {
1064 return preferred_size_;
1065}
1066
[email protected]0bfbf882011-12-22 18:19:271067int TabContents::GetContentRestrictions() const {
1068 return content_restrictions_;
1069}
1070
1071WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]f3f3b722012-01-07 01:29:431072 return content::GetContentClient()->browser()->GetWebUIFactory()->
1073 GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271074}
1075
1076WebUI* TabContents::GetWebUIForCurrentState() {
1077 // When there is a pending navigation entry, we want to use the pending WebUI
1078 // that goes along with it to control the basic flags. For example, we want to
1079 // show the pending URL in the URL bar, so we want the display_url flag to
1080 // be from the pending entry.
1081 //
1082 // The confusion comes because there are multiple possibilities for the
1083 // initial load in a tab as a side effect of the way the RenderViewHostManager
1084 // works.
1085 //
1086 // - For the very first tab the load looks "normal". The new tab Web UI is
1087 // the pending one, and we want it to apply here.
1088 //
1089 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1090 // get switched to the one previously associated with the new tab pages.
1091 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1092 // have a committed Web UI in this case.
1093 //
1094 // This condition handles all of these cases:
1095 //
1096 // - First load in first tab: no committed nav entry + pending nav entry +
1097 // pending dom ui:
1098 // -> Use pending Web UI if any.
1099 //
1100 // - First load in second tab: no committed nav entry + pending nav entry +
1101 // no pending Web UI:
1102 // -> Use the committed Web UI if any.
1103 //
1104 // - Second navigation in any tab: committed nav entry + pending nav entry:
1105 // -> Use pending Web UI if any.
1106 //
1107 // - Normal state with no load: committed nav entry + no pending nav entry:
1108 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251109 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271110 (controller_.GetLastCommittedEntry() ||
1111 render_manager_.pending_web_ui()))
1112 return render_manager_.pending_web_ui();
1113 return render_manager_.web_ui();
1114}
1115
1116bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1117 return GetRenderViewHost() ?
1118 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1119}
1120
1121bool TabContents::FocusLocationBarByDefault() {
1122 WebUI* web_ui = GetWebUIForCurrentState();
1123 if (web_ui)
1124 return web_ui->focus_location_bar_by_default();
[email protected]10f417c52011-12-28 21:04:231125 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511126 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271127 return true;
1128 return false;
1129}
1130
1131void TabContents::SetFocusToLocationBar(bool select_all) {
1132 if (delegate_)
1133 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211134}
1135
[email protected]8b5af492011-11-28 21:50:581136void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301137 const string16& type,
1138 const string16& href,
1139 const string16& title,
1140 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511141 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301142 this, action, type, href, title, disposition);
1143}
1144
[email protected]678105012011-12-09 04:01:211145void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301146 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001147 WebIntentsDispatcherImpl* intents_dispatcher =
1148 new WebIntentsDispatcherImpl(this, intent, intent_id);
1149 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301150}
1151
[email protected]724159a2010-12-30 01:11:181152void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1153 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591154 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181155 const GURL& url) {
1156 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1157 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521158 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301159 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181160
[email protected]8093a542011-05-13 07:29:321161 RenderViewHost* rvh =
1162 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521163 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101164 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101166 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321167 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101168
[email protected]724159a2010-12-30 01:11:181169 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591170 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251171 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591172 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181173 }
1174}
1175
1176void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591177 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181178 const GURL& source_url,
1179 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491180 // TODO(creis): Remove this method and have the pre-rendering code listen to
1181 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1182 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231183 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181184 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251185 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181186 else
1187 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511188 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181189 return;
[email protected]e7d50892011-01-19 21:47:381190
[email protected]4850a7f2011-03-08 23:36:591191 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251192 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261193 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591194 opener_url));
[email protected]724159a2010-12-30 01:11:181195}
1196
1197void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581198 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1199 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1200 << ", error_code: " << params.error_code
1201 << ", error_description: " << params.error_description
1202 << ", is_main_frame: " << params.is_main_frame
1203 << ", showing_repost_interstitial: " <<
1204 params.showing_repost_interstitial
1205 << ", frame_id: " << params.frame_id;
1206 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521207 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301208 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181209
[email protected]d7b175e2011-10-11 15:31:581210 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181211 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1212 // This means that the interstitial won't be torn down properly, which is
1213 // bad. But if we have an interstitial, go back to another tab type, and
1214 // then load the same interstitial again, we could end up getting the first
1215 // interstitial's "failed" message (as a result of the cancel) when we're on
1216 // the second one.
1217 //
1218 // We can't tell this apart, so we think we're tearing down the current page
1219 // which will cause a crash later one. There is also some code in
1220 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1221 // out because of this problem.
1222 //
1223 // http://code.google.com/p/chromium/issues/detail?id=2855
1224 // Because this will not tear down the interstitial properly, if "back" is
1225 // back to another tab type, the interstitial will still be somewhat alive
1226 // in the previous tab type. If you navigate somewhere that activates the
1227 // tab with the interstitial again, you'll see a flash before the new load
1228 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271229 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181230 LOG(WARNING) << "Discarding message during interstitial.";
1231 return;
1232 }
1233
[email protected]02102f82011-06-13 20:37:021234 // Discard our pending entry if the load canceled (e.g. if we decided to
1235 // download the file instead of load it). We do not verify that the URL
1236 // being canceled matches the pending entry's URL because they will not
1237 // match if a redirect occurred (in which case we do not want to leave a
1238 // stale redirect URL showing). This means that we also cancel the pending
1239 // entry if the user started a new navigation. As a result, the navigation
1240 // controller may not remember that a load is in progress, but the
1241 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251242 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161243 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181244
[email protected]151a63d2011-12-20 22:32:521245 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181246 }
1247
1248 // Send out a notification that we failed a provisional load with an error.
1249 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581250 params.is_main_frame,
1251 controller_.IsURLInPageNavigation(validated_url),
1252 validated_url,
1253 std::string(),
1254 false,
1255 params.frame_id);
1256 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181257
[email protected]ad50def52011-10-19 23:17:071258 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271259 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]c5eed492012-01-04 17:07:501260 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531261 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101262
[email protected]d8c660432011-12-22 20:51:251263 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581264 observers_,
1265 DidFailProvisionalLoad(params.frame_id,
1266 params.is_main_frame,
1267 validated_url,
1268 params.error_code,
1269 params.error_description));
[email protected]724159a2010-12-30 01:11:181270}
1271
1272void TabContents::OnDidLoadResourceFromMemoryCache(
1273 const GURL& url,
[email protected]70435962011-08-02 20:13:281274 const std::string& security_info,
1275 const std::string& http_method,
1276 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191277 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181278 cache.Increment();
1279
1280 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081281 int cert_id = 0;
1282 net::CertStatus cert_status = 0;
1283 int security_bits = -1;
1284 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181285 SSLManager::DeserializeSecurityInfo(security_info,
1286 &cert_id, &cert_status,
1287 &security_bits,
1288 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301289 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161290 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181291
[email protected]ad50def52011-10-19 23:17:071292 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271293 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501294 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531295 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181296}
1297
1298void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381299 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181300 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201301 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181302}
1303
1304void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021305 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231306 LOG(INFO) << security_origin << " ran insecure content from "
1307 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381308 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051309 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381310 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051311 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1312 }
[email protected]71fde352011-12-29 03:29:561313 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411314 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201315 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181316}
1317
1318void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1319 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101321 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181322}
1323
[email protected]1a55c5be2011-11-29 11:36:311324void TabContents::OnDidFinishLoad(
1325 int64 frame_id,
1326 const GURL& validated_url,
1327 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251328 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311329 DidFinishLoad(frame_id, validated_url, is_main_frame));
1330}
1331
1332void TabContents::OnDidFailLoadWithError(int64 frame_id,
1333 const GURL& validated_url,
1334 bool is_main_frame,
1335 int error_code,
1336 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251337 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311338 DidFailLoad(frame_id, validated_url, is_main_frame,
1339 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181340}
1341
[email protected]c8f73ab2011-01-22 00:05:171342void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271343 content_restrictions_ = restrictions;
1344 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171345}
1346
[email protected]216813952011-05-19 22:21:261347void TabContents::OnGoToEntryAtOffset(int offset) {
1348 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231349 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251350 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261351 if (!entry)
1352 return;
1353 // Note that we don't call NavigationController::GotToOffset() as we don't
1354 // want to create a pending navigation entry (it might end up lingering
1355 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251356 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581357 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511358 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581359 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471360 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571361
1362 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1363 // it in now that we know. This allows us to find the entry when it commits.
1364 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231365 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381366 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571367 }
[email protected]216813952011-05-19 22:21:261368 }
1369}
1370
1371void TabContents::OnUpdateZoomLimits(int minimum_percent,
1372 int maximum_percent,
1373 bool remember) {
1374 minimum_zoom_percent_ = minimum_percent;
1375 maximum_zoom_percent_ = maximum_percent;
1376 temporary_zoom_settings_ = !remember;
1377}
1378
[email protected]0bfbf882011-12-22 18:19:271379void TabContents::OnSaveURL(const GURL& url) {
1380 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1381 dlm->DownloadUrl(url, GetURL(), "", this);
1382}
1383
[email protected]3a29a6e2011-08-24 18:26:211384void TabContents::OnEnumerateDirectory(int request_id,
1385 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511386 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211387}
1388
[email protected]7d189022011-08-25 22:54:201389void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511390 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201391}
1392
1393void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1394 const GURL& url,
1395 const string16& title) {
[email protected]6934a702011-12-20 00:04:511396 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201397}
1398
[email protected]b888919c2011-09-02 00:32:161399void TabContents::OnFindReply(int request_id,
1400 int number_of_matches,
1401 const gfx::Rect& selection_rect,
1402 int active_match_ordinal,
1403 bool final_update) {
[email protected]6934a702011-12-20 00:04:511404 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1405 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001406 // Send a notification to the renderer that we are ready to receive more
1407 // results from the scoping effort of the Find operation. The FindInPage
1408 // scoping is asynchronous and periodically sends results back up to the
1409 // browser using IPC. In an effort to not spam the browser we have the
1410 // browser send an ACK for each FindReply message and have the renderer
1411 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521412 GetRenderViewHost()->Send(
1413 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161414}
1415
[email protected]d952a052011-09-06 18:42:451416void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511417 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451418}
1419
[email protected]7fc4bbb2011-09-08 21:23:101420void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1421 bool blocked_by_policy) {
1422 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251423 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101424 AppCacheAccessed(manifest_url, blocked_by_policy));
1425}
1426
[email protected]96d185d2009-04-24 03:28:541427// Notifies the RenderWidgetHost instance about the fact that the page is
1428// loading, or done loading and calls the base implementation.
1429void TabContents::SetIsLoading(bool is_loading,
1430 LoadNotificationDetails* details) {
1431 if (is_loading == is_loading_)
1432 return;
1433
1434 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211435 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541436 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561437 upload_size_ = 0;
1438 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541439 }
1440
1441 render_manager_.SetIsLoading(is_loading);
1442
1443 is_loading_ = is_loading;
1444 waiting_for_response_ = is_loading;
1445
[email protected]6ebdc9b2010-09-27 16:55:571446 if (delegate_)
1447 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461448 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541449
[email protected]432115822011-07-10 15:52:271450 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1451 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071452 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541453 if (details)
[email protected]6c2381d2011-10-19 02:52:531454 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071455 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501456 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541457 det);
1458}
1459
[email protected]420ae012009-04-24 05:16:321460void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131461 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321462 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561463 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381464 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441465 // that opened the window, as long as both renderers have the same
1466 // privileges.
[email protected]1fd1a502011-03-30 16:55:561467 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1468 WebUI* web_ui = content::GetContentClient()->browser()->
1469 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581470 // web_ui might be NULL if the URL refers to a non-existent extension.
1471 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401472 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521473 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441474 }
1475 }
[email protected]1fd1a502011-03-30 16:55:561476 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441477 }
1478
[email protected]4e697b042011-07-08 06:44:561479 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321480 // Clear the status bubble. This is a workaround for a bug where WebKit
1481 // doesn't let us know that the cursor left an element during a
1482 // transition (this is also why the mouse cursor remains as a hand after
1483 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1484 // clear the bubble when a user navigates to a named anchor in the same
1485 // page.
[email protected]36fc0392011-12-25 03:59:511486 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321487 }
1488
[email protected]a6e82fc2010-02-24 22:28:141489 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471490 // Once the main frame is navigated, we're no longer considered to have
1491 // displayed insecure content.
1492 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171493 }
[email protected]ce5c4502009-05-06 16:46:111494
[email protected]3c9e1872010-11-18 16:17:491495 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251496 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041497 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321498}
1499
1500void TabContents::DidNavigateAnyFramePostCommit(
1501 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131502 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321503 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061504 // If we navigate off the page, reset JavaScript state. This does nothing
1505 // to prevent a malicious script from spamming messages, since the script
1506 // could just reload the page to stop blocking.
1507 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551508 dialog_creator_->ResetJavaScriptState(this);
1509 dialog_creator_ = NULL;
1510 }
[email protected]420ae012009-04-24 05:16:321511
[email protected]3c9e1872010-11-18 16:17:491512 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251513 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041514 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321515}
1516
[email protected]74ce1ad2011-12-16 21:51:461517void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1518 // If we are creating a RVH for a restored controller, then we need to make
1519 // sure the RenderView starts with a next_page_id_ larger than the number
1520 // of restored entries. This must be called before the RenderView starts
1521 // navigating (to avoid a race between the browser updating max_page_id and
1522 // the renderer updating next_page_id_). Because of this, we only call this
1523 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561524 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461525 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1526 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321527}
1528
[email protected]10f417c52011-12-28 21:04:231529bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571530 const string16& title) {
[email protected]420ae012009-04-24 05:16:321531 // For file URLs without a title, use the pathname instead. In the case of a
1532 // synthesized title, we don't want the update to count toward the "one set
1533 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511534 string16 final_title;
[email protected]420ae012009-04-24 05:16:321535 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511536 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1537 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321538 explicit_set = false; // Don't count synthetic titles toward the set limit.
1539 } else {
[email protected]acafd272011-07-26 17:35:571540 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321541 explicit_set = true;
1542 }
1543
[email protected]987fc3a2011-05-26 14:18:091544 // If a page is created via window.open and never navigated,
1545 // there will be no navigation entry. In this situation,
1546 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1547 if (entry) {
[email protected]36fc0392011-12-25 03:59:511548 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091549 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321550
[email protected]36fc0392011-12-25 03:59:511551 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091552 } else {
1553 if (page_title_when_no_navigation_entry_ == final_title)
1554 return false; // Nothing changed, don't bother.
1555
1556 page_title_when_no_navigation_entry_ = final_title;
1557 }
[email protected]420ae012009-04-24 05:16:321558
[email protected]420ae012009-04-24 05:16:321559 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231560 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321561
[email protected]105bb0f2011-05-24 17:12:141562 TitleUpdatedDetails details(entry, explicit_set);
1563
[email protected]ad50def52011-10-19 23:17:071564 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441565 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1566 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531567 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041568
[email protected]420ae012009-04-24 05:16:321569 return true;
1570}
1571
1572void TabContents::NotifySwapped() {
1573 // After sending out a swap notification, we need to send a disconnect
1574 // notification so that clients that pick up a pointer to |this| can NULL the
1575 // pointer. See Bug 1230284.
1576 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071577 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201578 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1579 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071580 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321581}
1582
1583void TabContents::NotifyConnected() {
1584 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071585 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121586 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1587 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071588 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321589}
1590
1591void TabContents::NotifyDisconnected() {
1592 if (!notify_disconnection_)
1593 return;
1594
1595 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071596 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321597 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1598 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071599 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321600}
1601
[email protected]8d3347f2009-07-09 22:00:211602RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321603 return view_.get();
1604}
1605
[email protected]8d3347f2009-07-09 22:00:211606RenderViewHostDelegate::RendererManagement*
1607TabContents::GetRendererManagementDelegate() {
1608 return &render_manager_;
1609}
1610
[email protected]daf82f82011-10-31 22:35:311611content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371612 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461613 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511614}
1615
[email protected]57c6a652009-05-04 07:58:341616TabContents* TabContents::GetAsTabContents() {
1617 return this;
1618}
1619
[email protected]768c5472011-12-26 19:06:171620WebContents* TabContents::GetAsWebContents() {
1621 return this;
1622}
1623
[email protected]da4dfc42011-10-12 15:53:561624content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431625 return view_type_;
[email protected]7b291f92009-08-14 05:43:531626}
1627
[email protected]420ae012009-04-24 05:16:321628void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071629 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271630 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321631 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531632 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231633 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321634 if (!entry)
1635 return;
1636
1637 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351638 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561639 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581640 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321641
1642 if (entry->IsViewSourceMode()) {
1643 // Put the renderer in view source mode.
1644 render_view_host->Send(
1645 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1646 }
[email protected]0666aef2009-05-13 19:48:081647
[email protected]d487beefe2011-12-21 05:41:211648 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261649
1650 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251651 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321652}
1653
1654void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521655 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321656 // Don't notify the world, since this came from a renderer in the
1657 // background.
1658 return;
1659 }
1660
1661 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311662 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231663 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301664
1665 // Restore the focus to the tab (otherwise the focus will be on the top
1666 // window).
[email protected]484ae5912010-09-29 19:16:141667 if (was_crashed && !FocusLocationBarByDefault() &&
1668 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301669 Focus();
[email protected]484ae5912010-09-29 19:16:141670 }
[email protected]32ded2212011-11-10 18:51:431671
[email protected]d8c660432011-12-22 20:51:251672 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321673}
1674
[email protected]443b80e2010-12-14 00:42:231675void TabContents::RenderViewGone(RenderViewHost* rvh,
1676 base::TerminationStatus status,
1677 int error_code) {
[email protected]151a63d2011-12-20 22:32:521678 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321679 // The pending page's RenderViewHost is gone.
1680 return;
1681 }
1682
1683 SetIsLoading(false, NULL);
1684 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231685 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311686 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321687
[email protected]d8c660432011-12-22 20:51:251688 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271689 observers_,
[email protected]be1f56ab2011-12-22 06:55:311690 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321691}
1692
[email protected]2e4633c2009-07-09 16:58:061693void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481694 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251695 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061696}
1697
[email protected]420ae012009-04-24 05:16:321698void TabContents::DidNavigate(RenderViewHost* rvh,
1699 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581700 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321701 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371702
[email protected]420ae012009-04-24 05:16:321703 // Update the site of the SiteInstance if it doesn't have one yet.
1704 if (!GetSiteInstance()->has_site())
1705 GetSiteInstance()->SetSite(params.url);
1706
1707 // Need to update MIME type here because it's referred to in
1708 // UpdateNavigationCommands() called by RendererDidNavigate() to
1709 // determine whether or not to enable the encoding menu.
1710 // It's updated only for the main frame. For a subframe,
1711 // RenderView::UpdateURL does not set params.contents_mime_type.
1712 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1713 // TODO(jungshik): Add a test for the encoding menu to avoid
1714 // regressing it again.
[email protected]2905f742011-10-13 03:51:581715 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321716 contents_mime_type_ = params.contents_mime_type;
1717
[email protected]8286f51a2011-05-31 17:39:131718 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001719 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391720
[email protected]a9c0bfe2010-09-17 08:35:221721 // Send notification about committed provisional loads. This notification is
1722 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1723 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081724 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071725 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1726 // that is not recorded in the navigation history. For the purpose of
1727 // tracking navigation events, we treat this event as a sub frame navigation
1728 // event.
1729 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581730 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221731 // Whether or not a page transition was triggered by going backward or
1732 // forward in the history is only stored in the navigation controller's
1733 // entry list.
1734 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511735 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581736 content::PAGE_TRANSITION_FORWARD_BACK)) {
1737 transition_type = content::PageTransitionFromInt(
1738 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221739 }
[email protected]0d60f0192011-04-14 12:40:101740 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251741 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101742 DidCommitProvisionalLoadForFrame(params.frame_id,
1743 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221744 }
1745
[email protected]76543b92009-08-31 17:27:451746 if (!did_navigate)
1747 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321748
1749 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1750 // for the appropriate notification (best) or you can add it to
1751 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1752 // necessary, please).
1753
1754 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001755 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321756 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511757 if (delegate_)
1758 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001759 }
[email protected]420ae012009-04-24 05:16:321760 DidNavigateAnyFramePostCommit(rvh, details, params);
1761}
1762
1763void TabContents::UpdateState(RenderViewHost* rvh,
1764 int32 page_id,
1765 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151766 // Ensure that this state update comes from either the active RVH or one of
1767 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521768 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321769
1770 // We must be prepared to handle state updates for any page, these occur
1771 // when the user is scrolling and entering form data, as well as when we're
1772 // leaving a page, in which case our state may have already been moved to
1773 // the next page. The navigation controller will look up the appropriate
1774 // NavigationEntry and update it when it is notified via the delegate.
1775
1776 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151777 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321778 if (entry_index < 0)
1779 return;
[email protected]10f417c52011-12-28 21:04:231780 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321781
[email protected]36fc0392011-12-25 03:59:511782 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321783 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511784 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321785 controller_.NotifyEntryChanged(entry, entry_index);
1786}
1787
1788void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571789 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461790 const string16& title,
1791 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321792 // If we have a title, that's a pretty good indication that we've started
1793 // getting useful data.
1794 SetNotWaitingForResponse();
1795
[email protected]151a63d2011-12-20 22:32:521796 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231797 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1798 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091799
[email protected]a49e10b2011-08-01 23:57:461800 // TODO(evan): make use of title_direction.
1801 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091802 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321803 return;
1804
1805 // Broadcast notifications when the UI should be updated.
1806 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:461807 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:321808}
1809
[email protected]420ae012009-04-24 05:16:321810void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401811 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311812 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321813}
1814
1815void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511816 if (delegate_)
1817 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321818}
1819
[email protected]420ae012009-04-24 05:16:321820void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291821 // The UI may be in an event-tracking loop, such as between the
1822 // mouse-down and mouse-up in text selection or a button click.
1823 // Defer the close until after tracking is complete, so that we
1824 // don't free objects out from under the UI.
1825 // TODO(shess): This could probably be integrated with the
1826 // IsDoingDrag() test below. Punting for now because I need more
1827 // research to understand how this impacts platforms other than Mac.
1828 // TODO(shess): This could get more fine-grained. For instance,
1829 // closing a tab in another window while selecting text in the
1830 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211831 if (GetView()->IsEventTracking()) {
1832 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291833 return;
1834 }
1835
[email protected]24a4d1062009-07-10 23:10:421836 // If we close the tab while we're in the middle of a drag, we'll crash.
1837 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211838 if (GetView()->IsDoingDrag()) {
1839 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421840 return;
1841 }
1842
[email protected]420ae012009-04-24 05:16:321843 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521844 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511845 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321846}
1847
[email protected]cd9ed79d2011-11-15 19:22:571848void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521849 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511850 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571851}
1852
[email protected]420ae012009-04-24 05:16:321853void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511854 if (delegate_ && delegate_->IsPopupOrPanel(this))
1855 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321856}
1857
[email protected]7ab1e7d62009-10-14 23:32:011858void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321859 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491860
[email protected]6934a702011-12-20 00:04:511861 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211862 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511863 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001864 }
[email protected]3c9e1872010-11-18 16:17:491865
1866 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251867 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321868}
1869
[email protected]7ab1e7d62009-10-14 23:32:011870void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321871 scoped_ptr<LoadNotificationDetails> details;
1872
[email protected]10f417c52011-12-28 21:04:231873 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321874 // An entry may not exist for a stop when loading an initial blank page or
1875 // if an iframe injected by script into a blank page finishes loading.
1876 if (entry) {
[email protected]420ae012009-04-24 05:16:321877 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1878
1879 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511880 entry->GetVirtualURL(),
1881 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321882 elapsed,
1883 &controller_,
1884 controller_.GetCurrentEntryIndex()));
1885 }
1886
[email protected]420ae012009-04-24 05:16:321887 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491888
1889 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251890 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321891}
1892
[email protected]c95fa8b2011-04-28 20:26:161893void TabContents::DidCancelLoading() {
1894 controller_.DiscardNonCommittedEntries();
1895
1896 // Update the URL display.
[email protected]d9083482012-01-06 00:38:461897 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:161898}
1899
[email protected]1a3c3cb2010-12-16 21:03:401900void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511901 if (delegate_)
1902 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401903}
1904
[email protected]952a68e2011-11-17 00:36:101905void TabContents::DocumentAvailableInMainFrame(
1906 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251907 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101908 DocumentAvailableInMainFrame());
1909}
1910
[email protected]25497492010-09-11 15:15:081911void TabContents::DocumentOnLoadCompletedInMainFrame(
1912 RenderViewHost* render_view_host,
1913 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071914 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271915 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321916 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531917 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081918}
1919
[email protected]ae5184d62011-10-06 19:25:581920void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151921 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581922 WindowOpenDisposition disposition,
1923 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481924 // Delegate to RequestTransferURL because this is just the generic
1925 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581926 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481927 GlobalRequestID());
1928}
1929
1930void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581931 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481932 WindowOpenDisposition disposition,
1933 int64 source_frame_id,
1934 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201935 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581936 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581937 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351938 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321939 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1940 // generated suggestions).
1941 //
[email protected]e0112912011-02-02 22:54:351942 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161943 // want web sites to see a referrer of "chrome://blah" (and some
1944 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321945 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581946 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481947 render_manager_.web_ui()->link_transition_type(),
1948 false /* is_renderer_initiated */);
1949 params.transferred_global_request_id = old_request_id;
1950 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581951 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321952 } else {
[email protected]4ad5d77d2011-12-03 02:00:481953 OpenURLParams params(url, referrer, disposition,
1954 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1955 params.transferred_global_request_id = old_request_id;
1956 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581957 }
1958 if (new_contents) {
1959 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251960 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581961 DidOpenRequestedURL(new_contents,
1962 url,
1963 referrer,
1964 disposition,
1965 transition_type,
1966 source_frame_id));
[email protected]420ae012009-04-24 05:16:321967 }
1968}
1969
[email protected]420ae012009-04-24 05:16:321970void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151971 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411972 const string16& message,
1973 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321974 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471975 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321976 IPC::Message* reply_msg,
1977 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071978 // Suppress JavaScript dialogs when requested. Also suppress messages when
1979 // showing an interstitial as it's shown over the previous page and we don't
1980 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501981 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151982 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271983 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071984 !delegate_ ||
1985 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321986
1987 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341988 content::JavaScriptDialogCreator::TitleType title_type;
1989 string16 title;
1990
1991 if (!frame_url.has_host()) {
1992 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1993 } else {
1994 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1995 title = net::FormatUrl(
1996 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201997 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301998 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341999 }
2000
[email protected]2e5b90c2011-08-16 21:11:552001 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2002 dialog_creator_->RunJavaScriptDialog(this,
2003 title_type,
2004 title,
[email protected]269f86d2011-12-07 02:43:472005 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:552006 message,
2007 default_prompt,
2008 reply_msg,
2009 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322010 }
[email protected]3ab9cb82011-06-03 18:02:072011
2012 if (suppress_this_message) {
2013 // If we are suppressing messages, just reply as if the user immediately
2014 // pressed "Cancel".
2015 OnDialogClosed(reply_msg, false, string16());
2016 }
2017
2018 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322019}
2020
[email protected]992db4c2011-05-12 15:37:152021void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412022 const string16& message,
[email protected]420ae012009-04-24 05:16:322023 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512024 if (delegate_)
2025 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072026
2027 bool suppress_this_message =
2028 rvh->is_swapped_out() ||
2029 !delegate_ ||
2030 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152031 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522032 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502033 return;
2034 }
[email protected]3ab9cb82011-06-03 18:02:072035
[email protected]7ab1e7d62009-10-14 23:32:012036 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552037 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2038 dialog_creator_->RunBeforeUnloadDialog(this,
2039 message,
2040 reply_msg);
[email protected]420ae012009-04-24 05:16:322041}
2042
[email protected]420ae012009-04-24 05:16:322043WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082044 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362045 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522046 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082047
[email protected]b8299c12011-06-03 19:52:282048 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212049 // chrome-devtools: pages (unless it's specifically allowed).
2050 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572051 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282052 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302053 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2054 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212055 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082056 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432057 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082058 }
2059
2060 return web_prefs;
[email protected]420ae012009-04-24 05:16:322061}
2062
[email protected]7d472472011-01-22 01:30:252063void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272064 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252065 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222066
[email protected]99907362012-01-11 05:41:402067 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
[email protected]b39e7a88b2012-01-10 21:43:172068 if (rdh) // NULL in unittests.
2069 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252070}
2071
[email protected]fa1cf0b82010-01-15 21:49:442072void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442073 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252074 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442075}
2076
[email protected]420ae012009-04-24 05:16:322077void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2078 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152079 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522080 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152081 return;
2082
[email protected]e5fc1632011-08-08 07:51:532083 // Ignore renderer unresponsive event if debugger is attached to the tab
2084 // since the event may be a result of the renderer sitting on a breakpoint.
2085 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442086 DevToolsAgentHost* agent =
2087 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2088 if (agent &&
2089 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532090 return;
2091
[email protected]420ae012009-04-24 05:16:322092 if (is_during_unload) {
2093 // Hang occurred while firing the beforeunload/unload handler.
2094 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112095 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322096
2097 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2098 return;
2099
2100 // If the tab hangs in the beforeunload/unload handler there's really
2101 // nothing we can do to recover. Pretend the unload listeners have
2102 // all fired and close the tab. If the hang is in the beforeunload handler
2103 // then the user will not have the option of cancelling the close.
2104 Close(rvh);
2105 return;
2106 }
2107
[email protected]151a63d2011-12-20 22:32:522108 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472109 return;
2110
[email protected]6934a702011-12-20 00:04:512111 if (delegate_)
2112 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322113}
2114
2115void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512116 if (delegate_)
2117 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322118}
2119
2120void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212121 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562122 uint64 upload_position,
2123 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322124 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562125 upload_position_ = upload_position;
2126 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502127 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202128 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302129 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212130 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322131 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462132 if (IsLoading()) {
2133 NotifyNavigationStateChanged(
2134 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2135 }
[email protected]420ae012009-04-24 05:16:322136}
2137
[email protected]7d472472011-01-22 01:30:252138void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512139 if (delegate_)
2140 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252141}
2142
[email protected]420ae012009-04-24 05:16:322143void TabContents::BeforeUnloadFiredFromRenderManager(
2144 bool proceed,
2145 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512146 if (delegate_)
2147 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322148}
2149
[email protected]3a3d47472010-07-15 21:03:542150void TabContents::DidStartLoadingFromRenderManager(
2151 RenderViewHost* render_view_host) {
2152 DidStartLoading();
2153}
2154
2155void TabContents::RenderViewGoneFromRenderManager(
2156 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232157 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2158 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542159}
2160
[email protected]420ae012009-04-24 05:16:322161void TabContents::UpdateRenderViewSizeForRenderManager() {
2162 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262163 gfx::Size size = view_->GetContainerSize();
2164 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2165 // here during container initialization and normal window size will be set
2166 // later. In case of tab duplication this resizing to 0x0 prevents setting
2167 // normal size later so just ignore it.
2168 if (!size.IsEmpty())
2169 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322170}
2171
[email protected]3a3d47472010-07-15 21:03:542172void TabContents::NotifySwappedFromRenderManager() {
2173 NotifySwapped();
2174}
2175
[email protected]d202a7c2012-01-04 07:53:472176NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202177 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542178}
2179
[email protected]d0980792011-02-13 19:41:402180WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]f3f3b722012-01-07 01:29:432181 return content::GetContentClient()->browser()->GetWebUIFactory()->
2182 CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322183}
2184
[email protected]10f417c52011-12-28 21:04:232185NavigationEntry*
2186 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322187 return controller_.GetLastCommittedEntry();
2188}
2189
2190bool TabContents::CreateRenderViewForRenderManager(
2191 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442192 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322193 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522194
[email protected]420ae012009-04-24 05:16:322195 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442196 if (rwh_view)
2197 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322198
[email protected]74ce1ad2011-12-16 21:51:462199 // Make sure we use the correct starting page_id in the new RenderView.
2200 UpdateMaxPageIDIfNecessary(render_view_host);
2201 int32 max_page_id =
2202 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2203
2204 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522205 return false;
2206
[email protected]e60c0232011-11-11 19:56:352207#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502208 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2209 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442210 if (rwh_view) {
2211 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2212 render_widget_host->WasResized();
2213 }
[email protected]f8233cc2011-05-31 20:24:502214#endif
2215
[email protected]420ae012009-04-24 05:16:322216 return true;
2217}
2218
[email protected]3ab9cb82011-06-03 18:02:072219void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2220 bool success,
2221 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542222 if (is_showing_before_unload_dialog_ && !success) {
2223 // If a beforeunload dialog is canceled, we need to stop the throbber from
2224 // spinning, since we forced it to start spinning in Navigate.
2225 DidStopLoading();
2226
2227 tab_close_start_time_ = base::TimeTicks();
2228 }
2229 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522230 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542231}
2232
[email protected]0b08add2011-11-29 03:27:062233gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072234 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542235}
2236
[email protected]a1e97f02011-06-30 14:04:342237void TabContents::OnDialogShown() {
2238 Activate();
[email protected]3a3d47472010-07-15 21:03:542239}
2240
[email protected]be1f56ab2011-12-22 06:55:312241void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122242 encoding_ = content::GetContentClient()->browser()->
2243 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102244}
[email protected]f45d2a72010-03-08 23:28:352245
[email protected]33f74972010-12-08 16:40:362246void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212247 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442248 // Can be NULL during tests.
2249 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212250 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362251}