Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / nacl / browser / nacl_host_message_filter.h
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                             bool is_executable,
59                             IPC::Message* reply_msg);
60   void OnNaClCreateTemporaryFile(IPC::Message* reply_msg);
61   void OnNaClGetNumProcessors(int* num_processors);
62   void OnGetNexeFd(int render_view_id,
63                    int pp_instance,
64                    const PnaclCacheInfo& cache_info);
65   void OnTranslationFinished(int instance, bool success);
66   void OnMissingArchError(int render_view_id);
67   void OnOpenNaClExecutable(int render_view_id,
68                             const GURL& file_url,
69                             IPC::Message* reply_msg);
70   void SyncReturnTemporaryFile(IPC::Message* reply_msg,
71                                base::File file);
72   void AsyncReturnTemporaryFile(int pp_instance,
73                                 const base::File& file,
74                                 bool is_hit);
75   void OnNaClDebugEnabledForURL(const GURL& nmf_url, bool* should_debug);
76
77   int render_process_id_;
78
79   // off_the_record_ is copied from the profile partly so that it can be
80   // read on the IO thread.
81   bool off_the_record_;
82   base::FilePath profile_directory_;
83   scoped_refptr<net::URLRequestContextGetter> request_context_;
84
85   base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_;
86
87   DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter);
88 };
89
90 }  // namespace nacl
91
92 #endif  // COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_