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_BROWSER_EXTENSION_MESSAGE_FILTER_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_
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"
15 struct ExtensionHostMsg_Request_Params
;
18 class DictionaryValue
;
25 namespace extensions
{
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
{
34 ExtensionMessageFilter(int render_process_id
,
35 content::BrowserContext
* context
);
37 int render_process_id() { return render_process_id_
; }
40 virtual ~ExtensionMessageFilter();
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
;
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
,
62 void OnExtensionRemoveFilteredListener(const std::string
& extension_id
,
63 const std::string
& event_name
,
64 const base::DictionaryValue
& filter
,
66 void OnExtensionShouldSuspendAck(const std::string
& extension_id
,
68 void OnExtensionSuspendAck(const std::string
& extension_id
);
70 // Message handlers on the IO thread.
71 void OnExtensionGenerateUniqueID(int* unique_id
);
72 void OnExtensionResumeRequests(int route_id
);
73 void OnExtensionRequestForIOThread(
75 const ExtensionHostMsg_Request_Params
& params
);
77 const int render_process_id_
;
79 // Should only be accessed on the UI thread.
80 content::BrowserContext
* browser_context_
;
82 scoped_refptr
<extensions::InfoMap
> extension_info_map_
;
84 base::WeakPtrFactory
<ExtensionMessageFilter
> weak_ptr_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter
);
89 } // namespace extensions
91 #endif // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_