Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/messaging/native_messaging_policy_handle r.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/prefs/pref_value_map.h" | |
| 9 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest .h" | |
| 10 #include "chrome/browser/extensions/external_policy_loader.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "components/policy/core/browser/policy_error_map.h" | |
| 13 #include "components/policy/core/common/policy_map.h" | |
| 14 #include "grit/component_strings.h" | |
| 15 #include "policy/policy_constants.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 NativeMessagingHostListPolicyHandler::NativeMessagingHostListPolicyHandler( | |
| 20 const char* policy_name, | |
| 21 const char* pref_path, | |
| 22 bool allow_wildcards) | |
| 23 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | |
| 24 pref_path_(pref_path), | |
| 25 allow_wildcards_(allow_wildcards) {} | |
| 26 | |
| 27 NativeMessagingHostListPolicyHandler::~NativeMessagingHostListPolicyHandler() {} | |
| 28 | |
| 29 bool NativeMessagingHostListPolicyHandler::CheckPolicySettings( | |
| 30 const policy::PolicyMap& policies, | |
| 31 policy::PolicyErrorMap* errors) { | |
| 32 return CheckAndGetList(policies, errors, NULL); | |
| 33 } | |
| 34 | |
| 35 void NativeMessagingHostListPolicyHandler::ApplyPolicySettings( | |
| 36 const policy::PolicyMap& policies, | |
| 37 PrefValueMap* prefs) { | |
| 38 scoped_ptr<base::ListValue> list; | |
| 39 policy::PolicyErrorMap errors; | |
| 40 if (CheckAndGetList(policies, &errors, &list) && list) | |
|
not at google - send to devlin
2013/12/28 04:55:51
If I'm reading this correctly... the "&& list" her
Sergey Ulanov
2014/01/06 23:21:55
That's the way it works for all other policies, e.
| |
| 41 prefs->SetValue(pref_path(), list.release()); | |
| 42 } | |
| 43 | |
| 44 const char* NativeMessagingHostListPolicyHandler::pref_path() const { | |
| 45 return pref_path_; | |
| 46 } | |
| 47 | |
| 48 bool NativeMessagingHostListPolicyHandler::CheckAndGetList( | |
| 49 const policy::PolicyMap& policies, | |
| 50 policy::PolicyErrorMap* errors, | |
| 51 scoped_ptr<base::ListValue>* names) { | |
|
not at google - send to devlin
2013/12/28 04:55:51
you could just pass a base::ListValue* here and th
Sergey Ulanov
2014/01/06 23:21:55
We want to distinguish between the case when the p
| |
| 52 if (names) | |
| 53 names->reset(); | |
|
not at google - send to devlin
2013/12/28 04:55:51
this will always be a no-op I think.
Sergey Ulanov
2014/01/06 23:21:55
Done.
| |
| 54 | |
| 55 const base::Value* value = NULL; | |
| 56 if (!CheckAndGetValue(policies, errors, &value)) | |
| 57 return false; | |
| 58 | |
| 59 if (!value) | |
|
not at google - send to devlin
2013/12/28 04:55:51
what does not finding this value mean?
Sergey Ulanov
2014/01/06 23:21:55
It means that the policy isn't set.
| |
| 60 return true; | |
| 61 | |
| 62 const base::ListValue* list_value = NULL; | |
| 63 if (!value->GetAsList(&list_value)) { | |
| 64 NOTREACHED(); | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 // Filter the list, rejecting any invalid extension IDs. | |
|
Joao da Silva
2013/12/29 23:25:28
IIUC there are no extension IDs in these values.
Sergey Ulanov
2014/01/06 23:21:55
Copied this code from chrome/browser/extensions/po
| |
| 69 scoped_ptr<base::ListValue> filtered_list(new base::ListValue()); | |
| 70 for (base::ListValue::const_iterator entry(list_value->begin()); | |
| 71 entry != list_value->end(); ++entry) { | |
| 72 std::string name; | |
| 73 if (!(*entry)->GetAsString(&name)) { | |
| 74 errors->AddError(policy_name(), | |
| 75 entry - list_value->begin(), | |
| 76 IDS_POLICY_TYPE_ERROR, | |
| 77 ValueTypeToString(base::Value::TYPE_STRING)); | |
| 78 continue; | |
| 79 } | |
| 80 if (!(allow_wildcards_ && name == "*") && | |
| 81 !NativeMessagingHostManifest::IsValidName(name)) { | |
| 82 errors->AddError(policy_name(), | |
| 83 entry - list_value->begin(), | |
| 84 IDS_POLICY_VALUE_FORMAT_ERROR); | |
| 85 continue; | |
| 86 } | |
| 87 filtered_list->Append(base::Value::CreateStringValue(name)); | |
|
not at google - send to devlin
2013/12/28 04:55:51
the "CreateStringValue(...)" methods are deprecate
Sergey Ulanov
2014/01/06 23:21:55
Done.
| |
| 88 } | |
| 89 | |
| 90 if (names) | |
| 91 *names = filtered_list.Pass(); | |
|
not at google - send to devlin
2013/12/28 04:55:51
the way this is implemented there isn't any advant
Sergey Ulanov
2014/01/06 23:21:55
We want to distinguish between the case when the p
| |
| 92 | |
| 93 return true; | |
| 94 } | |
| 95 | |
| 96 } // namespace extensions | |
| OLD | NEW |