blob: 7683fd2c0c17a193ca2c683f4d9bbbfeb1b9794e [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]cdcb1dee2012-01-04 00:46:20294NavigationController& TabContents::GetControllerImpl() {
295 return controller_;
296}
297
[email protected]724159a2010-12-30 01:11:18298bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]be1f56ab2011-12-22 06:55:31299 if (GetWebUI() && GetWebUI()->OnMessageReceived(message))
[email protected]f82d57b52011-04-27 19:13:17300 return true;
301
[email protected]d8c660432011-12-22 20:51:25302 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
303 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10304 while ((observer = it.GetNext()) != NULL)
305 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53306 return true;
[email protected]403415a2011-01-10 18:57:53307
[email protected]724159a2010-12-30 01:11:18308 bool handled = true;
309 bool message_is_ok = true;
310 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58311 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
312 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24313 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
314 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18315 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
316 OnDidStartProvisionalLoadForFrame)
317 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
318 OnDidRedirectProvisionalLoad)
319 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
320 OnDidFailProvisionalLoadWithError)
321 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
322 OnDidLoadResourceFromMemoryCache)
323 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
324 OnDidDisplayInsecureContent)
325 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
326 OnDidRunInsecureContent)
327 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
328 OnDocumentLoadedInFrame)
329 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17330 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
331 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25332 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26333 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59334 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21335 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20336 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
337 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
338 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16339 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45340 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10341 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]724159a2010-12-30 01:11:18342 IPC_MESSAGE_UNHANDLED(handled = false)
343 IPC_END_MESSAGE_MAP_EX()
344
345 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38346 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18347 GetRenderProcessHost()->ReceivedBadMessage();
348 }
349
350 return handled;
351}
352
[email protected]6c2e472f2011-08-24 23:26:18353void TabContents::RunFileChooser(
354 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23355 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51356 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18357}
358
[email protected]cdcb1dee2012-01-04 00:46:20359content::NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56360 return controller_;
361}
362
[email protected]cdcb1dee2012-01-04 00:46:20363const content::NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56364 return controller_;
365}
366
[email protected]627e0512011-12-21 22:55:30367content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55368 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30369}
370
[email protected]f5fa20e2011-12-21 22:35:56371void TabContents::SetViewType(content::ViewType type) {
372 view_type_ = type;
373}
374
[email protected]ea049a02011-12-25 21:37:09375content::ViewType TabContents::GetViewType() const {
376 return view_type_;
377}
378
[email protected]be1f56ab2011-12-22 06:55:31379const GURL& TabContents::GetURL() const {
380 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23381 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51382 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31383}
384
385
386const base::PropertyBag* TabContents::GetPropertyBag() const {
387 return &property_bag_;
388}
389
390base::PropertyBag* TabContents::GetPropertyBag() {
391 return &property_bag_;
392}
393
394content::WebContentsDelegate* TabContents::GetDelegate() {
395 return delegate_;
396}
397
398void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
399 // TODO(cbentzel): remove this debugging code?
400 if (delegate == delegate_)
401 return;
402 if (delegate_)
403 delegate_->Detach(this);
404 delegate_ = delegate;
405 if (delegate_)
406 delegate_->Attach(this);
407}
408
[email protected]f3b1a082011-11-18 00:34:30409content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]4d0df262011-10-03 20:05:03410 if (render_manager_.current_host())
411 return render_manager_.current_host()->process();
412 else
413 return NULL;
[email protected]8cb5d5b2010-02-09 11:36:16414}
415
[email protected]be1f56ab2011-12-22 06:55:31416RenderViewHost* TabContents::GetRenderViewHost() const {
417 return render_manager_.current_host();
418}
419
420RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
421 return render_manager_.GetRenderWidgetHostView();
422}
423
424TabContentsView* TabContents::GetView() const {
425 return view_.get();
426}
427
428WebUI* TabContents::GetWebUI() const {
429 return render_manager_.web_ui() ? render_manager_.web_ui()
430 : render_manager_.pending_web_ui();
431}
432
433WebUI* TabContents::GetCommittedWebUI() const {
434 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34435}
436
[email protected]96d185d2009-04-24 03:28:54437const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55438 // Transient entries take precedence. They are used for interstitial pages
439 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23440 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08441 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20442 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30443 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23444 if (entry) {
[email protected]b5cca982011-05-26 04:42:08445 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23446 }
[email protected]7ade2732011-02-10 00:13:58447 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
448 render_manager_.pending_web_ui() : render_manager_.web_ui();
449 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54450 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55451 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54452 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35453 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58454 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54455 if (!title.empty())
456 return title;
457 }
458 }
459
460 // We use the title for the last committed entry rather than a pending
461 // navigation entry. For example, when the user types in a URL, we want to
462 // keep the old page's title until the new load has committed and we get a new
463 // title.
[email protected]96d185d2009-04-24 03:28:54464 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23465 if (entry) {
[email protected]b5cca982011-05-26 04:42:08466 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23467 }
[email protected]987fc3a2011-05-26 14:18:09468
469 // |page_title_when_no_navigation_entry_| is finally used
470 // if no title cannot be retrieved.
471 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54472}
473
[email protected]d5f942ba2008-09-26 19:30:34474int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46475 return GetMaxPageIDForSiteInstance(GetSiteInstance());
476}
477
478int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
479 if (max_page_ids_.find(site_instance->id()) == max_page_ids_.end())
480 max_page_ids_[site_instance->id()] = -1;
481
482 return max_page_ids_[site_instance->id()];
[email protected]d5f942ba2008-09-26 19:30:34483}
484
485void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46486 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
487}
488
489void TabContents::UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
490 int32 page_id) {
491 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
492 max_page_ids_[site_instance->id()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34493}
494
[email protected]96d185d2009-04-24 03:28:54495SiteInstance* TabContents::GetSiteInstance() const {
496 return render_manager_.current_host()->site_instance();
497}
498
[email protected]77362eb2011-08-01 17:18:38499SiteInstance* TabContents::GetPendingSiteInstance() const {
500 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
501 render_manager_.pending_render_view_host() :
502 render_manager_.current_host();
503 return dest_rvh->site_instance();
504}
505
[email protected]be1f56ab2011-12-22 06:55:31506bool TabContents::IsLoading() const {
507 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49508}
509
[email protected]be1f56ab2011-12-22 06:55:31510bool TabContents::IsWaitingForResponse() const {
511 return waiting_for_response_;
512}
513
514const net::LoadStateWithParam& TabContents::GetLoadState() const {
515 return load_state_;
516}
517
518const string16& TabContents::GetLoadStateHost() const {
519 return load_state_host_;
520}
521
522uint64 TabContents::GetUploadSize() const {
523 return upload_size_;
524}
525
526uint64 TabContents::GetUploadPosition() const {
527 return upload_position_;
528}
529
530const std::string& TabContents::GetEncoding() const {
531 return encoding_;
532}
533
534bool TabContents::DisplayedInsecureContent() const {
535 return displayed_insecure_content_;
536}
537
538void TabContents::SetCapturingContents(bool cap) {
539 capturing_contents_ = cap;
540}
541
542bool TabContents::IsCrashed() const {
543 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
544 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
545 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49546}
547
[email protected]443b80e2010-12-14 00:42:23548void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
549 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34550 return;
551
[email protected]443b80e2010-12-14 00:42:23552 crashed_status_ = status;
553 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50554 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34555}
556
[email protected]be1f56ab2011-12-22 06:55:31557base::TerminationStatus TabContents::GetCrashedStatus() const {
558 return crashed_status_;
559}
560
561bool TabContents::IsBeingDestroyed() const {
562 return is_being_destroyed_;
563}
564
[email protected]d5f942ba2008-09-26 19:30:34565void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
566 if (delegate_)
567 delegate_->NavigationStateChanged(this, changed_flags);
568}
569
[email protected]96d185d2009-04-24 03:28:54570void TabContents::DidBecomeSelected() {
571 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16572 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
573 if (rwhv) {
574 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43575#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16576 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43577#endif
578 }
[email protected]96d185d2009-04-24 03:28:54579
[email protected]5ac20162010-11-24 23:33:11580 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38581
[email protected]d8c660432011-12-22 20:51:25582 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54583}
584
[email protected]be1f56ab2011-12-22 06:55:31585
586base::TimeTicks TabContents::GetLastSelectedTime() const {
587 return last_selected_time_;
588}
589
[email protected]96d185d2009-04-24 03:28:54590void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31591 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52592 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
593 // open a tab in then background, then closes the tab before selecting it.
594 // This is because closing the tab calls TabContents::Destroy(), which
595 // removes the |GetRenderViewHost()|; then when we actually destroy the
596 // window, OnWindowPosChanged() notices and calls HideContents() (which
597 // calls us).
[email protected]8cb5d5b2010-02-09 11:36:16598 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
599 if (rwhv)
600 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54601 }
602
[email protected]ad50def52011-10-19 23:17:07603 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09604 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
605 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07606 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54607}
608
[email protected]be1f56ab2011-12-22 06:55:31609void TabContents::ShowContents() {
610 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
611 if (rwhv)
612 rwhv->DidBecomeSelected();
613}
614
615void TabContents::HideContents() {
616 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
617 // our superclass HideContents(), because some callers want to be very picky
618 // about the order in which these get called. In addition to making the code
619 // here practically impossible to understand, this also means we end up
620 // calling TabContents::WasHidden() twice if callers call both versions of
621 // HideContents() on a TabContents.
622 WasHidden();
623}
624
625bool TabContents::NeedToFireBeforeUnload() {
626 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27627 return WillNotifyDisconnection() &&
628 !ShowingInterstitialPage() &&
[email protected]be1f56ab2011-12-22 06:55:31629 !GetRenderViewHost()->SuddenTerminationAllowed();
630}
631
632RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
633 return &render_manager_;
634}
635
[email protected]0bfbf882011-12-22 18:19:27636void TabContents::Stop() {
637 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25638 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27639}
640
641TabContents* TabContents::Clone() {
642 // We create a new SiteInstance so that the new tab won't share processes
643 // with the old one. This can be changed in the future if we need it to share
644 // processes for some reason.
645 TabContents* tc = new TabContents(
646 GetBrowserContext(),
647 SiteInstance::CreateSiteInstance(GetBrowserContext()),
648 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20649 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27650 return tc;
651}
652
653void TabContents::ShowPageInfo(const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17654 const SSLStatus& ssl,
[email protected]0bfbf882011-12-22 18:19:27655 bool show_history) {
656 if (!delegate_)
657 return;
658
659 delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history);
660}
661
[email protected]2a6bc3e2011-12-28 23:51:33662void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27663 WindowOpenDisposition disposition,
664 const gfx::Rect& initial_pos,
665 bool user_gesture) {
666 if (!delegate_)
667 return;
668
669 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
670 user_gesture);
671}
672
673gfx::NativeView TabContents::GetContentNativeView() const {
674 return view_->GetContentNativeView();
675}
676
677gfx::NativeView TabContents::GetNativeView() const {
678 return view_->GetNativeView();
679}
680
681void TabContents::GetContainerBounds(gfx::Rect* out) const {
682 view_->GetContainerBounds(out);
683}
684
685void TabContents::Focus() {
686 view_->Focus();
687}
688
[email protected]d8c660432011-12-22 20:51:25689void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31690 observers_.AddObserver(observer);
691}
692
[email protected]d8c660432011-12-22 20:51:25693void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31694 observers_.RemoveObserver(observer);
695}
696
[email protected]d5f942ba2008-09-26 19:30:34697void TabContents::Activate() {
698 if (delegate_)
699 delegate_->ActivateContents(this);
700}
701
[email protected]ea42e7782010-08-23 23:58:12702void TabContents::Deactivate() {
703 if (delegate_)
704 delegate_->DeactivateContents(this);
705}
706
[email protected]63954792011-07-11 04:17:48707void TabContents::LostCapture() {
708 if (delegate_)
709 delegate_->LostCapture();
710}
711
712bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
713 bool* is_keyboard_shortcut) {
714 return delegate_ &&
715 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
716}
717
718void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
719 if (delegate_)
720 delegate_->HandleKeyboardEvent(event);
721}
722
[email protected]32ded2212011-11-10 18:51:43723void TabContents::HandleMouseDown() {
724 if (delegate_)
725 delegate_->HandleMouseDown();
726}
727
[email protected]63954792011-07-11 04:17:48728void TabContents::HandleMouseUp() {
729 if (delegate_)
730 delegate_->HandleMouseUp();
731}
732
733void TabContents::HandleMouseActivate() {
734 if (delegate_)
735 delegate_->HandleMouseActivate();
736}
737
[email protected]8a5e0ca2011-08-25 06:30:47738void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
739 if (delegate_)
740 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
741}
742
[email protected]5d5f7af2011-10-01 01:38:12743bool TabContents::IsFullscreenForCurrentTab() const {
744 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
745}
746
[email protected]e9621112011-10-17 05:38:37747void TabContents::RequestToLockMouse() {
748 if (delegate_) {
749 delegate_->RequestToLockMouse(this);
750 } else {
751 GotResponseToLockMouseRequest(false);
752 }
753}
754
755void TabContents::LostMouseLock() {
756 if (delegate_)
757 delegate_->LostMouseLock();
758}
759
[email protected]0548c5352011-09-07 00:33:33760void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
761 if (delegate_)
762 delegate_->UpdatePreferredSize(this, pref_size);
763}
764
[email protected]32ded2212011-11-10 18:51:43765void TabContents::WebUISend(RenderViewHost* render_view_host,
766 const GURL& source_url,
767 const std::string& name,
768 const base::ListValue& args) {
769 if (delegate_)
770 delegate_->WebUISend(this, source_url, name, args);
771}
772
[email protected]e5d549d2011-12-28 01:29:20773WebContents* TabContents::OpenURL(const OpenURLParams& params) {
774 if (!delegate_)
775 return NULL;
[email protected]00c37fc2011-08-02 00:22:50776
[email protected]e5d549d2011-12-28 01:29:20777 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
778 // Notify observers.
779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
780 DidOpenURL(params.url, params.referrer,
781 params.disposition, params.transition));
782 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:34783}
784
[email protected]1ccb3568d2010-02-19 10:51:16785bool TabContents::NavigateToPendingEntry(
[email protected]71fde352011-12-29 03:29:56786 content::NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:25787 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23788 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:25789 reload_type);
[email protected]876bc832010-09-07 16:29:54790}
[email protected]96d185d2009-04-24 03:28:54791
[email protected]876bc832010-09-07 16:29:54792bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:23793 const NavigationEntryImpl& entry,
[email protected]71fde352011-12-29 03:29:56794 content::NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:40795 // The renderer will reject IPC messages with URLs longer than
796 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:51797 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:40798 return false;
799
[email protected]dd11de52011-11-03 22:54:27800 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
[email protected]ffc906f2011-10-04 22:55:40801 if (!dest_render_view_host)
802 return false; // Unable to create the desired render view host.
803
[email protected]80a8fad2011-01-29 04:02:38804 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07805 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58806 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56807 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
[email protected]627e0512011-12-21 22:55:30808 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(GetBrowserContext(),
[email protected]36fc0392011-12-25 03:59:51809 entry.GetURL());
[email protected]32ded2212011-11-10 18:51:43810#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:51811 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:43812#endif
[email protected]e091df82011-10-11 18:13:21813 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:55814 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58815
[email protected]96d185d2009-04-24 03:28:54816 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:44817 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:52818 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:44819 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:51820 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:54821
822 // Used for page load time metrics.
823 current_load_start_ = base::TimeTicks::Now();
824
825 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34826 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:27827 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:47828 &navigate_params);
[email protected]056de2d2009-06-26 16:41:34829 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54830
[email protected]36fc0392011-12-25 03:59:51831 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:54832 // HACK!! This code suppresses javascript: URLs from being added to
833 // session history, which is what we want to do for javascript: URLs that
834 // do not generate content. What we really need is a message from the
835 // renderer telling us that a new page was not created. The same message
836 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:51837 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:54838 return false;
839 }
840
[email protected]3c9e1872010-11-18 16:17:49841 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:25842 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:04843 observers_,
[email protected]36fc0392011-12-25 03:59:51844 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:54845
[email protected]09b29342011-06-24 19:18:48846 if (delegate_)
847 delegate_->DidNavigateToPendingEntry(this);
848
[email protected]d5f942ba2008-09-26 19:30:34849 return true;
850}
851
[email protected]9e1ad4b2011-08-14 16:49:19852void TabContents::SetHistoryLengthAndPrune(const SiteInstance* site_instance,
853 int history_length,
854 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:41855 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
856 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:19857 if (render_manager_.pending_render_view_host()) {
858 NOTREACHED();
[email protected]796931a92011-08-10 01:32:14859 return;
[email protected]9e1ad4b2011-08-14 16:49:19860 }
[email protected]151a63d2011-12-20 22:32:52861 RenderViewHost* rvh = GetRenderViewHost();
[email protected]9e1ad4b2011-08-14 16:49:19862 if (!rvh) {
863 NOTREACHED();
864 return;
865 }
866 if (site_instance && rvh->site_instance() != site_instance) {
867 NOTREACHED();
868 return;
869 }
870 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(),
871 history_length,
872 minimum_page_id));
[email protected]796931a92011-08-10 01:32:14873}
874
[email protected]90daadb42009-06-08 21:27:28875void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:27876 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:54877 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
878 return;
879 }
[email protected]151a63d2011-12-20 22:32:52880 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:54881}
882
[email protected]0bfbf882011-12-22 18:19:27883bool TabContents::ShowingInterstitialPage() const {
884 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:54885}
886
[email protected]0bfbf882011-12-22 18:19:27887InterstitialPage* TabContents::GetInterstitialPage() const {
888 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:22889}
890
[email protected]c7dd2f62011-07-18 15:57:59891void TabContents::OnSavePage() {
892 // If we can not save the page, try to download it.
[email protected]0bfbf882011-12-22 18:19:27893 if (!SavePackage::IsSavableContents(GetContentsMimeType())) {
[email protected]627e0512011-12-21 22:55:30894 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
[email protected]c7dd2f62011-07-18 15:57:59895 const GURL& current_page_url = GetURL();
896 if (dlm && current_page_url.is_valid()) {
897 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]8bd9e562011-08-16 23:55:46898 download_stats::RecordDownloadCount(
899 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT);
[email protected]c7dd2f62011-07-18 15:57:59900 return;
901 }
902 }
903
904 Stop();
905
906 // Create the save package and possibly prompt the user for the name to save
907 // the page as. The user prompt is an asynchronous operation that runs on
908 // another thread.
909 save_package_ = new SavePackage(this);
910 save_package_->GetSaveInfo();
911}
912
913// Used in automated testing to bypass prompting the user for file names.
914// Instead, the names and paths are hard coded rather than running them through
915// file name sanitation and extension / mime checking.
916bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
917 SavePackage::SavePackageType save_type) {
918 // Stop the page from navigating.
919 Stop();
920
921 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
922 return save_package_->Init();
923}
924
[email protected]420ae012009-04-24 05:16:32925bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:23926 NavigationEntryImpl* active_entry =
927 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:32928 return (active_entry != NULL &&
929 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:51930 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:32931}
932
[email protected]0bfbf882011-12-22 18:19:27933const std::string& TabContents::GetContentsMimeType() const {
934 return contents_mime_type_;
935}
936
937bool TabContents::WillNotifyDisconnection() const {
938 return notify_disconnection_;
939}
940
[email protected]b2fe07d12010-02-09 14:38:08941void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:31942 SetEncoding(encoding);
[email protected]151a63d2011-12-20 22:32:52943 GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding(
944 GetRenderViewHost()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16945}
946
[email protected]b2fe07d12010-02-09 14:38:08947void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:31948 encoding_.clear();
[email protected]151a63d2011-12-20 22:32:52949 GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault(
950 GetRenderViewHost()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16951}
952
[email protected]0bfbf882011-12-22 18:19:27953content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
954 return &renderer_preferences_;
955}
956
957void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
958 new_tab_start_time_ = time;
959}
960
961base::TimeTicks TabContents::GetNewTabStartTime() const {
962 return new_tab_start_time_;
963}
964
[email protected]7ab1e7d62009-10-14 23:32:01965void TabContents::OnCloseStarted() {
966 if (tab_close_start_time_.is_null())
967 tab_close_start_time_ = base::TimeTicks::Now();
968}
969
[email protected]46624bf2010-06-09 16:04:19970bool TabContents::ShouldAcceptDragAndDrop() const {
971#if defined(OS_CHROMEOS)
972 // ChromeOS panels (pop-ups) do not take drag-n-drop.
973 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:51974 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20975 return false;
976 return true;
[email protected]46624bf2010-06-09 16:04:19977#else
978 return true;
979#endif
980}
981
[email protected]7813bd72011-02-05 02:19:34982void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:52983 if (GetRenderViewHost())
984 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:51985 if (delegate_)
986 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:34987}
988
[email protected]0bfbf882011-12-22 18:19:27989void TabContents::SetClosedByUserGesture(bool value) {
990 closed_by_user_gesture_ = value;
991}
992
993bool TabContents::GetClosedByUserGesture() const {
994 return closed_by_user_gesture_;
995}
996
[email protected]d0b8d092010-10-25 04:05:17997double TabContents::GetZoomLevel() const {
[email protected]627e0512011-12-21 22:55:30998 HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap();
[email protected]b75b8292010-10-01 07:28:25999 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171000 return 0;
[email protected]b75b8292010-10-01 07:28:251001
1002 double zoom_level;
1003 if (temporary_zoom_settings_) {
1004 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]151a63d2011-12-20 22:32:521005 GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id());
[email protected]b75b8292010-10-01 07:28:251006 } else {
[email protected]2ae88d12011-10-14 09:11:191007 GURL url;
[email protected]10f417c52011-12-28 21:04:231008 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191009 // Since zoom map is updated using rewritten URL, use rewritten URL
1010 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511011 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191012 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251013 }
[email protected]d0b8d092010-10-25 04:05:171014 return zoom_level;
1015}
[email protected]b75b8292010-10-01 07:28:251016
[email protected]d0b8d092010-10-25 04:05:171017int TabContents::GetZoomPercent(bool* enable_increment,
1018 bool* enable_decrement) {
1019 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011020 // Calculate the zoom percent from the factor. Round up to the nearest whole
1021 // number.
[email protected]b75b8292010-10-01 07:28:251022 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011023 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251024 *enable_decrement = percent > minimum_zoom_percent_;
1025 *enable_increment = percent < maximum_zoom_percent_;
1026 return percent;
1027}
1028
[email protected]3c733bde2010-12-21 19:56:311029void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501030 if (!delegate_)
1031 return;
1032
[email protected]10f417c52011-12-28 21:04:231033 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501034 if (!active_entry)
1035 return;
1036
[email protected]36fc0392011-12-25 03:59:511037 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121038}
1039
[email protected]932b7a12011-03-09 12:50:271040void TabContents::ViewFrameSource(const GURL& url,
1041 const std::string& content_state) {
1042 if (!delegate_)
1043 return;
1044
1045 delegate_->ViewSourceForFrame(this, url, content_state);
1046}
1047
[email protected]0bfbf882011-12-22 18:19:271048int TabContents::GetMinimumZoomPercent() const {
1049 return minimum_zoom_percent_;
1050}
1051
1052int TabContents::GetMaximumZoomPercent() const {
1053 return maximum_zoom_percent_;
1054}
1055
1056int TabContents::GetContentRestrictions() const {
1057 return content_restrictions_;
1058}
1059
1060WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1061 return content::WebUIFactory::Get()->GetWebUIType(GetBrowserContext(),
1062 GetURL());
1063}
1064
1065WebUI* TabContents::GetWebUIForCurrentState() {
1066 // When there is a pending navigation entry, we want to use the pending WebUI
1067 // that goes along with it to control the basic flags. For example, we want to
1068 // show the pending URL in the URL bar, so we want the display_url flag to
1069 // be from the pending entry.
1070 //
1071 // The confusion comes because there are multiple possibilities for the
1072 // initial load in a tab as a side effect of the way the RenderViewHostManager
1073 // works.
1074 //
1075 // - For the very first tab the load looks "normal". The new tab Web UI is
1076 // the pending one, and we want it to apply here.
1077 //
1078 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1079 // get switched to the one previously associated with the new tab pages.
1080 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1081 // have a committed Web UI in this case.
1082 //
1083 // This condition handles all of these cases:
1084 //
1085 // - First load in first tab: no committed nav entry + pending nav entry +
1086 // pending dom ui:
1087 // -> Use pending Web UI if any.
1088 //
1089 // - First load in second tab: no committed nav entry + pending nav entry +
1090 // no pending Web UI:
1091 // -> Use the committed Web UI if any.
1092 //
1093 // - Second navigation in any tab: committed nav entry + pending nav entry:
1094 // -> Use pending Web UI if any.
1095 //
1096 // - Normal state with no load: committed nav entry + no pending nav entry:
1097 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251098 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271099 (controller_.GetLastCommittedEntry() ||
1100 render_manager_.pending_web_ui()))
1101 return render_manager_.pending_web_ui();
1102 return render_manager_.web_ui();
1103}
1104
1105bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1106 return GetRenderViewHost() ?
1107 GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false;
1108}
1109
1110bool TabContents::FocusLocationBarByDefault() {
1111 WebUI* web_ui = GetWebUIForCurrentState();
1112 if (web_ui)
1113 return web_ui->focus_location_bar_by_default();
[email protected]10f417c52011-12-28 21:04:231114 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:511115 if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL))
[email protected]0bfbf882011-12-22 18:19:271116 return true;
1117 return false;
1118}
1119
1120void TabContents::SetFocusToLocationBar(bool select_all) {
1121 if (delegate_)
1122 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211123}
1124
[email protected]8b5af492011-11-28 21:50:581125void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301126 const string16& type,
1127 const string16& href,
1128 const string16& title,
1129 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511130 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301131 this, action, type, href, title, disposition);
1132}
1133
[email protected]678105012011-12-09 04:01:211134void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301135 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001136 WebIntentsDispatcherImpl* intents_dispatcher =
1137 new WebIntentsDispatcherImpl(this, intent, intent_id);
1138 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301139}
1140
[email protected]724159a2010-12-30 01:11:181141void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1142 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591143 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181144 const GURL& url) {
1145 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1146 GURL validated_url(url);
[email protected]151a63d2011-12-20 22:32:521147 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301148 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181149
[email protected]8093a542011-05-13 07:29:321150 RenderViewHost* rvh =
1151 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521152 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101153 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251154 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101155 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321156 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101157
[email protected]724159a2010-12-30 01:11:181158 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591159 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251160 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]57b9396c2011-10-07 19:11:591161 ProvisionalChangeToMainFrameUrl(url, opener_url));
[email protected]724159a2010-12-30 01:11:181162 }
1163}
1164
1165void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591166 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181167 const GURL& source_url,
1168 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491169 // TODO(creis): Remove this method and have the pre-rendering code listen to
1170 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1171 // instead. See http://crbug.com/78512.
[email protected]10f417c52011-12-28 21:04:231172 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181173 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251174 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181175 else
1176 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]36fc0392011-12-25 03:59:511177 if (!entry || entry->GetURL() != source_url)
[email protected]724159a2010-12-30 01:11:181178 return;
[email protected]e7d50892011-01-19 21:47:381179
[email protected]4850a7f2011-03-08 23:36:591180 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251181 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:261182 ProvisionalChangeToMainFrameUrl(target_url,
[email protected]57b9396c2011-10-07 19:11:591183 opener_url));
[email protected]724159a2010-12-30 01:11:181184}
1185
1186void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581187 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1188 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1189 << ", error_code: " << params.error_code
1190 << ", error_description: " << params.error_description
1191 << ", is_main_frame: " << params.is_main_frame
1192 << ", showing_repost_interstitial: " <<
1193 params.showing_repost_interstitial
1194 << ", frame_id: " << params.frame_id;
1195 GURL validated_url(params.url);
[email protected]151a63d2011-12-20 22:32:521196 GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
[email protected]f3b1a082011-11-18 00:34:301197 GetRenderProcessHost()->GetID(), &validated_url);
[email protected]724159a2010-12-30 01:11:181198
[email protected]d7b175e2011-10-11 15:31:581199 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181200 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1201 // This means that the interstitial won't be torn down properly, which is
1202 // bad. But if we have an interstitial, go back to another tab type, and
1203 // then load the same interstitial again, we could end up getting the first
1204 // interstitial's "failed" message (as a result of the cancel) when we're on
1205 // the second one.
1206 //
1207 // We can't tell this apart, so we think we're tearing down the current page
1208 // which will cause a crash later one. There is also some code in
1209 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1210 // out because of this problem.
1211 //
1212 // http://code.google.com/p/chromium/issues/detail?id=2855
1213 // Because this will not tear down the interstitial properly, if "back" is
1214 // back to another tab type, the interstitial will still be somewhat alive
1215 // in the previous tab type. If you navigate somewhere that activates the
1216 // tab with the interstitial again, you'll see a flash before the new load
1217 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271218 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181219 LOG(WARNING) << "Discarding message during interstitial.";
1220 return;
1221 }
1222
[email protected]02102f82011-06-13 20:37:021223 // Discard our pending entry if the load canceled (e.g. if we decided to
1224 // download the file instead of load it). We do not verify that the URL
1225 // being canceled matches the pending entry's URL because they will not
1226 // match if a redirect occurred (in which case we do not want to leave a
1227 // stale redirect URL showing). This means that we also cancel the pending
1228 // entry if the user started a new navigation. As a result, the navigation
1229 // controller may not remember that a load is in progress, but the
1230 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251231 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161232 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181233
[email protected]151a63d2011-12-20 22:32:521234 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181235 }
1236
1237 // Send out a notification that we failed a provisional load with an error.
1238 ProvisionalLoadDetails details(
[email protected]d7b175e2011-10-11 15:31:581239 params.is_main_frame,
1240 controller_.IsURLInPageNavigation(validated_url),
1241 validated_url,
1242 std::string(),
1243 false,
1244 params.frame_id);
1245 details.set_error_code(params.error_code);
[email protected]724159a2010-12-30 01:11:181246
[email protected]ad50def52011-10-19 23:17:071247 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271248 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]cca0f1e2012-01-03 18:27:461249 content::Source<content::NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531250 content::Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101251
[email protected]d8c660432011-12-22 20:51:251252 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581253 observers_,
1254 DidFailProvisionalLoad(params.frame_id,
1255 params.is_main_frame,
1256 validated_url,
1257 params.error_code,
1258 params.error_description));
[email protected]724159a2010-12-30 01:11:181259}
1260
1261void TabContents::OnDidLoadResourceFromMemoryCache(
1262 const GURL& url,
[email protected]70435962011-08-02 20:13:281263 const std::string& security_info,
1264 const std::string& http_method,
1265 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191266 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181267 cache.Increment();
1268
1269 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081270 int cert_id = 0;
1271 net::CertStatus cert_status = 0;
1272 int security_bits = -1;
1273 int connection_status = 0;
[email protected]724159a2010-12-30 01:11:181274 SSLManager::DeserializeSecurityInfo(security_info,
1275 &cert_id, &cert_status,
1276 &security_bits,
1277 &connection_status);
[email protected]f3b1a082011-11-18 00:34:301278 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161279 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181280
[email protected]ad50def52011-10-19 23:17:071281 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271282 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]cca0f1e2012-01-03 18:27:461283 content::Source<content::NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531284 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181285}
1286
1287void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381288 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181289 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201290 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181291}
1292
1293void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021294 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231295 LOG(INFO) << security_origin << " ran insecure content from "
1296 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381297 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]ca406032011-07-19 21:53:051298 if (EndsWith(security_origin, kDotGoogleDotCom, false)) {
[email protected]7f6f44c2011-12-14 13:23:381299 content::RecordAction(
[email protected]ca406032011-07-19 21:53:051300 UserMetricsAction("SSL.RanInsecureContentGoogle"));
1301 }
[email protected]71fde352011-12-29 03:29:561302 controller_.GetSSLManager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411303 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201304 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181305}
1306
1307void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1308 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251309 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101310 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181311}
1312
[email protected]1a55c5be2011-11-29 11:36:311313void TabContents::OnDidFinishLoad(
1314 int64 frame_id,
1315 const GURL& validated_url,
1316 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251317 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311318 DidFinishLoad(frame_id, validated_url, is_main_frame));
1319}
1320
1321void TabContents::OnDidFailLoadWithError(int64 frame_id,
1322 const GURL& validated_url,
1323 bool is_main_frame,
1324 int error_code,
1325 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251326 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311327 DidFailLoad(frame_id, validated_url, is_main_frame,
1328 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181329}
1330
[email protected]c8f73ab2011-01-22 00:05:171331void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271332 content_restrictions_ = restrictions;
1333 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171334}
1335
[email protected]216813952011-05-19 22:21:261336void TabContents::OnGoToEntryAtOffset(int offset) {
1337 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231338 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251339 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261340 if (!entry)
1341 return;
1342 // Note that we don't call NavigationController::GotToOffset() as we don't
1343 // want to create a pending navigation entry (it might end up lingering
1344 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251345 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581346 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511347 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581348 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]dd11de52011-11-03 22:54:271349 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571350
1351 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1352 // it in now that we know. This allows us to find the entry when it commits.
1353 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231354 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]77362eb2011-08-01 17:18:381355 entry->set_site_instance(GetPendingSiteInstance());
[email protected]a13cc362011-07-28 21:29:571356 }
[email protected]216813952011-05-19 22:21:261357 }
1358}
1359
1360void TabContents::OnUpdateZoomLimits(int minimum_percent,
1361 int maximum_percent,
1362 bool remember) {
1363 minimum_zoom_percent_ = minimum_percent;
1364 maximum_zoom_percent_ = maximum_percent;
1365 temporary_zoom_settings_ = !remember;
1366}
1367
[email protected]0bfbf882011-12-22 18:19:271368void TabContents::OnSaveURL(const GURL& url) {
1369 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
1370 dlm->DownloadUrl(url, GetURL(), "", this);
1371}
1372
[email protected]3a29a6e2011-08-24 18:26:211373void TabContents::OnEnumerateDirectory(int request_id,
1374 const FilePath& path) {
[email protected]6934a702011-12-20 00:04:511375 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211376}
1377
[email protected]7d189022011-08-25 22:54:201378void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511379 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201380}
1381
1382void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1383 const GURL& url,
1384 const string16& title) {
[email protected]6934a702011-12-20 00:04:511385 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201386}
1387
[email protected]b888919c2011-09-02 00:32:161388void TabContents::OnFindReply(int request_id,
1389 int number_of_matches,
1390 const gfx::Rect& selection_rect,
1391 int active_match_ordinal,
1392 bool final_update) {
[email protected]6934a702011-12-20 00:04:511393 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1394 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001395 // Send a notification to the renderer that we are ready to receive more
1396 // results from the scoping effort of the Find operation. The FindInPage
1397 // scoping is asynchronous and periodically sends results back up to the
1398 // browser using IPC. In an effort to not spam the browser we have the
1399 // browser send an ACK for each FindReply message and have the renderer
1400 // queue up the latest status message while waiting for this ACK.
[email protected]151a63d2011-12-20 22:32:521401 GetRenderViewHost()->Send(
1402 new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id()));
[email protected]b888919c2011-09-02 00:32:161403}
1404
[email protected]d952a052011-09-06 18:42:451405void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511406 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451407}
1408
[email protected]7fc4bbb2011-09-08 21:23:101409void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1410 bool blocked_by_policy) {
1411 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251412 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101413 AppCacheAccessed(manifest_url, blocked_by_policy));
1414}
1415
[email protected]96d185d2009-04-24 03:28:541416// Notifies the RenderWidgetHost instance about the fact that the page is
1417// loading, or done loading and calls the base implementation.
1418void TabContents::SetIsLoading(bool is_loading,
1419 LoadNotificationDetails* details) {
1420 if (is_loading == is_loading_)
1421 return;
1422
1423 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211424 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541425 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561426 upload_size_ = 0;
1427 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541428 }
1429
1430 render_manager_.SetIsLoading(is_loading);
1431
1432 is_loading_ = is_loading;
1433 waiting_for_response_ = is_loading;
1434
[email protected]6ebdc9b2010-09-27 16:55:571435 if (delegate_)
1436 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351437 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541438
[email protected]432115822011-07-10 15:52:271439 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1440 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071441 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541442 if (details)
[email protected]6c2381d2011-10-19 02:52:531443 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071444 content::NotificationService::current()->Notify(type,
[email protected]cca0f1e2012-01-03 18:27:461445 content::Source<content::NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541446 det);
1447}
1448
[email protected]420ae012009-04-24 05:16:321449void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131450 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321451 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561452 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381453 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441454 // that opened the window, as long as both renderers have the same
1455 // privileges.
[email protected]1fd1a502011-03-30 16:55:561456 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1457 WebUI* web_ui = content::GetContentClient()->browser()->
1458 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581459 // web_ui might be NULL if the URL refers to a non-existent extension.
1460 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401461 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521462 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441463 }
1464 }
[email protected]1fd1a502011-03-30 16:55:561465 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441466 }
1467
[email protected]4e697b042011-07-08 06:44:561468 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321469 // Clear the status bubble. This is a workaround for a bug where WebKit
1470 // doesn't let us know that the cursor left an element during a
1471 // transition (this is also why the mouse cursor remains as a hand after
1472 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1473 // clear the bubble when a user navigates to a named anchor in the same
1474 // page.
[email protected]36fc0392011-12-25 03:59:511475 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321476 }
1477
[email protected]a6e82fc2010-02-24 22:28:141478 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471479 // Once the main frame is navigated, we're no longer considered to have
1480 // displayed insecure content.
1481 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171482 }
[email protected]ce5c4502009-05-06 16:46:111483
[email protected]3c9e1872010-11-18 16:17:491484 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251485 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041486 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321487}
1488
1489void TabContents::DidNavigateAnyFramePostCommit(
1490 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131491 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321492 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071493 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321494 // a malicious script from spamming messages, since the script could just
1495 // reload the page to stop blocking.
[email protected]2e5b90c2011-08-16 21:11:551496 if (dialog_creator_) {
1497 dialog_creator_->ResetJavaScriptState(this);
1498 dialog_creator_ = NULL;
1499 }
[email protected]420ae012009-04-24 05:16:321500
[email protected]3c9e1872010-11-18 16:17:491501 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251502 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041503 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321504}
1505
[email protected]74ce1ad2011-12-16 21:51:461506void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1507 // If we are creating a RVH for a restored controller, then we need to make
1508 // sure the RenderView starts with a next_page_id_ larger than the number
1509 // of restored entries. This must be called before the RenderView starts
1510 // navigating (to avoid a race between the browser updating max_page_id and
1511 // the renderer updating next_page_id_). Because of this, we only call this
1512 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561513 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]74ce1ad2011-12-16 21:51:461514 if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance()))
1515 UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321516}
1517
[email protected]10f417c52011-12-28 21:04:231518bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571519 const string16& title) {
[email protected]420ae012009-04-24 05:16:321520 // For file URLs without a title, use the pathname instead. In the case of a
1521 // synthesized title, we don't want the update to count toward the "one set
1522 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511523 string16 final_title;
[email protected]420ae012009-04-24 05:16:321524 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511525 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1526 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321527 explicit_set = false; // Don't count synthetic titles toward the set limit.
1528 } else {
[email protected]acafd272011-07-26 17:35:571529 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321530 explicit_set = true;
1531 }
1532
[email protected]987fc3a2011-05-26 14:18:091533 // If a page is created via window.open and never navigated,
1534 // there will be no navigation entry. In this situation,
1535 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1536 if (entry) {
[email protected]36fc0392011-12-25 03:59:511537 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091538 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321539
[email protected]36fc0392011-12-25 03:59:511540 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091541 } else {
1542 if (page_title_when_no_navigation_entry_ == final_title)
1543 return false; // Nothing changed, don't bother.
1544
1545 page_title_when_no_navigation_entry_ = final_title;
1546 }
[email protected]420ae012009-04-24 05:16:321547
[email protected]420ae012009-04-24 05:16:321548 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231549 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321550
[email protected]105bb0f2011-05-24 17:12:141551 TitleUpdatedDetails details(entry, explicit_set);
1552
[email protected]ad50def52011-10-19 23:17:071553 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441554 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1555 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531556 content::Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041557
[email protected]420ae012009-04-24 05:16:321558 return true;
1559}
1560
1561void TabContents::NotifySwapped() {
1562 // After sending out a swap notification, we need to send a disconnect
1563 // notification so that clients that pick up a pointer to |this| can NULL the
1564 // pointer. See Bug 1230284.
1565 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071566 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201567 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1568 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071569 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321570}
1571
1572void TabContents::NotifyConnected() {
1573 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071574 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271575 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]6c2381d2011-10-19 02:52:531576 content::Source<TabContents>(this),
[email protected]ad50def52011-10-19 23:17:071577 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321578}
1579
1580void TabContents::NotifyDisconnected() {
1581 if (!notify_disconnection_)
1582 return;
1583
1584 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071585 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321586 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1587 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071588 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321589}
1590
[email protected]8d3347f2009-07-09 22:00:211591RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321592 return view_.get();
1593}
1594
[email protected]8d3347f2009-07-09 22:00:211595RenderViewHostDelegate::RendererManagement*
1596TabContents::GetRendererManagementDelegate() {
1597 return &render_manager_;
1598}
1599
[email protected]daf82f82011-10-31 22:35:311600content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371601 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461602 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511603}
1604
[email protected]57c6a652009-05-04 07:58:341605TabContents* TabContents::GetAsTabContents() {
1606 return this;
1607}
1608
[email protected]768c5472011-12-26 19:06:171609WebContents* TabContents::GetAsWebContents() {
1610 return this;
1611}
1612
[email protected]da4dfc42011-10-12 15:53:561613content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431614 return view_type_;
[email protected]7b291f92009-08-14 05:43:531615}
1616
[email protected]420ae012009-04-24 05:16:321617void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071618 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271619 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321620 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531621 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231622 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321623 if (!entry)
1624 return;
1625
1626 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351627 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561628 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581629 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321630
1631 if (entry->IsViewSourceMode()) {
1632 // Put the renderer in view source mode.
1633 render_view_host->Send(
1634 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1635 }
[email protected]0666aef2009-05-13 19:48:081636
[email protected]d487beefe2011-12-21 05:41:211637 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261638
1639 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251640 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321641}
1642
1643void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521644 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321645 // Don't notify the world, since this came from a renderer in the
1646 // background.
1647 return;
1648 }
1649
1650 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311651 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231652 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301653
1654 // Restore the focus to the tab (otherwise the focus will be on the top
1655 // window).
[email protected]484ae5912010-09-29 19:16:141656 if (was_crashed && !FocusLocationBarByDefault() &&
1657 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301658 Focus();
[email protected]484ae5912010-09-29 19:16:141659 }
[email protected]32ded2212011-11-10 18:51:431660
[email protected]d8c660432011-12-22 20:51:251661 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:321662}
1663
[email protected]443b80e2010-12-14 00:42:231664void TabContents::RenderViewGone(RenderViewHost* rvh,
1665 base::TerminationStatus status,
1666 int error_code) {
[email protected]151a63d2011-12-20 22:32:521667 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321668 // The pending page's RenderViewHost is gone.
1669 return;
1670 }
1671
1672 SetIsLoading(false, NULL);
1673 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231674 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:311675 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:321676
[email protected]d8c660432011-12-22 20:51:251677 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:271678 observers_,
[email protected]be1f56ab2011-12-22 06:55:311679 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:321680}
1681
[email protected]2e4633c2009-07-09 16:58:061682void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481683 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:251684 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:061685}
1686
[email protected]420ae012009-04-24 05:16:321687void TabContents::DidNavigate(RenderViewHost* rvh,
1688 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:581689 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321690 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371691
[email protected]420ae012009-04-24 05:16:321692 // Update the site of the SiteInstance if it doesn't have one yet.
1693 if (!GetSiteInstance()->has_site())
1694 GetSiteInstance()->SetSite(params.url);
1695
1696 // Need to update MIME type here because it's referred to in
1697 // UpdateNavigationCommands() called by RendererDidNavigate() to
1698 // determine whether or not to enable the encoding menu.
1699 // It's updated only for the main frame. For a subframe,
1700 // RenderView::UpdateURL does not set params.contents_mime_type.
1701 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1702 // TODO(jungshik): Add a test for the encoding menu to avoid
1703 // regressing it again.
[email protected]2905f742011-10-13 03:51:581704 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321705 contents_mime_type_ = params.contents_mime_type;
1706
[email protected]8286f51a2011-05-31 17:39:131707 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001708 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391709
[email protected]a9c0bfe2010-09-17 08:35:221710 // Send notification about committed provisional loads. This notification is
1711 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1712 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:081713 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071714 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1715 // that is not recorded in the navigation history. For the purpose of
1716 // tracking navigation events, we treat this event as a sub frame navigation
1717 // event.
1718 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:581719 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221720 // Whether or not a page transition was triggered by going backward or
1721 // forward in the history is only stored in the navigation controller's
1722 // entry list.
1723 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:511724 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:581725 content::PAGE_TRANSITION_FORWARD_BACK)) {
1726 transition_type = content::PageTransitionFromInt(
1727 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:221728 }
[email protected]0d60f0192011-04-14 12:40:101729 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:251730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101731 DidCommitProvisionalLoadForFrame(params.frame_id,
1732 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221733 }
1734
[email protected]76543b92009-08-31 17:27:451735 if (!did_navigate)
1736 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321737
1738 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1739 // for the appropriate notification (best) or you can add it to
1740 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1741 // necessary, please).
1742
1743 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001744 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321745 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:511746 if (delegate_)
1747 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001748 }
[email protected]420ae012009-04-24 05:16:321749 DidNavigateAnyFramePostCommit(rvh, details, params);
1750}
1751
1752void TabContents::UpdateState(RenderViewHost* rvh,
1753 int32 page_id,
1754 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151755 // Ensure that this state update comes from either the active RVH or one of
1756 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:521757 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321758
1759 // We must be prepared to handle state updates for any page, these occur
1760 // when the user is scrolling and entering form data, as well as when we're
1761 // leaving a page, in which case our state may have already been moved to
1762 // the next page. The navigation controller will look up the appropriate
1763 // NavigationEntry and update it when it is notified via the delegate.
1764
1765 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151766 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321767 if (entry_index < 0)
1768 return;
[email protected]10f417c52011-12-28 21:04:231769 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:321770
[email protected]36fc0392011-12-25 03:59:511771 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:321772 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:511773 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:321774 controller_.NotifyEntryChanged(entry, entry_index);
1775}
1776
1777void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:571778 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:461779 const string16& title,
1780 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:321781 // If we have a title, that's a pretty good indication that we've started
1782 // getting useful data.
1783 SetNotWaitingForResponse();
1784
[email protected]151a63d2011-12-20 22:32:521785 DCHECK(rvh == GetRenderViewHost());
[email protected]10f417c52011-12-28 21:04:231786 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
1787 rvh->site_instance(), page_id);
[email protected]987fc3a2011-05-26 14:18:091788
[email protected]a49e10b2011-08-01 23:57:461789 // TODO(evan): make use of title_direction.
1790 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:091791 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321792 return;
1793
1794 // Broadcast notifications when the UI should be updated.
1795 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031796 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321797}
1798
[email protected]420ae012009-04-24 05:16:321799void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401800 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311801 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:321802}
1803
1804void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:511805 if (delegate_)
1806 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:321807}
1808
[email protected]420ae012009-04-24 05:16:321809void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291810 // The UI may be in an event-tracking loop, such as between the
1811 // mouse-down and mouse-up in text selection or a button click.
1812 // Defer the close until after tracking is complete, so that we
1813 // don't free objects out from under the UI.
1814 // TODO(shess): This could probably be integrated with the
1815 // IsDoingDrag() test below. Punting for now because I need more
1816 // research to understand how this impacts platforms other than Mac.
1817 // TODO(shess): This could get more fine-grained. For instance,
1818 // closing a tab in another window while selecting text in the
1819 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:211820 if (GetView()->IsEventTracking()) {
1821 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:291822 return;
1823 }
1824
[email protected]24a4d1062009-07-10 23:10:421825 // If we close the tab while we're in the middle of a drag, we'll crash.
1826 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:211827 if (GetView()->IsDoingDrag()) {
1828 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:421829 return;
1830 }
1831
[email protected]420ae012009-04-24 05:16:321832 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:521833 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511834 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:321835}
1836
[email protected]cd9ed79d2011-11-15 19:22:571837void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521838 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:511839 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:571840}
1841
[email protected]420ae012009-04-24 05:16:321842void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:511843 if (delegate_ && delegate_->IsPopupOrPanel(this))
1844 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:321845}
1846
[email protected]7ab1e7d62009-10-14 23:32:011847void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321848 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491849
[email protected]6934a702011-12-20 00:04:511850 if (delegate_ && content_restrictions_) {
[email protected]c40d6232011-03-25 00:16:211851 content_restrictions_ = 0;
[email protected]6934a702011-12-20 00:04:511852 delegate_->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001853 }
[email protected]3c9e1872010-11-18 16:17:491854
1855 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251856 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321857}
1858
[email protected]7ab1e7d62009-10-14 23:32:011859void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321860 scoped_ptr<LoadNotificationDetails> details;
1861
[email protected]10f417c52011-12-28 21:04:231862 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321863 // An entry may not exist for a stop when loading an initial blank page or
1864 // if an iframe injected by script into a blank page finishes loading.
1865 if (entry) {
[email protected]420ae012009-04-24 05:16:321866 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1867
1868 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:511869 entry->GetVirtualURL(),
1870 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:321871 elapsed,
1872 &controller_,
1873 controller_.GetCurrentEntryIndex()));
1874 }
1875
[email protected]420ae012009-04-24 05:16:321876 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491877
1878 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251879 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321880}
1881
[email protected]c95fa8b2011-04-28 20:26:161882void TabContents::DidCancelLoading() {
1883 controller_.DiscardNonCommittedEntries();
1884
1885 // Update the URL display.
1886 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1887}
1888
[email protected]1a3c3cb2010-12-16 21:03:401889void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:511890 if (delegate_)
1891 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:401892}
1893
[email protected]952a68e2011-11-17 00:36:101894void TabContents::DocumentAvailableInMainFrame(
1895 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:251896 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:101897 DocumentAvailableInMainFrame());
1898}
1899
[email protected]25497492010-09-11 15:15:081900void TabContents::DocumentOnLoadCompletedInMainFrame(
1901 RenderViewHost* render_view_host,
1902 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:071903 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271904 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:321905 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531906 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:081907}
1908
[email protected]ae5184d62011-10-06 19:25:581909void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:151910 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:581911 WindowOpenDisposition disposition,
1912 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:481913 // Delegate to RequestTransferURL because this is just the generic
1914 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:581915 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:481916 GlobalRequestID());
1917}
1918
1919void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:581920 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:481921 WindowOpenDisposition disposition,
1922 int64 source_frame_id,
1923 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:201924 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:581925 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:581926 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351927 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321928 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1929 // generated suggestions).
1930 //
[email protected]e0112912011-02-02 22:54:351931 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161932 // want web sites to see a referrer of "chrome://blah" (and some
1933 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321934 // send to the site), so we send no referrer.
[email protected]bce1f1c2011-12-05 15:11:581935 OpenURLParams params(url, content::Referrer(), disposition,
[email protected]4ad5d77d2011-12-03 02:00:481936 render_manager_.web_ui()->link_transition_type(),
1937 false /* is_renderer_initiated */);
1938 params.transferred_global_request_id = old_request_id;
1939 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581940 transition_type = render_manager_.web_ui()->link_transition_type();
[email protected]420ae012009-04-24 05:16:321941 } else {
[email protected]4ad5d77d2011-12-03 02:00:481942 OpenURLParams params(url, referrer, disposition,
1943 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
1944 params.transferred_global_request_id = old_request_id;
1945 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:581946 }
1947 if (new_contents) {
1948 // Notify observers.
[email protected]d8c660432011-12-22 20:51:251949 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:581950 DidOpenRequestedURL(new_contents,
1951 url,
1952 referrer,
1953 disposition,
1954 transition_type,
1955 source_frame_id));
[email protected]420ae012009-04-24 05:16:321956 }
1957}
1958
[email protected]420ae012009-04-24 05:16:321959void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151960 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411961 const string16& message,
1962 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321963 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:471964 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:321965 IPC::Message* reply_msg,
1966 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071967 // Suppress JavaScript dialogs when requested. Also suppress messages when
1968 // showing an interstitial as it's shown over the previous page and we don't
1969 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501970 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151971 rvh->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:271972 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:071973 !delegate_ ||
1974 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321975
1976 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341977 content::JavaScriptDialogCreator::TitleType title_type;
1978 string16 title;
1979
1980 if (!frame_url.has_host()) {
1981 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1982 } else {
1983 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1984 title = net::FormatUrl(
1985 frame_url.GetOrigin(),
[email protected]597a867b2011-11-18 18:31:201986 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:301987 GetBrowserContext()));
[email protected]b627d9a2011-06-28 14:06:341988 }
1989
[email protected]2e5b90c2011-08-16 21:11:551990 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
1991 dialog_creator_->RunJavaScriptDialog(this,
1992 title_type,
1993 title,
[email protected]269f86d2011-12-07 02:43:471994 javascript_message_type,
[email protected]2e5b90c2011-08-16 21:11:551995 message,
1996 default_prompt,
1997 reply_msg,
1998 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321999 }
[email protected]3ab9cb82011-06-03 18:02:072000
2001 if (suppress_this_message) {
2002 // If we are suppressing messages, just reply as if the user immediately
2003 // pressed "Cancel".
2004 OnDialogClosed(reply_msg, false, string16());
2005 }
2006
2007 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322008}
2009
[email protected]992db4c2011-05-12 15:37:152010void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412011 const string16& message,
[email protected]420ae012009-04-24 05:16:322012 IPC::Message* reply_msg) {
[email protected]6934a702011-12-20 00:04:512013 if (delegate_)
2014 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072015
2016 bool suppress_this_message =
2017 rvh->is_swapped_out() ||
2018 !delegate_ ||
2019 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:152020 if (suppress_this_message) {
[email protected]151a63d2011-12-20 22:32:522021 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502022 return;
2023 }
[email protected]3ab9cb82011-06-03 18:02:072024
[email protected]7ab1e7d62009-10-14 23:32:012025 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552026 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
2027 dialog_creator_->RunBeforeUnloadDialog(this,
2028 message,
2029 reply_msg);
[email protected]420ae012009-04-24 05:16:322030}
2031
[email protected]420ae012009-04-24 05:16:322032WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:082033 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:362034 content::GetContentClient()->browser()->GetWebkitPrefs(
[email protected]151a63d2011-12-20 22:32:522035 GetRenderViewHost());
[email protected]447021c2010-09-08 21:29:082036
[email protected]b8299c12011-06-03 19:52:282037 // Force accelerated compositing and 2d canvas off for chrome:, about: and
[email protected]2ef216b2011-08-01 19:25:212038 // chrome-devtools: pages (unless it's specifically allowed).
2039 if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]30b8e0ee2011-09-12 14:45:572040 // Allow accelerated compositing for keyboard and log in screen.
[email protected]b8299c12011-06-03 19:52:282041 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
[email protected]cd4a5bd22011-09-13 06:46:302042 (GetURL().SchemeIs(chrome::kAboutScheme) &&
2043 GetURL().spec() != chrome::kAboutBlankURL)) &&
[email protected]2ef216b2011-08-01 19:25:212044 !web_prefs.allow_webui_compositing) {
[email protected]447021c2010-09-08 21:29:082045 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432046 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082047 }
2048
2049 return web_prefs;
[email protected]420ae012009-04-24 05:16:322050}
2051
[email protected]7d472472011-01-22 01:30:252052void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272053 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252054 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222055
2056 ResourceDispatcherHost* rdh =
2057 content::GetContentClient()->browser()->GetResourceDispatcherHost();
2058 if (rdh) // NULL in unittests.
[email protected]8ec98cd22011-08-09 22:31:302059 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252060}
2061
[email protected]fa1cf0b82010-01-15 21:49:442062void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442063 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252064 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442065}
2066
[email protected]420ae012009-04-24 05:16:322067void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2068 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152069 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522070 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152071 return;
2072
[email protected]e5fc1632011-08-08 07:51:532073 // Ignore renderer unresponsive event if debugger is attached to the tab
2074 // since the event may be a result of the renderer sitting on a breakpoint.
2075 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442076 DevToolsAgentHost* agent =
2077 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2078 if (agent &&
2079 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532080 return;
2081
[email protected]420ae012009-04-24 05:16:322082 if (is_during_unload) {
2083 // Hang occurred while firing the beforeunload/unload handler.
2084 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112085 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322086
2087 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2088 return;
2089
2090 // If the tab hangs in the beforeunload/unload handler there's really
2091 // nothing we can do to recover. Pretend the unload listeners have
2092 // all fired and close the tab. If the hang is in the beforeunload handler
2093 // then the user will not have the option of cancelling the close.
2094 Close(rvh);
2095 return;
2096 }
2097
[email protected]151a63d2011-12-20 22:32:522098 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472099 return;
2100
[email protected]6934a702011-12-20 00:04:512101 if (delegate_)
2102 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322103}
2104
2105void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512106 if (delegate_)
2107 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322108}
2109
2110void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212111 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562112 uint64 upload_position,
2113 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322114 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562115 upload_position_ = upload_position;
2116 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502117 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202118 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302119 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212120 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322121 SetNotWaitingForResponse();
[email protected]f5d978c2011-07-21 14:43:512122 if (IsLoading())
[email protected]c9cd2222009-05-06 05:16:502123 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322124}
2125
[email protected]7d472472011-01-22 01:30:252126void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512127 if (delegate_)
2128 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252129}
2130
[email protected]420ae012009-04-24 05:16:322131void TabContents::BeforeUnloadFiredFromRenderManager(
2132 bool proceed,
2133 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512134 if (delegate_)
2135 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322136}
2137
[email protected]3a3d47472010-07-15 21:03:542138void TabContents::DidStartLoadingFromRenderManager(
2139 RenderViewHost* render_view_host) {
2140 DidStartLoading();
2141}
2142
2143void TabContents::RenderViewGoneFromRenderManager(
2144 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232145 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2146 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542147}
2148
[email protected]420ae012009-04-24 05:16:322149void TabContents::UpdateRenderViewSizeForRenderManager() {
2150 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262151 gfx::Size size = view_->GetContainerSize();
2152 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2153 // here during container initialization and normal window size will be set
2154 // later. In case of tab duplication this resizing to 0x0 prevents setting
2155 // normal size later so just ignore it.
2156 if (!size.IsEmpty())
2157 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322158}
2159
[email protected]3a3d47472010-07-15 21:03:542160void TabContents::NotifySwappedFromRenderManager() {
2161 NotifySwapped();
2162}
2163
2164NavigationController& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202165 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542166}
2167
[email protected]d0980792011-02-13 19:41:402168WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562169 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322170}
2171
[email protected]10f417c52011-12-28 21:04:232172NavigationEntry*
2173 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322174 return controller_.GetLastCommittedEntry();
2175}
2176
2177bool TabContents::CreateRenderViewForRenderManager(
2178 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442179 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322180 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522181
[email protected]420ae012009-04-24 05:16:322182 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442183 if (rwh_view)
2184 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322185
[email protected]74ce1ad2011-12-16 21:51:462186 // Make sure we use the correct starting page_id in the new RenderView.
2187 UpdateMaxPageIDIfNecessary(render_view_host);
2188 int32 max_page_id =
2189 GetMaxPageIDForSiteInstance(render_view_host->site_instance());
2190
2191 if (!render_view_host->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522192 return false;
2193
[email protected]e60c0232011-11-11 19:56:352194#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502195 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2196 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442197 if (rwh_view) {
2198 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2199 render_widget_host->WasResized();
2200 }
[email protected]f8233cc2011-05-31 20:24:502201#endif
2202
[email protected]420ae012009-04-24 05:16:322203 return true;
2204}
2205
[email protected]3ab9cb82011-06-03 18:02:072206void TabContents::OnDialogClosed(IPC::Message* reply_msg,
2207 bool success,
2208 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542209 if (is_showing_before_unload_dialog_ && !success) {
2210 // If a beforeunload dialog is canceled, we need to stop the throbber from
2211 // spinning, since we forced it to start spinning in Navigate.
2212 DidStopLoading();
2213
2214 tab_close_start_time_ = base::TimeTicks();
2215 }
2216 is_showing_before_unload_dialog_ = false;
[email protected]151a63d2011-12-20 22:32:522217 GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542218}
2219
[email protected]0b08add2011-11-29 03:27:062220gfx::NativeWindow TabContents::GetDialogRootWindow() const {
[email protected]3ab9cb82011-06-03 18:02:072221 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:542222}
2223
[email protected]a1e97f02011-06-30 14:04:342224void TabContents::OnDialogShown() {
2225 Activate();
[email protected]3a3d47472010-07-15 21:03:542226}
2227
[email protected]be1f56ab2011-12-22 06:55:312228void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122229 encoding_ = content::GetContentClient()->browser()->
2230 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102231}
[email protected]f45d2a72010-03-08 23:28:352232
[email protected]33f74972010-12-08 16:40:362233void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212234 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442235 // Can be NULL during tests.
2236 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212237 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362238}