OLD | NEW |
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/extensions/app_notify_channel_ui_impl.h" | 5 #include "chrome/browser/extensions/app_notify_channel_ui_impl.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
9 #include "chrome/browser/api/infobars/infobar_service.h" | 9 #include "chrome/browser/api/infobars/infobar_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 class AppNotifyChannelUIImpl::InfoBar : public ConfirmInfoBarDelegate { | 32 namespace { |
| 33 |
| 34 class AppNotifyChannelUIInfoBarDelegate : public ConfirmInfoBarDelegate { |
33 public: | 35 public: |
34 InfoBar(AppNotifyChannelUIImpl* creator, | 36 AppNotifyChannelUIInfoBarDelegate(AppNotifyChannelUIImpl* creator, |
35 InfoBarService* infobar_service, | 37 InfoBarService* infobar_service, |
36 const std::string& app_name); | 38 const std::string& app_name); |
37 virtual ~InfoBar(); | 39 virtual ~AppNotifyChannelUIInfoBarDelegate(); |
38 | 40 |
39 // ConfirmInfoBarDelegate. | 41 // ConfirmInfoBarDelegate. |
40 virtual string16 GetMessageText() const OVERRIDE; | 42 virtual string16 GetMessageText() const OVERRIDE; |
41 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 43 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
42 virtual bool Accept() OVERRIDE; | 44 virtual bool Accept() OVERRIDE; |
43 virtual bool Cancel() OVERRIDE; | 45 virtual bool Cancel() OVERRIDE; |
44 virtual void InfoBarDismissed() OVERRIDE; | 46 virtual void InfoBarDismissed() OVERRIDE; |
45 | 47 |
46 private: | 48 private: |
47 AppNotifyChannelUIImpl* creator_; | 49 AppNotifyChannelUIImpl* creator_; |
48 std::string app_name_; | 50 std::string app_name_; |
49 | 51 |
50 DISALLOW_COPY_AND_ASSIGN(InfoBar); | 52 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIInfoBarDelegate); |
51 }; | 53 }; |
52 | 54 |
53 AppNotifyChannelUIImpl::InfoBar::InfoBar( | 55 AppNotifyChannelUIInfoBarDelegate::AppNotifyChannelUIInfoBarDelegate( |
54 AppNotifyChannelUIImpl* creator, | 56 AppNotifyChannelUIImpl* creator, |
55 InfoBarService* infobar_service, | 57 InfoBarService* infobar_service, |
56 const std::string& app_name) | 58 const std::string& app_name) |
57 : ConfirmInfoBarDelegate(infobar_service), | 59 : ConfirmInfoBarDelegate(infobar_service), |
58 creator_(creator), | 60 creator_(creator), |
59 app_name_(app_name) { | 61 app_name_(app_name) { |
60 } | 62 } |
61 | 63 |
62 AppNotifyChannelUIImpl::InfoBar::~InfoBar() {} | 64 AppNotifyChannelUIInfoBarDelegate::~AppNotifyChannelUIInfoBarDelegate() { |
| 65 } |
63 | 66 |
64 string16 AppNotifyChannelUIImpl::InfoBar::GetMessageText() const { | 67 string16 AppNotifyChannelUIInfoBarDelegate::GetMessageText() const { |
65 return l10n_util::GetStringFUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN, | 68 return l10n_util::GetStringFUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN, |
66 UTF8ToUTF16(app_name_)); | 69 UTF8ToUTF16(app_name_)); |
67 } | 70 } |
68 | 71 |
69 string16 AppNotifyChannelUIImpl::InfoBar::GetButtonLabel( | 72 string16 AppNotifyChannelUIInfoBarDelegate::GetButtonLabel( |
70 InfoBarButton button) const { | 73 InfoBarButton button) const { |
71 if (button == BUTTON_OK) { | 74 if (button == BUTTON_OK) { |
72 return l10n_util::GetStringUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN_ACCEPT); | 75 return l10n_util::GetStringUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN_ACCEPT); |
73 } else if (button == BUTTON_CANCEL) { | 76 } else if (button == BUTTON_CANCEL) { |
74 return l10n_util::GetStringUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN_CANCEL); | 77 return l10n_util::GetStringUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN_CANCEL); |
75 } else { | 78 } else { |
76 NOTREACHED(); | 79 NOTREACHED(); |
77 } | 80 } |
78 return string16(); | 81 return string16(); |
79 } | 82 } |
80 | 83 |
81 bool AppNotifyChannelUIImpl::InfoBar::Accept() { | 84 bool AppNotifyChannelUIInfoBarDelegate::Accept() { |
82 creator_->OnInfoBarResult(true); | 85 creator_->OnInfoBarResult(true); |
83 return true; | 86 return true; |
84 } | 87 } |
85 | 88 |
86 bool AppNotifyChannelUIImpl::InfoBar::Cancel() { | 89 bool AppNotifyChannelUIInfoBarDelegate::Cancel() { |
87 creator_->OnInfoBarResult(false); | 90 creator_->OnInfoBarResult(false); |
88 return true; | 91 return true; |
89 } | 92 } |
90 | 93 |
91 void AppNotifyChannelUIImpl::InfoBar::InfoBarDismissed() { | 94 void AppNotifyChannelUIInfoBarDelegate::InfoBarDismissed() { |
92 Cancel(); | 95 Cancel(); |
93 } | 96 } |
94 | 97 |
| 98 } // namespace |
| 99 |
95 | 100 |
96 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( | 101 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( |
97 Profile* profile, | 102 Profile* profile, |
98 content::WebContents* web_contents, | 103 content::WebContents* web_contents, |
99 const std::string& app_name, | 104 const std::string& app_name, |
100 AppNotifyChannelUI::UIType ui_type) | 105 AppNotifyChannelUI::UIType ui_type) |
101 : profile_(profile->GetOriginalProfile()), | 106 : profile_(profile->GetOriginalProfile()), |
102 web_contents_(web_contents), | 107 web_contents_(web_contents), |
103 app_name_(app_name), | 108 app_name_(app_name), |
104 ui_type_(ui_type), | 109 ui_type_(ui_type), |
(...skipping 27 matching lines...) Expand all Loading... |
132 return; | 137 return; |
133 } | 138 } |
134 | 139 |
135 if (ui_type_ == NO_INFOBAR) { | 140 if (ui_type_ == NO_INFOBAR) { |
136 OnInfoBarResult(true); | 141 OnInfoBarResult(true); |
137 return; | 142 return; |
138 } | 143 } |
139 | 144 |
140 InfoBarService* infobar_service = | 145 InfoBarService* infobar_service = |
141 InfoBarService::FromWebContents(web_contents_); | 146 InfoBarService::FromWebContents(web_contents_); |
142 infobar_service->AddInfoBar(new AppNotifyChannelUIImpl::InfoBar( | 147 infobar_service->AddInfoBar(new AppNotifyChannelUIInfoBarDelegate( |
143 this, infobar_service, app_name_)); | 148 this, infobar_service, app_name_)); |
144 } | 149 } |
145 | 150 |
146 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { | 151 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { |
147 if (!accepted) { | 152 if (!accepted) { |
148 delegate_->OnSyncSetupResult(false); | 153 delegate_->OnSyncSetupResult(false); |
149 return; | 154 return; |
150 } | 155 } |
151 | 156 |
152 StartObservingSync(); | 157 StartObservingSync(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 208 } |
204 | 209 |
205 void AppNotifyChannelUIImpl::StopObservingSync() { | 210 void AppNotifyChannelUIImpl::StopObservingSync() { |
206 CHECK(observing_sync_); | 211 CHECK(observing_sync_); |
207 observing_sync_ = false; | 212 observing_sync_ = false; |
208 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 213 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
209 profile_)->RemoveObserver(this); | 214 profile_)->RemoveObserver(this); |
210 } | 215 } |
211 | 216 |
212 } // namespace extensions | 217 } // namespace extensions |
OLD | NEW |