blob: b7ebf7e5f0ce1c01e8bc6efb612f287aebb096b3 [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]567812d2011-02-24 17:40:5016#include "content/browser/child_process_security_policy.h"
[email protected]0e12d7d2011-12-01 16:21:4417#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4618#include "content/browser/download/download_stats.h"
[email protected]567812d2011-02-24 17:40:5019#include "content/browser/host_zoom_map.h"
20#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]0d9989d2011-12-21 20:26:0021#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0122#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0423#include "content/browser/load_notification_details.h"
[email protected]f3b1a082011-11-18 00:34:3024#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]567812d2011-02-24 17:40:5025#include "content/browser/renderer_host/render_view_host.h"
26#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2227#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5028#include "content/browser/renderer_host/resource_request_details.h"
29#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4430#include "content/browser/tab_contents/interstitial_page.h"
[email protected]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]1fd1a502011-03-30 16:55:5635#include "content/browser/webui/web_ui_factory.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]ccb797302011-12-15 16:55:1138#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4439#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4440#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1741#include "content/public/browser/download_manager.h"
[email protected]5b96836f2011-12-22 07:39:0042#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4843#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3844#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4245#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2546#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2147#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1849#include "content/public/common/content_restriction.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d686e812009-06-03 19:10:2951#include "net/base/net_util.h"
[email protected]abe2c032011-03-31 18:49:3452#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3753#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3854#include "ui/gfx/codec/png_codec.h"
[email protected]ce9751942011-09-21 01:57:2455#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3156#include "webkit/glue/webpreferences.h"
57
58#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1259#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3160#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0061
[email protected]420ae012009-04-24 05:16:3262// Cross-Site Navigations
63//
64// If a TabContents is told to navigate to a different web site (as determined
65// by SiteInstance), it will replace its current RenderViewHost with a new
66// RenderViewHost dedicated to the new SiteInstance. This works as follows:
67//
68// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4669// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3270// - The pending RVH is "suspended," so that no navigation messages are sent to
71// its renderer until the onbeforeunload JavaScript handler has a chance to
72// run in the current RVH.
73// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
74// that it has a pending cross-site request. ResourceDispatcherHost will
75// check for this when the response arrives.
76// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4677// cancel all the pending logic. Otherwise we allow the pending RVH to send
78// the navigation request to its renderer.
79// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
80// main resource load on the pending RVH. It checks CrossSiteRequestManager
81// to see that it is a cross-site request, and installs a
82// CrossSiteResourceHandler.
83// - When RDH receives a response, the BufferedResourceHandler determines
84// whether it is a download. If so, it sends a message to the new renderer
85// causing it to cancel the request, and the download proceeds. For now, the
86// pending RVH remains until the next DidNavigate event for this TabContents.
87// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:3288// - After RDH receives a response and determines that it is safe and not a
89// download, it pauses the response to first run the old page's onunload
90// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1591// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3292// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1593// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3294// the ResourceDispatcherHost, who unpauses the response. Data is then sent
95// to the pending RVH.
96// - The pending renderer sends a FrameNavigate message that invokes the
97// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:4698// pending RVH.
[email protected]992db4c2011-05-12 15:37:1599// - The previous renderer is kept swapped out in RenderViewHostManager in case
100// the user goes back. The process only stays live if another tab is using
101// it, but if so, the existing frame relationships will be maintained.
[email protected]0e47edc2011-11-22 08:01:02102//
103// It is possible that we trigger a new navigation after we have received
104// a SwapOut_ACK message but before the FrameNavigation has been confirmed.
105// In this case the old RVH has been swapped out but the new one has not
106// replaced it, yet. Therefore, we cancel the pending RVH and skip the unloading
107// of the old RVH.
[email protected]420ae012009-04-24 05:16:32108
[email protected]0e12d7d2011-12-01 16:21:44109using content::DevToolsAgentHost;
110using content::DevToolsAgentHostRegistry;
111using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17112using content::DownloadItem;
113using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20114using content::GlobalRequestID;
[email protected]10f417c52011-12-28 21:04:23115using content::NavigationEntry;
116using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20117using content::OpenURLParams;
[email protected]d583e3f22011-12-27 21:38:17118using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38119using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09120using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25121using content::WebContentsObserver;
[email protected]0e12d7d2011-12-01 16:21:44122
[email protected]420ae012009-04-24 05:16:32123namespace {
124
125// Amount of time we wait between when a key event is received and the renderer
126// is queried for its state and pushed to the NavigationEntry.
127const int kQueryStateDelay = 5000;
128
[email protected]6ebdc9b2010-09-27 16:55:57129const int kSyncWaitDelay = 40;
130
[email protected]ca406032011-07-19 21:53:05131static const char kDotGoogleDotCom[] = ".google.com";
132
[email protected]420ae012009-04-24 05:16:32133#if defined(OS_WIN)
134
135BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
136 // Note: erase is required to properly paint some widgets borders. This can
137 // be seen with textfields.
138 InvalidateRect(hwnd, NULL, TRUE);
139 return TRUE;
140}
141#endif
142
[email protected]2c5569662011-03-22 20:45:02143ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23144 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56145 content::NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16146 switch (reload_type) {
147 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02148 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16149 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02150 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16151 case NavigationController::NO_RELOAD:
152 break; // Fall through to rest of function.
153 }
[email protected]5e369672009-11-03 23:48:30154
[email protected]10f417c52011-12-28 21:04:23155 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]3d7474ff2011-07-27 17:47:37156 browser_context->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02157 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30158
[email protected]2c5569662011-03-22 20:45:02159 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30160}
161
[email protected]10f417c52011-12-28 21:04:23162void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]876bc832010-09-07 16:29:54163 const NavigationController& controller,
[email protected]674bc592011-12-20 23:00:42164 content::WebContentsDelegate* delegate,
[email protected]71fde352011-12-29 03:29:56165 content::NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16166 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51167 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54168 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55169 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
170 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51171 params->url = entry.GetURL();
172 params->referrer = entry.GetReferrer();
173 params->transition = entry.GetTransitionType();
174 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00175 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55176 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34177 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47178 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48179 params->transferred_request_child_id =
180 entry.transferred_global_request_id().child_id;
181 params->transferred_request_request_id =
182 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47183
184 if (delegate)
185 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34186}
187
[email protected]420ae012009-04-24 05:16:32188} // namespace
189
[email protected]a81343d232011-12-27 07:39:20190namespace content {
191
192WebContents* WebContents::Create(
193 BrowserContext* browser_context,
194 SiteInstance* site_instance,
195 int routing_id,
196 const WebContents* base_tab_contents,
197 SessionStorageNamespace* session_storage_namespace) {
198 return new TabContents(browser_context,
199 site_instance,
200 routing_id,
201 static_cast<const TabContents*>(base_tab_contents),
202 session_storage_namespace);
203}
204}
[email protected]f4f50ef2011-01-21 19:01:19205
206// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32207
[email protected]3d7474ff2011-07-27 17:47:37208TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32209 SiteInstance* site_instance,
210 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07211 const TabContents* base_tab_contents,
212 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42213 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07214 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37215 this, browser_context, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13216 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]74313b42011-08-24 16:51:32217 content::GetContentClient()->browser()->CreateTabContentsView(this))),
[email protected]d82ed61e2009-06-16 02:46:22218 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34219 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23220 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
221 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34222 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21223 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56224 upload_size_(0),
225 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47226 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57227 capturing_contents_(false),
228 is_being_destroyed_(false),
229 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55230 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57231#if defined(OS_WIN)
232 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
233#endif
[email protected]7ab1e7d62009-10-14 23:32:01234 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56235 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38236 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25237 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01238 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25239 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01240 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00241 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43242 content_restrictions_(0),
243 view_type_(content::VIEW_TYPE_TAB_CONTENTS) {
[email protected]3d7474ff2011-07-27 17:47:37244 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32245
[email protected]34ac70502009-09-25 17:07:23246 // We have the initial size of the view be based on the size of the passed in
247 // tab contents (normally a tab from the same window).
248 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21249 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00250
251#if defined(ENABLE_JAVA_BRIDGE)
252 java_bridge_dispatcher_host_manager_.reset(
253 new JavaBridgeDispatcherHostManager(this));
254#endif
[email protected]332af7732009-03-11 13:21:35255}
initial.commit09911bf2008-07-26 23:55:29256
257TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32258 is_being_destroyed_ = true;
259
[email protected]3ab9cb82011-06-03 18:02:07260 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55261 if (dialog_creator_)
262 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07263
[email protected]420ae012009-04-24 05:16:32264 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32265
[email protected]420ae012009-04-24 05:16:32266 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07267 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09268 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
269 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07270 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32271
272 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07273#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32274 // If we still have a window handle, destroy it. GetNativeView can return
275 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42276 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52277 RenderViewHost* host = GetRenderViewHost();
[email protected]b9a1fb42011-04-12 23:16:44278 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42279 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42280 }
[email protected]420ae012009-04-24 05:16:32281#endif
[email protected]7ab1e7d62009-10-14 23:32:01282
283 // OnCloseStarted isn't called in unit tests.
284 if (!tab_close_start_time_.is_null()) {
285 UMA_HISTOGRAM_TIMES("Tab.Close",
286 base::TimeTicks::Now() - tab_close_start_time_);
287 }
[email protected]b5a1d11c2011-02-17 03:09:42288
[email protected]d8c660432011-12-22 20:51:25289 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08290
[email protected]6934a702011-12-20 00:04:51291 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42292}
293
[email protected]724159a2010-12-30 01:11:18294bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]be1f56ab2011-12-22 06:55:31295 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17296 return true;
297
[email protected]d8c660432011-12-22 20:51:25298 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
299 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10300 while ((observer = it.GetNext()) != NULL)
301 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53302 return true;
[email protected]403415a2011-01-10 18:57:53303
[email protected]724159a2010-12-30 01:11:18304 bool handled = true;
305 bool message_is_ok = true;
306 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58307 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
308 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24309 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
310 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18311 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
312 OnDidStartProvisionalLoadForFrame)
313 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
314 OnDidRedirectProvisionalLoad)
315 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
316 OnDidFailProvisionalLoadWithError)
317 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
318 OnDidLoadResourceFromMemoryCache)
319 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
320 OnDidDisplayInsecureContent)
321 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
322 OnDidRunInsecureContent)
323 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
324 OnDocumentLoadedInFrame)
325 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17326 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
327 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25328 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26329 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59330 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21331 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20332 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
333 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
334 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16335 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45336 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10337 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18338 IPC_MESSAGE_UNHANDLED(handled = false)
339 IPC_END_MESSAGE_MAP_EX()
340
341 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38342 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18343 GetRenderProcessHost()->ReceivedBadMessage();
344 }
345
346 return handled;
347}
348
[email protected]6c2e472f2011-08-24 23:26:18349void TabContents::RunFileChooser(
350 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23351 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51352 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18353}
354
[email protected]f5fa20e2011-12-21 22:35:56355NavigationController& TabContents::GetController() {
356 return controller_;
357}
358
359const NavigationController& TabContents::GetController() const {
360 return controller_;
361}
362
[email protected]627e0512011-12-21 22:55:30363content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55364 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30365}
366
[email protected]f5fa20e2011-12-21 22:35:56367void TabContents::SetViewType(content::ViewType type) {
368 view_type_ = type;
369}
370
[email protected]ea049a02011-12-25 21:37:09371content::ViewType TabContents::GetViewType() const {
372 return view_type_;
373}
374
[email protected]be1f56ab2011-12-22 06:55:31375const GURL& TabContents::GetURL() const {
376 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23377 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51378 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31379}
380
381
382const base::PropertyBag* TabContents::GetPropertyBag() const {
383 return &property_bag_;
384}
385
386base::PropertyBag* TabContents::GetPropertyBag() {
387 return &property_bag_;
388}
389
390content::WebContentsDelegate* TabContents::GetDelegate() {
391 return delegate_;
392}
393
394void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
395 // TODO(cbentzel): remove this debugging code?
396 if (delegate == delegate_)
397 return;
398 if (delegate_)
399 delegate_->Detach(this);
400 delegate_ = delegate;
401 if (delegate_)
402 delegate_->Attach(this);
403}
404
[email protected]f3b1a082011-11-18 00:34:30405content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03406 if (render_manager_.current_host())
407 return render_manager_.current_host()->process();
408 else
409 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16410}
411
[email protected]be1f56ab2011-12-22 06:55:31412RenderViewHost* TabContents::GetRenderViewHost() const {
413 return render_manager_.current_host();
414}
415
416RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
417 return render_manager_.GetRenderWidgetHostView();
418}
419
420TabContentsView* TabContents::GetView() const {
421 return view_.get();
422}
423
424WebUI* TabContents::GetWebUI() const {
425 return render_manager_.web_ui() ? render_manager_.web_ui()
426 : render_manager_.pending_web_ui();
427}
428
429WebUI* TabContents::GetCommittedWebUI() const {
430 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34431}
432
[email protected]96d185d2009-04-24 03:28:54433const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55434 // Transient entries take precedence. They are used for interstitial pages
435 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23436 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08437 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20438 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30439 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23440 if (entry) {
[email protected]b5cca982011-05-26 04:42:08441 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23442 }
[email protected]7ade2732011-02-10 00:13:58443 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
444 render_manager_.pending_web_ui() : render_manager_.web_ui();
445 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54446 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55447 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54448 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35449 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58450 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54451 if (!title.empty())
452 return title;
453 }
454 }
455
456 // We use the title for the last committed entry rather than a pending
457 // navigation entry. For example, when the user types in a URL, we want to
458 // keep the old page's title until the new load has committed and we get a new
459 // title.
[email protected]96d185d2009-04-24 03:28:54460 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23461 if (entry) {
[email protected]b5cca982011-05-26 04:42:08462 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23463 }
[email protected]987fc3a2011-05-26 14:18:09464
465 // |page_title_when_no_navigation_entry_| is finally used
466 // if no title cannot be retrieved.
467 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54468}
469
[email protected]d5f942ba2008-09-26 19:30:34470int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46471 return GetMaxPageIDForSiteInstance(GetSiteInstance());
472}
473
474int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
475 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
476 max_page_ids_[site_instance->id()] = -1;
477
478 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34479}
480
481void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46482 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
483}
484
485void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
486 int32 page_id) {
487 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
488 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34489}
490
[email protected]96d185d2009-04-24 03:28:54491SiteInstance* TabContents::GetSiteInstance() const {
492 return render_manager_.current_host()->site_instance();
493}
494
[email protected]77362eb2011-08-01 17:18:38495SiteInstance* TabContents::GetPendingSiteInstance() const {
496 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
497 render_manager_.pending_render_view_host() :
498 render_manager_.current_host();
499 return dest_rvh->site_instance();
500}
501
[email protected]be1f56ab2011-12-22 06:55:31502bool TabContents::IsLoading() const {
503 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49504}
505
[email protected]be1f56ab2011-12-22 06:55:31506bool TabContents::IsWaitingForResponse() const {
507 return waiting_for_response_;
508}
509
510const net::LoadStateWithParam& TabContents::GetLoadState() const {
511 return load_state_;
512}
513
514const string16& TabContents::GetLoadStateHost() const {
515 return load_state_host_;
516}
517
518uint64 TabContents::GetUploadSize() const {
519 return upload_size_;
520}
521
522uint64 TabContents::GetUploadPosition() const {
523 return upload_position_;
524}
525
526const std::string& TabContents::GetEncoding() const {
527 return encoding_;
528}
529
530bool TabContents::DisplayedInsecureContent() const {
531 return displayed_insecure_content_;
532}
533
534void TabContents::SetCapturingContents(bool cap) {
535 capturing_contents_ = cap;
536}
537
538bool TabContents::IsCrashed() const {
539 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
540 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
541 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49542}
543
[email protected]443b80e2010-12-14 00:42:23544void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
545 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34546 return;
547
[email protected]443b80e2010-12-14 00:42:23548 crashed_status_ = status;
549 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50550 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34551}
552
[email protected]be1f56ab2011-12-22 06:55:31553base::TerminationStatus TabContents::GetCrashedStatus() const {
554 return crashed_status_;
555}
556
557bool TabContents::IsBeingDestroyed() const {
558 return is_being_destroyed_;
559}
560
[email protected]d5f942ba2008-09-26 19:30:34561void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
562 if (delegate_)
563 delegate_->NavigationStateChanged(this, changed_flags);
564}
565
[email protected]96d185d2009-04-24 03:28:54566void TabContents::DidBecomeSelected() {
567 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16568 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
569 if (rwhv) {
570 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43571#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16572 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43573#endif
574 }
[email protected]96d185d2009-04-24 03:28:54575
[email protected]5ac20162010-11-24 23:33:11576 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38577
[email protected]d8c660432011-12-22 20:51:25578 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54579}
580
[email protected]be1f56ab2011-12-22 06:55:31581
582base::TimeTicks TabContents::GetLastSelectedTime() const {
583 return last_selected_time_;
584}
585
[email protected]96d185d2009-04-24 03:28:54586void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31587 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52588 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
589 // open a tab in then background, then closes the tab before selecting it.
590 // This is because closing the tab calls TabContents::Destroy(), which
591 // removes the |GetRenderViewHost()|; then when we actually destroy the
592 // window, OnWindowPosChanged() notices and calls HideContents() (which
593 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16594 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
595 if (rwhv)
596 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54597 }
598
[email protected]ad50def52011-10-19 23:17:07599 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09600 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
601 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07602 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54603}
604
[email protected]be1f56ab2011-12-22 06:55:31605void TabContents::ShowContents() {
606 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
607 if (rwhv)
608 rwhv->DidBecomeSelected();
609}
610
611void TabContents::HideContents() {
612 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
613 // our superclass HideContents(), because some callers want to be very picky
614 // about the order in which these get called. In addition to making the code
615 // here practically impossible to understand, this also means we end up
616 // calling TabContents::WasHidden() twice if callers call both versions of
617 // HideContents() on a TabContents.
618 WasHidden();
619}
620
621bool TabContents::NeedToFireBeforeUnload() {
622 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27623 return WillNotifyDisconnection() &&
624 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31625 !GetRenderViewHost()->SuddenTerminationAllowed();
626}
627
628RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
629 return &render_manager_;
630}
631
[email protected]0bfbf882011-12-22 18:19:27632void TabContents::Stop() {
633 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25634 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27635}
636
637TabContents* TabContents::Clone() {
638 // We create a new SiteInstance so that the new tab won't share processes
639 // with the old one. This can be changed in the future if we need it to share
640 // processes for some reason.
641 TabContents* tc = new TabContents(
642 GetBrowserContext(),
643 SiteInstance::CreateSiteInstance(GetBrowserContext()),
644 MSG_ROUTING_NONE, this, NULL);
645 tc->GetController().CopyStateFrom(controller_);
646 return tc;
647}
648
649void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17650 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27651 bool show_history) {
652 if (!delegate_)
653 return;
654
655 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
656}
657
[email protected]2a6bc3e2011-12-28 23:51:33658void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27659 WindowOpenDisposition disposition,
660 const gfx::Rect& initial_pos,
661 bool user_gesture) {
662 if (!delegate_)
663 return;
664
665 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
666 user_gesture);
667}
668
669gfx::NativeView TabContents::GetContentNativeView() const {
670 return view_->GetContentNativeView();
671}
672
673gfx::NativeView TabContents::GetNativeView() const {
674 return view_->GetNativeView();
675}
676
677void TabContents::GetContainerBounds(gfx::Rect* out) const {
678 view_->GetContainerBounds(out);
679}
680
681void TabContents::Focus() {
682 view_->Focus();
683}
684
[email protected]d8c660432011-12-22 20:51:25685void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31686 observers_.AddObserver(observer);
687}
688
[email protected]d8c660432011-12-22 20:51:25689void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31690 observers_.RemoveObserver(observer);
691}
692
[email protected]d5f942ba2008-09-26 19:30:34693void TabContents::Activate() {
694 if (delegate_)
695 delegate_->ActivateContents(this);
696}
697
[email protected]ea42e7782010-08-23 23:58:12698void TabContents::Deactivate() {
699 if (delegate_)
700 delegate_->DeactivateContents(this);
701}
702
[email protected]63954792011-07-11 04:17:48703void TabContents::LostCapture() {
704 if (delegate_)
705 delegate_->LostCapture();
706}
707
708bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
709 bool* is_keyboard_shortcut) {
710 return delegate_ &&
711 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
712}
713
714void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
715 if (delegate_)
716 delegate_->HandleKeyboardEvent(event);
717}
718
[email protected]32ded2212011-11-10 18:51:43719void TabContents::HandleMouseDown() {
720 if (delegate_)
721 delegate_->HandleMouseDown();
722}
723
[email protected]63954792011-07-11 04:17:48724void TabContents::HandleMouseUp() {
725 if (delegate_)
726 delegate_->HandleMouseUp();
727}
728
729void TabContents::HandleMouseActivate() {
730 if (delegate_)
731 delegate_->HandleMouseActivate();
732}
733
[email protected]8a5e0ca2011-08-25 06:30:47734void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
735 if (delegate_)
736 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
737}
738
[email protected]5d5f7af2011-10-01 01:38:12739bool TabContents::IsFullscreenForCurrentTab() const {
740 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
741}
742
[email protected]e9621112011-10-17 05:38:37743void TabContents::RequestToLockMouse() {
744 if (delegate_) {
745 delegate_->RequestToLockMouse(this);
746 } else {
747 GotResponseToLockMouseRequest(false);
748 }
749}
750
751void TabContents::LostMouseLock() {
752 if (delegate_)
753 delegate_->LostMouseLock();
754}
755
[email protected]0548c5352011-09-07 00:33:33756void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
757 if (delegate_)
758 delegate_->UpdatePreferredSize(this, pref_size);
759}
760
[email protected]32ded2212011-11-10 18:51:43761void TabContents::WebUISend(RenderViewHost* render_view_host,
762 const GURL& source_url,
763 const std::string& name,
764 const base::ListValue& args) {
765 if (delegate_)
766 delegate_->WebUISend(this, source_url, name, args);
767}
768
[email protected]e5d549d2011-12-28 01:29:20769WebContents* TabContents::OpenURL(const OpenURLParams& params) {
770 if (!delegate_)
771 return NULL;
[email protected]00c37fc2011-08-02 00:22:50772
[email protected]e5d549d2011-12-28 01:29:20773 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
774 // Notify observers.
775 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
776 DidOpenURL(params.url, params.referrer,
777 params.disposition, params.transition));
778 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34779}
780
[email protected]1ccb3568d2010-02-19 10:51:16781bool TabContents::NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:56782 content::NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25783 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23784 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25785 reload_type);
[email protected]876bc832010-09-07 16:29:54786}
[email protected]96d185d2009-04-24 03:28:54787
[email protected]876bc832010-09-07 16:29:54788bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23789 const NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56790 content::NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40791 // The renderer will reject IPC messages with URLs longer than
792 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51793 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40794 return false;
795
[email protected]dd11de52011-11-03 22:54:27796 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40797 if (!dest_render_view_host)
798 return false; // Unable to create the desired render view host.
799
[email protected]80a8fad2011-01-29 04:02:38800 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07801 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58802 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56803 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30804 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51805 entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43806#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51807 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43808#endif
[email protected]e091df82011-10-11 18:13:21809 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55810 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58811
[email protected]96d185d2009-04-24 03:28:54812 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44813 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52814 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44815 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51816 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54817
818 // Used for page load time metrics.
819 current_load_start_ = base::TimeTicks::Now();
820
821 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34822 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27823 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47824 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34825 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54826
[email protected]36fc0392011-12-25 03:59:51827 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54828 // HACK!! This code suppresses javascript: URLs from being added to
829 // session history, which is what we want to do for javascript: URLs that
830 // do not generate content. What we really need is a message from the
831 // renderer telling us that a new page was not created. The same message
832 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51833 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54834 return false;
835 }
836
[email protected]3c9e1872010-11-18 16:17:49837 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25838 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04839 observers_,
[email protected]36fc0392011-12-25 03:59:51840 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54841
[email protected]09b29342011-06-24 19:18:48842 if (delegate_)
843 delegate_->DidNavigateToPendingEntry(this);
844
[email protected]d5f942ba2008-09-26 19:30:34845 return true;
846}
847
[email protected]9e1ad4b2011-08-14 16:49:19848void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
849 int history_length,
850 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41851 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
852 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19853 if (render_manager_.pending_render_view_host()) {
854 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14855 return;
[email protected]9e1ad4b2011-08-14 16:49:19856 }
[email protected]151a63d2011-12-20 22:32:52857 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19858 if (!rvh) {
859 NOTREACHED();
860 return;
861 }
862 if (site_instance && rvh->site_instance() != site_instance) {
863 NOTREACHED();
864 return;
865 }
866 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
867 history_length,
868 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14869}
870
[email protected]90daadb42009-06-08 21:27:28871void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27872 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54873 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
874 return;
875 }
[email protected]151a63d2011-12-20 22:32:52876 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54877}
878
[email protected]0bfbf882011-12-22 18:19:27879bool TabContents::ShowingInterstitialPage() const {
880 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54881}
882
[email protected]0bfbf882011-12-22 18:19:27883InterstitialPage* TabContents::GetInterstitialPage() const {
884 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22885}
886
[email protected]c7dd2f62011-07-18 15:57:59887void TabContents::OnSavePage() {
888 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27889 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30890 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59891 const GURL& current_page_url = GetURL();
892 if (dlm && current_page_url.is_valid()) {
893 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46894 download_stats::RecordDownloadCount(
895 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59896 return;
897 }
898 }
899
900 Stop();
901
902 // Create the save package and possibly prompt the user for the name to save
903 // the page as. The user prompt is an asynchronous operation that runs on
904 // another thread.
905 save_package_ = new SavePackage(this);
906 save_package_->GetSaveInfo();
907}
908
909// Used in automated testing to bypass prompting the user for file names.
910// Instead, the names and paths are hard coded rather than running them through
911// file name sanitation and extension / mime checking.
912bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
913 SavePackage::SavePackageType save_type) {
914 // Stop the page from navigating.
915 Stop();
916
917 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
918 return save_package_->Init();
919}
920
[email protected]420ae012009-04-24 05:16:32921bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:23922 NavigationEntryImpl* active_entry =
923 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:32924 return (active_entry != NULL &&
925 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51926 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32927}
928
[email protected]0bfbf882011-12-22 18:19:27929const std::string& TabContents::GetContentsMimeType() const {
930 return contents_mime_type_;
931}
932
933bool TabContents::WillNotifyDisconnection() const {
934 return notify_disconnection_;
935}
936
[email protected]b2fe07d12010-02-09 14:38:08937void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31938 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52939 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
940 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16941}
942
[email protected]b2fe07d12010-02-09 14:38:08943void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31944 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52945 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
946 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16947}
948
[email protected]0bfbf882011-12-22 18:19:27949content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
950 return &renderer_preferences_;
951}
952
953void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
954 new_tab_start_time_ = time;
955}
956
957base::TimeTicks TabContents::GetNewTabStartTime() const {
958 return new_tab_start_time_;
959}
960
[email protected]7ab1e7d62009-10-14 23:32:01961void TabContents::OnCloseStarted() {
962 if (tab_close_start_time_.is_null())
963 tab_close_start_time_ = base::TimeTicks::Now();
964}
965
[email protected]46624bf2010-06-09 16:04:19966bool TabContents::ShouldAcceptDragAndDrop() const {
967#if defined(OS_CHROMEOS)
968 // ChromeOS panels (pop-ups) do not take drag-n-drop.
969 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51970 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20971 return false;
972 return true;
[email protected]46624bf2010-06-09 16:04:19973#else
974 return true;
975#endif
976}
977
[email protected]7813bd72011-02-05 02:19:34978void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52979 if (GetRenderViewHost())
980 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51981 if (delegate_)
982 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34983}
984
[email protected]0bfbf882011-12-22 18:19:27985void TabContents::SetClosedByUserGesture(bool value) {
986 closed_by_user_gesture_ = value;
987}
988
989bool TabContents::GetClosedByUserGesture() const {
990 return closed_by_user_gesture_;
991}
992
[email protected]d0b8d092010-10-25 04:05:17993double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:30994 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25995 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17996 return 0;
[email protected]b75b8292010-10-01 07:28:25997
998 double zoom_level;
999 if (temporary_zoom_settings_) {
1000 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521001 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251002 } else {
[email protected]2ae88d12011-10-14 09:11:191003 GURL url;
[email protected]10f417c52011-12-28 21:04:231004 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191005 // Since zoom map is updated using rewritten URL, use rewritten URL
1006 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511007 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191008 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251009 }
[email protected]d0b8d092010-10-25 04:05:171010 return zoom_level;
1011}
[email protected]b75b8292010-10-01 07:28:251012
[email protected]d0b8d092010-10-25 04:05:171013int TabContents::GetZoomPercent(bool* enable_increment,
1014 bool* enable_decrement) {
1015 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011016 // Calculate the zoom percent from the factor. Round up to the nearest whole
1017 // number.
[email protected]b75b8292010-10-01 07:28:251018 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011019 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251020 *enable_decrement = percent > minimum_zoom_percent_;
1021 *enable_increment = percent < maximum_zoom_percent_;
1022 return percent;
1023}
1024
[email protected]3c733bde2010-12-21 19:56:311025void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501026 if (!delegate_)
1027 return;
1028
[email protected]10f417c52011-12-28 21:04:231029 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501030 if (!active_entry)
1031 return;
1032
[email protected]36fc0392011-12-25 03:59:511033 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121034}
1035
[email protected]932b7a12011-03-09 12:50:271036void TabContents::ViewFrameSource(const GURL& url,
1037 const std::string& content_state) {
1038 if (!delegate_)
1039 return;
1040
1041 delegate_->ViewSourceForFrame(this, url, content_state);
1042}
1043
[email protected]0bfbf882011-12-22 18:19:271044int TabContents::GetMinimumZoomPercent() const {
1045 return minimum_zoom_percent_;
1046}
1047
1048int TabContents::GetMaximumZoomPercent() const {
1049 return maximum_zoom_percent_;
1050}
1051
1052int TabContents::GetContentRestrictions() const {
1053 return content_restrictions_;
1054}
1055
1056WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1057 return content::WebUIFactory::Get()->GetWebUIType(GetBrowserContext(),
1058 GetURL());
1059}
1060
1061WebUI* TabContents::GetWebUIForCurrentState() {
1062 // When there is a pending navigation entry, we want to use the pending WebUI
1063 // that goes along with it to control the basic flags. For example, we want to
1064 // show the pending URL in the URL bar, so we want the display_url flag to
1065 // be from the pending entry.
1066 //
1067 // The confusion comes because there are multiple possibilities for the
1068 // initial load in a tab as a side effect of the way the RenderViewHostManager
1069 // works.
1070 //
1071 // - For the very first tab the load looks "normal". The new tab Web UI is
1072 // the pending one, and we want it to apply here.
1073 //
1074 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1075 // get switched to the one previously associated with the new tab pages.
1076 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1077 // have a committed Web UI in this case.
1078 //
1079 // This condition handles all of these cases:
1080 //
1081 // - First load in first tab: no committed nav entry + pending nav entry +
1082 // pending dom ui:
1083 // -> Use pending Web UI if any.
1084 //
1085 // - First load in second tab: no committed nav entry + pending nav entry +
1086 // no pending Web UI:
1087 // -> Use the committed Web UI if any.
1088 //
1089 // - Second navigation in any tab: committed nav entry + pending nav entry:
1090 // -> Use pending Web UI if any.
1091 //
1092 // - Normal state with no load: committed nav entry + no pending nav entry:
1093 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251094 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271095 (controller_.GetLastCommittedEntry() ||
1096 render_manager_.pending_web_ui()))
1097 return render_manager_.pending_web_ui();
1098 return render_manager_.web_ui();
1099}
1100
1101bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1102 return GetRenderViewHost() ?
1103 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1104}
1105
1106bool TabContents::FocusLocationBarByDefault() {
1107 WebUI* web_ui = GetWebUIForCurrentState();
1108 if (web_ui)
1109 return web_ui->focus_location_bar_by_default();
[email protected]10f417c52011-12-28 21:04:231110 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511111 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271112 return true;
1113 return false;
1114}
1115
1116void TabContents::SetFocusToLocationBar(bool select_all) {
1117 if (delegate_)
1118 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211119}
1120
[email protected]8b5af492011-11-28 21:50:581121void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301122 const string16& type,
1123 const string16& href,
1124 const string16& title,
1125 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511126 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301127 this, action, type, href, title, disposition);
1128}
1129
[email protected]678105012011-12-09 04:01:211130void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301131 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001132 WebIntentsDispatcherImpl* intents_dispatcher =
1133 new WebIntentsDispatcherImpl(this, intent, intent_id);
1134 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301135}
1136
[email protected]724159a2010-12-30 01:11:181137void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1138 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591139 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181140 const GURL& url) {
1141 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1142 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521143 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301144 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181145
[email protected]8093a542011-05-13 07:29:321146 RenderViewHost* rvh =
1147 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521148 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101149 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251150 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101151 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321152 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101153
[email protected]724159a2010-12-30 01:11:181154 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591155 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251156 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591157 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181158 }
1159}
1160
1161void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591162 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181163 const GURL& source_url,
1164 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491165 // TODO(creis): Remove this method and have the pre-rendering code listen to
1166 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1167 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231168 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181169 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251170 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181171 else
1172 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511173 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181174 return;
[email protected]e7d50892011-01-19 21:47:381175
[email protected]4850a7f2011-03-08 23:36:591176 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251177 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261178 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591179 opener_url));
[email protected]724159a2010-12-30 01:11:181180}
1181
1182void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581183 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1184 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1185 << ", error_code: " << params.error_code
1186 << ", error_description: " << params.error_description
1187 << ", is_main_frame: " << params.is_main_frame
1188 << ", showing_repost_interstitial: " <<
1189 params.showing_repost_interstitial
1190 << ", frame_id: " << params.frame_id;
1191 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521192 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301193 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181194
[email protected]d7b175e2011-10-11 15:31:581195 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181196 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1197 // This means that the interstitial won't be torn down properly, which is
1198 // bad. But if we have an interstitial, go back to another tab type, and
1199 // then load the same interstitial again, we could end up getting the first
1200 // interstitial's "failed" message (as a result of the cancel) when we're on
1201 // the second one.
1202 //
1203 // We can't tell this apart, so we think we're tearing down the current page
1204 // which will cause a crash later one. There is also some code in
1205 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1206 // out because of this problem.
1207 //
1208 // http://code.google.com/p/chromium/issues/detail?id=2855
1209 // Because this will not tear down the interstitial properly, if "back" is
1210 // back to another tab type, the interstitial will still be somewhat alive
1211 // in the previous tab type. If you navigate somewhere that activates the
1212 // tab with the interstitial again, you'll see a flash before the new load
1213 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271214 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181215 LOG(WARNING) << "Discarding message during interstitial.";
1216 return;
1217 }
1218
[email protected]02102f82011-06-13 20:37:021219 // Discard our pending entry if the load canceled (e.g. if we decided to
1220 // download the file instead of load it). We do not verify that the URL
1221 // being canceled matches the pending entry's URL because they will not
1222 // match if a redirect occurred (in which case we do not want to leave a
1223 // stale redirect URL showing). This means that we also cancel the pending
1224 // entry if the user started a new navigation. As a result, the navigation
1225 // controller may not remember that a load is in progress, but the
1226 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251227 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161228 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181229
[email protected]151a63d2011-12-20 22:32:521230 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181231 }
1232
1233 // Send out a notification that we failed a provisional load with an error.
1234 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581235 params.is_main_frame,
1236 controller_.IsURLInPageNavigation(validated_url),
1237 validated_url,
1238 std::string(),
1239 false,
1240 params.frame_id);
1241 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181242
[email protected]ad50def52011-10-19 23:17:071243 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271244 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]cca0f1e2012-01-03 18:27:461245 content::Source<content::NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531246 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101247
[email protected]d8c660432011-12-22 20:51:251248 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581249 observers_,
1250 DidFailProvisionalLoad(params.frame_id,
1251 params.is_main_frame,
1252 validated_url,
1253 params.error_code,
1254 params.error_description));
[email protected]724159a2010-12-30 01:11:181255}
1256
1257void TabContents::OnDidLoadResourceFromMemoryCache(
1258 const GURL& url,
[email protected]70435962011-08-02 20:13:281259 const std::string& security_info,
1260 const std::string& http_method,
1261 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191262 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181263 cache.Increment();
1264
1265 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081266 int cert_id = 0;
1267 net::CertStatus cert_status = 0;
1268 int security_bits = -1;
1269 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181270 SSLManager::DeserializeSecurityInfo(security_info,
1271 &cert_id, &cert_status,
1272 &security_bits,
1273 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301274 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161275 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181276
[email protected]ad50def52011-10-19 23:17:071277 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271278 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]cca0f1e2012-01-03 18:27:461279 content::Source<content::NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531280 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181281}
1282
1283void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381284 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181285 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561286 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181287}
1288
1289void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021290 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231291 LOG(INFO) << security_origin << " ran insecure content from "
1292 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381293 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051294 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381295 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051296 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1297 }
[email protected]71fde352011-12-29 03:29:561298 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411299 displayed_insecure_content_ = true;
[email protected]f5fa20e2011-12-21 22:35:561300 SSLManager::NotifySSLInternalStateChanged(&GetController());
[email protected]724159a2010-12-30 01:11:181301}
1302
1303void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1304 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251305 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101306 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181307}
1308
[email protected]1a55c5be2011-11-29 11:36:311309void TabContents::OnDidFinishLoad(
1310 int64 frame_id,
1311 const GURL& validated_url,
1312 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251313 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311314 DidFinishLoad(frame_id, validated_url, is_main_frame));
1315}
1316
1317void TabContents::OnDidFailLoadWithError(int64 frame_id,
1318 const GURL& validated_url,
1319 bool is_main_frame,
1320 int error_code,
1321 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251322 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311323 DidFailLoad(frame_id, validated_url, is_main_frame,
1324 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181325}
1326
[email protected]c8f73ab2011-01-22 00:05:171327void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271328 content_restrictions_ = restrictions;
1329 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171330}
1331
[email protected]216813952011-05-19 22:21:261332void TabContents::OnGoToEntryAtOffset(int offset) {
1333 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231334 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251335 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261336 if (!entry)
1337 return;
1338 // Note that we don't call NavigationController::GotToOffset() as we don't
1339 // want to create a pending navigation entry (it might end up lingering
1340 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251341 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581342 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511343 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581344 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271345 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571346
1347 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1348 // it in now that we know. This allows us to find the entry when it commits.
1349 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231350 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381351 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571352 }
[email protected]216813952011-05-19 22:21:261353 }
1354}
1355
1356void TabContents::OnUpdateZoomLimits(int minimum_percent,
1357 int maximum_percent,
1358 bool remember) {
1359 minimum_zoom_percent_ = minimum_percent;
1360 maximum_zoom_percent_ = maximum_percent;
1361 temporary_zoom_settings_ = !remember;
1362}
1363
[email protected]0bfbf882011-12-22 18:19:271364void TabContents::OnSaveURL(const GURL& url) {
1365 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1366 dlm->DownloadUrl(url, GetURL(), "", this);
1367}
1368
[email protected]3a29a6e2011-08-24 18:26:211369void TabContents::OnEnumerateDirectory(int request_id,
1370 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511371 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211372}
1373
[email protected]7d189022011-08-25 22:54:201374void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511375 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201376}
1377
1378void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1379 const GURL& url,
1380 const string16& title) {
[email protected]6934a702011-12-20 00:04:511381 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201382}
1383
[email protected]b888919c2011-09-02 00:32:161384void TabContents::OnFindReply(int request_id,
1385 int number_of_matches,
1386 const gfx::Rect& selection_rect,
1387 int active_match_ordinal,
1388 bool final_update) {
[email protected]6934a702011-12-20 00:04:511389 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1390 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001391 // Send a notification to the renderer that we are ready to receive more
1392 // results from the scoping effort of the Find operation. The FindInPage
1393 // scoping is asynchronous and periodically sends results back up to the
1394 // browser using IPC. In an effort to not spam the browser we have the
1395 // browser send an ACK for each FindReply message and have the renderer
1396 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521397 GetRenderViewHost()->Send(
1398 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161399}
1400
[email protected]d952a052011-09-06 18:42:451401void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511402 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451403}
1404
[email protected]7fc4bbb2011-09-08 21:23:101405void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1406 bool blocked_by_policy) {
1407 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251408 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101409 AppCacheAccessed(manifest_url, blocked_by_policy));
1410}
1411
[email protected]96d185d2009-04-24 03:28:541412// Notifies the RenderWidgetHost instance about the fact that the page is
1413// loading, or done loading and calls the base implementation.
1414void TabContents::SetIsLoading(bool is_loading,
1415 LoadNotificationDetails* details) {
1416 if (is_loading == is_loading_)
1417 return;
1418
1419 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211420 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541421 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561422 upload_size_ = 0;
1423 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541424 }
1425
1426 render_manager_.SetIsLoading(is_loading);
1427
1428 is_loading_ = is_loading;
1429 waiting_for_response_ = is_loading;
1430
[email protected]6ebdc9b2010-09-27 16:55:571431 if (delegate_)
1432 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351433 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541434
[email protected]432115822011-07-10 15:52:271435 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1436 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071437 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541438 if (details)
[email protected]6c2381d2011-10-19 02:52:531439 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071440 content::NotificationService::current()->Notify(type,
[email protected]cca0f1e2012-01-03 18:27:461441 content::Source<content::NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541442 det);
1443}
1444
[email protected]420ae012009-04-24 05:16:321445void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131446 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321447 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561448 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381449 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441450 // that opened the window, as long as both renderers have the same
1451 // privileges.
[email protected]1fd1a502011-03-30 16:55:561452 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1453 WebUI* web_ui = content::GetContentClient()->browser()->
1454 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581455 // web_ui might be NULL if the URL refers to a non-existent extension.
1456 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401457 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521458 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441459 }
1460 }
[email protected]1fd1a502011-03-30 16:55:561461 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441462 }
1463
[email protected]4e697b042011-07-08 06:44:561464 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321465 // Clear the status bubble. This is a workaround for a bug where WebKit
1466 // doesn't let us know that the cursor left an element during a
1467 // transition (this is also why the mouse cursor remains as a hand after
1468 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1469 // clear the bubble when a user navigates to a named anchor in the same
1470 // page.
[email protected]36fc0392011-12-25 03:59:511471 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321472 }
1473
[email protected]a6e82fc2010-02-24 22:28:141474 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471475 // Once the main frame is navigated, we're no longer considered to have
1476 // displayed insecure content.
1477 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171478 }
[email protected]ce5c4502009-05-06 16:46:111479
[email protected]3c9e1872010-11-18 16:17:491480 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251481 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041482 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321483}
1484
1485void TabContents::DidNavigateAnyFramePostCommit(
1486 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131487 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321488 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071489 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321490 // a malicious script from spamming messages, since the script could just
1491 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551492 if (dialog_creator_) {
1493 dialog_creator_->ResetJavaScriptState(this);
1494 dialog_creator_ = NULL;
1495 }
[email protected]420ae012009-04-24 05:16:321496
[email protected]3c9e1872010-11-18 16:17:491497 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251498 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041499 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321500}
1501
[email protected]74ce1ad2011-12-16 21:51:461502void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1503 // If we are creating a RVH for a restored controller, then we need to make
1504 // sure the RenderView starts with a next_page_id_ larger than the number
1505 // of restored entries. This must be called before the RenderView starts
1506 // navigating (to avoid a race between the browser updating max_page_id and
1507 // the renderer updating next_page_id_). Because of this, we only call this
1508 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561509 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461510 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1511 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321512}
1513
[email protected]10f417c52011-12-28 21:04:231514bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571515 const string16& title) {
[email protected]420ae012009-04-24 05:16:321516 // For file URLs without a title, use the pathname instead. In the case of a
1517 // synthesized title, we don't want the update to count toward the "one set
1518 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511519 string16 final_title;
[email protected]420ae012009-04-24 05:16:321520 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511521 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1522 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321523 explicit_set = false; // Don't count synthetic titles toward the set limit.
1524 } else {
[email protected]acafd272011-07-26 17:35:571525 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321526 explicit_set = true;
1527 }
1528
[email protected]987fc3a2011-05-26 14:18:091529 // If a page is created via window.open and never navigated,
1530 // there will be no navigation entry. In this situation,
1531 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1532 if (entry) {
[email protected]36fc0392011-12-25 03:59:511533 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091534 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321535
[email protected]36fc0392011-12-25 03:59:511536 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091537 } else {
1538 if (page_title_when_no_navigation_entry_ == final_title)
1539 return false; // Nothing changed, don't bother.
1540
1541 page_title_when_no_navigation_entry_ = final_title;
1542 }
[email protected]420ae012009-04-24 05:16:321543
[email protected]420ae012009-04-24 05:16:321544 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231545 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321546
[email protected]105bb0f2011-05-24 17:12:141547 TitleUpdatedDetails details(entry, explicit_set);
1548
[email protected]ad50def52011-10-19 23:17:071549 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271550 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]6c2381d2011-10-19 02:52:531551 content::Source<TabContents>(this),
1552 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041553
[email protected]420ae012009-04-24 05:16:321554 return true;
1555}
1556
1557void TabContents::NotifySwapped() {
1558 // After sending out a swap notification, we need to send a disconnect
1559 // notification so that clients that pick up a pointer to |this| can NULL the
1560 // pointer. See Bug 1230284.
1561 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071562 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201563 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1564 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071565 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321566}
1567
1568void TabContents::NotifyConnected() {
1569 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071570 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271571 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531572 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071573 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321574}
1575
1576void TabContents::NotifyDisconnected() {
1577 if (!notify_disconnection_)
1578 return;
1579
1580 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071581 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321582 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1583 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071584 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321585}
1586
[email protected]8d3347f2009-07-09 22:00:211587RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321588 return view_.get();
1589}
1590
[email protected]8d3347f2009-07-09 22:00:211591RenderViewHostDelegate::RendererManagement*
1592TabContents::GetRendererManagementDelegate() {
1593 return &render_manager_;
1594}
1595
[email protected]daf82f82011-10-31 22:35:311596content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371597 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461598 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511599}
1600
[email protected]57c6a652009-05-04 07:58:341601TabContents* TabContents::GetAsTabContents() {
1602 return this;
1603}
1604
[email protected]768c5472011-12-26 19:06:171605WebContents* TabContents::GetAsWebContents() {
1606 return this;
1607}
1608
[email protected]da4dfc42011-10-12 15:53:561609content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431610 return view_type_;
[email protected]7b291f92009-08-14 05:43:531611}
1612
[email protected]420ae012009-04-24 05:16:321613void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071614 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271615 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321616 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531617 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231618 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321619 if (!entry)
1620 return;
1621
1622 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351623 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561624 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581625 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321626
1627 if (entry->IsViewSourceMode()) {
1628 // Put the renderer in view source mode.
1629 render_view_host->Send(
1630 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1631 }
[email protected]0666aef2009-05-13 19:48:081632
[email protected]d487beefe2011-12-21 05:41:211633 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261634
1635 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251636 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321637}
1638
1639void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521640 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321641 // Don't notify the world, since this came from a renderer in the
1642 // background.
1643 return;
1644 }
1645
1646 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311647 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231648 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301649
1650 // Restore the focus to the tab (otherwise the focus will be on the top
1651 // window).
[email protected]484ae5912010-09-29 19:16:141652 if (was_crashed && !FocusLocationBarByDefault() &&
1653 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301654 Focus();
[email protected]484ae5912010-09-29 19:16:141655 }
[email protected]32ded2212011-11-10 18:51:431656
[email protected]d8c660432011-12-22 20:51:251657 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321658}
1659
[email protected]443b80e2010-12-14 00:42:231660void TabContents::RenderViewGone(RenderViewHost* rvh,
1661 base::TerminationStatus status,
1662 int error_code) {
[email protected]151a63d2011-12-20 22:32:521663 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321664 // The pending page's RenderViewHost is gone.
1665 return;
1666 }
1667
1668 SetIsLoading(false, NULL);
1669 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231670 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311671 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321672
[email protected]d8c660432011-12-22 20:51:251673 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271674 observers_,
[email protected]be1f56ab2011-12-22 06:55:311675 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321676}
1677
[email protected]2e4633c2009-07-09 16:58:061678void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481679 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251680 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061681}
1682
[email protected]420ae012009-04-24 05:16:321683void TabContents::DidNavigate(RenderViewHost* rvh,
1684 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581685 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321686 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371687
[email protected]420ae012009-04-24 05:16:321688 // Update the site of the SiteInstance if it doesn't have one yet.
1689 if (!GetSiteInstance()->has_site())
1690 GetSiteInstance()->SetSite(params.url);
1691
1692 // Need to update MIME type here because it's referred to in
1693 // UpdateNavigationCommands() called by RendererDidNavigate() to
1694 // determine whether or not to enable the encoding menu.
1695 // It's updated only for the main frame. For a subframe,
1696 // RenderView::UpdateURL does not set params.contents_mime_type.
1697 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1698 // TODO(jungshik): Add a test for the encoding menu to avoid
1699 // regressing it again.
[email protected]2905f742011-10-13 03:51:581700 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321701 contents_mime_type_ = params.contents_mime_type;
1702
[email protected]8286f51a2011-05-31 17:39:131703 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001704 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391705
[email protected]a9c0bfe2010-09-17 08:35:221706 // Send notification about committed provisional loads. This notification is
1707 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1708 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081709 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071710 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1711 // that is not recorded in the navigation history. For the purpose of
1712 // tracking navigation events, we treat this event as a sub frame navigation
1713 // event.
1714 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581715 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221716 // Whether or not a page transition was triggered by going backward or
1717 // forward in the history is only stored in the navigation controller's
1718 // entry list.
1719 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511720 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581721 content::PAGE_TRANSITION_FORWARD_BACK)) {
1722 transition_type = content::PageTransitionFromInt(
1723 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221724 }
[email protected]0d60f0192011-04-14 12:40:101725 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251726 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101727 DidCommitProvisionalLoadForFrame(params.frame_id,
1728 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221729 }
1730
[email protected]76543b92009-08-31 17:27:451731 if (!did_navigate)
1732 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321733
1734 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1735 // for the appropriate notification (best) or you can add it to
1736 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1737 // necessary, please).
1738
1739 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001740 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321741 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511742 if (delegate_)
1743 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001744 }
[email protected]420ae012009-04-24 05:16:321745 DidNavigateAnyFramePostCommit(rvh, details, params);
1746}
1747
1748void TabContents::UpdateState(RenderViewHost* rvh,
1749 int32 page_id,
1750 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151751 // Ensure that this state update comes from either the active RVH or one of
1752 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521753 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321754
1755 // We must be prepared to handle state updates for any page, these occur
1756 // when the user is scrolling and entering form data, as well as when we're
1757 // leaving a page, in which case our state may have already been moved to
1758 // the next page. The navigation controller will look up the appropriate
1759 // NavigationEntry and update it when it is notified via the delegate.
1760
1761 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151762 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321763 if (entry_index < 0)
1764 return;
[email protected]10f417c52011-12-28 21:04:231765 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321766
[email protected]36fc0392011-12-25 03:59:511767 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321768 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511769 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321770 controller_.NotifyEntryChanged(entry, entry_index);
1771}
1772
1773void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571774 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461775 const string16& title,
1776 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321777 // If we have a title, that's a pretty good indication that we've started
1778 // getting useful data.
1779 SetNotWaitingForResponse();
1780
[email protected]151a63d2011-12-20 22:32:521781 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231782 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1783 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091784
[email protected]a49e10b2011-08-01 23:57:461785 // TODO(evan): make use of title_direction.
1786 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091787 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321788 return;
1789
1790 // Broadcast notifications when the UI should be updated.
1791 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031792 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321793}
1794
[email protected]420ae012009-04-24 05:16:321795void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401796 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311797 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321798}
1799
1800void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511801 if (delegate_)
1802 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321803}
1804
[email protected]420ae012009-04-24 05:16:321805void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291806 // The UI may be in an event-tracking loop, such as between the
1807 // mouse-down and mouse-up in text selection or a button click.
1808 // Defer the close until after tracking is complete, so that we
1809 // don't free objects out from under the UI.
1810 // TODO(shess): This could probably be integrated with the
1811 // IsDoingDrag() test below. Punting for now because I need more
1812 // research to understand how this impacts platforms other than Mac.
1813 // TODO(shess): This could get more fine-grained. For instance,
1814 // closing a tab in another window while selecting text in the
1815 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211816 if (GetView()->IsEventTracking()) {
1817 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291818 return;
1819 }
1820
[email protected]24a4d1062009-07-10 23:10:421821 // If we close the tab while we're in the middle of a drag, we'll crash.
1822 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211823 if (GetView()->IsDoingDrag()) {
1824 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421825 return;
1826 }
1827
[email protected]420ae012009-04-24 05:16:321828 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521829 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511830 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321831}
1832
[email protected]cd9ed79d2011-11-15 19:22:571833void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521834 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511835 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571836}
1837
[email protected]420ae012009-04-24 05:16:321838void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511839 if (delegate_ && delegate_->IsPopupOrPanel(this))
1840 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321841}
1842
[email protected]7ab1e7d62009-10-14 23:32:011843void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321844 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491845
[email protected]6934a702011-12-20 00:04:511846 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211847 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511848 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001849 }
[email protected]3c9e1872010-11-18 16:17:491850
1851 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251852 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321853}
1854
[email protected]7ab1e7d62009-10-14 23:32:011855void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321856 scoped_ptr<LoadNotificationDetails> details;
1857
[email protected]10f417c52011-12-28 21:04:231858 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321859 // An entry may not exist for a stop when loading an initial blank page or
1860 // if an iframe injected by script into a blank page finishes loading.
1861 if (entry) {
[email protected]420ae012009-04-24 05:16:321862 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1863
1864 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511865 entry->GetVirtualURL(),
1866 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321867 elapsed,
1868 &controller_,
1869 controller_.GetCurrentEntryIndex()));
1870 }
1871
[email protected]420ae012009-04-24 05:16:321872 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491873
1874 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251875 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321876}
1877
[email protected]c95fa8b2011-04-28 20:26:161878void TabContents::DidCancelLoading() {
1879 controller_.DiscardNonCommittedEntries();
1880
1881 // Update the URL display.
1882 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1883}
1884
[email protected]1a3c3cb2010-12-16 21:03:401885void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511886 if (delegate_)
1887 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401888}
1889
[email protected]952a68e2011-11-17 00:36:101890void TabContents::DocumentAvailableInMainFrame(
1891 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251892 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101893 DocumentAvailableInMainFrame());
1894}
1895
[email protected]25497492010-09-11 15:15:081896void TabContents::DocumentOnLoadCompletedInMainFrame(
1897 RenderViewHost* render_view_host,
1898 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071899 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271900 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321901 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531902 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081903}
1904
[email protected]ae5184d62011-10-06 19:25:581905void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151906 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581907 WindowOpenDisposition disposition,
1908 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481909 // Delegate to RequestTransferURL because this is just the generic
1910 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581911 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481912 GlobalRequestID());
1913}
1914
1915void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581916 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481917 WindowOpenDisposition disposition,
1918 int64 source_frame_id,
1919 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201920 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581921 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581922 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351923 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321924 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1925 // generated suggestions).
1926 //
[email protected]e0112912011-02-02 22:54:351927 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161928 // want web sites to see a referrer of "chrome://blah" (and some
1929 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321930 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581931 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481932 render_manager_.web_ui()->link_transition_type(),
1933 false /* is_renderer_initiated */);
1934 params.transferred_global_request_id = old_request_id;
1935 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581936 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321937 } else {
[email protected]4ad5d77d2011-12-03 02:00:481938 OpenURLParams params(url, referrer, disposition,
1939 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1940 params.transferred_global_request_id = old_request_id;
1941 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581942 }
1943 if (new_contents) {
1944 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251945 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581946 DidOpenRequestedURL(new_contents,
1947 url,
1948 referrer,
1949 disposition,
1950 transition_type,
1951 source_frame_id));
[email protected]420ae012009-04-24 05:16:321952 }
1953}
1954
[email protected]420ae012009-04-24 05:16:321955void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151956 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411957 const string16& message,
1958 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321959 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471960 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321961 IPC::Message* reply_msg,
1962 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071963 // Suppress JavaScript dialogs when requested. Also suppress messages when
1964 // showing an interstitial as it's shown over the previous page and we don't
1965 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501966 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151967 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271968 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071969 !delegate_ ||
1970 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321971
1972 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341973 content::JavaScriptDialogCreator::TitleType title_type;
1974 string16 title;
1975
1976 if (!frame_url.has_host()) {
1977 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1978 } else {
1979 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1980 title = net::FormatUrl(
1981 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201982 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301983 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341984 }
1985
[email protected]2e5b90c2011-08-16 21:11:551986 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1987 dialog_creator_->RunJavaScriptDialog(this,
1988 title_type,
1989 title,
[email protected]269f86d2011-12-07 02:43:471990 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551991 message,
1992 default_prompt,
1993 reply_msg,
1994 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321995 }
[email protected]3ab9cb82011-06-03 18:02:071996
1997 if (suppress_this_message) {
1998 // If we are suppressing messages, just reply as if the user immediately
1999 // pressed "Cancel".
2000 OnDialogClosed(reply_msg, false, string16());
2001 }
2002
2003 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322004}
2005
[email protected]992db4c2011-05-12 15:37:152006void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412007 const string16& message,
[email protected]420ae012009-04-24 05:16:322008 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512009 if (delegate_)
2010 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072011
2012 bool suppress_this_message =
2013 rvh->is_swapped_out() ||
2014 !delegate_ ||
2015 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152016 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522017 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502018 return;
2019 }
[email protected]3ab9cb82011-06-03 18:02:072020
[email protected]7ab1e7d62009-10-14 23:32:012021 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552022 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2023 dialog_creator_->RunBeforeUnloadDialog(this,
2024 message,
2025 reply_msg);
[email protected]420ae012009-04-24 05:16:322026}
2027
[email protected]420ae012009-04-24 05:16:322028WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082029 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362030 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522031 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082032
[email protected]b8299c12011-06-03 19:52:282033 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212034 // chrome-devtools: pages (unless it's specifically allowed).
2035 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572036 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282037 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302038 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2039 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212040 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082041 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432042 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082043 }
2044
2045 return web_prefs;
[email protected]420ae012009-04-24 05:16:322046}
2047
[email protected]7d472472011-01-22 01:30:252048void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272049 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252050 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222051
2052 ResourceDispatcherHost* rdh =
2053 content::GetContentClient()->browser()->GetResourceDispatcherHost();
2054 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:302055 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252056}
2057
[email protected]fa1cf0b82010-01-15 21:49:442058void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442059 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252060 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442061}
2062
[email protected]420ae012009-04-24 05:16:322063void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2064 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152065 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522066 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152067 return;
2068
[email protected]e5fc1632011-08-08 07:51:532069 // Ignore renderer unresponsive event if debugger is attached to the tab
2070 // since the event may be a result of the renderer sitting on a breakpoint.
2071 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442072 DevToolsAgentHost* agent =
2073 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2074 if (agent &&
2075 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532076 return;
2077
[email protected]420ae012009-04-24 05:16:322078 if (is_during_unload) {
2079 // Hang occurred while firing the beforeunload/unload handler.
2080 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112081 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322082
2083 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2084 return;
2085
2086 // If the tab hangs in the beforeunload/unload handler there's really
2087 // nothing we can do to recover. Pretend the unload listeners have
2088 // all fired and close the tab. If the hang is in the beforeunload handler
2089 // then the user will not have the option of cancelling the close.
2090 Close(rvh);
2091 return;
2092 }
2093
[email protected]151a63d2011-12-20 22:32:522094 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472095 return;
2096
[email protected]6934a702011-12-20 00:04:512097 if (delegate_)
2098 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322099}
2100
2101void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512102 if (delegate_)
2103 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322104}
2105
2106void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212107 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562108 uint64 upload_position,
2109 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322110 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562111 upload_position_ = upload_position;
2112 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502113 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202114 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302115 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212116 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322117 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:512118 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:502119 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322120}
2121
[email protected]7d472472011-01-22 01:30:252122void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512123 if (delegate_)
2124 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252125}
2126
[email protected]420ae012009-04-24 05:16:322127void TabContents::BeforeUnloadFiredFromRenderManager(
2128 bool proceed,
2129 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512130 if (delegate_)
2131 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322132}
2133
[email protected]3a3d47472010-07-15 21:03:542134void TabContents::DidStartLoadingFromRenderManager(
2135 RenderViewHost* render_view_host) {
2136 DidStartLoading();
2137}
2138
2139void TabContents::RenderViewGoneFromRenderManager(
2140 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232141 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2142 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542143}
2144
[email protected]420ae012009-04-24 05:16:322145void TabContents::UpdateRenderViewSizeForRenderManager() {
2146 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262147 gfx::Size size = view_->GetContainerSize();
2148 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2149 // here during container initialization and normal window size will be set
2150 // later. In case of tab duplication this resizing to 0x0 prevents setting
2151 // normal size later so just ignore it.
2152 if (!size.IsEmpty())
2153 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322154}
2155
[email protected]3a3d47472010-07-15 21:03:542156void TabContents::NotifySwappedFromRenderManager() {
2157 NotifySwapped();
2158}
2159
2160NavigationController& TabContents::GetControllerForRenderManager() {
[email protected]f5fa20e2011-12-21 22:35:562161 return GetController();
[email protected]3a3d47472010-07-15 21:03:542162}
2163
[email protected]d0980792011-02-13 19:41:402164WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562165 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322166}
2167
[email protected]10f417c52011-12-28 21:04:232168NavigationEntry*
2169 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322170 return controller_.GetLastCommittedEntry();
2171}
2172
2173bool TabContents::CreateRenderViewForRenderManager(
2174 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442175 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322176 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522177
[email protected]420ae012009-04-24 05:16:322178 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442179 if (rwh_view)
2180 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322181
[email protected]74ce1ad2011-12-16 21:51:462182 // Make sure we use the correct starting page_id in the new RenderView.
2183 UpdateMaxPageIDIfNecessary(render_view_host);
2184 int32 max_page_id =
2185 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2186
2187 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522188 return false;
2189
[email protected]e60c0232011-11-11 19:56:352190#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502191 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2192 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442193 if (rwh_view) {
2194 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2195 render_widget_host->WasResized();
2196 }
[email protected]f8233cc2011-05-31 20:24:502197#endif
2198
[email protected]420ae012009-04-24 05:16:322199 return true;
2200}
2201
[email protected]3ab9cb82011-06-03 18:02:072202void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2203 bool success,
2204 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542205 if (is_showing_before_unload_dialog_ && !success) {
2206 // If a beforeunload dialog is canceled, we need to stop the throbber from
2207 // spinning, since we forced it to start spinning in Navigate.
2208 DidStopLoading();
2209
2210 tab_close_start_time_ = base::TimeTicks();
2211 }
2212 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522213 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542214}
2215
[email protected]0b08add2011-11-29 03:27:062216gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072217 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542218}
2219
[email protected]a1e97f02011-06-30 14:04:342220void TabContents::OnDialogShown() {
2221 Activate();
[email protected]3a3d47472010-07-15 21:03:542222}
2223
[email protected]be1f56ab2011-12-22 06:55:312224void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122225 encoding_ = content::GetContentClient()->browser()->
2226 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102227}
[email protected]f45d2a72010-03-08 23:28:352228
[email protected]33f74972010-12-08 16:40:362229void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212230 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442231 // Can be NULL during tests.
2232 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212233 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362234}