Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / extensions / common / manifest_handlers / offline_enabled_info.cc
blob4ce6637f87439645d3f025ea570f7441fb69581a
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.
5 #include "extensions/common/manifest_handlers/offline_enabled_info.h"
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"
16 namespace extensions {
18 namespace keys = manifest_keys;
20 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled)
21 : offline_enabled(is_offline_enabled) {
24 OfflineEnabledInfo::~OfflineEnabledInfo() {
27 // static
28 bool OfflineEnabledInfo::IsOfflineEnabled(const Extension* extension) {
29 OfflineEnabledInfo* info = static_cast<OfflineEnabledInfo*>(
30 extension->GetManifestData(keys::kOfflineEnabled));
31 return info ? info->offline_enabled : false;
34 OfflineEnabledHandler::OfflineEnabledHandler() {
37 OfflineEnabledHandler::~OfflineEnabledHandler() {
40 bool 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());
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;
55 bool offline_enabled = false;
57 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled,
58 &offline_enabled)) {
59 *error = base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled);
60 return false;
63 extension->SetManifestData(keys::kOfflineEnabled,
64 new OfflineEnabledInfo(offline_enabled));
65 return true;
68 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const {
69 return type == Manifest::TYPE_PLATFORM_APP;
72 const std::vector<std::string> OfflineEnabledHandler::Keys() const {
73 return SingleKey(keys::kOfflineEnabled);
76 } // namespace extensions