OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/prefs/pref_service.h" |
11 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" | 15 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
15 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 16 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "chrome/common/pref_names.h" |
17 #include "extensions/common/constants.h" | 19 #include "extensions/common/constants.h" |
18 #include "extensions/common/features/feature.h" | 20 #include "extensions/common/features/feature.h" |
19 #include "net/base/file_stream.h" | 21 #include "net/base/file_stream.h" |
20 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
(...skipping 15 matching lines...) Expand all Loading... |
42 const char kNotFoundError[] = "Specified native messaging host not found."; | 44 const char kNotFoundError[] = "Specified native messaging host not found."; |
43 const char kForbiddenError[] = | 45 const char kForbiddenError[] = |
44 "Access to the specified native messaging host is forbidden."; | 46 "Access to the specified native messaging host is forbidden."; |
45 const char kHostInputOuputError[] = | 47 const char kHostInputOuputError[] = |
46 "Error when communicating with the native messaging host."; | 48 "Error when communicating with the native messaging host."; |
47 | 49 |
48 } // namespace | 50 } // namespace |
49 | 51 |
50 namespace extensions { | 52 namespace extensions { |
51 | 53 |
| 54 // static |
| 55 bool NativeMessageProcessHost::IsHostAllowed( |
| 56 const PrefService* pref_service, |
| 57 const std::string& native_host_name) { |
| 58 // All native messaging hosts are allowed if there is no blacklist. |
| 59 if (!pref_service->IsManagedPreference(prefs::kNativeMessagingBlacklist)) |
| 60 return true; |
| 61 const base::ListValue* blacklist = |
| 62 pref_service->GetList(prefs::kNativeMessagingBlacklist); |
| 63 if (!blacklist) |
| 64 return true; |
| 65 |
| 66 // Check if the name or the wildcard is in the blacklist. |
| 67 base::StringValue name_value(native_host_name); |
| 68 base::StringValue wildcard_value("*"); |
| 69 if (blacklist->Find(name_value) == blacklist->end() && |
| 70 blacklist->Find(wildcard_value) == blacklist->end()) { |
| 71 return true; |
| 72 } |
| 73 |
| 74 // The native messaging host is blacklisted. Check the whitelist. |
| 75 if (pref_service->IsManagedPreference(prefs::kNativeMessagingWhitelist)) { |
| 76 const base::ListValue* whitelist = |
| 77 pref_service->GetList(prefs::kNativeMessagingWhitelist); |
| 78 if (whitelist && whitelist->Find(name_value) != whitelist->end()) |
| 79 return true; |
| 80 } |
| 81 |
| 82 return false; |
| 83 } |
| 84 |
52 NativeMessageProcessHost::NativeMessageProcessHost( | 85 NativeMessageProcessHost::NativeMessageProcessHost( |
53 base::WeakPtr<Client> weak_client_ui, | 86 base::WeakPtr<Client> weak_client_ui, |
54 const std::string& source_extension_id, | 87 const std::string& source_extension_id, |
55 const std::string& native_host_name, | 88 const std::string& native_host_name, |
56 int destination_port, | 89 int destination_port, |
57 scoped_ptr<NativeProcessLauncher> launcher) | 90 scoped_ptr<NativeProcessLauncher> launcher) |
58 : weak_client_ui_(weak_client_ui), | 91 : weak_client_ui_(weak_client_ui), |
59 source_extension_id_(source_extension_id), | 92 source_extension_id_(source_extension_id), |
60 native_host_name_(native_host_name), | 93 native_host_name_(native_host_name), |
61 destination_port_(destination_port), | 94 destination_port_(destination_port), |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 content::BrowserThread::PostBlockingPoolTask( | 394 content::BrowserThread::PostBlockingPoolTask( |
362 FROM_HERE, base::Bind(&base::EnsureProcessTerminated, process_handle_)); | 395 FROM_HERE, base::Bind(&base::EnsureProcessTerminated, process_handle_)); |
363 #else | 396 #else |
364 base::EnsureProcessTerminated(process_handle_); | 397 base::EnsureProcessTerminated(process_handle_); |
365 #endif | 398 #endif |
366 process_handle_ = base::kNullProcessHandle; | 399 process_handle_ = base::kNullProcessHandle; |
367 } | 400 } |
368 } | 401 } |
369 | 402 |
370 } // namespace extensions | 403 } // namespace extensions |
OLD | NEW |