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() {
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
));
55 bool offline_enabled
= false;
57 if (!extension
->manifest()->GetBoolean(keys::kOfflineEnabled
,
59 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled
);
63 extension
->SetManifestData(keys::kOfflineEnabled
,
64 new OfflineEnabledInfo(offline_enabled
));
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