blob: b197f5b92cbb8934cb98af48ae4241f0691ed524 [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]686493142011-07-15 21:47:2216#include "chrome/browser/download/download_request_limiter.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]b46442d7e2011-06-29 02:16:0620#include "content/browser/debugger/devtools_manager.h"
[email protected]567812d2011-02-24 17:40:5021#include "content/browser/host_zoom_map.h"
22#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]37a72af2011-06-13 05:42:0123#include "content/browser/load_from_memory_cache_details.h"
[email protected]35e251d2011-05-24 21:01:0424#include "content/browser/load_notification_details.h"
[email protected]567812d2011-02-24 17:40:5025#include "content/browser/renderer_host/render_process_host.h"
26#include "content/browser/renderer_host/render_view_host.h"
27#include "content/browser/renderer_host/render_widget_host_view.h"
[email protected]686493142011-07-15 21:47:2228#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]567812d2011-02-24 17:40:5029#include "content/browser/renderer_host/resource_request_details.h"
30#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4431#include "content/browser/tab_contents/interstitial_page.h"
[email protected]8286f51a2011-05-31 17:39:1332#include "content/browser/tab_contents/navigation_details.h"
[email protected]0dd3a0ab2011-02-18 08:17:4433#include "content/browser/tab_contents/navigation_entry.h"
34#include "content/browser/tab_contents/provisional_load_details.h"
35#include "content/browser/tab_contents/tab_contents_delegate.h"
36#include "content/browser/tab_contents/tab_contents_observer.h"
37#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]105bb0f2011-05-24 17:12:1438#include "content/browser/tab_contents/title_updated_details.h"
[email protected]afd1e522011-04-27 23:29:5939#include "content/browser/user_metrics.h"
[email protected]1fd1a502011-03-30 16:55:5640#include "content/browser/webui/web_ui_factory.h"
[email protected]9966325b2011-04-18 05:00:1041#include "content/common/bindings_policy.h"
[email protected]1fd1a502011-03-30 16:55:5642#include "content/common/content_client.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "content/common/content_restriction.h"
[email protected]4dd57932011-03-17 06:06:1244#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3245#include "content/common/notification_service.h"
[email protected]0f012df82011-05-19 14:15:2946#include "content/common/url_constants.h"
[email protected]2c5569662011-03-22 20:45:0247#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2948#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3249#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3450#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3751#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]08397d52011-02-05 01:53:3852#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0353#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3154#include "webkit/glue/webpreferences.h"
55
56#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1257#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3158#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0059
[email protected]420ae012009-04-24 05:16:3260// Cross-Site Navigations
61//
62// If a TabContents is told to navigate to a different web site (as determined
63// by SiteInstance), it will replace its current RenderViewHost with a new
64// RenderViewHost dedicated to the new SiteInstance. This works as follows:
65//
66// - Navigate determines whether the destination is cross-site, and if so,
67// it creates a pending_render_view_host_ and moves into the PENDING
68// RendererState.
69// - The pending RVH is "suspended," so that no navigation messages are sent to
70// its renderer until the onbeforeunload JavaScript handler has a chance to
71// run in the current RVH.
72// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
73// that it has a pending cross-site request. ResourceDispatcherHost will
74// check for this when the response arrives.
75// - The current RVH runs its onbeforeunload handler. If it returns false, we
76// cancel all the pending logic and go back to NORMAL. Otherwise we allow
77// the pending RVH to send the navigation request to its renderer.
78// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
79// checks CrossSiteRequestManager to see that the RVH responsible has a
80// pending cross-site request, and then installs a CrossSiteEventHandler.
81// - When RDH receives a response, the BufferedEventHandler determines whether
82// it is a download. If so, it sends a message to the new renderer causing
83// it to cancel the request, and the download proceeds in the download
84// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:3485// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:3286// doesn't affect any functionality.
87// - After RDH receives a response and determines that it is safe and not a
88// download, it pauses the response to first run the old page's onunload
89// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:1590// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:3291// to the current RVH.
[email protected]992db4c2011-05-12 15:37:1592// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:3293// the ResourceDispatcherHost, who unpauses the response. Data is then sent
94// to the pending RVH.
95// - The pending renderer sends a FrameNavigate message that invokes the
96// DidNavigate method. This replaces the current RVH with the
97// pending RVH and goes back to the NORMAL RendererState.
[email protected]992db4c2011-05-12 15:37:1598// - The previous renderer is kept swapped out in RenderViewHostManager in case
99// the user goes back. The process only stays live if another tab is using
100// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32101
102namespace {
103
104// Amount of time we wait between when a key event is received and the renderer
105// is queried for its state and pushed to the NavigationEntry.
106const int kQueryStateDelay = 5000;
107
[email protected]6ebdc9b2010-09-27 16:55:57108const int kSyncWaitDelay = 40;
109
[email protected]420ae012009-04-24 05:16:32110#if defined(OS_WIN)
111
112BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
113 // Note: erase is required to properly paint some widgets borders. This can
114 // be seen with textfields.
115 InvalidateRect(hwnd, NULL, TRUE);
116 return TRUE;
117}
118#endif
119
[email protected]2c5569662011-03-22 20:45:02120ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16121 Profile* profile, const NavigationEntry& entry,
122 NavigationController::ReloadType reload_type) {
123 switch (reload_type) {
124 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02125 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16126 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02127 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16128 case NavigationController::NO_RELOAD:
129 break; // Fall through to rest of function.
130 }
[email protected]5e369672009-11-03 23:48:30131
132 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
133 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02134 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30135
[email protected]2c5569662011-03-22 20:45:02136 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30137}
138
[email protected]876bc832010-09-07 16:29:54139void MakeNavigateParams(const NavigationEntry& entry,
140 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16141 NavigationController::ReloadType reload_type,
142 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34143 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54144 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00145 params->current_history_list_offset = controller.last_committed_entry_index();
146 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34147 params->url = entry.url();
148 params->referrer = entry.referrer();
149 params->transition = entry.transition_type();
150 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00151 params->navigation_type =
152 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34153 params->request_time = base::Time::Now();
154}
155
[email protected]420ae012009-04-24 05:16:32156} // namespace
157
[email protected]f4f50ef2011-01-21 19:01:19158
159// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32160
[email protected]420ae012009-04-24 05:16:32161TabContents::TabContents(Profile* profile,
162 SiteInstance* site_instance,
163 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07164 const TabContents* base_tab_contents,
165 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42166 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07167 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
168 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13169 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22170 TabContentsView::Create(this))),
171 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[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]332af7732009-03-11 13:21:35203}
initial.commit09911bf2008-07-26 23:55:29204
205TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32206 is_being_destroyed_ = true;
207
[email protected]3ab9cb82011-06-03 18:02:07208 // Clear out any JavaScript state.
209 if (delegate_)
210 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this);
211
[email protected]420ae012009-04-24 05:16:32212 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32213
[email protected]420ae012009-04-24 05:16:32214 // First cleanly close all child windows.
215 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
216 // some of these to close. CloseWindows is async, so it might get called
217 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49218 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32219
[email protected]420ae012009-04-24 05:16:32220 // Notify any observer that have a reference on this tab contents.
221 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27222 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
[email protected]420ae012009-04-24 05:16:32223 Source<TabContents>(this),
224 NotificationService::NoDetails());
225
226 // TODO(brettw) this should be moved to the view.
227#if defined(OS_WIN)
228 // If we still have a window handle, destroy it. GetNativeView can return
229 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42230 if (GetNativeView()) {
231 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44232 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42233 host->view()->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42234 }
[email protected]420ae012009-04-24 05:16:32235#endif
[email protected]7ab1e7d62009-10-14 23:32:01236
237 // OnCloseStarted isn't called in unit tests.
238 if (!tab_close_start_time_.is_null()) {
239 UMA_HISTOGRAM_TIMES("Tab.Close",
240 base::TimeTicks::Now() - tab_close_start_time_);
241 }
[email protected]b5a1d11c2011-02-17 03:09:42242
[email protected]07d490bc2011-03-07 17:05:26243 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08244
[email protected]1de2b8b2011-06-29 19:38:46245 set_delegate(NULL);
246}
247
248// TODO(cbentzel): Either remove the debugging code, or rename to SetDelegate.
249void TabContents::set_delegate(TabContentsDelegate* delegate) {
250 if (delegate == delegate_)
251 return;
252 if (delegate_)
253 delegate_->Detach(this);
254 delegate_ = delegate;
255 if (delegate_)
256 delegate_->Attach(this);
[email protected]b5a1d11c2011-02-17 03:09:42257}
258
[email protected]724159a2010-12-30 01:11:18259bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]f82d57b52011-04-27 19:13:17260 if (web_ui() && web_ui()->OnMessageReceived(message))
261 return true;
262
[email protected]585b30362011-01-28 02:30:17263 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
264 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10265 while ((observer = it.GetNext()) != NULL)
266 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53267 return true;
[email protected]403415a2011-01-10 18:57:53268
[email protected]724159a2010-12-30 01:11:18269 bool handled = true;
270 bool message_is_ok = true;
271 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
272 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
273 OnDidStartProvisionalLoadForFrame)
274 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
275 OnDidRedirectProvisionalLoad)
276 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
277 OnDidFailProvisionalLoadWithError)
278 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
279 OnDidLoadResourceFromMemoryCache)
280 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
281 OnDidDisplayInsecureContent)
282 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
283 OnDidRunInsecureContent)
284 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
285 OnDocumentLoadedInFrame)
286 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17287 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
288 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25289 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26290 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
291 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
[email protected]724159a2010-12-30 01:11:18292 IPC_MESSAGE_UNHANDLED(handled = false)
293 IPC_END_MESSAGE_MAP_EX()
294
295 if (!message_is_ok) {
296 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
297 GetRenderProcessHost()->ReceivedBadMessage();
298 }
299
300 return handled;
301}
302
[email protected]13367f72009-07-08 16:39:02303// Returns true if contains content rendered by an extension.
304bool TabContents::HostsExtension() const {
305 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34306}
307
[email protected]8cb5d5b2010-02-09 11:36:16308RenderProcessHost* TabContents::GetRenderProcessHost() const {
309 return render_manager_.current_host()->process();
310}
311
[email protected]d5f942ba2008-09-26 19:30:34312const GURL& TabContents::GetURL() const {
313 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57314 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54315 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34316}
317
[email protected]96d185d2009-04-24 03:28:54318const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55319 // Transient entries take precedence. They are used for interstitial pages
320 // that are shown on top of existing pages.
321 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08322 std::string accept_languages =
323 content::GetContentClient()->browser()->GetAcceptLangs(this);
[email protected]45d0ef7f2011-01-05 13:46:23324 if (entry) {
[email protected]b5cca982011-05-26 04:42:08325 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23326 }
[email protected]7ade2732011-02-10 00:13:58327 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
328 render_manager_.pending_web_ui() : render_manager_.web_ui();
329 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54330 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55331 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54332 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35333 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58334 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54335 if (!title.empty())
336 return title;
337 }
338 }
339
340 // We use the title for the last committed entry rather than a pending
341 // navigation entry. For example, when the user types in a URL, we want to
342 // keep the old page's title until the new load has committed and we get a new
343 // title.
[email protected]96d185d2009-04-24 03:28:54344 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23345 if (entry) {
[email protected]b5cca982011-05-26 04:42:08346 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23347 }
[email protected]987fc3a2011-05-26 14:18:09348
349 // |page_title_when_no_navigation_entry_| is finally used
350 // if no title cannot be retrieved.
351 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54352}
353
[email protected]d5f942ba2008-09-26 19:30:34354int32 TabContents::GetMaxPageID() {
355 if (GetSiteInstance())
356 return GetSiteInstance()->max_page_id();
357 else
358 return max_page_id_;
359}
360
361void TabContents::UpdateMaxPageID(int32 page_id) {
362 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34363 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34364 // testing.
365 if (GetSiteInstance())
366 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16367 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34368}
369
[email protected]96d185d2009-04-24 03:28:54370SiteInstance* TabContents::GetSiteInstance() const {
371 return render_manager_.current_host()->site_instance();
372}
373
[email protected]96d185d2009-04-24 03:28:54374bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15375 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54376 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15377 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01378 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54379 return true;
[email protected]8ab24cc2009-11-13 20:56:15380 }
[email protected]83e3895b2009-06-11 00:07:16381
[email protected]2b9a06402011-02-16 04:57:10382 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56383 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10384 return true;
385
[email protected]d0980792011-02-13 19:41:40386 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58387 if (web_ui)
388 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54389 return true;
390}
391
[email protected]585b30362011-01-28 02:30:17392void TabContents::AddObserver(TabContentsObserver* observer) {
393 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49394}
395
[email protected]585b30362011-01-28 02:30:17396void TabContents::RemoveObserver(TabContentsObserver* observer) {
397 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49398}
399
[email protected]443b80e2010-12-14 00:42:23400void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
401 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34402 return;
403
[email protected]443b80e2010-12-14 00:42:23404 crashed_status_ = status;
405 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50406 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34407}
408
409void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
410 if (delegate_)
411 delegate_->NavigationStateChanged(this, changed_flags);
412}
413
[email protected]96d185d2009-04-24 03:28:54414void TabContents::DidBecomeSelected() {
415 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16416 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
417 if (rwhv) {
418 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43419#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16420 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43421#endif
422 }
[email protected]96d185d2009-04-24 03:28:54423
[email protected]5ac20162010-11-24 23:33:11424 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38425
426 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidBecomeSelected());
[email protected]96d185d2009-04-24 03:28:54427}
428
429void TabContents::WasHidden() {
430 if (!capturing_contents()) {
431 // |render_view_host()| can be NULL if the user middle clicks a link to open
432 // a tab in then background, then closes the tab before selecting it. This
433 // is because closing the tab calls TabContents::Destroy(), which removes
434 // the |render_view_host()|; then when we actually destroy the window,
435 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16436 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
437 if (rwhv)
438 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54439 }
440
441 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27442 content::NOTIFICATION_TAB_CONTENTS_HIDDEN,
[email protected]96d185d2009-04-24 03:28:54443 Source<TabContents>(this),
444 NotificationService::NoDetails());
445}
446
[email protected]d5f942ba2008-09-26 19:30:34447void TabContents::Activate() {
448 if (delegate_)
449 delegate_->ActivateContents(this);
450}
451
[email protected]ea42e7782010-08-23 23:58:12452void TabContents::Deactivate() {
453 if (delegate_)
454 delegate_->DeactivateContents(this);
455}
456
[email protected]63954792011-07-11 04:17:48457void TabContents::LostCapture() {
458 if (delegate_)
459 delegate_->LostCapture();
460}
461
462bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
463 bool* is_keyboard_shortcut) {
464 return delegate_ &&
465 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
466}
467
468void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
469 if (delegate_)
470 delegate_->HandleKeyboardEvent(event);
471}
472
473void TabContents::HandleMouseUp() {
474 if (delegate_)
475 delegate_->HandleMouseUp();
476}
477
478void TabContents::HandleMouseActivate() {
479 if (delegate_)
480 delegate_->HandleMouseActivate();
481}
482
[email protected]96d185d2009-04-24 03:28:54483void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16484 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
485 if (rwhv)
486 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54487}
488
489void TabContents::HideContents() {
490 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
491 // our superclass HideContents(), because some callers want to be very picky
492 // about the order in which these get called. In addition to making the code
493 // here practically impossible to understand, this also means we end up
494 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34495 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54496 WasHidden();
497}
498
[email protected]5aab5e22010-12-08 22:13:29499bool TabContents::NeedToFireBeforeUnload() {
500 // TODO(creis): Should we fire even for interstitial pages?
501 return notify_disconnection() &&
502 !showing_interstitial_page() &&
503 !render_view_host()->SuddenTerminationAllowed();
504}
505
[email protected]c0588052008-10-27 23:01:50506void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34507 WindowOpenDisposition disposition,
508 PageTransition::Type transition) {
[email protected]1c642b52011-04-15 09:05:49509 if (delegate_) {
[email protected]c0588052008-10-27 23:01:50510 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]1c642b52011-04-15 09:05:49511 // Notify observers.
512 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
513 DidOpenURL(url, referrer, disposition, transition));
514 }
[email protected]d5f942ba2008-09-26 19:30:34515}
516
[email protected]1ccb3568d2010-02-19 10:51:16517bool TabContents::NavigateToPendingEntry(
518 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54519 return NavigateToEntry(*controller_.pending_entry(), reload_type);
520}
[email protected]96d185d2009-04-24 03:28:54521
[email protected]876bc832010-09-07 16:29:54522bool TabContents::NavigateToEntry(
523 const NavigationEntry& entry,
524 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54525 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
526 if (!dest_render_view_host)
527 return false; // Unable to create the desired render view host.
528
[email protected]80a8fad2011-01-29 04:02:38529 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07530 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58531 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56532 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
533 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
534 entry.url());
[email protected]c09163a2011-02-15 00:05:55535 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
536 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58537
[email protected]96d185d2009-04-24 03:28:54538 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12539 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32540 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00541 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
542 dest_render_view_host,
543 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32544 }
[email protected]96d185d2009-04-24 03:28:54545
546 // Used for page load time metrics.
547 current_load_start_ = base::TimeTicks::Now();
548
549 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34550 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54551 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04552 if (delegate_) {
553 navigate_params.extra_headers =
554 delegate_->GetNavigationHeaders(navigate_params.url);
555 }
[email protected]056de2d2009-06-26 16:41:34556 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54557
558 if (entry.page_id() == -1) {
559 // HACK!! This code suppresses javascript: URLs from being added to
560 // session history, which is what we want to do for javascript: URLs that
561 // do not generate content. What we really need is a message from the
562 // renderer telling us that a new page was not created. The same message
563 // could be used for mailto: URLs and the like.
564 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
565 return false;
566 }
567
[email protected]3c9e1872010-11-18 16:17:49568 // Notify observers about navigation.
[email protected]b375c5d2011-05-03 21:15:04569 FOR_EACH_OBSERVER(TabContentsObserver,
570 observers_,
571 NavigateToPendingEntry(entry.url(), reload_type));
[email protected]96d185d2009-04-24 03:28:54572
[email protected]09b29342011-06-24 19:18:48573 if (delegate_)
574 delegate_->DidNavigateToPendingEntry(this);
575
[email protected]d5f942ba2008-09-26 19:30:34576 return true;
577}
578
[email protected]96d185d2009-04-24 03:28:54579void TabContents::Stop() {
580 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47581 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54582}
583
[email protected]96d185d2009-04-24 03:28:54584TabContents* TabContents::Clone() {
585 // We create a new SiteInstance so that the new tab won't share processes
586 // with the old one. This can be changed in the future if we need it to share
587 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32588 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54589 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07590 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54591 tc->controller().CopyStateFrom(controller_);
592 return tc;
593}
594
[email protected]4d677202009-07-19 07:37:12595void TabContents::ShowPageInfo(const GURL& url,
596 const NavigationEntry::SSLStatus& ssl,
597 bool show_history) {
598 if (!delegate_)
599 return;
600
[email protected]bb678332009-07-21 00:15:50601 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12602}
603
initial.commit09911bf2008-07-26 23:55:29604ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28605 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29606 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28607 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33608 AddConstrainedDialog(window);
609 return window;
610}
611
612void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29613 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44614
615 if (child_windows_.size() == 1) {
616 window->ShowConstrainedWindow();
617 BlockTabContent(true);
618 }
initial.commit09911bf2008-07-26 23:55:29619}
620
[email protected]fa1cf0b82010-01-15 21:49:44621void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55622 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45623 // 70% opaque grey.
624 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55625 if (rwhv)
[email protected]1b072562010-12-13 19:37:45626 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]a7eccac2011-04-15 03:05:19627 // RenderViewHost may be NULL during shutdown.
628 if (render_view_host())
629 render_view_host()->set_ignore_input_events(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44630 if (delegate_)
631 delegate_->SetTabContentBlocked(this, blocked);
632}
633
[email protected]e7cfdbd2011-04-22 14:41:37634void TabContents::AddNewContents(TabContents* new_contents,
635 WindowOpenDisposition disposition,
636 const gfx::Rect& initial_pos,
637 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29638 if (!delegate_)
639 return;
640
[email protected]e7cfdbd2011-04-22 14:41:37641 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
642 user_gesture);
[email protected]96d185d2009-04-24 03:28:54643}
644
[email protected]5c9e97a2009-09-09 23:48:30645gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54646 return view_->GetContentNativeView();
647}
648
649gfx::NativeView TabContents::GetNativeView() const {
650 return view_->GetNativeView();
651}
652
653void TabContents::GetContainerBounds(gfx::Rect *out) const {
654 view_->GetContainerBounds(out);
655}
656
657void TabContents::Focus() {
658 view_->Focus();
659}
660
[email protected]90daadb42009-06-08 21:27:28661void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54662 if (showing_interstitial_page()) {
663 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
664 return;
665 }
[email protected]96d185d2009-04-24 03:28:54666 render_view_host()->SetInitialFocus(reverse);
667}
668
669bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40670 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58671 if (web_ui)
672 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43673 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25674 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43675 return true;
[email protected]96d185d2009-04-24 03:28:54676 return false;
677}
678
[email protected]a26dc362010-04-23 01:48:58679void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38680 if (delegate())
[email protected]a26dc362010-04-23 01:48:58681 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38682}
683
[email protected]686493142011-07-15 21:47:22684bool TabContents::CanDownload(int request_id) {
685 TabContentsDelegate* d = delegate();
686 if (d)
687 return d->CanDownload(this, request_id);
688 return true;
689}
690
691void TabContents::OnStartDownload(DownloadItem* download) {
692 TabContentsDelegate* d = delegate();
693 if (d)
694 d->OnStartDownload(this, download);
695}
696
[email protected]d5f942ba2008-09-26 19:30:34697void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:37698 ConstrainedWindowList::iterator i(
699 std::find(child_windows_.begin(), child_windows_.end(), window));
700 bool removed_topmost_window = i == child_windows_.begin();
701 if (i != child_windows_.end())
702 child_windows_.erase(i);
703 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:44704 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:37705 } else {
706 if (removed_topmost_window)
707 child_windows_[0]->ShowConstrainedWindow();
708 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:44709 }
[email protected]66ba4932009-06-04 19:22:13710}
[email protected]d5f942ba2008-09-26 19:30:34711
[email protected]420ae012009-04-24 05:16:32712bool TabContents::IsActiveEntry(int32 page_id) {
713 NavigationEntry* active_entry = controller_.GetActiveEntry();
714 return (active_entry != NULL &&
715 active_entry->site_instance() == GetSiteInstance() &&
716 active_entry->page_id() == page_id);
717}
718
[email protected]b2fe07d12010-02-09 14:38:08719void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:16720 set_encoding(encoding);
[email protected]216813952011-05-19 22:21:26721 render_view_host()->Send(new ViewMsg_SetPageEncoding(
722 render_view_host()->routing_id(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:16723}
724
[email protected]b2fe07d12010-02-09 14:38:08725void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:16726 reset_encoding();
[email protected]216813952011-05-19 22:21:26727 render_view_host()->Send(new ViewMsg_ResetPageEncodingToDefault(
728 render_view_host()->routing_id()));
[email protected]8cb5d5b2010-02-09 11:36:16729}
730
[email protected]7ab1e7d62009-10-14 23:32:01731void TabContents::OnCloseStarted() {
732 if (tab_close_start_time_.is_null())
733 tab_close_start_time_ = base::TimeTicks::Now();
734}
735
[email protected]46624bf2010-06-09 16:04:19736bool TabContents::ShouldAcceptDragAndDrop() const {
737#if defined(OS_CHROMEOS)
738 // ChromeOS panels (pop-ups) do not take drag-n-drop.
739 // See http://crosbug.com/2413
[email protected]b35b26b32011-05-05 20:35:14740 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:20741 return false;
742 return true;
[email protected]46624bf2010-06-09 16:04:19743#else
744 return true;
745#endif
746}
747
[email protected]7813bd72011-02-05 02:19:34748void TabContents::SystemDragEnded() {
749 if (render_view_host())
750 render_view_host()->DragSourceSystemDragEnded();
751 if (delegate())
752 delegate()->DragEnded();
753}
754
[email protected]d0b8d092010-10-25 04:05:17755double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:25756 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
757 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:17758 return 0;
[email protected]b75b8292010-10-01 07:28:25759
760 double zoom_level;
761 if (temporary_zoom_settings_) {
762 zoom_level = zoom_map->GetTemporaryZoomLevel(
763 GetRenderProcessHost()->id(), render_view_host()->routing_id());
764 } else {
[email protected]13ffa32e2011-05-27 16:37:01765 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(GetURL()));
[email protected]b75b8292010-10-01 07:28:25766 }
[email protected]d0b8d092010-10-25 04:05:17767 return zoom_level;
768}
[email protected]b75b8292010-10-01 07:28:25769
[email protected]d0b8d092010-10-25 04:05:17770int TabContents::GetZoomPercent(bool* enable_increment,
771 bool* enable_decrement) {
772 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:25773 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:17774 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:25775 *enable_decrement = percent > minimum_zoom_percent_;
776 *enable_increment = percent < maximum_zoom_percent_;
777 return percent;
778}
779
[email protected]3c733bde2010-12-21 19:56:31780void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:50781 if (!delegate_)
782 return;
783
784 NavigationEntry* active_entry = controller().GetActiveEntry();
785 if (!active_entry)
786 return;
787
788 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:12789}
790
[email protected]932b7a12011-03-09 12:50:27791void TabContents::ViewFrameSource(const GURL& url,
792 const std::string& content_state) {
793 if (!delegate_)
794 return;
795
796 delegate_->ViewSourceForFrame(this, url, content_state);
797}
798
[email protected]c40d6232011-03-25 00:16:21799void TabContents::SetContentRestrictions(int restrictions) {
800 content_restrictions_ = restrictions;
801 delegate()->ContentRestrictionsChanged(this);
802}
803
[email protected]724159a2010-12-30 01:11:18804void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
805 bool is_main_frame,
[email protected]eacb080b2011-05-22 19:40:26806 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18807 const GURL& url) {
808 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
809 GURL validated_url(url);
810 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
811 GetRenderProcessHost()->id(), &validated_url);
812
[email protected]8093a542011-05-13 07:29:32813 RenderViewHost* rvh =
814 render_manager_.pending_render_view_host() ?
815 render_manager_.pending_render_view_host() : render_view_host();
[email protected]0d60f0192011-04-14 12:40:10816 // Notify observers about the start of the provisional load.
817 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
818 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:32819 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:10820
[email protected]724159a2010-12-30 01:11:18821 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:59822 // Notify observers about the provisional change in the main frame URL.
823 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26824 ProvisionalChangeToMainFrameUrl(url, has_opener_set));
[email protected]724159a2010-12-30 01:11:18825 }
826}
827
828void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]eacb080b2011-05-22 19:40:26829 bool has_opener_set,
[email protected]724159a2010-12-30 01:11:18830 const GURL& source_url,
831 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:49832 // TODO(creis): Remove this method and have the pre-rendering code listen to
833 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
834 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:18835 NavigationEntry* entry;
836 if (page_id == -1)
837 entry = controller_.pending_entry();
838 else
839 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
840 if (!entry || entry->url() != source_url)
841 return;
[email protected]e7d50892011-01-19 21:47:38842
[email protected]4850a7f2011-03-08 23:36:59843 // Notify observers about the provisional change in the main frame URL.
844 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]eacb080b2011-05-22 19:40:26845 ProvisionalChangeToMainFrameUrl(target_url,
846 has_opener_set));
[email protected]724159a2010-12-30 01:11:18847}
848
849void TabContents::OnDidFailProvisionalLoadWithError(
850 int64 frame_id,
851 bool is_main_frame,
852 int error_code,
853 const GURL& url,
854 bool showing_repost_interstitial) {
855 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
856 << ", error_code: " << error_code
857 << " is_main_frame: " << is_main_frame
858 << " showing_repost_interstitial: " << showing_repost_interstitial
859 << " frame_id: " << frame_id;
860 GURL validated_url(url);
861 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
862 GetRenderProcessHost()->id(), &validated_url);
863
864 if (net::ERR_ABORTED == error_code) {
865 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
866 // This means that the interstitial won't be torn down properly, which is
867 // bad. But if we have an interstitial, go back to another tab type, and
868 // then load the same interstitial again, we could end up getting the first
869 // interstitial's "failed" message (as a result of the cancel) when we're on
870 // the second one.
871 //
872 // We can't tell this apart, so we think we're tearing down the current page
873 // which will cause a crash later one. There is also some code in
874 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
875 // out because of this problem.
876 //
877 // http://code.google.com/p/chromium/issues/detail?id=2855
878 // Because this will not tear down the interstitial properly, if "back" is
879 // back to another tab type, the interstitial will still be somewhat alive
880 // in the previous tab type. If you navigate somewhere that activates the
881 // tab with the interstitial again, you'll see a flash before the new load
882 // commits of the interstitial page.
883 if (showing_interstitial_page()) {
884 LOG(WARNING) << "Discarding message during interstitial.";
885 return;
886 }
887
[email protected]02102f82011-06-13 20:37:02888 // Discard our pending entry if the load canceled (e.g. if we decided to
889 // download the file instead of load it). We do not verify that the URL
890 // being canceled matches the pending entry's URL because they will not
891 // match if a redirect occurred (in which case we do not want to leave a
892 // stale redirect URL showing). This means that we also cancel the pending
893 // entry if the user started a new navigation. As a result, the navigation
894 // controller may not remember that a load is in progress, but the
895 // navigation will still commit even if there is no pending entry.
[email protected]724159a2010-12-30 01:11:18896 NavigationEntry* pending_entry = controller_.pending_entry();
[email protected]02102f82011-06-13 20:37:02897 if (pending_entry)
[email protected]c95fa8b2011-04-28 20:26:16898 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:18899
900 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
901 }
902
903 // Send out a notification that we failed a provisional load with an error.
904 ProvisionalLoadDetails details(
905 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:09906 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:18907 details.set_error_code(error_code);
908
909 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27910 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR,
[email protected]724159a2010-12-30 01:11:18911 Source<NavigationController>(&controller_),
912 Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:10913
914 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
915 DidFailProvisionalLoad(frame_id, is_main_frame,
916 validated_url, error_code));
[email protected]724159a2010-12-30 01:11:18917}
918
919void TabContents::OnDidLoadResourceFromMemoryCache(
920 const GURL& url,
[email protected]724159a2010-12-30 01:11:18921 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:19922 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:18923 cache.Increment();
924
925 // Send out a notification that we loaded a resource from our memory cache.
926 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
927 SSLManager::DeserializeSecurityInfo(security_info,
928 &cert_id, &cert_status,
929 &security_bits,
930 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:16931 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
932 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:18933
934 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27935 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]724159a2010-12-30 01:11:18936 Source<NavigationController>(&controller_),
937 Details<LoadFromMemoryCacheDetails>(&details));
938}
939
940void TabContents::OnDidDisplayInsecureContent() {
[email protected]221a5d92011-04-28 18:23:16941 UserMetrics::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:18942 displayed_insecure_content_ = true;
943 SSLManager::NotifySSLInternalStateChanged();
944}
945
946void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:02947 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:23948 LOG(INFO) << security_origin << " ran insecure content from "
949 << target_url.possibly_invalid_spec();
[email protected]221a5d92011-04-28 18:23:16950 UserMetrics::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]724159a2010-12-30 01:11:18951 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:41952 displayed_insecure_content_ = true;
953 SSLManager::NotifySSLInternalStateChanged();
[email protected]724159a2010-12-30 01:11:18954}
955
956void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
957 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:10958 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
959 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:18960}
961
962void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:10963 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
964 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:18965}
966
[email protected]c8f73ab2011-01-22 00:05:17967void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:21968 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:17969}
970
[email protected]216813952011-05-19 22:21:26971void TabContents::OnGoToEntryAtOffset(int offset) {
972 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
973 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
974 if (!entry)
975 return;
976 // Note that we don't call NavigationController::GotToOffset() as we don't
977 // want to create a pending navigation entry (it might end up lingering
978 // http://crbug.com/51680).
979 entry->set_transition_type(entry->transition_type() |
980 PageTransition::FORWARD_BACK);
981 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
982 }
983}
984
985void TabContents::OnUpdateZoomLimits(int minimum_percent,
986 int maximum_percent,
987 bool remember) {
988 minimum_zoom_percent_ = minimum_percent;
989 maximum_zoom_percent_ = maximum_percent;
990 temporary_zoom_settings_ = !remember;
991}
992
993void TabContents::OnFocusedNodeChanged(bool is_editable_node) {
994 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27995 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
[email protected]216813952011-05-19 22:21:26996 Source<TabContents>(this),
997 Details<const bool>(&is_editable_node));
998}
999
[email protected]96d185d2009-04-24 03:28:541000// Notifies the RenderWidgetHost instance about the fact that the page is
1001// loading, or done loading and calls the base implementation.
1002void TabContents::SetIsLoading(bool is_loading,
1003 LoadNotificationDetails* details) {
1004 if (is_loading == is_loading_)
1005 return;
1006
1007 if (!is_loading) {
1008 load_state_ = net::LOAD_STATE_IDLE;
1009 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561010 upload_size_ = 0;
1011 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541012 }
1013
1014 render_manager_.SetIsLoading(is_loading);
1015
1016 is_loading_ = is_loading;
1017 waiting_for_response_ = is_loading;
1018
[email protected]6ebdc9b2010-09-27 16:55:571019 if (delegate_)
1020 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351021 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541022
[email protected]432115822011-07-10 15:52:271023 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1024 content::NOTIFICATION_LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111025 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541026 if (details)
1027 det = Details<LoadNotificationDetails>(details);
1028 NotificationService::current()->Notify(type,
1029 Source<NavigationController>(&controller_),
1030 det);
1031}
1032
[email protected]d0980792011-02-13 19:41:401033WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581034 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541035 // that goes along with it to control the basic flags. For example, we want to
1036 // show the pending URL in the URL bar, so we want the display_url flag to
1037 // be from the pending entry.
1038 //
1039 // The confusion comes because there are multiple possibilities for the
1040 // initial load in a tab as a side effect of the way the RenderViewHostManager
1041 // works.
1042 //
[email protected]e0112912011-02-02 22:54:351043 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541044 // the pending one, and we want it to apply here.
1045 //
1046 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1047 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581048 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351049 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541050 //
1051 // This condition handles all of these cases:
1052 //
1053 // - First load in first tab: no committed nav entry + pending nav entry +
1054 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351055 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541056 //
1057 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351058 // no pending Web UI:
1059 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541060 //
1061 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351062 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541063 //
1064 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351065 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541066 if (controller_.pending_entry() &&
1067 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581068 render_manager_.pending_web_ui()))
1069 return render_manager_.pending_web_ui();
1070 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541071}
[email protected]420ae012009-04-24 05:16:321072
[email protected]1fd1a502011-03-30 16:55:561073WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1074 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1075}
1076
[email protected]420ae012009-04-24 05:16:321077void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131078 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321079 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561080 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381081 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441082 // that opened the window, as long as both renderers have the same
1083 // privileges.
[email protected]1fd1a502011-03-30 16:55:561084 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1085 WebUI* web_ui = content::GetContentClient()->browser()->
1086 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581087 // web_ui might be NULL if the URL refers to a non-existent extension.
1088 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401089 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581090 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441091 }
1092 }
[email protected]1fd1a502011-03-30 16:55:561093 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441094 }
1095
[email protected]4e697b042011-07-08 06:44:561096 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321097 // Clear the status bubble. This is a workaround for a bug where WebKit
1098 // doesn't let us know that the cursor left an element during a
1099 // transition (this is also why the mouse cursor remains as a hand after
1100 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1101 // clear the bubble when a user navigates to a named anchor in the same
1102 // page.
1103 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321104 }
1105
[email protected]a6e82fc2010-02-24 22:28:141106 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471107 // Once the main frame is navigated, we're no longer considered to have
1108 // displayed insecure content.
1109 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171110 }
[email protected]ce5c4502009-05-06 16:46:111111
[email protected]8cc8d492010-02-02 10:40:491112 // Close constrained windows if necessary.
1113 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1114 details.previous_url, details.entry->url()))
1115 CloseConstrainedWindows();
1116
[email protected]3c9e1872010-11-18 16:17:491117 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171118 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491119 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321120}
1121
1122void TabContents::DidNavigateAnyFramePostCommit(
1123 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131124 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321125 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]3ab9cb82011-06-03 18:02:071126 // If we navigate, reset JavaScript state. This does nothing to prevent
[email protected]420ae012009-04-24 05:16:321127 // a malicious script from spamming messages, since the script could just
1128 // reload the page to stop blocking.
[email protected]3ab9cb82011-06-03 18:02:071129 if (delegate_)
1130 delegate_->GetJavaScriptDialogCreator()->ResetJavaScriptState(this);
[email protected]420ae012009-04-24 05:16:321131
[email protected]3c9e1872010-11-18 16:17:491132 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171133 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491134 DidNavigateAnyFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321135}
1136
[email protected]8cc8d492010-02-02 10:40:491137void TabContents::CloseConstrainedWindows() {
1138 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331139 // To ensure that we iterate over every element in child_windows_ we
1140 // need to use a copy of child_windows_. Otherwise if
1141 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1142 // skipping some elements.
1143 ConstrainedWindowList child_windows_copy(child_windows_);
1144 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1145 it != child_windows_copy.end(); ++it) {
1146 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441147 if (window) {
[email protected]420ae012009-04-24 05:16:321148 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441149 BlockTabContent(false);
1150 }
[email protected]420ae012009-04-24 05:16:321151 }
1152}
1153
[email protected]420ae012009-04-24 05:16:321154void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1155 RenderViewHost* rvh) {
1156 // If we are creating a RVH for a restored controller, then we might
1157 // have more page IDs than the SiteInstance's current max page ID. We must
1158 // make sure that the max page ID is larger than any restored page ID.
1159 // Note that it is ok for conflicting page IDs to exist in another tab
1160 // (i.e., NavigationController), but if any page ID is larger than the max,
1161 // the back/forward list will get confused.
1162 int max_restored_page_id = controller_.max_restored_page_id();
1163 if (max_restored_page_id > 0) {
1164 int curr_max_page_id = site_instance->max_page_id();
1165 if (max_restored_page_id > curr_max_page_id) {
1166 // Need to update the site instance immediately.
1167 site_instance->UpdateMaxPageID(max_restored_page_id);
1168
1169 // Also tell the renderer to update its internal representation. We
1170 // need to reserve enough IDs to make all restored page IDs less than
1171 // the max.
1172 if (curr_max_page_id < 0)
1173 curr_max_page_id = 0;
[email protected]216813952011-05-19 22:21:261174 rvh->Send(new ViewMsg_ReservePageIDRange(
1175 rvh->routing_id(), max_restored_page_id - curr_max_page_id));
[email protected]420ae012009-04-24 05:16:321176 }
1177 }
1178}
1179
[email protected]6b2f7a82011-04-25 19:30:511180bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1181 const std::wstring& title) {
[email protected]420ae012009-04-24 05:16:321182 // For file URLs without a title, use the pathname instead. In the case of a
1183 // synthesized title, we don't want the update to count toward the "one set
1184 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511185 string16 final_title;
[email protected]420ae012009-04-24 05:16:321186 bool explicit_set;
[email protected]987fc3a2011-05-26 14:18:091187 if (entry && entry->url().SchemeIsFile() && title.empty()) {
[email protected]6b2f7a82011-04-25 19:30:511188 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321189 explicit_set = false; // Don't count synthetic titles toward the set limit.
1190 } else {
[email protected]6b2f7a82011-04-25 19:30:511191 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321192 explicit_set = true;
1193 }
1194
[email protected]987fc3a2011-05-26 14:18:091195 // If a page is created via window.open and never navigated,
1196 // there will be no navigation entry. In this situation,
1197 // |page_title_when_no_navigaiton_entry_| will be used for page title.
1198 if (entry) {
1199 if (final_title == entry->title())
1200 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321201
[email protected]987fc3a2011-05-26 14:18:091202 entry->set_title(final_title);
1203 } else {
1204 if (page_title_when_no_navigation_entry_ == final_title)
1205 return false; // Nothing changed, don't bother.
1206
1207 page_title_when_no_navigation_entry_ = final_title;
1208 }
[email protected]420ae012009-04-24 05:16:321209
[email protected]420ae012009-04-24 05:16:321210 // Lastly, set the title for the view.
[email protected]6b2f7a82011-04-25 19:30:511211 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321212
[email protected]105bb0f2011-05-24 17:12:141213 TitleUpdatedDetails details(entry, explicit_set);
1214
[email protected]cbc0e1b2010-04-12 18:33:041215 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271216 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
[email protected]cbc0e1b2010-04-12 18:33:041217 Source<TabContents>(this),
[email protected]105bb0f2011-05-24 17:12:141218 Details<TitleUpdatedDetails>(&details));
[email protected]cbc0e1b2010-04-12 18:33:041219
[email protected]420ae012009-04-24 05:16:321220 return true;
1221}
1222
1223void TabContents::NotifySwapped() {
1224 // After sending out a swap notification, we need to send a disconnect
1225 // notification so that clients that pick up a pointer to |this| can NULL the
1226 // pointer. See Bug 1230284.
1227 notify_disconnection_ = true;
1228 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271229 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221230 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321231 NotificationService::NoDetails());
1232}
1233
1234void TabContents::NotifyConnected() {
1235 notify_disconnection_ = true;
1236 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271237 content::NOTIFICATION_TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221238 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321239 NotificationService::NoDetails());
1240}
1241
1242void TabContents::NotifyDisconnected() {
1243 if (!notify_disconnection_)
1244 return;
1245
1246 notify_disconnection_ = false;
1247 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271248 content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221249 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321250 NotificationService::NoDetails());
1251}
1252
[email protected]8d3347f2009-07-09 22:00:211253RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321254 return view_.get();
1255}
1256
[email protected]8d3347f2009-07-09 22:00:211257RenderViewHostDelegate::RendererManagement*
1258TabContents::GetRendererManagementDelegate() {
1259 return &render_manager_;
1260}
1261
[email protected]93623c5d2009-12-10 21:40:321262RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461263 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511264}
1265
[email protected]57c6a652009-05-04 07:58:341266TabContents* TabContents::GetAsTabContents() {
1267 return this;
1268}
1269
[email protected]7b291f92009-08-14 05:43:531270ViewType::Type TabContents::GetRenderViewType() const {
1271 return ViewType::TAB_CONTENTS;
1272}
1273
[email protected]420ae012009-04-24 05:16:321274void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061275 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271276 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]2e4633c2009-07-09 16:58:061277 Source<TabContents>(this),
1278 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321279 NavigationEntry* entry = controller_.GetActiveEntry();
1280 if (!entry)
1281 return;
1282
1283 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351284 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561285 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581286 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321287
1288 if (entry->IsViewSourceMode()) {
1289 // Put the renderer in view source mode.
1290 render_view_host->Send(
1291 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1292 }
[email protected]0666aef2009-05-13 19:48:081293
1294 view()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261295
1296 FOR_EACH_OBSERVER(
1297 TabContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321298}
1299
1300void TabContents::RenderViewReady(RenderViewHost* rvh) {
1301 if (rvh != render_view_host()) {
1302 // Don't notify the world, since this came from a renderer in the
1303 // background.
1304 return;
1305 }
1306
1307 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301308 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231309 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301310
1311 // Restore the focus to the tab (otherwise the focus will be on the top
1312 // window).
[email protected]484ae5912010-09-29 19:16:141313 if (was_crashed && !FocusLocationBarByDefault() &&
1314 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301315 Focus();
[email protected]484ae5912010-09-29 19:16:141316 }
[email protected]420ae012009-04-24 05:16:321317}
1318
[email protected]443b80e2010-12-14 00:42:231319void TabContents::RenderViewGone(RenderViewHost* rvh,
1320 base::TerminationStatus status,
1321 int error_code) {
[email protected]420ae012009-04-24 05:16:321322 if (rvh != render_view_host()) {
1323 // The pending page's RenderViewHost is gone.
1324 return;
1325 }
1326
1327 SetIsLoading(false, NULL);
1328 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231329 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321330
[email protected]55452902011-06-01 21:57:471331 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
[email protected]420ae012009-04-24 05:16:321332}
1333
[email protected]2e4633c2009-07-09 16:58:061334void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481335 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061336}
1337
[email protected]420ae012009-04-24 05:16:321338void TabContents::DidNavigate(RenderViewHost* rvh,
1339 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]09b29342011-06-24 19:18:481340 if (PageTransition::IsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:321341 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:371342
[email protected]420ae012009-04-24 05:16:321343 // Update the site of the SiteInstance if it doesn't have one yet.
1344 if (!GetSiteInstance()->has_site())
1345 GetSiteInstance()->SetSite(params.url);
1346
1347 // Need to update MIME type here because it's referred to in
1348 // UpdateNavigationCommands() called by RendererDidNavigate() to
1349 // determine whether or not to enable the encoding menu.
1350 // It's updated only for the main frame. For a subframe,
1351 // RenderView::UpdateURL does not set params.contents_mime_type.
1352 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1353 // TODO(jungshik): Add a test for the encoding menu to avoid
1354 // regressing it again.
1355 if (PageTransition::IsMainFrame(params.transition))
1356 contents_mime_type_ = params.contents_mime_type;
1357
[email protected]8286f51a2011-05-31 17:39:131358 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:001359 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:391360
[email protected]a9c0bfe2010-09-17 08:35:221361 // Send notification about committed provisional loads. This notification is
1362 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1363 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1364 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071365 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1366 // that is not recorded in the navigation history. For the purpose of
1367 // tracking navigation events, we treat this event as a sub frame navigation
1368 // event.
1369 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]0d60f0192011-04-14 12:40:101370 PageTransition::Type transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221371 // Whether or not a page transition was triggered by going backward or
1372 // forward in the history is only stored in the navigation controller's
1373 // entry list.
1374 if (did_navigate &&
1375 (controller_.GetActiveEntry()->transition_type() &
1376 PageTransition::FORWARD_BACK)) {
[email protected]0d60f0192011-04-14 12:40:101377 transition_type = params.transition | PageTransition::FORWARD_BACK;
[email protected]a9c0bfe2010-09-17 08:35:221378 }
[email protected]0d60f0192011-04-14 12:40:101379 // Notify observers about the commit of the provisional load.
1380 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1381 DidCommitProvisionalLoadForFrame(params.frame_id,
1382 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221383 }
1384
[email protected]76543b92009-08-31 17:27:451385 if (!did_navigate)
1386 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321387
1388 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1389 // for the appropriate notification (best) or you can add it to
1390 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1391 // necessary, please).
1392
1393 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:001394 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:321395 DidNavigateMainFramePostCommit(details, params);
[email protected]09b29342011-06-24 19:18:481396 if (delegate())
1397 delegate()->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:001398 }
[email protected]420ae012009-04-24 05:16:321399 DidNavigateAnyFramePostCommit(rvh, details, params);
1400}
1401
1402void TabContents::UpdateState(RenderViewHost* rvh,
1403 int32 page_id,
1404 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:151405 // Ensure that this state update comes from either the active RVH or one of
1406 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1407 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:321408
1409 // We must be prepared to handle state updates for any page, these occur
1410 // when the user is scrolling and entering form data, as well as when we're
1411 // leaving a page, in which case our state may have already been moved to
1412 // the next page. The navigation controller will look up the appropriate
1413 // NavigationEntry and update it when it is notified via the delegate.
1414
1415 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]992db4c2011-05-12 15:37:151416 rvh->site_instance(), page_id);
[email protected]420ae012009-04-24 05:16:321417 if (entry_index < 0)
1418 return;
1419 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1420
1421 if (state == entry->content_state())
1422 return; // Nothing to update.
1423 entry->set_content_state(state);
1424 controller_.NotifyEntryChanged(entry, entry_index);
1425}
1426
1427void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]6b2f7a82011-04-25 19:30:511428 int32 page_id, const std::wstring& title) {
[email protected]420ae012009-04-24 05:16:321429 // If we have a title, that's a pretty good indication that we've started
1430 // getting useful data.
1431 SetNotWaitingForResponse();
1432
1433 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:481434 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:581435 page_id);
[email protected]987fc3a2011-05-26 14:18:091436
1437 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:321438 return;
1439
1440 // Broadcast notifications when the UI should be updated.
1441 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:031442 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:321443}
1444
[email protected]420ae012009-04-24 05:16:321445void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:401446 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:321447 set_encoding(encoding);
1448}
1449
1450void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1451 if (delegate())
1452 delegate()->UpdateTargetURL(this, url);
1453}
1454
[email protected]420ae012009-04-24 05:16:321455void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:291456 // The UI may be in an event-tracking loop, such as between the
1457 // mouse-down and mouse-up in text selection or a button click.
1458 // Defer the close until after tracking is complete, so that we
1459 // don't free objects out from under the UI.
1460 // TODO(shess): This could probably be integrated with the
1461 // IsDoingDrag() test below. Punting for now because I need more
1462 // research to understand how this impacts platforms other than Mac.
1463 // TODO(shess): This could get more fine-grained. For instance,
1464 // closing a tab in another window while selecting text in the
1465 // current window's Omnibox should be just fine.
1466 if (view()->IsEventTracking()) {
1467 view()->CloseTabAfterEventTracking();
1468 return;
1469 }
1470
[email protected]24a4d1062009-07-10 23:10:421471 // If we close the tab while we're in the middle of a drag, we'll crash.
1472 // Instead, cancel the drag and close it as soon as the drag ends.
1473 if (view()->IsDoingDrag()) {
1474 view()->CancelDragAndCloseTab();
1475 return;
1476 }
1477
[email protected]420ae012009-04-24 05:16:321478 // Ignore this if it comes from a RenderViewHost that we aren't showing.
1479 if (delegate() && rvh == render_view_host())
1480 delegate()->CloseContents(this);
1481}
1482
1483void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]b35b26b32011-05-05 20:35:141484 if (delegate() && delegate()->IsPopupOrPanel(this))
[email protected]420ae012009-04-24 05:16:321485 delegate()->MoveContents(this, new_bounds);
1486}
1487
[email protected]7ab1e7d62009-10-14 23:32:011488void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:321489 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:491490
[email protected]c40d6232011-03-25 00:16:211491 if (delegate() && content_restrictions_) {
1492 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:211493 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:001494 }
[email protected]3c9e1872010-11-18 16:17:491495
1496 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171497 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:321498}
1499
[email protected]7ab1e7d62009-10-14 23:32:011500void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:321501 scoped_ptr<LoadNotificationDetails> details;
1502
1503 NavigationEntry* entry = controller_.GetActiveEntry();
1504 // An entry may not exist for a stop when loading an initial blank page or
1505 // if an iframe injected by script into a blank page finishes loading.
1506 if (entry) {
[email protected]420ae012009-04-24 05:16:321507 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
1508
1509 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:541510 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:321511 entry->transition_type(),
1512 elapsed,
1513 &controller_,
1514 controller_.GetCurrentEntryIndex()));
1515 }
1516
[email protected]420ae012009-04-24 05:16:321517 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:491518
1519 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171520 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:321521}
1522
[email protected]c95fa8b2011-04-28 20:26:161523void TabContents::DidCancelLoading() {
1524 controller_.DiscardNonCommittedEntries();
1525
1526 // Update the URL display.
1527 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1528}
1529
[email protected]1a3c3cb2010-12-16 21:03:401530void TabContents::DidChangeLoadProgress(double progress) {
1531 if (delegate())
1532 delegate()->LoadProgressChanged(progress);
1533}
1534
[email protected]25497492010-09-11 15:15:081535void TabContents::DocumentOnLoadCompletedInMainFrame(
1536 RenderViewHost* render_view_host,
1537 int32 page_id) {
1538 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271539 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]25497492010-09-11 15:15:081540 Source<TabContents>(this),
1541 Details<int>(&page_id));
1542}
1543
[email protected]420ae012009-04-24 05:16:321544void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
1545 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:581546 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:351547 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:321548 // is so the new tab page can specify AUTO_BOOKMARK for automatically
1549 // generated suggestions).
1550 //
[email protected]e0112912011-02-02 22:54:351551 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:161552 // want web sites to see a referrer of "chrome://blah" (and some
1553 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:321554 // send to the site), so we send no referrer.
1555 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:581556 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:321557 } else {
1558 OpenURL(url, referrer, disposition, PageTransition::LINK);
1559 }
1560}
1561
[email protected]420ae012009-04-24 05:16:321562void TabContents::RunJavaScriptMessage(
[email protected]992db4c2011-05-12 15:37:151563 const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411564 const string16& message,
1565 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:321566 const GURL& frame_url,
1567 const int flags,
1568 IPC::Message* reply_msg,
1569 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:071570 // Suppress JavaScript dialogs when requested. Also suppress messages when
1571 // showing an interstitial as it's shown over the previous page and we don't
1572 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:501573 bool suppress_this_message =
[email protected]992db4c2011-05-12 15:37:151574 rvh->is_swapped_out() ||
[email protected]8f55e802010-12-06 18:11:501575 showing_interstitial_page() ||
[email protected]3ab9cb82011-06-03 18:02:071576 !delegate_ ||
1577 delegate_->ShouldSuppressDialogs();
[email protected]420ae012009-04-24 05:16:321578
1579 if (!suppress_this_message) {
[email protected]b627d9a2011-06-28 14:06:341580 content::JavaScriptDialogCreator::TitleType title_type;
1581 string16 title;
1582
1583 if (!frame_url.has_host()) {
1584 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE;
1585 } else {
1586 title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL;
1587 title = net::FormatUrl(
1588 frame_url.GetOrigin(),
1589 content::GetContentClient()->browser()->GetAcceptLangs(this));
1590 }
1591
[email protected]3ab9cb82011-06-03 18:02:071592 delegate_->GetJavaScriptDialogCreator()->RunJavaScriptDialog(
1593 this,
[email protected]b627d9a2011-06-28 14:06:341594 title_type,
1595 title,
[email protected]3ab9cb82011-06-03 18:02:071596 flags,
1597 message,
1598 default_prompt,
1599 reply_msg,
[email protected]b627d9a2011-06-28 14:06:341600 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:321601 }
[email protected]3ab9cb82011-06-03 18:02:071602
1603 if (suppress_this_message) {
1604 // If we are suppressing messages, just reply as if the user immediately
1605 // pressed "Cancel".
1606 OnDialogClosed(reply_msg, false, string16());
1607 }
1608
1609 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:321610}
1611
[email protected]992db4c2011-05-12 15:37:151612void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:411613 const string16& message,
[email protected]420ae012009-04-24 05:16:321614 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:291615 if (delegate())
1616 delegate()->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:071617
1618 bool suppress_this_message =
1619 rvh->is_swapped_out() ||
1620 !delegate_ ||
1621 delegate_->ShouldSuppressDialogs();
[email protected]992db4c2011-05-12 15:37:151622 if (suppress_this_message) {
[email protected]4f5ce842011-05-27 19:34:411623 render_view_host()->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:501624 return;
1625 }
[email protected]3ab9cb82011-06-03 18:02:071626
[email protected]7ab1e7d62009-10-14 23:32:011627 is_showing_before_unload_dialog_ = true;
[email protected]3ab9cb82011-06-03 18:02:071628 delegate_->GetJavaScriptDialogCreator()->RunBeforeUnloadDialog(
1629 this,
1630 message,
1631 reply_msg);
[email protected]420ae012009-04-24 05:16:321632}
1633
[email protected]420ae012009-04-24 05:16:321634WebPreferences TabContents::GetWebkitPrefs() {
[email protected]447021c2010-09-08 21:29:081635 WebPreferences web_prefs =
[email protected]181a95ee2011-07-12 19:26:361636 content::GetContentClient()->browser()->GetWebkitPrefs(
1637 render_view_host()->process()->profile(), false);
[email protected]447021c2010-09-08 21:29:081638
[email protected]b8299c12011-06-03 19:52:281639 // Force accelerated compositing and 2d canvas off for chrome:, about: and
1640 // chrome-devtools: pages.
[email protected]27c790d42010-10-22 09:28:431641 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]b8299c12011-06-03 19:52:281642 GetURL().SchemeIs(chrome::kChromeUIScheme) ||
1643 GetURL().SchemeIs(chrome::kAboutScheme)) {
[email protected]447021c2010-09-08 21:29:081644 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:431645 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:081646 }
1647
[email protected]39553442010-09-09 00:01:551648#if defined(OS_MACOSX)
1649 // Disable accelerated compositing if IOSurface's are not supported,
1650 // as is the case in 10.5.
1651 if (!IOSurfaceSupport::Initialize())
1652 web_prefs.accelerated_compositing_enabled = false;
1653#endif
1654
[email protected]447021c2010-09-08 21:29:081655 return web_prefs;
[email protected]420ae012009-04-24 05:16:321656}
1657
[email protected]7d472472011-01-22 01:30:251658void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:271659 // Notify observers.
1660 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:221661
1662 ResourceDispatcherHost* rdh =
1663 content::GetContentClient()->browser()->GetResourceDispatcherHost();
1664 if (rdh) // NULL in unittests.
1665 rdh->download_request_limiter()->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:251666}
1667
[email protected]fa1cf0b82010-01-15 21:49:441668void TabContents::OnIgnoredUIEvent() {
1669 if (constrained_window_count()) {
1670 ConstrainedWindow* window = *constrained_window_begin();
1671 window->FocusConstrainedWindow();
1672 }
1673}
1674
[email protected]420ae012009-04-24 05:16:321675void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
1676 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:341677 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:321678 // delivered to a pending RenderViewHost. We must first run the onunload
1679 // handler of the old RenderViewHost before we can allow it to proceed.
1680 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
1681 new_request_id);
1682}
1683
[email protected]420ae012009-04-24 05:16:321684void TabContents::RendererUnresponsive(RenderViewHost* rvh,
1685 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:151686 // Don't show hung renderer dialog for a swapped out RVH.
1687 if (rvh != render_view_host())
1688 return;
1689
[email protected]420ae012009-04-24 05:16:321690 if (is_during_unload) {
1691 // Hang occurred while firing the beforeunload/unload handler.
1692 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:111693 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:321694
1695 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
1696 return;
1697
1698 // If the tab hangs in the beforeunload/unload handler there's really
1699 // nothing we can do to recover. Pretend the unload listeners have
1700 // all fired and close the tab. If the hang is in the beforeunload handler
1701 // then the user will not have the option of cancelling the close.
1702 Close(rvh);
1703 return;
1704 }
1705
[email protected]55452902011-06-01 21:57:471706 if (!render_view_host() || !render_view_host()->IsRenderViewLive())
1707 return;
1708
1709 if (delegate())
1710 delegate()->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:321711}
1712
1713void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]55452902011-06-01 21:57:471714 if (delegate())
1715 delegate()->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:321716}
1717
1718void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:561719 net::LoadState load_state,
1720 uint64 upload_position,
1721 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:321722 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:561723 upload_position_ = upload_position;
1724 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:501725 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]b5cca982011-05-26 04:42:081726 content::GetContentClient()->browser()->GetAcceptLangs(this));
[email protected]420ae012009-04-24 05:16:321727 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
1728 SetNotWaitingForResponse();
1729 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:501730 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]7d472472011-01-22 01:30:251733void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:441734 if (delegate())
[email protected]55452902011-06-01 21:57:471735 delegate()->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:251736}
1737
[email protected]420ae012009-04-24 05:16:321738void TabContents::BeforeUnloadFiredFromRenderManager(
1739 bool proceed,
1740 bool* proceed_to_fire_unload) {
1741 if (delegate())
1742 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
1743}
1744
[email protected]3a3d47472010-07-15 21:03:541745void TabContents::DidStartLoadingFromRenderManager(
1746 RenderViewHost* render_view_host) {
1747 DidStartLoading();
1748}
1749
1750void TabContents::RenderViewGoneFromRenderManager(
1751 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:231752 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
1753 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:541754}
1755
[email protected]420ae012009-04-24 05:16:321756void TabContents::UpdateRenderViewSizeForRenderManager() {
1757 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:261758 gfx::Size size = view_->GetContainerSize();
1759 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
1760 // here during container initialization and normal window size will be set
1761 // later. In case of tab duplication this resizing to 0x0 prevents setting
1762 // normal size later so just ignore it.
1763 if (!size.IsEmpty())
1764 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:321765}
1766
[email protected]3a3d47472010-07-15 21:03:541767void TabContents::NotifySwappedFromRenderManager() {
1768 NotifySwapped();
1769}
1770
1771NavigationController& TabContents::GetControllerForRenderManager() {
1772 return controller();
1773}
1774
[email protected]d0980792011-02-13 19:41:401775WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:561776 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:321777}
1778
1779NavigationEntry*
1780TabContents::GetLastCommittedNavigationEntryForRenderManager() {
1781 return controller_.GetLastCommittedEntry();
1782}
1783
1784bool TabContents::CreateRenderViewForRenderManager(
1785 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:321786 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:521787
[email protected]420ae012009-04-24 05:16:321788 // Now that the RenderView has been created, we need to tell it its size.
1789 rwh_view->SetSize(view_->GetContainerSize());
1790
[email protected]a4127722011-04-27 23:13:521791 if (!render_view_host->CreateRenderView(string16()))
1792 return false;
1793
[email protected]f8233cc2011-05-31 20:24:501794#if defined(OS_LINUX)
1795 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
1796 // linux. See crbug.com/83941.
1797 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1798 render_widget_host->WasResized();
1799#endif
1800
[email protected]420ae012009-04-24 05:16:321801 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
1802 render_view_host);
1803 return true;
1804}
1805
[email protected]3ab9cb82011-06-03 18:02:071806void TabContents::OnDialogClosed(IPC::Message* reply_msg,
1807 bool success,
1808 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:541809 if (is_showing_before_unload_dialog_ && !success) {
1810 // If a beforeunload dialog is canceled, we need to stop the throbber from
1811 // spinning, since we forced it to start spinning in Navigate.
1812 DidStopLoading();
1813
1814 tab_close_start_time_ = base::TimeTicks();
1815 }
1816 is_showing_before_unload_dialog_ = false;
[email protected]4f5ce842011-05-27 19:34:411817 render_view_host()->JavaScriptDialogClosed(reply_msg,
1818 success,
[email protected]3ab9cb82011-06-03 18:02:071819 user_input);
[email protected]beb440c2009-11-06 04:08:541820}
1821
[email protected]3ab9cb82011-06-03 18:02:071822gfx::NativeWindow TabContents::GetDialogRootWindow() {
1823 return view_->GetTopLevelNativeWindow();
[email protected]beb440c2009-11-06 04:08:541824}
1825
[email protected]a1e97f02011-06-30 14:04:341826void TabContents::OnDialogShown() {
1827 Activate();
[email protected]3a3d47472010-07-15 21:03:541828}
1829
[email protected]41fc0322009-09-04 22:23:401830void TabContents::set_encoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:121831 encoding_ = content::GetContentClient()->browser()->
1832 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:101833}
[email protected]f45d2a72010-03-08 23:28:351834
[email protected]33f74972010-12-08 16:40:361835void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
1836 render_manager_.SwapInRenderViewHost(rvh);
1837}
1838
1839void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
1840 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
1841 rwh_view->SetSize(view()->GetContainerSize());
1842}