Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: extensions/common/manifest_handlers/action_handlers_handler.cc

Issue 2618493002: Chrome app manifest support for action handlers. (Closed)
Patch Set: Make //components/version_info:version_info dep explicit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/common/manifest_handlers/action_handlers_handler.cc
diff --git a/extensions/common/manifest_handlers/action_handlers_handler.cc b/extensions/common/manifest_handlers/action_handlers_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..967db225b5132542ba5256606538df4c19ddcf3e
--- /dev/null
+++ b/extensions/common/manifest_handlers/action_handlers_handler.cc
@@ -0,0 +1,70 @@
+// Copyright 2017 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/action_handlers_handler.h"
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "extensions/common/error_utils.h"
+#include "extensions/common/manifest_constants.h"
+
+namespace extensions {
+
+namespace app_runtime = api::app_runtime;
+namespace errors = manifest_errors;
+namespace keys = manifest_keys;
+
+// static
+bool ActionHandlersInfo::HasActionHandler(
+ const Extension* extension,
+ api::app_runtime::ActionType action_type) {
+ ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>(
+ extension->GetManifestData(keys::kActionHandlers));
+ return info && info->action_handlers.count(action_type) > 0;
+}
+
+ActionHandlersInfo::ActionHandlersInfo() = default;
+
+ActionHandlersInfo::~ActionHandlersInfo() = default;
+
+ActionHandlersHandler::ActionHandlersHandler() = default;
+
+ActionHandlersHandler::~ActionHandlersHandler() = default;
+
+bool ActionHandlersHandler::Parse(Extension* extension, base::string16* error) {
+ const base::ListValue* entries = nullptr;
+ if (!extension->manifest()->GetList(keys::kActionHandlers, &entries)) {
+ *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType);
+ return false;
+ }
+
+ auto info = base::MakeUnique<ActionHandlersInfo>();
+ for (const std::unique_ptr<base::Value>& wrapped_value : *entries) {
+ std::string value;
+ if (!wrapped_value->GetAsString(&value)) {
+ *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType);
+ return false;
+ }
+
+ app_runtime::ActionType action_type = app_runtime::ParseActionType(value);
+ if (action_type == app_runtime::ACTION_TYPE_NONE) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidActionHandlersActionType, value);
+ return false;
+ }
+
+ info->action_handlers.insert(action_type);
+ }
+
+ extension->SetManifestData(keys::kActionHandlers, info.release());
+ return true;
+}
+
+const std::vector<std::string> ActionHandlersHandler::Keys() const {
+ return SingleKey(keys::kActionHandlers);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698