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

Side by Side Diff: chrome/common/extensions/manifest_handlers/nacl_modules_handler.cc

Issue 435343002: Move NaClModulesHandler to src/extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (nacl-modules) rebase, fix gyp Created 6 years, 4 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 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/manifest_handlers/nacl_modules_handler.h"
6
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"
14
15 namespace extensions {
16
17 namespace keys = manifest_keys;
18 namespace errors = manifest_errors;
19
20 namespace {
21
22 struct NaClModuleData : Extension::ManifestData {
23 // Optional list of NaCl modules and associated properties.
24 NaClModuleInfo::List nacl_modules_;
25 };
26
27 } // namespace
28
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;
35 }
36
37 NaClModulesHandler::NaClModulesHandler() {
38 }
39
40 NaClModulesHandler::~NaClModulesHandler() {
41 }
42
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;
48 }
49
50 scoped_ptr<NaClModuleData> nacl_module_data(new NaClModuleData);
51
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;
57 }
58
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;
65 }
66
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;
73 }
74
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;
79 }
80
81 extension->SetManifestData(keys::kNaClModules, nacl_module_data.release());
82 return true;
83 }
84
85 const std::vector<std::string> NaClModulesHandler::Keys() const {
86 return SingleKey(keys::kNaClModules);
87 }
88
89 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_handlers/nacl_modules_handler.h ('k') | extensions/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698