843a340dcccfb4be98cb4de3460ef6d86d4b0a95
[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_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 GURL;
14
15 namespace nacl {
16 struct NaClLaunchParams;
17 struct PnaclCacheInfo;
18 }
19
20 namespace net {
21 class HostResolver;
22 class URLRequestContextGetter;
23 }
24
25 namespace nacl {
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                         net::URLRequestContextGetter* request_context);
35
36   // content::BrowserMessageFilter methods:
37   virtual bool OnMessageReceived(const IPC::Message& message,
38                                  bool* message_was_ok) 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   net::HostResolver* GetHostResolver();
44
45  private:
46   friend class content::BrowserThread;
47   friend class base::DeleteHelper<NaClHostMessageFilter>;
48
49   virtual ~NaClHostMessageFilter();
50
51 #if !defined(DISABLE_NACL)
52   void OnLaunchNaCl(const NaClLaunchParams& launch_params,
53                     IPC::Message* reply_msg);
54   void OnGetReadonlyPnaclFd(const std::string& filename,
55                             IPC::Message* reply_msg);
56   void OnNaClCreateTemporaryFile(IPC::Message* reply_msg);
57   void OnNaClGetNumProcessors(int* num_processors);
58   void OnGetNexeFd(int render_view_id,
59                    int pp_instance,
60                    const PnaclCacheInfo& cache_info);
61   void OnTranslationFinished(int instance, bool success);
62   void OnNaClErrorStatus(int render_view_id, int error_id);
63   void OnOpenNaClExecutable(int render_view_id,
64                             const GURL& file_url,
65                             IPC::Message* reply_msg);
66   void SyncReturnTemporaryFile(IPC::Message* reply_msg,
67                                base::PlatformFile fd);
68   void AsyncReturnTemporaryFile(int pp_instance,
69                                 base::PlatformFile fd,
70                                 bool is_hit);
71 #endif
72   int render_process_id_;
73
74   // off_the_record_ is copied from the profile partly so that it can be
75   // read on the IO thread.
76   bool off_the_record_;
77   base::FilePath profile_directory_;
78   scoped_refptr<net::URLRequestContextGetter> request_context_;
79
80   base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_;
81
82   DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter);
83 };
84
85 }  // namespace nacl
86
87 #endif  // COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_