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