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.
5 #ifndef COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_
6 #define COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_
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"
16 struct NaClLaunchParams;
17 struct PnaclCacheInfo;
22 class URLRequestContextGetter;
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 {
31 NaClHostMessageFilter(int render_process_id,
32 bool is_off_the_record,
33 const base::FilePath& profile_directory,
34 net::URLRequestContextGetter* request_context);
36 // content::BrowserMessageFilter methods:
37 virtual bool OnMessageReceived(const IPC::Message& message,
38 bool* message_was_ok) OVERRIDE;
39 virtual void OnChannelClosing() OVERRIDE;
41 int render_process_id() { return render_process_id_; }
42 bool off_the_record() { return off_the_record_; }
43 net::HostResolver* GetHostResolver();
46 friend class content::BrowserThread;
47 friend class base::DeleteHelper<NaClHostMessageFilter>;
49 virtual ~NaClHostMessageFilter();
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,
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,
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,
72 int render_process_id_;
74 // off_the_record_ is copied from the profile partly so that it can be
75 // read on the IO thread.
77 base::FilePath profile_directory_;
78 scoped_refptr<net::URLRequestContextGetter> request_context_;
80 base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_;
82 DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter);
87 #endif // COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_