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/background/background_application_list_model.h" | 5 #include "chrome/browser/background/background_application_list_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_icon_set.h" | 23 #include "chrome/common/extensions/extension_icon_set.h" |
24 #include "chrome/common/extensions/extension_resource.h" | 24 #include "chrome/common/extensions/extension_resource.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 #include "ui/base/l10n/l10n_util_collator.h" | 27 #include "ui/base/l10n/l10n_util_collator.h" |
28 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
29 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
30 | 30 |
| 31 using extensions::APIPermission; |
31 using extensions::Extension; | 32 using extensions::Extension; |
32 using extensions::ExtensionList; | 33 using extensions::ExtensionList; |
| 34 using extensions::PermissionSet; |
33 using extensions::UnloadedExtensionInfo; | 35 using extensions::UnloadedExtensionInfo; |
34 using extensions::UpdatedExtensionPermissionsInfo; | 36 using extensions::UpdatedExtensionPermissionsInfo; |
35 | 37 |
36 class ExtensionNameComparator { | 38 class ExtensionNameComparator { |
37 public: | 39 public: |
38 explicit ExtensionNameComparator(icu::Collator* collator); | 40 explicit ExtensionNameComparator(icu::Collator* collator); |
39 bool operator()(const Extension* x, const Extension* y); | 41 bool operator()(const Extension* x, const Extension* y); |
40 | 42 |
41 private: | 43 private: |
42 icu::Collator* collator_; | 44 icu::Collator* collator_; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // static | 269 // static |
268 bool BackgroundApplicationListModel::IsBackgroundApp( | 270 bool BackgroundApplicationListModel::IsBackgroundApp( |
269 const Extension& extension, Profile* profile) { | 271 const Extension& extension, Profile* profile) { |
270 // An extension is a "background app" if it has the "background API" | 272 // An extension is a "background app" if it has the "background API" |
271 // permission, and meets one of the following criteria: | 273 // permission, and meets one of the following criteria: |
272 // 1) It is an extension (not a hosted app). | 274 // 1) It is an extension (not a hosted app). |
273 // 2) It is a hosted app, and has a background contents registered or in the | 275 // 2) It is a hosted app, and has a background contents registered or in the |
274 // manifest. | 276 // manifest. |
275 | 277 |
276 // Not a background app if we don't have the background permission. | 278 // Not a background app if we don't have the background permission. |
277 if (!extension.HasAPIPermission(ExtensionAPIPermission::kBackground)) | 279 if (!extension.HasAPIPermission(APIPermission::kBackground)) |
278 return false; | 280 return false; |
279 | 281 |
280 // Extensions and packaged apps with background permission are always treated | 282 // Extensions and packaged apps with background permission are always treated |
281 // as background apps. | 283 // as background apps. |
282 if (!extension.is_hosted_app()) | 284 if (!extension.is_hosted_app()) |
283 return true; | 285 return true; |
284 | 286 |
285 // Hosted apps with manifest-provided background pages are background apps. | 287 // Hosted apps with manifest-provided background pages are background apps. |
286 if (extension.has_background_page()) | 288 if (extension.has_background_page()) |
287 return true; | 289 return true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 const Extension* extension) { | 358 const Extension* extension) { |
357 if (!IsBackgroundApp(*extension, profile_)) | 359 if (!IsBackgroundApp(*extension, profile_)) |
358 return; | 360 return; |
359 Update(); | 361 Update(); |
360 DissociateApplicationData(extension); | 362 DissociateApplicationData(extension); |
361 } | 363 } |
362 | 364 |
363 void BackgroundApplicationListModel::OnExtensionPermissionsUpdated( | 365 void BackgroundApplicationListModel::OnExtensionPermissionsUpdated( |
364 const Extension* extension, | 366 const Extension* extension, |
365 UpdatedExtensionPermissionsInfo::Reason reason, | 367 UpdatedExtensionPermissionsInfo::Reason reason, |
366 const ExtensionPermissionSet* permissions) { | 368 const PermissionSet* permissions) { |
367 if (permissions->HasAPIPermission(ExtensionAPIPermission::kBackground)) { | 369 if (permissions->HasAPIPermission(APIPermission::kBackground)) { |
368 switch (reason) { | 370 switch (reason) { |
369 case UpdatedExtensionPermissionsInfo::ADDED: | 371 case UpdatedExtensionPermissionsInfo::ADDED: |
370 DCHECK(IsBackgroundApp(*extension, profile_)); | 372 DCHECK(IsBackgroundApp(*extension, profile_)); |
371 OnExtensionLoaded(extension); | 373 OnExtensionLoaded(extension); |
372 break; | 374 break; |
373 case UpdatedExtensionPermissionsInfo::REMOVED: | 375 case UpdatedExtensionPermissionsInfo::REMOVED: |
374 DCHECK(!IsBackgroundApp(*extension, profile_)); | 376 DCHECK(!IsBackgroundApp(*extension, profile_)); |
375 Update(); | 377 Update(); |
376 DissociateApplicationData(extension); | 378 DissociateApplicationData(extension); |
377 break; | 379 break; |
(...skipping 25 matching lines...) Expand all Loading... |
403 (*old_cursor)->name() == (*new_cursor)->name() && | 405 (*old_cursor)->name() == (*new_cursor)->name() && |
404 (*old_cursor)->id() == (*new_cursor)->id()) { | 406 (*old_cursor)->id() == (*new_cursor)->id()) { |
405 ++old_cursor; | 407 ++old_cursor; |
406 ++new_cursor; | 408 ++new_cursor; |
407 } | 409 } |
408 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 410 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
409 extensions_ = extensions; | 411 extensions_ = extensions; |
410 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); | 412 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
411 } | 413 } |
412 } | 414 } |
OLD | NEW |