summaryrefslogtreecommitdiffstats
path: root/extensions/common/manifest_handlers
diff options
context:
space:
mode:
authortfarina <tfarina@chromium.org>2015-06-29 15:19:26 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-29 22:19:49 +0000
commit0bcdf36e3b924ad6810dcdfce66d730befb386e9 (patch)
tree5de84e9149cf112b7188bb892c7deaa4c365d0d1 /extensions/common/manifest_handlers
parent2b9a102727da708451c0d63f7d2b9cb81ae10802 (diff)
downloadchromium_src-0bcdf36e3b924ad6810dcdfce66d730befb386e9.zip
chromium_src-0bcdf36e3b924ad6810dcdfce66d730befb386e9.tar.gz
chromium_src-0bcdf36e3b924ad6810dcdfce66d730befb386e9.tar.bz2
Move AppIsolationInfo from chrome to extensions.
This is necessary because HasIsolatedStorage() depends on it, so in order to get HasIsolatedStorage() in extensions as well we need to have AIF in there too. This will help for the tmdiep's TODO in extensions/browser/extension_util.h. BUG=None R=rdevlin.cronin@chromium.org tbr=thestig@chromium.org Review URL: https://codereview.chromium.org/1212373004 Cr-Commit-Position: refs/heads/master@{#336658}
Diffstat (limited to 'extensions/common/manifest_handlers')
-rw-r--r--extensions/common/manifest_handlers/app_isolation_info.cc98
-rw-r--r--extensions/common/manifest_handlers/app_isolation_info.h44
2 files changed, 142 insertions, 0 deletions
diff --git a/extensions/common/manifest_handlers/app_isolation_info.cc b/extensions/common/manifest_handlers/app_isolation_info.cc
new file mode 100644
index 0000000..423976c
--- /dev/null
+++ b/extensions/common/manifest_handlers/app_isolation_info.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/manifest_handlers/app_isolation_info.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "extensions/common/error_utils.h"
+#include "extensions/common/manifest_constants.h"
+#include "extensions/common/manifest_handlers/permissions_parser.h"
+#include "extensions/common/permissions/api_permission_set.h"
+
+namespace extensions {
+
+namespace keys = manifest_keys;
+
+AppIsolationInfo::AppIsolationInfo(bool isolated_storage)
+ : has_isolated_storage(isolated_storage) {
+}
+
+AppIsolationInfo::~AppIsolationInfo() {
+}
+
+// static
+bool AppIsolationInfo::HasIsolatedStorage(const Extension* extension) {
+ AppIsolationInfo* info = static_cast<AppIsolationInfo*>(
+ extension->GetManifestData(keys::kIsolation));
+ return info ? info->has_isolated_storage : false;
+}
+
+AppIsolationHandler::AppIsolationHandler() {
+}
+
+AppIsolationHandler::~AppIsolationHandler() {
+}
+
+bool AppIsolationHandler::Parse(Extension* extension, base::string16* error) {
+ // Platform apps always get isolated storage.
+ if (extension->is_platform_app()) {
+ extension->SetManifestData(keys::kIsolation, new AppIsolationInfo(true));
+ return true;
+ }
+
+ // Other apps only get it if it is requested _and_ experimental APIs are
+ // enabled.
+ if (!extension->is_app() ||
+ !PermissionsParser::HasAPIPermission(extension,
+ APIPermission::kExperimental)) {
+ return true;
+ }
+
+ // We should only be parsing if the extension has the key in the manifest,
+ // or is a platform app (which we already handled).
+ DCHECK(extension->manifest()->HasPath(keys::kIsolation));
+
+ const base::ListValue* isolation_list = NULL;
+ if (!extension->manifest()->GetList(keys::kIsolation, &isolation_list)) {
+ *error = base::ASCIIToUTF16(manifest_errors::kInvalidIsolation);
+ return false;
+ }
+
+ bool has_isolated_storage = false;
+ for (size_t i = 0; i < isolation_list->GetSize(); ++i) {
+ std::string isolation_string;
+ if (!isolation_list->GetString(i, &isolation_string)) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ manifest_errors::kInvalidIsolationValue,
+ base::UintToString(i));
+ return false;
+ }
+
+ // Check for isolated storage.
+ if (isolation_string == manifest_values::kIsolatedStorage) {
+ has_isolated_storage = true;
+ } else {
+ DLOG(WARNING) << "Did not recognize isolation type: " << isolation_string;
+ }
+ }
+
+ if (has_isolated_storage)
+ extension->SetManifestData(keys::kIsolation, new AppIsolationInfo(true));
+
+ return true;
+}
+
+bool AppIsolationHandler::AlwaysParseForType(Manifest::Type type) const {
+ return type == Manifest::TYPE_PLATFORM_APP;
+}
+
+const std::vector<std::string> AppIsolationHandler::Keys() const {
+ return SingleKey(keys::kIsolation);
+}
+
+} // namespace extensions
diff --git a/extensions/common/manifest_handlers/app_isolation_info.h b/extensions/common/manifest_handlers/app_isolation_info.h
new file mode 100644
index 0000000..bb50b1e
--- /dev/null
+++ b/extensions/common/manifest_handlers/app_isolation_info.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_COMMON_MANIFEST_HANDLERS_APP_ISOLATION_INFO_H_
+#define EXTENSIONS_COMMON_MANIFEST_HANDLERS_APP_ISOLATION_INFO_H_
+
+#include <string>
+#include <vector>
+
+#include "extensions/common/extension.h"
+#include "extensions/common/manifest.h"
+#include "extensions/common/manifest_handler.h"
+
+namespace extensions {
+
+struct AppIsolationInfo : public Extension::ManifestData {
+ explicit AppIsolationInfo(bool isolated_storage);
+ ~AppIsolationInfo() override;
+
+ static bool HasIsolatedStorage(const Extension* extension);
+
+ // Whether this extension requests isolated storage.
+ bool has_isolated_storage;
+};
+
+// Parses the "isolation" manifest key.
+class AppIsolationHandler : public ManifestHandler {
+ public:
+ AppIsolationHandler();
+ ~AppIsolationHandler() override;
+
+ bool Parse(Extension* extension, base::string16* error) override;
+ bool AlwaysParseForType(Manifest::Type type) const override;
+
+ private:
+ const std::vector<std::string> Keys() const override;
+
+ DISALLOW_COPY_AND_ASSIGN(AppIsolationHandler);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_APP_ISOLATION_INFO_H_