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.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"
17 struct NaClLaunchParams;
18 struct PnaclCacheInfo;
23 class URLRequestContextGetter;
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 {
32 NaClHostMessageFilter(int render_process_id,
33 bool is_off_the_record,
34 const base::FilePath& profile_directory,
35 net::URLRequestContextGetter* request_context);
37 // content::BrowserMessageFilter methods:
38 virtual bool OnMessageReceived(const IPC::Message& message) 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 const base::FilePath& profile_directory() const { return profile_directory_; }
44 net::HostResolver* GetHostResolver();
47 friend class content::BrowserThread;
48 friend class base::DeleteHelper<NaClHostMessageFilter>;
50 virtual ~NaClHostMessageFilter();
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,
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,
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,
69 IPC::Message* reply_msg);
70 void SyncReturnTemporaryFile(IPC::Message* reply_msg,
72 void AsyncReturnTemporaryFile(int pp_instance,
73 const base::File& file,
75 void OnNaClDebugEnabledForURL(const GURL& nmf_url, bool* should_debug);
77 int render_process_id_;
79 // off_the_record_ is copied from the profile partly so that it can be
80 // read on the IO thread.
82 base::FilePath profile_directory_;
83 scoped_refptr<net::URLRequestContextGetter> request_context_;
85 base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_;
87 DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter);
92 #endif // COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_