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

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

Issue 1486043002: [webnfc] Implement push method for Android nfc mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@step_6_add_mojo_service_CL
Patch Set: Move WindowAndroidChangedObserver to other observers in content layer Created 4 years, 4 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/resources/nfc-helpers.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (value->IsArrayBuffer()) { 95 if (value->IsArrayBuffer()) {
96 return NFCRecordType::OPAQUE_RECORD; 96 return NFCRecordType::OPAQUE_RECORD;
97 } 97 }
98 } 98 }
99 99
100 return NFCRecordType::EMPTY; 100 return NFCRecordType::EMPTY;
101 } 101 }
102 102
103 void setMediaType(NFCRecordPtr& recordPtr, const WTF::String& recordMediaType, c onst WTF::String& defaultMediaType) 103 void setMediaType(NFCRecordPtr& recordPtr, const WTF::String& recordMediaType, c onst WTF::String& defaultMediaType)
104 { 104 {
105 recordPtr->mediaType = recordMediaType.isEmpty() ? defaultMediaType : record MediaType; 105 recordPtr->media_type = recordMediaType.isEmpty() ? defaultMediaType : recor dMediaType;
106 } 106 }
107 107
108 template <> 108 template <>
109 struct TypeConverter<mojo::WTFArray<uint8_t>, WTF::String> { 109 struct TypeConverter<mojo::WTFArray<uint8_t>, WTF::String> {
110 static mojo::WTFArray<uint8_t> Convert(const WTF::String& string) 110 static mojo::WTFArray<uint8_t> Convert(const WTF::String& string)
111 { 111 {
112 WTF::CString utf8String = string.utf8(); 112 WTF::CString utf8String = string.utf8();
113 WTF::Vector<uint8_t> array; 113 WTF::Vector<uint8_t> array;
114 array.append(utf8String.data(), utf8String.length()); 114 array.append(utf8String.data(), utf8String.length());
115 return mojo::WTFArray<uint8_t>(std::move(array)); 115 return mojo::WTFArray<uint8_t>(std::move(array));
116 } 116 }
117 }; 117 };
118 118
119 template <> 119 template <>
120 struct TypeConverter<mojo::WTFArray<uint8_t>, blink::DOMArrayBuffer*> { 120 struct TypeConverter<mojo::WTFArray<uint8_t>, blink::DOMArrayBuffer*> {
121 static mojo::WTFArray<uint8_t> Convert(blink::DOMArrayBuffer* buffer) 121 static mojo::WTFArray<uint8_t> Convert(blink::DOMArrayBuffer* buffer)
122 { 122 {
123 WTF::Vector<uint8_t> array; 123 WTF::Vector<uint8_t> array;
124 array.append(static_cast<uint8_t*>(buffer->data()), buffer->byteLength() ); 124 array.append(static_cast<uint8_t*>(buffer->data()), buffer->byteLength() );
125 return mojo::WTFArray<uint8_t>(std::move(array)); 125 return mojo::WTFArray<uint8_t>(std::move(array));
126 } 126 }
127 }; 127 };
128 128
129 template <> 129 template <>
130 struct TypeConverter<NFCRecordPtr, WTF::String> { 130 struct TypeConverter<NFCRecordPtr, WTF::String> {
131 static NFCRecordPtr Convert(const WTF::String& string) 131 static NFCRecordPtr Convert(const WTF::String& string)
132 { 132 {
133 NFCRecordPtr record = NFCRecord::New(); 133 NFCRecordPtr record = NFCRecord::New();
134 record->recordType = NFCRecordType::TEXT; 134 record->record_type = NFCRecordType::TEXT;
135 record->mediaType = kPlainTextMimeType; 135 record->media_type = kPlainTextMimeType;
136 record->mediaType.append(kCharSetUTF8); 136 record->media_type.append(kCharSetUTF8);
137 record->data = mojo::WTFArray<uint8_t>::From(string); 137 record->data = mojo::WTFArray<uint8_t>::From(string);
138 return record; 138 return record;
139 } 139 }
140 }; 140 };
141 141
142 template <> 142 template <>
143 struct TypeConverter<NFCRecordPtr, blink::DOMArrayBuffer*> { 143 struct TypeConverter<NFCRecordPtr, blink::DOMArrayBuffer*> {
144 static NFCRecordPtr Convert(blink::DOMArrayBuffer* buffer) 144 static NFCRecordPtr Convert(blink::DOMArrayBuffer* buffer)
145 { 145 {
146 NFCRecordPtr record = NFCRecord::New(); 146 NFCRecordPtr record = NFCRecord::New();
147 record->recordType = NFCRecordType::OPAQUE_RECORD; 147 record->record_type = NFCRecordType::OPAQUE_RECORD;
148 record->mediaType = kOpaqueMimeType; 148 record->media_type = kOpaqueMimeType;
149 record->data = mojo::WTFArray<uint8_t>::From(buffer); 149 record->data = mojo::WTFArray<uint8_t>::From(buffer);
150 return record; 150 return record;
151 } 151 }
152 }; 152 };
153 153
154 template <> 154 template <>
155 struct TypeConverter<NFCMessagePtr, WTF::String> { 155 struct TypeConverter<NFCMessagePtr, WTF::String> {
156 static NFCMessagePtr Convert(const WTF::String& string) 156 static NFCMessagePtr Convert(const WTF::String& string)
157 { 157 {
158 NFCMessagePtr message = NFCMessage::New(); 158 NFCMessagePtr message = NFCMessage::New();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 }; 191 };
192 192
193 template <> 193 template <>
194 struct TypeConverter<NFCRecordPtr, blink::NFCRecord> { 194 struct TypeConverter<NFCRecordPtr, blink::NFCRecord> {
195 static NFCRecordPtr Convert(const blink::NFCRecord& record) 195 static NFCRecordPtr Convert(const blink::NFCRecord& record)
196 { 196 {
197 NFCRecordPtr recordPtr = NFCRecord::New(); 197 NFCRecordPtr recordPtr = NFCRecord::New();
198 198
199 if (record.hasRecordType()) 199 if (record.hasRecordType())
200 recordPtr->recordType = toNFCRecordType(record.recordType()); 200 recordPtr->record_type = toNFCRecordType(record.recordType());
201 else 201 else
202 recordPtr->recordType = deduceRecordTypeFromDataType(record); 202 recordPtr->record_type = deduceRecordTypeFromDataType(record);
203 203
204 // If record type is "empty", no need to set media type or data. 204 // If record type is "empty", no need to set media type or data.
205 // https://w3c.github.io/web-nfc/#creating-web-nfc-message 205 // https://w3c.github.io/web-nfc/#creating-web-nfc-message
206 if (recordPtr->recordType == NFCRecordType::EMPTY) 206 if (recordPtr->record_type == NFCRecordType::EMPTY)
207 return recordPtr; 207 return recordPtr;
208 208
209 switch (recordPtr->recordType) { 209 switch (recordPtr->record_type) {
210 case NFCRecordType::TEXT: 210 case NFCRecordType::TEXT:
211 case NFCRecordType::URL: 211 case NFCRecordType::URL:
212 setMediaType(recordPtr, record.mediaType(), kPlainTextMimeType); 212 setMediaType(recordPtr, record.mediaType(), kPlainTextMimeType);
213 recordPtr->mediaType.append(kCharSetUTF8); 213 recordPtr->media_type.append(kCharSetUTF8);
214 break; 214 break;
215 case NFCRecordType::JSON: 215 case NFCRecordType::JSON:
216 setMediaType(recordPtr, record.mediaType(), kJsonMimeType); 216 setMediaType(recordPtr, record.mediaType(), kJsonMimeType);
217 break; 217 break;
218 case NFCRecordType::OPAQUE_RECORD: 218 case NFCRecordType::OPAQUE_RECORD:
219 setMediaType(recordPtr, record.mediaType(), kOpaqueMimeType); 219 setMediaType(recordPtr, record.mediaType(), kOpaqueMimeType);
220 break; 220 break;
221 default: 221 default:
222 NOTREACHED(); 222 NOTREACHED();
223 break; 223 break;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 pushOptionsPtr->target = toNFCPushTarget(pushOptions.target()); 296 pushOptionsPtr->target = toNFCPushTarget(pushOptions.target());
297 else 297 else
298 pushOptionsPtr->target = NFCPushTarget::ANY; 298 pushOptionsPtr->target = NFCPushTarget::ANY;
299 299
300 if (pushOptions.hasTimeout()) 300 if (pushOptions.hasTimeout())
301 pushOptionsPtr->timeout = pushOptions.timeout(); 301 pushOptionsPtr->timeout = pushOptions.timeout();
302 else 302 else
303 pushOptionsPtr->timeout = std::numeric_limits<double>::infinity(); 303 pushOptionsPtr->timeout = std::numeric_limits<double>::infinity();
304 304
305 if (pushOptions.hasIgnoreRead()) 305 if (pushOptions.hasIgnoreRead())
306 pushOptionsPtr->ignoreRead = pushOptions.ignoreRead(); 306 pushOptionsPtr->ignore_read = pushOptions.ignoreRead();
307 else 307 else
308 pushOptionsPtr->ignoreRead = true; 308 pushOptionsPtr->ignore_read = true;
309 309
310 return pushOptionsPtr; 310 return pushOptionsPtr;
311 } 311 }
312 }; 312 };
313 313
314 } // namespace mojo 314 } // namespace mojo
315 315
316 namespace blink { 316 namespace blink {
317 namespace { 317 namespace {
318 318
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 580 }
581 581
582 DEFINE_TRACE(NFC) 582 DEFINE_TRACE(NFC)
583 { 583 {
584 PageVisibilityObserver::trace(visitor); 584 PageVisibilityObserver::trace(visitor);
585 ContextLifecycleObserver::trace(visitor); 585 ContextLifecycleObserver::trace(visitor);
586 visitor->trace(m_requests); 586 visitor->trace(m_requests);
587 } 587 }
588 588
589 } // namespace blink 589 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/resources/nfc-helpers.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698