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

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

Issue 7006010: Change InfoBar-related notifications to be sourced from a TabContentsWrapper, not a TabContents. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/tab_contents/tab_contents_wrapper.h" 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "chrome/browser/autocomplete_history_manager.h" 9 #include "chrome/browser/autocomplete_history_manager.h"
10 #include "chrome/browser/autofill/autofill_manager.h" 10 #include "chrome/browser/autofill/autofill_manager.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (infobar_delegates_[i]->EqualsDelegate(delegate)) { 444 if (infobar_delegates_[i]->EqualsDelegate(delegate)) {
445 // Tell the new infobar to close so that it can clean itself up. 445 // Tell the new infobar to close so that it can clean itself up.
446 delegate->InfoBarClosed(); 446 delegate->InfoBarClosed();
447 return; 447 return;
448 } 448 }
449 } 449 }
450 450
451 infobar_delegates_.push_back(delegate); 451 infobar_delegates_.push_back(delegate);
452 NotificationService::current()->Notify( 452 NotificationService::current()->Notify(
453 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, 453 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
454 Source<TabContents>(tab_contents_.get()), 454 Source<TabContentsWrapper>(this),
455 Details<InfoBarDelegate>(delegate)); 455 Details<InfoBar>(delegate->CreateInfoBar(this)));
456 456
457 // Add ourselves as an observer for navigations the first time a delegate is 457 // Add ourselves as an observer for navigations the first time a delegate is
458 // added. We use this notification to expire InfoBars that need to expire on 458 // added. We use this notification to expire InfoBars that need to expire on
459 // page transitions. 459 // page transitions.
460 if (infobar_delegates_.size() == 1) { 460 if (infobar_delegates_.size() == 1) {
461 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 461 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
462 Source<NavigationController>(&tab_contents_->controller())); 462 Source<NavigationController>(&tab_contents_->controller()));
463 } 463 }
464 } 464 }
465 465
466 void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { 466 void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) {
467 if (!infobars_enabled_) 467 if (!infobars_enabled_)
468 return; 468 return;
469 469
470 std::vector<InfoBarDelegate*>::iterator it = 470 std::vector<InfoBarDelegate*>::iterator it =
471 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); 471 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
472 if (it != infobar_delegates_.end()) { 472 if (it != infobar_delegates_.end()) {
473 InfoBarDelegate* delegate = *it; 473 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails;
474 RemoveDetails remove_details(*it, true);
474 NotificationService::current()->Notify( 475 NotificationService::current()->Notify(
475 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, 476 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
476 Source<TabContents>(tab_contents_.get()), 477 Source<TabContentsWrapper>(this),
477 Details<InfoBarDelegate>(delegate)); 478 Details<RemoveDetails>(&remove_details));
478 479
479 infobar_delegates_.erase(it); 480 infobar_delegates_.erase(it);
480 // Remove ourselves as an observer if we are tracking no more InfoBars. 481 // Remove ourselves as an observer if we are tracking no more InfoBars.
481 if (infobar_delegates_.empty()) { 482 if (infobar_delegates_.empty()) {
482 registrar_.Remove( 483 registrar_.Remove(
483 this, NotificationType::NAV_ENTRY_COMMITTED, 484 this, NotificationType::NAV_ENTRY_COMMITTED,
484 Source<NavigationController>(&tab_contents_->controller())); 485 Source<NavigationController>(&tab_contents_->controller()));
485 } 486 }
486 } 487 }
487 } 488 }
488 489
489 void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, 490 void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate,
490 InfoBarDelegate* new_delegate) { 491 InfoBarDelegate* new_delegate) {
491 if (!infobars_enabled_) { 492 if (!infobars_enabled_) {
492 new_delegate->InfoBarClosed(); 493 new_delegate->InfoBarClosed();
493 return; 494 return;
494 } 495 }
495 496
496 std::vector<InfoBarDelegate*>::iterator it = 497 std::vector<InfoBarDelegate*>::iterator it =
497 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); 498 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
498 DCHECK(it != infobar_delegates_.end()); 499 DCHECK(it != infobar_delegates_.end());
499 500
500 // Notify the container about the change of plans. 501 // Notify the container about the change of plans.
501 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( 502 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails;
502 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( 503 ReplaceDetails replace_details(old_delegate,
503 old_delegate, new_delegate)); 504 new_delegate->CreateInfoBar(this));
504 NotificationService::current()->Notify( 505 NotificationService::current()->Notify(
505 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, 506 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
506 Source<TabContents>(tab_contents_.get()), 507 Source<TabContentsWrapper>(this),
507 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); 508 Details<ReplaceDetails>(&replace_details));
508 509
509 // Remove the old one. 510 // Remove the old one.
510 infobar_delegates_.erase(it); 511 infobar_delegates_.erase(it);
511 512
512 // Add the new one. 513 // Add the new one.
513 DCHECK(find(infobar_delegates_.begin(), 514 DCHECK(find(infobar_delegates_.begin(),
514 infobar_delegates_.end(), new_delegate) == 515 infobar_delegates_.end(), new_delegate) ==
515 infobar_delegates_.end()); 516 infobar_delegates_.end());
516 infobar_delegates_.push_back(new_delegate); 517 infobar_delegates_.push_back(new_delegate);
517 } 518 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void TabContentsWrapper::UpdateWebPreferences() { 582 void TabContentsWrapper::UpdateWebPreferences() {
582 RenderViewHostDelegate* rvhd = tab_contents(); 583 RenderViewHostDelegate* rvhd = tab_contents();
583 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); 584 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs()));
584 } 585 }
585 586
586 void TabContentsWrapper::UpdateRendererPreferences() { 587 void TabContentsWrapper::UpdateRendererPreferences() {
587 renderer_preferences_util::UpdateFromSystemSettings( 588 renderer_preferences_util::UpdateFromSystemSettings(
588 tab_contents()->GetMutableRendererPrefs(), profile()); 589 tab_contents()->GetMutableRendererPrefs(), profile());
589 render_view_host()->SyncRendererPrefs(); 590 render_view_host()->SyncRendererPrefs();
590 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698