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

Side by Side Diff: chrome/browser/infobars/infobar_delegate.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/infobars/infobar_delegate.h" 5 #include "chrome/browser/infobars/infobar_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/infobars/infobar.h"
9 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
10 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 16
16 using content::NavigationEntry; 17 using content::NavigationEntry;
17 18
18 // InfoBarDelegate ------------------------------------------------------------ 19 // InfoBarDelegate ------------------------------------------------------------
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 88 }
88 89
89 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() { 90 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
90 return NULL; 91 return NULL;
91 } 92 }
92 93
93 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { 94 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() {
94 return NULL; 95 return NULL;
95 } 96 }
96 97
98 void InfoBarDelegate::StoreActiveEntryUniqueID() {
99 DCHECK(web_contents());
100 NavigationEntry* active_entry =
101 web_contents()->GetController().GetActiveEntry();
102 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0;
103 }
104
97 gfx::Image InfoBarDelegate::GetIcon() const { 105 gfx::Image InfoBarDelegate::GetIcon() const {
98 int icon_id = GetIconID(); 106 int icon_id = GetIconID();
99 return (icon_id == kNoIconID) ? gfx::Image() : 107 return (icon_id == kNoIconID) ? gfx::Image() :
100 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); 108 ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id);
101 } 109 }
102 110
103 InfoBarDelegate::InfoBarDelegate(InfoBarService* owner) 111 content::WebContents* InfoBarDelegate::web_contents() {
104 : contents_unique_id_(0), 112 return infobar_->owner() ? infobar_->owner()->web_contents() : NULL;
105 owner_(owner) {
106 if (owner_)
107 StoreActiveEntryUniqueID();
108 } 113 }
109 114
110 void InfoBarDelegate::StoreActiveEntryUniqueID() { 115 InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) {
111 DCHECK(web_contents());
112 NavigationEntry* active_entry =
113 web_contents()->GetController().GetActiveEntry();
114 contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0;
115 } 116 }
116 117
117 bool InfoBarDelegate::ShouldExpireInternal( 118 bool InfoBarDelegate::ShouldExpireInternal(
118 const content::LoadCommittedDetails& details) const { 119 const content::LoadCommittedDetails& details) const {
119 // NOTE: If you change this, be sure to check and adjust the behavior of 120 // NOTE: If you change this, be sure to check and adjust the behavior of
120 // anyone who overrides this as necessary! 121 // anyone who overrides this as necessary!
121 return (contents_unique_id_ != details.entry->GetUniqueID()) || 122 return (contents_unique_id_ != details.entry->GetUniqueID()) ||
122 (content::PageTransitionStripQualifier( 123 (content::PageTransitionStripQualifier(
123 details.entry->GetTransitionType()) == 124 details.entry->GetTransitionType()) ==
124 content::PAGE_TRANSITION_RELOAD); 125 content::PAGE_TRANSITION_RELOAD);
125 } 126 }
126
127 void InfoBarDelegate::RemoveSelf() {
128 if (owner_)
129 owner_->RemoveInfoBar(this); // Clears |owner_|.
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698