Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 140343002: extensions: Relocate pref name constants. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing include for mac Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/pref_service.h"
12 #include "base/process/kill.h" 12 #include "base/process/kill.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest .h" 15 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest .h"
16 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 16 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
17 #include "chrome/common/chrome_version_info.h" 17 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/pref_names.h" 18 #include "extensions/browser/pref_names.h"
19 #include "extensions/common/constants.h" 19 #include "extensions/common/constants.h"
20 #include "extensions/common/features/feature.h" 20 #include "extensions/common/features/feature.h"
21 #include "net/base/file_stream.h" 21 #include "net/base/file_stream.h"
22 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 namespace { 27 namespace {
28 28
(...skipping 20 matching lines...) Expand all
49 49
50 } // namespace 50 } // namespace
51 51
52 namespace extensions { 52 namespace extensions {
53 53
54 // static 54 // static
55 bool NativeMessageProcessHost::IsHostAllowed( 55 bool NativeMessageProcessHost::IsHostAllowed(
56 const PrefService* pref_service, 56 const PrefService* pref_service,
57 const std::string& native_host_name) { 57 const std::string& native_host_name) {
58 // All native messaging hosts are allowed if there is no blacklist. 58 // All native messaging hosts are allowed if there is no blacklist.
59 if (!pref_service->IsManagedPreference(prefs::kNativeMessagingBlacklist)) 59 if (!pref_service->IsManagedPreference(pref_names::kNativeMessagingBlacklist))
60 return true; 60 return true;
61 const base::ListValue* blacklist = 61 const base::ListValue* blacklist =
62 pref_service->GetList(prefs::kNativeMessagingBlacklist); 62 pref_service->GetList(pref_names::kNativeMessagingBlacklist);
63 if (!blacklist) 63 if (!blacklist)
64 return true; 64 return true;
65 65
66 // Check if the name or the wildcard is in the blacklist. 66 // Check if the name or the wildcard is in the blacklist.
67 base::StringValue name_value(native_host_name); 67 base::StringValue name_value(native_host_name);
68 base::StringValue wildcard_value("*"); 68 base::StringValue wildcard_value("*");
69 if (blacklist->Find(name_value) == blacklist->end() && 69 if (blacklist->Find(name_value) == blacklist->end() &&
70 blacklist->Find(wildcard_value) == blacklist->end()) { 70 blacklist->Find(wildcard_value) == blacklist->end()) {
71 return true; 71 return true;
72 } 72 }
73 73
74 // The native messaging host is blacklisted. Check the whitelist. 74 // The native messaging host is blacklisted. Check the whitelist.
75 if (pref_service->IsManagedPreference(prefs::kNativeMessagingWhitelist)) { 75 if (pref_service->IsManagedPreference(
76 pref_names::kNativeMessagingWhitelist)) {
76 const base::ListValue* whitelist = 77 const base::ListValue* whitelist =
77 pref_service->GetList(prefs::kNativeMessagingWhitelist); 78 pref_service->GetList(pref_names::kNativeMessagingWhitelist);
78 if (whitelist && whitelist->Find(name_value) != whitelist->end()) 79 if (whitelist && whitelist->Find(name_value) != whitelist->end())
79 return true; 80 return true;
80 } 81 }
81 82
82 return false; 83 return false;
83 } 84 }
84 85
85 NativeMessageProcessHost::NativeMessageProcessHost( 86 NativeMessageProcessHost::NativeMessageProcessHost(
86 base::WeakPtr<Client> weak_client_ui, 87 base::WeakPtr<Client> weak_client_ui,
87 const std::string& source_extension_id, 88 const std::string& source_extension_id,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 content::BrowserThread::PostBlockingPoolTask( 395 content::BrowserThread::PostBlockingPoolTask(
395 FROM_HERE, base::Bind(&base::EnsureProcessTerminated, process_handle_)); 396 FROM_HERE, base::Bind(&base::EnsureProcessTerminated, process_handle_));
396 #else 397 #else
397 base::EnsureProcessTerminated(process_handle_); 398 base::EnsureProcessTerminated(process_handle_);
398 #endif 399 #endif
399 process_handle_ = base::kNullProcessHandle; 400 process_handle_ = base::kNullProcessHandle;
400 } 401 }
401 } 402 }
402 403
403 } // namespace extensions 404 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698