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_
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"
17 struct ExtensionHostMsg_Request_Params
;
20 class DictionaryValue
;
27 namespace extensions
{
31 // This class filters out incoming extension-specific IPC messages from the
32 // renderer process. It is created on the UI thread. Messages may be handled on
33 // the IO thread or the UI thread.
34 class ExtensionMessageFilter
: public content::BrowserMessageFilter
{
36 ExtensionMessageFilter(int render_process_id
,
37 content::BrowserContext
* context
);
39 int render_process_id() { return render_process_id_
; }
42 friend class content::BrowserThread
;
43 friend class base::DeleteHelper
<ExtensionMessageFilter
>;
45 virtual ~ExtensionMessageFilter();
47 // content::BrowserMessageFilter implementation.
48 virtual void OverrideThreadForMessage(
49 const IPC::Message
& message
,
50 content::BrowserThread::ID
* thread
) OVERRIDE
;
51 virtual void OnDestruct() const OVERRIDE
;
52 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
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 OnExtensionRemoveLazyListener(const std::string
& extension_id
,
68 const std::string
& event_name
);
69 void OnExtensionAddFilteredListener(const std::string
& extension_id
,
70 const std::string
& event_name
,
71 const base::DictionaryValue
& filter
,
73 void OnExtensionRemoveFilteredListener(const std::string
& extension_id
,
74 const std::string
& event_name
,
75 const base::DictionaryValue
& filter
,
77 void OnExtensionShouldSuspendAck(const std::string
& extension_id
,
79 void OnExtensionSuspendAck(const std::string
& extension_id
);
80 void OnExtensionTransferBlobsAck(const std::vector
<std::string
>& blob_uuids
);
82 // Message handlers on the IO thread.
83 void OnExtensionGenerateUniqueID(int* unique_id
);
84 void OnExtensionResumeRequests(int route_id
);
85 void OnExtensionRequestForIOThread(
87 const ExtensionHostMsg_Request_Params
& params
);
89 const int render_process_id_
;
91 // Should only be accessed on the UI thread.
92 content::BrowserContext
* browser_context_
;
94 scoped_refptr
<extensions::InfoMap
> extension_info_map_
;
96 // Weak pointers produced by this factory are bound to the IO thread.
97 base::WeakPtrFactory
<ExtensionMessageFilter
> weak_ptr_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter
);
102 } // namespace extensions
104 #endif // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_