| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer/automation/dom_automation_controller.h" | 5 #include "chrome/renderer/automation/dom_automation_controller.h" |
| 6 | 6 |
| 7 #include "chrome/common/json_value_serializer.h" | 7 #include "chrome/common/json_value_serializer.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 return; | 24 return; |
| 25 } | 25 } |
| 26 | 26 |
| 27 if (automation_id_ == MSG_ROUTING_NONE) { | 27 if (automation_id_ == MSG_ROUTING_NONE) { |
| 28 result->SetNull(); | 28 result->SetNull(); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 | 31 |
| 32 std::string json; | 32 std::string json; |
| 33 JSONStringValueSerializer serializer(&json); | 33 JSONStringValueSerializer serializer(&json); |
| 34 Value* value = NULL; | 34 scoped_ptr<Value> value; |
| 35 | 35 |
| 36 // Warning: note that JSON officially requires the root-level object to be | 36 // Warning: note that JSON officially requires the root-level object to be |
| 37 // an object (e.g. {foo:3}) or an array, while here we're serializing | 37 // an object (e.g. {foo:3}) or an array, while here we're serializing |
| 38 // strings, bools, etc. to "JSON". This only works because (a) the JSON | 38 // strings, bools, etc. to "JSON". This only works because (a) the JSON |
| 39 // writer is lenient, and (b) on the receiving side we wrap the JSON string | 39 // writer is lenient, and (b) on the receiving side we wrap the JSON string |
| 40 // in square brackets, converting it to an array, then parsing it and | 40 // in square brackets, converting it to an array, then parsing it and |
| 41 // grabbing the 0th element to get the value out. | 41 // grabbing the 0th element to get the value out. |
| 42 switch(args[0].type) { | 42 switch(args[0].type) { |
| 43 case NPVariantType_String: { | 43 case NPVariantType_String: { |
| 44 value = Value::CreateStringValue(args[0].ToString()); | 44 value.reset(Value::CreateStringValue(args[0].ToString())); |
| 45 break; | 45 break; |
| 46 } | 46 } |
| 47 case NPVariantType_Bool: { | 47 case NPVariantType_Bool: { |
| 48 value = Value::CreateBooleanValue(args[0].ToBoolean()); | 48 value.reset(Value::CreateBooleanValue(args[0].ToBoolean())); |
| 49 break; | 49 break; |
| 50 } | 50 } |
| 51 case NPVariantType_Int32: { | 51 case NPVariantType_Int32: { |
| 52 value = Value::CreateIntegerValue(args[0].ToInt32()); | 52 value.reset(Value::CreateIntegerValue(args[0].ToInt32())); |
| 53 break; | 53 break; |
| 54 } | 54 } |
| 55 case NPVariantType_Double: { | 55 case NPVariantType_Double: { |
| 56 // The value that is sent back is an integer while it is treated | 56 // The value that is sent back is an integer while it is treated |
| 57 // as a double in this binding. The reason being that KJS treats | 57 // as a double in this binding. The reason being that KJS treats |
| 58 // any number value as a double. Refer for more details, | 58 // any number value as a double. Refer for more details, |
| 59 // chrome/third_party/webkit/src/JavaScriptCore/bindings/c/c_utility.cpp | 59 // chrome/third_party/webkit/src/JavaScriptCore/bindings/c/c_utility.cpp |
| 60 value = Value::CreateIntegerValue(args[0].ToInt32()); | 60 value.reset(Value::CreateIntegerValue(args[0].ToInt32())); |
| 61 break; | 61 break; |
| 62 } | 62 } |
| 63 default: { | 63 default: { |
| 64 result->SetNull(); | 64 result->SetNull(); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool succeeded = serializer.Serialize(*value); | 69 bool succeeded = serializer.Serialize(*value); |
| 70 if (!succeeded) { | 70 if (!succeeded) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 // KJS::JSType only defines a NumberType (no Int32) | 92 // KJS::JSType only defines a NumberType (no Int32) |
| 93 if (!args[0].isNumber()) { | 93 if (!args[0].isNumber()) { |
| 94 result->SetNull(); | 94 result->SetNull(); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 automation_id_ = args[0].ToInt32(); | 98 automation_id_ = args[0].ToInt32(); |
| 99 result->Set(true); | 99 result->Set(true); |
| 100 } | 100 } |
| 101 | 101 |
| OLD | NEW |