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

Side by Side Diff: Source/web/WebBindings.cpp

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/web/WebArrayBufferView.cpp ('k') | Source/wtf/ArrayBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "public/web/WebBindings.h" 32 #include "public/web/WebBindings.h"
33 33
34 #include "bindings/core/v8/NPV8Object.h" 34 #include "bindings/core/v8/NPV8Object.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/V8ArrayBuffer.h"
37 #include "bindings/core/v8/V8ArrayBufferView.h"
36 #include "bindings/core/v8/V8DOMWrapper.h" 38 #include "bindings/core/v8/V8DOMWrapper.h"
37 #include "bindings/core/v8/V8Element.h" 39 #include "bindings/core/v8/V8Element.h"
38 #include "bindings/core/v8/V8NPObject.h" 40 #include "bindings/core/v8/V8NPObject.h"
39 #include "bindings/core/v8/V8NPUtils.h" 41 #include "bindings/core/v8/V8NPUtils.h"
40 #include "bindings/core/v8/V8Range.h" 42 #include "bindings/core/v8/V8Range.h"
41 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
42 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
43 #include "bindings/core/v8/npruntime_impl.h" 43 #include "bindings/core/v8/npruntime_impl.h"
44 #include "bindings/core/v8/npruntime_priv.h" 44 #include "bindings/core/v8/npruntime_priv.h"
45 #include "core/dom/Range.h" 45 #include "core/dom/Range.h"
46 #include "core/frame/LocalDOMWindow.h" 46 #include "core/frame/LocalDOMWindow.h"
47 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
48 #include "public/platform/WebArrayBuffer.h" 48 #include "public/platform/WebArrayBuffer.h"
49 #include "public/web/WebArrayBufferView.h" 49 #include "public/web/WebArrayBufferView.h"
50 #include "public/web/WebElement.h" 50 #include "public/web/WebElement.h"
51 #include "public/web/WebRange.h" 51 #include "public/web/WebRange.h"
52 #include "wtf/ArrayBufferView.h"
53 52
54 namespace blink { 53 namespace blink {
55 54
56 bool WebBindings::construct(NPP npp, NPObject* object, const NPVariant* args, ui nt32_t argCount, NPVariant* result) 55 bool WebBindings::construct(NPP npp, NPObject* object, const NPVariant* args, ui nt32_t argCount, NPVariant* result)
57 { 56 {
58 return _NPN_Construct(npp, object, args, argCount, result); 57 return _NPN_Construct(npp, object, args, argCount, result);
59 } 58 }
60 59
61 NPObject* WebBindings::createObject(NPP npp, NPClass* npClass) 60 NPObject* WebBindings::createObject(NPP npp, NPClass* npClass)
62 { 61 {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return false; 278 return false;
280 279
281 V8NPObject* v8NPObject = npObjectToV8NPObject(object); 280 V8NPObject* v8NPObject = npObjectToV8NPObject(object);
282 if (!v8NPObject) 281 if (!v8NPObject)
283 return false; 282 return false;
284 283
285 v8::HandleScope handleScope(isolate); 284 v8::HandleScope handleScope(isolate);
286 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NPOb ject->v8Object); 285 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NPOb ject->v8Object);
287 if (v8Object.IsEmpty()) 286 if (v8Object.IsEmpty())
288 return false; 287 return false;
289 ArrayBuffer* native = V8ArrayBuffer::hasInstance(v8Object, isolate) ? V8Arra yBuffer::toImpl(v8Object) : 0; 288 DOMArrayBuffer* impl = V8ArrayBuffer::hasInstance(v8Object, isolate) ? V8Arr ayBuffer::toImpl(v8Object) : 0;
290 if (!native) 289 if (!impl)
291 return false; 290 return false;
292 291
293 *arrayBuffer = WebArrayBuffer(native); 292 *arrayBuffer = WebArrayBuffer(impl->buffer());
294 return true; 293 return true;
295 } 294 }
296 295
297 static bool getArrayBufferViewImpl(NPObject* object, WebArrayBufferView* arrayBu fferView, v8::Isolate* isolate) 296 static bool getArrayBufferViewImpl(NPObject* object, WebArrayBufferView* arrayBu fferView, v8::Isolate* isolate)
298 { 297 {
299 if (!object) 298 if (!object)
300 return false; 299 return false;
301 300
302 V8NPObject* v8NPObject = npObjectToV8NPObject(object); 301 V8NPObject* v8NPObject = npObjectToV8NPObject(object);
303 if (!v8NPObject) 302 if (!v8NPObject)
304 return false; 303 return false;
305 304
306 v8::HandleScope handleScope(isolate); 305 v8::HandleScope handleScope(isolate);
307 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NPOb ject->v8Object); 306 v8::Handle<v8::Object> v8Object = v8::Local<v8::Object>::New(isolate, v8NPOb ject->v8Object);
308 if (v8Object.IsEmpty()) 307 if (v8Object.IsEmpty())
309 return false; 308 return false;
310 ArrayBufferView* native = V8ArrayBufferView::hasInstance(v8Object, isolate) ? V8ArrayBufferView::toImpl(v8Object) : 0; 309 DOMArrayBufferView* impl = V8ArrayBufferView::hasInstance(v8Object, isolate) ? V8ArrayBufferView::toImpl(v8Object) : 0;
311 if (!native) 310 if (!impl)
312 return false; 311 return false;
313 312
314 *arrayBufferView = WebArrayBufferView(native); 313 *arrayBufferView = WebArrayBufferView(impl->view());
315 return true; 314 return true;
316 } 315 }
317 316
318 static NPObject* makeIntArrayImpl(const WebVector<int>& data, v8::Isolate* isola te) 317 static NPObject* makeIntArrayImpl(const WebVector<int>& data, v8::Isolate* isola te)
319 { 318 {
320 v8::HandleScope handleScope(isolate); 319 v8::HandleScope handleScope(isolate);
321 v8::Handle<v8::Array> result = v8::Array::New(isolate, data.size()); 320 v8::Handle<v8::Array> result = v8::Array::New(isolate, data.size());
322 for (size_t i = 0; i < data.size(); ++i) 321 for (size_t i = 0; i < data.size(); ++i)
323 result->Set(i, v8::Number::New(isolate, data[i])); 322 result->Set(i, v8::Number::New(isolate, data[i]));
324 323
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (!v8Object) 395 if (!v8Object)
397 return v8::Undefined(isolate); 396 return v8::Undefined(isolate);
398 return convertNPVariantToV8Object(variant, v8Object->rootObject->frame() ->script().windowScriptNPObject(), isolate); 397 return convertNPVariantToV8Object(variant, v8Object->rootObject->frame() ->script().windowScriptNPObject(), isolate);
399 } 398 }
400 // Safe to pass 0 since we have checked the script object class to make sure the 399 // Safe to pass 0 since we have checked the script object class to make sure the
401 // argument is a primitive v8 type. 400 // argument is a primitive v8 type.
402 return convertNPVariantToV8Object(variant, 0, isolate); 401 return convertNPVariantToV8Object(variant, 0, isolate);
403 } 402 }
404 403
405 } // namespace blink 404 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebArrayBufferView.cpp ('k') | Source/wtf/ArrayBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698