| 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/manifest_handlers/permissions_parser.h" |
| 13 #include "extensions/common/permissions/api_permission_set.h" | 14 #include "extensions/common/permissions/api_permission_set.h" |
| 14 #include "extensions/common/permissions/permissions_data.h" | |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 namespace keys = manifest_keys; | 18 namespace keys = manifest_keys; |
| 19 | 19 |
| 20 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) | 20 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) |
| 21 : offline_enabled(is_offline_enabled) { | 21 : offline_enabled(is_offline_enabled) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 OfflineEnabledInfo::~OfflineEnabledInfo() { | 24 OfflineEnabledInfo::~OfflineEnabledInfo() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 bool OfflineEnabledHandler::Parse(Extension* extension, base::string16* error) { | 40 bool OfflineEnabledHandler::Parse(Extension* extension, base::string16* error) { |
| 41 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { | 41 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { |
| 42 // Only platform apps are provided with a default offline enabled value. | 42 // Only platform apps are provided with a default offline enabled value. |
| 43 // A platform app is offline enabled unless it requests the webview | 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 | 44 // permission. That is, offline_enabled is true when there is NO webview |
| 45 // permission requested and false when webview permission is present. | 45 // permission requested and false when webview permission is present. |
| 46 DCHECK(extension->is_platform_app()); | 46 DCHECK(extension->is_platform_app()); |
| 47 | 47 |
| 48 const bool has_webview_permission = | 48 const bool has_webview_permission = |
| 49 !!PermissionsData::GetInitialAPIPermissions(extension) | 49 PermissionsParser::HasAPIPermission(extension, APIPermission::kWebView); |
| 50 ->count(APIPermission::kWebView); | |
| 51 extension->SetManifestData(keys::kOfflineEnabled, | 50 extension->SetManifestData(keys::kOfflineEnabled, |
| 52 new OfflineEnabledInfo(!has_webview_permission)); | 51 new OfflineEnabledInfo(!has_webview_permission)); |
| 53 return true; | 52 return true; |
| 54 } | 53 } |
| 55 | 54 |
| 56 bool offline_enabled = false; | 55 bool offline_enabled = false; |
| 57 | 56 |
| 58 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, | 57 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, |
| 59 &offline_enabled)) { | 58 &offline_enabled)) { |
| 60 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); | 59 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); |
| 61 return false; | 60 return false; |
| 62 } | 61 } |
| 63 | 62 |
| 64 extension->SetManifestData(keys::kOfflineEnabled, | 63 extension->SetManifestData(keys::kOfflineEnabled, |
| 65 new OfflineEnabledInfo(offline_enabled)); | 64 new OfflineEnabledInfo(offline_enabled)); |
| 66 return true; | 65 return true; |
| 67 } | 66 } |
| 68 | 67 |
| 69 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { | 68 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { |
| 70 return type == Manifest::TYPE_PLATFORM_APP; | 69 return type == Manifest::TYPE_PLATFORM_APP; |
| 71 } | 70 } |
| 72 | 71 |
| 73 const std::vector<std::string> OfflineEnabledHandler::Keys() const { | 72 const std::vector<std::string> OfflineEnabledHandler::Keys() const { |
| 74 return SingleKey(keys::kOfflineEnabled); | 73 return SingleKey(keys::kOfflineEnabled); |
| 75 } | 74 } |
| 76 | 75 |
| 77 } // namespace extensions | 76 } // namespace extensions |
| OLD | NEW |