| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/v8_inspector/RemoteObjectId.h" | 5 #include "platform/v8_inspector/RemoteObjectId.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/Parser.h" | 7 #include "platform/inspector_protocol/Parser.h" |
| 8 #include "platform/inspector_protocol/Values.h" | 8 #include "platform/inspector_protocol/Values.h" |
| 9 #include "wtf/PassOwnPtr.h" | 9 #include "wtf/PassOwnPtr.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) { } | 13 RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) { } |
| 14 | 14 |
| 15 PassOwnPtr<protocol::DictionaryValue> RemoteObjectIdBase::parseInjectedScriptId(
const String16& objectId) | 15 PassOwnPtr<protocol::DictionaryValue> RemoteObjectIdBase::parseInjectedScriptId(
const String16& objectId) |
| 16 { | 16 { |
| 17 OwnPtr<protocol::Value> parsedValue = protocol::parseJSON(objectId); | 17 OwnPtr<protocol::Value> parsedValue = protocol::parseJSON(objectId); |
| 18 if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject) | 18 if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject) |
| 19 return nullptr; | 19 return nullptr; |
| 20 | 20 |
| 21 OwnPtr<protocol::DictionaryValue> parsedObjectId = adoptPtr(protocol::Dictio
naryValue::cast(parsedValue.leakPtr())); | 21 OwnPtr<protocol::DictionaryValue> parsedObjectId = adoptPtr(protocol::Dictio
naryValue::cast(parsedValue.leakPtr())); |
| 22 bool success = parsedObjectId->getNumber("injectedScriptId", &m_injectedScri
ptId); | 22 bool success = parsedObjectId->getNumber("injectedScriptId", &m_injectedScri
ptId); |
| 23 if (success) | 23 if (success) |
| 24 return parsedObjectId.release(); | 24 return parsedObjectId; |
| 25 return nullptr; | 25 return nullptr; |
| 26 } | 26 } |
| 27 | 27 |
| 28 RemoteObjectId::RemoteObjectId() : RemoteObjectIdBase(), m_id(0) { } | 28 RemoteObjectId::RemoteObjectId() : RemoteObjectIdBase(), m_id(0) { } |
| 29 | 29 |
| 30 PassOwnPtr<RemoteObjectId> RemoteObjectId::parse(ErrorString* errorString, const
String16& objectId) | 30 PassOwnPtr<RemoteObjectId> RemoteObjectId::parse(ErrorString* errorString, const
String16& objectId) |
| 31 { | 31 { |
| 32 OwnPtr<RemoteObjectId> result = adoptPtr(new RemoteObjectId()); | 32 OwnPtr<RemoteObjectId> result = adoptPtr(new RemoteObjectId()); |
| 33 OwnPtr<protocol::DictionaryValue> parsedObjectId = result->parseInjectedScri
ptId(objectId); | 33 OwnPtr<protocol::DictionaryValue> parsedObjectId = result->parseInjectedScri
ptId(objectId); |
| 34 if (!parsedObjectId) { | 34 if (!parsedObjectId) { |
| 35 *errorString = "Invalid remote object id"; | 35 *errorString = "Invalid remote object id"; |
| 36 return nullptr; | 36 return nullptr; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool success = parsedObjectId->getNumber("id", &result->m_id); | 39 bool success = parsedObjectId->getNumber("id", &result->m_id); |
| 40 if (!success) { | 40 if (!success) { |
| 41 *errorString = "Invalid remote object id"; | 41 *errorString = "Invalid remote object id"; |
| 42 return nullptr; | 42 return nullptr; |
| 43 } | 43 } |
| 44 return result.release(); | 44 return result; |
| 45 } | 45 } |
| 46 | 46 |
| 47 RemoteCallFrameId::RemoteCallFrameId() : RemoteObjectIdBase(), m_frameOrdinal(0)
{ } | 47 RemoteCallFrameId::RemoteCallFrameId() : RemoteObjectIdBase(), m_frameOrdinal(0)
{ } |
| 48 | 48 |
| 49 PassOwnPtr<RemoteCallFrameId> RemoteCallFrameId::parse(ErrorString* errorString,
const String16& objectId) | 49 PassOwnPtr<RemoteCallFrameId> RemoteCallFrameId::parse(ErrorString* errorString,
const String16& objectId) |
| 50 { | 50 { |
| 51 OwnPtr<RemoteCallFrameId> result = adoptPtr(new RemoteCallFrameId()); | 51 OwnPtr<RemoteCallFrameId> result = adoptPtr(new RemoteCallFrameId()); |
| 52 OwnPtr<protocol::DictionaryValue> parsedObjectId = result->parseInjectedScri
ptId(objectId); | 52 OwnPtr<protocol::DictionaryValue> parsedObjectId = result->parseInjectedScri
ptId(objectId); |
| 53 if (!parsedObjectId) { | 53 if (!parsedObjectId) { |
| 54 *errorString = "Invalid call frame id"; | 54 *errorString = "Invalid call frame id"; |
| 55 return nullptr; | 55 return nullptr; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool success = parsedObjectId->getNumber("ordinal", &result->m_frameOrdinal)
; | 58 bool success = parsedObjectId->getNumber("ordinal", &result->m_frameOrdinal)
; |
| 59 if (!success) { | 59 if (!success) { |
| 60 *errorString = "Invalid call frame id"; | 60 *errorString = "Invalid call frame id"; |
| 61 return nullptr; | 61 return nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 return result.release(); | 64 return result; |
| 65 } | 65 } |
| 66 | 66 |
| 67 String16 RemoteCallFrameId::serialize(int injectedScriptId, int frameOrdinal) | 67 String16 RemoteCallFrameId::serialize(int injectedScriptId, int frameOrdinal) |
| 68 { | 68 { |
| 69 return "{\"ordinal\":" + String16::number(frameOrdinal) + ",\"injectedScript
Id\":" + String16::number(injectedScriptId) + "}"; | 69 return "{\"ordinal\":" + String16::number(frameOrdinal) + ",\"injectedScript
Id\":" + String16::number(injectedScriptId) + "}"; |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |