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

Side by Side Diff: extensions/renderer/api_signature.h

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef EXTENSIONS_RENDERER_API_SIGNATURE_H_
6 #define EXTENSIONS_RENDERER_API_SIGNATURE_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "v8/include/v8.h"
14
15 namespace base {
16 class Value;
17 class ListValue;
18 }
19
20 namespace extensions {
21 class APITypeReferenceMap;
22 class ArgumentSpec;
23
24 // A representation of the expected signature for an API method, along with the
25 // ability to match provided arguments and convert them to base::Values.
26 class APISignature {
27 public:
28 explicit APISignature(const base::ListValue& specification);
29 explicit APISignature(std::vector<std::unique_ptr<ArgumentSpec>> signature);
30 ~APISignature();
31
32 // Parses |arguments| against this signature, and populates |args_out| with
33 // the v8 values (performing no conversion). The resulting vector may differ
34 // from the list of arguments passed in because it will include null-filled
35 // optional arguments.
36 // Returns true if the arguments were successfully parsed and converted.
37 bool ParseArgumentsToV8(v8::Local<v8::Context> context,
38 const std::vector<v8::Local<v8::Value>>& arguments,
39 const APITypeReferenceMap& type_refs,
40 std::vector<v8::Local<v8::Value>>* args_out,
41 std::string* error) const;
42
43 // Parses |arguments| against this signature, converting to a base::ListValue.
44 // Returns true if the arguments were successfully parsed and converted, and
45 // populates |args_out| and |callback_out| with the JSON arguments and
46 // callback values, respectively. On failure, returns false populates |error|.
47 bool ParseArgumentsToJSON(v8::Local<v8::Context> context,
48 const std::vector<v8::Local<v8::Value>>& arguments,
49 const APITypeReferenceMap& type_refs,
50 std::unique_ptr<base::ListValue>* args_out,
51 v8::Local<v8::Function>* callback_out,
52 std::string* error) const;
53
54 // Converts |arguments| to a base::ListValue, ignoring the defined signature.
55 // This is used when custom bindings modify the passed arguments to a form
56 // that doesn't match the documented signature.
57 bool ConvertArgumentsIgnoringSchema(
58 v8::Local<v8::Context> context,
59 const std::vector<v8::Local<v8::Value>>& arguments,
60 std::unique_ptr<base::ListValue>* json_out,
61 v8::Local<v8::Function>* callback_out) const;
62
63 // Returns a developer-readable string of the expected signature. For
64 // instance, if this signature expects a string 'someStr' and an optional int
65 // 'someInt', this would return "string someStr, optional integer someInt".
66 std::string GetExpectedSignature() const;
67
68 private:
69 // The list of expected arguments.
70 std::vector<std::unique_ptr<ArgumentSpec>> signature_;
71
72 // A developer-readable signature string, lazily set.
73 mutable std::string expected_signature_;
74
75 DISALLOW_COPY_AND_ASSIGN(APISignature);
76 };
77
78 } // namespace extensions
79
80 #endif // EXTENSIONS_RENDERER_API_SIGNATURE_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_request_handler_unittest.cc ('k') | extensions/renderer/api_signature.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698