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

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

Issue 2762623003: [Extensions Bindings] Add lastError utilities to APIBindingJSUtil (Closed)
Patch Set: . Created 3 years, 9 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_BINDING_JS_UTIL_H_ 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_
6 #define EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_ 6 #define EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "extensions/renderer/api_binding_types.h"
11 #include "gin/wrappable.h" 12 #include "gin/wrappable.h"
12 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
13 14
14 namespace gin { 15 namespace gin {
15 class Arguments; 16 class Arguments;
16 } 17 }
17 18
18 namespace extensions { 19 namespace extensions {
19 class APIEventHandler; 20 class APIEventHandler;
20 class APIRequestHandler; 21 class APIRequestHandler;
21 class APITypeReferenceMap; 22 class APITypeReferenceMap;
22 23
23 // An object that exposes utility methods to the existing JS bindings, such as 24 // An object that exposes utility methods to the existing JS bindings, such as
24 // sendRequest and registering event argument massagers. If/when we get rid of 25 // sendRequest and registering event argument massagers. If/when we get rid of
25 // some of our JS bindings, we can reduce or remove this class. 26 // some of our JS bindings, we can reduce or remove this class.
26 class APIBindingJSUtil final : public gin::Wrappable<APIBindingJSUtil> { 27 class APIBindingJSUtil final : public gin::Wrappable<APIBindingJSUtil> {
27 public: 28 public:
28 APIBindingJSUtil(const APITypeReferenceMap* type_refs, 29 APIBindingJSUtil(const APITypeReferenceMap* type_refs,
29 APIRequestHandler* request_handler, 30 APIRequestHandler* request_handler,
30 APIEventHandler* event_handler); 31 APIEventHandler* event_handler,
32 const binding::RunJSFunction& run_js);
31 ~APIBindingJSUtil() override; 33 ~APIBindingJSUtil() override;
32 34
33 static gin::WrapperInfo kWrapperInfo; 35 static gin::WrapperInfo kWrapperInfo;
34 36
35 // gin::Wrappable: 37 // gin::Wrappable:
36 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 38 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
37 v8::Isolate* isolate) final; 39 v8::Isolate* isolate) final;
38 40
39 private: 41 private:
40 // A handler to initiate an API request through the APIRequestHandler. A 42 // A handler to initiate an API request through the APIRequestHandler. A
(...skipping 14 matching lines...) Expand all
55 // at least options into account. 57 // at least options into account.
56 void CreateCustomEvent(gin::Arguments* arguments, 58 void CreateCustomEvent(gin::Arguments* arguments,
57 v8::Local<v8::Value> v8_event_name, 59 v8::Local<v8::Value> v8_event_name,
58 v8::Local<v8::Value> unused_schema, 60 v8::Local<v8::Value> unused_schema,
59 v8::Local<v8::Value> unused_event_options); 61 v8::Local<v8::Value> unused_event_options);
60 62
61 // Invalidates an event, removing its listeners and preventing any more from 63 // Invalidates an event, removing its listeners and preventing any more from
62 // being added. 64 // being added.
63 void InvalidateEvent(gin::Arguments* arguments, v8::Local<v8::Object> event); 65 void InvalidateEvent(gin::Arguments* arguments, v8::Local<v8::Object> event);
64 66
67 // Sets the last error in the context.
68 void SetLastError(gin::Arguments* arguments, const std::string& error);
69
70 // Clears the last error in the context.
71 void ClearLastError(gin::Arguments* arguments);
72
73 // Returns true if there is a set lastError in the given context.
74 void HasLastError(gin::Arguments* arguments);
75
76 // Sets the lastError in the given context, runs the provided callback with
77 // the supplied arguments, and then clears the last error.
78 void RunCallbackWithLastError(
79 gin::Arguments* arguments,
80 const std::string& error,
81 v8::Local<v8::Function> callback,
82 std::vector<v8::Local<v8::Value>> callback_args);
jbroman 2017/03/20 20:14:49 Is it advantageous to provide the arguments separa
Devlin 2017/03/20 23:10:40 Nope - this was just for parity with the JS equiva
83
65 // Type references. Guaranteed to outlive this object. 84 // Type references. Guaranteed to outlive this object.
66 const APITypeReferenceMap* type_refs_; 85 const APITypeReferenceMap* type_refs_;
67 86
68 // The request handler. Guaranteed to outlive this object. 87 // The request handler. Guaranteed to outlive this object.
69 APIRequestHandler* request_handler_; 88 APIRequestHandler* request_handler_;
70 89
71 // The event handler. Guaranteed to outlive this object. 90 // The event handler. Guaranteed to outlive this object.
72 APIEventHandler* event_handler_; 91 APIEventHandler* event_handler_;
73 92
93 binding::RunJSFunction run_js_;
94
74 DISALLOW_COPY_AND_ASSIGN(APIBindingJSUtil); 95 DISALLOW_COPY_AND_ASSIGN(APIBindingJSUtil);
75 }; 96 };
76 97
77 } // namespace extensions 98 } // namespace extensions
78 99
79 #endif // EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_ 100 #endif // EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698