| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_messaging_policy_handle
r.h" | 5 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handle
r.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" | 10 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 bool NativeMessagingHostListPolicyHandler::CheckPolicySettings( | 30 bool NativeMessagingHostListPolicyHandler::CheckPolicySettings( |
| 31 const policy::PolicyMap& policies, | 31 const policy::PolicyMap& policies, |
| 32 policy::PolicyErrorMap* errors) { | 32 policy::PolicyErrorMap* errors) { |
| 33 return CheckAndGetList(policies, errors, NULL); | 33 return CheckAndGetList(policies, errors, NULL); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void NativeMessagingHostListPolicyHandler::ApplyPolicySettings( | 36 void NativeMessagingHostListPolicyHandler::ApplyPolicySettings( |
| 37 const policy::PolicyMap& policies, | 37 const policy::PolicyMap& policies, |
| 38 PrefValueMap* prefs) { | 38 PrefValueMap* prefs) { |
| 39 scoped_ptr<base::ListValue> list; | 39 std::unique_ptr<base::ListValue> list; |
| 40 policy::PolicyErrorMap errors; | 40 policy::PolicyErrorMap errors; |
| 41 if (CheckAndGetList(policies, &errors, &list) && list) | 41 if (CheckAndGetList(policies, &errors, &list) && list) |
| 42 prefs->SetValue(pref_path(), std::move(list)); | 42 prefs->SetValue(pref_path(), std::move(list)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const char* NativeMessagingHostListPolicyHandler::pref_path() const { | 45 const char* NativeMessagingHostListPolicyHandler::pref_path() const { |
| 46 return pref_path_; | 46 return pref_path_; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool NativeMessagingHostListPolicyHandler::CheckAndGetList( | 49 bool NativeMessagingHostListPolicyHandler::CheckAndGetList( |
| 50 const policy::PolicyMap& policies, | 50 const policy::PolicyMap& policies, |
| 51 policy::PolicyErrorMap* errors, | 51 policy::PolicyErrorMap* errors, |
| 52 scoped_ptr<base::ListValue>* names) { | 52 std::unique_ptr<base::ListValue>* names) { |
| 53 const base::Value* value = NULL; | 53 const base::Value* value = NULL; |
| 54 if (!CheckAndGetValue(policies, errors, &value)) | 54 if (!CheckAndGetValue(policies, errors, &value)) |
| 55 return false; | 55 return false; |
| 56 | 56 |
| 57 if (!value) | 57 if (!value) |
| 58 return true; | 58 return true; |
| 59 | 59 |
| 60 const base::ListValue* list_value = NULL; | 60 const base::ListValue* list_value = NULL; |
| 61 if (!value->GetAsList(&list_value)) { | 61 if (!value->GetAsList(&list_value)) { |
| 62 NOTREACHED(); | 62 NOTREACHED(); |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Filter the list, rejecting any invalid native messaging host names. | 66 // Filter the list, rejecting any invalid native messaging host names. |
| 67 scoped_ptr<base::ListValue> filtered_list(new base::ListValue()); | 67 std::unique_ptr<base::ListValue> filtered_list(new base::ListValue()); |
| 68 for (base::ListValue::const_iterator entry(list_value->begin()); | 68 for (base::ListValue::const_iterator entry(list_value->begin()); |
| 69 entry != list_value->end(); ++entry) { | 69 entry != list_value->end(); ++entry) { |
| 70 std::string name; | 70 std::string name; |
| 71 if (!(*entry)->GetAsString(&name)) { | 71 if (!(*entry)->GetAsString(&name)) { |
| 72 errors->AddError(policy_name(), | 72 errors->AddError(policy_name(), |
| 73 entry - list_value->begin(), | 73 entry - list_value->begin(), |
| 74 IDS_POLICY_TYPE_ERROR, | 74 IDS_POLICY_TYPE_ERROR, |
| 75 ValueTypeToString(base::Value::TYPE_STRING)); | 75 ValueTypeToString(base::Value::TYPE_STRING)); |
| 76 continue; | 76 continue; |
| 77 } | 77 } |
| 78 if (!(allow_wildcards_ && name == "*") && | 78 if (!(allow_wildcards_ && name == "*") && |
| 79 !NativeMessagingHostManifest::IsValidName(name)) { | 79 !NativeMessagingHostManifest::IsValidName(name)) { |
| 80 errors->AddError(policy_name(), | 80 errors->AddError(policy_name(), |
| 81 entry - list_value->begin(), | 81 entry - list_value->begin(), |
| 82 IDS_POLICY_VALUE_FORMAT_ERROR); | 82 IDS_POLICY_VALUE_FORMAT_ERROR); |
| 83 continue; | 83 continue; |
| 84 } | 84 } |
| 85 filtered_list->Append(new base::StringValue(name)); | 85 filtered_list->Append(new base::StringValue(name)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 if (names) | 88 if (names) |
| 89 *names = std::move(filtered_list); | 89 *names = std::move(filtered_list); |
| 90 | 90 |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace extensions | 94 } // namespace extensions |
| OLD | NEW |