OLD | NEW |
| (Empty) |
1 // Copyright (c) 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 "chrome/common/extensions/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 | |
14 namespace extensions { | |
15 | |
16 namespace keys = manifest_keys; | |
17 | |
18 OfflineEnabledInfo::OfflineEnabledInfo(bool is_offline_enabled) | |
19 : offline_enabled(is_offline_enabled) { | |
20 } | |
21 | |
22 OfflineEnabledInfo::~OfflineEnabledInfo() { | |
23 } | |
24 | |
25 // static | |
26 bool OfflineEnabledInfo::IsOfflineEnabled(const Extension* extension) { | |
27 OfflineEnabledInfo* info = static_cast<OfflineEnabledInfo*>( | |
28 extension->GetManifestData(keys::kOfflineEnabled)); | |
29 return info ? info->offline_enabled : false; | |
30 } | |
31 | |
32 OfflineEnabledHandler::OfflineEnabledHandler() { | |
33 } | |
34 | |
35 OfflineEnabledHandler::~OfflineEnabledHandler() { | |
36 } | |
37 | |
38 bool OfflineEnabledHandler::Parse(Extension* extension, string16* error) { | |
39 if (!extension->manifest()->HasKey(keys::kOfflineEnabled)) { | |
40 // Only platform apps default to being enabled offline, and we should only | |
41 // attempt parsing without a key present if it is a platform app. | |
42 DCHECK(extension->is_platform_app()); | |
43 extension->SetManifestData(keys::kOfflineEnabled, | |
44 new OfflineEnabledInfo(true)); | |
45 return true; | |
46 } | |
47 | |
48 bool offline_enabled = false; | |
49 | |
50 if (!extension->manifest()->GetBoolean(keys::kOfflineEnabled, | |
51 &offline_enabled)) { | |
52 *error = ASCIIToUTF16(manifest_errors::kInvalidOfflineEnabled); | |
53 return false; | |
54 } | |
55 | |
56 extension->SetManifestData(keys::kOfflineEnabled, | |
57 new OfflineEnabledInfo(offline_enabled)); | |
58 return true; | |
59 } | |
60 | |
61 bool OfflineEnabledHandler::AlwaysParseForType(Manifest::Type type) const { | |
62 return type == Manifest::TYPE_PLATFORM_APP; | |
63 } | |
64 | |
65 const std::vector<std::string> OfflineEnabledHandler::Keys() const { | |
66 return SingleKey(keys::kOfflineEnabled); | |
67 } | |
68 | |
69 } // namespace extensions | |
OLD | NEW |