| OLD | NEW |
| 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 if (infobar_delegates_[i]->EqualsDelegate(delegate)) { | 454 if (infobar_delegates_[i]->EqualsDelegate(delegate)) { |
| 455 // Tell the new infobar to close so that it can clean itself up. | 455 // Tell the new infobar to close so that it can clean itself up. |
| 456 delegate->InfoBarClosed(); | 456 delegate->InfoBarClosed(); |
| 457 return; | 457 return; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 infobar_delegates_.push_back(delegate); | 461 infobar_delegates_.push_back(delegate); |
| 462 NotificationService::current()->Notify( | 462 NotificationService::current()->Notify( |
| 463 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, | 463 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, |
| 464 Source<TabContents>(tab_contents_.get()), | 464 Source<TabContentsWrapper>(this), |
| 465 Details<InfoBarDelegate>(delegate)); | 465 Details<InfoBar>(delegate->CreateInfoBar(this))); |
| 466 | 466 |
| 467 // Add ourselves as an observer for navigations the first time a delegate is | 467 // Add ourselves as an observer for navigations the first time a delegate is |
| 468 // added. We use this notification to expire InfoBars that need to expire on | 468 // added. We use this notification to expire InfoBars that need to expire on |
| 469 // page transitions. | 469 // page transitions. |
| 470 if (infobar_delegates_.size() == 1) { | 470 if (infobar_delegates_.size() == 1) { |
| 471 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 471 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 472 Source<NavigationController>(&tab_contents_->controller())); | 472 Source<NavigationController>(&tab_contents_->controller())); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { | 476 void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { |
| 477 if (!infobars_enabled_) | 477 if (!infobars_enabled_) |
| 478 return; | 478 return; |
| 479 | 479 |
| 480 std::vector<InfoBarDelegate*>::iterator it = | 480 std::vector<InfoBarDelegate*>::iterator it = |
| 481 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); | 481 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
| 482 if (it != infobar_delegates_.end()) { | 482 if (it != infobar_delegates_.end()) { |
| 483 InfoBarDelegate* delegate = *it; | 483 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; |
| 484 RemoveDetails remove_details(*it, true); |
| 484 NotificationService::current()->Notify( | 485 NotificationService::current()->Notify( |
| 485 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 486 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 486 Source<TabContents>(tab_contents_.get()), | 487 Source<TabContentsWrapper>(this), |
| 487 Details<InfoBarDelegate>(delegate)); | 488 Details<RemoveDetails>(&remove_details)); |
| 488 | 489 |
| 489 infobar_delegates_.erase(it); | 490 infobar_delegates_.erase(it); |
| 490 // Remove ourselves as an observer if we are tracking no more InfoBars. | 491 // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 491 if (infobar_delegates_.empty()) { | 492 if (infobar_delegates_.empty()) { |
| 492 registrar_.Remove( | 493 registrar_.Remove( |
| 493 this, NotificationType::NAV_ENTRY_COMMITTED, | 494 this, NotificationType::NAV_ENTRY_COMMITTED, |
| 494 Source<NavigationController>(&tab_contents_->controller())); | 495 Source<NavigationController>(&tab_contents_->controller())); |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 } | 498 } |
| 498 | 499 |
| 499 void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, | 500 void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
| 500 InfoBarDelegate* new_delegate) { | 501 InfoBarDelegate* new_delegate) { |
| 501 if (!infobars_enabled_) { | 502 if (!infobars_enabled_) { |
| 502 new_delegate->InfoBarClosed(); | 503 new_delegate->InfoBarClosed(); |
| 503 return; | 504 return; |
| 504 } | 505 } |
| 505 | 506 |
| 506 std::vector<InfoBarDelegate*>::iterator it = | 507 std::vector<InfoBarDelegate*>::iterator it = |
| 507 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); | 508 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
| 508 DCHECK(it != infobar_delegates_.end()); | 509 DCHECK(it != infobar_delegates_.end()); |
| 509 | 510 |
| 510 // Notify the container about the change of plans. | 511 // Notify the container about the change of plans. |
| 511 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( | 512 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails; |
| 512 new std::pair<InfoBarDelegate*, InfoBarDelegate*>( | 513 ReplaceDetails replace_details(old_delegate, |
| 513 old_delegate, new_delegate)); | 514 new_delegate->CreateInfoBar(this)); |
| 514 NotificationService::current()->Notify( | 515 NotificationService::current()->Notify( |
| 515 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | 516 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
| 516 Source<TabContents>(tab_contents_.get()), | 517 Source<TabContentsWrapper>(this), |
| 517 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); | 518 Details<ReplaceDetails>(&replace_details)); |
| 518 | 519 |
| 519 // Remove the old one. | 520 // Remove the old one. |
| 520 infobar_delegates_.erase(it); | 521 infobar_delegates_.erase(it); |
| 521 | 522 |
| 522 // Add the new one. | 523 // Add the new one. |
| 523 DCHECK(find(infobar_delegates_.begin(), | 524 DCHECK(find(infobar_delegates_.begin(), |
| 524 infobar_delegates_.end(), new_delegate) == | 525 infobar_delegates_.end(), new_delegate) == |
| 525 infobar_delegates_.end()); | 526 infobar_delegates_.end()); |
| 526 infobar_delegates_.push_back(new_delegate); | 527 infobar_delegates_.push_back(new_delegate); |
| 527 } | 528 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 void TabContentsWrapper::UpdateWebPreferences() { | 592 void TabContentsWrapper::UpdateWebPreferences() { |
| 592 RenderViewHostDelegate* rvhd = tab_contents(); | 593 RenderViewHostDelegate* rvhd = tab_contents(); |
| 593 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); | 594 Send(new ViewMsg_UpdateWebPreferences(routing_id(), rvhd->GetWebkitPrefs())); |
| 594 } | 595 } |
| 595 | 596 |
| 596 void TabContentsWrapper::UpdateRendererPreferences() { | 597 void TabContentsWrapper::UpdateRendererPreferences() { |
| 597 renderer_preferences_util::UpdateFromSystemSettings( | 598 renderer_preferences_util::UpdateFromSystemSettings( |
| 598 tab_contents()->GetMutableRendererPrefs(), profile()); | 599 tab_contents()->GetMutableRendererPrefs(), profile()); |
| 599 render_view_host()->SyncRendererPrefs(); | 600 render_view_host()->SyncRendererPrefs(); |
| 600 } | 601 } |
| OLD | NEW |