OLD | NEW |
(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(Extension* extension, string16* error) { |
| 26 scoped_ptr<ActionInfo> page_action_info; |
| 27 const DictionaryValue* page_action_value = NULL; |
| 28 |
| 29 if (extension->manifest()->HasKey(keys::kPageActions)) { |
| 30 const ListValue* list_value = NULL; |
| 31 if (!extension->manifest()->GetList(keys::kPageActions, &list_value)) { |
| 32 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); |
| 33 return false; |
| 34 } |
| 35 |
| 36 size_t list_value_length = list_value->GetSize(); |
| 37 |
| 38 if (list_value_length == 0u) { |
| 39 // A list with zero items is allowed, and is equivalent to not having |
| 40 // a page_actions key in the manifest. Don't set |page_action_value|. |
| 41 } else if (list_value_length == 1u) { |
| 42 if (!list_value->GetDictionary(0, &page_action_value)) { |
| 43 *error = ASCIIToUTF16(errors::kInvalidPageAction); |
| 44 return false; |
| 45 } |
| 46 } else { // list_value_length > 1u. |
| 47 *error = ASCIIToUTF16(errors::kInvalidPageActionsListSize); |
| 48 return false; |
| 49 } |
| 50 } else if (extension->manifest()->HasKey(keys::kPageAction)) { |
| 51 if (!extension->manifest()->GetDictionary(keys::kPageAction, |
| 52 &page_action_value)) { |
| 53 *error = ASCIIToUTF16(errors::kInvalidPageAction); |
| 54 return false; |
| 55 } |
| 56 } |
| 57 |
| 58 // If page_action_value is not NULL, then there was a valid page action. |
| 59 if (page_action_value) { |
| 60 page_action_info = manifest_handler_helpers::LoadActionInfo( |
| 61 extension, page_action_value, error); |
| 62 if (!page_action_info) |
| 63 return false; // Failed to parse page action definition. |
| 64 } |
| 65 ActionInfo::SetPageActionInfo(extension, page_action_info.release()); |
| 66 |
| 67 return true; |
| 68 } |
| 69 |
| 70 } // namespace extensions |
OLD | NEW |