Update To 11.40.268.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 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/browser_message_filter.h"
15 #include "url/gurl.h"
16
17 struct ExtensionHostMsg_Request_Params;
18
19 namespace base {
20 class DictionaryValue;
21 }
22
23 namespace content {
24 class BrowserContext;
25 class WebContents;
26 }
27
28 namespace extensions {
29
30 class InfoMap;
31
32 // This class filters out incoming extension-specific IPC messages from the
33 // renderer process. It is created on the UI thread. Messages may be handled on
34 // the IO thread or the UI thread.
35 class ExtensionMessageFilter : public content::BrowserMessageFilter {
36  public:
37   ExtensionMessageFilter(int render_process_id,
38                          content::BrowserContext* context);
39
40   int render_process_id() { return render_process_id_; }
41
42  private:
43   friend class content::BrowserThread;
44   friend class base::DeleteHelper<ExtensionMessageFilter>;
45
46   ~ExtensionMessageFilter() override;
47
48   // content::BrowserMessageFilter implementation.
49   void OverrideThreadForMessage(const IPC::Message& message,
50                                 content::BrowserThread::ID* thread) override;
51   void OnDestruct() const override;
52   bool OnMessageReceived(const IPC::Message& message) override;
53
54   // Message handlers on the UI thread.
55   void OnExtensionAddListener(const std::string& extension_id,
56                               const GURL& listener_url,
57                               const std::string& event_name);
58   void OnExtensionRemoveListener(const std::string& extension_id,
59                                  const GURL& listener_url,
60                                  const std::string& event_name);
61   void OnExtensionAddLazyListener(const std::string& extension_id,
62                                   const std::string& event_name);
63   void OnExtensionAttachGuest(int routing_id,
64                               int element_instance_id,
65                               int guest_instance_id,
66                               const base::DictionaryValue& attach_params);
67   void OnExtensionCreateMimeHandlerViewGuest(int render_frame_id,
68                                              const std::string& url,
69                                              const std::string& mime_type,
70                                              int element_instance_id);
71   void OnExtensionRemoveLazyListener(const std::string& extension_id,
72                                      const std::string& event_name);
73   void OnExtensionAddFilteredListener(const std::string& extension_id,
74                                       const std::string& event_name,
75                                       const base::DictionaryValue& filter,
76                                       bool lazy);
77   void OnExtensionRemoveFilteredListener(const std::string& extension_id,
78                                          const std::string& event_name,
79                                          const base::DictionaryValue& filter,
80                                          bool lazy);
81   void OnExtensionShouldSuspendAck(const std::string& extension_id,
82                                    int sequence_id);
83   void OnExtensionSuspendAck(const std::string& extension_id);
84   void OnExtensionTransferBlobsAck(const std::vector<std::string>& blob_uuids);
85
86   // Message handlers on the IO thread.
87   void OnExtensionGenerateUniqueID(int* unique_id);
88   void OnExtensionResumeRequests(int route_id);
89   void OnExtensionRequestForIOThread(
90       int routing_id,
91       const ExtensionHostMsg_Request_Params& params);
92
93   // Runs on UI thread.
94   void MimeHandlerViewGuestCreatedCallback(int element_instance_id,
95                                            int embedder_render_process_id,
96                                            int embedder_render_frame_id,
97                                            const std::string& src,
98                                            content::WebContents* web_contents);
99
100   const int render_process_id_;
101
102   // Should only be accessed on the UI thread.
103   content::BrowserContext* browser_context_;
104
105   scoped_refptr<extensions::InfoMap> extension_info_map_;
106
107   // Weak pointers produced by this factory are bound to the IO thread.
108   base::WeakPtrFactory<ExtensionMessageFilter> weak_ptr_factory_;
109
110   DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter);
111 };
112
113 }  // namespace extensions
114
115 #endif  // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_