| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/push_messaging/PushMessageData.h" | 5 #include "modules/push_messaging/PushMessageData.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "bindings/modules/v8/ArrayBufferOrArrayBufferViewOrUSVString.h" | 10 #include "bindings/modules/v8/ArrayBufferOrArrayBufferViewOrUSVString.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // Note that the content type of the Blob object is deliberately not being | 66 // Note that the content type of the Blob object is deliberately not being |
| 67 // provided, following the specification. | 67 // provided, following the specification. |
| 68 | 68 |
| 69 const long long byteLength = blobData->length(); | 69 const long long byteLength = blobData->length(); |
| 70 return Blob::create(BlobDataHandle::create(std::move(blobData), byteLength)); | 70 return Blob::create(BlobDataHandle::create(std::move(blobData), byteLength)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ScriptValue PushMessageData::json(ScriptState* scriptState, | 73 ScriptValue PushMessageData::json(ScriptState* scriptState, |
| 74 ExceptionState& exceptionState) const { | 74 ExceptionState& exceptionState) const { |
| 75 v8::Isolate* isolate = scriptState->isolate(); | |
| 76 | |
| 77 ScriptState::Scope scope(scriptState); | 75 ScriptState::Scope scope(scriptState); |
| 78 v8::Local<v8::String> dataString = v8String(isolate, text()); | 76 v8::Local<v8::Value> parsed = |
| 79 | 77 fromJSONString(scriptState->isolate(), text(), exceptionState); |
| 80 v8::TryCatch block(isolate); | 78 if (exceptionState.hadException()) |
| 81 v8::Local<v8::Value> parsed; | |
| 82 if (!v8Call(v8::JSON::Parse(isolate, dataString), parsed, block)) { | |
| 83 exceptionState.rethrowV8Exception(block.Exception()); | |
| 84 return ScriptValue(); | 79 return ScriptValue(); |
| 85 } | |
| 86 | 80 |
| 87 return ScriptValue(scriptState, parsed); | 81 return ScriptValue(scriptState, parsed); |
| 88 } | 82 } |
| 89 | 83 |
| 90 String PushMessageData::text() const { | 84 String PushMessageData::text() const { |
| 91 return UTF8Encoding().decode(m_data.data(), m_data.size()); | 85 return UTF8Encoding().decode(m_data.data(), m_data.size()); |
| 92 } | 86 } |
| 93 | 87 |
| 94 DEFINE_TRACE(PushMessageData) {} | 88 DEFINE_TRACE(PushMessageData) {} |
| 95 | 89 |
| 96 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |