blob: 70988e2de365c71a757e66386f9bf57a81fbcd0c [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// 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]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
7#include "chrome/browser/cert_store.h"
initial.commit09911bf2008-07-26 23:55:298#include "chrome/browser/views/download_shelf_view.h"
9#include "chrome/browser/views/download_started_animation.h"
[email protected]d6598c052008-11-05 19:03:2510#include "chrome/browser/views/blocked_popup_container.h"
[email protected]f3ec7742009-01-15 00:59:1611#include "chrome/browser/tab_contents/infobar_delegate.h"
12#include "chrome/browser/tab_contents/navigation_entry.h"
13#include "chrome/browser/tab_contents/tab_contents_delegate.h"
14#include "chrome/browser/tab_contents/web_contents.h"
[email protected]a4feef82008-10-02 15:11:2215#include "chrome/common/l10n_util.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/common/pref_names.h"
[email protected]1eb89e82008-08-15 12:27:0317#include "chrome/common/pref_service.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/views/native_scroll_bar.h"
[email protected]1eb89e82008-08-15 12:27:0319#include "chrome/views/root_view.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/views/view.h"
21#include "chrome/views/view_storage.h"
[email protected]a0dde122008-11-21 20:51:2022#include "chrome/views/widget.h"
initial.commit09911bf2008-07-26 23:55:2923
24#include "generated_resources.h"
25
[email protected]d5f942ba2008-09-26 19:30:3426namespace {
27
28BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
[email protected]4d0bd102008-10-16 00:26:3029 // Note: erase is required to properly paint some widgets borders. This can
30 // be seen with textfields.
[email protected]d5f942ba2008-09-26 19:30:3431 InvalidateRect(hwnd, NULL, TRUE);
32 return TRUE;
33}
34
35} // namespace
36
initial.commit09911bf2008-07-26 23:55:2937TabContents::TabContents(TabContentsType type)
[email protected]d5f942ba2008-09-26 19:30:3438 : type_(type),
initial.commit09911bf2008-07-26 23:55:2939 delegate_(NULL),
40 controller_(NULL),
[email protected]d5f942ba2008-09-26 19:30:3441 is_loading_(false),
42 is_active_(true),
initial.commit09911bf2008-07-26 23:55:2943 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:3444 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:3445 shelf_visible_(false),
46 max_page_id_(-1),
[email protected]d6598c052008-11-05 19:03:2547 blocked_popups_(NULL),
[email protected]2d843e62008-11-26 21:16:3548 capturing_contents_(false),
49 is_being_destroyed_(false) {
initial.commit09911bf2008-07-26 23:55:2950 last_focused_view_storage_id_ =
[email protected]c2dacc92008-10-16 23:51:3851 views::ViewStorage::GetSharedInstance()->CreateStorageID();
initial.commit09911bf2008-07-26 23:55:2952}
53
54TabContents::~TabContents() {
55 // Makes sure to remove any stored view we may still have in the ViewStorage.
56 //
57 // It is possible the view went away before us, so we only do this if the
58 // view is registered.
[email protected]c2dacc92008-10-16 23:51:3859 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
initial.commit09911bf2008-07-26 23:55:2960 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
61 view_storage->RemoveView(last_focused_view_storage_id_);
62}
63
[email protected]d5f942ba2008-09-26 19:30:3464// static
65void TabContents::RegisterUserPrefs(PrefService* prefs) {
66 prefs->RegisterBooleanPref(prefs::kBlockPopups, false);
initial.commit09911bf2008-07-26 23:55:2967}
68
initial.commit09911bf2008-07-26 23:55:2969void TabContents::CloseContents() {
70 // Destroy our NavigationController, which will Destroy all tabs it owns.
71 controller_->Destroy();
72 // Note that the controller may have deleted us at this point,
73 // so don't touch any member variables here.
74}
75
76void TabContents::Destroy() {
[email protected]9501428d2008-11-27 01:44:4477 DCHECK(!is_being_destroyed_);
[email protected]2d843e62008-11-26 21:16:3578 is_being_destroyed_ = true;
79
initial.commit09911bf2008-07-26 23:55:2980 // First cleanly close all child windows.
81 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
82 // some of these to close. CloseWindows is async, so it might get called
83 // twice before it runs.
84 int size = static_cast<int>(child_windows_.size());
85 for (int i = size - 1; i >= 0; --i) {
86 ConstrainedWindow* window = child_windows_[i];
87 if (window)
88 window->CloseConstrainedWindow();
89 }
90
91 // Notify any observer that have a reference on this tab contents.
92 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_DESTROYED,
93 Source<TabContents>(this),
94 NotificationService::NoDetails());
95
96 // If we still have a window handle, destroy it. GetContainerHWND can return
97 // NULL if this contents was part of a window that closed.
98 if (GetContainerHWND())
99 ::DestroyWindow(GetContainerHWND());
100
101 // Notify our NavigationController. Make sure we are deleted first, so
102 // that the controller is the last to die.
103 NavigationController* controller = controller_;
104 TabContentsType type = this->type();
105
106 delete this;
107
108 controller->TabContentsWasDestroyed(type);
109}
110
[email protected]d5f942ba2008-09-26 19:30:34111void TabContents::SetupController(Profile* profile) {
112 DCHECK(!controller_);
113 controller_ = new NavigationController(this, profile);
114}
115
116bool TabContents::SupportsURL(GURL* url) {
117 GURL u(*url);
118 if (TabContents::TypeForURL(&u) == type()) {
119 *url = u;
120 return true;
121 }
122 return false;
123}
124
125const GURL& TabContents::GetURL() const {
126 // We may not have a navigation entry yet
127 NavigationEntry* entry = controller_->GetActiveEntry();
128 return entry ? entry->display_url() : GURL::EmptyGURL();
129}
130
131const std::wstring& TabContents::GetTitle() const {
[email protected]cbab76d2008-10-13 22:42:47132 // We use the title for the last committed entry rather than a pending
133 // navigation entry. For example, when the user types in a URL, we want to
134 // keep the old page's title until the new load has committed and we get a new
135 // title.
136 // The exception is with transient pages, for which we really want to use
137 // their title, as they are not committed.
138 NavigationEntry* entry = controller_->GetTransientEntry();
[email protected]3d627bbc2008-10-23 20:49:07139 if (entry)
140 return entry->GetTitleForDisplay();
[email protected]cbab76d2008-10-13 22:42:47141
142 entry = controller_->GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34143 if (entry)
[email protected]3d627bbc2008-10-23 20:49:07144 return entry->GetTitleForDisplay();
[email protected]d5f942ba2008-09-26 19:30:34145 else if (controller_->LoadingURLLazily())
146 return controller_->GetLazyTitle();
147 return EmptyWString();
148}
149
150int32 TabContents::GetMaxPageID() {
151 if (GetSiteInstance())
152 return GetSiteInstance()->max_page_id();
153 else
154 return max_page_id_;
155}
156
157void TabContents::UpdateMaxPageID(int32 page_id) {
158 // Ensure both the SiteInstance and RenderProcessHost update their max page
159 // IDs in sync. Only WebContents will also have site instances, except during
160 // testing.
161 if (GetSiteInstance())
162 GetSiteInstance()->UpdateMaxPageID(page_id);
163
164 if (AsWebContents())
165 AsWebContents()->process()->UpdateMaxPageID(page_id);
166 else
167 max_page_id_ = std::max(max_page_id_, page_id);
168}
169
170const std::wstring TabContents::GetDefaultTitle() const {
171 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
172}
173
174SkBitmap TabContents::GetFavIcon() const {
175 // Like GetTitle(), we also want to use the favicon for the last committed
176 // entry rather than a pending navigation entry.
[email protected]cbab76d2008-10-13 22:42:47177 NavigationEntry* entry = controller_->GetTransientEntry();
178 if (entry)
179 return entry->favicon().bitmap();
180
181 entry = controller_->GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34182 if (entry)
183 return entry->favicon().bitmap();
184 else if (controller_->LoadingURLLazily())
185 return controller_->GetLazyFavIcon();
186 return SkBitmap();
187}
188
189SecurityStyle TabContents::GetSecurityStyle() const {
190 // We may not have a navigation entry yet.
191 NavigationEntry* entry = controller_->GetActiveEntry();
192 return entry ? entry->ssl().security_style() : SECURITY_STYLE_UNKNOWN;
193}
194
195bool TabContents::GetSSLEVText(std::wstring* ev_text,
196 std::wstring* ev_tooltip_text) const {
197 DCHECK(ev_text && ev_tooltip_text);
198 ev_text->clear();
199 ev_tooltip_text->clear();
200
201 NavigationEntry* entry = controller_->GetActiveEntry();
202 if (!entry ||
203 net::IsCertStatusError(entry->ssl().cert_status()) ||
204 ((entry->ssl().cert_status() & net::CERT_STATUS_IS_EV) == 0))
205 return false;
206
207 scoped_refptr<net::X509Certificate> cert;
208 CertStore::GetSharedInstance()->RetrieveCert(entry->ssl().cert_id(), &cert);
209 if (!cert.get()) {
210 NOTREACHED();
211 return false;
212 }
213
214 return SSLManager::GetEVCertNames(*cert, ev_text, ev_tooltip_text);
215}
216
217void TabContents::SetIsCrashed(bool state) {
218 if (state == is_crashed_)
219 return;
220
221 is_crashed_ = state;
222 if (delegate_)
223 delegate_->ContentsStateChanged(this);
224}
225
226void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
227 if (delegate_)
228 delegate_->NavigationStateChanged(this, changed_flags);
229}
230
231void TabContents::DidBecomeSelected() {
232 if (controller_)
233 controller_->SetActive(true);
234
235 // Invalidate all descendants. (take care to exclude invalidating ourselves!)
236 EnumChildWindows(GetContainerHWND(), InvalidateWindow, 0);
237}
238
239void TabContents::WasHidden() {
240 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_HIDDEN,
241 Source<TabContents>(this),
242 NotificationService::NoDetails());
243}
244
245void TabContents::Activate() {
246 if (delegate_)
247 delegate_->ActivateContents(this);
248}
249
[email protected]c0588052008-10-27 23:01:50250void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34251 WindowOpenDisposition disposition,
252 PageTransition::Type transition) {
253 if (delegate_)
[email protected]c0588052008-10-27 23:01:50254 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34255}
256
257bool TabContents::NavigateToPendingEntry(bool reload) {
258 // Our benavior is just to report that the entry was committed.
259 controller()->GetPendingEntry()->set_title(GetDefaultTitle());
260 controller()->CommitPendingEntry();
261 return true;
262}
263
initial.commit09911bf2008-07-26 23:55:29264ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]c2dacc92008-10-16 23:51:38265 views::WindowDelegate* window_delegate,
266 views::View* contents_view) {
initial.commit09911bf2008-07-26 23:55:29267 ConstrainedWindow* window =
268 ConstrainedWindow::CreateConstrainedDialog(
269 this, gfx::Rect(), contents_view, window_delegate);
270 child_windows_.push_back(window);
271 return window;
272}
273
274void TabContents::AddNewContents(TabContents* new_contents,
275 WindowOpenDisposition disposition,
276 const gfx::Rect& initial_pos,
277 bool user_gesture) {
278 if (!delegate_)
279 return;
280
[email protected]3b0a45e82008-10-13 21:01:03281 if ((disposition == NEW_POPUP) && !user_gesture) {
282 // Unrequested popups from normal pages are constrained.
283 TabContents* popup_owner = this;
284 TabContents* our_owner = delegate_->GetConstrainingContents(this);
285 if (our_owner)
286 popup_owner = our_owner;
287 popup_owner->AddConstrainedPopup(new_contents, initial_pos);
initial.commit09911bf2008-07-26 23:55:29288 } else {
[email protected]0aa55312008-10-17 21:53:08289 new_contents->DisassociateFromPopupCount();
290
initial.commit09911bf2008-07-26 23:55:29291 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
292 user_gesture);
[email protected]634a6f92008-12-01 21:39:31293
294 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29295 }
296}
297
298void TabContents::AddConstrainedPopup(TabContents* new_contents,
299 const gfx::Rect& initial_pos) {
[email protected]d6598c052008-11-05 19:03:25300 if (!blocked_popups_) {
301 CRect client_rect;
302 GetClientRect(GetContainerHWND(), &client_rect);
303 gfx::Point anchor_position(
304 client_rect.Width() -
305 views::NativeScrollBar::GetVerticalScrollBarWidth(),
306 client_rect.Height());
initial.commit09911bf2008-07-26 23:55:29307
[email protected]d6598c052008-11-05 19:03:25308 blocked_popups_ = BlockedPopupContainer::Create(
309 this, profile(), anchor_position);
310 child_windows_.push_back(blocked_popups_);
311 }
312
313 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]634a6f92008-12-01 21:39:31314 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29315}
316
initial.commit09911bf2008-07-26 23:55:29317void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25318 if (blocked_popups_)
319 blocked_popups_->CloseAllPopups();
initial.commit09911bf2008-07-26 23:55:29320}
321
initial.commit09911bf2008-07-26 23:55:29322void TabContents::Focus() {
[email protected]be3877f2009-01-14 15:51:10323 HWND container_hwnd = GetContainerHWND();
324 if (!container_hwnd)
325 return;
326
[email protected]c2dacc92008-10-16 23:51:38327 views::FocusManager* focus_manager =
[email protected]be3877f2009-01-14 15:51:10328 views::FocusManager::GetFocusManager(container_hwnd);
initial.commit09911bf2008-07-26 23:55:29329 DCHECK(focus_manager);
[email protected]be3877f2009-01-14 15:51:10330 views::View* v = focus_manager->GetViewForWindow(container_hwnd, true);
initial.commit09911bf2008-07-26 23:55:29331 DCHECK(v);
332 if (v)
333 v->RequestFocus();
334}
335
336void TabContents::StoreFocus() {
[email protected]c2dacc92008-10-16 23:51:38337 views::ViewStorage* view_storage =
338 views::ViewStorage::GetSharedInstance();
initial.commit09911bf2008-07-26 23:55:29339
340 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
341 view_storage->RemoveView(last_focused_view_storage_id_);
342
[email protected]c2dacc92008-10-16 23:51:38343 views::FocusManager* focus_manager =
344 views::FocusManager::GetFocusManager(GetContainerHWND());
initial.commit09911bf2008-07-26 23:55:29345 if (focus_manager) {
346 // |focus_manager| can be NULL if the tab has been detached but still
347 // exists.
[email protected]c2dacc92008-10-16 23:51:38348 views::View* focused_view = focus_manager->GetFocusedView();
initial.commit09911bf2008-07-26 23:55:29349 if (focused_view)
350 view_storage->StoreView(last_focused_view_storage_id_, focused_view);
351
352 // If the focus was on the page, explicitly clear the focus so that we
353 // don't end up with the focused HWND not part of the window hierarchy.
[email protected]c80c5632008-10-10 20:34:35354 // TODO(brettw) this should move to the view somehow.
initial.commit09911bf2008-07-26 23:55:29355 HWND container_hwnd = GetContainerHWND();
356 if (container_hwnd) {
[email protected]c2dacc92008-10-16 23:51:38357 views::View* focused_view = focus_manager->GetFocusedView();
initial.commit09911bf2008-07-26 23:55:29358 if (focused_view) {
[email protected]a0dde122008-11-21 20:51:20359 HWND hwnd = focused_view->GetRootView()->GetWidget()->GetHWND();
initial.commit09911bf2008-07-26 23:55:29360 if (container_hwnd == hwnd || ::IsChild(container_hwnd, hwnd))
361 focus_manager->ClearFocus();
362 }
363 }
364 }
365}
366
367void TabContents::RestoreFocus() {
[email protected]c2dacc92008-10-16 23:51:38368 views::ViewStorage* view_storage =
369 views::ViewStorage::GetSharedInstance();
370 views::View* last_focused_view =
initial.commit09911bf2008-07-26 23:55:29371 view_storage->RetrieveView(last_focused_view_storage_id_);
372
373 if (!last_focused_view) {
374 SetInitialFocus();
375 } else {
[email protected]c2dacc92008-10-16 23:51:38376 views::FocusManager* focus_manager =
377 views::FocusManager::GetFocusManager(GetContainerHWND());
[email protected]6e2f2cec2008-09-23 22:59:06378
379 // If you hit this DCHECK, please report it to Jay (jcampan).
380 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus.";
381
382 if (focus_manager && focus_manager->ContainsView(last_focused_view)) {
initial.commit09911bf2008-07-26 23:55:29383 last_focused_view->RequestFocus();
384 } else {
385 // The focused view may not belong to the same window hierarchy (for
386 // example if the location bar was focused and the tab is dragged out).
387 // In that case we default to the default focus.
388 SetInitialFocus();
389 }
390 view_storage->RemoveView(last_focused_view_storage_id_);
391 }
392}
393
[email protected]d5f942ba2008-09-26 19:30:34394void TabContents::SetInitialFocus() {
395 ::SetFocus(GetContainerHWND());
initial.commit09911bf2008-07-26 23:55:29396}
397
[email protected]616ed5a2008-11-21 22:27:24398void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
399 // Look through the existing InfoBarDelegates we have for a match. If we've
400 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05401 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24402 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
403 return;
404 }
405
406 infobar_delegates_.push_back(delegate);
407 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_INFOBAR_ADDED,
408 Source<TabContents>(this),
409 Details<InfoBarDelegate>(delegate));
410
411 // Add ourselves as an observer for navigations the first time a delegate is
412 // added. We use this notification to expire InfoBars that need to expire on
413 // page transitions.
414 if (infobar_delegates_.size() == 1) {
[email protected]6a02963e2009-01-06 16:58:03415 DCHECK(controller());
416 registrar_.Add(this, NOTIFY_NAV_ENTRY_COMMITTED,
417 Source<NavigationController>(controller()));
[email protected]616ed5a2008-11-21 22:27:24418 }
419}
420
421void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
422 std::vector<InfoBarDelegate*>::iterator it =
423 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
424 if (it != infobar_delegates_.end()) {
425 InfoBarDelegate* delegate = *it;
[email protected]616ed5a2008-11-21 22:27:24426 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_INFOBAR_REMOVED,
427 Source<TabContents>(this),
428 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05429 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24430
[email protected]6a02963e2009-01-06 16:58:03431 // Remove ourselves as an observer if we are tracking no more InfoBars.
432 if (infobar_delegates_.empty()) {
433 registrar_.Remove(this, NOTIFY_NAV_ENTRY_COMMITTED,
434 Source<NavigationController>(controller()));
435 }
[email protected]616ed5a2008-11-21 22:27:24436 }
437}
438
initial.commit09911bf2008-07-26 23:55:29439void TabContents::SetDownloadShelfVisible(bool visible) {
440 if (shelf_visible_ != visible) {
441 if (visible) {
442 // Invoke GetDownloadShelfView to force the shelf to be created.
443 GetDownloadShelfView();
444 }
445 shelf_visible_ = visible;
446
[email protected]019d83502008-07-30 22:44:50447 if (delegate_)
448 delegate_->ContentsStateChanged(this);
initial.commit09911bf2008-07-26 23:55:29449 }
[email protected]ce2390b682008-08-08 22:24:51450
451 // SetShelfVisible can force-close the shelf, so make sure we lay out
452 // everything correctly, as if the animation had finished. This doesn't
453 // matter for showing the shelf, as the show animation will do it.
454 ToolbarSizeChanged(false);
initial.commit09911bf2008-07-26 23:55:29455}
456
initial.commit09911bf2008-07-26 23:55:29457void TabContents::ToolbarSizeChanged(bool is_animating) {
458 TabContentsDelegate* d = delegate();
459 if (d)
460 d->ToolbarSizeChanged(this, is_animating);
461}
462
[email protected]d5f942ba2008-09-26 19:30:34463void TabContents::OnStartDownload(DownloadItem* download) {
464 DCHECK(download);
465 TabContents* tab_contents = this;
466
467 // Download in a constrained popup is shown in the tab that opened it.
468 TabContents* constraining_tab = delegate()->GetConstrainingContents(this);
469 if (constraining_tab)
470 tab_contents = constraining_tab;
471
472 // GetDownloadShelfView creates the download shelf if it was not yet created.
473 tab_contents->GetDownloadShelfView()->AddDownload(download);
474 tab_contents->SetDownloadShelfVisible(true);
475
476 // This animation will delete itself when it finishes, or if we become hidden
477 // or destroyed.
478 if (IsWindowVisible(GetContainerHWND())) { // For minimized windows, unit
479 // tests, etc.
480 new DownloadStartedAnimation(tab_contents);
481 }
482}
483
initial.commit09911bf2008-07-26 23:55:29484DownloadShelfView* TabContents::GetDownloadShelfView() {
485 if (!download_shelf_view_.get()) {
486 download_shelf_view_.reset(new DownloadShelfView(this));
487 // The TabContents owns the download-shelf.
488 download_shelf_view_->SetParentOwned(false);
489 }
490 return download_shelf_view_.get();
491}
492
493void TabContents::MigrateShelfViewFrom(TabContents* tab_contents) {
494 download_shelf_view_.reset(tab_contents->GetDownloadShelfView());
495 download_shelf_view_->ChangeTabContents(tab_contents, this);
496 tab_contents->ReleaseDownloadShelfView();
497}
498
[email protected]d5f942ba2008-09-26 19:30:34499void TabContents::WillClose(ConstrainedWindow* window) {
500 ConstrainedWindowList::iterator it =
501 find(child_windows_.begin(), child_windows_.end(), window);
502 if (it != child_windows_.end())
503 child_windows_.erase(it);
504
[email protected]d6598c052008-11-05 19:03:25505 if (window == blocked_popups_)
506 blocked_popups_ = NULL;
507
[email protected]d5f942ba2008-09-26 19:30:34508 if (::IsWindow(GetContainerHWND())) {
509 CRect client_rect;
510 GetClientRect(GetContainerHWND(), &client_rect);
511 RepositionSupressedPopupsToFit(
512 gfx::Size(client_rect.Width(), client_rect.Height()));
513 }
514}
515
[email protected]d5f942ba2008-09-26 19:30:34516void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
517 UpdateWindow(GetContainerHWND());
518}
519
[email protected]616ed5a2008-11-21 22:27:24520void TabContents::Observe(NotificationType type,
521 const NotificationSource& source,
522 const NotificationDetails& details) {
523 DCHECK(type == NOTIFY_NAV_ENTRY_COMMITTED);
524 DCHECK(controller() == Source<NavigationController>(source).ptr());
525
526 NavigationController::LoadCommittedDetails& committed_details =
527 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
528 ExpireInfoBars(committed_details);
529}
530
initial.commit09911bf2008-07-26 23:55:29531// static
532void TabContents::MigrateShelfView(TabContents* from, TabContents* to) {
533 bool was_shelf_visible = from->IsDownloadShelfVisible();
534 if (was_shelf_visible)
535 to->MigrateShelfViewFrom(from);
536 to->SetDownloadShelfVisible(was_shelf_visible);
537}
538
[email protected]d5f942ba2008-09-26 19:30:34539void TabContents::SetIsLoading(bool is_loading,
540 LoadNotificationDetails* details) {
541 if (is_loading == is_loading_)
542 return;
543
544 is_loading_ = is_loading;
545 waiting_for_response_ = is_loading;
546
547 // Suppress notifications for this TabContents if we are not active.
548 if (!is_active_)
549 return;
550
551 if (delegate_)
552 delegate_->LoadingStateChanged(this);
553
554 NotificationService::current()->
555 Notify((is_loading ? NOTIFY_LOAD_START : NOTIFY_LOAD_STOP),
556 Source<NavigationController>(this->controller()),
557 details ? Details<LoadNotificationDetails>(details) :
558 NotificationService::NoDetails());
initial.commit09911bf2008-07-26 23:55:29559}
license.botbf09a502008-08-24 00:55:55560
[email protected]9e0534b2008-10-21 15:03:01561// TODO(brettw) This should be on the WebContentsView.
[email protected]d5f942ba2008-09-26 19:30:34562void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) {
563 // TODO(erg): There's no way to detect whether scroll bars are
564 // visible, so for beta, we're just going to assume that the
565 // vertical scroll bar is visible, and not care about covering up
566 // the horizontal scroll bar. Fixing this is half of
567 // http://b/1118139.
568 gfx::Point anchor_position(
569 new_size.width() -
[email protected]c2dacc92008-10-16 23:51:38570 views::NativeScrollBar::GetVerticalScrollBarWidth(),
[email protected]d5f942ba2008-09-26 19:30:34571 new_size.height());
[email protected]d6598c052008-11-05 19:03:25572
573 if (blocked_popups_)
574 blocked_popups_->RepositionConstrainedWindowTo(anchor_position);
[email protected]d5f942ba2008-09-26 19:30:34575}
576
577void TabContents::ReleaseDownloadShelfView() {
578 download_shelf_view_.release();
579}
[email protected]b9681312008-11-07 00:08:26580
581bool TabContents::ShowingBlockedPopupNotification() const {
582 return blocked_popups_ != NULL &&
583 blocked_popups_->GetTabContentsCount() != 0;
584}
[email protected]616ed5a2008-11-21 22:27:24585
586namespace {
587bool TransitionIsReload(PageTransition::Type transition) {
588 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
589}
590}
591
592void TabContents::ExpireInfoBars(
593 const NavigationController::LoadCommittedDetails& details) {
594 // Only hide InfoBars when the user has done something that makes the main
595 // frame load. We don't want various automatic or subframe navigations making
596 // it disappear.
597 if (!details.is_user_initiated_main_frame_load())
598 return;
599
[email protected]f86a07022008-11-25 01:06:05600 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:24601 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:05602 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:24603 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:24604 }
605}