OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/common/manifest_handlers/offline_enabled_info.h" | 5 #include "extensions/common/manifest_handlers/offline_enabled_info.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
| 13 #include "extensions/common/permissions/api_permission_set.h" |
| 14 #include "extensions/common/permissions/permissions_data.h" |
13 | 15 |
14 namespace extensions { | 16 namespace extensions { |
15 | 17 |
16 namespace keys = manifest_keys; | 18 namespace keys = manifest_keys; |
17 | 19 |
18 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) | 20 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) |
19 : offline_enabled(is_offline_enabled) { | 21 : offline_enabled(is_offline_enabled) { |
20 } | 22 } |
21 | 23 |
22 OfflineEnabledInfo::~OfflineEnabledInfo() { | 24 OfflineEnabledInfo::~OfflineEnabledInfo() { |
23 } | 25 } |
24 | 26 |
25 // static | 27 // static |
26 bool OfflineEnabledInfo::IsOfflineEnabled(const Extension* extension) { | 28 bool OfflineEnabledInfo::IsOfflineEnabled(const Extension* extension) { |
27 OfflineEnabledInfo* info = static_cast<OfflineEnabledInfo*>( | 29 OfflineEnabledInfo* info = static_cast<OfflineEnabledInfo*>( |
28 extension->GetManifestData(keys::kOfflineEnabled)); | 30 extension->GetManifestData(keys::kOfflineEnabled)); |
29 return info ? info->offline_enabled : false; | 31 return info ? info->offline_enabled : false; |
30 } | 32 } |
31 | 33 |
32 OfflineEnabledHandler::OfflineEnabledHandler() { | 34 OfflineEnabledHandler::OfflineEnabledHandler() { |
33 } | 35 } |
34 | 36 |
35 OfflineEnabledHandler::~OfflineEnabledHandler() { | 37 OfflineEnabledHandler::~OfflineEnabledHandler() { |
36 } | 38 } |
37 | 39 |
38 bool OfflineEnabledHandler::Parse(Extension* extension, base::string16* error) { | 40 bool OfflineEnabledHandler::Parse(Extension* extension, base::string16* error) { |
39 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { | 41 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { |
40 // Only platform apps default to being enabled offline, and we should only | 42 // Only platform apps are provided with a default offline enabled value. |
41 // attempt parsing without a key present if it is a platform app. | 43 // A platform app is offline enabled unless it requests the webview |
| 44 // permission. That is, offline_enabled is true when there is NO webview |
| 45 // permission requested and false when webview permission is present. |
42 DCHECK(extension->is_platform_app()); | 46 DCHECK(extension->is_platform_app()); |
| 47 |
| 48 const bool has_webview_permission = |
| 49 !!PermissionsData::GetInitialAPIPermissions(extension) |
| 50 ->count(APIPermission::kWebView); |
43 extension->SetManifestData(keys::kOfflineEnabled, | 51 extension->SetManifestData(keys::kOfflineEnabled, |
44 new OfflineEnabledInfo(true)); | 52 new OfflineEnabledInfo(!has_webview_permission)); |
45 return true; | 53 return true; |
46 } | 54 } |
47 | 55 |
48 bool offline_enabled = false; | 56 bool offline_enabled = false; |
49 | 57 |
50 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, | 58 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, |
51 &offline_enabled)) { | 59 &offline_enabled)) { |
52 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); | 60 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); |
53 return false; | 61 return false; |
54 } | 62 } |
55 | 63 |
56 extension->SetManifestData(keys::kOfflineEnabled, | 64 extension->SetManifestData(keys::kOfflineEnabled, |
57 new OfflineEnabledInfo(offline_enabled)); | 65 new OfflineEnabledInfo(offline_enabled)); |
58 return true; | 66 return true; |
59 } | 67 } |
60 | 68 |
61 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { | 69 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { |
62 return type == Manifest::TYPE_PLATFORM_APP; | 70 return type == Manifest::TYPE_PLATFORM_APP; |
63 } | 71 } |
64 | 72 |
65 const std::vector<std::string> OfflineEnabledHandler::Keys() const { | 73 const std::vector<std::string> OfflineEnabledHandler::Keys() const { |
66 return SingleKey(keys::kOfflineEnabled); | 74 return SingleKey(keys::kOfflineEnabled); |
67 } | 75 } |
68 | 76 |
69 } // namespace extensions | 77 } // namespace extensions |
OLD | NEW |