| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 57 // account. | 59 // account. |
| 58 void CreateCustomEvent(gin::Arguments* arguments, | 60 void CreateCustomEvent(gin::Arguments* arguments, |
| 59 v8::Local<v8::Value> v8_event_name, | 61 v8::Local<v8::Value> v8_event_name, |
| 60 v8::Local<v8::Value> unused_schema, | 62 v8::Local<v8::Value> unused_schema, |
| 61 bool supports_filters); | 63 bool supports_filters); |
| 62 | 64 |
| 63 // Invalidates an event, removing its listeners and preventing any more from | 65 // Invalidates an event, removing its listeners and preventing any more from |
| 64 // being added. | 66 // being added. |
| 65 void InvalidateEvent(gin::Arguments* arguments, v8::Local<v8::Object> event); | 67 void InvalidateEvent(gin::Arguments* arguments, v8::Local<v8::Object> event); |
| 66 | 68 |
| 69 // Sets the last error in the context. |
| 70 void SetLastError(gin::Arguments* arguments, const std::string& error); |
| 71 |
| 72 // Clears the last error in the context. |
| 73 void ClearLastError(gin::Arguments* arguments); |
| 74 |
| 75 // Returns true if there is a set lastError in the given context. |
| 76 void HasLastError(gin::Arguments* arguments); |
| 77 |
| 78 // Sets the lastError in the given context, runs the provided callback, and |
| 79 // then clears the last error. |
| 80 void RunCallbackWithLastError(gin::Arguments* arguments, |
| 81 const std::string& error, |
| 82 v8::Local<v8::Function> callback); |
| 83 |
| 67 // Type references. Guaranteed to outlive this object. | 84 // Type references. Guaranteed to outlive this object. |
| 68 const APITypeReferenceMap* type_refs_; | 85 const APITypeReferenceMap* type_refs_; |
| 69 | 86 |
| 70 // The request handler. Guaranteed to outlive this object. | 87 // The request handler. Guaranteed to outlive this object. |
| 71 APIRequestHandler* request_handler_; | 88 APIRequestHandler* request_handler_; |
| 72 | 89 |
| 73 // The event handler. Guaranteed to outlive this object. | 90 // The event handler. Guaranteed to outlive this object. |
| 74 APIEventHandler* event_handler_; | 91 APIEventHandler* event_handler_; |
| 75 | 92 |
| 93 binding::RunJSFunction run_js_; |
| 94 |
| 76 DISALLOW_COPY_AND_ASSIGN(APIBindingJSUtil); | 95 DISALLOW_COPY_AND_ASSIGN(APIBindingJSUtil); |
| 77 }; | 96 }; |
| 78 | 97 |
| 79 } // namespace extensions | 98 } // namespace extensions |
| 80 | 99 |
| 81 #endif // EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_ | 100 #endif // EXTENSIONS_RENDERER_API_BINDING_JS_UTIL_H_ |
| OLD | NEW |