Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (101895 => 101896)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-12-03 03:12:34 UTC (rev 101895)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-12-03 03:13:43 UTC (rev 101896)
@@ -1,3 +1,31 @@
+2011-12-02 Dave Michael <[email protected]>
+
+ Add WebArrayBuffer to chromium API
+ https://bugs.webkit.org/show_bug.cgi?id=73593
+
+ Reviewed by Darin Fisher.
+
+ * WebKit.gyp:
+ * public/WebArrayBuffer.h: Added.
+ (WebKit::WebArrayBuffer::~WebArrayBuffer):
+ (WebKit::WebArrayBuffer::WebArrayBuffer):
+ (WebKit::WebArrayBuffer::operator=):
+ (WebKit::WebArrayBuffer::isNull):
+ * public/WebBindings.h:
+ * src/WebArrayBuffer.cpp: Added.
+ (WebKit::WebArrayBuffer::create):
+ (WebKit::WebArrayBuffer::reset):
+ (WebKit::WebArrayBuffer::assign):
+ (WebKit::WebArrayBuffer::data):
+ (WebKit::WebArrayBuffer::byteLength):
+ (WebKit::WebArrayBuffer::toV8Value):
+ (WebKit::WebArrayBuffer::WebArrayBuffer):
+ (WebKit::WebArrayBuffer::operator=):
+ (WebKit::WebArrayBuffer::operator WTF::PassRefPtr<WTF::ArrayBuffer>):
+ * src/WebBindings.cpp:
+ (WebKit::getArrayBufferImpl):
+ (WebKit::WebBindings::getArrayBuffer):
+
2011-12-02 David Grogan <[email protected]>
Grant workers experimental access to IndexedDB.
Modified: trunk/Source/WebKit/chromium/WebKit.gyp (101895 => 101896)
--- trunk/Source/WebKit/chromium/WebKit.gyp 2011-12-03 03:12:34 UTC (rev 101895)
+++ trunk/Source/WebKit/chromium/WebKit.gyp 2011-12-03 03:13:43 UTC (rev 101896)
@@ -115,6 +115,7 @@
'public/WebAnimationController.h',
'public/WebApplicationCacheHost.h',
'public/WebApplicationCacheHostClient.h',
+ 'public/WebArrayBuffer.h',
'public/WebArrayBufferView.h',
'public/WebAttribute.h',
'public/WebAudioBus.h',
@@ -467,6 +468,7 @@
'src/WebAccessibilityObject.cpp',
'src/WebAnimationControllerImpl.cpp',
'src/WebAnimationControllerImpl.h',
+ 'src/WebArrayBuffer.cpp',
'src/WebArrayBufferView.cpp',
'src/WebAttribute.cpp',
'src/WebAudioBus.cpp',
Added: trunk/Source/WebKit/chromium/public/WebArrayBuffer.h (0 => 101896)
--- trunk/Source/WebKit/chromium/public/WebArrayBuffer.h (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebArrayBuffer.h 2011-12-03 03:13:43 UTC (rev 101896)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebArrayBuffer_h
+#define WebArrayBuffer_h
+
+#include "WebCommon.h"
+#include "WebPrivatePtr.h"
+
+#if WEBKIT_USING_V8
+namespace v8 {
+class Value;
+template <class T> class Handle;
+}
+#endif
+
+namespace WTF { class ArrayBuffer; }
+
+namespace WebKit {
+
+class WebArrayBuffer {
+public:
+ ~WebArrayBuffer() { reset(); }
+
+ WebArrayBuffer() { }
+ WebArrayBuffer(const WebArrayBuffer& b) { assign(b); }
+ WebArrayBuffer& operator=(const WebArrayBuffer& b)
+ {
+ assign(b);
+ return *this;
+ }
+
+ WEBKIT_EXPORT static WebArrayBuffer create(unsigned numElements, unsigned elementByteSize);
+
+ WEBKIT_EXPORT void reset();
+ WEBKIT_EXPORT void assign(const WebArrayBuffer&);
+
+ bool isNull() const { return m_private.isNull(); }
+ WEBKIT_EXPORT void* data() const;
+ unsigned byteLength() const;
+
+#if WEBKIT_USING_V8
+ WEBKIT_EXPORT v8::Handle<v8::Value> toV8Value();
+#endif
+
+#if WEBKIT_IMPLEMENTATION
+ WebArrayBuffer(const WTF::PassRefPtr<WTF::ArrayBuffer>&);
+ WebArrayBuffer& operator=(const PassRefPtr<WTF::ArrayBuffer>&);
+ operator WTF::PassRefPtr<WTF::ArrayBuffer>() const;
+#endif
+
+protected:
+ WebPrivatePtr<WTF::ArrayBuffer> m_private;
+};
+
+} // namespace WebKit
+
+#endif // WebArrayBuffer_h
Modified: trunk/Source/WebKit/chromium/public/WebBindings.h (101895 => 101896)
--- trunk/Source/WebKit/chromium/public/WebBindings.h 2011-12-03 03:12:34 UTC (rev 101895)
+++ trunk/Source/WebKit/chromium/public/WebBindings.h 2011-12-03 03:13:43 UTC (rev 101896)
@@ -46,6 +46,7 @@
namespace WebKit {
+class WebArrayBuffer;
class WebArrayBufferView;
class WebDragData;
class WebElement;
@@ -143,6 +144,10 @@
// If so, return that range as a WebRange object.
WEBKIT_EXPORT static bool getRange(NPObject* range, WebRange*);
+ // Return true (success) if the given npobj is an ArrayBuffer object.
+ // If so, return it as a WebArrayBuffer object.
+ WEBKIT_EXPORT static bool getArrayBuffer(NPObject* arrayBuffer, WebArrayBuffer*);
+
// Return true (success) if the given npobj is an ArrayBufferView object.
// If so, return it as a WebArrayBufferView object.
WEBKIT_EXPORT static bool getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView*);
Added: trunk/Source/WebKit/chromium/src/WebArrayBuffer.cpp (0 => 101896)
--- trunk/Source/WebKit/chromium/src/WebArrayBuffer.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/src/WebArrayBuffer.cpp 2011-12-03 03:13:43 UTC (rev 101896)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebArrayBuffer.h"
+
+#include "ArrayBuffer.h"
+#include "V8ArrayBuffer.h"
+#include <wtf/PassOwnPtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebArrayBuffer WebArrayBuffer::create(unsigned numElements, unsigned elementByteSize)
+{
+ RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(numElements, elementByteSize);
+ return WebArrayBuffer(buffer);
+}
+
+void WebArrayBuffer::reset()
+{
+ m_private.reset();
+}
+
+void WebArrayBuffer::assign(const WebArrayBuffer& other)
+{
+ m_private = other.m_private;
+}
+
+void* WebArrayBuffer::data() const
+{
+ if (!isNull())
+ return const_cast<void*>(m_private->data());
+ return 0;
+}
+
+unsigned WebArrayBuffer::byteLength() const
+{
+ if (!isNull())
+ return m_private->byteLength();
+ return 0;
+}
+
+#if WEBKIT_USING_V8
+v8::Handle<v8::Value> WebArrayBuffer::toV8Value()
+{
+ return V8ArrayBuffer::wrap(m_private.get());
+}
+#endif
+
+WebArrayBuffer::WebArrayBuffer(const WTF::PassRefPtr<WTF::ArrayBuffer>& blob)
+ : m_private(blob)
+{
+}
+
+WebArrayBuffer& WebArrayBuffer::operator=(const WTF::PassRefPtr<WTF::ArrayBuffer>& blob)
+{
+ m_private = blob;
+ return *this;
+}
+
+WebArrayBuffer::operator WTF::PassRefPtr<WTF::ArrayBuffer>() const
+{
+ return m_private.get();
+}
+
+} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebBindings.cpp (101895 => 101896)
--- trunk/Source/WebKit/chromium/src/WebBindings.cpp 2011-12-03 03:12:34 UTC (rev 101895)
+++ trunk/Source/WebKit/chromium/src/WebBindings.cpp 2011-12-03 03:13:43 UTC (rev 101896)
@@ -39,6 +39,7 @@
#include "DOMWindow.h"
#include "NPV8Object.h" // for PrivateIdentifier
#include "Range.h"
+#include "V8ArrayBuffer.h"
#include "V8ArrayBufferView.h"
#include "V8BindingState.h"
#include "V8DOMWrapper.h"
@@ -49,6 +50,7 @@
#elif USE(JSC)
#include "bridge/c/c_utility.h"
#endif
+#include "WebArrayBuffer.h"
#include "WebArrayBufferView.h"
#include "WebElement.h"
#include "WebRange.h"
@@ -234,6 +236,21 @@
return true;
}
+static bool getArrayBufferImpl(NPObject* object, WebArrayBuffer* arrayBuffer)
+{
+ if (!object || (object->_class != npScriptObjectClass))
+ return false;
+
+ V8NPObject* v8NPObject = reinterpret_cast<V8NPObject*>(object);
+ v8::Handle<v8::Object> v8Object(v8NPObject->v8Object);
+ ArrayBuffer* native = V8ArrayBuffer::HasInstance(v8Object) ? V8ArrayBuffer::toNative(v8Object) : 0;
+ if (!native)
+ return false;
+
+ *arrayBuffer = WebArrayBuffer(native);
+ return true;
+}
+
static bool getArrayBufferViewImpl(NPObject* object, WebArrayBufferView* arrayBufferView)
{
if (!object || (object->_class != npScriptObjectClass))
@@ -283,6 +300,16 @@
#endif
}
+bool WebBindings::getArrayBuffer(NPObject* arrayBuffer, WebArrayBuffer* webArrayBuffer)
+{
+#if USE(V8)
+ return getArrayBufferImpl(arrayBuffer, webArrayBuffer);
+#else
+ // Not supported on other ports (JSC, etc).
+ return false;
+#endif
+}
+
bool WebBindings::getArrayBufferView(NPObject* arrayBufferView, WebArrayBufferView* webArrayBufferView)
{
#if USE(V8)