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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_
6 #define EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_
10 #include "extensions/renderer/script_context_set.h"
13 class DictionaryValue
;
24 namespace extensions
{
27 class ObjectBackedNativeHandler
;
29 // Manually implements JavaScript bindings for extension messaging.
31 // 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
34 class MessagingBindings
{
36 // Creates an instance of the extension.
37 static ObjectBackedNativeHandler
* Get(Dispatcher
* dispatcher
,
38 ScriptContext
* context
);
40 // Dispatches the onConnect content script messaging event to some contexts
41 // in |contexts|. If |restrict_to_render_view| is specified, only contexts in
42 // that render view will receive the message.
43 static void DispatchOnConnect(const ScriptContextSet::ContextSet
& contexts
,
45 const std::string
& channel_name
,
46 const base::DictionaryValue
& source_tab
,
47 const std::string
& source_extension_id
,
48 const std::string
& target_extension_id
,
49 const GURL
& source_url
,
50 const std::string
& tls_channel_id
,
51 content::RenderView
* restrict_to_render_view
);
53 // 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 // specified, only contexts in that render view will receive the message.
56 static void DeliverMessage(const ScriptContextSet::ContextSet
& context_set
,
58 const Message
& message
,
59 content::RenderView
* restrict_to_render_view
);
61 // Dispatches the onDisconnect event in response to the channel being closed.
62 static void DispatchOnDisconnect(
63 const ScriptContextSet::ContextSet
& context_set
,
65 const std::string
& error_message
,
66 content::RenderView
* restrict_to_render_view
);
69 } // namespace extensions
71 #endif // EXTENSIONS_RENDERER_MESSAGING_BINDINGS_H_