Chromium Code Reviews| Index: components/policy/core/common/policy_loader_ios.mm |
| diff --git a/components/policy/core/common/policy_loader_ios.mm b/components/policy/core/common/policy_loader_ios.mm |
| index 19718eae21201a4db5ae4e63670985779846b00f..71891bc18e7ca633e97a0e88d3bdb860dffeda1c 100644 |
| --- a/components/policy/core/common/policy_loader_ios.mm |
| +++ b/components/policy/core/common/policy_loader_ios.mm |
| @@ -10,6 +10,7 @@ |
| #include "base/bind.h" |
| #include "base/location.h" |
| #include "base/logging.h" |
| +#include "base/mac/scoped_nsobject.h" |
| #include "base/sequenced_task_runner.h" |
| #include "components/policy/core/common/mac_util.h" |
| #include "components/policy/core/common/policy_bundle.h" |
| @@ -32,6 +33,10 @@ NSString* const kConfigurationKey = @"com.apple.configuration.managed"; |
| // Key in the managed app configuration that contains the Chrome policy. |
| NSString* const kChromePolicyKey = @"ChromePolicy"; |
| +// Key in the managed app configuration that contains the encoded Chrome policy. |
| +// This is a serialized Property List, encoded in base 64. |
| +NSString* const kEncodedChromePolicyKey = @"EncodedChromePolicy"; |
| + |
| } // namespace |
| // Helper that observes notifications for NSUserDefaults and triggers an update |
| @@ -107,15 +112,32 @@ scoped_ptr<PolicyBundle> PolicyLoaderIOS::Load() { |
| NSDictionary* configuration = [[NSUserDefaults standardUserDefaults] |
| dictionaryForKey:kConfigurationKey]; |
| id chromePolicy = configuration[kChromePolicyKey]; |
| + id encodedChromePolicy = configuration[kEncodedChromePolicyKey]; |
|
dconnelly
2014/03/27 13:14:19
I think a warning on !(chromePolicy ^ encodedChrom
Joao da Silva
2014/03/27 14:05:08
Added a warning on chromePolicy && encodedChromePo
|
| + |
| if (chromePolicy && [chromePolicy isKindOfClass:[NSDictionary class]]) { |
| - // NSDictionary is toll-free bridged to CFDictionaryRef, which is a |
| - // CFPropertyListRef. |
| - scoped_ptr<base::Value> value = |
| - PropertyToValue(static_cast<CFPropertyListRef>(chromePolicy)); |
| - base::DictionaryValue* dict = NULL; |
| - if (value && value->GetAsDictionary(&dict)) { |
| - PolicyMap& map = bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| - map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| + LoadNSDictionaryToPolicyBundle(chromePolicy, bundle.get()); |
| + } else if (encodedChromePolicy && |
| + [encodedChromePolicy isKindOfClass:[NSString class]]) { |
| + base::scoped_nsobject<NSData> data( |
| + [[NSData alloc] initWithBase64EncodedString:encodedChromePolicy |
| + options:0]); |
| + if (!data) { |
| + NSLog(@"Invalid Base64 encoding of EncodedChromePolicy"); |
| + } else { |
| + NSError* error = nil; |
| + NSDictionary* properties = [NSPropertyListSerialization |
| + propertyListWithData:data.get() |
| + options:NSPropertyListImmutable |
| + format:NULL |
| + error:&error]; |
| + if (!properties || error) { |
| + NSLog(@"Invalid property list in EncodedChromePolicy: %@", error); |
|
dconnelly
2014/03/27 13:14:19
Does !properties imply !!error? If not, maybe a di
Joao da Silva
2014/03/27 14:05:08
Done.
|
| + } else if (![properties isKindOfClass:[NSDictionary class]]) { |
| + NSLog(@"Invalid property list in EncodedChromePolicy: expected an " |
| + "NSDictionary but found %@", [properties class]); |
| + } else { |
| + LoadNSDictionaryToPolicyBundle(properties, bundle.get()); |
| + } |
| } |
| } |
| @@ -135,4 +157,18 @@ void PolicyLoaderIOS::UserDefaultsChanged() { |
| Reload(false); |
| } |
| +// static |
| +void PolicyLoaderIOS::LoadNSDictionaryToPolicyBundle(NSDictionary* dictionary, |
| + PolicyBundle* bundle) { |
| + // NSDictionary is toll-free bridged to CFDictionaryRef, which is a |
| + // CFPropertyListRef. |
| + scoped_ptr<base::Value> value = |
| + PropertyToValue(static_cast<CFPropertyListRef>(dictionary)); |
| + base::DictionaryValue* dict = NULL; |
| + if (value && value->GetAsDictionary(&dict)) { |
| + PolicyMap& map = bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| + map.LoadFrom(dict, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); |
| + } |
| +} |
| + |
| } // namespace policy |