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
;
28 namespace extensions
{
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
{
37 ExtensionMessageFilter(int render_process_id
,
38 content::BrowserContext
* context
);
40 int render_process_id() { return render_process_id_
; }
43 friend class content::BrowserThread
;
44 friend class base::DeleteHelper
<ExtensionMessageFilter
>;
46 ~ExtensionMessageFilter() override
;
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
;
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
,
77 void OnExtensionRemoveFilteredListener(const std::string
& extension_id
,
78 const std::string
& event_name
,
79 const base::DictionaryValue
& filter
,
81 void OnExtensionShouldSuspendAck(const std::string
& extension_id
,
83 void OnExtensionSuspendAck(const std::string
& extension_id
);
84 void OnExtensionTransferBlobsAck(const std::vector
<std::string
>& blob_uuids
);
86 // Message handlers on the IO thread.
87 void OnExtensionGenerateUniqueID(int* unique_id
);
88 void OnExtensionResumeRequests(int route_id
);
89 void OnExtensionRequestForIOThread(
91 const ExtensionHostMsg_Request_Params
& params
);
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
);
100 const int render_process_id_
;
102 // Should only be accessed on the UI thread.
103 content::BrowserContext
* browser_context_
;
105 scoped_refptr
<extensions::InfoMap
> extension_info_map_
;
107 // Weak pointers produced by this factory are bound to the IO thread.
108 base::WeakPtrFactory
<ExtensionMessageFilter
> weak_ptr_factory_
;
110 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter
);
113 } // namespace extensions
115 #endif // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_