Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / extensions / browser / extension_message_filter.h
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.
4
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/browser_message_filter.h"
14
15 struct ExtensionHostMsg_Request_Params;
16
17 namespace base {
18 class DictionaryValue;
19 }
20
21 namespace content {
22 class BrowserContext;
23 }
24
25 namespace extensions {
26
27 class InfoMap;
28
29 // This class filters out incoming extension-specific IPC messages from the
30 // renderer process. It is created on the UI thread. Messages may be handled on
31 // the IO thread or the UI thread.
32 class ExtensionMessageFilter : public content::BrowserMessageFilter {
33  public:
34   ExtensionMessageFilter(int render_process_id,
35                          content::BrowserContext* context);
36
37   int render_process_id() { return render_process_id_; }
38
39  private:
40   virtual ~ExtensionMessageFilter();
41
42   // content::BrowserMessageFilter implementation.
43   virtual void OverrideThreadForMessage(
44       const IPC::Message& message,
45       content::BrowserThread::ID* thread) OVERRIDE;
46   virtual bool OnMessageReceived(const IPC::Message& message,
47                                  bool* message_was_ok) OVERRIDE;
48
49   // Message handlers on the UI thread.
50   void OnExtensionAddListener(const std::string& extension_id,
51                               const std::string& event_name);
52   void OnExtensionRemoveListener(const std::string& extension_id,
53                                  const std::string& event_name);
54   void OnExtensionAddLazyListener(const std::string& extension_id,
55                                   const std::string& event_name);
56   void OnExtensionRemoveLazyListener(const std::string& extension_id,
57                                      const std::string& event_name);
58   void OnExtensionAddFilteredListener(const std::string& extension_id,
59                                       const std::string& event_name,
60                                       const base::DictionaryValue& filter,
61                                       bool lazy);
62   void OnExtensionRemoveFilteredListener(const std::string& extension_id,
63                                          const std::string& event_name,
64                                          const base::DictionaryValue& filter,
65                                          bool lazy);
66   void OnExtensionShouldSuspendAck(const std::string& extension_id,
67                                    int sequence_id);
68   void OnExtensionSuspendAck(const std::string& extension_id);
69
70   // Message handlers on the IO thread.
71   void OnExtensionGenerateUniqueID(int* unique_id);
72   void OnExtensionResumeRequests(int route_id);
73   void OnExtensionRequestForIOThread(
74       int routing_id,
75       const ExtensionHostMsg_Request_Params& params);
76
77   const int render_process_id_;
78
79   // Should only be accessed on the UI thread.
80   content::BrowserContext* browser_context_;
81
82   scoped_refptr<extensions::InfoMap> extension_info_map_;
83
84   base::WeakPtrFactory<ExtensionMessageFilter> weak_ptr_factory_;
85
86   DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter);
87 };
88
89 }  // namespace extensions
90
91 #endif  // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_