 Chromium Code Reviews
 Chromium Code Reviews Issue 591463003:
  Remote Assistance on Chrome OS Part III - NativeMessageHost  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
    
  
    Issue 591463003:
  Remote Assistance on Chrome OS Part III - NativeMessageHost  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging| Index: extensions/browser/api/messaging/native_message_host.cc | 
| diff --git a/extensions/browser/api/messaging/native_message_host.cc b/extensions/browser/api/messaging/native_message_host.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..8abc399f2397c436870f2839a2097c6b896f3955 | 
| --- /dev/null | 
| +++ b/extensions/browser/api/messaging/native_message_host.cc | 
| @@ -0,0 +1,52 @@ | 
| +// Copyright 2014 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "extensions/browser/api/messaging/native_message_host.h" | 
| + | 
| +#include "base/prefs/pref_service.h" | 
| +#include "base/values.h" | 
| +#include "extensions/browser/pref_names.h" | 
| + | 
| +namespace extensions { | 
| + | 
| +// static | 
| +NativeMessageHost::PolicyPermission | 
| +NativeMessageHost::IsHostAllowed(const PrefService* pref_service, | 
| 
Sergey Ulanov
2014/09/22 23:42:59
I don't think this function belongs in this interf
 
kelvinp
2014/09/23 20:16:42
Done.
 | 
| + const std::string& native_host_name) { | 
| + NativeMessageHost::PolicyPermission allow_result = ALLOW_ALL; | 
| + if (pref_service->IsManagedPreference( | 
| + pref_names::kNativeMessagingUserLevelHosts)) { | 
| + if (!pref_service->GetBoolean(pref_names::kNativeMessagingUserLevelHosts)) | 
| + allow_result = ALLOW_SYSTEM_ONLY; | 
| + } | 
| + | 
| + // All native messaging hosts are allowed if there is no blacklist. | 
| + if (!pref_service->IsManagedPreference(pref_names::kNativeMessagingBlacklist)) | 
| + return allow_result; | 
| + const base::ListValue* blacklist = | 
| + pref_service->GetList(pref_names::kNativeMessagingBlacklist); | 
| + if (!blacklist) | 
| + return allow_result; | 
| + | 
| + // Check if the name or the wildcard is in the blacklist. | 
| + base::StringValue name_value(native_host_name); | 
| + base::StringValue wildcard_value("*"); | 
| + if (blacklist->Find(name_value) == blacklist->end() && | 
| + blacklist->Find(wildcard_value) == blacklist->end()) { | 
| + return allow_result; | 
| + } | 
| + | 
| + // The native messaging host is blacklisted. Check the whitelist. | 
| + if (pref_service->IsManagedPreference( | 
| + pref_names::kNativeMessagingWhitelist)) { | 
| + const base::ListValue* whitelist = | 
| + pref_service->GetList(pref_names::kNativeMessagingWhitelist); | 
| + if (whitelist && whitelist->Find(name_value) != whitelist->end()) | 
| + return allow_result; | 
| + } | 
| + | 
| + return DISALLOW; | 
| +} | 
| + | 
| +} // namespace extensions |