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

Side by Side Diff: extensions/common/manifest_handlers/action_handlers_handler.cc

Issue 2618493002: Chrome app manifest support for action handlers. (Closed)
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 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
22 const Extension* extension) {
23 ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>(
24 extension->GetManifestData(keys::kActionHandlers));
25 return info ? info->action_handlers : std::set<app_runtime::ActionType>();
26 }
27
28 ActionHandlersInfo::ActionHandlersInfo() = default;
29
30 ActionHandlersInfo::~ActionHandlersInfo() = default;
31
32 ActionHandlersHandler::ActionHandlersHandler() = default;
33
34 ActionHandlersHandler::~ActionHandlersHandler() = default;
35
36 bool ActionHandlersHandler::Parse(Extension* extension, base::string16* error) {
37 auto info = base::MakeUnique<ActionHandlersInfo>();
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 for (const std::unique_ptr<base::Value>& wrapped_value : *entries) {
45 std::string value;
46 if (!wrapped_value->GetAsString(&value)) {
47 *error = base::ASCIIToUTF16(errors::kInvalidActionHandlersType);
48 return false;
49 }
50
51 app_runtime::ActionType action_type = app_runtime::ParseActionType(value);
52 if (action_type == app_runtime::ACTION_TYPE_NONE) {
53 *error = ErrorUtils::FormatErrorMessageUTF16(
54 errors::kInvalidActionHandlersActionType, value);
55 return false;
56 }
57
58 info->action_handlers.insert(action_type);
59 }
60
61 extension->SetManifestData(keys::kActionHandlers, info.release());
62 return true;
63 }
64
65 const std::vector<std::string> ActionHandlersHandler::Keys() const {
66 return SingleKey(keys::kActionHandlers);
67 }
68
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698