OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_ | 5 #ifndef COMPONENTS_NACL_BROWSER_NACL_HOST_IMPL_H_ |
6 #define COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_ | 6 #define COMPONENTS_NACL_BROWSER_NACL_HOST_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/nacl/common/nacl.mojom.h" |
14 #include "content/public/browser/browser_message_filter.h" | 15 #include "content/public/browser/browser_message_filter.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "ppapi/shared_impl/ppapi_permissions.h" | 17 #include "ppapi/shared_impl/ppapi_permissions.h" |
16 | 18 |
17 class GURL; | 19 class GURL; |
18 | 20 |
19 namespace nacl { | 21 namespace nacl { |
20 struct NaClLaunchParams; | |
21 struct NaClResourcePrefetchResult; | 22 struct NaClResourcePrefetchResult; |
22 struct PnaclCacheInfo; | 23 struct PnaclCacheInfo; |
23 } | 24 } |
24 | 25 |
25 namespace net { | |
26 class HostResolver; | |
27 class URLRequestContextGetter; | |
28 } | |
29 | |
30 namespace nacl { | 26 namespace nacl { |
31 | 27 |
32 // This class filters out incoming Chrome-specific IPC messages for the renderer | 28 // This class implements the NaClHost mojo interface on the IO thread. |
33 // process on the IPC thread. | 29 class NaClHostImpl : public mojom::NaClHost, |
34 class NaClHostMessageFilter : public content::BrowserMessageFilter { | 30 public base::RefCountedThreadSafe<NaClHostImpl> { |
35 public: | 31 public: |
36 NaClHostMessageFilter(int render_process_id, | 32 NaClHostImpl(int render_process_id, |
37 bool is_off_the_record, | 33 bool is_off_the_record, |
38 const base::FilePath& profile_directory, | 34 const base::FilePath& profile_directory, |
39 net::URLRequestContextGetter* request_context); | 35 mojom::NaClHostRequest request); |
40 | 36 |
41 // content::BrowserMessageFilter methods: | 37 static void Create(int render_process_id, |
42 bool OnMessageReceived(const IPC::Message& message) override; | 38 bool is_off_the_record, |
43 void OnChannelClosing() override; | 39 const base::FilePath& profile_directory, |
44 | 40 mojom::NaClHostRequest request); |
45 int render_process_id() { return render_process_id_; } | |
46 bool off_the_record() { return off_the_record_; } | |
47 const base::FilePath& profile_directory() const { return profile_directory_; } | |
48 net::HostResolver* GetHostResolver(); | |
49 | 41 |
50 private: | 42 private: |
51 friend class content::BrowserThread; | 43 friend class base::RefCountedThreadSafe<NaClHostImpl>; |
52 friend class base::DeleteHelper<NaClHostMessageFilter>; | |
53 | 44 |
54 ~NaClHostMessageFilter() override; | 45 ~NaClHostImpl() override; |
55 | 46 |
56 void OnLaunchNaCl(const NaClLaunchParams& launch_params, | 47 void OnConnectionError(); |
57 IPC::Message* reply_msg); | 48 |
58 void BatchOpenResourceFiles(const nacl::NaClLaunchParams& launch_params, | 49 void LaunchNaCl(mojom::NaClLaunchParamsPtr launch_params, |
59 IPC::Message* reply_msg, | 50 const LaunchNaClCallback& callback) override; |
| 51 void BatchOpenResourceFiles(mojom::NaClLaunchParamsPtr launch_params, |
| 52 const LaunchNaClCallback& callback, |
60 ppapi::PpapiPermissions permissions); | 53 ppapi::PpapiPermissions permissions); |
61 void LaunchNaClContinuation( | 54 void LaunchNaClContinuation(mojom::NaClLaunchParamsPtr launch_params, |
62 const nacl::NaClLaunchParams& launch_params, | 55 const LaunchNaClCallback& callback); |
63 IPC::Message* reply_msg); | |
64 void LaunchNaClContinuationOnIOThread( | 56 void LaunchNaClContinuationOnIOThread( |
65 const nacl::NaClLaunchParams& launch_params, | 57 mojom::NaClLaunchParamsPtr launch_params, |
66 IPC::Message* reply_msg, | 58 const LaunchNaClCallback& callback, |
67 const std::vector<NaClResourcePrefetchResult>& prefetched_resource_files, | 59 const std::vector<NaClResourcePrefetchResult>& prefetched_resource_files, |
68 ppapi::PpapiPermissions permissions); | 60 ppapi::PpapiPermissions permissions); |
69 void OnGetReadonlyPnaclFd(const std::string& filename, | 61 void GetReadonlyPnaclFd(const std::string& filename, |
70 bool is_executable, | 62 bool is_executable, |
71 IPC::Message* reply_msg); | 63 const GetReadonlyPnaclFdCallback& callback) override; |
72 void OnNaClCreateTemporaryFile(IPC::Message* reply_msg); | 64 void NaClCreateTemporaryFile( |
73 void OnNaClGetNumProcessors(int* num_processors); | 65 const NaClCreateTemporaryFileCallback& callback) override; |
74 void OnGetNexeFd(int render_view_id, | 66 void NaClGetNumProcessors( |
75 int pp_instance, | 67 const NaClGetNumProcessorsCallback& callback) override; |
76 const PnaclCacheInfo& cache_info); | 68 void NexeTempFileRequest( |
77 void OnTranslationFinished(int instance, bool success); | 69 int render_view_id, |
78 void OnMissingArchError(int render_view_id); | 70 int pp_instance, |
79 void OnOpenNaClExecutable(int render_view_id, | 71 const PnaclCacheInfo& cache_info, |
80 const GURL& file_url, | 72 const NexeTempFileRequestCallback& callback) override; |
81 bool enable_validation_caching, | 73 void ReportTranslationFinished(int instance, bool success) override; |
82 IPC::Message* reply_msg); | 74 void MissingArchError(int render_view_id) override; |
83 void SyncReturnTemporaryFile(IPC::Message* reply_msg, | 75 void OpenNaClExecutable(int render_view_id, |
84 base::File file); | 76 const GURL& file_url, |
85 void AsyncReturnTemporaryFile(int pp_instance, | 77 bool enable_validation_caching, |
86 const base::File& file, | 78 const OpenNaClExecutableCallback& callback) override; |
87 bool is_hit); | 79 void NaClDebugEnabledForURL( |
88 void OnNaClDebugEnabledForURL(const GURL& nmf_url, bool* should_debug); | 80 const GURL& nmf_url, |
| 81 const NaClDebugEnabledForURLCallback& callback) override; |
89 | 82 |
90 int render_process_id_; | 83 const int render_process_id_; |
91 | 84 |
92 // off_the_record_ is copied from the profile partly so that it can be | 85 // off_the_record_ is copied from the profile partly so that it can be |
93 // read on the IO thread. | 86 // read on the IO thread. |
94 bool off_the_record_; | 87 const bool off_the_record_; |
95 base::FilePath profile_directory_; | 88 base::FilePath profile_directory_; |
96 scoped_refptr<net::URLRequestContextGetter> request_context_; | 89 scoped_refptr<NaClHostImpl> self_; |
| 90 mojo::Binding<mojom::NaClHost> binding_; |
97 | 91 |
98 base::WeakPtrFactory<NaClHostMessageFilter> weak_ptr_factory_; | 92 base::WeakPtrFactory<NaClHostImpl> weak_ptr_factory_; |
99 | 93 |
100 DISALLOW_COPY_AND_ASSIGN(NaClHostMessageFilter); | 94 DISALLOW_COPY_AND_ASSIGN(NaClHostImpl); |
101 }; | 95 }; |
102 | 96 |
103 } // namespace nacl | 97 } // namespace nacl |
104 | 98 |
105 #endif // COMPONENTS_NACL_BROWSER_NACL_HOST_MESSAGE_FILTER_H_ | 99 #endif // COMPONENTS_NACL_BROWSER_NACL_HOST_IMPL_H_ |
OLD | NEW |