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/sha1.h" | 10 #include "base/sha1.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
27 #include "extensions/browser/extension_registry.h" | 27 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
30 #include "extensions/common/extension_icon_set.h" | 30 #include "extensions/common/extension_icon_set.h" |
31 #include "extensions/common/extension_resource.h" | 31 #include "extensions/common/extension_resource.h" |
32 #include "extensions/common/extension_set.h" | 32 #include "extensions/common/extension_set.h" |
33 #include "extensions/common/manifest_handlers/background_info.h" | 33 #include "extensions/common/manifest_handlers/background_info.h" |
34 #include "extensions/common/manifest_handlers/icons_handler.h" | 34 #include "extensions/common/manifest_handlers/icons_handler.h" |
35 #include "extensions/common/permissions/permission_set.h" | 35 #include "extensions/common/permissions/permission_set.h" |
| 36 #include "extensions/common/permissions/permissions_data.h" |
36 #include "ui/base/l10n/l10n_util_collator.h" | 37 #include "ui/base/l10n/l10n_util_collator.h" |
37 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
38 #include "ui/gfx/image/image_skia.h" | 39 #include "ui/gfx/image/image_skia.h" |
39 | 40 |
40 using extensions::APIPermission; | 41 using extensions::APIPermission; |
41 using extensions::Extension; | 42 using extensions::Extension; |
42 using extensions::ExtensionList; | 43 using extensions::ExtensionList; |
43 using extensions::ExtensionRegistry; | 44 using extensions::ExtensionRegistry; |
44 using extensions::ExtensionSet; | 45 using extensions::ExtensionSet; |
45 using extensions::PermissionSet; | 46 using extensions::PermissionSet; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return position; | 271 return position; |
271 } | 272 } |
272 NOTREACHED(); | 273 NOTREACHED(); |
273 return -1; | 274 return -1; |
274 } | 275 } |
275 | 276 |
276 // static | 277 // static |
277 bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging( | 278 bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging( |
278 const Extension& extension) { | 279 const Extension& extension) { |
279 // No PushMessaging permission - does not require the background mode. | 280 // No PushMessaging permission - does not require the background mode. |
280 if (!extension.HasAPIPermission(APIPermission::kPushMessaging)) | 281 if (!extension.permissions_data()->HasAPIPermission( |
| 282 APIPermission::kPushMessaging)) { |
281 return false; | 283 return false; |
| 284 } |
282 | 285 |
283 // If in the whitelist, then does not require background mode even if | 286 // If in the whitelist, then does not require background mode even if |
284 // uses push messaging. | 287 // uses push messaging. |
285 // TODO(dimich): remove this whitelist once we have a better way to keep | 288 // TODO(dimich): remove this whitelist once we have a better way to keep |
286 // listening for GCM. http://crbug.com/311268 | 289 // listening for GCM. http://crbug.com/311268 |
287 std::string id_hash = base::SHA1HashString(extension.id()); | 290 std::string id_hash = base::SHA1HashString(extension.id()); |
288 std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), | 291 std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), |
289 id_hash.length()); | 292 id_hash.length()); |
290 // The id starting from "9A04..." is a one from unit test. | 293 // The id starting from "9A04..." is a one from unit test. |
291 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || | 294 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || |
292 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") | 295 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") |
293 return false; | 296 return false; |
294 | 297 |
295 return true; | 298 return true; |
296 } | 299 } |
297 | 300 |
298 // static | 301 // static |
299 bool BackgroundApplicationListModel::IsBackgroundApp( | 302 bool BackgroundApplicationListModel::IsBackgroundApp( |
300 const Extension& extension, Profile* profile) { | 303 const Extension& extension, Profile* profile) { |
301 // An extension is a "background app" if it has the "background API" | 304 // An extension is a "background app" if it has the "background API" |
302 // permission, and meets one of the following criteria: | 305 // permission, and meets one of the following criteria: |
303 // 1) It is an extension (not a hosted app). | 306 // 1) It is an extension (not a hosted app). |
304 // 2) It is a hosted app, and has a background contents registered or in the | 307 // 2) It is a hosted app, and has a background contents registered or in the |
305 // manifest. | 308 // manifest. |
306 | 309 |
307 // Not a background app if we don't have the background permission or | 310 // Not a background app if we don't have the background permission or |
308 // the push messaging permission | 311 // the push messaging permission |
309 if (!extension.HasAPIPermission(APIPermission::kBackground) && | 312 if (!extension.permissions_data()->HasAPIPermission( |
| 313 APIPermission::kBackground) && |
310 !RequiresBackgroundModeForPushMessaging(extension)) | 314 !RequiresBackgroundModeForPushMessaging(extension)) |
311 return false; | 315 return false; |
312 | 316 |
313 // Extensions and packaged apps with background permission are always treated | 317 // Extensions and packaged apps with background permission are always treated |
314 // as background apps. | 318 // as background apps. |
315 if (!extension.is_hosted_app()) | 319 if (!extension.is_hosted_app()) |
316 return true; | 320 return true; |
317 | 321 |
318 // Hosted apps with manifest-provided background pages are background apps. | 322 // Hosted apps with manifest-provided background pages are background apps. |
319 if (extensions::BackgroundInfo::HasBackgroundPage(&extension)) | 323 if (extensions::BackgroundInfo::HasBackgroundPage(&extension)) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 (*old_cursor)->name() == (*new_cursor)->name() && | 442 (*old_cursor)->name() == (*new_cursor)->name() && |
439 (*old_cursor)->id() == (*new_cursor)->id()) { | 443 (*old_cursor)->id() == (*new_cursor)->id()) { |
440 ++old_cursor; | 444 ++old_cursor; |
441 ++new_cursor; | 445 ++new_cursor; |
442 } | 446 } |
443 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 447 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
444 extensions_ = extensions; | 448 extensions_ = extensions; |
445 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); | 449 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
446 } | 450 } |
447 } | 451 } |
OLD | NEW |