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 16 struct ExtensionHostMsg_Request_Params; 17 18 namespace base { 19 class DictionaryValue; 20 } 21 22 namespace content { 23 class BrowserContext; 24 } 25 26 namespace extensions { 27 28 class InfoMap; 29 30 // This class filters out incoming extension-specific IPC messages from the 31 // renderer process. It is created on the UI thread. Messages may be handled on 32 // the IO thread or the UI thread. 33 class ExtensionMessageFilter : public content::BrowserMessageFilter { 34 public: 35 ExtensionMessageFilter(int render_process_id, 36 content::BrowserContext* context); 37 38 int render_process_id() { return render_process_id_; } 39 40 private: 41 friend class content::BrowserThread; 42 friend class base::DeleteHelper<ExtensionMessageFilter>; 43 44 virtual ~ExtensionMessageFilter(); 45 46 // content::BrowserMessageFilter implementation. 47 virtual void OverrideThreadForMessage( 48 const IPC::Message& message, 49 content::BrowserThread::ID* thread) OVERRIDE; 50 virtual void OnDestruct() const OVERRIDE; 51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 52 53 // Message handlers on the UI thread. 54 void OnExtensionAddListener(const std::string& extension_id, 55 const std::string& event_name); 56 void OnExtensionRemoveListener(const std::string& extension_id, 57 const std::string& event_name); 58 void OnExtensionAddLazyListener(const std::string& extension_id, 59 const std::string& event_name); 60 void OnExtensionRemoveLazyListener(const std::string& extension_id, 61 const std::string& event_name); 62 void OnExtensionAddFilteredListener(const std::string& extension_id, 63 const std::string& event_name, 64 const base::DictionaryValue& filter, 65 bool lazy); 66 void OnExtensionRemoveFilteredListener(const std::string& extension_id, 67 const std::string& event_name, 68 const base::DictionaryValue& filter, 69 bool lazy); 70 void OnExtensionShouldSuspendAck(const std::string& extension_id, 71 int sequence_id); 72 void OnExtensionSuspendAck(const std::string& extension_id); 73 void OnExtensionTransferBlobsAck(const std::vector<std::string>& blob_uuids); 74 75 // Message handlers on the IO thread. 76 void OnExtensionGenerateUniqueID(int* unique_id); 77 void OnExtensionResumeRequests(int route_id); 78 void OnExtensionRequestForIOThread( 79 int routing_id, 80 const ExtensionHostMsg_Request_Params& params); 81 82 const int render_process_id_; 83 84 // Should only be accessed on the UI thread. 85 content::BrowserContext* browser_context_; 86 87 scoped_refptr<extensions::InfoMap> extension_info_map_; 88 89 // Weak pointers produced by this factory are bound to the IO thread. 90 base::WeakPtrFactory<ExtensionMessageFilter> weak_ptr_factory_; 91 92 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilter); 93 }; 94 95 } // namespace extensions 96 97 #endif // EXTENSIONS_BROWSER_EXTENSION_MESSAGE_FILTER_H_ 98