Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2473533002: Make NFC.cpp use JSON::Stringify (Closed)
Patch Set: Fix logic error Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "modules/nfc/NFC.h" 5 #include "modules/nfc/NFC.h"
6 6
7 #include "bindings/core/v8/JSONValuesForV8.h" 7 #include "bindings/core/v8/JSONValuesForV8.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/V8ArrayBuffer.h" 9 #include "bindings/core/v8/V8ArrayBuffer.h"
10 #include "bindings/core/v8/V8StringResource.h"
10 #include "core/dom/DOMArrayBuffer.h" 11 #include "core/dom/DOMArrayBuffer.h"
11 #include "core/dom/DOMException.h" 12 #include "core/dom/DOMException.h"
12 #include "core/dom/Document.h" 13 #include "core/dom/Document.h"
13 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
14 #include "core/frame/LocalDOMWindow.h" 15 #include "core/frame/LocalDOMWindow.h"
15 #include "modules/nfc/NFCError.h" 16 #include "modules/nfc/NFCError.h"
16 #include "modules/nfc/NFCMessage.h" 17 #include "modules/nfc/NFCMessage.h"
17 #include "modules/nfc/NFCPushOptions.h" 18 #include "modules/nfc/NFCPushOptions.h"
18 #include "platform/mojo/MojoHelper.h" 19 #include "platform/mojo/MojoHelper.h"
19 #include "public/platform/InterfaceProvider.h" 20 #include "public/platform/InterfaceProvider.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (value->IsNumber()) 167 if (value->IsNumber())
167 return mojo::WTFArray<uint8_t>::From( 168 return mojo::WTFArray<uint8_t>::From(
168 WTF::String::number(value.As<v8::Number>()->Value())); 169 WTF::String::number(value.As<v8::Number>()->Value()));
169 170
170 if (value->IsString()) { 171 if (value->IsString()) {
171 blink::V8StringResource<> stringResource = value; 172 blink::V8StringResource<> stringResource = value;
172 if (stringResource.prepare()) 173 if (stringResource.prepare())
173 return mojo::WTFArray<uint8_t>::From<WTF::String>(stringResource); 174 return mojo::WTFArray<uint8_t>::From<WTF::String>(stringResource);
174 } 175 }
175 176
176 if (value->IsObject() && !value->IsArrayBuffer()) { 177 if (value->IsObject() && !value->IsArray() && !value->IsArrayBuffer()) {
177 std::unique_ptr<blink::JSONValue> jsonResult = 178 v8::Local<v8::String> jsonString;
178 blink::toJSONValue(scriptValue.context(), value); 179 if (v8::JSON::Stringify(scriptValue.context(), value.As<v8::Object>())
179 if (jsonResult && (jsonResult->getType() == blink::JSONValue::TypeObject)) 180 .ToLocal(&jsonString)) {
180 return mojo::WTFArray<uint8_t>::From(jsonResult->toJSONString()); 181 WTF::String wtfString = blink::v8StringToWebCoreString<WTF::String>(
182 jsonString, blink::DoNotExternalize);
183 return mojo::WTFArray<uint8_t>::From(wtfString);
184 }
181 } 185 }
182 186
183 if (value->IsArrayBuffer()) 187 if (value->IsArrayBuffer())
184 return mojo::WTFArray<uint8_t>::From( 188 return mojo::WTFArray<uint8_t>::From(
185 blink::V8ArrayBuffer::toImpl(value.As<v8::Object>())); 189 blink::V8ArrayBuffer::toImpl(value.As<v8::Object>()));
186 190
187 return nullptr; 191 return nullptr;
188 } 192 }
189 }; 193 };
190 194
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // TODO(shalamov): Not implemented. 586 // TODO(shalamov): Not implemented.
583 } 587 }
584 588
585 DEFINE_TRACE(NFC) { 589 DEFINE_TRACE(NFC) {
586 PageVisibilityObserver::trace(visitor); 590 PageVisibilityObserver::trace(visitor);
587 ContextLifecycleObserver::trace(visitor); 591 ContextLifecycleObserver::trace(visitor);
588 visitor->trace(m_requests); 592 visitor->trace(m_requests);
589 } 593 }
590 594
591 } // namespace blink 595 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698