blob: 7d31a9039780f21773a0658860d8eebf176759b9 [file] [log] [blame]
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01001// 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
Ben Murdocheb525c52013-07-10 11:40:50 +01008#include "base/files/file_path.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01009#include "base/memory/weak_ptr.h"
10#include "content/public/browser/browser_message_filter.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010011#include "ipc/ipc_platform_file.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010012
13class ExtensionInfoMap;
14class GURL;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010015
16namespace nacl {
17struct NaClLaunchParams;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010018struct PnaclCacheInfo;
Ben Murdoch2385ea32013-08-06 11:01:04 +010019struct PnaclInstallProgress;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010020}
21
22namespace net {
23class HostResolver;
24class URLRequestContextGetter;
25}
26
27// This class filters out incoming Chrome-specific IPC messages for the renderer
28// process on the IPC thread.
29class NaClHostMessageFilter : public content::BrowserMessageFilter {
30 public:
31 NaClHostMessageFilter(int render_process_id,
Ben Murdocheb525c52013-07-10 11:40:50 +010032 bool is_off_the_record,
33 const base::FilePath& profile_directory,
34 ExtensionInfoMap* extension_info_map,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010035 net::URLRequestContextGetter* request_context);
36
37 // content::BrowserMessageFilter methods:
38 virtual bool OnMessageReceived(const IPC::Message& message,
39 bool* message_was_ok) OVERRIDE;
Ben Murdochca12bfa2013-07-23 11:17:05 +010040 virtual void OnChannelClosing() OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010041
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);
Ben Murdoch2385ea32013-08-06 11:01:04 +010055 void OnEnsurePnaclInstalled(int instance);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010056 void OnGetReadonlyPnaclFd(const std::string& filename,
57 IPC::Message* reply_msg);
58 void OnNaClCreateTemporaryFile(IPC::Message* reply_msg);
Ben Murdochca12bfa2013-07-23 11:17:05 +010059 void OnGetNexeFd(int render_view_id,
60 int pp_instance,
61 const nacl::PnaclCacheInfo& cache_info);
Ben Murdochbb1529c2013-08-08 10:24:53 +010062 void OnTranslationFinished(int instance, bool success);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010063 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);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010067
Ben Murdoch2385ea32013-08-06 11:01:04 +010068 void ReplyEnsurePnaclInstalled(int instance, bool success);
69 void SendProgressEnsurePnaclInstalled(
70 int instance,
71 const nacl::PnaclInstallProgress& progress);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010072 void SyncReturnTemporaryFile(IPC::Message* reply_msg,
73 IPC::PlatformFileForTransit fd);
Ben Murdochca12bfa2013-07-23 11:17:05 +010074 void AsyncReturnTemporaryFile(int pp_instance,
75 IPC::PlatformFileForTransit fd,
76 bool is_hit);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010077#endif
78 int render_process_id_;
79
Ben Murdocheb525c52013-07-10 11:40:50 +010080 // off_the_record_ is copied from the profile partly so that it can be
81 // read on the IO thread.
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010082 bool off_the_record_;
Ben Murdocheb525c52013-07-10 11:40:50 +010083 base::FilePath profile_directory_;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010084 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_