summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions/messaging_bindings.h
blob: 811bc777436504f883ed8b51d5273382e996020d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_EXTENSIONS_MESSAGING_BINDINGS_H_
#define CHROME_RENDERER_EXTENSIONS_MESSAGING_BINDINGS_H_

#include <string>

#include "chrome/renderer/extensions/chrome_v8_context_set.h"

namespace base {
class DictionaryValue;
}

namespace content {
class RenderView;
}

namespace v8 {
class Extension;
}

namespace extensions {
class ChromeV8Extension;
class Dispatcher;

// Manually implements JavaScript bindings for extension messaging.
//
// TODO(aa): This should all get re-implemented using SchemaGeneratedBindings.
// If anything needs to be manual for some reason, it should be implemented in
// its own class.
class MessagingBindings {
 public:
  // Creates an instance of the extension.
  static ChromeV8Extension* Get(Dispatcher* dispatcher,
                                ChromeV8Context* context);

  // Dispatches the onConnect content script messaging event to some contexts
  // in |contexts|. If |restrict_to_render_view| is specified, only contexts in
  // that render view will receive the message.
  static void DispatchOnConnect(
      const ChromeV8ContextSet::ContextSet& contexts,
      int target_port_id,
      const std::string& channel_name,
      const base::DictionaryValue& source_tab,
      const std::string& source_extension_id,
      const std::string& target_extension_id,
      const GURL& source_url,
      content::RenderView* restrict_to_render_view);

  // Delivers a message sent using content script messaging to some of the
  // contexts in |bindings_context_set|. If |restrict_to_render_view| is
  // specified, only contexts in that render view will receive the message.
  static void DeliverMessage(
      const ChromeV8ContextSet::ContextSet& context_set,
      int target_port_id,
      const std::string& message,
      content::RenderView* restrict_to_render_view);

  // Dispatches the onDisconnect event in response to the channel being closed.
  static void DispatchOnDisconnect(
      const ChromeV8ContextSet::ContextSet& context_set,
      int port_id,
      const std::string& error_message,
      content::RenderView* restrict_to_render_view);
};

}  // namespace extensions

#endif  // CHROME_RENDERER_EXTENSIONS_MESSAGING_BINDINGS_H_