2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Copyright (c) 2016 GitHub, Inc.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Use of this source code is governed by the MIT license that can be
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// found in the LICENSE file.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "shell/browser/mac/dict_util.h"
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-02 14:05:37 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <string>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "base/json/json_writer.h"
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "base/strings/sys_string_conversions.h"
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "base/values.h"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								namespace electron {
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-28 15:08:22 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								NSArray* ListValueToNSArray(const base::ListValue& value) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  std::string json;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if (!base::JSONWriter::Write(value, &json))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return nil;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-01 21:27:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  id obj = [NSJSONSerialization JSONObjectWithData:jsonData
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                           options:0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                             error:nil];
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-28 15:08:22 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if (![obj isKindOfClass:[NSArray class]])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return nil;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return obj;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								base::ListValue NSArrayToListValue(NSArray* arr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  base::ListValue result;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if (!arr)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return result;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  for (id value in arr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if ([value isKindOfClass:[NSString class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.AppendString(base::SysNSStringToUTF8(value));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSNumber class]]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const char* objc_type = [value objCType];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      if (strcmp(objc_type, @encode(BOOL)) == 0 ||
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          strcmp(objc_type, @encode(char)) == 0)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.AppendBoolean([value boolValue]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      else if (strcmp(objc_type, @encode(double)) == 0 ||
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               strcmp(objc_type, @encode(float)) == 0)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.AppendDouble([value doubleValue]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      else
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.AppendInteger([value intValue]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSArray class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.Append(NSArrayToListValue(value));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSDictionary class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.Append(NSDictionaryToDictionaryValue(value));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.AppendString(base::SysNSStringToUTF8([value description]));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return result;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-20 14:47:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								NSDictionary* DictionaryValueToNSDictionary(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const base::DictionaryValue& value) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  std::string json;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if (!base::JSONWriter::Write(value, &json))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return nil;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-01 21:27:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  id obj = [NSJSONSerialization JSONObjectWithData:jsonData
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                           options:0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                             error:nil];
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if (![obj isKindOfClass:[NSDictionary class]])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return nil;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return obj;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								base::DictionaryValue NSDictionaryToDictionaryValue(NSDictionary* dict) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  base::DictionaryValue result;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if (!dict)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return result;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 14:40:19 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  for (id key in dict) {
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 16:01:08 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    std::string str_key = base::SysNSStringToUTF8(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [key isKindOfClass:[NSString class]] ? key : [key description]);
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    id value = [dict objectForKey:key];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if ([value isKindOfClass:[NSString class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.SetKey(str_key, base::Value(base::SysNSStringToUTF8(value)));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSNumber class]]) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      const char* objc_type = [value objCType];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      if (strcmp(objc_type, @encode(BOOL)) == 0 ||
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          strcmp(objc_type, @encode(char)) == 0)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.SetKey(str_key, base::Value([value boolValue]));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      else if (strcmp(objc_type, @encode(double)) == 0 ||
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               strcmp(objc_type, @encode(float)) == 0)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.SetKey(str_key, base::Value([value doubleValue]));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      else
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        result.SetKey(str_key, base::Value([value intValue]));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSArray class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.SetKey(str_key, NSArrayToListValue(value));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ([value isKindOfClass:[NSDictionary class]]) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.SetKey(str_key, NSDictionaryToDictionaryValue(value));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 14:30:59 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      result.SetKey(str_key,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    base::Value(base::SysNSStringToUTF8([value description])));
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  }
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-18 15:49:33 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  return result;
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-05 16:26:44 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}  // namespace electron
							 |