Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/tab_contents.cc

Issue 11318: Beginnings of a new InfoBar system. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents.h ('k') | chrome/browser/views/browser_views.vcproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/tab_contents.h" 5 #include "chrome/browser/tab_contents.h"
6 6
7 #include "chrome/browser/cert_store.h" 7 #include "chrome/browser/cert_store.h"
8 #include "chrome/browser/navigation_entry.h" 8 #include "chrome/browser/navigation_entry.h"
9 #include "chrome/browser/infobar_delegate.h"
9 #include "chrome/browser/views/download_shelf_view.h" 10 #include "chrome/browser/views/download_shelf_view.h"
10 #include "chrome/browser/views/download_started_animation.h" 11 #include "chrome/browser/views/download_started_animation.h"
11 #include "chrome/browser/views/blocked_popup_container.h" 12 #include "chrome/browser/views/blocked_popup_container.h"
12 #include "chrome/browser/web_contents.h" 13 #include "chrome/browser/web_contents.h"
13 #include "chrome/browser/tab_contents_delegate.h" 14 #include "chrome/browser/tab_contents_delegate.h"
14 #include "chrome/common/l10n_util.h" 15 #include "chrome/common/l10n_util.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/common/pref_service.h" 17 #include "chrome/common/pref_service.h"
17 #include "chrome/views/container.h" 18 #include "chrome/views/container.h"
18 #include "chrome/views/native_scroll_bar.h" 19 #include "chrome/views/native_scroll_bar.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 SetInitialFocus(); 380 SetInitialFocus();
380 } 381 }
381 view_storage->RemoveView(last_focused_view_storage_id_); 382 view_storage->RemoveView(last_focused_view_storage_id_);
382 } 383 }
383 } 384 }
384 385
385 void TabContents::SetInitialFocus() { 386 void TabContents::SetInitialFocus() {
386 ::SetFocus(GetContainerHWND()); 387 ::SetFocus(GetContainerHWND());
387 } 388 }
388 389
390 void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
391 // Look through the existing InfoBarDelegates we have for a match. If we've
392 // already got one that matches, then we don't add the new one.
393 for (size_t i = 0; i < infobar_delegate_count(); ++i) {
394 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
395 return;
396 }
397
398 infobar_delegates_.push_back(delegate);
399 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_INFOBAR_ADDED,
400 Source<TabContents>(this),
401 Details<InfoBarDelegate>(delegate));
402
403 // Add ourselves as an observer for navigations the first time a delegate is
404 // added. We use this notification to expire InfoBars that need to expire on
405 // page transitions.
406 if (infobar_delegates_.size() == 1) {
407 NotificationService::current()->AddObserver(
408 this, NOTIFY_NAV_ENTRY_COMMITTED,
409 Source<NavigationController>(controller()));
410 }
411 }
412
413 void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
414 std::vector<InfoBarDelegate*>::iterator it =
415 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
416 if (it != infobar_delegates_.end()) {
417 InfoBarDelegate* delegate = *it;
418 infobar_delegates_.erase(it);
419 NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_INFOBAR_REMOVED,
420 Source<TabContents>(this),
421 Details<InfoBarDelegate>(delegate));
422 }
423
424 // Remove ourselves as an observer if we are tracking no more InfoBars.
425 if (infobar_delegates_.empty()) {
426 NotificationService::current()->RemoveObserver(
427 this, NOTIFY_NAV_ENTRY_COMMITTED,
428 Source<NavigationController>(controller()));
429 }
430 }
431
389 void TabContents::SetDownloadShelfVisible(bool visible) { 432 void TabContents::SetDownloadShelfVisible(bool visible) {
390 if (shelf_visible_ != visible) { 433 if (shelf_visible_ != visible) {
391 if (visible) { 434 if (visible) {
392 // Invoke GetDownloadShelfView to force the shelf to be created. 435 // Invoke GetDownloadShelfView to force the shelf to be created.
393 GetDownloadShelfView(); 436 GetDownloadShelfView();
394 } 437 }
395 shelf_visible_ = visible; 438 shelf_visible_ = visible;
396 439
397 if (delegate_) 440 if (delegate_)
398 delegate_->ContentsStateChanged(this); 441 delegate_->ContentsStateChanged(this);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 GetClientRect(GetContainerHWND(), &client_rect); 503 GetClientRect(GetContainerHWND(), &client_rect);
461 RepositionSupressedPopupsToFit( 504 RepositionSupressedPopupsToFit(
462 gfx::Size(client_rect.Width(), client_rect.Height())); 505 gfx::Size(client_rect.Width(), client_rect.Height()));
463 } 506 }
464 } 507 }
465 508
466 void TabContents::DidMoveOrResize(ConstrainedWindow* window) { 509 void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
467 UpdateWindow(GetContainerHWND()); 510 UpdateWindow(GetContainerHWND());
468 } 511 }
469 512
513 void TabContents::Observe(NotificationType type,
514 const NotificationSource& source,
515 const NotificationDetails& details) {
516 DCHECK(type == NOTIFY_NAV_ENTRY_COMMITTED);
517 DCHECK(controller() == Source<NavigationController>(source).ptr());
518
519 NavigationController::LoadCommittedDetails& committed_details =
520 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
521 ExpireInfoBars(committed_details);
522 }
523
470 // static 524 // static
471 void TabContents::MigrateShelfView(TabContents* from, TabContents* to) { 525 void TabContents::MigrateShelfView(TabContents* from, TabContents* to) {
472 bool was_shelf_visible = from->IsDownloadShelfVisible(); 526 bool was_shelf_visible = from->IsDownloadShelfVisible();
473 if (was_shelf_visible) 527 if (was_shelf_visible)
474 to->MigrateShelfViewFrom(from); 528 to->MigrateShelfViewFrom(from);
475 to->SetDownloadShelfVisible(was_shelf_visible); 529 to->SetDownloadShelfVisible(was_shelf_visible);
476 } 530 }
477 531
478 void TabContents::SetIsLoading(bool is_loading, 532 void TabContents::SetIsLoading(bool is_loading,
479 LoadNotificationDetails* details) { 533 LoadNotificationDetails* details) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 568 }
515 569
516 void TabContents::ReleaseDownloadShelfView() { 570 void TabContents::ReleaseDownloadShelfView() {
517 download_shelf_view_.release(); 571 download_shelf_view_.release();
518 } 572 }
519 573
520 bool TabContents::ShowingBlockedPopupNotification() const { 574 bool TabContents::ShowingBlockedPopupNotification() const {
521 return blocked_popups_ != NULL && 575 return blocked_popups_ != NULL &&
522 blocked_popups_->GetTabContentsCount() != 0; 576 blocked_popups_->GetTabContentsCount() != 0;
523 } 577 }
578
579 namespace {
580 bool TransitionIsReload(PageTransition::Type transition) {
581 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
582 }
583 }
584
585 void TabContents::ExpireInfoBars(
586 const NavigationController::LoadCommittedDetails& details) {
587 // Only hide InfoBars when the user has done something that makes the main
588 // frame load. We don't want various automatic or subframe navigations making
589 // it disappear.
590 if (!details.is_user_initiated_main_frame_load())
591 return;
592
593 for (size_t i = 0; i < infobar_delegate_count(); ++i) {
594 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
595 if (!TransitionIsReload(details.entry->transition_type()) &&
596 delegate->ShouldCloseOnNavigate()) {
597 RemoveInfoBar(delegate);
598 }
599 }
600 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents.h ('k') | chrome/browser/views/browser_views.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698