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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_messaging_host_manifest.cc

Issue 12285015: Require manifests for native messaging hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/browser/extensions/api/messaging/native_messaging_host_manifest .h"
6
7 #include "base/json/json_file_value_serializer.h"
8 #include "base/logging.h"
9 #include "base/values.h"
10
11 namespace extensions {
12
13 NativeMessagingHostManifest::~NativeMessagingHostManifest() {}
14
15 // static
16 scoped_ptr<NativeMessagingHostManifest> NativeMessagingHostManifest::Load(
17 const FilePath& file_path,
18 std::string* error_message) {
19 DCHECK(error_message);
20
21 JSONFileValueSerializer serializer(file_path);
22 scoped_ptr<base::Value> parsed(serializer.Deserialize(NULL, error_message));
23 if (!parsed) {
24 return scoped_ptr<NativeMessagingHostManifest>();
25 }
26
27 base::DictionaryValue* dictionary;
28 if (!parsed->GetAsDictionary(&dictionary)) {
29 *error_message = "Invalid manifest file.";
30 return scoped_ptr<NativeMessagingHostManifest>();
31 }
32
33 scoped_ptr<NativeMessagingHostManifest> result(
34 new NativeMessagingHostManifest());
35 if (!result->Parse(dictionary, error_message)) {
36 return scoped_ptr<NativeMessagingHostManifest>();
37 }
38
39 return result.Pass();
40 }
41
42 bool NativeMessagingHostManifest::IsAllowedOrigin(const std::string& origin) {
43 return allowed_origins_.find(origin) != allowed_origins_.end();
44 }
45
46 NativeMessagingHostManifest::NativeMessagingHostManifest() {
47 }
48
49 bool NativeMessagingHostManifest::Parse(base::DictionaryValue* dictionary,
50 std::string* error_message) {
51 scoped_ptr<NativeMessagingHostManifest> result(
Matt Perry 2013/02/16 02:00:51 unused
Sergey Ulanov 2013/02/20 00:05:36 Done.
52 new NativeMessagingHostManifest());
53
54 std::string type;
55 std::string path;
56 if (!dictionary->GetString("name", &name_) ||
57 !dictionary->GetString("description", &description_) ||
58 !dictionary->GetString("type", &type) ||
59 !dictionary->GetString("path", &path)) {
60 *error_message = "Invalid manifest file.";
Matt Perry 2013/02/16 02:00:51 Better: "Invalid value for <key>"
Matt Perry 2013/02/16 02:00:51 Also, maybe description should be optional.
Sergey Ulanov 2013/02/20 00:05:36 I think it's better if it is required. It doesn't
Sergey Ulanov 2013/02/20 00:05:36 Done.
61 return false;
62 }
63
64 if (type == "stdio") {
65 interface_ = HOST_INTERFACE_STDIO;
66 } else {
67 *error_message = "Unknown native messaging host type: " + type;
Matt Perry 2013/02/16 02:00:51 Better for consistency: "Invalid value for type: "
Sergey Ulanov 2013/02/20 00:05:36 Done.
68 return false;
69 }
70
71 // JSON parsed checks that all strings are valid UTF8.
72 path_ = FilePath::FromUTF8Unsafe(path);
73
74 const base::ListValue* allowed_origins_list;
75 if (!dictionary->GetList("allowed_origins", &allowed_origins_list)) {
76 *error_message = "allowed_origins must be list of strings.";
Matt Perry 2013/02/16 02:00:51 Better for consistency: "Invalid value for allowed
Matt Perry 2013/02/16 02:00:51 Isn't allowed_origins optional?
Sergey Ulanov 2013/02/20 00:05:36 Done.
Sergey Ulanov 2013/02/20 00:05:36 No, it's not optional. Access to each native host
77 return false;
78 }
79 allowed_origins_.clear();
80 for (base::ListValue::const_iterator it = allowed_origins_list->begin();
81 it != allowed_origins_list->end(); ++it) {
82 std::string origin;
83 if (!(*it)->GetAsString(&origin)) {
84 *error_message = "allowed_origins must be list of strings.";
85 return false;
86 }
87 allowed_origins_.insert(origin);
Matt Perry 2013/02/16 02:00:51 are these strings, or URL patterns? Extensions use
Sergey Ulanov 2013/02/20 00:05:36 Updated this code to use URLPattern and URLPattern
88 }
89
90 return true;
91 }
92
93 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698