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 "components/keyed_service/core/keyed_service_shutdown_notifier.h"
15 #include "content/public/browser/browser_message_filter.h"
27 namespace extensions
{
30 // This class filters out incoming extension-specific IPC messages from the
31 // renderer process. It is created and destroyed on the UI thread and handles
33 class ExtensionMessageFilter
: public content::BrowserMessageFilter
{
35 ExtensionMessageFilter(int render_process_id
,
36 content::BrowserContext
* context
);
38 int render_process_id() { return render_process_id_
; }
40 static void EnsureShutdownNotifierFactoryBuilt();
43 friend class base::DeleteHelper
<ExtensionMessageFilter
>;
44 friend class content::BrowserThread
;
46 ~ExtensionMessageFilter() override
;
48 EventRouter
* GetEventRouter();
50 void ShutdownOnUIThread();
52 // content::BrowserMessageFilter implementation:
53 void OverrideThreadForMessage(const IPC::Message
& message
,
54 content::BrowserThread::ID
* thread
) override
;
55 void OnDestruct() const override
;
56 bool OnMessageReceived(const IPC::Message
& message
) override
;
58 // Message handlers on the UI thread.
59 void OnExtensionAddListener(const std::string
& extension_id
,
60 const GURL
& listener_url
,
61 const std::string
& event_name
);
62 void OnExtensionRemoveListener(const std::string
& extension_id
,
63 const GURL
& listener_url
,
64 const std::string
& event_name
);
65 void OnExtensionAddLazyListener(const std::string
& extension_id
,
66 const std::string
& event_name
);
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
);
81 void OnExtensionWakeEventPage(int request_id
,
82 const std::string
& extension_id
);
84 // Responds to the ExtensionHostMsg_WakeEventPage message.
85 void SendWakeEventPageResponse(int request_id
, bool success
);
87 const int render_process_id_
;
89 scoped_ptr
<KeyedServiceShutdownNotifier::Subscription
> shutdown_notifier_
;
91 // Only access from the UI thread.
92 content::BrowserContext
* browser_context_
;
94 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter
);
97 } // namespace extensions
99 #endif // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_