Commit 14a30126 authored by eric@webkit.org's avatar eric@webkit.org

2010-01-27 Marcus Bulach <bulach@chromium.org>

        Reviewed by Dimitri Glazkov.

        Adds EventSource bindings for V8
        https://bugs.webkit.org/show_bug.cgi?id=33695

        No new tests (existing layout tests for EventSource should pass).

        * Android.v8bindings.mk:
        * WebCore.gypi:
        * bindings/scripts/CodeGeneratorV8.pm:
        * bindings/v8/DOMObjectsInclude.h:
        * bindings/v8/DerivedSourcesAllInOne.cpp:
        * bindings/v8/V8DOMWrapper.cpp:
        * bindings/v8/V8DOMWrapper.h:
        * bindings/v8/V8Index.cpp:
        * bindings/v8/V8Index.h:
        * bindings/v8/WorkerContextExecutionProxy.cpp:
        * bindings/v8/custom/V8CustomBinding.h:
        * bindings/v8/custom/V8EventSourceConstructor.cpp: Added.
        * bindings/v8/custom/V8EventSourceCustom.cpp: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53931 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 82e6b783
......@@ -110,6 +110,8 @@ LOCAL_SRC_FILES += \
bindings/v8/custom/V8DocumentLocationCustom.cpp \
bindings/v8/custom/V8ElementCustom.cpp \
bindings/v8/custom/V8EventCustom.cpp \
bindings/v8/custom/V8EventSourceConstructor.cpp \
bindings/v8/custom/V8EventSourceCustom.cpp \
bindings/v8/custom/V8FileListCustom.cpp \
bindings/v8/custom/V8GeolocationCustom.cpp \
bindings/v8/custom/V8HTMLAllCollectionCustom.cpp \
......
2010-01-27 Marcus Bulach <bulach@chromium.org>
Reviewed by Dimitri Glazkov.
Adds EventSource bindings for V8
https://bugs.webkit.org/show_bug.cgi?id=33695
No new tests (existing layout tests for EventSource should pass).
* Android.v8bindings.mk:
* WebCore.gypi:
* bindings/scripts/CodeGeneratorV8.pm:
* bindings/v8/DOMObjectsInclude.h:
* bindings/v8/DerivedSourcesAllInOne.cpp:
* bindings/v8/V8DOMWrapper.cpp:
* bindings/v8/V8DOMWrapper.h:
* bindings/v8/V8Index.cpp:
* bindings/v8/V8Index.h:
* bindings/v8/WorkerContextExecutionProxy.cpp:
* bindings/v8/custom/V8CustomBinding.h:
* bindings/v8/custom/V8EventSourceConstructor.cpp: Added.
* bindings/v8/custom/V8EventSourceCustom.cpp: Added.
2010-01-27 Kent Hansen <kent.hansen@nokia.com>
Reviewed by Simon Hausmann.
......@@ -196,6 +196,7 @@
'page/Coordinates.idl',
'page/DOMSelection.idl',
'page/DOMWindow.idl',
'page/EventSource.idl',
'page/Geolocation.idl',
'page/Geoposition.idl',
'page/History.idl',
......@@ -693,6 +694,8 @@
'bindings/v8/custom/V8DocumentCustom.cpp',
'bindings/v8/custom/V8ElementCustom.cpp',
'bindings/v8/custom/V8EventCustom.cpp',
'bindings/v8/custom/V8EventSourceConstructor.cpp',
'bindings/v8/custom/V8EventSourceCustom.cpp',
'bindings/v8/custom/V8GeolocationCustom.cpp',
'bindings/v8/custom/V8HistoryCustom.cpp',
'bindings/v8/custom/V8HTMLAudioElementConstructor.cpp',
......@@ -1796,6 +1799,8 @@
'page/EditorClient.h',
'page/EventHandler.cpp',
'page/EventHandler.h',
'page/EventSource.cpp',
'page/EventSource.h',
'page/FocusController.cpp',
'page/FocusController.h',
'page/FocusDirection.h',
......
......@@ -357,6 +357,7 @@ sub GetInternalFields
return ("cacheIndex", "implementationIndex") if ($name eq "Document") || ($name eq "SVGDocument");
return ("cacheIndex", "implementationIndex", "markerIndex", "shadowIndex") if $name eq "HTMLDocument";
return ("cacheIndex") if IsNodeSubType($dataNode);
return ("cacheIndex") if $name eq "EventSource";
return ("cacheIndex") if $name eq "XMLHttpRequest";
return ("cacheIndex") if $name eq "XMLHttpRequestUpload";
return ("cacheIndex") if $name eq "MessagePort";
......
......@@ -188,6 +188,10 @@
#include "StorageEvent.h"
#endif // DOM_STORAGE
#if ENABLE(EVENTSOURCE)
#include "EventSource.h"
#endif // EVENTSOURCE
// GEOLOCATION
#include "Coordinates.h"
#include "Geolocation.h"
......
......@@ -424,3 +424,7 @@
#include "bindings/V8InspectorBackend.cpp"
#include "bindings/V8InspectorFrontendHost.cpp"
#endif
#if ENABLE(EVENTSOURCE)
#include "bindings/V8EventSource.cpp"
#endif
......@@ -259,6 +259,13 @@ v8::Persistent<v8::FunctionTemplate> V8DOMWrapper::getTemplate(V8ClassIndex::V8W
break;
}
#if ENABLE(EVENTSOURCE)
case V8ClassIndex::EVENTSOURCE: {
descriptor->SetCallHandler(USE_CALLBACK(EventSourceConstructor));
break;
}
#endif
#if ENABLE(WORKERS)
case V8ClassIndex::WORKER: {
descriptor->SetCallHandler(USE_CALLBACK(WorkerConstructor));
......@@ -1226,6 +1233,12 @@ v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* ta
return convertToV8Object(V8ClassIndex::DOMAPPLICATIONCACHE, domAppCache);
#endif
#if ENABLE(EVENTSOURCE)
EventSource* eventSource = target->toEventSource();
if (eventSource)
return convertToV8Object(V8ClassIndex::EVENTSOURCE, eventSource);
#endif
ASSERT(0);
return notHandledByInterceptor();
}
......@@ -1290,6 +1303,22 @@ PassRefPtr<EventListener> V8DOMWrapper::getEventListener(XMLHttpRequestUpload* u
return getEventListener(upload->associatedXMLHttpRequest(), value, isAttribute, lookup);
}
#if ENABLE(EVENTSOURCE)
PassRefPtr<EventListener> V8DOMWrapper::getEventListener(EventSource* eventSource, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup)
{
if (V8Proxy::retrieve(eventSource->scriptExecutionContext()))
return (lookup == ListenerFindOnly) ? V8EventListenerList::findWrapper(value, isAttribute) : V8EventListenerList::findOrCreateWrapper<V8EventListener>(value, isAttribute);
#if ENABLE(WORKERS)
WorkerContextExecutionProxy* workerContextProxy = WorkerContextExecutionProxy::retrieve();
if (workerContextProxy)
return workerContextProxy->findOrCreateEventListener(value, isAttribute, lookup == ListenerFindOnly);
#endif
return 0;
}
#endif
PassRefPtr<EventListener> V8DOMWrapper::getEventListener(EventTarget* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup)
{
if (V8Proxy::retrieve(eventTarget->scriptExecutionContext()))
......
......@@ -190,6 +190,10 @@ namespace WebCore {
static PassRefPtr<EventListener> getEventListener(XMLHttpRequestUpload* upload, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#if ENABLE(EVENTSOURCE)
static PassRefPtr<EventListener> getEventListener(EventSource* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
#endif
static PassRefPtr<EventListener> getEventListener(EventTarget* eventTarget, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
static PassRefPtr<EventListener> getEventListener(V8Proxy* proxy, v8::Local<v8::Value> value, bool isAttribute, ListenerLookupType lookup);
......
......@@ -445,6 +445,10 @@
#include "V8InspectorFrontendHost.h"
#endif
#if ENABLE(EVENTSOURCE)
#include "V8EventSource.h"
#endif
// Geolocation
#include "V8Coordinates.h"
#include "V8Geolocation.h"
......
......@@ -85,6 +85,13 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)();
#define WORKER_NONNODE_WRAPPER_TYPES(V)
#endif
#if ENABLE(EVENTSOURCE)
#define EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V) \
V(EVENTSOURCE, EventSource)
#else
#define EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V)
#endif
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#define APPLICATIONCACHE_NONNODE_WRAPPER_TYPES(V) \
V(DOMAPPLICATIONCACHE, DOMApplicationCache)
......@@ -321,7 +328,8 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)();
V(XMLHTTPREQUEST, XMLHttpRequest) \
WORKER_ACTIVE_OBJECT_WRAPPER_TYPES(V) \
SHARED_WORKER_ACTIVE_OBJECT_WRAPPER_TYPES(V) \
WEBSOCKET_ACTIVE_OBJECT_WRAPPER_TYPES(V)
WEBSOCKET_ACTIVE_OBJECT_WRAPPER_TYPES(V) \
EVENTSOURCE_ACTIVE_OBJECT_WRAPPER_TYPES(V)
// NOTE: DOM_OBJECT_TYPES is split into two halves because
// Visual Studio's Intellinonsense crashes when macros get
......
......@@ -38,6 +38,7 @@
#include "DOMCoreException.h"
#include "DedicatedWorkerContext.h"
#include "Event.h"
#include "EventSource.h"
#include "Notification.h"
#include "NotificationCenter.h"
#include "EventException.h"
......@@ -326,6 +327,12 @@ v8::Handle<v8::Value> WorkerContextExecutionProxy::convertEventTargetToV8Object(
return convertToV8Object(V8ClassIndex::WEBSOCKET, webSocket);
#endif
#if ENABLE(EVENTSOURCE)
EventSource* eventSource = target->toEventSource();
if (eventSource)
return convertToV8Object(V8ClassIndex::EVENTSOURCE, eventSource);
#endif
ASSERT_NOT_REACHED();
return v8::Handle<v8::Value>();
}
......
......@@ -75,6 +75,10 @@ namespace WebCore {
DECLARE_CALLBACK(WebSocketConstructor);
#endif
#if ENABLE(EVENTSOURCE)
DECLARE_CALLBACK(EventSourceConstructor);
#endif
#undef DECLARE_CALLBACK
};
} // namespace WebCore
......
/*
* Copyright (C) 2010 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"
#if ENABLE(EVENTSOURCE)
#include "V8EventSource.h"
#include "EventSource.h"
#include "Frame.h"
#include "V8Binding.h"
#include "V8CustomBinding.h"
#include "V8Proxy.h"
#include "V8Utilities.h"
#include "WorkerContext.h"
#include "WorkerContextExecutionProxy.h"
namespace WebCore {
v8::Handle<v8::Value> V8Custom::v8EventSourceConstructorCallback(const v8::Arguments& args)
{
INC_STATS("DOM.EventSource.Constructor");
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
// Expect one parameter.
// Allocate an EventSource object as its internal field.
ScriptExecutionContext* context = getScriptExecutionContext();
if (!context)
return throwError("EventSource constructor's associated context is not available", V8Proxy::ReferenceError);
if (args.Length() != 1)
return throwError("EventSource constructor wrong number of parameters", V8Proxy::TypeError);
ExceptionCode ec = 0;
String url = toWebCoreString(args[0]);
RefPtr<EventSource> eventSource = EventSource::create(url, context, ec);
if (ec)
return throwError(ec);
V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::EVENTSOURCE), eventSource.get());
// Add object to the wrapper map.
eventSource->ref();
V8DOMWrapper::setJSWrapperForActiveDOMObject(eventSource.get(), v8::Persistent<v8::Object>::New(args.Holder()));
return args.Holder();
}
} // namespace WebCore
#endif // ENABLE(EVENTSOURCE)
/*
* Copyright 2010, The Android Open Source Project
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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"
#if ENABLE(EVENTSOURCE)
#include "V8EventSource.h"
#include "EventSource.h"
#include "V8Binding.h"
#include "V8CustomBinding.h"
#include "V8Proxy.h"
namespace WebCore {
v8::Handle<v8::Value> V8EventSource::addEventListenerCallback(const v8::Arguments& args)
{
INC_STATS("DOM.EventSource.addEventListener()");
EventSource* eventSource = V8EventSource::toNative(args.Holder());
RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOrCreate);
if (listener) {
String type = toWebCoreString(args[0]);
bool useCapture = args[2]->BooleanValue();
eventSource->addEventListener(type, listener, useCapture);
createHiddenDependency(args.Holder(), args[1], cacheIndex);
}
return v8::Undefined();
}
v8::Handle<v8::Value> V8EventSource::removeEventListenerCallback(const v8::Arguments& args)
{
INC_STATS("DOM.EventSource.removeEventListener()");
EventSource* eventSource = V8EventSource::toNative(args.Holder());
RefPtr<EventListener> listener = V8DOMWrapper::getEventListener(eventSource, args[1], false, ListenerFindOnly);
if (listener) {
String type = toWebCoreString(args[0]);
bool useCapture = args[2]->BooleanValue();
eventSource->removeEventListener(type, listener.get(), useCapture);
removeHiddenDependency(args.Holder(), args[1], cacheIndex);
}
return v8::Undefined();
}
} // namespace WebCore
#endif // ENABLE(EVENTSOURCE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment