blob: db5db15ab9f24780ab3d58492e24352c12383e28 [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]96d185d2009-04-24 03:28:5416#include "chrome/browser/debugger/devtools_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3317#include "chrome/browser/profiles/profile.h"
[email protected]567812d2011-02-24 17:40:5018#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5619#include "content/browser/content_browser_client.h"
[email protected]567812d2011-02-24 17:40:5020#include "content/browser/host_zoom_map.h"
21#include "content/browser/in_process_webkit/session_storage_namespace.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]567812d2011-02-24 17:40:5024#include "content/browser/renderer_host/render_process_host.h"
25#include "content/browser/renderer_host/render_view_host.h"
26#include "content/browser/renderer_host/render_widget_host_view.h"
27#include "content/browser/renderer_host/resource_request_details.h"
28#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4429#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1330#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/navigation_entry.h"
32#include "content/browser/tab_contents/provisional_load_details.h"
33#include "content/browser/tab_contents/tab_contents_delegate.h"
34#include "content/browser/tab_contents/tab_contents_observer.h"
35#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1436#include "content/browser/tab_contents/title_updated_details.h"
[email protected]afd1e522011-04-27 23:29:5937#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5638#include "content/browser/webui/web_ui_factory.h"
[email protected]9966325b2011-04-18 05:00:1039#include "content/common/bindings_policy.h"
[email protected]1fd1a502011-03-30 16:55:5640#include "content/common/content_client.h"
[email protected]763ec4ca2011-04-29 15:48:1241#include "content/common/content_restriction.h"
[email protected]4dd57932011-03-17 06:06:1242#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3243#include "content/common/notification_service.h"
[email protected]0f012df82011-05-19 14:15:2944#include "content/common/url_constants.h"
[email protected]2c5569662011-03-22 20:45:0245#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2946#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3247#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3448#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3749#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4650#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3851#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0352#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3153#include "webkit/glue/webpreferences.h"
54
55#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1256#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3157#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0058
[email protected]420ae012009-04-24 05:16:3259// Cross-Site Navigations
60//
61// If a TabContents is told to navigate to a different web site (as determined
62// by SiteInstance), it will replace its current RenderViewHost with a new
63// RenderViewHost dedicated to the new SiteInstance. This works as follows:
64//
65// - Navigate determines whether the destination is cross-site, and if so,
66// it creates a pending_render_view_host_ and moves into the PENDING
67// RendererState.
68// - The pending RVH is "suspended," so that no navigation messages are sent to
69// its renderer until the onbeforeunload JavaScript handler has a chance to
70// run in the current RVH.
71// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
72// that it has a pending cross-site request. ResourceDispatcherHost will
73// check for this when the response arrives.
74// - The current RVH runs its onbeforeunload handler. If it returns false, we
75// cancel all the pending logic and go back to NORMAL. Otherwise we allow
76// the pending RVH to send the navigation request to its renderer.
77// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
78// checks CrossSiteRequestManager to see that the RVH responsible has a
79// pending cross-site request, and then installs a CrossSiteEventHandler.
80// - When RDH receives a response, the BufferedEventHandler determines whether
81// it is a download. If so, it sends a message to the new renderer causing
82// it to cancel the request, and the download proceeds in the download
83// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:3484// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:3285// doesn't affect any functionality.
86// - After RDH receives a response and determines that it is safe and not a
87// download, it pauses the response to first run the old page's onunload
88// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1589// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3290// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1591// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3292// the ResourceDispatcherHost, who unpauses the response. Data is then sent
93// to the pending RVH.
94// - The pending renderer sends a FrameNavigate message that invokes the
95// DidNavigate method. This replaces the current RVH with the
96// pending RVH and goes back to the NORMAL RendererState.
[email protected]992db4c2011-05-12 15:37:1597// - The previous renderer is kept swapped out in RenderViewHostManager in case
98// the user goes back. The process only stays live if another tab is using
99// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32100
101namespace {
102
103// Amount of time we wait between when a key event is received and the renderer
104// is queried for its state and pushed to the NavigationEntry.
105const int kQueryStateDelay = 5000;
106
[email protected]6ebdc9b2010-09-27 16:55:57107const int kSyncWaitDelay = 40;
108
[email protected]420ae012009-04-24 05:16:32109#if defined(OS_WIN)
110
111BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
112 // Note: erase is required to properly paint some widgets borders. This can
113 // be seen with textfields.
114 InvalidateRect(hwnd, NULL, TRUE);
115 return TRUE;
116}
117#endif
118
[email protected]2c5569662011-03-22 20:45:02119ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16120 Profile* profile, const NavigationEntry& entry,
121 NavigationController::ReloadType reload_type) {
122 switch (reload_type) {
123 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02124 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16125 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02126 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16127 case NavigationController::NO_RELOAD:
128 break; // Fall through to rest of function.
129 }
[email protected]5e369672009-11-03 23:48:30130
131 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
132 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02133 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30134
[email protected]2c5569662011-03-22 20:45:02135 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30136}
137
[email protected]876bc832010-09-07 16:29:54138void MakeNavigateParams(const NavigationEntry& entry,
139 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16140 NavigationController::ReloadType reload_type,
141 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34142 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54143 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00144 params->current_history_list_offset = controller.last_committed_entry_index();
145 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34146 params->url = entry.url();
147 params->referrer = entry.referrer();
148 params->transition = entry.transition_type();
149 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00150 params->navigation_type =
151 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34152 params->request_time = base::Time::Now();
153}
154
[email protected]420ae012009-04-24 05:16:32155} // namespace
156
[email protected]f4f50ef2011-01-21 19:01:19157
158// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32159
[email protected]420ae012009-04-24 05:16:32160TabContents::TabContents(Profile* profile,
161 SiteInstance* site_instance,
162 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07163 const TabContents* base_tab_contents,
164 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42165 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07166 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
167 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13168 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22169 TabContentsView::Create(this))),
170 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06171 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34172 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23173 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
174 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34175 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34176 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57177 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56178 upload_size_(0),
179 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47180 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57181 capturing_contents_(false),
182 is_being_destroyed_(false),
183 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57184#if defined(OS_WIN)
185 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
186#endif
[email protected]7ab1e7d62009-10-14 23:32:01187 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56188 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38189 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25190 minimum_zoom_percent_(
191 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
192 maximum_zoom_percent_(
193 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00194 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59195 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54196
[email protected]12636df2009-09-28 22:32:21197 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32198
[email protected]34ac70502009-09-25 17:07:23199 // We have the initial size of the view be based on the size of the passed in
200 // tab contents (normally a tab from the same window).
201 view_->CreateView(base_tab_contents ?
202 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32203
[email protected]420ae012009-04-24 05:16:32204 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
205 NotificationService::AllSources());
[email protected]88152052010-10-01 04:05:18206
[email protected]b5a1d11c2011-02-17 03:09:42207 // Can only add observers after render_manager_.Init() is called, since that's
208 // what sets up the render_view_host which TabContentObserver's constructor
209 // uses to get the routing_id.
210 AddObservers();
[email protected]332af7732009-03-11 13:21:35211}
initial.commit09911bf2008-07-26 23:55:29212
213TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32214 is_being_destroyed_ = true;
215
[email protected]bfe4c1582009-10-02 18:11:09216 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32217 registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32218
[email protected]3ab9cb82011-06-03 18:02:07219 // Clear out any JavaScript state.
220 if (delegate_)
221 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this);
222
[email protected]420ae012009-04-24 05:16:32223 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32224
[email protected]420ae012009-04-24 05:16:32225 // First cleanly close all child windows.
226 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
227 // some of these to close. CloseWindows is async, so it might get called
228 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49229 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32230
[email protected]420ae012009-04-24 05:16:32231 // Notify any observer that have a reference on this tab contents.
232 NotificationService::current()->Notify(
233 NotificationType::TAB_CONTENTS_DESTROYED,
234 Source<TabContents>(this),
235 NotificationService::NoDetails());
236
237 // TODO(brettw) this should be moved to the view.
238#if defined(OS_WIN)
239 // If we still have a window handle, destroy it. GetNativeView can return
240 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42241 if (GetNativeView()) {
242 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44243 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42244 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42245 }
[email protected]420ae012009-04-24 05:16:32246#endif
[email protected]7ab1e7d62009-10-14 23:32:01247
248 // OnCloseStarted isn't called in unit tests.
249 if (!tab_close_start_time_.is_null()) {
250 UMA_HISTOGRAM_TIMES("Tab.Close",
251 base::TimeTicks::Now() - tab_close_start_time_);
252 }
[email protected]b5a1d11c2011-02-17 03:09:42253
[email protected]07d490bc2011-03-07 17:05:26254 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08255
256 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42257}
258
259void TabContents::AddObservers() {
[email protected]232a5812011-03-04 22:42:08260 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29261}
262
[email protected]724159a2010-12-30 01:11:18263bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17264 if (web_ui() && web_ui()->OnMessageReceived(message))
265 return true;
266
[email protected]585b30362011-01-28 02:30:17267 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
268 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10269 while ((observer = it.GetNext()) != NULL)
270 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53271 return true;
[email protected]403415a2011-01-10 18:57:53272
[email protected]724159a2010-12-30 01:11:18273 bool handled = true;
274 bool message_is_ok = true;
275 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
276 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
277 OnDidStartProvisionalLoadForFrame)
278 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
279 OnDidRedirectProvisionalLoad)
280 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
281 OnDidFailProvisionalLoadWithError)
282 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
283 OnDidLoadResourceFromMemoryCache)
284 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
285 OnDidDisplayInsecureContent)
286 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
287 OnDidRunInsecureContent)
288 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
289 OnDocumentLoadedInFrame)
290 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17291 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
292 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25293 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26294 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
295 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]724159a2010-12-30 01:11:18296 IPC_MESSAGE_UNHANDLED(handled = false)
297 IPC_END_MESSAGE_MAP_EX()
298
299 if (!message_is_ok) {
300 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
301 GetRenderProcessHost()->ReceivedBadMessage();
302 }
303
304 return handled;
305}
306
[email protected]13367f72009-07-08 16:39:02307// Returns true if contains content rendered by an extension.
308bool TabContents::HostsExtension() const {
309 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34310}
311
[email protected]8cb5d5b2010-02-09 11:36:16312RenderProcessHost* TabContents::GetRenderProcessHost() const {
313 return render_manager_.current_host()->process();
314}
315
[email protected]d5f942ba2008-09-26 19:30:34316const GURL& TabContents::GetURL() const {
317 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57318 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54319 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34320}
321
[email protected]96d185d2009-04-24 03:28:54322const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55323 // Transient entries take precedence. They are used for interstitial pages
324 // that are shown on top of existing pages.
325 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08326 std::string accept_languages =
327 content::GetContentClient()->browser()->GetAcceptLangs(this);
[email protected]45d0ef7f2011-01-05 13:46:23328 if (entry) {
[email protected]b5cca982011-05-26 04:42:08329 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23330 }
[email protected]7ade2732011-02-10 00:13:58331 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
332 render_manager_.pending_web_ui() : render_manager_.web_ui();
333 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54334 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55335 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54336 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35337 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58338 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54339 if (!title.empty())
340 return title;
341 }
342 }
343
344 // We use the title for the last committed entry rather than a pending
345 // navigation entry. For example, when the user types in a URL, we want to
346 // keep the old page's title until the new load has committed and we get a new
347 // title.
[email protected]96d185d2009-04-24 03:28:54348 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23349 if (entry) {
[email protected]b5cca982011-05-26 04:42:08350 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23351 }
[email protected]987fc3a2011-05-26 14:18:09352
353 // |page_title_when_no_navigation_entry_| is finally used
354 // if no title cannot be retrieved.
355 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54356}
357
[email protected]d5f942ba2008-09-26 19:30:34358int32 TabContents::GetMaxPageID() {
359 if (GetSiteInstance())
360 return GetSiteInstance()->max_page_id();
361 else
362 return max_page_id_;
363}
364
365void TabContents::UpdateMaxPageID(int32 page_id) {
366 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34367 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34368 // testing.
369 if (GetSiteInstance())
370 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16371 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34372}
373
[email protected]96d185d2009-04-24 03:28:54374SiteInstance* TabContents::GetSiteInstance() const {
375 return render_manager_.current_host()->site_instance();
376}
377
[email protected]96d185d2009-04-24 03:28:54378bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15379 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54380 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15381 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01382 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54383 return true;
[email protected]8ab24cc2009-11-13 20:56:15384 }
[email protected]83e3895b2009-06-11 00:07:16385
[email protected]2b9a06402011-02-16 04:57:10386 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56387 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10388 return true;
389
[email protected]d0980792011-02-13 19:41:40390 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58391 if (web_ui)
392 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54393 return true;
394}
395
[email protected]585b30362011-01-28 02:30:17396void TabContents::AddObserver(TabContentsObserver* observer) {
397 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49398}
399
[email protected]585b30362011-01-28 02:30:17400void TabContents::RemoveObserver(TabContentsObserver* observer) {
401 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49402}
403
[email protected]443b80e2010-12-14 00:42:23404void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
405 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34406 return;
407
[email protected]443b80e2010-12-14 00:42:23408 crashed_status_ = status;
409 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50410 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34411}
412
413void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
414 if (delegate_)
415 delegate_->NavigationStateChanged(this, changed_flags);
416}
417
[email protected]96d185d2009-04-24 03:28:54418void TabContents::DidBecomeSelected() {
419 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16420 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
421 if (rwhv) {
422 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43423#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16424 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43425#endif
426 }
[email protected]96d185d2009-04-24 03:28:54427
[email protected]5ac20162010-11-24 23:33:11428 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38429
430 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54431}
432
433void TabContents::WasHidden() {
434 if (!capturing_contents()) {
435 // |render_view_host()| can be NULL if the user middle clicks a link to open
436 // a tab in then background, then closes the tab before selecting it. This
437 // is because closing the tab calls TabContents::Destroy(), which removes
438 // the |render_view_host()|; then when we actually destroy the window,
439 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16440 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
441 if (rwhv)
442 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54443 }
444
445 NotificationService::current()->Notify(
446 NotificationType::TAB_CONTENTS_HIDDEN,
447 Source<TabContents>(this),
448 NotificationService::NoDetails());
449}
450
[email protected]d5f942ba2008-09-26 19:30:34451void TabContents::Activate() {
452 if (delegate_)
453 delegate_->ActivateContents(this);
454}
455
[email protected]ea42e7782010-08-23 23:58:12456void TabContents::Deactivate() {
457 if (delegate_)
458 delegate_->DeactivateContents(this);
459}
460
[email protected]96d185d2009-04-24 03:28:54461void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16462 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
463 if (rwhv)
464 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54465}
466
467void TabContents::HideContents() {
468 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
469 // our superclass HideContents(), because some callers want to be very picky
470 // about the order in which these get called. In addition to making the code
471 // here practically impossible to understand, this also means we end up
472 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34473 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54474 WasHidden();
475}
476
[email protected]5aab5e22010-12-08 22:13:29477bool TabContents::NeedToFireBeforeUnload() {
478 // TODO(creis): Should we fire even for interstitial pages?
479 return notify_disconnection() &&
480 !showing_interstitial_page() &&
481 !render_view_host()->SuddenTerminationAllowed();
482}
483
[email protected]c0588052008-10-27 23:01:50484void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34485 WindowOpenDisposition disposition,
486 PageTransition::Type transition) {
[email protected]1c642b52011-04-15 09:05:49487 if (delegate_) {
[email protected]c0588052008-10-27 23:01:50488 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]1c642b52011-04-15 09:05:49489 // Notify observers.
490 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
491 DidOpenURL(url, referrer, disposition, transition));
492 }
[email protected]d5f942ba2008-09-26 19:30:34493}
494
[email protected]1ccb3568d2010-02-19 10:51:16495bool TabContents::NavigateToPendingEntry(
496 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54497 return NavigateToEntry(*controller_.pending_entry(), reload_type);
498}
[email protected]96d185d2009-04-24 03:28:54499
[email protected]876bc832010-09-07 16:29:54500bool TabContents::NavigateToEntry(
501 const NavigationEntry& entry,
502 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54503 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
504 if (!dest_render_view_host)
505 return false; // Unable to create the desired render view host.
506
[email protected]770dd8b2010-05-24 18:11:39507 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
[email protected]216813952011-05-19 22:21:26508 dest_render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
509 dest_render_view_host->routing_id(),
510 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow));
[email protected]770dd8b2010-05-24 18:11:39511 }
[email protected]9fb325e2010-05-06 18:23:24512
[email protected]80a8fad2011-01-29 04:02:38513 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07514 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58515 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56516 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
517 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
518 entry.url());
[email protected]c09163a2011-02-15 00:05:55519 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
520 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58521
[email protected]96d185d2009-04-24 03:28:54522 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12523 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32524 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00525 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
526 dest_render_view_host,
527 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32528 }
[email protected]96d185d2009-04-24 03:28:54529
530 // Used for page load time metrics.
531 current_load_start_ = base::TimeTicks::Now();
532
533 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34534 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54535 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04536 if (delegate_) {
537 navigate_params.extra_headers =
538 delegate_->GetNavigationHeaders(navigate_params.url);
539 }
[email protected]056de2d2009-06-26 16:41:34540 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54541
542 if (entry.page_id() == -1) {
543 // HACK!! This code suppresses javascript: URLs from being added to
544 // session history, which is what we want to do for javascript: URLs that
545 // do not generate content. What we really need is a message from the
546 // renderer telling us that a new page was not created. The same message
547 // could be used for mailto: URLs and the like.
548 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
549 return false;
550 }
551
[email protected]3c9e1872010-11-18 16:17:49552 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04553 FOR_EACH_OBSERVER(TabContentsObserver,
554 observers_,
555 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54556
[email protected]d5f942ba2008-09-26 19:30:34557 return true;
558}
559
[email protected]96d185d2009-04-24 03:28:54560void TabContents::Stop() {
561 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47562 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54563}
564
[email protected]96d185d2009-04-24 03:28:54565TabContents* TabContents::Clone() {
566 // We create a new SiteInstance so that the new tab won't share processes
567 // with the old one. This can be changed in the future if we need it to share
568 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32569 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54570 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07571 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54572 tc->controller().CopyStateFrom(controller_);
573 return tc;
574}
575
[email protected]4d677202009-07-19 07:37:12576void TabContents::ShowPageInfo(const GURL& url,
577 const NavigationEntry::SSLStatus& ssl,
578 bool show_history) {
579 if (!delegate_)
580 return;
581
[email protected]bb678332009-07-21 00:15:50582 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12583}
584
initial.commit09911bf2008-07-26 23:55:29585ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28586 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29587 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28588 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33589 AddConstrainedDialog(window);
590 return window;
591}
592
593void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29594 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44595
596 if (child_windows_.size() == 1) {
597 window->ShowConstrainedWindow();
598 BlockTabContent(true);
599 }
initial.commit09911bf2008-07-26 23:55:29600}
601
[email protected]fa1cf0b82010-01-15 21:49:44602void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55603 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45604 // 70% opaque grey.
605 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55606 if (rwhv)
[email protected]1b072562010-12-13 19:37:45607 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]a7eccac2011-04-15 03:05:19608 // RenderViewHost may be NULL during shutdown.
609 if (render_view_host())
610 render_view_host()->set_ignore_input_events(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44611 if (delegate_)
612 delegate_->SetTabContentBlocked(this, blocked);
613}
614
[email protected]e7cfdbd2011-04-22 14:41:37615void TabContents::AddNewContents(TabContents* new_contents,
616 WindowOpenDisposition disposition,
617 const gfx::Rect& initial_pos,
618 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29619 if (!delegate_)
620 return;
621
[email protected]e7cfdbd2011-04-22 14:41:37622 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
623 user_gesture);
[email protected]96d185d2009-04-24 03:28:54624}
625
[email protected]5c9e97a2009-09-09 23:48:30626gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54627 return view_->GetContentNativeView();
628}
629
630gfx::NativeView TabContents::GetNativeView() const {
631 return view_->GetNativeView();
632}
633
634void TabContents::GetContainerBounds(gfx::Rect *out) const {
635 view_->GetContainerBounds(out);
636}
637
638void TabContents::Focus() {
639 view_->Focus();
640}
641
[email protected]90daadb42009-06-08 21:27:28642void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54643 if (showing_interstitial_page()) {
644 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
645 return;
646 }
[email protected]96d185d2009-04-24 03:28:54647 render_view_host()->SetInitialFocus(reverse);
648}
649
650bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40651 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58652 if (web_ui)
653 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43654 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25655 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43656 return true;
[email protected]96d185d2009-04-24 03:28:54657 return false;
658}
659
[email protected]a26dc362010-04-23 01:48:58660void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38661 if (delegate())
[email protected]a26dc362010-04-23 01:48:58662 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38663}
664
[email protected]d5f942ba2008-09-26 19:30:34665void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:37666 ConstrainedWindowList::iterator i(
667 std::find(child_windows_.begin(), child_windows_.end(), window));
668 bool removed_topmost_window = i == child_windows_.begin();
669 if (i != child_windows_.end())
670 child_windows_.erase(i);
671 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:44672 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:37673 } else {
674 if (removed_topmost_window)
675 child_windows_[0]->ShowConstrainedWindow();
676 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:44677 }
[email protected]66ba4932009-06-04 19:22:13678}
[email protected]d5f942ba2008-09-26 19:30:34679
[email protected]420ae012009-04-24 05:16:32680bool TabContents::IsActiveEntry(int32 page_id) {
681 NavigationEntry* active_entry = controller_.GetActiveEntry();
682 return (active_entry != NULL &&
683 active_entry->site_instance() == GetSiteInstance() &&
684 active_entry->page_id() == page_id);
685}
686
[email protected]b2fe07d12010-02-09 14:38:08687void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16688 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26689 render_view_host()->Send(new ViewMsg_SetPageEncoding(
690 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16691}
692
[email protected]b2fe07d12010-02-09 14:38:08693void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16694 reset_encoding();
[email protected]216813952011-05-19 22:21:26695 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
696 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16697}
698
[email protected]7ab1e7d62009-10-14 23:32:01699void TabContents::OnCloseStarted() {
700 if (tab_close_start_time_.is_null())
701 tab_close_start_time_ = base::TimeTicks::Now();
702}
703
[email protected]46624bf2010-06-09 16:04:19704bool TabContents::ShouldAcceptDragAndDrop() const {
705#if defined(OS_CHROMEOS)
706 // ChromeOS panels (pop-ups) do not take drag-n-drop.
707 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14708 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20709 return false;
710 return true;
[email protected]46624bf2010-06-09 16:04:19711#else
712 return true;
713#endif
714}
715
[email protected]7813bd72011-02-05 02:19:34716void TabContents::SystemDragEnded() {
717 if (render_view_host())
718 render_view_host()->DragSourceSystemDragEnded();
719 if (delegate())
720 delegate()->DragEnded();
721}
722
[email protected]d0b8d092010-10-25 04:05:17723double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:25724 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
725 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17726 return 0;
[email protected]b75b8292010-10-01 07:28:25727
728 double zoom_level;
729 if (temporary_zoom_settings_) {
730 zoom_level = zoom_map->GetTemporaryZoomLevel(
731 GetRenderProcessHost()->id(), render_view_host()->routing_id());
732 } else {
[email protected]13ffa32e2011-05-27 16:37:01733 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(GetURL()));
[email protected]b75b8292010-10-01 07:28:25734 }
[email protected]d0b8d092010-10-25 04:05:17735 return zoom_level;
736}
[email protected]b75b8292010-10-01 07:28:25737
[email protected]d0b8d092010-10-25 04:05:17738int TabContents::GetZoomPercent(bool* enable_increment,
739 bool* enable_decrement) {
740 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:25741 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:17742 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:25743 *enable_decrement = percent > minimum_zoom_percent_;
744 *enable_increment = percent < maximum_zoom_percent_;
745 return percent;
746}
747
[email protected]3c733bde2010-12-21 19:56:31748void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50749 if (!delegate_)
750 return;
751
752 NavigationEntry* active_entry = controller().GetActiveEntry();
753 if (!active_entry)
754 return;
755
756 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12757}
758
[email protected]932b7a12011-03-09 12:50:27759void TabContents::ViewFrameSource(const GURL& url,
760 const std::string& content_state) {
761 if (!delegate_)
762 return;
763
764 delegate_->ViewSourceForFrame(this, url, content_state);
765}
766
[email protected]c40d6232011-03-25 00:16:21767void TabContents::SetContentRestrictions(int restrictions) {
768 content_restrictions_ = restrictions;
769 delegate()->ContentRestrictionsChanged(this);
770}
771
[email protected]724159a2010-12-30 01:11:18772void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
773 bool is_main_frame,
[email protected]eacb080b2011-05-22 19:40:26774 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18775 const GURL& url) {
776 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
777 GURL validated_url(url);
778 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
779 GetRenderProcessHost()->id(), &validated_url);
780
[email protected]8093a542011-05-13 07:29:32781 RenderViewHost* rvh =
782 render_manager_.pending_render_view_host() ?
783 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10784 // Notify observers about the start of the provisional load.
785 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
786 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32787 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10788
[email protected]724159a2010-12-30 01:11:18789 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59790 // Notify observers about the provisional change in the main frame URL.
791 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26792 ProvisionalChangeToMainFrameUrl(url, has_opener_set));
[email protected]724159a2010-12-30 01:11:18793 }
794}
795
796void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26797 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18798 const GURL& source_url,
799 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49800 // TODO(creis): Remove this method and have the pre-rendering code listen to
801 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
802 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18803 NavigationEntry* entry;
804 if (page_id == -1)
805 entry = controller_.pending_entry();
806 else
807 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
808 if (!entry || entry->url() != source_url)
809 return;
[email protected]e7d50892011-01-19 21:47:38810
[email protected]4850a7f2011-03-08 23:36:59811 // Notify observers about the provisional change in the main frame URL.
812 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26813 ProvisionalChangeToMainFrameUrl(target_url,
814 has_opener_set));
[email protected]724159a2010-12-30 01:11:18815}
816
817void TabContents::OnDidFailProvisionalLoadWithError(
818 int64 frame_id,
819 bool is_main_frame,
820 int error_code,
821 const GURL& url,
822 bool showing_repost_interstitial) {
823 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
824 << ", error_code: " << error_code
825 << " is_main_frame: " << is_main_frame
826 << " showing_repost_interstitial: " << showing_repost_interstitial
827 << " frame_id: " << frame_id;
828 GURL validated_url(url);
829 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
830 GetRenderProcessHost()->id(), &validated_url);
831
832 if (net::ERR_ABORTED == error_code) {
833 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
834 // This means that the interstitial won't be torn down properly, which is
835 // bad. But if we have an interstitial, go back to another tab type, and
836 // then load the same interstitial again, we could end up getting the first
837 // interstitial's "failed" message (as a result of the cancel) when we're on
838 // the second one.
839 //
840 // We can't tell this apart, so we think we're tearing down the current page
841 // which will cause a crash later one. There is also some code in
842 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
843 // out because of this problem.
844 //
845 // http://code.google.com/p/chromium/issues/detail?id=2855
846 // Because this will not tear down the interstitial properly, if "back" is
847 // back to another tab type, the interstitial will still be somewhat alive
848 // in the previous tab type. If you navigate somewhere that activates the
849 // tab with the interstitial again, you'll see a flash before the new load
850 // commits of the interstitial page.
851 if (showing_interstitial_page()) {
852 LOG(WARNING) << "Discarding message during interstitial.";
853 return;
854 }
855
[email protected]02102f82011-06-13 20:37:02856 // Discard our pending entry if the load canceled (e.g. if we decided to
857 // download the file instead of load it). We do not verify that the URL
858 // being canceled matches the pending entry's URL because they will not
859 // match if a redirect occurred (in which case we do not want to leave a
860 // stale redirect URL showing). This means that we also cancel the pending
861 // entry if the user started a new navigation. As a result, the navigation
862 // controller may not remember that a load is in progress, but the
863 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:18864 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:02865 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:16866 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:18867
868 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
869 }
870
871 // Send out a notification that we failed a provisional load with an error.
872 ProvisionalLoadDetails details(
873 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:09874 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:18875 details.set_error_code(error_code);
876
877 NotificationService::current()->Notify(
878 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
879 Source<NavigationController>(&controller_),
880 Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:10881
882 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
883 DidFailProvisionalLoad(frame_id, is_main_frame,
884 validated_url, error_code));
[email protected]724159a2010-12-30 01:11:18885}
886
887void TabContents::OnDidLoadResourceFromMemoryCache(
888 const GURL& url,
[email protected]724159a2010-12-30 01:11:18889 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:19890 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:18891 cache.Increment();
892
893 // Send out a notification that we loaded a resource from our memory cache.
894 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
895 SSLManager::DeserializeSecurityInfo(security_info,
896 &cert_id, &cert_status,
897 &security_bits,
898 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:16899 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
900 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:18901
902 NotificationService::current()->Notify(
903 NotificationType::LOAD_FROM_MEMORY_CACHE,
904 Source<NavigationController>(&controller_),
905 Details<LoadFromMemoryCacheDetails>(&details));
906}
907
908void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:16909 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:18910 displayed_insecure_content_ = true;
911 SSLManager::NotifySSLInternalStateChanged();
912}
913
914void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:02915 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:23916 LOG(INFO) << security_origin << " ran insecure content from "
917 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:16918 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]724159a2010-12-30 01:11:18919 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:41920 displayed_insecure_content_ = true;
921 SSLManager::NotifySSLInternalStateChanged();
[email protected]724159a2010-12-30 01:11:18922}
923
924void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
925 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:10926 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
927 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:18928}
929
930void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:10931 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
932 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:18933}
934
[email protected]c8f73ab2011-01-22 00:05:17935void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:21936 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:17937}
938
[email protected]216813952011-05-19 22:21:26939void TabContents::OnGoToEntryAtOffset(int offset) {
940 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
941 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
942 if (!entry)
943 return;
944 // Note that we don't call NavigationController::GotToOffset() as we don't
945 // want to create a pending navigation entry (it might end up lingering
946 // http://crbug.com/51680).
947 entry->set_transition_type(entry->transition_type() |
948 PageTransition::FORWARD_BACK);
949 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
950 }
951}
952
953void TabContents::OnUpdateZoomLimits(int minimum_percent,
954 int maximum_percent,
955 bool remember) {
956 minimum_zoom_percent_ = minimum_percent;
957 maximum_zoom_percent_ = maximum_percent;
958 temporary_zoom_settings_ = !remember;
959}
960
961void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
962 NotificationService::current()->Notify(
963 NotificationType::FOCUS_CHANGED_IN_PAGE,
964 Source<TabContents>(this),
965 Details<const bool>(&is_editable_node));
966}
967
[email protected]96d185d2009-04-24 03:28:54968// Notifies the RenderWidgetHost instance about the fact that the page is
969// loading, or done loading and calls the base implementation.
970void TabContents::SetIsLoading(bool is_loading,
971 LoadNotificationDetails* details) {
972 if (is_loading == is_loading_)
973 return;
974
975 if (!is_loading) {
976 load_state_ = net::LOAD_STATE_IDLE;
977 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:56978 upload_size_ = 0;
979 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:54980 }
981
982 render_manager_.SetIsLoading(is_loading);
983
984 is_loading_ = is_loading;
985 waiting_for_response_ = is_loading;
986
[email protected]6ebdc9b2010-09-27 16:55:57987 if (delegate_)
988 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:35989 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:54990
991 NotificationType type = is_loading ? NotificationType::LOAD_START :
992 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:11993 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:54994 if (details)
995 det = Details<LoadNotificationDetails>(details);
996 NotificationService::current()->Notify(type,
997 Source<NavigationController>(&controller_),
998 det);
999}
1000
[email protected]d0980792011-02-13 19:41:401001WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581002 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541003 // that goes along with it to control the basic flags. For example, we want to
1004 // show the pending URL in the URL bar, so we want the display_url flag to
1005 // be from the pending entry.
1006 //
1007 // The confusion comes because there are multiple possibilities for the
1008 // initial load in a tab as a side effect of the way the RenderViewHostManager
1009 // works.
1010 //
[email protected]e0112912011-02-02 22:54:351011 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541012 // the pending one, and we want it to apply here.
1013 //
1014 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1015 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581016 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351017 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541018 //
1019 // This condition handles all of these cases:
1020 //
1021 // - First load in first tab: no committed nav entry + pending nav entry +
1022 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351023 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541024 //
1025 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351026 // no pending Web UI:
1027 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541028 //
1029 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351030 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541031 //
1032 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351033 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541034 if (controller_.pending_entry() &&
1035 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581036 render_manager_.pending_web_ui()))
1037 return render_manager_.pending_web_ui();
1038 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541039}
[email protected]420ae012009-04-24 05:16:321040
[email protected]1fd1a502011-03-30 16:55:561041WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1042 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1043}
1044
[email protected]420ae012009-04-24 05:16:321045void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131046 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321047 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561048 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381049 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441050 // that opened the window, as long as both renderers have the same
1051 // privileges.
[email protected]1fd1a502011-03-30 16:55:561052 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1053 WebUI* web_ui = content::GetContentClient()->browser()->
1054 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581055 // web_ui might be NULL if the URL refers to a non-existent extension.
1056 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401057 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581058 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441059 }
1060 }
[email protected]1fd1a502011-03-30 16:55:561061 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441062 }
1063
[email protected]420ae012009-04-24 05:16:321064 if (details.is_user_initiated_main_frame_load()) {
1065 // Clear the status bubble. This is a workaround for a bug where WebKit
1066 // doesn't let us know that the cursor left an element during a
1067 // transition (this is also why the mouse cursor remains as a hand after
1068 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1069 // clear the bubble when a user navigates to a named anchor in the same
1070 // page.
1071 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321072 }
1073
[email protected]a6e82fc2010-02-24 22:28:141074 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471075 // Once the main frame is navigated, we're no longer considered to have
1076 // displayed insecure content.
1077 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171078 }
[email protected]ce5c4502009-05-06 16:46:111079
[email protected]8cc8d492010-02-02 10:40:491080 // Close constrained windows if necessary.
1081 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1082 details.previous_url, details.entry->url()))
1083 CloseConstrainedWindows();
1084
[email protected]3c9e1872010-11-18 16:17:491085 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171086 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491087 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321088}
1089
1090void TabContents::DidNavigateAnyFramePostCommit(
1091 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131092 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321093 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071094 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321095 // a malicious script from spamming messages, since the script could just
1096 // reload the page to stop blocking.
[email protected]3ab9cb82011-06-03 18:02:071097 if (delegate_)
1098 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this);
[email protected]420ae012009-04-24 05:16:321099
[email protected]3c9e1872010-11-18 16:17:491100 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171101 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491102 DidNavigateAnyFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321103}
1104
[email protected]8cc8d492010-02-02 10:40:491105void TabContents::CloseConstrainedWindows() {
1106 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331107 // To ensure that we iterate over every element in child_windows_ we
1108 // need to use a copy of child_windows_. Otherwise if
1109 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1110 // skipping some elements.
1111 ConstrainedWindowList child_windows_copy(child_windows_);
1112 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1113 it != child_windows_copy.end(); ++it) {
1114 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441115 if (window) {
[email protected]420ae012009-04-24 05:16:321116 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441117 BlockTabContent(false);
1118 }
[email protected]420ae012009-04-24 05:16:321119 }
1120}
1121
[email protected]420ae012009-04-24 05:16:321122void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1123 RenderViewHost* rvh) {
1124 // If we are creating a RVH for a restored controller, then we might
1125 // have more page IDs than the SiteInstance's current max page ID. We must
1126 // make sure that the max page ID is larger than any restored page ID.
1127 // Note that it is ok for conflicting page IDs to exist in another tab
1128 // (i.e., NavigationController), but if any page ID is larger than the max,
1129 // the back/forward list will get confused.
1130 int max_restored_page_id = controller_.max_restored_page_id();
1131 if (max_restored_page_id > 0) {
1132 int curr_max_page_id = site_instance->max_page_id();
1133 if (max_restored_page_id > curr_max_page_id) {
1134 // Need to update the site instance immediately.
1135 site_instance->UpdateMaxPageID(max_restored_page_id);
1136
1137 // Also tell the renderer to update its internal representation. We
1138 // need to reserve enough IDs to make all restored page IDs less than
1139 // the max.
1140 if (curr_max_page_id < 0)
1141 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261142 rvh->Send(new ViewMsg_ReservePageIDRange(
1143 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321144 }
1145 }
1146}
1147
[email protected]6b2f7a82011-04-25 19:30:511148bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1149 const std::wstring& title) {
[email protected]420ae012009-04-24 05:16:321150 // For file URLs without a title, use the pathname instead. In the case of a
1151 // synthesized title, we don't want the update to count toward the "one set
1152 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511153 string16 final_title;
[email protected]420ae012009-04-24 05:16:321154 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091155 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511156 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321157 explicit_set = false; // Don't count synthetic titles toward the set limit.
1158 } else {
[email protected]6b2f7a82011-04-25 19:30:511159 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321160 explicit_set = true;
1161 }
1162
[email protected]987fc3a2011-05-26 14:18:091163 // If a page is created via window.open and never navigated,
1164 // there will be no navigation entry. In this situation,
1165 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1166 if (entry) {
1167 if (final_title == entry->title())
1168 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321169
[email protected]987fc3a2011-05-26 14:18:091170 entry->set_title(final_title);
1171 } else {
1172 if (page_title_when_no_navigation_entry_ == final_title)
1173 return false; // Nothing changed, don't bother.
1174
1175 page_title_when_no_navigation_entry_ = final_title;
1176 }
[email protected]420ae012009-04-24 05:16:321177
[email protected]420ae012009-04-24 05:16:321178 // Lastly, set the title for the view.
[email protected]6b2f7a82011-04-25 19:30:511179 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321180
[email protected]105bb0f2011-05-24 17:12:141181 TitleUpdatedDetails details(entry, explicit_set);
1182
[email protected]cbc0e1b2010-04-12 18:33:041183 NotificationService::current()->Notify(
1184 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1185 Source<TabContents>(this),
[email protected]105bb0f2011-05-24 17:12:141186 Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041187
[email protected]420ae012009-04-24 05:16:321188 return true;
1189}
1190
1191void TabContents::NotifySwapped() {
1192 // After sending out a swap notification, we need to send a disconnect
1193 // notification so that clients that pick up a pointer to |this| can NULL the
1194 // pointer. See Bug 1230284.
1195 notify_disconnection_ = true;
1196 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341197 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221198 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321199 NotificationService::NoDetails());
1200}
1201
1202void TabContents::NotifyConnected() {
1203 notify_disconnection_ = true;
1204 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341205 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221206 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321207 NotificationService::NoDetails());
1208}
1209
1210void TabContents::NotifyDisconnected() {
1211 if (!notify_disconnection_)
1212 return;
1213
1214 notify_disconnection_ = false;
1215 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341216 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221217 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321218 NotificationService::NoDetails());
1219}
1220
[email protected]8d3347f2009-07-09 22:00:211221RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321222 return view_.get();
1223}
1224
[email protected]8d3347f2009-07-09 22:00:211225RenderViewHostDelegate::RendererManagement*
1226TabContents::GetRendererManagementDelegate() {
1227 return &render_manager_;
1228}
1229
[email protected]ced90ae12010-02-20 02:06:161230RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1231 return bookmark_drag_;
1232}
1233
1234void TabContents::SetBookmarkDragDelegate(
1235 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1236 bookmark_drag_ = bookmark_drag;
1237}
1238
[email protected]93623c5d2009-12-10 21:40:321239RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461240 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511241}
1242
[email protected]57c6a652009-05-04 07:58:341243TabContents* TabContents::GetAsTabContents() {
1244 return this;
1245}
1246
[email protected]7b291f92009-08-14 05:43:531247ViewType::Type TabContents::GetRenderViewType() const {
1248 return ViewType::TAB_CONTENTS;
1249}
1250
[email protected]420ae012009-04-24 05:16:321251void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061252 NotificationService::current()->Notify(
1253 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1254 Source<TabContents>(this),
1255 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321256 NavigationEntry* entry = controller_.GetActiveEntry();
1257 if (!entry)
1258 return;
1259
1260 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351261 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561262 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581263 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321264
1265 if (entry->IsViewSourceMode()) {
1266 // Put the renderer in view source mode.
1267 render_view_host->Send(
1268 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1269 }
[email protected]0666aef2009-05-13 19:48:081270
1271 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261272
1273 FOR_EACH_OBSERVER(
1274 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]8683ad22011-06-08 19:17:151275
1276 if (delegate())
1277 delegate()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:321278}
1279
1280void TabContents::RenderViewReady(RenderViewHost* rvh) {
1281 if (rvh != render_view_host()) {
1282 // Don't notify the world, since this came from a renderer in the
1283 // background.
1284 return;
1285 }
1286
1287 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301288 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231289 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301290
1291 // Restore the focus to the tab (otherwise the focus will be on the top
1292 // window).
[email protected]484ae5912010-09-29 19:16:141293 if (was_crashed && !FocusLocationBarByDefault() &&
1294 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301295 Focus();
[email protected]484ae5912010-09-29 19:16:141296 }
[email protected]420ae012009-04-24 05:16:321297}
1298
[email protected]443b80e2010-12-14 00:42:231299void TabContents::RenderViewGone(RenderViewHost* rvh,
1300 base::TerminationStatus status,
1301 int error_code) {
[email protected]420ae012009-04-24 05:16:321302 if (rvh != render_view_host()) {
1303 // The pending page's RenderViewHost is gone.
1304 return;
1305 }
1306
1307 SetIsLoading(false, NULL);
1308 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231309 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321310
[email protected]55452902011-06-01 21:57:471311 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
[email protected]420ae012009-04-24 05:16:321312}
1313
[email protected]2e4633c2009-07-09 16:58:061314void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481315 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061316}
1317
[email protected]420ae012009-04-24 05:16:321318void TabContents::DidNavigate(RenderViewHost* rvh,
1319 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]93f230e02011-06-01 14:40:001320 scoped_ptr<TabContentsDelegate::MainFrameCommitDetails> commit_details;
[email protected]8030f012009-09-25 18:09:371321
1322 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]93f230e02011-06-01 14:40:001323 if (delegate())
1324 commit_details.reset(delegate()->CreateMainFrameCommitDetails(this));
[email protected]420ae012009-04-24 05:16:321325 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371326 }
1327
[email protected]420ae012009-04-24 05:16:321328 // Update the site of the SiteInstance if it doesn't have one yet.
1329 if (!GetSiteInstance()->has_site())
1330 GetSiteInstance()->SetSite(params.url);
1331
1332 // Need to update MIME type here because it's referred to in
1333 // UpdateNavigationCommands() called by RendererDidNavigate() to
1334 // determine whether or not to enable the encoding menu.
1335 // It's updated only for the main frame. For a subframe,
1336 // RenderView::UpdateURL does not set params.contents_mime_type.
1337 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1338 // TODO(jungshik): Add a test for the encoding menu to avoid
1339 // regressing it again.
1340 if (PageTransition::IsMainFrame(params.transition))
1341 contents_mime_type_ = params.contents_mime_type;
1342
[email protected]8286f51a2011-05-31 17:39:131343 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001344 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391345
[email protected]a9c0bfe2010-09-17 08:35:221346 // Send notification about committed provisional loads. This notification is
1347 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1348 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1349 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071350 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1351 // that is not recorded in the navigation history. For the purpose of
1352 // tracking navigation events, we treat this event as a sub frame navigation
1353 // event.
1354 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]0d60f0192011-04-14 12:40:101355 PageTransition::Type transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221356 // Whether or not a page transition was triggered by going backward or
1357 // forward in the history is only stored in the navigation controller's
1358 // entry list.
1359 if (did_navigate &&
1360 (controller_.GetActiveEntry()->transition_type() &
1361 PageTransition::FORWARD_BACK)) {
[email protected]0d60f0192011-04-14 12:40:101362 transition_type = params.transition | PageTransition::FORWARD_BACK;
[email protected]a9c0bfe2010-09-17 08:35:221363 }
[email protected]0d60f0192011-04-14 12:40:101364 // Notify observers about the commit of the provisional load.
1365 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1366 DidCommitProvisionalLoadForFrame(params.frame_id,
1367 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221368 }
1369
[email protected]76543b92009-08-31 17:27:451370 if (!did_navigate)
1371 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321372
1373 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1374 // for the appropriate notification (best) or you can add it to
1375 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1376 // necessary, please).
1377
1378 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001379 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321380 DidNavigateMainFramePostCommit(details, params);
[email protected]93f230e02011-06-01 14:40:001381 if (delegate() && commit_details.get())
1382 delegate()->DidNavigateMainFramePostCommit(this, *commit_details);
1383 }
[email protected]420ae012009-04-24 05:16:321384 DidNavigateAnyFramePostCommit(rvh, details, params);
1385}
1386
1387void TabContents::UpdateState(RenderViewHost* rvh,
1388 int32 page_id,
1389 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151390 // Ensure that this state update comes from either the active RVH or one of
1391 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1392 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321393
1394 // We must be prepared to handle state updates for any page, these occur
1395 // when the user is scrolling and entering form data, as well as when we're
1396 // leaving a page, in which case our state may have already been moved to
1397 // the next page. The navigation controller will look up the appropriate
1398 // NavigationEntry and update it when it is notified via the delegate.
1399
1400 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151401 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321402 if (entry_index < 0)
1403 return;
1404 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1405
1406 if (state == entry->content_state())
1407 return; // Nothing to update.
1408 entry->set_content_state(state);
1409 controller_.NotifyEntryChanged(entry, entry_index);
1410}
1411
1412void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]6b2f7a82011-04-25 19:30:511413 int32 page_id, const std::wstring& title) {
[email protected]420ae012009-04-24 05:16:321414 // If we have a title, that's a pretty good indication that we've started
1415 // getting useful data.
1416 SetNotWaitingForResponse();
1417
1418 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481419 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581420 page_id);
[email protected]987fc3a2011-05-26 14:18:091421
1422 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321423 return;
1424
1425 // Broadcast notifications when the UI should be updated.
1426 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031427 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321428}
1429
[email protected]420ae012009-04-24 05:16:321430void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401431 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321432 set_encoding(encoding);
1433}
1434
1435void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1436 if (delegate())
1437 delegate()->UpdateTargetURL(this, url);
1438}
1439
[email protected]c4e98902010-06-01 10:20:141440void TabContents::UpdateInspectorSetting(const std::string& key,
1441 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:051442 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:081443}
1444
[email protected]45aafc92010-06-07 14:18:531445void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:051446 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:531447}
1448
[email protected]420ae012009-04-24 05:16:321449void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291450 // The UI may be in an event-tracking loop, such as between the
1451 // mouse-down and mouse-up in text selection or a button click.
1452 // Defer the close until after tracking is complete, so that we
1453 // don't free objects out from under the UI.
1454 // TODO(shess): This could probably be integrated with the
1455 // IsDoingDrag() test below. Punting for now because I need more
1456 // research to understand how this impacts platforms other than Mac.
1457 // TODO(shess): This could get more fine-grained. For instance,
1458 // closing a tab in another window while selecting text in the
1459 // current window's Omnibox should be just fine.
1460 if (view()->IsEventTracking()) {
1461 view()->CloseTabAfterEventTracking();
1462 return;
1463 }
1464
[email protected]24a4d1062009-07-10 23:10:421465 // If we close the tab while we're in the middle of a drag, we'll crash.
1466 // Instead, cancel the drag and close it as soon as the drag ends.
1467 if (view()->IsDoingDrag()) {
1468 view()->CancelDragAndCloseTab();
1469 return;
1470 }
1471
[email protected]420ae012009-04-24 05:16:321472 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1473 if (delegate() && rvh == render_view_host())
1474 delegate()->CloseContents(this);
1475}
1476
1477void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141478 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321479 delegate()->MoveContents(this, new_bounds);
1480}
1481
[email protected]7ab1e7d62009-10-14 23:32:011482void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321483 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491484
[email protected]c40d6232011-03-25 00:16:211485 if (delegate() && content_restrictions_) {
1486 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211487 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001488 }
[email protected]3c9e1872010-11-18 16:17:491489
1490 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171491 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321492}
1493
[email protected]7ab1e7d62009-10-14 23:32:011494void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321495 scoped_ptr<LoadNotificationDetails> details;
1496
1497 NavigationEntry* entry = controller_.GetActiveEntry();
1498 // An entry may not exist for a stop when loading an initial blank page or
1499 // if an iframe injected by script into a blank page finishes loading.
1500 if (entry) {
[email protected]420ae012009-04-24 05:16:321501 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1502
1503 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541504 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321505 entry->transition_type(),
1506 elapsed,
1507 &controller_,
1508 controller_.GetCurrentEntryIndex()));
1509 }
1510
[email protected]420ae012009-04-24 05:16:321511 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491512
1513 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171514 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321515}
1516
[email protected]c95fa8b2011-04-28 20:26:161517void TabContents::DidCancelLoading() {
1518 controller_.DiscardNonCommittedEntries();
1519
1520 // Update the URL display.
1521 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1522}
1523
[email protected]1a3c3cb2010-12-16 21:03:401524void TabContents::DidChangeLoadProgress(double progress) {
1525 if (delegate())
1526 delegate()->LoadProgressChanged(progress);
1527}
1528
[email protected]25497492010-09-11 15:15:081529void TabContents::DocumentOnLoadCompletedInMainFrame(
1530 RenderViewHost* render_view_host,
1531 int32 page_id) {
1532 NotificationService::current()->Notify(
1533 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
1534 Source<TabContents>(this),
1535 Details<int>(&page_id));
1536}
1537
[email protected]420ae012009-04-24 05:16:321538void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
1539 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:581540 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351541 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321542 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1543 // generated suggestions).
1544 //
[email protected]e0112912011-02-02 22:54:351545 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161546 // want web sites to see a referrer of "chrome://blah" (and some
1547 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321548 // send to the site), so we send no referrer.
1549 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:581550 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:321551 } else {
1552 OpenURL(url, referrer, disposition, PageTransition::LINK);
1553 }
1554}
1555
[email protected]420ae012009-04-24 05:16:321556void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151557 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411558 const string16& message,
1559 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321560 const GURL& frame_url,
1561 const int flags,
1562 IPC::Message* reply_msg,
1563 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071564 // Suppress JavaScript dialogs when requested. Also suppress messages when
1565 // showing an interstitial as it's shown over the previous page and we don't
1566 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501567 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151568 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501569 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071570 !delegate_ ||
1571 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321572
1573 if (!suppress_this_message) {
[email protected]3ab9cb82011-06-03 18:02:071574 delegate_->GetJavaScriptDialogCreator()->RunJavaScriptDialog(
1575 this,
1576 frame_url,
1577 flags,
1578 message,
1579 default_prompt,
1580 reply_msg,
1581 &suppress_this_message,
1582 profile());
[email protected]420ae012009-04-24 05:16:321583 }
[email protected]3ab9cb82011-06-03 18:02:071584
1585 if (suppress_this_message) {
1586 // If we are suppressing messages, just reply as if the user immediately
1587 // pressed "Cancel".
1588 OnDialogClosed(reply_msg, false, string16());
1589 }
1590
1591 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321592}
1593
[email protected]992db4c2011-05-12 15:37:151594void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411595 const string16& message,
[email protected]420ae012009-04-24 05:16:321596 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291597 if (delegate())
1598 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071599
1600 bool suppress_this_message =
1601 rvh->is_swapped_out() ||
1602 !delegate_ ||
1603 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151604 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411605 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501606 return;
1607 }
[email protected]3ab9cb82011-06-03 18:02:071608
[email protected]7ab1e7d62009-10-14 23:32:011609 is_showing_before_unload_dialog_ = true;
[email protected]3ab9cb82011-06-03 18:02:071610 delegate_->GetJavaScriptDialogCreator()->RunBeforeUnloadDialog(
1611 this,
1612 message,
1613 reply_msg);
[email protected]420ae012009-04-24 05:16:321614}
1615
[email protected]420ae012009-04-24 05:16:321616WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:061617 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:581618 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:081619 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:581620 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:081621
[email protected]b8299c12011-06-03 19:52:281622 // Force accelerated compositing and 2d canvas off for chrome:, about: and
1623 // chrome-devtools: pages.
[email protected]27c790d42010-10-22 09:28:431624 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]b8299c12011-06-03 19:52:281625 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
1626 GetURL().SchemeIs(chrome::kAboutScheme)) {
[email protected]447021c2010-09-08 21:29:081627 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431628 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081629 }
1630
[email protected]39553442010-09-09 00:01:551631#if defined(OS_MACOSX)
1632 // Disable accelerated compositing if IOSurface's are not supported,
1633 // as is the case in 10.5.
1634 if (!IOSurfaceSupport::Initialize())
1635 web_prefs.accelerated_compositing_enabled = false;
1636#endif
1637
[email protected]447021c2010-09-08 21:29:081638 return web_prefs;
[email protected]420ae012009-04-24 05:16:321639}
1640
[email protected]7d472472011-01-22 01:30:251641void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271642 // Notify observers.
1643 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]7d472472011-01-22 01:30:251644}
1645
[email protected]fa1cf0b82010-01-15 21:49:441646void TabContents::OnIgnoredUIEvent() {
1647 if (constrained_window_count()) {
1648 ConstrainedWindow* window = *constrained_window_begin();
1649 window->FocusConstrainedWindow();
1650 }
1651}
1652
[email protected]420ae012009-04-24 05:16:321653void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
1654 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:341655 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:321656 // delivered to a pending RenderViewHost. We must first run the onunload
1657 // handler of the old RenderViewHost before we can allow it to proceed.
1658 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
1659 new_request_id);
1660}
1661
[email protected]420ae012009-04-24 05:16:321662void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1663 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151664 // Don't show hung renderer dialog for a swapped out RVH.
1665 if (rvh != render_view_host())
1666 return;
1667
[email protected]420ae012009-04-24 05:16:321668 if (is_during_unload) {
1669 // Hang occurred while firing the beforeunload/unload handler.
1670 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111671 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321672
1673 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1674 return;
1675
1676 // If the tab hangs in the beforeunload/unload handler there's really
1677 // nothing we can do to recover. Pretend the unload listeners have
1678 // all fired and close the tab. If the hang is in the beforeunload handler
1679 // then the user will not have the option of cancelling the close.
1680 Close(rvh);
1681 return;
1682 }
1683
[email protected]55452902011-06-01 21:57:471684 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1685 return;
1686
1687 if (delegate())
1688 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321689}
1690
1691void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471692 if (delegate())
1693 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321694}
1695
1696void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:561697 net::LoadState load_state,
1698 uint64 upload_position,
1699 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321700 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561701 upload_position_ = upload_position;
1702 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501703 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]b5cca982011-05-26 04:42:081704 content::GetContentClient()->browser()->GetAcceptLangs(this));
[email protected]420ae012009-04-24 05:16:321705 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
1706 SetNotWaitingForResponse();
1707 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:501708 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321709}
1710
[email protected]1ee614862009-07-06 20:29:181711bool TabContents::IsExternalTabContainer() const {
1712 if (!delegate())
1713 return false;
1714
1715 return delegate()->IsExternalTabContainer();
1716}
1717
[email protected]7d472472011-01-22 01:30:251718void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441719 if (delegate())
[email protected]55452902011-06-01 21:57:471720 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251721}
1722
[email protected]420ae012009-04-24 05:16:321723void TabContents::BeforeUnloadFiredFromRenderManager(
1724 bool proceed,
1725 bool* proceed_to_fire_unload) {
1726 if (delegate())
1727 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1728}
1729
[email protected]3a3d47472010-07-15 21:03:541730void TabContents::DidStartLoadingFromRenderManager(
1731 RenderViewHost* render_view_host) {
1732 DidStartLoading();
1733}
1734
1735void TabContents::RenderViewGoneFromRenderManager(
1736 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231737 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1738 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541739}
1740
[email protected]420ae012009-04-24 05:16:321741void TabContents::UpdateRenderViewSizeForRenderManager() {
1742 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261743 gfx::Size size = view_->GetContainerSize();
1744 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1745 // here during container initialization and normal window size will be set
1746 // later. In case of tab duplication this resizing to 0x0 prevents setting
1747 // normal size later so just ignore it.
1748 if (!size.IsEmpty())
1749 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321750}
1751
[email protected]3a3d47472010-07-15 21:03:541752void TabContents::NotifySwappedFromRenderManager() {
1753 NotifySwapped();
1754}
1755
1756NavigationController& TabContents::GetControllerForRenderManager() {
1757 return controller();
1758}
1759
[email protected]d0980792011-02-13 19:41:401760WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561761 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321762}
1763
1764NavigationEntry*
1765TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1766 return controller_.GetLastCommittedEntry();
1767}
1768
1769bool TabContents::CreateRenderViewForRenderManager(
1770 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:321771 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:521772
[email protected]420ae012009-04-24 05:16:321773 // Now that the RenderView has been created, we need to tell it its size.
1774 rwh_view->SetSize(view_->GetContainerSize());
1775
[email protected]a4127722011-04-27 23:13:521776 if (!render_view_host->CreateRenderView(string16()))
1777 return false;
1778
[email protected]f8233cc2011-05-31 20:24:501779#if defined(OS_LINUX)
1780 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
1781 // linux. See crbug.com/83941.
1782 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1783 render_widget_host->WasResized();
1784#endif
1785
[email protected]420ae012009-04-24 05:16:321786 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
1787 render_view_host);
1788 return true;
1789}
1790
1791void TabContents::Observe(NotificationType type,
1792 const NotificationSource& source,
1793 const NotificationDetails& details) {
1794 switch (type.value) {
[email protected]420ae012009-04-24 05:16:321795 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
1796 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
1797 break;
[email protected]420ae012009-04-24 05:16:321798 default:
1799 NOTREACHED();
1800 }
1801}
[email protected]aacd7cc2009-09-02 14:51:101802
[email protected]3ab9cb82011-06-03 18:02:071803// Overridden from JavaScriptDialogDelegate
[email protected]beb440c2009-11-06 04:08:541804
[email protected]3ab9cb82011-06-03 18:02:071805void TabContents::OnDialogClosed(IPC::Message* reply_msg,
1806 bool success,
1807 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:541808 if (is_showing_before_unload_dialog_ && !success) {
1809 // If a beforeunload dialog is canceled, we need to stop the throbber from
1810 // spinning, since we forced it to start spinning in Navigate.
1811 DidStopLoading();
1812
1813 tab_close_start_time_ = base::TimeTicks();
1814 }
1815 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:411816 render_view_host()->JavaScriptDialogClosed(reply_msg,
1817 success,
[email protected]3ab9cb82011-06-03 18:02:071818 user_input);
[email protected]beb440c2009-11-06 04:08:541819}
1820
[email protected]3ab9cb82011-06-03 18:02:071821gfx::NativeWindow TabContents::GetDialogRootWindow() {
1822 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:541823}
1824
[email protected]3a3d47472010-07-15 21:03:541825TabContents* TabContents::AsTabContents() {
1826 return this;
1827}
1828
1829ExtensionHost* TabContents::AsExtensionHost() {
1830 return NULL;
1831}
1832
[email protected]41fc0322009-09-04 22:23:401833void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:121834 encoding_ = content::GetContentClient()->browser()->
1835 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:101836}
[email protected]f45d2a72010-03-08 23:28:351837
[email protected]33f74972010-12-08 16:40:361838void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
1839 render_manager_.SwapInRenderViewHost(rvh);
1840}
1841
1842void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
1843 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
1844 rwh_view->SetSize(view()->GetContainerSize());
1845}
[email protected]e7d50892011-01-19 21:47:381846
[email protected]232a5812011-03-04 22:42:081847void TabContents::OnOnlineStateChanged(bool online) {
1848 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
1849 render_view_host()->routing_id(), online));
1850}