OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MESSAGING_BINDINGS_H_ | 5 #ifndef EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
6 #define EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ | 6 #define EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "extensions/renderer/script_context_set.h" | 10 #include "extensions/renderer/script_context_set.h" |
11 | 11 |
| 12 struct ExtensionMsg_ExternalConnectionInfo; |
| 13 |
12 namespace base { | 14 namespace base { |
13 class DictionaryValue; | 15 class DictionaryValue; |
14 } | 16 } |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 class RenderView; | 19 class RenderView; |
18 } | 20 } |
19 | 21 |
20 namespace v8 { | 22 namespace v8 { |
21 class Extension; | 23 class Extension; |
22 } | 24 } |
23 | 25 |
24 namespace extensions { | 26 namespace extensions { |
25 class Dispatcher; | 27 class Dispatcher; |
26 struct Message; | 28 struct Message; |
27 class ObjectBackedNativeHandler; | 29 class ObjectBackedNativeHandler; |
| 30 class ScriptContextSet; |
28 | 31 |
29 // Manually implements JavaScript bindings for extension messaging. | 32 // Manually implements JavaScript bindings for extension messaging. |
30 // | 33 // |
31 // TODO(aa): This should all get re-implemented using SchemaGeneratedBindings. | 34 // TODO(aa): This should all get re-implemented using SchemaGeneratedBindings. |
32 // If anything needs to be manual for some reason, it should be implemented in | 35 // If anything needs to be manual for some reason, it should be implemented in |
33 // its own class. | 36 // its own class. |
34 class MessagingBindings { | 37 class MessagingBindings { |
35 public: | 38 public: |
36 // Creates an instance of the extension. | 39 // Creates an instance of the extension. |
37 static ObjectBackedNativeHandler* Get(Dispatcher* dispatcher, | 40 static ObjectBackedNativeHandler* Get(Dispatcher* dispatcher, |
38 ScriptContext* context); | 41 ScriptContext* context); |
39 | 42 |
40 // Dispatches the onConnect content script messaging event to some contexts | 43 // Dispatches the onConnect content script messaging event to some contexts |
41 // in |contexts|. If |restrict_to_render_view| is specified, only contexts in | 44 // in |context_set|. If |restrict_to_render_view| is specified, only contexts |
42 // that render view will receive the message. | 45 // in that render view will receive the message. |
43 static void DispatchOnConnect(const ScriptContextSet::ContextSet& contexts, | 46 static void DispatchOnConnect(const ScriptContextSet& context_set, |
44 int target_port_id, | 47 int target_port_id, |
45 const std::string& channel_name, | 48 const std::string& channel_name, |
46 const base::DictionaryValue& source_tab, | 49 const base::DictionaryValue& source_tab, |
47 const std::string& source_extension_id, | 50 const ExtensionMsg_ExternalConnectionInfo& info, |
48 const std::string& target_extension_id, | |
49 const GURL& source_url, | |
50 const std::string& tls_channel_id, | 51 const std::string& tls_channel_id, |
51 content::RenderView* restrict_to_render_view); | 52 content::RenderView* restrict_to_render_view); |
52 | 53 |
53 // Delivers a message sent using content script messaging to some of the | 54 // Delivers a message sent using content script messaging to some of the |
54 // contexts in |bindings_context_set|. If |restrict_to_render_view| is | 55 // contexts in |bindings_context_set|. If |restrict_to_render_view| is |
55 // specified, only contexts in that render view will receive the message. | 56 // specified, only contexts in that render view will receive the message. |
56 static void DeliverMessage(const ScriptContextSet::ContextSet& context_set, | 57 static void DeliverMessage(const ScriptContextSet& context_set, |
57 int target_port_id, | 58 int target_port_id, |
58 const Message& message, | 59 const Message& message, |
59 content::RenderView* restrict_to_render_view); | 60 content::RenderView* restrict_to_render_view); |
60 | 61 |
61 // Dispatches the onDisconnect event in response to the channel being closed. | 62 // Dispatches the onDisconnect event in response to the channel being closed. |
62 static void DispatchOnDisconnect( | 63 static void DispatchOnDisconnect( |
63 const ScriptContextSet::ContextSet& context_set, | 64 const ScriptContextSet& context_set, |
64 int port_id, | 65 int port_id, |
65 const std::string& error_message, | 66 const std::string& error_message, |
66 content::RenderView* restrict_to_render_view); | 67 content::RenderView* restrict_to_render_view); |
67 }; | 68 }; |
68 | 69 |
69 } // namespace extensions | 70 } // namespace extensions |
70 | 71 |
71 #endif // EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ | 72 #endif // EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_ |
OLD | NEW |