1 // Copyright 2013 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 CHROME_BROWSER_NACL_HOST_NACL_HOST_MESSAGE_FILTER_H_ 6 #define CHROME_BROWSER_NACL_HOST_NACL_HOST_MESSAGE_FILTER_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/memory/weak_ptr.h" 10 #include "base/platform_file.h" 11 #include "content/public/browser/browser_message_filter.h" 12 13 class ExtensionInfoMap; 14 class GURL; 15 16 namespace nacl { 17 struct NaClLaunchParams; 18 struct PnaclCacheInfo; 19 struct PnaclInstallProgress; 20 } 21 22 namespace net { 23 class HostResolver; 24 class URLRequestContextGetter; 25 } 26 27 // This class filters out incoming Chrome-specific IPC messages for the renderer 28 // process on the IPC thread. 29 class NaClHostMessageFilter : public content::BrowserMessageFilter { 30 public: 31 NaClHostMessageFilter(int render_process_id, 32 bool is_off_the_record, 33 const base::FilePath& profile_directory, 34 ExtensionInfoMap* extension_info_map, 35 net::URLRequestContextGetter* request_context); 36 37 // content::BrowserMessageFilter methods: 38 virtual bool OnMessageReceived(const IPC::Message& message, 39 bool* message_was_ok) OVERRIDE; 40 virtual void OnChannelClosing() OVERRIDE; 41 42 int render_process_id() { return render_process_id_; } 43 bool off_the_record() { return off_the_record_; } 44 net::HostResolver* GetHostResolver(); 45 46 private: 47 friend class content::BrowserThread; 48 friend class base::DeleteHelper<NaClHostMessageFilter>; 49 50 virtual ~NaClHostMessageFilter(); 51 52 #if !defined(DISABLE_NACL) 53 void OnLaunchNaCl(const nacl::NaClLaunchParams& launch_params, 54 IPC::Message* reply_msg); 55 void OnEnsurePnaclInstalled(int instance); 56 void OnGetReadonlyPnaclFd(const std::string& filename, 57 IPC::Message* reply_msg); 58 void OnNaClCreateTemporaryFile(IPC::Message* reply_msg); 59 void OnGetNexeFd(int render_view_id, 60 int pp_instance, 61 const nacl::PnaclCacheInfo& cache_info); 62 void OnTranslationFinished(int instance, bool success); 63 void OnNaClErrorStatus(int render_view_id, int error_id); 64 void OnOpenNaClExecutable(int render_view_id, 65 const GURL& file_url, 66 IPC::Message* reply_msg); 67 68 void ReplyEnsurePnaclInstalled(int instance, bool success); 69 void SendProgressEnsurePnaclInstalled( 70 int instance, 71 const nacl::PnaclInstallProgress& progress); 72 void SyncReturnTemporaryFile(IPC::Message* reply_msg, 73 base::PlatformFile fd); 74 void AsyncReturnTemporaryFile(int pp_instance, 75 base::PlatformFile fd, 76 bool is_hit); 77 #endif 78 int render_process_id_; 79 80 // off_the_record_ is copied from the profile partly so that it can be 81 // read on the IO thread. 82 bool off_the_record_; 83 base::FilePath profile_directory_; 84 scoped_refptr<net::URLRequestContextGetter> request_context_; 85 scoped_refptr<ExtensionInfoMap> extension_info_map_; 86 87 base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_; 88 89 DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter); 90 }; 91 92 #endif // CHROME_BROWSER_NACL_HOST_NACL_HOST_MESSAGE_FILTER_H_ 93