Chromium Code Reviews| 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..9665d6240c3288be81be8215da6b032c8cae2bd8 |
| --- /dev/null |
| +++ b/extensions/common/manifest_handlers/action_handlers_handler.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 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 |
| +std::set<app_runtime::ActionType> ActionHandlersInfo::GetActionHandlers( |
|
Daniel Erat
2017/01/12 23:55:03
i take it that this can't return a const reference
jdufault
2017/01/14 00:30:42
Done. Tests need the full set of handlers, so I mo
|
| + const Extension* extension) { |
| + ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>( |
| + extension->GetManifestData(keys::kActionHandlers)); |
| + return info ? info->action_handlers : std::set<app_runtime::ActionType>(); |
| +} |
| + |
| +ActionHandlersInfo::ActionHandlersInfo() = default; |
| + |
| +ActionHandlersInfo::~ActionHandlersInfo() = default; |
| + |
| +ActionHandlersHandler::ActionHandlersHandler() = default; |
| + |
| +ActionHandlersHandler::~ActionHandlersHandler() = default; |
| + |
| +bool ActionHandlersHandler::Parse(Extension* extension, base::string16* error) { |
| + auto info = base::MakeUnique<ActionHandlersInfo>(); |
| + const base::ListValue* entries = nullptr; |
| + if (!extension->manifest()->GetList(keys::kActionHandlers, &entries)) { |
| + *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType); |
| + return false; |
| + } |
| + |
| + 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 |