Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_EXTENSION_BINDINGS_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_EXTENSION_BINDINGS_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_EXTENSION_BINDINGS_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_EXTENSION_BINDINGS_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 class DictionaryValue; | |
| 12 class ListValue; | 11 class ListValue; |
| 13 } | 12 } |
| 14 | 13 |
| 15 namespace extensions { | 14 namespace extensions { |
| 15 struct EventFilteringInfo; | |
|
lazyboy
2017/06/15 17:12:23
nit: struct after all class declarations.
Devlin
2017/06/15 18:01:06
Done.
| |
| 16 class RequestSender; | 16 class RequestSender; |
| 17 class ScriptContext; | 17 class ScriptContext; |
| 18 | 18 |
| 19 // The class responsible for creating extension bindings in different contexts, | 19 // The class responsible for creating extension bindings in different contexts, |
| 20 // as well as dispatching requests and handling responses, and dispatching | 20 // as well as dispatching requests and handling responses, and dispatching |
| 21 // events to listeners. | 21 // events to listeners. |
| 22 // This is designed to be used on a single thread, but should be safe to use on | 22 // This is designed to be used on a single thread, but should be safe to use on |
| 23 // threads other than the main thread (so that worker threads can have extension | 23 // threads other than the main thread (so that worker threads can have extension |
| 24 // bindings). | 24 // bindings). |
| 25 class ExtensionBindingsSystem { | 25 class ExtensionBindingsSystem { |
| 26 public: | 26 public: |
| 27 virtual ~ExtensionBindingsSystem() {} | 27 virtual ~ExtensionBindingsSystem() {} |
| 28 | 28 |
| 29 // Called when a new ScriptContext is created. | 29 // Called when a new ScriptContext is created. |
| 30 virtual void DidCreateScriptContext(ScriptContext* context) = 0; | 30 virtual void DidCreateScriptContext(ScriptContext* context) = 0; |
| 31 | 31 |
| 32 // Called when a ScriptContext is about to be released. | 32 // Called when a ScriptContext is about to be released. |
| 33 virtual void WillReleaseScriptContext(ScriptContext* context) = 0; | 33 virtual void WillReleaseScriptContext(ScriptContext* context) = 0; |
| 34 | 34 |
| 35 // Updates the bindings for a given |context|. This happens at initialization, | 35 // Updates the bindings for a given |context|. This happens at initialization, |
| 36 // but also when e.g. an extension gets updated permissions. | 36 // but also when e.g. an extension gets updated permissions. |
| 37 virtual void UpdateBindingsForContext(ScriptContext* context) = 0; | 37 virtual void UpdateBindingsForContext(ScriptContext* context) = 0; |
| 38 | 38 |
| 39 // Dispatches an event with the given |name|, |event_args|, and | 39 // Dispatches an event with the given |name|, |event_args|, and |
| 40 // |filtering_info| in the given |context|. | 40 // |filtering_info| in the given |context|. |
| 41 virtual void DispatchEventInContext( | 41 virtual void DispatchEventInContext(const std::string& event_name, |
| 42 const std::string& event_name, | 42 const base::ListValue* event_args, |
| 43 const base::ListValue* event_args, | 43 const EventFilteringInfo* filtering_info, |
| 44 const base::DictionaryValue* filtering_info, | 44 ScriptContext* context) = 0; |
| 45 ScriptContext* context) = 0; | |
| 46 | 45 |
| 47 // Returns true if there is a listener for the given |event_name| in the | 46 // Returns true if there is a listener for the given |event_name| in the |
| 48 // associated |context|. | 47 // associated |context|. |
| 49 virtual bool HasEventListenerInContext(const std::string& event_name, | 48 virtual bool HasEventListenerInContext(const std::string& event_name, |
| 50 ScriptContext* context) = 0; | 49 ScriptContext* context) = 0; |
| 51 | 50 |
| 52 // Handles the response associated with the given |request_id|. | 51 // Handles the response associated with the given |request_id|. |
| 53 virtual void HandleResponse(int request_id, | 52 virtual void HandleResponse(int request_id, |
| 54 bool success, | 53 bool success, |
| 55 const base::ListValue& response, | 54 const base::ListValue& response, |
| 56 const std::string& error) = 0; | 55 const std::string& error) = 0; |
| 57 | 56 |
| 58 // Returns the associated RequestSender, if any. | 57 // Returns the associated RequestSender, if any. |
| 59 // TODO(devlin): Factor this out. | 58 // TODO(devlin): Factor this out. |
| 60 virtual RequestSender* GetRequestSender() = 0; | 59 virtual RequestSender* GetRequestSender() = 0; |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 } // namespace extensions | 62 } // namespace extensions |
| 64 | 63 |
| 65 #endif // EXTENSIONS_RENDERER_EXTENSION_BINDINGS_SYSTEM_H_ | 64 #endif // EXTENSIONS_RENDERER_EXTENSION_BINDINGS_SYSTEM_H_ |
| OLD | NEW |