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

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

Issue 2469593002: [Extensions Bindings] Add Events support (Closed)
Patch Set: asantest Created 4 years, 1 month 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
« no previous file with comments | « extensions/renderer/api_binding_unittest.cc ('k') | extensions/renderer/api_bindings_system.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ 5 #ifndef EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_
6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "extensions/renderer/api_binding.h" 14 #include "extensions/renderer/api_binding.h"
15 #include "extensions/renderer/api_binding_types.h"
16 #include "extensions/renderer/api_event_handler.h"
15 #include "extensions/renderer/api_request_handler.h" 17 #include "extensions/renderer/api_request_handler.h"
16 #include "extensions/renderer/argument_spec.h" 18 #include "extensions/renderer/argument_spec.h"
17 19
18 namespace base { 20 namespace base {
19 class DictionaryValue; 21 class DictionaryValue;
20 class ListValue; 22 class ListValue;
21 } 23 }
22 24
23 namespace extensions { 25 namespace extensions {
24 class APIRequestHandler; 26 class APIRequestHandler;
(...skipping 11 matching lines...) Expand all
36 38
37 std::string request_id; 39 std::string request_id;
38 std::string method_name; 40 std::string method_name;
39 std::unique_ptr<base::ListValue> arguments; 41 std::unique_ptr<base::ListValue> arguments;
40 }; 42 };
41 43
42 using GetAPISchemaMethod = 44 using GetAPISchemaMethod =
43 base::Callback<const base::DictionaryValue&(const std::string&)>; 45 base::Callback<const base::DictionaryValue&(const std::string&)>;
44 using SendRequestMethod = base::Callback<void(std::unique_ptr<Request>)>; 46 using SendRequestMethod = base::Callback<void(std::unique_ptr<Request>)>;
45 47
46 APIBindingsSystem(const APIRequestHandler::CallJSFunction& call_js, 48 APIBindingsSystem(const binding::RunJSFunction& call_js,
47 const GetAPISchemaMethod& get_api_schema, 49 const GetAPISchemaMethod& get_api_schema,
48 const SendRequestMethod& send_request); 50 const SendRequestMethod& send_request);
49 ~APIBindingsSystem(); 51 ~APIBindingsSystem();
50 52
51 // Returns a new v8::Object representing the api specified by |api_name|. 53 // Returns a new v8::Object representing the api specified by |api_name|.
52 v8::Local<v8::Object> CreateAPIInstance( 54 v8::Local<v8::Object> CreateAPIInstance(
53 const std::string& api_name, 55 const std::string& api_name,
54 v8::Local<v8::Context> context, 56 v8::Local<v8::Context> context,
55 v8::Isolate* isolate, 57 v8::Isolate* isolate,
56 const APIBinding::AvailabilityCallback& is_available); 58 const APIBinding::AvailabilityCallback& is_available);
57 59
58 // Responds to the request with the given |request_id|, calling the callback 60 // Responds to the request with the given |request_id|, calling the callback
59 // with |response|. 61 // with |response|.
60 void CompleteRequest(const std::string& request_id, 62 void CompleteRequest(const std::string& request_id,
61 const base::ListValue& response); 63 const base::ListValue& response);
62 64
65 // Notifies the APIEventHandler to fire the corresponding event, notifying
66 // listeners.
67 void FireEventInContext(const std::string& event_name,
68 v8::Local<v8::Context> context,
69 const base::ListValue& response);
70
63 private: 71 private:
64 // Creates a new APIBinding for the given |api_name|. 72 // Creates a new APIBinding for the given |api_name|.
65 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); 73 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name);
66 74
67 // Handles a call into an API, adds a pending request to the 75 // Handles a call into an API, adds a pending request to the
68 // |request_handler_|, and calls |send_request_|. 76 // |request_handler_|, and calls |send_request_|.
69 void OnAPICall(const std::string& name, 77 void OnAPICall(const std::string& name,
70 std::unique_ptr<base::ListValue> arguments, 78 std::unique_ptr<base::ListValue> arguments,
71 v8::Isolate* isolate, 79 v8::Isolate* isolate,
72 v8::Local<v8::Context> context, 80 v8::Local<v8::Context> context,
73 v8::Local<v8::Function> callback); 81 v8::Local<v8::Function> callback);
74 82
75 // The map of cached API reference types. 83 // The map of cached API reference types.
76 ArgumentSpec::RefMap type_reference_map_; 84 ArgumentSpec::RefMap type_reference_map_;
77 85
78 // The request handler associated with the system. 86 // The request handler associated with the system.
79 APIRequestHandler request_handler_; 87 APIRequestHandler request_handler_;
80 88
89 // The event handler associated with the system.
90 APIEventHandler event_handler_;
91
81 // A map from api_name -> APIBinding for constructed APIs. APIBindings are 92 // A map from api_name -> APIBinding for constructed APIs. APIBindings are
82 // created lazily. 93 // created lazily.
83 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_; 94 std::map<std::string, std::unique_ptr<APIBinding>> api_bindings_;
84 95
85 // The method to retrieve the DictionaryValue describing a given extension 96 // The method to retrieve the DictionaryValue describing a given extension
86 // API. Curried in for testing purposes so we can use fake APIs. 97 // API. Curried in for testing purposes so we can use fake APIs.
87 GetAPISchemaMethod get_api_schema_; 98 GetAPISchemaMethod get_api_schema_;
88 99
89 // The method to call when a new API call is triggered. Curried in for testing 100 // The method to call when a new API call is triggered. Curried in for testing
90 // purposes. Typically, this would send an IPC to the browser to begin the 101 // purposes. Typically, this would send an IPC to the browser to begin the
91 // function work. 102 // function work.
92 SendRequestMethod send_request_; 103 SendRequestMethod send_request_;
93 104
94 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); 105 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem);
95 }; 106 };
96 107
97 } // namespace 108 } // namespace
98 109
99 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ 110 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_binding_unittest.cc ('k') | extensions/renderer/api_bindings_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698