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

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

Issue 16171011: Move parsing of NaCl modules out of Extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/manifest_handlers/nacl_modules_handler.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "chrome/common/extensions/extension_manifest_constants.h"
13 #include "extensions/common/error_utils.h"
14
15 namespace extensions {
16
17 namespace keys = extension_manifest_keys;
18 namespace errors = extension_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));
not at google - send to devlin 2013/05/29 16:29:21 I feel like GetManifestData should be called like
Yoyo Zhou 2013/05/29 22:27:47 Sounds reasonable. We could have exactly the same
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,
44 string16* error) {
45 const ListValue* list_value = NULL;
46 if (!extension->manifest()->GetList(keys::kNaClModules, &list_value)) {
47 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
48 return false;
49 }
50
51 scoped_ptr<NaClModuleData> nacl_module_data(new NaClModuleData);
52
53 for (size_t i = 0; i < list_value->GetSize(); ++i) {
54 const DictionaryValue* module_value = NULL;
55 if (!list_value->GetDictionary(i, &module_value)) {
56 *error = ASCIIToUTF16(errors::kInvalidNaClModules);
57 return false;
58 }
59
60 // Get nacl_modules[i].path.
61 std::string path_str;
62 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) {
63 *error = ErrorUtils::FormatErrorMessageUTF16(
64 errors::kInvalidNaClModulesPath, base::IntToString(i));
65 return false;
66 }
67
68 // Get nacl_modules[i].mime_type.
69 std::string mime_type;
70 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) {
71 *error = ErrorUtils::FormatErrorMessageUTF16(
72 errors::kInvalidNaClModulesMIMEType, base::IntToString(i));
73 return false;
74 }
75
76 nacl_module_data->nacl_modules_.push_back(NaClModuleInfo());
77 nacl_module_data->nacl_modules_.back().url =
78 extension->GetResourceURL(path_str);
79 nacl_module_data->nacl_modules_.back().mime_type = mime_type;
80 }
81
82 extension->SetManifestData(keys::kNaClModules, nacl_module_data.release());
83 return true;
84 }
85
86 const std::vector<std::string> NaClModulesHandler::Keys() const {
87 return SingleKey(keys::kNaClModules);
88 }
89
90 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698