Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / manifest_handlers / nacl_modules_handler.cc
blob6715b2e4133ac2e85d333602cc03729b38026ccc
1 // Copyright 2014 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.
5 #include "extensions/common/manifest_handlers/nacl_modules_handler.h"
7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "extensions/common/error_utils.h"
13 #include "extensions/common/manifest_constants.h"
15 namespace extensions {
17 namespace keys = manifest_keys;
18 namespace errors = manifest_errors;
20 namespace {
22 struct NaClModuleData : Extension::ManifestData {
23 // Optional list of NaCl modules and associated properties.
24 NaClModuleInfo::List nacl_modules_;
27 } // namespace
29 // static
30 const NaClModuleInfo::List* NaClModuleInfo::GetNaClModules(
31 const Extension* extension) {
32 NaClModuleData* data = static_cast<NaClModuleData*>(
33 extension->GetManifestData(keys::kNaClModules));
34 return data ? &data->nacl_modules_ : NULL;
37 NaClModulesHandler::NaClModulesHandler() {
40 NaClModulesHandler::~NaClModulesHandler() {
43 bool NaClModulesHandler::Parse(Extension* extension, base::string16* error) {
44 const base::ListValue* list_value = NULL;
45 if (!extension->manifest()->GetList(keys::kNaClModules, &list_value)) {
46 *error = base::ASCIIToUTF16(errors::kInvalidNaClModules);
47 return false;
50 scoped_ptr<NaClModuleData> nacl_module_data(new NaClModuleData);
52 for (size_t i = 0; i < list_value->GetSize(); ++i) {
53 const base::DictionaryValue* module_value = NULL;
54 if (!list_value->GetDictionary(i, &module_value)) {
55 *error = base::ASCIIToUTF16(errors::kInvalidNaClModules);
56 return false;
59 // Get nacl_modules[i].path.
60 std::string path_str;
61 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) {
62 *error = ErrorUtils::FormatErrorMessageUTF16(
63 errors::kInvalidNaClModulesPath, base::IntToString(i));
64 return false;
67 // Get nacl_modules[i].mime_type.
68 std::string mime_type;
69 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) {
70 *error = ErrorUtils::FormatErrorMessageUTF16(
71 errors::kInvalidNaClModulesMIMEType, base::IntToString(i));
72 return false;
75 nacl_module_data->nacl_modules_.push_back(NaClModuleInfo());
76 nacl_module_data->nacl_modules_.back().url =
77 extension->GetResourceURL(path_str);
78 nacl_module_data->nacl_modules_.back().mime_type = mime_type;
81 extension->SetManifestData(keys::kNaClModules, nacl_module_data.release());
82 return true;
85 const std::vector<std::string> NaClModulesHandler::Keys() const {
86 return SingleKey(keys::kNaClModules);
89 } // namespace extensions