EventSource* EventSource::create(ExecutionContext* context, const String& url, const EventSourceInit& eventSourceInit, ExceptionState& exceptionState) { if (url.isEmpty()) { exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSource to an empty URL."); return nullptr; } KURL fullURL = context->completeURL(url); if (!fullURL.isValid()) { exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSource to '" + url + "'. The URL is invalid."); return nullptr; } // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved. if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->contentSecurityPolicy()->allowConnectToSource(fullURL)) { // We can safely expose the URL to JavaScript, as this exception is generate synchronously before any redirects take place. exceptionState.throwSecurityError("Refused to connect to '" + fullURL.elidedString() + "' because it violates the document's Content Security Policy."); return nullptr; } EventSource* source = new EventSource(context, fullURL, eventSourceInit); source->scheduleInitialConnect(); source->suspendIfNeeded(); return source; }
void RunLoop::PerformFunction(std::function<void ()> fn) { EventSource* ev = new EventSource([fn](EventSource& __e) { fn(); }); AddEventSource(ev); ev->Signal(); }
void setJSEventSourceOnerror(ExecState* exec, JSObject* thisObject, JSValue value) { UNUSED_PARAM(exec); EventSource* imp = static_cast<EventSource*>(static_cast<JSEventSource*>(thisObject)->impl()); JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(imp->scriptExecutionContext(), exec); if (!globalObject) return; imp->setOnerror(globalObject->createJSAttributeEventListener(value)); }
JSValue jsEventSourceOnerror(ExecState* exec, const Identifier&, const PropertySlot& slot) { JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slot.slotBase())); UNUSED_PARAM(exec); EventSource* imp = static_cast<EventSource*>(castedThis->impl()); if (EventListener* listener = imp->onerror()) { if (JSObject* jsFunction = listener->jsFunction(imp->scriptExecutionContext())) return jsFunction; } return jsNull(); }
JSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionClose(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.inherits(&JSEventSource::s_info)) return throwError(exec, TypeError); JSEventSource* castedThisObj = static_cast<JSEventSource*>(asObject(thisValue)); EventSource* imp = static_cast<EventSource*>(castedThisObj->impl()); imp->close(); return jsUndefined(); }
Impl( EventSource& output ) : _output( output ) { for( uint8_t y = 0; y < 5; ++y ) output.add( Event( Vector3f( 0.f, y * 10.f, 0.f ), VALUE_UNSET, 1.f )); output.add( Event( Vector3f( 3.f, 5.f, 4.f ), VALUE_UNSET, 1.f )); output.add( Event( Vector3f( 5.f, 2.f, 1.f ), VALUE_UNSET, 1.f )); }
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(); }
JSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionDispatchEvent(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.inherits(&JSEventSource::s_info)) return throwError(exec, TypeError); JSEventSource* castedThisObj = static_cast<JSEventSource*>(asObject(thisValue)); EventSource* imp = static_cast<EventSource*>(castedThisObj->impl()); ExceptionCode ec = 0; Event* evt = toEvent(args.at(0)); JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec)); setDOMException(exec, ec); return result; }
void WorkQueue::unregisterMachPortEventHandler(mach_port_t machPort) { ASSERT(machPort != MACH_PORT_NULL); MutexLocker locker(m_eventSourcesMutex); HashMap<mach_port_t, EventSource*>::iterator it = m_eventSources.find(machPort); ASSERT(it != m_eventSources.end()); ASSERT(m_eventSources.contains(machPort)); EventSource* eventSource = it->second; // Cancel and release the source. It will be deleted in its finalize handler. dispatch_source_cancel(eventSource->dispatchSource()); dispatch_release(eventSource->dispatchSource()); m_eventSources.remove(it); }
void EventHandler::pull(EventSource& eventSource) { auto it=iters.find(eventSource.getID()); if(it!=iters.end()) { eventSource.handlers.erase(it->second); iters.erase(it); } }
// this method parses the characters as they become available instead of // buffering them. NS_METHOD EventSource::StreamReaderFunc(nsIInputStream *aInputStream, void *aClosure, const char *aFromRawSegment, uint32_t aToOffset, uint32_t aCount, uint32_t *aWriteCount) { EventSource* thisObject = static_cast<EventSource*>(aClosure); if (!thisObject || !aWriteCount) { NS_WARNING("EventSource cannot read from stream: no aClosure or aWriteCount"); return NS_ERROR_FAILURE; } *aWriteCount = 0; int32_t srcCount, outCount; PRUnichar out[2]; nsresult rv; const char *p = aFromRawSegment, *end = aFromRawSegment + aCount; do { srcCount = aCount - (p - aFromRawSegment); outCount = 2; thisObject->mLastConvertionResult = thisObject->mUnicodeDecoder->Convert(p, &srcCount, out, &outCount); MOZ_ASSERT(thisObject->mLastConvertionResult != NS_ERROR_ILLEGAL_INPUT); for (int32_t i = 0; i < outCount; ++i) { rv = thisObject->ParseCharacter(out[i]); NS_ENSURE_SUCCESS(rv, rv); } p = p + srcCount; } while (p < end && thisObject->mLastConvertionResult != NS_PARTIAL_MORE_INPUT && thisObject->mLastConvertionResult != NS_OK); *aWriteCount = aCount; return NS_OK; }
EventSource* EventSource::create(const String& url, IEventSourceReceiver* receiver, const Hashtable<String,String>& eventSourceInit ) { LOG(TRACE) + "Creating EventSource with URL: " + url; if (url.empty()) { return 0; } String fullUrl( (url.find("://")==String::npos)? (RHODESAPP().getCurrentUrl(-1) + url): (url) ); LOG(TRACE) + "Full URL for EventSource: " + fullUrl; EventSource* source = new EventSource(fullUrl, receiver, eventSourceInit); source->scheduleInitialConnect(); return source; }
bool EventSource::operator==(EventSource& xSource) { Rect * thisRegion = getEventRegion(); Rect * thatRegion = xSource.getEventRegion(); // If they are exactly in the same region, then they are the same. // Current exceptions: Frame & Window. if (thisRegion->m_x == thatRegion->m_x && thisRegion->m_y == thatRegion->m_y && thisRegion->m_width == thatRegion->m_width && thisRegion->m_height == thatRegion->m_height) { return true; } else { return false; } }
static void eventHandler(void* source) { EventSource* eventSource = static_cast<EventSource*>(source); eventSource->m_function(); }
IFACEMETHODIMP add_Event(IEventHandler<IInspectable*>* theValue, EventRegistrationToken* token) { return m_eventSource.Add(theValue, token); }
IFACEMETHODIMP remove_Event(EventRegistrationToken token) { return m_eventSource.Remove(token); }
void Raise() { ThrowIfFailed(m_eventSource.InvokeAll(nullptr, nullptr)); }
void EventHandler::push(EventSource& eventSource) { iters[eventSource.getID()]=eventSource.handlers.insert(eventSource.handlers.begin(), this); }