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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 cursor != extensions_.end(); | 273 cursor != extensions_.end(); |
274 ++cursor, ++position) { | 274 ++cursor, ++position) { |
275 if (id == cursor->get()->id()) | 275 if (id == cursor->get()->id()) |
276 return position; | 276 return position; |
277 } | 277 } |
278 NOTREACHED(); | 278 NOTREACHED(); |
279 return -1; | 279 return -1; |
280 } | 280 } |
281 | 281 |
282 // static | 282 // static |
283 bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging( | |
284 const Extension& extension) { | |
285 // No PushMessaging permission - does not require the background mode. | |
286 if (!extension.permissions_data()->HasAPIPermission( | |
287 APIPermission::kPushMessaging)) { | |
288 return false; | |
289 } | |
290 | |
291 // If in the whitelist, then does not require background mode even if | |
292 // uses push messaging. | |
293 // TODO(dimich): remove this whitelist once we have a better way to keep | |
294 // listening for GCM. http://crbug.com/311268 | |
295 std::string hexencoded_id_hash = | |
296 crx_file::id_util::HashedIdInHex(extension.id()); | |
297 // The id starting from "9A04..." is a one from unit test. | |
298 if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || | |
299 hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") | |
300 return false; | |
301 | |
302 return true; | |
303 } | |
304 | |
305 // static | |
306 bool BackgroundApplicationListModel::IsBackgroundApp( | 283 bool BackgroundApplicationListModel::IsBackgroundApp( |
307 const Extension& extension, Profile* profile) { | 284 const Extension& extension, Profile* profile) { |
308 // An extension is a "background app" if it has the "background API" | 285 // An extension is a "background app" if it has the "background API" |
309 // permission, and meets one of the following criteria: | 286 // permission, and meets one of the following criteria: |
310 // 1) It is an extension (not a hosted app). | 287 // 1) It is an extension (not a hosted app). |
311 // 2) It is a hosted app, and has a background contents registered or in the | 288 // 2) It is a hosted app, and has a background contents registered or in the |
312 // manifest. | 289 // manifest. |
313 | 290 |
314 // Ephemeral apps are denied any background activity after their event page | 291 // Ephemeral apps are denied any background activity after their event page |
315 // has been destroyed, thus they cannot be background apps. | 292 // has been destroyed, thus they cannot be background apps. |
316 if (extensions::util::IsEphemeralApp(extension.id(), profile)) | 293 if (extensions::util::IsEphemeralApp(extension.id(), profile)) |
317 return false; | 294 return false; |
318 | 295 |
319 // Not a background app if we don't have the background permission or | 296 // Not a background app if we don't have the background permission. |
320 // the push messaging permission | |
321 if (!extension.permissions_data()->HasAPIPermission( | 297 if (!extension.permissions_data()->HasAPIPermission( |
322 APIPermission::kBackground) && | 298 APIPermission::kBackground)) { |
323 !RequiresBackgroundModeForPushMessaging(extension)) | |
324 return false; | 299 return false; |
| 300 } |
325 | 301 |
326 // Extensions and packaged apps with background permission are always treated | 302 // Extensions and packaged apps with background permission are always treated |
327 // as background apps. | 303 // as background apps. |
328 if (!extension.is_hosted_app()) | 304 if (!extension.is_hosted_app()) |
329 return true; | 305 return true; |
330 | 306 |
331 // Hosted apps with manifest-provided background pages are background apps. | 307 // Hosted apps with manifest-provided background pages are background apps. |
332 if (extensions::BackgroundInfo::HasBackgroundPage(&extension)) | 308 if (extensions::BackgroundInfo::HasBackgroundPage(&extension)) |
333 return true; | 309 return true; |
334 | 310 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 (*old_cursor)->name() == (*new_cursor)->name() && | 428 (*old_cursor)->name() == (*new_cursor)->name() && |
453 (*old_cursor)->id() == (*new_cursor)->id()) { | 429 (*old_cursor)->id() == (*new_cursor)->id()) { |
454 ++old_cursor; | 430 ++old_cursor; |
455 ++new_cursor; | 431 ++new_cursor; |
456 } | 432 } |
457 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { | 433 if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { |
458 extensions_ = extensions; | 434 extensions_ = extensions; |
459 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); | 435 FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); |
460 } | 436 } |
461 } | 437 } |
OLD | NEW |