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/notifications/notification_options_menu_model.h" | 5 #include "chrome/browser/notifications/notification_options_menu_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 NOTREACHED(); | 110 NOTREACHED(); |
111 } | 111 } |
112 | 112 |
113 NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) | 113 NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) |
114 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 114 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
115 balloon_(balloon) { | 115 balloon_(balloon) { |
116 const Notification& notification = balloon->notification(); | 116 const Notification& notification = balloon->notification(); |
117 const GURL& origin = notification.origin_url(); | 117 const GURL& origin = notification.origin_url(); |
118 | 118 |
119 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 119 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
120 ExtensionService* ext_service = | 120 ExtensionService* extension_service = |
121 balloon_->profile()->GetExtensionService(); | 121 balloon_->profile()->GetExtensionService(); |
122 const Extension* extension = ext_service->GetExtensionByURL(origin); | 122 const Extension* extension = |
| 123 extension_service->extensions()->GetExtensionOrAppByURL( |
| 124 ExtensionURLInfo(origin)); |
123 // We get back no extension here when we show the notification after | 125 // We get back no extension here when we show the notification after |
124 // the extension has crashed. | 126 // the extension has crashed. |
125 if (extension) { | 127 if (extension) { |
126 const string16 disable_label = l10n_util::GetStringUTF16( | 128 const string16 disable_label = l10n_util::GetStringUTF16( |
127 IDS_EXTENSIONS_DISABLE); | 129 IDS_EXTENSIONS_DISABLE); |
128 AddItem(kToggleExtensionCommand, disable_label); | 130 AddItem(kToggleExtensionCommand, disable_label); |
129 } | 131 } |
130 } else { | 132 } else { |
131 const string16 disable_label = l10n_util::GetStringFUTF16( | 133 const string16 disable_label = l10n_util::GetStringFUTF16( |
132 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, | 134 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, |
(...skipping 25 matching lines...) Expand all Loading... |
158 // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications | 160 // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications |
159 // after permissions are revoked. | 161 // after permissions are revoked. |
160 if (command_id == kTogglePermissionCommand || | 162 if (command_id == kTogglePermissionCommand || |
161 command_id == kToggleExtensionCommand) { | 163 command_id == kToggleExtensionCommand) { |
162 const Notification& notification = balloon_->notification(); | 164 const Notification& notification = balloon_->notification(); |
163 const GURL& origin = notification.origin_url(); | 165 const GURL& origin = notification.origin_url(); |
164 | 166 |
165 DesktopNotificationService* service = | 167 DesktopNotificationService* service = |
166 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); | 168 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); |
167 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 169 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
168 ExtensionService* ext_service = | 170 ExtensionService* extension_service = |
169 balloon_->profile()->GetExtensionService(); | 171 balloon_->profile()->GetExtensionService(); |
170 const Extension* extension = ext_service->GetExtensionByURL(origin); | 172 const Extension* extension = |
| 173 extension_service->extensions()->GetExtensionOrAppByURL( |
| 174 ExtensionURLInfo(origin)); |
171 if (extension) { | 175 if (extension) { |
172 return l10n_util::GetStringUTF16( | 176 return l10n_util::GetStringUTF16( |
173 ext_service->IsExtensionEnabled(extension->id()) ? | 177 extension_service->IsExtensionEnabled(extension->id()) ? |
174 IDS_EXTENSIONS_DISABLE : | 178 IDS_EXTENSIONS_DISABLE : |
175 IDS_EXTENSIONS_ENABLE); | 179 IDS_EXTENSIONS_ENABLE); |
176 } | 180 } |
177 } else { | 181 } else { |
178 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) { | 182 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) { |
179 return l10n_util::GetStringFUTF16( | 183 return l10n_util::GetStringFUTF16( |
180 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, | 184 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, |
181 notification.display_source()); | 185 notification.display_source()); |
182 } else { | 186 } else { |
183 return l10n_util::GetStringFUTF16( | 187 return l10n_util::GetStringFUTF16( |
(...skipping 21 matching lines...) Expand all Loading... |
205 | 209 |
206 bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( | 210 bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( |
207 int /* command_id */, ui::Accelerator* /* accelerator */) { | 211 int /* command_id */, ui::Accelerator* /* accelerator */) { |
208 // Currently no accelerators. | 212 // Currently no accelerators. |
209 return false; | 213 return false; |
210 } | 214 } |
211 | 215 |
212 void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { | 216 void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { |
213 DesktopNotificationService* service = | 217 DesktopNotificationService* service = |
214 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); | 218 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); |
215 ExtensionService* ext_service = | 219 ExtensionService* extension_service = |
216 balloon_->profile()->GetExtensionService(); | 220 balloon_->profile()->GetExtensionService(); |
217 const GURL& origin = balloon_->notification().origin_url(); | 221 const GURL& origin = balloon_->notification().origin_url(); |
218 switch (command_id) { | 222 switch (command_id) { |
219 case kTogglePermissionCommand: | 223 case kTogglePermissionCommand: |
220 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) | 224 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) |
221 service->DenyPermission(origin); | 225 service->DenyPermission(origin); |
222 else | 226 else |
223 service->GrantPermission(origin); | 227 service->GrantPermission(origin); |
224 break; | 228 break; |
225 case kToggleExtensionCommand: { | 229 case kToggleExtensionCommand: { |
226 const Extension* extension = ext_service->GetExtensionByURL(origin); | 230 const Extension* extension = |
| 231 extension_service->extensions()->GetExtensionOrAppByURL( |
| 232 ExtensionURLInfo(origin)); |
227 if (extension) { | 233 if (extension) { |
228 const std::string& id = extension->id(); | 234 const std::string& id = extension->id(); |
229 if (ext_service->IsExtensionEnabled(id)) | 235 if (extension_service->IsExtensionEnabled(id)) |
230 ext_service->DisableExtension(id); | 236 extension_service->DisableExtension(id); |
231 else | 237 else |
232 ext_service->EnableExtension(id); | 238 extension_service->EnableExtension(id); |
233 } | 239 } |
234 break; | 240 break; |
235 } | 241 } |
236 case kOpenContentSettingsCommand: { | 242 case kOpenContentSettingsCommand: { |
237 Browser* browser = | 243 Browser* browser = |
238 BrowserList::GetLastActiveWithProfile(balloon_->profile()); | 244 BrowserList::GetLastActiveWithProfile(balloon_->profile()); |
239 if (!browser) { | 245 if (!browser) { |
240 // It is possible that there is no browser window (e.g. when there are | 246 // It is possible that there is no browser window (e.g. when there are |
241 // background pages, or for a chrome frame process on windows). | 247 // background pages, or for a chrome frame process on windows). |
242 browser = Browser::Create(balloon_->profile()); | 248 browser = Browser::Create(balloon_->profile()); |
243 } | 249 } |
244 browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 250 browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
245 break; | 251 break; |
246 } | 252 } |
247 default: | 253 default: |
248 NOTREACHED(); | 254 NOTREACHED(); |
249 break; | 255 break; |
250 } | 256 } |
251 } | 257 } |
OLD | NEW |