| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "extensions/common/manifest_handlers/action_handlers_handler.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "extensions/common/error_utils.h" |
| 12 #include "extensions/common/manifest_constants.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 namespace app_runtime = api::app_runtime; |
| 17 namespace errors = manifest_errors; |
| 18 namespace keys = manifest_keys; |
| 19 |
| 20 // static |
| 21 bool ActionHandlersInfo::HasActionHandler( |
| 22 const Extension* extension, |
| 23 api::app_runtime::ActionType action_type) { |
| 24 ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>( |
| 25 extension->GetManifestData(keys::kActionHandlers)); |
| 26 return info && info->action_handlers.count(action_type) > 0; |
| 27 } |
| 28 |
| 29 ActionHandlersInfo::ActionHandlersInfo() = default; |
| 30 |
| 31 ActionHandlersInfo::~ActionHandlersInfo() = default; |
| 32 |
| 33 ActionHandlersHandler::ActionHandlersHandler() = default; |
| 34 |
| 35 ActionHandlersHandler::~ActionHandlersHandler() = default; |
| 36 |
| 37 bool ActionHandlersHandler::Parse(Extension* extension, base::string16* error) { |
| 38 const base::ListValue* entries = nullptr; |
| 39 if (!extension->manifest()->GetList(keys::kActionHandlers, &entries)) { |
| 40 *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType); |
| 41 return false; |
| 42 } |
| 43 |
| 44 auto info = base::MakeUnique<ActionHandlersInfo>(); |
| 45 for (const std::unique_ptr<base::Value>& wrapped_value : *entries) { |
| 46 std::string value; |
| 47 if (!wrapped_value->GetAsString(&value)) { |
| 48 *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType); |
| 49 return false; |
| 50 } |
| 51 |
| 52 app_runtime::ActionType action_type = app_runtime::ParseActionType(value); |
| 53 if (action_type == app_runtime::ACTION_TYPE_NONE) { |
| 54 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 55 errors::kInvalidActionHandlersActionType, value); |
| 56 return false; |
| 57 } |
| 58 |
| 59 info->action_handlers.insert(action_type); |
| 60 } |
| 61 |
| 62 extension->SetManifestData(keys::kActionHandlers, info.release()); |
| 63 return true; |
| 64 } |
| 65 |
| 66 const std::vector<std::string> ActionHandlersHandler::Keys() const { |
| 67 return SingleKey(keys::kActionHandlers); |
| 68 } |
| 69 |
| 70 } // namespace extensions |
| OLD | NEW |