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

Side by Side Diff: chrome/common/extensions/api/extension_action/page_action_handler.cc

Issue 12042096: Move page action manifest parsing out of Extension; the first multi-key manifest handler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "chrome/common/extensions/api/extension_action/page_action_handler.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/extension.h"
10 #include "chrome/common/extensions/extension_constants.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "chrome/common/extensions/manifest_handler_helpers.h"
13
14 namespace keys = extension_manifest_keys;
15 namespace errors = extension_manifest_errors;
16
17 namespace extensions {
18
19 PageActionHandler::PageActionHandler() {
20 }
21
22 PageActionHandler::~PageActionHandler() {
23 }
24
25 bool PageActionHandler::Parse(const base::DictionaryValue* value,
26 Extension* extension,
27 string16* error) {
28 scoped_ptr<ActionInfo> page_action_info;
Matt Perry 2013/01/25 20:56:40 nit: move this down where it's first used.
29 const DictionaryValue* page_action_value = NULL;
30
31 if (value->HasKey(keys::kPageActions)) {
32 const ListValue* list_value = NULL;
33 if (!value->GetList(keys::kPageActions, &list_value)) {
34 *error = ASCIIToUTF16(errors::kInvalidPageActionsList);
35 return false;
36 }
37
38 size_t list_value_length = list_value->GetSize();
39
40 if (list_value_length == 0u) {
41 // A list with zero items is allowed, and is equivalent to not having
42 // a page_actions key in the manifest. Don't set |page_action_value|.
43 } else if (list_value_length == 1u) {
44 if (!list_value->GetDictionary(0, &page_action_value)) {
45 *error = ASCIIToUTF16(errors::kInvalidPageAction);
46 return false;
47 }
48 } else { // list_value_length > 1u.
49 *error = ASCIIToUTF16(errors::kInvalidPageActionsListSize);
50 return false;
51 }
52 } else if (value->HasKey(keys::kPageAction)) {
53 if (!value->GetDictionary(keys::kPageAction, &page_action_value)) {
54 *error = ASCIIToUTF16(errors::kInvalidPageAction);
55 return false;
56 }
57 }
58
59 // If page_action_value is not NULL, then there was a valid page action.
60 if (page_action_value) {
61 page_action_info = manifest_handler_helpers::LoadActionInfo(
62 extension, page_action_value, error);
63 if (!page_action_info)
64 return false; // Failed to parse page action definition.
65 }
66 ActionInfo::SetPageActionInfo(extension, page_action_info.release());
67
68 return true;
69 }
70
71 const ManifestMultiKeyHandler::KeySet PageActionHandler::key_set() {
72 ManifestMultiKeyHandler::KeySet page_action_keys;
73 page_action_keys.push_back(extension_manifest_keys::kPageAction);
74 page_action_keys.push_back(extension_manifest_keys::kPageActions);
75 return page_action_keys;
76 }
77
78 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698