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 3 // found in the LICENSE file. 4 5 #include "extensions/common/manifest_handlers/offline_enabled_info.h" 6 7 #include "base/memory/scoped_ptr.h" 8 #include "base/strings/string16.h" 9 #include "base/strings/string_util.h" 10 #include "base/strings/utf_string_conversions.h" 11 #include "base/values.h" 12 #include "extensions/common/manifest_constants.h" 13 #include "extensions/common/manifest_handlers/permissions_parser.h" 14 #include "extensions/common/permissions/api_permission_set.h" 15 16 namespace extensions { 17 18 namespace keys = manifest_keys; 19 OfflineEnabledInfo(bool is_offline_enabled)20OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) 21 : offline_enabled(is_offline_enabled) { 22 } 23 ~OfflineEnabledInfo()24OfflineEnabledInfo::~OfflineEnabledInfo() { 25 } 26 27 // static IsOfflineEnabled(const Extension * extension)28bool OfflineEnabledInfo::IsOfflineEnabled(const Extension* extension) { 29 OfflineEnabledInfo* info = static_cast<OfflineEnabledInfo*>( 30 extension->GetManifestData(keys::kOfflineEnabled)); 31 return info ? info->offline_enabled : false; 32 } 33 OfflineEnabledHandler()34OfflineEnabledHandler::OfflineEnabledHandler() { 35 } 36 ~OfflineEnabledHandler()37OfflineEnabledHandler::~OfflineEnabledHandler() { 38 } 39 Parse(Extension * extension,base::string16 * error)40bool OfflineEnabledHandler::Parse(Extension* extension, base::string16* error) { 41 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { 42 // Only platform apps are provided with a default offline enabled value. 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. 46 DCHECK(extension->is_platform_app()); 47 48 const bool has_webview_permission = 49 PermissionsParser::HasAPIPermission(extension, APIPermission::kWebView); 50 extension->SetManifestData(keys::kOfflineEnabled, 51 new OfflineEnabledInfo(!has_webview_permission)); 52 return true; 53 } 54 55 bool offline_enabled = false; 56 57 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, 58 &offline_enabled)) { 59 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); 60 return false; 61 } 62 63 extension->SetManifestData(keys::kOfflineEnabled, 64 new OfflineEnabledInfo(offline_enabled)); 65 return true; 66 } 67 AlwaysParseForType(Manifest::Type type) const68bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { 69 return type == Manifest::TYPE_PLATFORM_APP; 70 } 71 Keys() const72const std::vector<std::string> OfflineEnabledHandler::Keys() const { 73 return SingleKey(keys::kOfflineEnabled); 74 } 75 76 } // namespace extensions 77